From 12c9e664f0378743e1451c7d27601f039c31b160 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Tue, 21 Feb 2023 20:08:50 +0300 Subject: [PATCH] fixed nbt(which somehow worked before), enderman ai updates --- src/entity/Entity.php | 2 +- src/entity/monster/Enderman.php | 22 ++++++++++++++++++++++ src/nbt/NBT_new.php | 6 +++--- src/nbt/tag/Enum.php | 6 +++--- src/recipes/CraftingRecipes.php | 1 - src/world/Level.php | 24 ++++++++++++------------ 6 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 71c36d36..bc42dee6 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -431,7 +431,7 @@ class Entity extends Position $this->fire = 0; $this->updateMetadata(); } - if ($this->air <= 0 && ! $waterDone) { + if (($this->air <= 0 && ! $waterDone) || $this->type === MOB_ENDERMAN) { //TODO check is correct $this->harm(2, "water"); $hasUpdate = true; $waterDone = true; diff --git a/src/entity/monster/Enderman.php b/src/entity/monster/Enderman.php index 3dd6ff2a..8b5ca28b 100644 --- a/src/entity/monster/Enderman.php +++ b/src/entity/monster/Enderman.php @@ -3,6 +3,9 @@ class Enderman extends Monster { const TYPE = MOB_ENDERMAN; + + public $forceTeleport; + public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $this->setSize(0.6, 2.9); parent::__construct($level, $eid, $class, $type, $data); @@ -11,6 +14,25 @@ class Enderman extends Monster $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 40, "generic"); } + public function harm($dmg, $cause = "generic", $force = false){ + parent::harm($dmg, $cause, $force); + if($cause === "water"){ + $this->randomTeleport(); + } + } + + public function randomTeleport(){ + $x = $this->x + ($this->random->nextFloat() - 0.5) * 64; + $z = $this->z + ($this->random->nextFloat() - 0.5) * 64; + for($y = 0; $y < 128; ++$y){ + $b = $this->level->getBlockWithoutVector($x, $y, $z); + if($b instanceof Block && !$b->isTransparent){ //TODO hitbox check + $this->x = $x; + $this->y = $y+0.5; + $this->z = $z; + } + } + } } diff --git a/src/nbt/NBT_new.php b/src/nbt/NBT_new.php index 09945c1d..9352c969 100644 --- a/src/nbt/NBT_new.php +++ b/src/nbt/NBT_new.php @@ -121,7 +121,7 @@ class NBT_new{ $tag->read($this); break; case NBT::TAG_Int: - $tag = new Int($this->getString()); + $tag = new IntTag($this->getString()); $tag->read($this); break; case NBT::TAG_Long: @@ -129,7 +129,7 @@ class NBT_new{ $tag->read($this); break; case NBT::TAG_Float: - $tag = new Float($this->getString()); + $tag = new FloatTag($this->getString()); $tag->read($this); break; case NBT::TAG_Double: @@ -141,7 +141,7 @@ class NBT_new{ $tag->read($this); break; case NBT::TAG_String: - $tag = new String($this->getString()); + $tag = new StringTag($this->getString()); $tag->read($this); break; case NBT::TAG_Enum: diff --git a/src/nbt/tag/Enum.php b/src/nbt/tag/Enum.php index 18080917..ead30972 100644 --- a/src/nbt/tag/Enum.php +++ b/src/nbt/tag/Enum.php @@ -110,7 +110,7 @@ class Enum extends NamedTag implements \ArrayAccess, \Countable{ $this->{$i} = $tag; break; case NBT_new::TAG_Int: - $tag = new Int(false); + $tag = new IntTag(false); $tag->read($NBT_new); $this->{$i} = $tag; break; @@ -120,7 +120,7 @@ class Enum extends NamedTag implements \ArrayAccess, \Countable{ $this->{$i} = $tag; break; case NBT_new::TAG_Float: - $tag = new Float(false); + $tag = new FloatTag(false); $tag->read($NBT_new); $this->{$i} = $tag; break; @@ -135,7 +135,7 @@ class Enum extends NamedTag implements \ArrayAccess, \Countable{ $this->{$i} = $tag; break; case NBT_new::TAG_String: - $tag = new String(false); + $tag = new StringTag(false); $tag->read($NBT_new); $this->{$i} = $tag; break; diff --git a/src/recipes/CraftingRecipes.php b/src/recipes/CraftingRecipes.php index 6854317b..70bb3c44 100644 --- a/src/recipes/CraftingRecipes.php +++ b/src/recipes/CraftingRecipes.php @@ -1,7 +1,6 @@ CLAY_BLOCK:0x1", diff --git a/src/world/Level.php b/src/world/Level.php index 9673ea7e..a8ae9784 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -137,14 +137,14 @@ class Level{ case "Sign": $text = $tile->getText(); $nbt->setData(new Compound("", array( - new String("Text1", $text[0]), - new String("Text2", $text[1]), - new String("Text3", $text[2]), - new String("Text4", $text[3]), - new String("id", "Sign"), - new Int("x", (int) $tile->x), - new Int("y", (int) $tile->y), - new Int("z", (int) $tile->z) + new StringTag("Text1", $text[0]), + new StringTag("Text2", $text[1]), + new StringTag("Text3", $text[2]), + new StringTag("Text4", $text[3]), + new StringTag("id", "Sign"), + new IntTag("x", (int) $tile->x), + new IntTag("y", (int) $tile->y), + new IntTag("z", (int) $tile->z) ))); $tileEntities .= $nbt->write(); break; @@ -153,10 +153,10 @@ class Level{ break; case "Chest": $nbt->setData(new Compound("", array( - new String("id", "Chest"), - new Int("x", (int) $tile->x), - new Int("y", (int) $tile->y), - new Int("z", (int) $tile->z) + new StringTag("id", "Chest"), + new IntTag("x", (int) $tile->x), + new IntTag("y", (int) $tile->y), + new IntTag("z", (int) $tile->z) ))); $tileEntities .= $nbt->write(); break;