From 9abba9a2a2837a3ad62db28aff8db7d9a862bd55 Mon Sep 17 00:00:00 2001 From: ArkQuark <74979909+ArkQuark@users.noreply.github.com> Date: Sat, 25 Mar 2023 18:37:40 +0300 Subject: [PATCH] php 8.1 fixs --- src/Player.php | 9 ++- src/entity/object/Snowball.php | 0 src/entity/object/{ => projectile}/Arrow.php | 4 +- src/entity/object/{ => projectile}/Egg.php | 0 src/entity/object/projectile/Snowball.php | 61 ++++++++++++++++++++ src/entity/registry/EntityRegistry.php | 2 + src/material/Item.php | 2 +- src/math/Matrix.php | 6 +- src/nbt/tag/Compound.php | 4 ++ src/nbt/tag/Enum.php | 5 ++ src/network/raknet/RakNetCodec.php | 4 +- src/network/raknet/RakNetDataPacket.php | 2 +- src/world/generator/biome/BiomeSelector.php | 2 +- 13 files changed, 90 insertions(+), 11 deletions(-) delete mode 100644 src/entity/object/Snowball.php rename src/entity/object/{ => projectile}/Arrow.php (97%) rename src/entity/object/{ => projectile}/Egg.php (100%) create mode 100644 src/entity/object/projectile/Snowball.php diff --git a/src/Player.php b/src/Player.php index ea6df2f7..21e9036c 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1717,7 +1717,7 @@ class Player{ switch($packet->action){ case 5: //Shot arrow if($this->entity->inAction === true){ - if($this->getSlot($this->slot)->getID() === BOW){ + if($this->getSlot($this->slot)->getID() === BOW){ // and player had arrow){ if($this->startAction !== false){ $time = microtime(true) - $this->startAction; $d = [ @@ -1727,12 +1727,15 @@ class Player{ "yaw" => $this->entity->yaw, "pitch" => $this->entity->pitch ]; - $e = $this->server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_ARROW, $d); + $e = $this->server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_SNOWBALL, $d); $e->speedX = -sin(($e->yaw / 180) * M_PI) * cos(($e->pitch / 180) * M_PI); $e->speedZ = cos(($e->yaw / 180) * M_PI) * cos(($e->pitch / 180) * M_PI); $e->speedY = -sin(($e->pitch / 180) * M_PI); $e->shoot($e->speedX, $e->speedY, $e->speedZ, 1.5, 1.0); - $this->server->api->entity->spawnToAll($e); + //$this->server->api->entity->spawnToAll($e); + $e->spawn($this); + $this->getSlot($this->slot)->useOn("shooting", true); + $this->removeItem(ARROW, 0, 1); } } } diff --git a/src/entity/object/Snowball.php b/src/entity/object/Snowball.php deleted file mode 100644 index e69de29b..00000000 diff --git a/src/entity/object/Arrow.php b/src/entity/object/projectile/Arrow.php similarity index 97% rename from src/entity/object/Arrow.php rename to src/entity/object/projectile/Arrow.php index 2fb08ae5..744e9732 100644 --- a/src/entity/object/Arrow.php +++ b/src/entity/object/projectile/Arrow.php @@ -40,7 +40,7 @@ class Arrow extends Projectile{ } public function spawn($player){ - if($this->type === OBJECT_ARROW){ + //if($this->type === OBJECT_ARROW){ $pk = new AddEntityPacket; $pk->eid = $this->eid; $pk->type = $this->type; @@ -56,6 +56,6 @@ class Arrow extends Projectile{ $pk = new SetEntityMotionPacket; $pk->entities = [[$this->eid, $this->speedX, $this->speedY, $this->speedZ]]; $player->dataPacket($pk); - } + //} } } diff --git a/src/entity/object/Egg.php b/src/entity/object/projectile/Egg.php similarity index 100% rename from src/entity/object/Egg.php rename to src/entity/object/projectile/Egg.php diff --git a/src/entity/object/projectile/Snowball.php b/src/entity/object/projectile/Snowball.php new file mode 100644 index 00000000..fc01ede0 --- /dev/null +++ b/src/entity/object/projectile/Snowball.php @@ -0,0 +1,61 @@ +server->schedule(1210, array($this, "update")); //Despawn + } + + public function handleUpdate(){ + $pk = new MoveEntityPacket_PosRot; + $pk->eid = $this->eid; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->yaw = $this->yaw; + $pk->pitch = $this->pitch; + $this->server->api->player->broadcastPacket($this->level->players, $pk); + } + + public function shoot($d, $d1, $d2, $f, $f1){ //original name from 0.8.1 IDA decompilation, var names are taken from b1.7.3 + $f2 = sqrt($d * $d + $d1 * $d1 + $d2 * $d2); + $d /= $f2; + $d1 /= $f2; + $d2 /= $f2; + $d += $this->random->nextGaussian() * 0.0075 * $f1; //0.0074999998323619366 replaced with 0.0075 + $d1 += $this->random->nextGaussian() * 0.0075 * $f1; + $d2 += $this->random->nextGaussian() * 0.0075 * $f1; + $d *= $f; + $d1 *= $f; + $d2 *= $f; + $this->speedX = $d; + $this->speedY = $d1; + $this->speedZ = $d2; + $f3 = sqrt($d * $d + $d2 * $d2); + $this->yaw = (atan2($d, $d2) * 180) / M_PI; + $this->pitch = (atan2($d1, $f3) * 180) / M_PI; + $this->update(); + //TODO i guess? $ticksInGround = 0; + } + + public function spawn($player){ + //if($this->type === OBJECT_ARROW){ + $pk = new AddEntityPacket; + $pk->eid = $this->eid; + $pk->type = $this->type; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->did = 1; + $pk->speedX = $this->speedX; + $pk->speedY = $this->speedY; + $pk->speedZ = $this->speedZ; + $player->dataPacket($pk); + + $pk = new SetEntityMotionPacket; + $pk->entities = [[$this->eid, $this->speedX, $this->speedY, $this->speedZ]]; + $player->dataPacket($pk); + //} + } +} \ No newline at end of file diff --git a/src/entity/registry/EntityRegistry.php b/src/entity/registry/EntityRegistry.php index 0bbb8b0b..fc719089 100644 --- a/src/entity/registry/EntityRegistry.php +++ b/src/entity/registry/EntityRegistry.php @@ -25,6 +25,8 @@ class EntityRegistry{ self::registerEntity(PrimedTNT::class); self::registerEntity(Painting::class); self::registerEntity(Minecart::class); + self::registerEntity(Snowball::class); + //self::registerEntity(Egg::class); } /*Register an Entity*/ diff --git a/src/material/Item.php b/src/material/Item.php index 25e03311..e5cc0a1a 100755 --- a/src/material/Item.php +++ b/src/material/Item.php @@ -245,7 +245,7 @@ class Item{ 5 => 1561, //DIAMOND(called EMERALD in disassembled code) FLINT_STEEL => 65, //lets assume it is correct SHEARS => 239, //x2 - BOW => 385 //x3 + BOW => 2 //x3 ]; if(($type = $this->getLevel()) === false){ diff --git a/src/math/Matrix.php b/src/math/Matrix.php index 44fe49f7..46c60568 100644 --- a/src/math/Matrix.php +++ b/src/math/Matrix.php @@ -21,18 +21,22 @@ class Matrix implements ArrayAccess{ } } - public function offsetExists($offset){ + #[\ReturnTypeWillChange] + public function offsetExists($offset){ return isset($this->matrix[(int) $offset]); } + #[\ReturnTypeWillChange] public function offsetGet($offset){ return $this->matrix[(int) $offset]; } + #[\ReturnTypeWillChange] public function offsetSet($offset, $value){ $this->matrix[(int) $offset] = $value; } + #[\ReturnTypeWillChange] public function offsetUnset($offset){ unset($this->matrix[(int) $offset]); } diff --git a/src/nbt/tag/Compound.php b/src/nbt/tag/Compound.php index cad3d6e3..a8f99aaf 100644 --- a/src/nbt/tag/Compound.php +++ b/src/nbt/tag/Compound.php @@ -28,10 +28,12 @@ class Compound extends NamedTag implements \ArrayAccess{ } } + #[\ReturnTypeWillChange] public function offsetExists($offset){ return isset($this->{$offset}); } + #[\ReturnTypeWillChange] public function offsetGet($offset){ if($this->{$offset} instanceof Tag){ if($this->{$offset} instanceof \ArrayAccess){ @@ -44,6 +46,7 @@ class Compound extends NamedTag implements \ArrayAccess{ return null; } + #[\ReturnTypeWillChange] public function offsetSet($offset, $value){ if($value instanceof Tag){ $this->{$offset} = $value; @@ -52,6 +55,7 @@ class Compound extends NamedTag implements \ArrayAccess{ } } + #[\ReturnTypeWillChange] public function offsetUnset($offset){ unset($this->{$offset}); } diff --git a/src/nbt/tag/Enum.php b/src/nbt/tag/Enum.php index ead30972..8572dde4 100644 --- a/src/nbt/tag/Enum.php +++ b/src/nbt/tag/Enum.php @@ -40,10 +40,12 @@ class Enum extends NamedTag implements \ArrayAccess, \Countable{ return $value; } + #[\ReturnTypeWillChange] public function offsetExists($offset){ return isset($this->{$offset}); } + #[\ReturnTypeWillChange] public function offsetGet($offset){ if($this->{$offset} instanceof Tag){ if($this->{$offset} instanceof \ArrayAccess){ @@ -56,6 +58,7 @@ class Enum extends NamedTag implements \ArrayAccess, \Countable{ return null; } + #[\ReturnTypeWillChange] public function offsetSet($offset, $value){ if($value instanceof Tag){ $this->{$offset} = $value; @@ -64,10 +67,12 @@ class Enum extends NamedTag implements \ArrayAccess, \Countable{ } } + #[\ReturnTypeWillChange] public function offsetUnset($offset){ unset($this->{$offset}); } + #[\ReturnTypeWillChange] public function count($mode = COUNT_NORMAL){ for($i = 0; true; $i++){ if(!isset($this->{$i})){ diff --git a/src/network/raknet/RakNetCodec.php b/src/network/raknet/RakNetCodec.php index b7754061..6b2313b8 100644 --- a/src/network/raknet/RakNetCodec.php +++ b/src/network/raknet/RakNetCodec.php @@ -6,12 +6,12 @@ class RakNetCodec{ public function __construct(RakNetPacket $packet){ $this->packet = $packet; - $this->buffer =& $this->packet->buffer; + $this->buffer = &$this->packet->buffer; $this->encode(); } private function encode(){ - if(strlen($this->packet->buffer) > 0){ + if($this->packet->buffer != null && strlen($this->packet->buffer) > 0){ return; } $this->buffer .= chr($this->packet->pid()); diff --git a/src/network/raknet/RakNetDataPacket.php b/src/network/raknet/RakNetDataPacket.php index b9d842b3..012fd7c7 100755 --- a/src/network/raknet/RakNetDataPacket.php +++ b/src/network/raknet/RakNetDataPacket.php @@ -139,7 +139,7 @@ abstract class RakNetDataPacket extends stdClass{ } protected function putByte($v){ - $this->buffer .= chr($v); + $this->buffer .= chr((int)$v); } protected function getString(){ diff --git a/src/world/generator/biome/BiomeSelector.php b/src/world/generator/biome/BiomeSelector.php index 2c9e5fa1..1e2a7a27 100644 --- a/src/world/generator/biome/BiomeSelector.php +++ b/src/world/generator/biome/BiomeSelector.php @@ -25,7 +25,7 @@ class BiomeSelector } public static function registerBiome(Biome $b){ - ConsoleAPI::debug("Registered $b"); + //ConsoleAPI::debug("Registered $b"); self::$biomes[$b->getID()] = $b; } /**