From f73d3d086ed671de65f144f90fa0cb895e4aebcb Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 18 Aug 2017 13:58:05 +0100 Subject: [PATCH] Added some new blocks, fixed collisions not being detected when standing on top of a full block --- src/pocketmine/block/Block.php | 10 ++-- src/pocketmine/block/Magma.php | 75 ++++++++++++++++++++++++ src/pocketmine/block/NetherBrick.php | 10 ---- src/pocketmine/block/NetherQuartzOre.php | 59 +++++++++++++++++++ src/pocketmine/block/NetherWartBlock.php | 41 +++++++++++++ src/pocketmine/entity/Entity.php | 13 ++-- 6 files changed, 187 insertions(+), 21 deletions(-) create mode 100644 src/pocketmine/block/Magma.php create mode 100644 src/pocketmine/block/NetherQuartzOre.php create mode 100644 src/pocketmine/block/NetherWartBlock.php diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 3bbffeedf..6f4bfd5f3 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -188,7 +188,7 @@ class Block extends Position implements BlockIds, Metadatable{ self::registerBlock(new StoneBrickStairs()); self::registerBlock(new Mycelium()); self::registerBlock(new WaterLily()); - self::registerBlock(new NetherBrick()); + self::registerBlock(new NetherBrick(Block::NETHER_BRICK_BLOCK, 0, "Nether Bricks")); self::registerBlock(new NetherBrickFence()); self::registerBlock(new NetherBrickStairs()); self::registerBlock(new NetherWartPlant()); @@ -229,7 +229,7 @@ class Block extends Position implements BlockIds, Metadatable{ //TODO: POWERED_COMPARATOR self::registerBlock(new DaylightSensor()); self::registerBlock(new Redstone()); - //TODO: NETHER_QUARTZ_ORE + self::registerBlock(new NetherQuartzOre()); //TODO: HOPPER_BLOCK self::registerBlock(new Quartz()); self::registerBlock(new QuartzStairs()); @@ -283,9 +283,9 @@ class Block extends Position implements BlockIds, Metadatable{ self::registerBlock(new EndRod()); //TODO: END_GATEWAY - //TODO: MAGMA - //TODO: NETHER_WART_BLOCK - //TODO: RED_NETHER_BRICK + self::registerBlock(new Magma()); + self::registerBlock(new NetherWartBlock()); + self::registerBlock(new NetherBrick(Block::RED_NETHER_BRICK, 0, "Red Nether Bricks")); //TODO: BONE_BLOCK //TODO: SHULKER_BOX diff --git a/src/pocketmine/block/Magma.php b/src/pocketmine/block/Magma.php new file mode 100644 index 000000000..beff40d1a --- /dev/null +++ b/src/pocketmine/block/Magma.php @@ -0,0 +1,75 @@ +meta = $meta; + } + + public function getName() : string{ + return "Magma Block"; + } + + public function getHardness() : float{ + return 0.5; + } + + public function getToolType() : int{ + return Tool::TYPE_PICKAXE; + } + + public function getLightLevel() : int{ + return 3; + } + + public function hasEntityCollision() : bool{ + return true; + } + + public function onEntityCollide(Entity $entity){ + if(!$entity->isSneaking()){ + $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1); + $entity->attack($ev->getFinalDamage(), $ev); + } + } + + public function getDrops(Item $item) : array{ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ + return parent::getDrops($item); + } + + return []; + } + +} \ No newline at end of file diff --git a/src/pocketmine/block/NetherBrick.php b/src/pocketmine/block/NetherBrick.php index b2380c829..a1d7ef1a1 100644 --- a/src/pocketmine/block/NetherBrick.php +++ b/src/pocketmine/block/NetherBrick.php @@ -28,20 +28,10 @@ use pocketmine\item\Tool; class NetherBrick extends Solid{ - protected $id = self::NETHER_BRICK_BLOCK; - - public function __construct(int $meta = 0){ - $this->meta = $meta; - } - public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName() : string{ - return "Nether Bricks"; - } - public function getHardness() : float{ return 2; } diff --git a/src/pocketmine/block/NetherQuartzOre.php b/src/pocketmine/block/NetherQuartzOre.php new file mode 100644 index 000000000..fc1aa5ab5 --- /dev/null +++ b/src/pocketmine/block/NetherQuartzOre.php @@ -0,0 +1,59 @@ +meta = $meta; + } + + public function getName() : string{ + return "Nether Quartz Ore"; + } + + public function getHardness() : float{ + return 3; + } + + public function getToolType() : int{ + return Tool::TYPE_PICKAXE; + } + + public function getDrops(Item $item) : array{ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ + return [ + Item::get(Item::QUARTZ, 0, 1) + ]; + } + + return []; + } + +} \ No newline at end of file diff --git a/src/pocketmine/block/NetherWartBlock.php b/src/pocketmine/block/NetherWartBlock.php new file mode 100644 index 000000000..f01204873 --- /dev/null +++ b/src/pocketmine/block/NetherWartBlock.php @@ -0,0 +1,41 @@ +meta = $meta; + } + + public function getName() : string{ + return "Nether Wart Block"; + } + + public function getHardness() : float{ + return 1; + } +} \ No newline at end of file diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 1648539ce..ec641a7c8 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1611,12 +1611,13 @@ abstract class Entity extends Location implements Metadatable{ */ public function getBlocksAround() : array{ if($this->blocksAround === null){ - $minX = Math::floorFloat($this->boundingBox->minX); - $minY = Math::floorFloat($this->boundingBox->minY); - $minZ = Math::floorFloat($this->boundingBox->minZ); - $maxX = Math::ceilFloat($this->boundingBox->maxX); - $maxY = Math::ceilFloat($this->boundingBox->maxY); - $maxZ = Math::ceilFloat($this->boundingBox->maxZ); + $bb = $this->boundingBox->grow(0.01, 0.01, 0.01); + $minX = Math::floorFloat($bb->minX); + $minY = Math::floorFloat($bb->minY); + $minZ = Math::floorFloat($bb->minZ); + $maxX = Math::ceilFloat($bb->maxX); + $maxY = Math::ceilFloat($bb->maxY); + $maxZ = Math::ceilFloat($bb->maxZ); $this->blocksAround = [];