Rename two misleadingly-named functions

This commit is contained in:
Dylan K. Taylor 2019-02-27 12:59:12 +00:00
parent ba616ed8a7
commit 9ad0ea85c7
20 changed files with 34 additions and 30 deletions

View File

@ -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() . ")";
}
/**

View File

@ -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

View File

@ -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
){

View File

@ -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()
]));

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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

View File

@ -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()){

View File

@ -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");

View File

@ -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;
}

View File

@ -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()];
}
}

View File

@ -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());
}
}
}

View File

@ -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());
}
}

View File

@ -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()){

View File

@ -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;

View File

@ -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());
}
}
}

View File

@ -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();

View File

@ -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{

View File

@ -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());
}
/**