Fixed several Cake bugs

fixed cake flat-out doesn't work
fixed last slice of cake vanishing (NOOOOO)
fixed EntityEatBlockEvent not getting called
made AABB calculation less confusing
This commit is contained in:
Dylan K. Taylor 2017-09-03 13:08:27 +01:00
parent 58bf5d6679
commit bb9299070d

View File

@ -50,10 +50,10 @@ class Cake extends Transparent implements FoodSource{
protected function recalculateBoundingBox(){
$f = (1 + $this->getDamage() * 2) / 16;
$f = $this->getDamage() * 0.125; //1 slice width
return new AxisAlignedBB(
$this->x + $f,
$this->x + 0.0625 + $f,
$this->y,
$this->z + 0.0625,
$this->x + 1 - 0.0625,
@ -90,10 +90,17 @@ class Cake extends Transparent implements FoodSource{
}
public function onActivate(Item $item, Player $player = null) : bool{
if($player instanceof Player and $player->getHealth() < $player->getMaxHealth()){
$ev = new EntityEatBlockEvent($player, $this);
//TODO: refactor this into generic food handling
if($player instanceof Player and $player->getFood() < $player->getMaxFood()){
$player->getServer()->getPluginManager()->callEvent($ev = new EntityEatBlockEvent($player, $this));
if(!$ev->isCancelled()){
$player->addFood($ev->getFoodRestore());
$player->addSaturation($ev->getSaturationRestore());
foreach($ev->getAdditionalEffects() as $effect){
$player->addEffect($effect);
}
$this->getLevel()->setBlock($this, $ev->getResidue());
return true;
}
@ -113,7 +120,7 @@ class Cake extends Transparent implements FoodSource{
public function getResidue(){
$clone = clone $this;
$clone->meta++;
if($clone->meta >= 0x06){
if($clone->meta > 0x06){
$clone = BlockFactory::get(Block::AIR);
}
return $clone;