From fb9f7891c7696b9e99cf24d4aaa7521b644434a6 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 25 Nov 2013 09:42:41 +0100 Subject: [PATCH] Added Beetroot soup, beetroot seeds, crafting --- src/constants/ItemIDs.php | 5 +- src/material/Block.php | 3 +- src/material/Item.php | 1 + src/material/block/plant/Beetroot.php | 82 +++++++++++++++++++++ src/material/item/generic/BeetrootSeeds.php | 27 +++++++ 5 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 src/material/block/plant/Beetroot.php create mode 100644 src/material/item/generic/BeetrootSeeds.php diff --git a/src/constants/ItemIDs.php b/src/constants/ItemIDs.php index a00dbd1c2..f0e81dbaf 100644 --- a/src/constants/ItemIDs.php +++ b/src/constants/ItemIDs.php @@ -158,4 +158,7 @@ define("QUARTZ", 406); define("NETHER_QUARTZ", 406); define("CAMERA", 456); -define("BEETROOT", 457); \ No newline at end of file +define("BEETROOT", 457); +define("BEETROOT_SEEDS", 458); +define("BEETROOT_SEED", 458); +define("BEETROOT_SOUP", 459); \ No newline at end of file diff --git a/src/material/Block.php b/src/material/Block.php index 255645409..c7f1ffdea 100644 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -140,7 +140,8 @@ abstract class Block extends Position{ CARPET => "CarpetBlock", COAL_BLOCK => "CoalBlock", - + + BEETROOT_BLOCK => "BeetrootBlock", STONECUTTER => "StonecutterBlock", GLOWING_OBSIDIAN => "GlowingObsidianBlock", NETHER_REACTOR => "NetherReactorBlock", diff --git a/src/material/Item.php b/src/material/Item.php index 4c4d5f79b..12a4b97e8 100644 --- a/src/material/Item.php +++ b/src/material/Item.php @@ -27,6 +27,7 @@ class Item{ MELON_SEEDS => "MelonSeedsItem", CARROT => "CarrotItem", POTATO => "PotatoItem", + BEETROOT_SEEDS => "BeetrootSeedsItem", SIGN => "SignItem", WOODEN_DOOR => "WoodenDoorItem", BUCKET => "BucketItem", diff --git a/src/material/block/plant/Beetroot.php b/src/material/block/plant/Beetroot.php new file mode 100644 index 000000000..d133d8278 --- /dev/null +++ b/src/material/block/plant/Beetroot.php @@ -0,0 +1,82 @@ +isActivable = true; + $this->hardness = 0; + } + + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $down = $this->getSide(0); + if($down->getID() === FARMLAND){ + $this->level->setBlock($block, $this, true, false, true); + $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); + return true; + } + return false; + } + + public function onActivate(Item $item, Player $player){ + if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal + $this->meta = 0x07; + $this->level->setBlock($this, $this, true, false, true); + if(($player->gamemode & 0x01) === 0){ + $item->count--; + } + return true; + } + return false; + } + + public function onUpdate($type){ + if($type === BLOCK_UPDATE_NORMAL){ + if($this->getSide(0)->isTransparent === true){ //Replace with common break method + ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(BEETROOT_SEEDS, 0, 1)); + $this->level->setBlock($this, new AirBlock(), false, false, true); + return BLOCK_UPDATE_NORMAL; + } + }elseif($type === BLOCK_UPDATE_RANDOM){ + if(mt_rand(0, 2) == 1){ + if($this->meta < 0x07){ + ++$this->meta; + $this->level->setBlock($this, $this, true, false, true); + return BLOCK_UPDATE_RANDOM; + } + }else{ + return BLOCK_UPDATE_RANDOM; + } + } + return false; + } + + public function getDrops(Item $item, Player $player){ + $drops = array(); + if($this->meta >= 0x07){ + $drops[] = array(BEETROOT, 0, 1); + $drops[] = array(BEETROOT_SEEDS, 0, mt_rand(0, 3)); + }else{ + $drops[] = array(BEETROOT_SEEDS, 0, 1); + } + return $drops; + } +} \ No newline at end of file diff --git a/src/material/item/generic/BeetrootSeeds.php b/src/material/item/generic/BeetrootSeeds.php new file mode 100644 index 000000000..e94e934b8 --- /dev/null +++ b/src/material/item/generic/BeetrootSeeds.php @@ -0,0 +1,27 @@ +block = BlockAPI::get(BEETROOT_BLOCK); + parent::__construct(BEETROOT_SEEDS, 0, $count, "Beetroot Seeds"); + } +} \ No newline at end of file