Fixed block-pick on crops giving the crop block itself

This commit is contained in:
Dylan K. Taylor 2017-11-03 12:17:38 +00:00
parent 42ed03fd02
commit 451f5d0cd7
8 changed files with 33 additions and 3 deletions

View File

@ -2580,9 +2580,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{
$block = $this->level->getBlockAt($packet->blockX, $packet->blockY, $packet->blockZ);
//TODO: this doesn't handle crops correctly (need more API work)
$item = Item::get($block->getItemId(), $block->getVariant());
$item = $block->getPickedItem();
if($packet->addUserData){
$tile = $this->getLevel()->getTile($block);
if($tile instanceof Tile){

View File

@ -50,4 +50,8 @@ class Beetroot extends Crops{
ItemFactory::get(Item::BEETROOT_SEEDS, 0, 1)
];
}
public function getPickedItem() : Item{
return ItemFactory::get(Item::BEETROOT_SEEDS);
}
}

View File

@ -425,6 +425,14 @@ class Block extends Position implements BlockIds, Metadatable{
];
}
/**
* Returns the item that players will equip when middle-clicking on this block.
* @return Item
*/
public function getPickedItem() : Item{
return ItemFactory::get($this->getItemId(), $this->getVariant());
}
/**
* Returns the time in ticks which the block will fuel a furnace for.
* @return int

View File

@ -43,4 +43,8 @@ class Carrot extends Crops{
ItemFactory::get(Item::CARROT, 0, $this->meta >= 0x07 ? mt_rand(1, 4) : 1)
];
}
public function getPickedItem() : Item{
return ItemFactory::get(Item::CARROT);
}
}

View File

@ -88,4 +88,8 @@ class MelonStem extends Crops{
ItemFactory::get(Item::MELON_SEEDS, 0, mt_rand(0, 2))
];
}
public function getPickedItem() : Item{
return ItemFactory::get(Item::MELON_SEEDS);
}
}

View File

@ -43,4 +43,8 @@ class Potato extends Crops{
ItemFactory::get(Item::POTATO, 0, $this->getDamage() >= 0x07 ? mt_rand(1, 4) : 1)
];
}
public function getPickedItem() : Item{
return ItemFactory::get(Item::POTATO);
}
}

View File

@ -88,4 +88,8 @@ class PumpkinStem extends Crops{
ItemFactory::get(Item::PUMPKIN_SEEDS, 0, mt_rand(0, 2))
];
}
public function getPickedItem() : Item{
return ItemFactory::get(Item::PUMPKIN_SEEDS);
}
}

View File

@ -50,4 +50,8 @@ class Wheat extends Crops{
];
}
}
public function getPickedItem() : Item{
return ItemFactory::get(Item::WHEAT_SEEDS);
}
}