fixes related to packets and entities

This commit is contained in:
GameHerobrine 2023-02-21 16:25:34 +03:00
parent abe7846bb9
commit 1ecbc1d308
6 changed files with 12 additions and 16 deletions

View file

@ -1266,7 +1266,6 @@ class Player{
if(EventHandler::callEvent(new DataPacketReceiveEvent($this, $packet)) === BaseEvent::DENY){ if(EventHandler::callEvent(new DataPacketReceiveEvent($this, $packet)) === BaseEvent::DENY){
return; return;
} }
switch($packet->pid()){ switch($packet->pid()){
case 0x01: case 0x01:
break; break;
@ -1359,8 +1358,6 @@ class Player{
return; return;
} }
$this->server->send2Discord($this->username . " joined the game");
$this->auth = true; $this->auth = true;
if(!$this->data->exists("inventory") or ($this->gamemode & 0x01) === 0x01){ if(!$this->data->exists("inventory") or ($this->gamemode & 0x01) === 0x01){
if(($this->gamemode & 0x01) === 0x01){ if(($this->gamemode & 0x01) === 0x01){
@ -1610,7 +1607,10 @@ class Player{
//$this->lastChunk = [$packet->chunkX, $packet->chunkZ]; //$this->lastChunk = [$packet->chunkX, $packet->chunkZ];
break; break;
case ProtocolInfo::UPDATE_BLOCK_PACKET: case ProtocolInfo::UPDATE_BLOCK_PACKET:
$this->level->setBlock(new Vector3($packet->x, $packet->y, $packet->z), BlockAPI::get($packet->block, $packet->meta)); if($this->gamemode & 0x01 === 0){
$this->level->setBlock(new Vector3($packet->x, $packet->y, $packet->z), BlockAPI::get($packet->block, $packet->meta));
}
break; break;
case ProtocolInfo::USE_ITEM_PACKET: case ProtocolInfo::USE_ITEM_PACKET:
if(!($this->entity instanceof Entity)){ if(!($this->entity instanceof Entity)){
@ -1658,7 +1658,6 @@ class Player{
$data["posX"] = $packet->posX; $data["posX"] = $packet->posX;
$data["posY"] = $packet->posY; $data["posY"] = $packet->posY;
$data["posZ"] = $packet->posZ; $data["posZ"] = $packet->posZ;
if($packet->face >= 0 and $packet->face <= 5){ //Use Block, place if($packet->face >= 0 and $packet->face <= 5){ //Use Block, place
if($this->entity->inAction === true){ if($this->entity->inAction === true){
$this->entity->inAction = false; $this->entity->inAction = false;

View file

@ -628,9 +628,9 @@ class Entity extends Position
$fall = $this->level->getBlock(new Vector3(intval($this->x - 0.5), intval(ceil($this->y)), intval($this->z - 0.5))); $fall = $this->level->getBlock(new Vector3(intval($this->x - 0.5), intval(ceil($this->y)), intval($this->z - 0.5)));
$down = $this->level->getBlock(new Vector3(intval($this->x - 0.5), intval(ceil($this->y) - 1), intval($this->z - 0.5))); $down = $this->level->getBlock(new Vector3(intval($this->x - 0.5), intval(ceil($this->y) - 1), intval($this->z - 0.5)));
if($fall->isFullBlock === false or $down->isFullBlock === false){ if($fall->isFullBlock === false or $down->isFullBlock === false){
$this->server->api->entity->drop($this, BlockAPI::getItem($this->data["Tile"] & 0xFFFF, 0, 1), true); $this->server->api->entity->drop($this, BlockAPI::getItem($this->data["Tile"] & 0xFFFF, $this->data["Metadata"], 1), true);
} else{ } else{
$this->level->setBlock($fall, BlockAPI::get($this->data["Tile"]), true, false, true); $this->level->setBlock($fall, BlockAPI::get($this->data["Tile"], $this->data["Metadata"]), true, false, true);
} }
$this->server->api->handle("entity.motion", $this); $this->server->api->handle("entity.motion", $this);
$this->close(); $this->close();
@ -969,13 +969,13 @@ class Entity extends Position
$player->dataPacket($pk); $player->dataPacket($pk);
break; break;
case ENTITY_FALLING: case ENTITY_FALLING:
$pk = new AddEntityPacket(); $pk = new AddEntityPacket(); //TODO fix
$pk->eid = $this->eid; $pk->eid = $this->eid;
$pk->type = $this->type; $pk->type = $this->type;
$pk->x = $this->x; $pk->x = $this->x;
$pk->y = $this->y; $pk->y = $this->y;
$pk->z = $this->z; $pk->z = $this->z;
$pk->did = - $this->data["Tile"]; $pk->did = -($this->data["Tile"] | $this->data["Metadata"] << 0x10);
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = new SetEntityMotionPacket(); $pk = new SetEntityMotionPacket();
@ -1251,10 +1251,7 @@ class Entity extends Position
public function sendMotion() public function sendMotion()
{ {
$pk = new SetEntityMotionPacket(); $pk = new SetEntityMotionPacket();
$pk->eid = $this->eid; $pk->entities = [[$this->eid, $this->speedX, $this->speedY, $this->speedZ]];
$pk->speedX = $this->speedX;
$pk->speedY = $this->speedY;
$pk->speedZ = $this->speedZ;
$this->server->api->player->broadcastPacket($this->level->players, $pk); $this->server->api->player->broadcastPacket($this->level->players, $pk);
} }

View file

@ -55,7 +55,7 @@ class EntityAI
} }
public function updateTasks(){ public function updateTasks(){
if(!isset($entity) or !($this->entity instanceof Entity)){ if(!isset($this->entity) or !($this->entity instanceof Entity)){
return; return;
} }
foreach($this->tasks as $t){ foreach($this->tasks as $t){

View file

@ -61,6 +61,7 @@ class GenericBlock extends Block{
"y" => $this->y + 0.5, "y" => $this->y + 0.5,
"z" => $this->z + 0.5, "z" => $this->z + 0.5,
"Tile" => $this->id, "Tile" => $this->id,
"Metadata" => $this->getMetadata()
); );
$server = ServerAPI::request(); $server = ServerAPI::request();
$this->level->setBlock($this, new AirBlock(), false, false, true); $this->level->setBlock($this, new AirBlock(), false, false, true);

View file

@ -12,7 +12,6 @@ class UpdateBlockPacket extends RakNetDataPacket{
} }
public function decode(){ public function decode(){
} }
public function encode(){ public function encode(){

View file

@ -25,7 +25,7 @@ class UseItemPacket extends RakNetDataPacket{
$this->z = $this->getInt(); $this->z = $this->getInt();
$this->face = $this->getInt(); $this->face = $this->getInt();
$this->item = $this->getShort(); $this->item = $this->getShort();
$this->meta = $this->getByte(); //Mojang: fix this $this->meta = $this->getShort();
$this->eid = $this->getInt(); $this->eid = $this->getInt();
$this->fx = $this->getFloat(); $this->fx = $this->getFloat();
$this->fy = $this->getFloat(); $this->fy = $this->getFloat();