diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 1bbb61d4c..36926fd1b 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -116,13 +116,13 @@ class Block extends Position implements BlockIds, Metadatable{ * @return int */ public function getRuntimeId() : int{ - return BlockFactory::toStaticRuntimeId($this->getId(), $this->getDamage()); + return BlockFactory::toStaticRuntimeId($this->getId(), $this->getMeta()); } /** * @return int */ - public function getDamage() : int{ + public function getMeta() : int{ $stateMeta = $this->writeStateToMeta(); assert(($stateMeta & ~$this->getStateBitmask()) === 0); return $this->idInfo->getVariant() | $stateMeta; @@ -155,7 +155,7 @@ class Block extends Position implements BlockIds, Metadatable{ } public function writeStateToWorld() : void{ - $this->level->getChunkAtPosition($this)->setBlock($this->x & 0xf, $this->y, $this->z & 0xf, $this->getId(), $this->getDamage()); + $this->level->getChunkAtPosition($this)->setBlock($this->x & 0xf, $this->y, $this->z & 0xf, $this->getId(), $this->getMeta()); $tileType = $this->idInfo->getTileClass(); $oldTile = $this->level->getTile($this); @@ -692,7 +692,7 @@ class Block extends Position implements BlockIds, Metadatable{ * @return string */ public function __toString(){ - return "Block[" . $this->getName() . "] (" . $this->getId() . ":" . $this->getDamage() . ")"; + return "Block[" . $this->getName() . "] (" . $this->getId() . ":" . $this->getMeta() . ")"; } /** diff --git a/src/pocketmine/block/BlockFactory.php b/src/pocketmine/block/BlockFactory.php index 4db1f4b9e..b51dab9d0 100644 --- a/src/pocketmine/block/BlockFactory.php +++ b/src/pocketmine/block/BlockFactory.php @@ -555,7 +555,7 @@ class BlockFactory{ $v = clone $block; try{ $v->readStateFromData($id, $m & $stateMask); - if($v->getDamage() !== $m){ + if($v->getMeta() !== $m){ throw new InvalidBlockStateException("Corrupted meta"); //don't register anything that isn't the same when we read it back again } }catch(InvalidBlockStateException $e){ //invalid property combination diff --git a/src/pocketmine/block/Grass.php b/src/pocketmine/block/Grass.php index 39c4eaa30..4f095efba 100644 --- a/src/pocketmine/block/Grass.php +++ b/src/pocketmine/block/Grass.php @@ -75,7 +75,7 @@ class Grass extends Solid{ $b = $this->level->getBlockAt($x, $y, $z); if( $b->getId() !== Block::DIRT or - $b->getDamage() === 1 or //coarse dirt + $b->getMeta() === 1 or //coarse dirt $this->level->getFullLightAt($x, $y + 1, $z) < 4 or $this->level->getBlockAt($x, $y + 1, $z)->getLightFilter() >= 2 ){ diff --git a/src/pocketmine/command/defaults/GiveCommand.php b/src/pocketmine/command/defaults/GiveCommand.php index 0e43bcac1..c84ee3345 100644 --- a/src/pocketmine/command/defaults/GiveCommand.php +++ b/src/pocketmine/command/defaults/GiveCommand.php @@ -90,7 +90,7 @@ class GiveCommand extends VanillaCommand{ $player->getInventory()->addItem(clone $item); Command::broadcastCommandMessage($sender, new TranslationContainer("%commands.give.success", [ - $item->getName() . " (" . $item->getId() . ":" . $item->getDamage() . ")", + $item->getName() . " (" . $item->getId() . ":" . $item->getMeta() . ")", (string) $item->getCount(), $player->getName() ])); diff --git a/src/pocketmine/entity/object/FallingBlock.php b/src/pocketmine/entity/object/FallingBlock.php index d13a58802..4016ceed7 100644 --- a/src/pocketmine/entity/object/FallingBlock.php +++ b/src/pocketmine/entity/object/FallingBlock.php @@ -132,7 +132,7 @@ class FallingBlock extends Entity{ public function saveNBT() : CompoundTag{ $nbt = parent::saveNBT(); $nbt->setInt("TileID", $this->block->getId()); - $nbt->setByte("Data", $this->block->getDamage()); + $nbt->setByte("Data", $this->block->getMeta()); return $nbt; } diff --git a/src/pocketmine/entity/projectile/Projectile.php b/src/pocketmine/entity/projectile/Projectile.php index b6ef1154d..57bb71307 100644 --- a/src/pocketmine/entity/projectile/Projectile.php +++ b/src/pocketmine/entity/projectile/Projectile.php @@ -154,7 +154,7 @@ abstract class Projectile extends Entity{ //we intentionally use different ones to PC because we don't have stringy IDs $nbt->setInt("blockId", $this->blockHit->getId()); - $nbt->setByte("blockData", $this->blockHit->getDamage()); + $nbt->setByte("blockData", $this->blockHit->getMeta()); } return $nbt; diff --git a/src/pocketmine/inventory/CraftingManager.php b/src/pocketmine/inventory/CraftingManager.php index 8cb3e843f..b35f3a9e5 100644 --- a/src/pocketmine/inventory/CraftingManager.php +++ b/src/pocketmine/inventory/CraftingManager.php @@ -139,7 +139,7 @@ class CraftingManager{ */ public static function sort(Item $i1, Item $i2){ //Use spaceship operator to compare each property, then try the next one if they are equivalent. - ($retval = $i1->getId() <=> $i2->getId()) === 0 && ($retval = $i1->getDamage() <=> $i2->getDamage()) === 0 && ($retval = $i1->getCount() <=> $i2->getCount()); + ($retval = $i1->getId() <=> $i2->getId()) === 0 && ($retval = $i1->getMeta() <=> $i2->getMeta()) === 0 && ($retval = $i1->getCount() <=> $i2->getCount()); return $retval; } @@ -223,7 +223,7 @@ class CraftingManager{ */ public function registerFurnaceRecipe(FurnaceRecipe $recipe) : void{ $input = $recipe->getInput(); - $this->furnaceRecipes[$input->getId() . ":" . ($input->hasAnyDamageValue() ? "?" : $input->getDamage())] = $recipe; + $this->furnaceRecipes[$input->getId() . ":" . ($input->hasAnyDamageValue() ? "?" : $input->getMeta())] = $recipe; $this->craftingDataCache = null; } @@ -286,6 +286,6 @@ class CraftingManager{ * @return FurnaceRecipe|null */ public function matchFurnaceRecipe(Item $input) : ?FurnaceRecipe{ - return $this->furnaceRecipes[$input->getId() . ":" . $input->getDamage()] ?? $this->furnaceRecipes[$input->getId() . ":?"] ?? null; + return $this->furnaceRecipes[$input->getId() . ":" . $input->getMeta()] ?? $this->furnaceRecipes[$input->getId() . ":?"] ?? null; } } diff --git a/src/pocketmine/item/Durable.php b/src/pocketmine/item/Durable.php index 6cd8af780..0f43bd125 100644 --- a/src/pocketmine/item/Durable.php +++ b/src/pocketmine/item/Durable.php @@ -33,6 +33,10 @@ abstract class Durable extends Item{ /** @var int */ protected $damage = 0; + public function getMeta() : int{ + return $this->damage; + } + /** * Returns whether this item will take damage when used. * @return bool diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index c5e409b0e..259adb682 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -657,7 +657,7 @@ class Item implements ItemIds, \JsonSerializable{ /** * @return int */ - public function getDamage() : int{ + public function getMeta() : int{ return $this->meta; } @@ -811,7 +811,7 @@ class Item implements ItemIds, \JsonSerializable{ * @return bool */ final public function equals(Item $item, bool $checkDamage = true, bool $checkCompound = true) : bool{ - if($this->id === $item->getId() and (!$checkDamage or $this->getDamage() === $item->getDamage())){ + if($this->id === $item->getId() and (!$checkDamage or $this->getMeta() === $item->getMeta())){ if($checkCompound){ if($this->hasNamedTag() and $item->hasNamedTag()){ //both items have NBT return $this->getNamedTag()->equals($item->getNamedTag()); @@ -841,7 +841,7 @@ class Item implements ItemIds, \JsonSerializable{ * @return string */ final public function __toString() : string{ - return "Item " . $this->name . " (" . $this->id . ":" . ($this->hasAnyDamageValue() ? "?" : $this->getDamage()) . ")x" . $this->count . ($this->hasNamedTag() ? " tags:0x" . self::writeCompoundTag($this->nbt) : ""); + return "Item " . $this->name . " (" . $this->id . ":" . ($this->hasAnyDamageValue() ? "?" : $this->getMeta()) . ")x" . $this->count . ($this->hasNamedTag() ? " tags:0x" . self::writeCompoundTag($this->nbt) : ""); } /** @@ -854,8 +854,8 @@ class Item implements ItemIds, \JsonSerializable{ "id" => $this->getId() ]; - if($this->getDamage() !== 0){ - $data["damage"] = $this->getDamage(); + if($this->getMeta() !== 0){ + $data["damage"] = $this->getMeta(); } if($this->getCount() !== 1){ @@ -904,7 +904,7 @@ class Item implements ItemIds, \JsonSerializable{ $result = new CompoundTag($tagName, [ new ShortTag("id", $this->id), new ByteTag("Count", Binary::signByte($this->count)), - new ShortTag("Damage", $this->getDamage()) + new ShortTag("Damage", $this->getMeta()) ]); if($this->hasNamedTag()){ diff --git a/src/pocketmine/item/ItemFactory.php b/src/pocketmine/item/ItemFactory.php index 5f5a57844..d83c1e4e6 100644 --- a/src/pocketmine/item/ItemFactory.php +++ b/src/pocketmine/item/ItemFactory.php @@ -330,7 +330,7 @@ class ItemFactory{ */ public static function register(Item $item, bool $override = false){ $id = $item->getId(); - $variant = $item->getDamage(); + $variant = $item->getMeta(); if(!$override and self::isRegistered($id, $variant)){ throw new \RuntimeException("Trying to overwrite an already registered item"); diff --git a/src/pocketmine/level/SimpleChunkManager.php b/src/pocketmine/level/SimpleChunkManager.php index a51452cef..aa875b371 100644 --- a/src/pocketmine/level/SimpleChunkManager.php +++ b/src/pocketmine/level/SimpleChunkManager.php @@ -54,7 +54,7 @@ class SimpleChunkManager implements ChunkManager{ public function setBlockAt(int $x, int $y, int $z, Block $block) : bool{ if(($chunk = $this->getChunk($x >> 4, $z >> 4)) !== null){ - return $chunk->setBlock($x & 0xf, $y, $z & 0xf, $block->getId(), $block->getDamage()); + return $chunk->setBlock($x & 0xf, $y, $z & 0xf, $block->getId(), $block->getMeta()); } return false; } diff --git a/src/pocketmine/level/generator/Flat.php b/src/pocketmine/level/generator/Flat.php index 2c488b74c..220ec3a0e 100644 --- a/src/pocketmine/level/generator/Flat.php +++ b/src/pocketmine/level/generator/Flat.php @@ -116,7 +116,7 @@ class Flat extends Generator{ throw new InvalidGeneratorOptionsException("Invalid preset layer \"$line\": " . $e->getMessage(), 0, $e); } for($cY = $y, $y += $cnt; $cY < $y; ++$cY){ - $result[$cY] = [$b->getId(), $b->getDamage()]; + $result[$cY] = [$b->getId(), $b->getMeta()]; } } diff --git a/src/pocketmine/level/generator/populator/GroundCover.php b/src/pocketmine/level/generator/populator/GroundCover.php index 9e36da337..6127d66a0 100644 --- a/src/pocketmine/level/generator/populator/GroundCover.php +++ b/src/pocketmine/level/generator/populator/GroundCover.php @@ -64,7 +64,7 @@ class GroundCover extends Populator{ continue; } - $chunk->setBlock($x, $y, $z, $b->getId(), $b->getDamage()); + $chunk->setBlock($x, $y, $z, $b->getId(), $b->getMeta()); } } } diff --git a/src/pocketmine/level/particle/ItemBreakParticle.php b/src/pocketmine/level/particle/ItemBreakParticle.php index 0baffed37..3e706c687 100644 --- a/src/pocketmine/level/particle/ItemBreakParticle.php +++ b/src/pocketmine/level/particle/ItemBreakParticle.php @@ -28,6 +28,6 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds; class ItemBreakParticle extends GenericParticle{ public function __construct(Item $item){ - parent::__construct(ParticleIds::ITEM_BREAK, ($item->getId() << 16) | $item->getDamage()); + parent::__construct(ParticleIds::ITEM_BREAK, ($item->getId() << 16) | $item->getMeta()); } } diff --git a/src/pocketmine/network/mcpe/NetworkBinaryStream.php b/src/pocketmine/network/mcpe/NetworkBinaryStream.php index 3c78b3cbf..160bac86b 100644 --- a/src/pocketmine/network/mcpe/NetworkBinaryStream.php +++ b/src/pocketmine/network/mcpe/NetworkBinaryStream.php @@ -132,7 +132,7 @@ class NetworkBinaryStream extends BinaryStream{ } $this->putVarInt($item->getId()); - $auxValue = (($item->getDamage() & 0x7fff) << 8) | $item->getCount(); + $auxValue = (($item->getMeta() & 0x7fff) << 8) | $item->getCount(); $this->putVarInt($auxValue); if($item->hasNamedTag()){ diff --git a/src/pocketmine/network/mcpe/protocol/CraftingDataPacket.php b/src/pocketmine/network/mcpe/protocol/CraftingDataPacket.php index f3940dd82..781ad8392 100644 --- a/src/pocketmine/network/mcpe/protocol/CraftingDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/CraftingDataPacket.php @@ -169,7 +169,7 @@ class CraftingDataPacket extends DataPacket implements ClientboundPacket{ private static function writeFurnaceRecipe(FurnaceRecipe $recipe, NetworkBinaryStream $stream) : int{ if(!$recipe->getInput()->hasAnyDamageValue()){ //Data recipe $stream->putVarInt($recipe->getInput()->getId()); - $stream->putVarInt($recipe->getInput()->getDamage()); + $stream->putVarInt($recipe->getInput()->getMeta()); $stream->putSlot($recipe->getResult()); return CraftingDataPacket::ENTRY_FURNACE_DATA; diff --git a/src/pocketmine/tile/FlowerPot.php b/src/pocketmine/tile/FlowerPot.php index ccfc5bc31..a9005c706 100644 --- a/src/pocketmine/tile/FlowerPot.php +++ b/src/pocketmine/tile/FlowerPot.php @@ -55,7 +55,7 @@ class FlowerPot extends Spawnable{ protected function writeSaveData(CompoundTag $nbt) : void{ if($this->plant !== null){ $nbt->setShort(self::TAG_ITEM, $this->plant->getId()); - $nbt->setInt(self::TAG_ITEM_DATA, $this->plant->getDamage()); + $nbt->setInt(self::TAG_ITEM_DATA, $this->plant->getMeta()); } } @@ -75,7 +75,7 @@ class FlowerPot extends Spawnable{ protected function addAdditionalSpawnData(CompoundTag $nbt) : void{ if($this->plant !== null){ $nbt->setShort(self::TAG_ITEM, $this->plant->getId()); - $nbt->setInt(self::TAG_ITEM_DATA, $this->plant->getDamage()); + $nbt->setInt(self::TAG_ITEM_DATA, $this->plant->getMeta()); } } } diff --git a/src/pocketmine/tile/Furnace.php b/src/pocketmine/tile/Furnace.php index b98dd5b55..29dbc53c5 100644 --- a/src/pocketmine/tile/Furnace.php +++ b/src/pocketmine/tile/Furnace.php @@ -177,7 +177,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{ ++$this->cookTime; if($this->cookTime >= 200){ //10 seconds - $product = ItemFactory::get($smelt->getResult()->getId(), $smelt->getResult()->getDamage(), $product->getCount() + 1); + $product = ItemFactory::get($smelt->getResult()->getId(), $smelt->getResult()->getMeta(), $product->getCount() + 1); $ev = new FurnaceSmeltEvent($this, $raw, $product); $ev->call(); diff --git a/tests/phpunit/block/BlockTest.php b/tests/phpunit/block/BlockTest.php index 5931f9c2b..faf52a96a 100644 --- a/tests/phpunit/block/BlockTest.php +++ b/tests/phpunit/block/BlockTest.php @@ -119,7 +119,7 @@ class BlockTest extends TestCase{ $block = BlockFactory::get($id, $meta); self::assertEquals($id, $block->getId()); - self::assertEquals($meta, $block->getDamage()); + self::assertEquals($meta, $block->getMeta()); } public function testBlockIds() : void{ diff --git a/tests/phpunit/item/ItemFactoryTest.php b/tests/phpunit/item/ItemFactoryTest.php index c3d35c1a1..5676f7b83 100644 --- a/tests/phpunit/item/ItemFactoryTest.php +++ b/tests/phpunit/item/ItemFactoryTest.php @@ -64,7 +64,7 @@ class ItemFactoryTest extends TestCase{ $item = ItemFactory::fromString($string); self::assertEquals($id, $item->getId()); - self::assertEquals($meta, $item->getDamage()); + self::assertEquals($meta, $item->getMeta()); } /**