From c0962a47be1e65155ae7ac9a3f351f33914a232c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 12 Sep 2018 20:07:39 +0100 Subject: [PATCH] Block: Use parent::place() instead of setBlock() directly --- src/pocketmine/block/Anvil.php | 2 +- src/pocketmine/block/BaseRail.php | 2 +- src/pocketmine/block/Bed.php | 8 ++++---- src/pocketmine/block/Block.php | 2 +- src/pocketmine/block/BoneBlock.php | 2 +- src/pocketmine/block/BurningFurnace.php | 9 +++++---- src/pocketmine/block/Button.php | 3 +-- src/pocketmine/block/Cactus.php | 4 +--- src/pocketmine/block/Cake.php | 4 +--- src/pocketmine/block/Carpet.php | 4 +--- src/pocketmine/block/Chest.php | 15 +++++++++------ src/pocketmine/block/Crops.php | 4 +--- src/pocketmine/block/Dandelion.php | 4 +--- src/pocketmine/block/Door.php | 2 +- src/pocketmine/block/EnchantingTable.php | 9 +++++---- src/pocketmine/block/EndRod.php | 2 +- src/pocketmine/block/EnderChest.php | 8 +++++--- src/pocketmine/block/FenceGate.php | 3 +-- src/pocketmine/block/Flower.php | 4 +--- src/pocketmine/block/FlowerPot.php | 9 ++++++--- src/pocketmine/block/GlazedTerracotta.php | 3 ++- src/pocketmine/block/HayBale.php | 4 +--- src/pocketmine/block/ItemFrame.php | 8 +++++--- src/pocketmine/block/Ladder.php | 4 +--- src/pocketmine/block/Lava.php | 10 ---------- src/pocketmine/block/Leaves.php | 2 +- src/pocketmine/block/Lever.php | 2 +- src/pocketmine/block/NetherWartPlant.php | 4 +--- src/pocketmine/block/Quartz.php | 2 +- src/pocketmine/block/RedMushroom.php | 4 +--- src/pocketmine/block/Sapling.php | 4 +--- src/pocketmine/block/SignPost.php | 11 ++++++----- src/pocketmine/block/Skull.php | 8 +++++--- src/pocketmine/block/Slab.php | 3 +-- src/pocketmine/block/SnowLayer.php | 4 +--- src/pocketmine/block/Stair.php | 3 +-- src/pocketmine/block/StandingBanner.php | 10 ++++++---- src/pocketmine/block/Sugarcane.php | 8 ++------ src/pocketmine/block/TallGrass.php | 4 +--- src/pocketmine/block/Torch.php | 7 ++----- src/pocketmine/block/Trapdoor.php | 4 ++-- src/pocketmine/block/Vine.php | 3 +-- src/pocketmine/block/Water.php | 10 ---------- src/pocketmine/block/WaterLily.php | 3 +-- src/pocketmine/block/Wood.php | 2 +- 45 files changed, 93 insertions(+), 134 deletions(-) diff --git a/src/pocketmine/block/Anvil.php b/src/pocketmine/block/Anvil.php index 7279fc8c3..fb9019f96 100644 --- a/src/pocketmine/block/Anvil.php +++ b/src/pocketmine/block/Anvil.php @@ -97,6 +97,6 @@ class Anvil extends Fallable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $direction = $player !== null ? Bearing::rotate($player->getDirection(), -1) : 0; $this->meta = $this->getVariant() | $direction; - return $this->getLevel()->setBlock($blockReplace, $this, true, true); + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } } diff --git a/src/pocketmine/block/BaseRail.php b/src/pocketmine/block/BaseRail.php index 69f555d3c..bfcdf32ca 100644 --- a/src/pocketmine/block/BaseRail.php +++ b/src/pocketmine/block/BaseRail.php @@ -85,7 +85,7 @@ abstract class BaseRail extends Flowable{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - if(!$blockReplace->getSide(Facing::DOWN)->isTransparent() and $this->getLevel()->setBlock($blockReplace, $this, true, true)){ + if(!$blockReplace->getSide(Facing::DOWN)->isTransparent() and parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){ $this->tryReconnect(); return true; } diff --git a/src/pocketmine/block/Bed.php b/src/pocketmine/block/Bed.php index 229fbedad..525734547 100644 --- a/src/pocketmine/block/Bed.php +++ b/src/pocketmine/block/Bed.php @@ -152,11 +152,11 @@ class Bed extends Transparent{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $down = $this->getSide(Facing::DOWN); if(!$down->isTransparent()){ - $meta = $player instanceof Player ? Bearing::rotate($player->getDirection(), 2) : 0; //rotate 180 degrees - $next = $this->getSide(self::getOtherHalfSide($meta)); + $this->meta = $player instanceof Player ? Bearing::rotate($player->getDirection(), 2) : 0; //rotate 180 degrees + $next = $this->getSide(self::getOtherHalfSide($this->meta)); if($next->canBeReplaced() and !$next->getSide(Facing::DOWN)->isTransparent()){ - $this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->id, $meta), true, true); - $this->getLevel()->setBlock($next, BlockFactory::get($this->id, $meta | self::BITFLAG_HEAD), true, true); + parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); + $this->getLevel()->setBlock($next, BlockFactory::get($this->id, $this->meta | self::BITFLAG_HEAD), true, true); Tile::createTile(Tile::BED, $this->getLevel(), TileBed::createNBT($this, $face, $item, $player)); Tile::createTile(Tile::BED, $this->getLevel(), TileBed::createNBT($next, $face, $item, $player)); diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 023c92dd8..07215efa7 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -181,7 +181,7 @@ class Block extends Position implements BlockIds, Metadatable{ * @return bool */ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - return $this->getLevel()->setBlock($this, $this, true, true); + return $this->getLevel()->setBlock($blockReplace, $this, true, true); } /** diff --git a/src/pocketmine/block/BoneBlock.php b/src/pocketmine/block/BoneBlock.php index 696565fae..7d9efaceb 100644 --- a/src/pocketmine/block/BoneBlock.php +++ b/src/pocketmine/block/BoneBlock.php @@ -55,7 +55,7 @@ class BoneBlock extends Solid{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face); - return $this->getLevel()->setBlock($blockReplace, $this, true, true); + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function getVariantBitmask() : int{ diff --git a/src/pocketmine/block/BurningFurnace.php b/src/pocketmine/block/BurningFurnace.php index 98d0c135d..7440d0f28 100644 --- a/src/pocketmine/block/BurningFurnace.php +++ b/src/pocketmine/block/BurningFurnace.php @@ -65,11 +65,12 @@ class BurningFurnace extends Solid{ if($player !== null){ $this->meta = Bearing::toFacing($player->getDirection()); } - $this->getLevel()->setBlock($blockReplace, $this, true, true); + if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){ + Tile::createTile(Tile::FURNACE, $this->getLevel(), TileFurnace::createNBT($this, $face, $item, $player)); + return true; + } - Tile::createTile(Tile::FURNACE, $this->getLevel(), TileFurnace::createNBT($this, $face, $item, $player)); - - return true; + return false; } public function onActivate(Item $item, Player $player = null) : bool{ diff --git a/src/pocketmine/block/Button.php b/src/pocketmine/block/Button.php index 2745fdd58..d8b333e82 100644 --- a/src/pocketmine/block/Button.php +++ b/src/pocketmine/block/Button.php @@ -40,8 +40,7 @@ abstract class Button extends Flowable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ //TODO: check valid target block $this->meta = $face; - - return $this->level->setBlock($this, $this, true, true); + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function onActivate(Item $item, Player $player = null) : bool{ diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index 8964cd248..a8fdd1c3b 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -112,9 +112,7 @@ class Cactus extends Transparent{ $block2 = $this->getSide(Facing::WEST); $block3 = $this->getSide(Facing::EAST); if(!$block0->isSolid() and !$block1->isSolid() and !$block2->isSolid() and !$block3->isSolid()){ - $this->getLevel()->setBlock($this, $this, true); - - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } } diff --git a/src/pocketmine/block/Cake.php b/src/pocketmine/block/Cake.php index 83d2b61c1..dd31ec231 100644 --- a/src/pocketmine/block/Cake.php +++ b/src/pocketmine/block/Cake.php @@ -64,9 +64,7 @@ class Cake extends Transparent implements FoodSource{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $down = $this->getSide(Facing::DOWN); if($down->getId() !== self::AIR){ - $this->getLevel()->setBlock($blockReplace, $this, true, true); - - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } return false; diff --git a/src/pocketmine/block/Carpet.php b/src/pocketmine/block/Carpet.php index a3cbc8c55..a79dac092 100644 --- a/src/pocketmine/block/Carpet.php +++ b/src/pocketmine/block/Carpet.php @@ -57,9 +57,7 @@ class Carpet extends Flowable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $down = $this->getSide(Facing::DOWN); if($down->getId() !== self::AIR){ - $this->getLevel()->setBlock($blockReplace, $this, true, true); - - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } return false; diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index 2e1f1e91b..2ca3536ee 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -77,15 +77,18 @@ class Chest extends Transparent{ } } - $this->getLevel()->setBlock($blockReplace, $this, true, true); - $tile = Tile::createTile(Tile::CHEST, $this->getLevel(), TileChest::createNBT($this, $face, $item, $player)); + if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){ + $tile = Tile::createTile(Tile::CHEST, $this->getLevel(), TileChest::createNBT($this, $face, $item, $player)); - if($chest instanceof TileChest and $tile instanceof TileChest){ - $chest->pairWith($tile); - $tile->pairWith($chest); + if($chest instanceof TileChest and $tile instanceof TileChest){ + $chest->pairWith($tile); + $tile->pairWith($chest); + } + + return true; } - return true; + return false; } public function onActivate(Item $item, Player $player = null) : bool{ diff --git a/src/pocketmine/block/Crops.php b/src/pocketmine/block/Crops.php index 476c8d5ce..f92f94add 100644 --- a/src/pocketmine/block/Crops.php +++ b/src/pocketmine/block/Crops.php @@ -34,9 +34,7 @@ abstract class Crops extends Flowable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ if($blockReplace->getSide(Facing::DOWN)->getId() === Block::FARMLAND){ - $this->getLevel()->setBlock($blockReplace, $this, true, true); - - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } return false; diff --git a/src/pocketmine/block/Dandelion.php b/src/pocketmine/block/Dandelion.php index 443ba0811..474054e72 100644 --- a/src/pocketmine/block/Dandelion.php +++ b/src/pocketmine/block/Dandelion.php @@ -44,9 +44,7 @@ class Dandelion extends Flowable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $down = $this->getSide(Facing::DOWN); if($down->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){ - $this->getLevel()->setBlock($blockReplace, $this, true, true); - - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } return false; diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index c95947725..e5acf3708 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -138,7 +138,7 @@ abstract class Door extends Transparent{ } $this->setDamage(Bearing::rotate($player->getDirection(), -1)); - $this->getLevel()->setBlock($blockReplace, $this, true, true); //Bottom + parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); $this->getLevel()->setBlock($blockUp, BlockFactory::get($this->getId(), $metaUp), true); //Top return true; } diff --git a/src/pocketmine/block/EnchantingTable.php b/src/pocketmine/block/EnchantingTable.php index 5574677c4..f86616bee 100644 --- a/src/pocketmine/block/EnchantingTable.php +++ b/src/pocketmine/block/EnchantingTable.php @@ -40,11 +40,12 @@ class EnchantingTable extends Transparent{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $this->getLevel()->setBlock($blockReplace, $this, true, true); + if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){ + Tile::createTile(Tile::ENCHANT_TABLE, $this->getLevel(), TileEnchantTable::createNBT($this, $face, $item, $player)); + return true; + } - Tile::createTile(Tile::ENCHANT_TABLE, $this->getLevel(), TileEnchantTable::createNBT($this, $face, $item, $player)); - - return true; + return false; } public function getHardness() : float{ diff --git a/src/pocketmine/block/EndRod.php b/src/pocketmine/block/EndRod.php index e65270740..9aa157670 100644 --- a/src/pocketmine/block/EndRod.php +++ b/src/pocketmine/block/EndRod.php @@ -51,7 +51,7 @@ class EndRod extends Flowable{ $this->meta ^= 0x01; } - return $this->level->setBlock($blockReplace, $this, true, true); + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function isSolid() : bool{ diff --git a/src/pocketmine/block/EnderChest.php b/src/pocketmine/block/EnderChest.php index 015f90948..c619a3fef 100644 --- a/src/pocketmine/block/EnderChest.php +++ b/src/pocketmine/block/EnderChest.php @@ -66,10 +66,12 @@ class EnderChest extends Chest{ $this->meta = Bearing::toFacing($player->getDirection()); } - $this->getLevel()->setBlock($blockReplace, $this, true, true); - Tile::createTile(Tile::ENDER_CHEST, $this->getLevel(), TileEnderChest::createNBT($this, $face, $item, $player)); + if(Block::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){ + Tile::createTile(Tile::ENDER_CHEST, $this->getLevel(), TileEnderChest::createNBT($this, $face, $item, $player)); + return true; + } - return true; + return false; } public function onActivate(Item $item, Player $player = null) : bool{ diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index 1aacbbf84..5a1942f8d 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -72,9 +72,8 @@ class FenceGate extends Transparent{ if($player !== null){ $this->meta = Bearing::rotate($player->getDirection(), 2); } - $this->getLevel()->setBlock($blockReplace, $this, true, true); - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function getVariantBitmask() : int{ diff --git a/src/pocketmine/block/Flower.php b/src/pocketmine/block/Flower.php index ac7a063a8..d19bfa3a2 100644 --- a/src/pocketmine/block/Flower.php +++ b/src/pocketmine/block/Flower.php @@ -63,9 +63,7 @@ class Flower extends Flowable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $down = $this->getSide(Facing::DOWN); if($down->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){ - $this->getLevel()->setBlock($blockReplace, $this, true); - - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } return false; diff --git a/src/pocketmine/block/FlowerPot.php b/src/pocketmine/block/FlowerPot.php index 8dd7f9db2..8e50621cd 100644 --- a/src/pocketmine/block/FlowerPot.php +++ b/src/pocketmine/block/FlowerPot.php @@ -57,9 +57,12 @@ class FlowerPot extends Flowable{ return false; } - $this->getLevel()->setBlock($blockReplace, $this, true, true); - Tile::createTile(Tile::FLOWER_POT, $this->getLevel(), TileFlowerPot::createNBT($this, $face, $item, $player)); - return true; + if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){ + Tile::createTile(Tile::FLOWER_POT, $this->getLevel(), TileFlowerPot::createNBT($this, $face, $item, $player)); + return true; + } + + return false; } public function onNearbyBlockChange() : void{ diff --git a/src/pocketmine/block/GlazedTerracotta.php b/src/pocketmine/block/GlazedTerracotta.php index d4c3e3063..d8276666b 100644 --- a/src/pocketmine/block/GlazedTerracotta.php +++ b/src/pocketmine/block/GlazedTerracotta.php @@ -48,7 +48,8 @@ class GlazedTerracotta extends Solid{ if($player !== null){ $this->meta = Bearing::toFacing($player->getDirection()); } - return $this->getLevel()->setBlock($blockReplace, $this, true, true); + + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function getVariantBitmask() : int{ diff --git a/src/pocketmine/block/HayBale.php b/src/pocketmine/block/HayBale.php index 7dd2989da..112f9f788 100644 --- a/src/pocketmine/block/HayBale.php +++ b/src/pocketmine/block/HayBale.php @@ -46,9 +46,7 @@ class HayBale extends Solid{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face); - $this->getLevel()->setBlock($blockReplace, $this, true, true); - - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function getVariantBitmask() : int{ diff --git a/src/pocketmine/block/ItemFrame.php b/src/pocketmine/block/ItemFrame.php index e01fcc938..f744d05f3 100644 --- a/src/pocketmine/block/ItemFrame.php +++ b/src/pocketmine/block/ItemFrame.php @@ -83,11 +83,13 @@ class ItemFrame extends Flowable{ ]; $this->meta = $faces[$face]; - $this->level->setBlock($blockReplace, $this, true, true); - Tile::createTile(Tile::ITEM_FRAME, $this->getLevel(), TileItemFrame::createNBT($this, $face, $item, $player)); + if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){ + Tile::createTile(Tile::ITEM_FRAME, $this->getLevel(), TileItemFrame::createNBT($this, $face, $item, $player)); + return true; + } - return true; + return false; } diff --git a/src/pocketmine/block/Ladder.php b/src/pocketmine/block/Ladder.php index f1b73cf80..0fcbe8217 100644 --- a/src/pocketmine/block/Ladder.php +++ b/src/pocketmine/block/Ladder.php @@ -93,9 +93,7 @@ class Ladder extends Transparent{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ if(!$blockClicked->isTransparent() and Facing::axis($face) !== Facing::AXIS_Y){ $this->meta = $face; - $this->getLevel()->setBlock($blockReplace, $this, true, true); - - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } return false; diff --git a/src/pocketmine/block/Lava.php b/src/pocketmine/block/Lava.php index 057ad42f4..04ab07fae 100644 --- a/src/pocketmine/block/Lava.php +++ b/src/pocketmine/block/Lava.php @@ -27,10 +27,7 @@ use pocketmine\entity\Entity; use pocketmine\event\entity\EntityCombustByBlockEvent; use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\event\entity\EntityDamageEvent; -use pocketmine\item\Item; -use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; -use pocketmine\Player; use pocketmine\Server; class Lava extends Liquid{ @@ -114,11 +111,4 @@ class Lava extends Liquid{ $entity->resetFallDistance(); } - - public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $ret = $this->getLevel()->setBlock($this, $this, true, false); - $this->getLevel()->scheduleDelayedBlockUpdate($this, $this->tickRate()); - - return $ret; - } } diff --git a/src/pocketmine/block/Leaves.php b/src/pocketmine/block/Leaves.php index 212354682..7eea23052 100644 --- a/src/pocketmine/block/Leaves.php +++ b/src/pocketmine/block/Leaves.php @@ -160,7 +160,7 @@ class Leaves extends Transparent{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $this->meta |= 0x04; - return $this->getLevel()->setBlock($this, $this, true); + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function getVariantBitmask() : int{ diff --git a/src/pocketmine/block/Lever.php b/src/pocketmine/block/Lever.php index 7b622af4a..a57fc1c66 100644 --- a/src/pocketmine/block/Lever.php +++ b/src/pocketmine/block/Lever.php @@ -73,7 +73,7 @@ class Lever extends Flowable{ } } - return $this->level->setBlock($blockReplace, $this, true, true); + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function onNearbyBlockChange() : void{ diff --git a/src/pocketmine/block/NetherWartPlant.php b/src/pocketmine/block/NetherWartPlant.php index 9071ca29e..5c5e25694 100644 --- a/src/pocketmine/block/NetherWartPlant.php +++ b/src/pocketmine/block/NetherWartPlant.php @@ -47,9 +47,7 @@ class NetherWartPlant extends Flowable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $down = $this->getSide(Facing::DOWN); if($down->getId() === Block::SOUL_SAND){ - $this->getLevel()->setBlock($blockReplace, $this, false, true); - - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } return false; diff --git a/src/pocketmine/block/Quartz.php b/src/pocketmine/block/Quartz.php index e0813022c..dbda5ca3c 100644 --- a/src/pocketmine/block/Quartz.php +++ b/src/pocketmine/block/Quartz.php @@ -58,7 +58,7 @@ class Quartz extends Solid{ if($this->meta !== self::NORMAL){ $this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face); } - return $this->getLevel()->setBlock($blockReplace, $this, true, true); + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function getToolType() : int{ diff --git a/src/pocketmine/block/RedMushroom.php b/src/pocketmine/block/RedMushroom.php index d5f25a60b..6a4b9118f 100644 --- a/src/pocketmine/block/RedMushroom.php +++ b/src/pocketmine/block/RedMushroom.php @@ -53,9 +53,7 @@ class RedMushroom extends Flowable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $down = $this->getSide(Facing::DOWN); if(!$down->isTransparent()){ - $this->getLevel()->setBlock($blockReplace, $this, true, true); - - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } return false; diff --git a/src/pocketmine/block/Sapling.php b/src/pocketmine/block/Sapling.php index 5d6d51c0f..1573f6321 100644 --- a/src/pocketmine/block/Sapling.php +++ b/src/pocketmine/block/Sapling.php @@ -59,9 +59,7 @@ class Sapling extends Flowable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $down = $this->getSide(Facing::DOWN); if($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::FARMLAND){ - $this->getLevel()->setBlock($blockReplace, $this, true, true); - - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } return false; diff --git a/src/pocketmine/block/SignPost.php b/src/pocketmine/block/SignPost.php index c1b820f66..948c77ed1 100644 --- a/src/pocketmine/block/SignPost.php +++ b/src/pocketmine/block/SignPost.php @@ -63,15 +63,16 @@ class SignPost extends Transparent{ if($face === Facing::UP){ $this->meta = $player !== null ? (floor((($player->yaw + 180) * 16 / 360) + 0.5) & 0x0f) : 0; - $this->getLevel()->setBlock($blockReplace, $this, true); + $ret = parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); }else{ $this->meta = $face; - $this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::WALL_SIGN, $this->meta), true); + $ret = $this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::WALL_SIGN, $this->meta), true); } - Tile::createTile(Tile::SIGN, $this->getLevel(), TileSign::createNBT($this, $face, $item, $player)); - - return true; + if($ret){ + Tile::createTile(Tile::SIGN, $this->getLevel(), TileSign::createNBT($this, $face, $item, $player)); + return true; + } } return false; diff --git a/src/pocketmine/block/Skull.php b/src/pocketmine/block/Skull.php index 34c6077d7..fe7c63a1c 100644 --- a/src/pocketmine/block/Skull.php +++ b/src/pocketmine/block/Skull.php @@ -60,10 +60,12 @@ class Skull extends Flowable{ } $this->meta = $face; - $this->getLevel()->setBlock($blockReplace, $this, true); - Tile::createTile(Tile::SKULL, $this->getLevel(), TileSkull::createNBT($this, $face, $item, $player)); + if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){ + Tile::createTile(Tile::SKULL, $this->getLevel(), TileSkull::createNBT($this, $face, $item, $player)); + return true; + } - return true; + return false; } public function getDropsForCompatibleTool(Item $item) : array{ diff --git a/src/pocketmine/block/Slab.php b/src/pocketmine/block/Slab.php index 66bb2940f..96fec3e31 100644 --- a/src/pocketmine/block/Slab.php +++ b/src/pocketmine/block/Slab.php @@ -96,9 +96,8 @@ abstract class Slab extends Transparent{ if($blockReplace->getId() === $this->id and $blockClicked->getVariant() !== $this->getVariant()){ return false; } - $this->getLevel()->setBlock($blockReplace, $this, true, true); - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function getVariantBitmask() : int{ diff --git a/src/pocketmine/block/SnowLayer.php b/src/pocketmine/block/SnowLayer.php index b7c730b9d..9c4106f31 100644 --- a/src/pocketmine/block/SnowLayer.php +++ b/src/pocketmine/block/SnowLayer.php @@ -61,9 +61,7 @@ class SnowLayer extends Flowable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ if($blockReplace->getSide(Facing::DOWN)->isSolid()){ //TODO: fix placement - $this->getLevel()->setBlock($blockReplace, $this, true); - - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } return false; diff --git a/src/pocketmine/block/Stair.php b/src/pocketmine/block/Stair.php index a7a7a425a..db0bcdaa4 100644 --- a/src/pocketmine/block/Stair.php +++ b/src/pocketmine/block/Stair.php @@ -83,9 +83,8 @@ abstract class Stair extends Transparent{ if(($clickVector->y > 0.5 and $face !== Facing::UP) or $face === Facing::DOWN){ $this->meta |= 0x04; //Upside-down stairs } - $this->getLevel()->setBlock($blockReplace, $this, true, true); - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function getVariantBitmask() : int{ diff --git a/src/pocketmine/block/StandingBanner.php b/src/pocketmine/block/StandingBanner.php index 352bbd170..9d6675914 100644 --- a/src/pocketmine/block/StandingBanner.php +++ b/src/pocketmine/block/StandingBanner.php @@ -62,14 +62,16 @@ class StandingBanner extends Transparent{ if($face !== Facing::DOWN){ if($face === Facing::UP and $player !== null){ $this->meta = floor((($player->yaw + 180) * 16 / 360) + 0.5) & 0x0f; - $this->getLevel()->setBlock($blockReplace, $this, true); + $ret = parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); }else{ $this->meta = $face; - $this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::WALL_BANNER, $this->meta), true); + $ret = $this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::WALL_BANNER, $this->meta), true); } - Tile::createTile(Tile::BANNER, $this->getLevel(), TileBanner::createNBT($this, $face, $item, $player)); - return true; + if($ret){ + Tile::createTile(Tile::BANNER, $this->getLevel(), TileBanner::createNBT($this, $face, $item, $player)); + return true; + } } return false; diff --git a/src/pocketmine/block/Sugarcane.php b/src/pocketmine/block/Sugarcane.php index f2ddab721..69eda6814 100644 --- a/src/pocketmine/block/Sugarcane.php +++ b/src/pocketmine/block/Sugarcane.php @@ -102,18 +102,14 @@ class Sugarcane extends Flowable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $down = $this->getSide(Facing::DOWN); if($down->getId() === self::SUGARCANE_BLOCK){ - $this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::SUGARCANE_BLOCK), true); - - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); }elseif($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::SAND){ $block0 = $down->getSide(Facing::NORTH); $block1 = $down->getSide(Facing::SOUTH); $block2 = $down->getSide(Facing::WEST); $block3 = $down->getSide(Facing::EAST); if(($block0 instanceof Water) or ($block1 instanceof Water) or ($block2 instanceof Water) or ($block3 instanceof Water)){ - $this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::SUGARCANE_BLOCK), true); - - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } } diff --git a/src/pocketmine/block/TallGrass.php b/src/pocketmine/block/TallGrass.php index 310398f53..5d15a10e8 100644 --- a/src/pocketmine/block/TallGrass.php +++ b/src/pocketmine/block/TallGrass.php @@ -53,9 +53,7 @@ class TallGrass extends Flowable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $down = $this->getSide(Facing::DOWN); if($down->getId() === self::GRASS){ - $this->getLevel()->setBlock($blockReplace, $this, true); - - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } return false; diff --git a/src/pocketmine/block/Torch.php b/src/pocketmine/block/Torch.php index b553bfd8c..98473c92d 100644 --- a/src/pocketmine/block/Torch.php +++ b/src/pocketmine/block/Torch.php @@ -73,14 +73,11 @@ class Torch extends Flowable{ Facing::EAST => 1 ]; $this->meta = $faces[$face]; - $this->getLevel()->setBlock($blockReplace, $this, true, true); - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); }elseif(!$below->isTransparent() or $below->getId() === self::FENCE or $below->getId() === self::COBBLESTONE_WALL){ $this->meta = 0; - $this->getLevel()->setBlock($blockReplace, $this, true, true); - - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } return false; diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index 1d01dcd02..437ca730e 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -95,8 +95,8 @@ class Trapdoor extends Transparent{ if(($clickVector->y > 0.5 and $face !== Facing::UP) or $face === Facing::DOWN){ $this->meta |= self::MASK_UPPER; //top half of block } - $this->getLevel()->setBlock($blockReplace, $this, true, true); - return true; + + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function getVariantBitmask() : int{ diff --git a/src/pocketmine/block/Vine.php b/src/pocketmine/block/Vine.php index 72bc36fc5..b4adf98c6 100644 --- a/src/pocketmine/block/Vine.php +++ b/src/pocketmine/block/Vine.php @@ -141,8 +141,7 @@ class Vine extends Flowable{ $this->meta |= $blockReplace->meta; } - $this->getLevel()->setBlock($blockReplace, $this, true, true); - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function onNearbyBlockChange() : void{ diff --git a/src/pocketmine/block/Water.php b/src/pocketmine/block/Water.php index 00eeb3a9d..a4c96bdab 100644 --- a/src/pocketmine/block/Water.php +++ b/src/pocketmine/block/Water.php @@ -24,10 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\entity\Entity; -use pocketmine\item\Item; -use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; -use pocketmine\Player; class Water extends Liquid{ @@ -73,11 +70,4 @@ class Water extends Liquid{ $entity->resetFallDistance(); } - - public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $ret = $this->getLevel()->setBlock($this, $this, true, false); - $this->getLevel()->scheduleDelayedBlockUpdate($this, $this->tickRate()); - - return $ret; - } } diff --git a/src/pocketmine/block/WaterLily.php b/src/pocketmine/block/WaterLily.php index 59f999960..4260a8a3e 100644 --- a/src/pocketmine/block/WaterLily.php +++ b/src/pocketmine/block/WaterLily.php @@ -54,8 +54,7 @@ class WaterLily extends Flowable{ if($blockClicked instanceof Water){ $up = $blockClicked->getSide(Facing::UP); if($up->getId() === Block::AIR){ - $this->getLevel()->setBlock($up, $this, true, true); - return true; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } } diff --git a/src/pocketmine/block/Wood.php b/src/pocketmine/block/Wood.php index 2c309aed6..f50cdea3e 100644 --- a/src/pocketmine/block/Wood.php +++ b/src/pocketmine/block/Wood.php @@ -56,7 +56,7 @@ class Wood extends Solid{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face); - return $this->getLevel()->setBlock($blockReplace, $this, true, true); + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function getVariantBitmask() : int{