mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-27 13:49:55 +00:00
Added Furnace recipes
This commit is contained in:
parent
d5f160ea3d
commit
9aed430fda
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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,
|
@ -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
|
||||
*
|
||||
|
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\recipes;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Smelt{
|
||||
public static $product = array(
|
||||
Item::COBBLESTONE => 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),
|
||||
);
|
||||
}
|
@ -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){
|
||||
|
Loading…
x
Reference in New Issue
Block a user