From 9aed430fdac08a0a01ecd3bf755c3ae99cd5400e Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 May 2014 00:29:36 +0200 Subject: [PATCH] Added Furnace recipes --- src/pocketmine/inventory/CraftingManager.php | 43 +++++++++++++++++- .../{recipes => inventory}/Fuel.php | 3 +- src/pocketmine/item/Item.php | 18 -------- src/pocketmine/recipes/Smelt.php | 44 ------------------- src/pocketmine/tile/Furnace.php | 9 ++-- 5 files changed, 49 insertions(+), 68 deletions(-) rename src/pocketmine/{recipes => inventory}/Fuel.php (96%) delete mode 100644 src/pocketmine/recipes/Smelt.php diff --git a/src/pocketmine/inventory/CraftingManager.php b/src/pocketmine/inventory/CraftingManager.php index 310b173fa..7c05292e6 100644 --- a/src/pocketmine/inventory/CraftingManager.php +++ b/src/pocketmine/inventory/CraftingManager.php @@ -40,6 +40,7 @@ class CraftingManager{ public function __construct(){ $this->registerStonecutter(); + $this->registerFurnace(); $this->registerDyes(); @@ -101,6 +102,23 @@ class CraftingManager{ $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::IRON_BARS, 0, 16)))->addIngredient(Item::get(Item::IRON_INGOT, 0, 6))); } + protected function registerFurnace(){ + $this->registerRecipe(new FurnaceRecipe(Item::get(Item::STONE, 0, 1), Item::get(Item::COBBLESTONE, 0, 1))); + $this->registerRecipe(new FurnaceRecipe(Item::get(Item::GLASS, 0, 1), Item::get(Item::SAND, 0, 1))); + $this->registerRecipe(new FurnaceRecipe(Item::get(Item::COAL, 1, 1), Item::get(Item::TRUNK, null, 1))); + $this->registerRecipe(new FurnaceRecipe(Item::get(Item::GOLD_INGOT, 0, 1), Item::get(Item::GOLD_ORE, 0, 1))); + $this->registerRecipe(new FurnaceRecipe(Item::get(Item::IRON_INGOT, 0, 1), Item::get(Item::IRON_ORE, 0, 1))); + $this->registerRecipe(new FurnaceRecipe(Item::get(Item::NETHER_BRICK, 0, 1), Item::get(Item::NETHERRACK, 0, 1))); + $this->registerRecipe(new FurnaceRecipe(Item::get(Item::COOKED_PORKCHOP, 0, 1), Item::get(Item::RAW_PORKCHOP, 0, 1))); + $this->registerRecipe(new FurnaceRecipe(Item::get(Item::BRICK, 0, 1), Item::get(Item::CLAY, 0, 1))); + //$this->registerRecipe(new FurnaceRecipe(Item::get(Item::COOKED_FISH, 0, 1), Item::get(Item::RAW_FISH, 0, 1))); + $this->registerRecipe(new FurnaceRecipe(Item::get(Item::DYE, 2, 1), Item::get(Item::CACTUS, 0, 1))); + $this->registerRecipe(new FurnaceRecipe(Item::get(Item::DYE, 1, 1), Item::get(Item::RED_MUSHROOM, 0, 1))); + $this->registerRecipe(new FurnaceRecipe(Item::get(Item::STEAK, 0, 1), Item::get(Item::RAW_BEEF, 0, 1))); + $this->registerRecipe(new FurnaceRecipe(Item::get(Item::COOKED_CHICKEN, 0, 1), Item::get(Item::RAW_CHICKEN, 0, 1))); + $this->registerRecipe(new FurnaceRecipe(Item::get(Item::BAKED_POTATO, 0, 1), Item::get(Item::POTATO, 0, 1))); + } + protected function registerStonecutter(){ $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::QUARTZ_BLOCK, 0, 1)))->addIngredient(Item::get(Item::QUARTZ, 0, 4))); $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::BRICK_STAIRS, 0, 4)))->addIngredient(Item::get(Item::BRICKS_BLOCK, 0, 6))); @@ -272,6 +290,28 @@ class CraftingManager{ return $this->recipes; } + /** + * @return FurnaceRecipe[] + */ + public function getFurnaceRecipes(){ + return $this->furnaceRecipes; + } + + /** + * @param Item $input + * + * @return FurnaceRecipe + */ + public function matchFurnaceRecipe(Item $input){ + if(isset($this->furnaceRecipes[$input->getID().":".$input->getDamage()])){ + return $this->furnaceRecipes[$input->getID().":".$input->getDamage()]; + }elseif($this->furnaceRecipes[$input->getID().":?"]){ + return $this->furnaceRecipes[$input->getID().":?"]; + } + + return null; + } + /** * @param ShapedRecipe $recipe */ @@ -298,7 +338,8 @@ class CraftingManager{ * @param FurnaceRecipe $recipe */ public function registerFurnaceRecipe(FurnaceRecipe $recipe){ - + $input = $recipe->getInput(); + $this->furnaceRecipes[$input->getID().":".($input->getDamage() === null ? "?":$input->getDamage())] = $recipe; } /** diff --git a/src/pocketmine/recipes/Fuel.php b/src/pocketmine/inventory/Fuel.php similarity index 96% rename from src/pocketmine/recipes/Fuel.php rename to src/pocketmine/inventory/Fuel.php index 3f0663b0c..352afb300 100644 --- a/src/pocketmine/recipes/Fuel.php +++ b/src/pocketmine/inventory/Fuel.php @@ -19,10 +19,11 @@ * */ -namespace pocketmine\recipes; +namespace pocketmine\inventory; use pocketmine\item\Item; +//TODO: remove this abstract class Fuel{ public static $duration = array( Item::COAL => 80, diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 6bfe7a85f..aeff008a8 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -30,7 +30,6 @@ use pocketmine\item\Block as ItemBlock; use pocketmine\level\Level; use pocketmine\Player; use pocketmine\recipes\Fuel; -use pocketmine\recipes\Smelt; class Item{ //All Block IDs are here too @@ -540,23 +539,6 @@ class Item{ return false; } - final public function getSmeltItem(){ - if(!isset(Smelt::$product[$this->id])){ - return false; - } - - if(isset(Smelt::$product[$this->id][0]) and !is_array(Smelt::$product[$this->id][0])){ - return self::get(Smelt::$product[$this->id][0], Smelt::$product[$this->id][1]); - } - - if(!isset(Smelt::$product[$this->id][$this->meta])){ - return false; - } - - return self::get(Smelt::$product[$this->id][$this->meta][0], Smelt::$product[$this->id][$this->meta][1]); - - } - /** * @param Entity|Block $object * diff --git a/src/pocketmine/recipes/Smelt.php b/src/pocketmine/recipes/Smelt.php deleted file mode 100644 index abbdd5445..000000000 --- a/src/pocketmine/recipes/Smelt.php +++ /dev/null @@ -1,44 +0,0 @@ - array(Item::STONE, 0), - Item::SAND => array(Item::GLASS, 0), - Item::TRUNK => array(Item::COAL, 1), //Charcoal - Item::GOLD_ORE => array(Item::GOLD_INGOT, 0), - Item::IRON_ORE => array(Item::IRON_INGOT, 0), - Item::NETHERRACK => array(Item::NETHER_BRICK, 0), - Item::RAW_PORKCHOP => array(Item::COOKED_PORKCHOP, 0), - Item::CLAY => array(Item::BRICK, 0), - //Item::RAW_FISH => array(Item::COOKED_FISH, 0), - Item::CACTUS => array(Item::DYE, 2), - Item::RED_MUSHROOM => array(Item::DYE, 1), - Item::RAW_BEEF => array(Item::STEAK, 0), - Item::RAW_CHICKEN => array(Item::COOKED_CHICKEN, 0), - Item::RED_MUSHROOM => array(Item::DYE, 1), - Item::POTATO => array(Item::BAKED_POTATO, 0), - ); -} \ No newline at end of file diff --git a/src/pocketmine/tile/Furnace.php b/src/pocketmine/tile/Furnace.php index 7931e6bc3..314df9047 100644 --- a/src/pocketmine/tile/Furnace.php +++ b/src/pocketmine/tile/Furnace.php @@ -23,6 +23,7 @@ namespace pocketmine\tile; use pocketmine\block\Block; use pocketmine\inventory\FurnaceInventory; +use pocketmine\inventory\FurnaceRecipe; use pocketmine\inventory\InventoryHolder; use pocketmine\item\Item; use pocketmine\level\Level; @@ -158,8 +159,8 @@ class Furnace extends Tile implements InventoryHolder, Container{ $fuel = $this->inventory->getFuel(); $raw = $this->inventory->getSmelting(); $product = $this->inventory->getResult(); - $smelt = $raw->getSmeltItem(); - $canSmelt = ($smelt !== false and $raw->getCount() > 0 and (($product->getID() === $smelt->getID() and $product->getDamage() === $smelt->getDamage() and $product->getCount() < $product->getMaxStackSize()) or $product->getID() === Item::AIR)); + $smelt = $this->server->getCraftingManager()->matchFurnaceRecipe($raw); + $canSmelt = ($smelt instanceof FurnaceRecipe and $raw->getCount() > 0 and (($smelt->getResult()->equals($product, true) and $product->getCount() < $product->getMaxStackSize()) or $product->getID() === Item::AIR)); if($this->namedtag->BurnTime <= 0 and $canSmelt and $fuel->getFuelTime() !== false and $fuel->getCount() > 0){ $this->lastUpdate = microtime(true); $this->namedtag->MaxTime = $this->namedtag->BurnTime = floor($fuel->getFuelTime() * 20); @@ -178,10 +179,10 @@ class Furnace extends Tile implements InventoryHolder, Container{ $ticks = (microtime(true) - $this->lastUpdate) * 20; $this->namedtag->BurnTime -= $ticks; $this->namedtag->BurnTicks = ceil(($this->namedtag->BurnTime / $this->namedtag->MaxTime) * 200); - if($smelt !== false and $canSmelt){ + if($smelt instanceof FurnaceRecipe and $canSmelt){ $this->namedtag->CookTime += $ticks; if($this->namedtag->CookTime >= 200){ //10 seconds - $product = Item::get($smelt->getID(), $smelt->getDamage(), $product->getCount() + 1); + $product = Item::get($smelt->getResult()->getID(), $smelt->getResult()->getDamage(), $product->getCount() + 1); $this->inventory->setResult($product); $raw->setCount($raw->getCount() - 1); if($raw->getCount() === 0){