Update fuel duration to ticks

This commit is contained in:
Shoghi Cervantes 2014-10-09 12:21:14 +02:00
parent b45ef8928c
commit 22ad75c5a0
4 changed files with 29 additions and 31 deletions

View File

@ -26,29 +26,28 @@ use pocketmine\item\Item;
//TODO: remove this //TODO: remove this
abstract class Fuel{ abstract class Fuel{
public static $duration = [ public static $duration = [
Item::COAL => 80, Item::COAL => 1600,
Item::COAL_BLOCK => 800, Item::COAL_BLOCK => 16000,
Item::TRUNK => 15, Item::TRUNK => 300,
Item::WOODEN_PLANKS => 15, Item::WOODEN_PLANKS => 300,
Item::SAPLING => 5, Item::SAPLING => 100,
Item::WOODEN_AXE => 10, Item::WOODEN_AXE => 200,
Item::WOODEN_PICKAXE => 10, Item::WOODEN_PICKAXE => 200,
Item::WOODEN_SWORD => 10, Item::WOODEN_SWORD => 200,
Item::WOODEN_SHOVEL => 10, Item::WOODEN_SHOVEL => 200,
Item::WOODEN_HOE => 10, Item::WOODEN_HOE => 200,
Item::STICK => 5, Item::STICK => 100,
Item::FENCE => 15, Item::FENCE => 300,
Item::FENCE_GATE => 15, Item::FENCE_GATE => 300,
Item::WOODEN_STAIRS => 15, Item::WOODEN_STAIRS => 300,
Item::SPRUCE_WOOD_STAIRS => 15, Item::SPRUCE_WOOD_STAIRS => 300,
Item::BIRCH_WOOD_STAIRS => 15, Item::BIRCH_WOOD_STAIRS => 300,
Item::JUNGLE_WOOD_STAIRS => 15, Item::JUNGLE_WOOD_STAIRS => 300,
Item::TRAPDOOR => 15, Item::TRAPDOOR => 300,
Item::WORKBENCH => 15, Item::WORKBENCH => 300,
Item::BOOKSHELF => 15, Item::BOOKSHELF => 300,
Item::CHEST => 15, Item::CHEST => 300,
Item::BUCKET => 1000, Item::BUCKET => 20000,
]; ];
} }

View File

@ -24,7 +24,7 @@ namespace pocketmine\inventory;
/** /**
* Saves all the information regarding default inventory sizes and types * Saves all the information regarding default inventory sizes and types
*/ */
abstract class SlotType{ interface SlotType{
const RESULT = 0; const RESULT = 0;
const CRAFTING = 1; //Not used in Minecraft: PE yet const CRAFTING = 1; //Not used in Minecraft: PE yet

View File

@ -556,13 +556,13 @@ class Item{
final public function getFuelTime(){ final public function getFuelTime(){
if(!isset(Fuel::$duration[$this->id])){ if(!isset(Fuel::$duration[$this->id])){
return false; return null;
} }
if($this->id !== self::BUCKET or $this->meta === 10){ if($this->id !== self::BUCKET or $this->meta === 10){
return Fuel::$duration[$this->id]; return Fuel::$duration[$this->id];
} }
return false; return null;
} }
/** /**

View File

@ -180,9 +180,9 @@ class Furnace extends Tile implements InventoryHolder, Container{
$product = $this->inventory->getResult(); $product = $this->inventory->getResult();
$smelt = $this->server->getCraftingManager()->matchFurnaceRecipe($raw); $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)); $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){ if($this->namedtag["BurnTime"] <= 0 and $canSmelt and $fuel->getFuelTime() !== null and $fuel->getCount() > 0){
$this->lastUpdate = microtime(true); $this->lastUpdate = microtime(true);
$time = floor($fuel->getFuelTime() * 20); $time = floor($fuel->getFuelTime());
$this->namedtag->MaxTime = new Short("MaxTime", $time); $this->namedtag->MaxTime = new Short("MaxTime", $time);
$this->namedtag->BurnTime = new Short("BurnTime", $time); $this->namedtag->BurnTime = new Short("BurnTime", $time);
$this->namedtag->BurnTicks = new Short("BurnTicks", 0); $this->namedtag->BurnTicks = new Short("BurnTicks", 0);
@ -197,12 +197,11 @@ class Furnace extends Tile implements InventoryHolder, Container{
} }
} }
if($this->namedtag["BurnTime"] > 0){ if($this->namedtag["BurnTime"] > 0){
$ticks = (microtime(true) - $this->lastUpdate) * 20; $this->namedtag->BurnTime = new Short("BurnTime", $this->namedtag["BurnTime"] - 1);
$this->namedtag->BurnTime = new Short("BurnTime", $this->namedtag["BurnTime"] - $ticks);
$this->namedtag->BurnTicks = new Short("BurnTicks", ceil(($this->namedtag["BurnTime"] / $this->namedtag["MaxTime"] * 200))); $this->namedtag->BurnTicks = new Short("BurnTicks", ceil(($this->namedtag["BurnTime"] / $this->namedtag["MaxTime"] * 200)));
if($smelt instanceof FurnaceRecipe and $canSmelt){ if($smelt instanceof FurnaceRecipe and $canSmelt){
$this->namedtag->CookTime = new Short("CookTime", $this->namedtag["CookTime"] + $ticks); $this->namedtag->CookTime = new Short("CookTime", $this->namedtag["CookTime"] + 1);
if($this->namedtag["CookTime"] >= 200){ //10 seconds if($this->namedtag["CookTime"] >= 200){ //10 seconds
$product = Item::get($smelt->getResult()->getID(), $smelt->getResult()->getDamage(), $product->getCount() + 1); $product = Item::get($smelt->getResult()->getID(), $smelt->getResult()->getDamage(), $product->getCount() + 1);
$this->inventory->setResult($product); $this->inventory->setResult($product);