From ac4194eb3f736f7d08c051317e027bb7687a584e Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 5 Jun 2015 13:58:59 +0200 Subject: [PATCH] Added lily pad, checked some bounding boxes --- src/pocketmine/block/Air.php | 4 ++ src/pocketmine/block/Block.php | 8 ++- src/pocketmine/block/Door.php | 37 +++++------ src/pocketmine/block/PumpkinStem.php | 2 +- src/pocketmine/block/StoneWall.php | 39 +++++------ src/pocketmine/block/Vine.php | 6 +- src/pocketmine/block/WaterLily.php | 96 ++++++++++++++++++++++++++++ src/pocketmine/item/Item.php | 5 +- src/pocketmine/level/Level.php | 2 +- 9 files changed, 156 insertions(+), 43 deletions(-) create mode 100644 src/pocketmine/block/WaterLily.php diff --git a/src/pocketmine/block/Air.php b/src/pocketmine/block/Air.php index 22d9a7386..02920d54c 100644 --- a/src/pocketmine/block/Air.php +++ b/src/pocketmine/block/Air.php @@ -40,6 +40,10 @@ class Air extends Transparent{ return "Air"; } + public function canPassThrough(){ + return true; + } + public function isBreakable(Item $item){ return false; } diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 9819fe2c9..efc72589b 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -175,7 +175,8 @@ class Block extends Position implements Metadatable{ const BRICK_STAIRS = 108; const STONE_BRICK_STAIRS = 109; const MYCELIUM = 110; - + const WATER_LILY = 111; + const LILY_PAD = 111; const NETHER_BRICKS = 112; const NETHER_BRICK_BLOCK = 112; @@ -402,6 +403,7 @@ class Block extends Position implements Metadatable{ self::$list[self::STONE_BRICK_STAIRS] = StoneBrickStairs::class; self::$list[self::MYCELIUM] = Mycelium::class; + self::$list[self::WATER_LILY] = WaterLily::class; self::$list[self::NETHER_BRICKS] = NetherBrick::class; self::$list[self::NETHER_BRICKS_STAIRS] = NetherBrickStairs::class; @@ -671,6 +673,10 @@ class Block extends Position implements Metadatable{ return false; } + public function canPassThrough(){ + return false; + } + /** * @return string */ diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index 96119c2d7..c8ac0e7f4 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -25,6 +25,7 @@ use pocketmine\item\Item; use pocketmine\level\Level; use pocketmine\level\sound\DoorSound; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Vector3; use pocketmine\network\protocol\LevelEventPacket; use pocketmine\Player; use pocketmine\Server; @@ -42,19 +43,19 @@ abstract class Door extends Transparent{ private function getFullDamage(){ $damage = $this->getDamage(); - $flag = ($damage & 0x08) > 0; + $isUp = ($damage & 0x08) > 0; - if($flag){ - $first = $this->getSide(0)->getDamage(); - $second = $damage; + if($isUp){ + $down = $this->getSide(Vector3::SIDE_DOWN)->getDamage(); + $up = $damage; }else{ - $first = $damage; - $second = $this->getSide(1)->getDamage(); + $down = $damage; + $up = $this->getSide(Vector3::SIDE_UP)->getDamage(); } - $flag1 = ($second & 0x01) > 0; + $isRight = ($up & 0x01) > 0; - return $first & 0x07 | ($flag ? 8 : 0) | ($flag1 ? 0x10 : 0); + return $down & 0x07 | ($isUp ? 8 : 0) | ($isRight ? 0x10 : 0); } protected function recalculateBoundingBox(){ @@ -72,12 +73,12 @@ abstract class Door extends Transparent{ ); $j = $damage & 0x03; - $flag = (($damage & 0x04) > 0); - $flag1 = (($damage & 0x10) > 0); + $isOpen = (($damage & 0x04) > 0); + $isRight = (($damage & 0x10) > 0); if($j === 0){ - if($flag){ - if(!$flag1){ + if($isOpen){ + if(!$isRight){ $bb->setBounds( $this->x, $this->y, @@ -107,8 +108,8 @@ abstract class Door extends Transparent{ ); } }elseif($j === 1){ - if($flag){ - if(!$flag1){ + if($isOpen){ + if(!$isRight){ $bb->setBounds( $this->x + 1 - $f, $this->y, @@ -138,8 +139,8 @@ abstract class Door extends Transparent{ ); } }elseif($j === 2){ - if($flag){ - if(!$flag1){ + if($isOpen){ + if(!$isRight){ $bb->setBounds( $this->x, $this->y, @@ -169,8 +170,8 @@ abstract class Door extends Transparent{ ); } }elseif($j === 3){ - if($flag){ - if(!$flag1){ + if($isOpen){ + if(!$isRight){ $bb->setBounds( $this->x, $this->y, diff --git a/src/pocketmine/block/PumpkinStem.php b/src/pocketmine/block/PumpkinStem.php index 1f902025e..f9c274b07 100644 --- a/src/pocketmine/block/PumpkinStem.php +++ b/src/pocketmine/block/PumpkinStem.php @@ -40,7 +40,7 @@ class PumpkinStem extends Crops{ public function onUpdate($type){ if($type === Level::BLOCK_UPDATE_NORMAL){ - if($this->getSide(0)->isTransparent() === true){ + if($this->getSide(0)->isTransparent()){ $this->getLevel()->useBreakOn($this); return Level::BLOCK_UPDATE_NORMAL; } diff --git a/src/pocketmine/block/StoneWall.php b/src/pocketmine/block/StoneWall.php index 648cafc1d..26e12e65c 100644 --- a/src/pocketmine/block/StoneWall.php +++ b/src/pocketmine/block/StoneWall.php @@ -23,6 +23,7 @@ namespace pocketmine\block; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Vector3; class StoneWall extends Transparent{ @@ -50,36 +51,36 @@ class StoneWall extends Transparent{ protected function recalculateBoundingBox(){ - $flag = $this->canConnect($this->getSide(2)); - $flag1 = $this->canConnect($this->getSide(3)); - $flag2 = $this->canConnect($this->getSide(4)); - $flag3 = $this->canConnect($this->getSide(5)); + $north = $this->canConnect($this->getSide(Vector3::SIDE_NORTH)); + $south = $this->canConnect($this->getSide(Vector3::SIDE_SOUTH)); + $west = $this->canConnect($this->getSide(Vector3::SIDE_WEST)); + $east = $this->canConnect($this->getSide(Vector3::SIDE_EAST)); - $f = $flag2 ? 0 : 0.25; - $f1 = $flag3 ? 1 : 0.75; - $f2 = $flag ? 0 : 0.25; - $f3 = $flag1 ? 1 : 0.75; + $n = $north ? 0 : 0.25; + $s = $south ? 1 : 0.75; + $w = $west ? 0 : 0.25; + $e = $east ? 1 : 0.75; - if($flag and $flag1 and !$flag2 and !$flag3){ - $f = 0.3125; - $f1 = 0.6875; - }elseif(!$flag and !$flag1 and $flag2 and $flag3){ - $f2 = 0.3125; - $f3 = 0.6875; + if($north and $south and !$west and !$east){ + $w = 0.3125; + $e = 0.6875; + }elseif(!$north and !$south and $west and $east){ + $n = 0.3125; + $s = 0.6875; } return new AxisAlignedBB( - $this->x + $f, + $this->x + $w, $this->y, - $this->z + $f2, - $this->x + $f1, + $this->z + $n, + $this->x + $e, $this->y + 1.5, - $this->z + $f3 + $this->z + $s ); } public function canConnect(Block $block){ - return ($block->getId() !== self::COBBLE_WALL and $block->getId() !== self::FENCE_GATE) ? $block->isSolid() : true; + return ($block->getId() !== self::COBBLE_WALL and $block->getId() !== self::FENCE_GATE) ? $block->isSolid() and !$block->isTransparent() : true; } } \ No newline at end of file diff --git a/src/pocketmine/block/Vine.php b/src/pocketmine/block/Vine.php index b9272b7a0..4ba8511af 100644 --- a/src/pocketmine/block/Vine.php +++ b/src/pocketmine/block/Vine.php @@ -48,6 +48,10 @@ class Vine extends Transparent{ return 1; } + public function canPassThrough(){ + return true; + } + public function hasEntityCollision(){ return true; } @@ -118,7 +122,7 @@ class Vine extends Transparent{ public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ - if($target->isSolid()){ + if(!$target->isTransparent() and $target->isSolid()){ $faces = [ 0 => 0, 1 => 0, diff --git a/src/pocketmine/block/WaterLily.php b/src/pocketmine/block/WaterLily.php new file mode 100644 index 000000000..b3d6abee0 --- /dev/null +++ b/src/pocketmine/block/WaterLily.php @@ -0,0 +1,96 @@ +meta = $meta; + } + + public function isSolid(){ + return false; + } + + public function getName(){ + return "Lily Pad"; + } + + public function getHardness(){ + return 0.6; + } + + public function canPassThrough(){ + return true; + } + + protected function recalculateBoundingBox(){ + return new AxisAlignedBB( + $this->x, + $this->y, + $this->z, + $this->x, + $this->y + 0.0625, + $this->z + ); + } + + + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + if($target instanceof Water){ + $up = $target->getSide(Vector3::SIDE_UP); + if($up->getId() === Block::AIR){ + $this->getLevel()->setBlock($up, $this, true, true); + return true; + } + } + + return false; + } + + public function onUpdate($type){ + if($type === Level::BLOCK_UPDATE_NORMAL){ + if(!($this->getSide(0) instanceof Water)){ + $this->getLevel()->useBreakOn($this); + return Level::BLOCK_UPDATE_NORMAL; + } + } + + return false; + } + + public function getDrops(Item $item){ + return [ + [$this->id, 0, 1] + ]; + } +} \ No newline at end of file diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index f92fc8987..1ec933430 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -170,7 +170,8 @@ class Item{ const BRICK_STAIRS = 108; const STONE_BRICK_STAIRS = 109; const MYCELIUM = 110; - + const WATER_LILY = 111; + const LILY_PAD = 111; const NETHER_BRICKS = 112; const NETHER_BRICK_BLOCK = 112; @@ -606,7 +607,7 @@ class Item{ //Decoration self::addCreativeItem(Item::get(Item::COBBLESTONE_WALL, 0)); self::addCreativeItem(Item::get(Item::COBBLESTONE_WALL, 1)); - //TODO: Lilly Pad + self::addCreativeItem(Item::get(Item::WATER_LILY, 0)); self::addCreativeItem(Item::get(Item::GOLD_BLOCK, 0)); self::addCreativeItem(Item::get(Item::IRON_BLOCK, 0)); self::addCreativeItem(Item::get(Item::DIAMOND_BLOCK, 0)); diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 93d14398f..403e366cb 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1070,7 +1070,7 @@ class Level implements ChunkManager, Metadatable{ for($x = $minX; $x <= $maxX; ++$x){ for($y = $minY; $y <= $maxY; ++$y){ $block = $this->getBlock($this->temporalVector->setComponents($x, $y, $z)); - if($block->getId() !== 0 and $block->collidesWithBB($bb)){ + if(!$block->canPassThrough() and $block->collidesWithBB($bb)){ $collides[] = $block->getBoundingBox(); } }