Implemented Transactions

This commit is contained in:
Shoghi Cervantes
2014-05-27 01:20:18 +02:00
parent 160c633c08
commit 6fcd5322d0
13 changed files with 844 additions and 234 deletions

View File

@ -0,0 +1,114 @@
<?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\inventory;
use pocketmine\item\Item;
class FurnaceRecipe implements Recipe{
/** @var Item */
private $output;
/** @var Item */
private $ingredient;
/**
* @param Item $result
* @param Item $ingredient
*/
public function __construct(Item $result, Item $ingredient){
$this->output = clone $result;
$this->ingredient = clone $ingredient;
}
/**
* @param Item $item
*/
public function setInput(Item $item){
$this->ingredient = clone $item;
}
/**
* @return Item
*/
public function getInput(){
return clone $this->ingredient;
}
/**
* @return Item
*/
public function getResult(){
return clone $this->output;
}
/**
* @param Item $item
*
* @returns ShapelessRecipe
*
* @throws \Exception
*/
public function addIngredient(Item $item){
if(count($this->ingredients) >= 9){
throw new \Exception("Shapeless recipes cannot have more than 9 ingredients");
}
$it = clone $item;
$it->setCount(1);
while($item->getCount() > 0){
$this->ingredients[] = clone $it;
$item->setCount($item->getCount() - 1);
}
return $this;
}
/**
* @param Item $item
*
* @return $this
*/
public function removeIngredient(Item $item){
foreach($this->ingredients as $index => $ingredient){
if($item->getCount() <= 0){
break;
}
if($ingredient->equals($item, $item->getDamage() === null ? false : true)){
unset($this->ingredients[$index]);
$item->setCount($item->getCount() - 1);
}
}
return $this;
}
/**
* @return Item[]
*/
public function getIngredientList(){
$ingredients = [];
foreach($this->ingredients as $ingredient){
$ingredients[] = clone $ingredient;
}
return $ingredients;
}
}