diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 25ad14a463..9c30f8ba07 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2587,7 +2587,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } $block = $target->getSide($packet->face); if($block->getId() === Block::FIRE){ - $this->level->setBlock($block, new Air()); + $this->level->setBlock($block, Block::get(Block::AIR)); break; } diff --git a/src/pocketmine/block/ActivatorRail.php b/src/pocketmine/block/ActivatorRail.php index 56e8a99792..ec7bf85d48 100644 --- a/src/pocketmine/block/ActivatorRail.php +++ b/src/pocketmine/block/ActivatorRail.php @@ -30,4 +30,6 @@ class ActivatorRail extends Rail{ public function getName() : string{ return "Activator Rail"; } + + //TODO } diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index a55700b541..5cd2cfd033 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -377,12 +377,7 @@ class Block extends Position implements BlockIds, Metadatable{ */ public static function get(int $id, int $meta = 0, Position $pos = null) : Block{ try{ - $block = self::$fullList[($id << 4) | $meta]; - if($block !== null){ - $block = clone $block; - }else{ - $block = new UnknownBlock($id, $meta); - } + $block = clone self::$fullList[($id << 4) | $meta]; }catch(\RuntimeException $e){ //TODO: this probably should return null (out of bounds IDs may cause unexpected behaviour) $block = new UnknownBlock($id, $meta); @@ -398,8 +393,9 @@ class Block extends Position implements BlockIds, Metadatable{ return $block; } - + /** @var int */ protected $id; + /** @var int */ protected $meta = 0; /** @var string */ protected $fallbackName; @@ -460,6 +456,19 @@ class Block extends Position implements BlockIds, Metadatable{ $this->meta = $meta & 0x0f; } + /** + * Bitmask to use to remove superfluous information from block meta when getting its item form or name. + * This defaults to -1 (don't remove any data). Used to remove rotation data and bitflags from block drops. + * + * If your block should not have any meta value when it's dropped as an item, override this to return 0 in + * descendent classes. + * + * @return int + */ + public function getVariantBitmask() : int{ + return -1; + } + /** * Places the Block, using block space and block target, and side. Returns if the block has been placed. * @@ -497,7 +506,7 @@ class Block extends Position implements BlockIds, Metadatable{ * @return bool */ public function onBreak(Item $item) : bool{ - return $this->getLevel()->setBlock($this, new Air(), true, true); + return $this->getLevel()->setBlock($this, Block::get(Block::AIR), true, true); } /** @@ -658,7 +667,7 @@ class Block extends Position implements BlockIds, Metadatable{ */ public function getDrops(Item $item) : array{ return [ - Item::get($this->getItemId(), $this->getDamage(), 1), + Item::get($this->getItemId(), $this->getDamage() & $this->getVariantBitmask(), 1), ]; } diff --git a/src/pocketmine/block/BrewingStand.php b/src/pocketmine/block/BrewingStand.php index 329f71d616..b0bc1f6a90 100644 --- a/src/pocketmine/block/BrewingStand.php +++ b/src/pocketmine/block/BrewingStand.php @@ -44,4 +44,10 @@ class BrewingStand extends Transparent{ public function getToolType() : int{ return Tool::TYPE_PICKAXE; } + + public function getVariantBitmask() : int{ + return 0; + } + + //TODO } \ No newline at end of file diff --git a/src/pocketmine/block/BrownMushroom.php b/src/pocketmine/block/BrownMushroom.php index ff03f18fd6..9a548843d6 100644 --- a/src/pocketmine/block/BrownMushroom.php +++ b/src/pocketmine/block/BrownMushroom.php @@ -67,7 +67,7 @@ class BrownMushroom extends Flowable{ return false; } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ return null; } diff --git a/src/pocketmine/block/BurningFurnace.php b/src/pocketmine/block/BurningFurnace.php index c4ac26b73b..0afd9924a1 100644 --- a/src/pocketmine/block/BurningFurnace.php +++ b/src/pocketmine/block/BurningFurnace.php @@ -118,11 +118,13 @@ class BurningFurnace extends Solid{ return true; } + public function getVariantBitmask() : int{ + return 0; + } + public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_WOODEN){ - return [ - Item::get($this->getItemId(), 0, 1) - ]; + return parent::getDrops($item); } return []; diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index a04f376652..957376b3aa 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -90,7 +90,7 @@ class Cactus extends Transparent{ for($y = 1; $y < 3; ++$y){ $b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z)); if($b->getId() === self::AIR){ - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Cactus())); + Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, Block::get(Block::CACTUS))); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($b, $ev->getNewState(), true); } @@ -125,9 +125,7 @@ class Cactus extends Transparent{ return false; } - public function getDrops(Item $item) : array{ - return [ - Item::get($this->getItemId(), 0, 1) - ]; + public function getVariantBitmask() : int{ + return 0; } } \ No newline at end of file diff --git a/src/pocketmine/block/Cake.php b/src/pocketmine/block/Cake.php index 64ba440df6..46149050da 100644 --- a/src/pocketmine/block/Cake.php +++ b/src/pocketmine/block/Cake.php @@ -76,7 +76,7 @@ class Cake extends Transparent implements FoodSource{ public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ //Replace with common break method - $this->getLevel()->setBlock($this, new Air(), true); + $this->getLevel()->setBlock($this, Block::get(Block::AIR), true); return Level::BLOCK_UPDATE_NORMAL; } @@ -114,7 +114,7 @@ class Cake extends Transparent implements FoodSource{ $clone = clone $this; $clone->meta++; if($clone->meta >= 0x06){ - $clone = new Air(); + $clone = Block::get(Block::AIR); } return $clone; } diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index cf92156fe4..fb0d2412b2 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -129,7 +129,7 @@ class Chest extends Transparent{ if($t instanceof TileChest){ $t->unpair(); } - $this->getLevel()->setBlock($this, new Air(), true, true); + $this->getLevel()->setBlock($this, Block::get(Block::AIR), true, true); return true; } @@ -169,10 +169,8 @@ class Chest extends Transparent{ return true; } - public function getDrops(Item $item) : array{ - return [ - Item::get($this->getItemId(), 0, 1) - ]; + public function getVariantBitmask() : int{ + return 0; } public function getFuelTime() : int{ diff --git a/src/pocketmine/block/CocoaBlock.php b/src/pocketmine/block/CocoaBlock.php index 74c349dd98..44804c0dc7 100644 --- a/src/pocketmine/block/CocoaBlock.php +++ b/src/pocketmine/block/CocoaBlock.php @@ -34,4 +34,6 @@ class CocoaBlock extends Solid{ public function getName() : string{ return "Cocoa Block"; } + + //TODO } diff --git a/src/pocketmine/block/DaylightSensor.php b/src/pocketmine/block/DaylightSensor.php index 14c41b1878..f3fa72b532 100644 --- a/src/pocketmine/block/DaylightSensor.php +++ b/src/pocketmine/block/DaylightSensor.php @@ -42,4 +42,6 @@ class DaylightSensor extends Transparent{ public function getFuelTime() : int{ return 300; } + + //TODO } diff --git a/src/pocketmine/block/DetectorRail.php b/src/pocketmine/block/DetectorRail.php index d221b7c947..367ed14c0e 100644 --- a/src/pocketmine/block/DetectorRail.php +++ b/src/pocketmine/block/DetectorRail.php @@ -30,4 +30,6 @@ class DetectorRail extends Rail{ public function getName() : string{ return "Detector Rail"; } + + //TODO } diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index fc02d773e4..7b13292b02 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -204,9 +204,9 @@ abstract class Door extends Transparent{ public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ //Replace with common break method - $this->getLevel()->setBlock($this, new Air(), false); + $this->getLevel()->setBlock($this, Block::get(Block::AIR), false); if($this->getSide(Vector3::SIDE_UP) instanceof Door){ - $this->getLevel()->setBlock($this->getSide(Vector3::SIDE_UP), new Air(), false); + $this->getLevel()->setBlock($this->getSide(Vector3::SIDE_UP), Block::get(Block::AIR), false); } return Level::BLOCK_UPDATE_NORMAL; @@ -250,15 +250,15 @@ abstract class Door extends Transparent{ if(($this->getDamage() & 0x08) === 0x08){ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === $this->getId()){ - $this->getLevel()->setBlock($down, new Air(), true); + $this->getLevel()->setBlock($down, Block::get(Block::AIR), true); } }else{ $up = $this->getSide(Vector3::SIDE_UP); if($up->getId() === $this->getId()){ - $this->getLevel()->setBlock($up, new Air(), true); + $this->getLevel()->setBlock($up, Block::get(Block::AIR), true); } } - $this->getLevel()->setBlock($this, new Air(), true); + $this->getLevel()->setBlock($this, Block::get(Block::AIR), true); return true; } @@ -282,4 +282,8 @@ abstract class Door extends Transparent{ return true; } + + public function getVariantBitmask() : int{ + return 0; + } } \ No newline at end of file diff --git a/src/pocketmine/block/DoublePlant.php b/src/pocketmine/block/DoublePlant.php index b66833781d..730ede9cb5 100644 --- a/src/pocketmine/block/DoublePlant.php +++ b/src/pocketmine/block/DoublePlant.php @@ -104,6 +104,10 @@ class DoublePlant extends Flowable{ return false; } + public function getVariantBitmask() : int{ + return 0x07; + } + public function getDrops(Item $item) : array{ if(!$item->isShears() and ($this->meta === 2 or $this->meta === 3)){ //grass or fern if(mt_rand(0, 24) === 0){ @@ -115,8 +119,6 @@ class DoublePlant extends Flowable{ return []; } - return [ - Item::get($this->getItemId(), $this->getDamage() & 0x07, 1) - ]; + return parent::getDrops($item); } } \ No newline at end of file diff --git a/src/pocketmine/block/EnchantingTable.php b/src/pocketmine/block/EnchantingTable.php index 9cd1af2f16..5566ca113c 100644 --- a/src/pocketmine/block/EnchantingTable.php +++ b/src/pocketmine/block/EnchantingTable.php @@ -92,9 +92,7 @@ class EnchantingTable extends Transparent{ public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_WOODEN){ - return [ - Item::get($this->getItemId(), 0, 1) - ]; + return parent::getDrops($item); } return []; diff --git a/src/pocketmine/block/EndRod.php b/src/pocketmine/block/EndRod.php index 664469211f..ded66fe889 100644 --- a/src/pocketmine/block/EndRod.php +++ b/src/pocketmine/block/EndRod.php @@ -19,8 +19,9 @@ * */ -namespace pocketmine\block; +declare(strict_types=1); +namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; @@ -97,10 +98,7 @@ class EndRod extends Flowable{ return null; } - public function getDrops(Item $item) : array{ - return [ - Item::get($this->getId(), 0, 1) - ]; + public function getVariantBitmask() : int{ + return 0; } - } \ No newline at end of file diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index e417da24ab..1c1d23e9a5 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -75,10 +75,8 @@ class FenceGate extends Transparent{ return true; } - public function getDrops(Item $item) : array{ - return [ - Item::get($this->getItemId(), 0, 1) - ]; + public function getVariantBitmask() : int{ + return 0; } public function onActivate(Item $item, Player $player = null) : bool{ diff --git a/src/pocketmine/block/Fire.php b/src/pocketmine/block/Fire.php index 7568a9264d..e0825d65ac 100644 --- a/src/pocketmine/block/Fire.php +++ b/src/pocketmine/block/Fire.php @@ -87,14 +87,14 @@ class Fire extends Flowable{ return false; } } - $this->getLevel()->setBlock($this, new Air(), true); + $this->getLevel()->setBlock($this, Block::get(Block::AIR), true); return Level::BLOCK_UPDATE_NORMAL; }elseif($type === Level::BLOCK_UPDATE_RANDOM){ if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::NETHERRACK){ if(mt_rand(0, 2) === 0){ if($this->meta === 0x0F){ - $this->level->setBlock($this, new Air()); + $this->level->setBlock($this, Block::get(Block::AIR)); }else{ $this->meta++; $this->level->setBlock($this, $this); diff --git a/src/pocketmine/block/GlazedTerracotta.php b/src/pocketmine/block/GlazedTerracotta.php index d707c38e3a..4d6638865a 100644 --- a/src/pocketmine/block/GlazedTerracotta.php +++ b/src/pocketmine/block/GlazedTerracotta.php @@ -52,11 +52,13 @@ class GlazedTerracotta extends Solid{ return $this->getLevel()->setBlock($block, $this, true, true); } + public function getVariantBitmask() : int{ + return 0; + } + public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_WOODEN){ - return [ - Item::get($this->getItemId(), 0, 1) - ]; + return parent::getDrops($item); } return []; diff --git a/src/pocketmine/block/Grass.php b/src/pocketmine/block/Grass.php index 204d4ea502..fd46b6a227 100644 --- a/src/pocketmine/block/Grass.php +++ b/src/pocketmine/block/Grass.php @@ -105,12 +105,12 @@ class Grass extends Solid{ return true; }elseif($item->isHoe()){ $item->useOn($this); - $this->getLevel()->setBlock($this, new Farmland()); + $this->getLevel()->setBlock($this, Block::get(Block::FARMLAND)); return true; }elseif($item->isShovel() and $this->getSide(Vector3::SIDE_UP)->getId() === Block::AIR){ $item->useOn($this); - $this->getLevel()->setBlock($this, new GrassPath()); + $this->getLevel()->setBlock($this, Block::get(Block::GRASS_PATH)); return true; } diff --git a/src/pocketmine/block/Gravel.php b/src/pocketmine/block/Gravel.php index 7fc70070c3..1355298b36 100644 --- a/src/pocketmine/block/Gravel.php +++ b/src/pocketmine/block/Gravel.php @@ -53,9 +53,7 @@ class Gravel extends Fallable{ ]; } - return [ - Item::get(Item::GRAVEL, 0, 1) - ]; + return parent::getDrops($item); } } \ No newline at end of file diff --git a/src/pocketmine/block/HayBale.php b/src/pocketmine/block/HayBale.php index fca892481b..7acf1afd9a 100644 --- a/src/pocketmine/block/HayBale.php +++ b/src/pocketmine/block/HayBale.php @@ -58,10 +58,7 @@ class HayBale extends Solid{ return true; } - public function getDrops(Item $item) : array{ - return [ - Item::get($this->getItemId(), 0, 1) - ]; + public function getVariantBitmask() : int{ + return 0x03; } - } \ No newline at end of file diff --git a/src/pocketmine/block/Ice.php b/src/pocketmine/block/Ice.php index 3b65092099..0c5c1a664d 100644 --- a/src/pocketmine/block/Ice.php +++ b/src/pocketmine/block/Ice.php @@ -52,7 +52,7 @@ class Ice extends Transparent{ } public function onBreak(Item $item) : bool{ - $this->getLevel()->setBlock($this, new Water(), true); + $this->getLevel()->setBlock($this, Block::get(Block::WATER), true); return true; } diff --git a/src/pocketmine/block/IronBars.php b/src/pocketmine/block/IronBars.php index 2c8d1bbf02..748d58f09c 100644 --- a/src/pocketmine/block/IronBars.php +++ b/src/pocketmine/block/IronBars.php @@ -46,11 +46,13 @@ class IronBars extends Thin{ return Tool::TYPE_PICKAXE; } + public function getVariantBitmask() : int{ + return 0; + } + public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_WOODEN){ - return [ - Item::get($this->getItemId(), 0, 1) - ]; + return parent::getDrops($item); } return []; diff --git a/src/pocketmine/block/ItemFrame.php b/src/pocketmine/block/ItemFrame.php index f57390616b..95a65855f7 100644 --- a/src/pocketmine/block/ItemFrame.php +++ b/src/pocketmine/block/ItemFrame.php @@ -139,10 +139,7 @@ class ItemFrame extends Flowable{ } - public function getDrops(Item $item) : array{ - return [ - Item::get($this->getItemId(), 0, 1) - ]; + public function getVariantBitmask() : int{ + return 0; } - } \ No newline at end of file diff --git a/src/pocketmine/block/Ladder.php b/src/pocketmine/block/Ladder.php index b73293fd6e..471ca6fb9b 100644 --- a/src/pocketmine/block/Ladder.php +++ b/src/pocketmine/block/Ladder.php @@ -149,9 +149,7 @@ class Ladder extends Transparent{ return Tool::TYPE_AXE; } - public function getDrops(Item $item) : array{ - return [ - Item::get($this->getItemId(), 0, 1) - ]; + public function getVariantBitmask() : int{ + return 0; } } \ No newline at end of file diff --git a/src/pocketmine/block/Liquid.php b/src/pocketmine/block/Liquid.php index a4cd8a23c9..254196938f 100644 --- a/src/pocketmine/block/Liquid.php +++ b/src/pocketmine/block/Liquid.php @@ -241,7 +241,7 @@ abstract class Liquid extends Transparent{ if($k !== $decay){ $decay = $k; if($decay < 0){ - $this->getLevel()->setBlock($this, new Air(), true, true); + $this->getLevel()->setBlock($this, Block::get(Block::AIR), true, true); }else{ $this->getLevel()->setBlock($this, Block::get($this->id, $decay), true, true); $this->getLevel()->scheduleDelayedBlockUpdate($this, $this->tickRate()); @@ -442,7 +442,7 @@ abstract class Liquid extends Transparent{ } } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ return null; } diff --git a/src/pocketmine/block/MelonStem.php b/src/pocketmine/block/MelonStem.php index 067582cbd2..99b87f0778 100644 --- a/src/pocketmine/block/MelonStem.php +++ b/src/pocketmine/block/MelonStem.php @@ -68,7 +68,7 @@ class MelonStem extends Crops{ $side = $this->getSide(mt_rand(2, 5)); $d = $side->getSide(Vector3::SIDE_DOWN); if($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)){ - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, new Melon())); + Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, Block::get(Block::MELON_BLOCK))); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($side, $ev->getNewState(), true); } diff --git a/src/pocketmine/block/MossyCobblestone.php b/src/pocketmine/block/MossyCobblestone.php index e6e0f95ba2..d0a1c04d79 100644 --- a/src/pocketmine/block/MossyCobblestone.php +++ b/src/pocketmine/block/MossyCobblestone.php @@ -23,8 +23,6 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\item\Item; -use pocketmine\item\Tool; class MossyCobblestone extends Cobblestone{ diff --git a/src/pocketmine/block/Mycelium.php b/src/pocketmine/block/Mycelium.php index 90a41dd5d1..ff14961a0a 100644 --- a/src/pocketmine/block/Mycelium.php +++ b/src/pocketmine/block/Mycelium.php @@ -65,7 +65,7 @@ class Mycelium extends Solid{ $block = $this->getLevel()->getBlock(new Vector3($x, $y, $z)); if($block->getId() === Block::DIRT){ if($block->getSide(Vector3::SIDE_UP) instanceof Transparent){ - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, new Mycelium())); + Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, Block::get(Block::MYCELIUM))); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($block, $ev->getNewState()); } diff --git a/src/pocketmine/block/NetherBrickStairs.php b/src/pocketmine/block/NetherBrickStairs.php index a912d95a50..67f380cc70 100644 --- a/src/pocketmine/block/NetherBrickStairs.php +++ b/src/pocketmine/block/NetherBrickStairs.php @@ -29,6 +29,10 @@ class NetherBrickStairs extends Stair{ protected $id = self::NETHER_BRICK_STAIRS; + public function __construct(int $meta = 0){ + $this->meta = $meta; + } + public function getName() : string{ return "Nether Brick Stairs"; } @@ -41,8 +45,4 @@ class NetherBrickStairs extends Stair{ return Tool::TYPE_PICKAXE; } - public function __construct(int $meta = 0){ - $this->meta = $meta; - } - } \ No newline at end of file diff --git a/src/pocketmine/block/Prismarine.php b/src/pocketmine/block/Prismarine.php index 1443aa2441..d7b7f7aec3 100644 --- a/src/pocketmine/block/Prismarine.php +++ b/src/pocketmine/block/Prismarine.php @@ -55,11 +55,13 @@ class Prismarine extends Solid{ return Tool::TYPE_PICKAXE; } + public function getVariantBitmask() : int{ + return 0x03; + } + public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_WOODEN){ - return [ - Item::get($this->getItemId(), $this->getDamage() & 0x03, 1) - ]; + return parent::getDrops($item); } return []; diff --git a/src/pocketmine/block/Pumpkin.php b/src/pocketmine/block/Pumpkin.php index 882089ae70..b2501c3128 100644 --- a/src/pocketmine/block/Pumpkin.php +++ b/src/pocketmine/block/Pumpkin.php @@ -56,4 +56,7 @@ class Pumpkin extends Solid{ return true; } + public function getVariantBitmask() : int{ + return 0; + } } \ No newline at end of file diff --git a/src/pocketmine/block/PumpkinStem.php b/src/pocketmine/block/PumpkinStem.php index b2b3b799ff..89a22dcbc7 100644 --- a/src/pocketmine/block/PumpkinStem.php +++ b/src/pocketmine/block/PumpkinStem.php @@ -68,7 +68,7 @@ class PumpkinStem extends Crops{ $side = $this->getSide(mt_rand(2, 5)); $d = $side->getSide(Vector3::SIDE_DOWN); if($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)){ - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, new Pumpkin())); + Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, Block::get(Block::PUMPKIN))); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($side, $ev->getNewState(), true); } diff --git a/src/pocketmine/block/Quartz.php b/src/pocketmine/block/Quartz.php index 4fa8115f3e..5bd4a8733d 100644 --- a/src/pocketmine/block/Quartz.php +++ b/src/pocketmine/block/Quartz.php @@ -57,11 +57,13 @@ class Quartz extends Solid{ return Tool::TYPE_PICKAXE; } + public function getVariantBitmask() : int{ + return 0x03; + } + public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_WOODEN){ - return [ - Item::get($this->getItemId(), $this->getDamage() & 0x03, 1) - ]; + return parent::getDrops($item); } return []; diff --git a/src/pocketmine/block/Rail.php b/src/pocketmine/block/Rail.php index 041be4a595..7cbf77326e 100644 --- a/src/pocketmine/block/Rail.php +++ b/src/pocketmine/block/Rail.php @@ -75,4 +75,8 @@ class Rail extends Flowable{ return false; } + + public function getVariantBitmask() : int{ + return 0; + } } diff --git a/src/pocketmine/block/Sandstone.php b/src/pocketmine/block/Sandstone.php index a9def36c6e..a178e8a3d1 100644 --- a/src/pocketmine/block/Sandstone.php +++ b/src/pocketmine/block/Sandstone.php @@ -55,11 +55,13 @@ class Sandstone extends Solid{ return Tool::TYPE_PICKAXE; } + public function getVariantBitmask() : int{ + return 0x03; + } + public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_WOODEN){ - return [ - Item::get($this->getItemId(), $this->getDamage() & 0x03, 1) - ]; + return parent::getDrops($item); } return []; diff --git a/src/pocketmine/block/SignPost.php b/src/pocketmine/block/SignPost.php index 13f66f6617..e8db4799f4 100644 --- a/src/pocketmine/block/SignPost.php +++ b/src/pocketmine/block/SignPost.php @@ -55,7 +55,7 @@ class SignPost extends Transparent{ return "Sign Post"; } - public function getBoundingBox(){ + protected function recalculateBoundingBox(){ return null; } @@ -114,4 +114,8 @@ class SignPost extends Transparent{ public function getToolType() : int{ return Tool::TYPE_AXE; } + + public function getVariantBitmask() : int{ + return 0; + } } \ No newline at end of file diff --git a/src/pocketmine/block/StainedGlass.php b/src/pocketmine/block/StainedGlass.php index 26ff1fbaa5..2bf2914069 100644 --- a/src/pocketmine/block/StainedGlass.php +++ b/src/pocketmine/block/StainedGlass.php @@ -24,16 +24,11 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\ColorBlockMetaHelper; -use pocketmine\item\Item; class StainedGlass extends Glass{ protected $id = self::STAINED_GLASS; - public function __construct(int $meta = 0){ - $this->meta = $meta; - } - public function getName() : string{ return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Stained Glass"; } diff --git a/src/pocketmine/block/StainedGlassPane.php b/src/pocketmine/block/StainedGlassPane.php index a1bf6d4e59..1a7a3daa3e 100644 --- a/src/pocketmine/block/StainedGlassPane.php +++ b/src/pocketmine/block/StainedGlassPane.php @@ -24,16 +24,11 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\ColorBlockMetaHelper; -use pocketmine\item\Item; class StainedGlassPane extends GlassPane{ protected $id = self::STAINED_GLASS_PANE; - public function __construct(int $meta = 0){ - $this->meta = $meta; - } - public function getName() : string{ return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Stained Glass Pane"; } diff --git a/src/pocketmine/block/Stair.php b/src/pocketmine/block/Stair.php index 1e65c356b5..e7991909c0 100644 --- a/src/pocketmine/block/Stair.php +++ b/src/pocketmine/block/Stair.php @@ -145,11 +145,13 @@ abstract class Stair extends Transparent{ return true; } + public function getVariantBitmask() : int{ + return 0; + } + public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_WOODEN){ - return [ - Item::get($this->getItemId(), 0, 1) - ]; + return parent::getDrops($item); } return []; diff --git a/src/pocketmine/block/StoneBricks.php b/src/pocketmine/block/StoneBricks.php index de33f72d8e..0645c517b9 100644 --- a/src/pocketmine/block/StoneBricks.php +++ b/src/pocketmine/block/StoneBricks.php @@ -58,9 +58,7 @@ class StoneBricks extends Solid{ public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_WOODEN){ - return [ - Item::get($this->getItemId(), $this->getDamage() & 0x03, 1) - ]; + return parent::getDrops($item); } return []; diff --git a/src/pocketmine/block/StoneButton.php b/src/pocketmine/block/StoneButton.php index 616d416bda..6f1c51a804 100644 --- a/src/pocketmine/block/StoneButton.php +++ b/src/pocketmine/block/StoneButton.php @@ -38,4 +38,8 @@ class StoneButton extends Flowable{ public function getHardness() : float{ return 0.5; } + + public function getVariantBitmask() : int{ + return 0; + } } diff --git a/src/pocketmine/block/StonePressurePlate.php b/src/pocketmine/block/StonePressurePlate.php index b6f1e672b7..cafa7303d2 100644 --- a/src/pocketmine/block/StonePressurePlate.php +++ b/src/pocketmine/block/StonePressurePlate.php @@ -42,4 +42,8 @@ class StonePressurePlate extends Transparent{ public function getHardness() : float{ return 0.5; } + + public function getVariantBitmask() : int{ + return 0; + } } diff --git a/src/pocketmine/block/Sugarcane.php b/src/pocketmine/block/Sugarcane.php index d054291131..c18c6e74b9 100644 --- a/src/pocketmine/block/Sugarcane.php +++ b/src/pocketmine/block/Sugarcane.php @@ -50,7 +50,7 @@ class Sugarcane extends Flowable{ for($y = 1; $y < 3; ++$y){ $b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z)); if($b->getId() === self::AIR){ - Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Sugarcane())); + Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, Block::get(Block::SUGARCANE_BLOCK))); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($b, $ev->getNewState(), true); } @@ -84,7 +84,7 @@ class Sugarcane extends Flowable{ for($y = 1; $y < 3; ++$y){ $b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z)); if($b->getId() === self::AIR){ - $this->getLevel()->setBlock($b, new Sugarcane(), true); + $this->getLevel()->setBlock($b, Block::get(Block::SUGARCANE_BLOCK), true); break; } } @@ -105,7 +105,7 @@ class Sugarcane extends Flowable{ public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === self::SUGARCANE_BLOCK){ - $this->getLevel()->setBlock($block, new Sugarcane(), true); + $this->getLevel()->setBlock($block, Block::get(Block::SUGARCANE_BLOCK), true); return true; }elseif($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::SAND){ @@ -114,7 +114,7 @@ class Sugarcane extends Flowable{ $block2 = $down->getSide(Vector3::SIDE_WEST); $block3 = $down->getSide(Vector3::SIDE_EAST); if(($block0 instanceof Water) or ($block1 instanceof Water) or ($block2 instanceof Water) or ($block3 instanceof Water)){ - $this->getLevel()->setBlock($block, new Sugarcane(), true); + $this->getLevel()->setBlock($block, Block::get(Block::SUGARCANE_BLOCK), true); return true; } @@ -122,4 +122,8 @@ class Sugarcane extends Flowable{ return false; } + + public function getVariantBitmask() : int{ + return 0; + } } \ No newline at end of file diff --git a/src/pocketmine/block/TNT.php b/src/pocketmine/block/TNT.php index ac7b849b29..25bcf24914 100644 --- a/src/pocketmine/block/TNT.php +++ b/src/pocketmine/block/TNT.php @@ -60,7 +60,7 @@ class TNT extends Solid{ } public function ignite(int $fuse = 80){ - $this->getLevel()->setBlock($this, new Air(), true); + $this->getLevel()->setBlock($this, Block::get(Block::AIR), true); $mot = (new Random())->nextSignedFloat() * M_PI * 2; $tnt = Entity::createEntity("PrimedTNT", $this->getLevel(), new CompoundTag("", [ diff --git a/src/pocketmine/block/TallGrass.php b/src/pocketmine/block/TallGrass.php index 723f351bc2..8c5a09219d 100644 --- a/src/pocketmine/block/TallGrass.php +++ b/src/pocketmine/block/TallGrass.php @@ -64,7 +64,7 @@ class TallGrass extends Flowable{ public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if($this->getSide(Vector3::SIDE_DOWN)->isTransparent() === true){ //Replace with common break method - $this->getLevel()->setBlock($this, new Air(), true, true); + $this->getLevel()->setBlock($this, Block::get(Block::AIR), true, true); return Level::BLOCK_UPDATE_NORMAL; } diff --git a/src/pocketmine/block/Torch.php b/src/pocketmine/block/Torch.php index 52fb3aafea..33b47d0825 100644 --- a/src/pocketmine/block/Torch.php +++ b/src/pocketmine/block/Torch.php @@ -93,9 +93,7 @@ class Torch extends Flowable{ return false; } - public function getDrops(Item $item) : array{ - return [ - Item::get($this->getItemId(), 0, 1) - ]; + public function getVariantBitmask() : int{ + return 0; } } \ No newline at end of file diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index 5b5f20abd8..613193ffa1 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -140,10 +140,8 @@ class Trapdoor extends Transparent{ return true; } - public function getDrops(Item $item) : array{ - return [ - Item::get($this->getItemId(), 0, 1) - ]; + public function getVariantBitmask() : int{ + return 0; } public function onActivate(Item $item, Player $player = null) : bool{ diff --git a/src/pocketmine/block/TripwireHook.php b/src/pocketmine/block/TripwireHook.php index 9a0017ae09..8bf328573a 100644 --- a/src/pocketmine/block/TripwireHook.php +++ b/src/pocketmine/block/TripwireHook.php @@ -34,4 +34,10 @@ class TripwireHook extends Flowable{ public function getName() : string{ return "Tripwire Hook"; } + + public function getVariantBitmask() : int{ + return 0; + } + + //TODO } diff --git a/src/pocketmine/block/Vine.php b/src/pocketmine/block/Vine.php index 18ae763b65..893bf80732 100644 --- a/src/pocketmine/block/Vine.php +++ b/src/pocketmine/block/Vine.php @@ -174,11 +174,13 @@ class Vine extends Transparent{ return false; } + public function getVariantBitmask() : int{ + return 0; + } + public function getDrops(Item $item) : array{ if($item->isShears()){ - return [ - Item::get($this->getItemId(), 0, 1) - ]; + return parent::getDrops($item); } return []; diff --git a/src/pocketmine/block/WaterLily.php b/src/pocketmine/block/WaterLily.php index cd47daf799..05cfa1b2bc 100644 --- a/src/pocketmine/block/WaterLily.php +++ b/src/pocketmine/block/WaterLily.php @@ -80,9 +80,7 @@ class WaterLily extends Flowable{ return false; } - public function getDrops(Item $item) : array{ - return [ - Item::get($this->getItemId(), 0, 1) - ]; + public function getVariantBitmask() : int{ + return 0; } } \ No newline at end of file diff --git a/src/pocketmine/block/WeightedPressurePlateLight.php b/src/pocketmine/block/WeightedPressurePlateLight.php index ac4e793ad6..cb43fcc9c0 100644 --- a/src/pocketmine/block/WeightedPressurePlateLight.php +++ b/src/pocketmine/block/WeightedPressurePlateLight.php @@ -42,4 +42,8 @@ class WeightedPressurePlateLight extends Transparent{ public function getHardness() : float{ return 0.5; } + + public function getVariantBitmask() : int{ + return 0; + } } diff --git a/src/pocketmine/block/Wood.php b/src/pocketmine/block/Wood.php index c2d6eb7f4b..2aa208bc90 100644 --- a/src/pocketmine/block/Wood.php +++ b/src/pocketmine/block/Wood.php @@ -69,10 +69,8 @@ class Wood extends Solid{ return true; } - public function getDrops(Item $item) : array{ - return [ - Item::get($this->getItemId(), $this->getDamage() & 0x03, 1) - ]; + public function getVariantBitmask() : int{ + return 0x03; } public function getToolType() : int{ diff --git a/src/pocketmine/block/WoodenDoor.php b/src/pocketmine/block/WoodenDoor.php index 8d946d4582..401e443dbe 100644 --- a/src/pocketmine/block/WoodenDoor.php +++ b/src/pocketmine/block/WoodenDoor.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\item\Item; use pocketmine\item\Tool; class WoodenDoor extends Door{ @@ -35,10 +34,4 @@ class WoodenDoor extends Door{ public function getToolType() : int{ return Tool::TYPE_AXE; } - - public function getDrops(Item $item) : array{ - return [ - Item::get($this->getItemId(), 0, 1) - ]; - } } \ No newline at end of file diff --git a/src/pocketmine/block/WoodenSlab.php b/src/pocketmine/block/WoodenSlab.php index 7fe17c5361..862cdd60fb 100644 --- a/src/pocketmine/block/WoodenSlab.php +++ b/src/pocketmine/block/WoodenSlab.php @@ -129,10 +129,8 @@ class WoodenSlab extends Transparent{ return Tool::TYPE_AXE; } - public function getDrops(Item $item) : array{ - return [ - Item::get($this->getItemId(), $this->getDamage() & 0x07, 1) - ]; + public function getVariantBitmask() : int{ + return 0x07; } public function getFuelTime() : int{ diff --git a/src/pocketmine/block/WoodenStairs.php b/src/pocketmine/block/WoodenStairs.php index 7fdd138efc..c14b20a542 100644 --- a/src/pocketmine/block/WoodenStairs.php +++ b/src/pocketmine/block/WoodenStairs.php @@ -41,8 +41,9 @@ class WoodenStairs extends Stair{ } public function getDrops(Item $item) : array{ + //TODO: Hierarchy problem (base class is for stone stairs) return [ - Item::get($this->getItemId(), 0, 1) + Item::get($this->getItemId(), $this->getDamage() & $this->getVariantBitmask(), 1) ]; } } \ No newline at end of file diff --git a/src/pocketmine/event/block/BlockBreakEvent.php b/src/pocketmine/event/block/BlockBreakEvent.php index 2fcf48394c..1b791e8d15 100644 --- a/src/pocketmine/event/block/BlockBreakEvent.php +++ b/src/pocketmine/event/block/BlockBreakEvent.php @@ -28,6 +28,9 @@ use pocketmine\event\Cancellable; use pocketmine\item\Item; use pocketmine\Player; +/** + * Called when a player destroys a block somewhere in the world. + */ class BlockBreakEvent extends BlockEvent implements Cancellable{ public static $handlerList = null; @@ -42,30 +45,56 @@ class BlockBreakEvent extends BlockEvent implements Cancellable{ /** @var Item[] */ protected $blockDrops = []; - public function __construct(Player $player, Block $block, Item $item, $instaBreak = false){ - $this->block = $block; + public function __construct(Player $player, Block $block, Item $item, bool $instaBreak = false){ + parent::__construct($block); $this->item = $item; $this->player = $player; - $this->instaBreak = (bool) $instaBreak; - $this->blockDrops = $player->isSurvival() ? $block->getDrops($item) : []; + + $this->instaBreak = $instaBreak; + + if($player->isSurvival()){ + $this->setDrops($block->getDrops($item)); + } } - public function getPlayer(){ + /** + * Returns the player who is destroying the block. + * @return Player + */ + public function getPlayer() : Player{ return $this->player; } - public function getItem(){ + /** + * Returns the item used to destroy the block. + * @return Item + */ + public function getItem() : Item{ return $this->item; } - public function getInstaBreak(){ + /** + * Returns whether the block may be broken in less than the amount of time calculated. This is usually true for + * creative players. + * + * @return bool + */ + public function getInstaBreak() : bool{ return $this->instaBreak; } + /** + * @param bool $instaBreak + */ + public function setInstaBreak(bool $instaBreak){ + $this->instaBreak = $instaBreak; + } + + /** * @return Item[] */ - public function getDrops(){ + public function getDrops() : array{ return $this->blockDrops; } @@ -73,13 +102,15 @@ class BlockBreakEvent extends BlockEvent implements Cancellable{ * @param Item[] $drops */ public function setDrops(array $drops){ - $this->blockDrops = $drops; + $this->setDropsVariadic(...$drops); } /** - * @param bool $instaBreak + * Variadic hack for easy array member type enforcement. + * + * @param Item[] ...$drops */ - public function setInstaBreak($instaBreak){ - $this->instaBreak = (bool) $instaBreak; + public function setDropsVariadic(Item ...$drops){ + $this->blockDrops = $drops; } } \ No newline at end of file diff --git a/src/pocketmine/event/block/BlockEvent.php b/src/pocketmine/event/block/BlockEvent.php index 6f6049c420..8aeb5d8092 100644 --- a/src/pocketmine/event/block/BlockEvent.php +++ b/src/pocketmine/event/block/BlockEvent.php @@ -43,7 +43,7 @@ abstract class BlockEvent extends Event{ /** * @return Block */ - public function getBlock(){ + public function getBlock() : Block{ return $this->block; } } \ No newline at end of file diff --git a/src/pocketmine/event/block/BlockGrowEvent.php b/src/pocketmine/event/block/BlockGrowEvent.php index 7957521737..24c3bc0455 100644 --- a/src/pocketmine/event/block/BlockGrowEvent.php +++ b/src/pocketmine/event/block/BlockGrowEvent.php @@ -26,6 +26,9 @@ namespace pocketmine\event\block; use pocketmine\block\Block; use pocketmine\event\Cancellable; +/** + * Called when plants or crops grow. + */ class BlockGrowEvent extends BlockEvent implements Cancellable{ public static $handlerList = null; @@ -40,7 +43,7 @@ class BlockGrowEvent extends BlockEvent implements Cancellable{ /** * @return Block */ - public function getNewState(){ + public function getNewState() : Block{ return $this->newState; } diff --git a/src/pocketmine/event/block/BlockPlaceEvent.php b/src/pocketmine/event/block/BlockPlaceEvent.php index 39346eb396..7d12d03cc0 100644 --- a/src/pocketmine/event/block/BlockPlaceEvent.php +++ b/src/pocketmine/event/block/BlockPlaceEvent.php @@ -40,36 +40,46 @@ class BlockPlaceEvent extends BlockEvent implements Cancellable{ /** @var Item */ protected $item; - + /** @var Block */ protected $blockReplace; + /** @var Block */ protected $blockAgainst; public function __construct(Player $player, Block $blockPlace, Block $blockReplace, Block $blockAgainst, Item $item){ - $this->block = $blockPlace; + parent::__construct($blockPlace); $this->blockReplace = $blockReplace; $this->blockAgainst = $blockAgainst; $this->item = $item; $this->player = $player; } - public function getPlayer(){ + /** + * Returns the player who is placing the block. + * @return Player + */ + public function getPlayer() : Player{ return $this->player; } /** * Gets the item in hand - * - * @return mixed + * @return Item */ - public function getItem(){ + public function getItem() : Item{ return $this->item; } - public function getBlockReplaced(){ + /** + * @return Block + */ + public function getBlockReplaced() : Block{ return $this->blockReplace; } - public function getBlockAgainst(){ + /** + * @return Block + */ + public function getBlockAgainst() : Block{ return $this->blockAgainst; } } \ No newline at end of file diff --git a/src/pocketmine/event/block/BlockSpreadEvent.php b/src/pocketmine/event/block/BlockSpreadEvent.php index 6065b2c281..10294d7877 100644 --- a/src/pocketmine/event/block/BlockSpreadEvent.php +++ b/src/pocketmine/event/block/BlockSpreadEvent.php @@ -25,6 +25,9 @@ namespace pocketmine\event\block; use pocketmine\block\Block; +/** + * Called when a block spreads to another block, such as grass spreading to nearby dirt blocks. + */ class BlockSpreadEvent extends BlockFormEvent{ public static $handlerList = null; @@ -39,7 +42,7 @@ class BlockSpreadEvent extends BlockFormEvent{ /** * @return Block */ - public function getSource(){ + public function getSource() : Block{ return $this->source; } diff --git a/src/pocketmine/event/block/LeavesDecayEvent.php b/src/pocketmine/event/block/LeavesDecayEvent.php index 0b10f17011..394ef41897 100644 --- a/src/pocketmine/event/block/LeavesDecayEvent.php +++ b/src/pocketmine/event/block/LeavesDecayEvent.php @@ -23,14 +23,12 @@ declare(strict_types=1); namespace pocketmine\event\block; -use pocketmine\block\Block; use pocketmine\event\Cancellable; +/** + * Called when leaves decay due to not being attached to wood. + */ class LeavesDecayEvent extends BlockEvent implements Cancellable{ public static $handlerList = null; - public function __construct(Block $block){ - parent::__construct($block); - } - } \ No newline at end of file diff --git a/src/pocketmine/event/block/SignChangeEvent.php b/src/pocketmine/event/block/SignChangeEvent.php index d9c45baa78..69643fccfe 100644 --- a/src/pocketmine/event/block/SignChangeEvent.php +++ b/src/pocketmine/event/block/SignChangeEvent.php @@ -52,14 +52,14 @@ class SignChangeEvent extends BlockEvent implements Cancellable{ /** * @return Player */ - public function getPlayer(){ + public function getPlayer() : Player{ return $this->player; } /** * @return string[] */ - public function getLines(){ + public function getLines() : array{ return $this->lines; } @@ -67,16 +67,21 @@ class SignChangeEvent extends BlockEvent implements Cancellable{ * @param int $index 0-3 * * @return string + * + * @throws \InvalidArgumentException if the index is out of bounds */ - public function getLine($index){ + public function getLine(int $index) : string{ if($index < 0 or $index > 3){ throw new \InvalidArgumentException("Index must be in the range 0-3!"); } + return $this->lines[$index]; } /** * @param string[] $lines + * + * @throws \InvalidArgumentException if there are more or less than 4 lines in the passed array */ public function setLines(array $lines){ if(count($lines) !== 4){ @@ -88,8 +93,10 @@ class SignChangeEvent extends BlockEvent implements Cancellable{ /** * @param int $index 0-3 * @param string $line + * + * @throws \InvalidArgumentException if the index is out of bounds */ - public function setLine($index, $line){ + public function setLine(int $index, string $line){ if($index < 0 or $index > 3){ throw new \InvalidArgumentException("Index must be in the range 0-3!"); } diff --git a/src/pocketmine/item/Bucket.php b/src/pocketmine/item/Bucket.php index 44b2c53827..070fc4992d 100644 --- a/src/pocketmine/item/Bucket.php +++ b/src/pocketmine/item/Bucket.php @@ -56,7 +56,7 @@ class Bucket extends Item{ $result->setDamage($target->getId()); $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result)); if(!$ev->isCancelled()){ - $player->getLevel()->setBlock($target, new Air(), true, true); + $player->getLevel()->setBlock($target, Block::get(Block::AIR), true, true); if($player->isSurvival()){ $player->getInventory()->setItemInHand($ev->getItem()); } diff --git a/src/pocketmine/item/FlintSteel.php b/src/pocketmine/item/FlintSteel.php index cfb1d24c79..6cd5d47823 100644 --- a/src/pocketmine/item/FlintSteel.php +++ b/src/pocketmine/item/FlintSteel.php @@ -36,7 +36,7 @@ class FlintSteel extends Tool{ public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($block->getId() === self::AIR and ($target instanceof Solid)){ - $level->setBlock($block, new Fire(), true); + $level->setBlock($block, Block::get(Block::FIRE), true); if(($player->gamemode & 0x01) === 0 and $this->useOn($block)){ if($this->getDamage() >= $this->getMaxDurability()){ $player->getInventory()->setItemInHand(new Item(Item::AIR, 0, 0)); diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 06c98de712..99a799fddd 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1652,7 +1652,7 @@ class Level implements ChunkManager, Metadatable{ $above = $this->getBlock(new Vector3($target->x, $target->y + 1, $target->z)); if($above !== null){ if($above->getId() === Item::FIRE){ - $this->setBlock($above, new Air(), true); + $this->setBlock($above, Block::get(Block::AIR), true); } } diff --git a/src/pocketmine/level/generator/Flat.php b/src/pocketmine/level/generator/Flat.php index f81bac425b..f907825229 100644 --- a/src/pocketmine/level/generator/Flat.php +++ b/src/pocketmine/level/generator/Flat.php @@ -23,17 +23,11 @@ declare(strict_types=1); namespace pocketmine\level\generator; -use pocketmine\block\CoalOre; -use pocketmine\block\DiamondOre; -use pocketmine\block\Dirt; -use pocketmine\block\GoldOre; -use pocketmine\block\Gravel; -use pocketmine\block\IronOre; -use pocketmine\block\LapisOre; -use pocketmine\block\RedstoneOre; +use pocketmine\block\Block; use pocketmine\item\Item; use pocketmine\level\ChunkManager; use pocketmine\level\format\Chunk; +use pocketmine\level\generator\object\OreType; use pocketmine\level\generator\populator\Ore; use pocketmine\level\generator\populator\Populator; use pocketmine\math\Vector3; @@ -67,14 +61,14 @@ class Flat extends Generator{ if(isset($this->options["decoration"])){ $ores = new Ore(); $ores->setOreTypes([ - new object\OreType(new CoalOre(), 20, 16, 0, 128), - new object\OreType(new IronOre(), 20, 8, 0, 64), - new object\OreType(new RedstoneOre(), 8, 7, 0, 16), - new object\OreType(new LapisOre(), 1, 6, 0, 32), - new object\OreType(new GoldOre(), 2, 8, 0, 32), - new object\OreType(new DiamondOre(), 1, 7, 0, 16), - new object\OreType(new Dirt(), 20, 32, 0, 128), - new object\OreType(new Gravel(), 10, 16, 0, 128) + new OreType(Block::get(Block::COAL_ORE), 20, 16, 0, 128), + new OreType(Block::get(Block::IRON_ORE), 20, 8, 0, 64), + new OreType(Block::get(Block::REDSTONE_ORE), 8, 7, 0, 16), + new OreType(Block::get(Block::LAPIS_ORE), 1, 6, 0, 32), + new OreType(Block::get(Block::GOLD_ORE), 2, 8, 0, 32), + new OreType(Block::get(Block::DIAMOND_ORE), 1, 7, 0, 16), + new OreType(Block::get(Block::DIRT), 20, 32, 0, 128), + new OreType(Block::get(Block::GRAVEL), 10, 16, 0, 128) ]); $this->populators[] = $ores; } diff --git a/src/pocketmine/level/generator/normal/Normal.php b/src/pocketmine/level/generator/normal/Normal.php index 6e940a207f..84971bbd69 100644 --- a/src/pocketmine/level/generator/normal/Normal.php +++ b/src/pocketmine/level/generator/normal/Normal.php @@ -24,14 +24,6 @@ declare(strict_types=1); namespace pocketmine\level\generator\normal; use pocketmine\block\Block; -use pocketmine\block\CoalOre; -use pocketmine\block\DiamondOre; -use pocketmine\block\Dirt; -use pocketmine\block\GoldOre; -use pocketmine\block\Gravel; -use pocketmine\block\IronOre; -use pocketmine\block\LapisOre; -use pocketmine\block\RedstoneOre; use pocketmine\level\ChunkManager; use pocketmine\level\generator\biome\Biome; use pocketmine\level\generator\biome\BiomeSelector; @@ -179,14 +171,14 @@ class Normal extends Generator{ $ores = new Ore(); $ores->setOreTypes([ - new OreType(new CoalOre(), 20, 16, 0, 128), - new OreType(New IronOre(), 20, 8, 0, 64), - new OreType(new RedstoneOre(), 8, 7, 0, 16), - new OreType(new LapisOre(), 1, 6, 0, 32), - new OreType(new GoldOre(), 2, 8, 0, 32), - new OreType(new DiamondOre(), 1, 7, 0, 16), - new OreType(new Dirt(), 20, 32, 0, 128), - new OreType(new Gravel(), 10, 16, 0, 128) + new OreType(Block::get(Block::COAL_ORE), 20, 16, 0, 128), + new OreType(Block::get(Block::IRON_ORE), 20, 8, 0, 64), + new OreType(Block::get(Block::REDSTONE_ORE), 8, 7, 0, 16), + new OreType(Block::get(Block::LAPIS_ORE), 1, 6, 0, 32), + new OreType(Block::get(Block::GOLD_ORE), 2, 8, 0, 32), + new OreType(Block::get(Block::DIAMOND_ORE), 1, 7, 0, 16), + new OreType(Block::get(Block::DIRT), 20, 32, 0, 128), + new OreType(Block::get(Block::GRAVEL), 10, 16, 0, 128) ]); $this->populators[] = $ores; } diff --git a/src/pocketmine/level/generator/populator/Pond.php b/src/pocketmine/level/generator/populator/Pond.php index 9c1a2f88cb..d6ea804019 100644 --- a/src/pocketmine/level/generator/populator/Pond.php +++ b/src/pocketmine/level/generator/populator/Pond.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\level\generator\populator; +use pocketmine\block\Block; use pocketmine\block\Water; use pocketmine\level\ChunkManager; use pocketmine\math\Vector3; @@ -38,7 +39,7 @@ class Pond extends Populator{ $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 16); $y = $random->nextBoundedInt(128); $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16); - $pond = new \pocketmine\level\generator\object\Pond($random, new Water()); + $pond = new \pocketmine\level\generator\object\Pond($random, Block::get(Block::WATER)); if($pond->canPlaceObject($level, $v = new Vector3($x, $y, $z))){ $pond->placeObject($level, $v); } diff --git a/src/pocketmine/network/mcpe/protocol/ExplodePacket.php b/src/pocketmine/network/mcpe/protocol/ExplodePacket.php index 5b73ed624b..e7a27f211b 100644 --- a/src/pocketmine/network/mcpe/protocol/ExplodePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ExplodePacket.php @@ -61,7 +61,7 @@ class ExplodePacket extends DataPacket{ $this->putUnsignedVarInt(count($this->records)); if(count($this->records) > 0){ foreach($this->records as $record){ - $this->putSignedBlockPosition($record->x, $record->y, $record->z); + $this->putSignedBlockPosition((int) $record->x, (int) $record->y, (int) $record->z); } } } @@ -70,4 +70,4 @@ class ExplodePacket extends DataPacket{ return $session->handleExplode($this); } -} \ No newline at end of file +}