From b83c6fbfa308f4707205ed0c0ac81b831d580706 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 7 Oct 2014 10:17:31 +0200 Subject: [PATCH] Added Vine blocks, closes #2162 --- src/pocketmine/block/Block.php | 7 +- src/pocketmine/block/Vine.php | 168 +++++++++++++++++++++++++++++++++ src/pocketmine/item/Item.php | 3 +- 3 files changed, 174 insertions(+), 4 deletions(-) create mode 100644 src/pocketmine/block/Vine.php diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 3762b229e..a62f28d89 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -167,7 +167,8 @@ abstract class Block extends Position implements Metadatable{ const MELON_BLOCK = 103; const PUMPKIN_STEM = 104; const MELON_STEM = 105; - + const VINE = 106; + const VINES = 106; const FENCE_GATE = 107; const BRICK_STAIRS = 108; const STONE_BRICK_STAIRS = 109; @@ -345,7 +346,7 @@ abstract class Block extends Position implements Metadatable{ [Item::SNOW_LAYER, 0], [Item::GLASS, 0], [Item::GLOWSTONE_BLOCK, 0], - //TODO: Vines + [Item::VINES, 0], [Item::NETHER_REACTOR, 0], [Item::LADDER, 0], [Item::SPONGE, 0], @@ -621,7 +622,7 @@ abstract class Block extends Position implements Metadatable{ self::MELON_BLOCK => Melon::class, self::PUMPKIN_STEM => PumpkinStem::class, self::MELON_STEM => MelonStem::class, - + self::VINE => Vine::class, self::FENCE_GATE => FenceGate::class, self::BRICK_STAIRS => BrickStairs::class, self::STONE_BRICK_STAIRS => StoneBrickStairs::class, diff --git a/src/pocketmine/block/Vine.php b/src/pocketmine/block/Vine.php new file mode 100644 index 000000000..8dfc837b2 --- /dev/null +++ b/src/pocketmine/block/Vine.php @@ -0,0 +1,168 @@ +isSolid = false; + $this->isFullBlock = false; + $this->hardness = 1; + } + + public function onEntityCollide(Entity $entity){ + $entity->fallDistance = 0; + } + + public function getBoundingBox(){ + $f1 = 1; + $f2 = 1; + $f3 = 1; + $f4 = 0; + $f5 = 0; + $f6 = 0; + + $flag = $this->meta > 0; + + if(($this->meta & 0x02) > 0){ + $f4 = max($f4, 0.0625); + $f1 = 0; + $f2 = 0; + $f5 = 1; + $f3 = 0; + $f6 = 1; + $flag = true; + } + + if(($this->meta & 0x08) > 0){ + $f1 = min($f1, 0.9375); + $f4 = 1; + $f2 = 0; + $f5 = 1; + $f3 = 0; + $f6 = 1; + $flag = true; + } + + if(($this->meta & 0x01) > 0){ + $f3 = min($f3, 0.9375); + $f6 = 1; + $f1 = 0; + $f4 = 1; + $f2 = 0; + $f5 = 1; + $flag = true; + } + + if(!$flag and $this->getSide(1)->isSolid){ + $f2 = min($f2, 0.9375); + $f5 = 1; + $f1 = 0; + $f4 = 1; + $f3 = 0; + $f6 = 1; + } + + return new AxisAlignedBB( + $this->x + $f1, + $this->y + $f2, + $this->z + $f3, + $this->x + $f4, + $this->y + $f5, + $this->z + $f6 + ); + } + + + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + if($target->isSolid){ + $faces = [ + 0 => 0, + 1 => 0, + 2 => 1, + 3 => 4, + 4 => 8, + 5 => 2, + ]; + if(isset($faces[$face])){ + $this->meta = $faces[$face]; + $this->getLevel()->setBlock($block, $this, true, true); + + return true; + } + } + + return false; + } + + public function getBreakTime(Item $item){ + if($item->isShears()){ + return 0.02; + }elseif($item->isSword()){ + return 0.2; + }elseif($item->isAxe()){ + switch($item->isAxe()){ + case Tool::TIER_WOODEN: + return 0.15; + case Tool::TIER_STONE: + return 0.075; + case Tool::TIER_IRON: + return 0.05; + case Tool::TIER_DIAMOND: + return 0.0375; + case Tool::TIER_GOLD: + return 0.025; + } + } + + return 0.3; + } + + public function onUpdate($type){ + if($type === Level::BLOCK_UPDATE_NORMAL){ + /*if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method + Server::getInstance()->api->entity->drop($this, Item::get(LADDER, 0, 1)); + $this->getLevel()->setBlock($this, new Air(), true, true, true); + return Level::BLOCK_UPDATE_NORMAL; + }*/ + } + + return false; + } + + public function getDrops(Item $item){ + if($item->isShears()){ + return [ + [$this->id, 0, 1], + ]; + }else{ + return []; + } + } +} \ No newline at end of file diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 8e99b4ac5..baea79cb9 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -159,7 +159,8 @@ class Item{ const MELON_BLOCK = 103; const PUMPKIN_STEM = 104; const MELON_STEM = 105; - + const VINE = 106; + const VINES = 106; const FENCE_GATE = 107; const BRICK_STAIRS = 108; const STONE_BRICK_STAIRS = 109;