mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Use -1 for anydamage and empty string for null NBT, closes #146
This commit is contained in:
@ -158,8 +158,8 @@ abstract class BaseInventory implements Inventory{
|
||||
|
||||
public function contains(Item $item){
|
||||
$count = max(1, $item->getCount());
|
||||
$checkDamage = $item->getDamage() === null ? false : true;
|
||||
$checkTags = $item->getCompoundTag() === null ? false : true;
|
||||
$checkDamage = !$item->hasAnyDamageValue();
|
||||
$checkTags = $item->hasCompoundTag();
|
||||
foreach($this->getContents() as $i){
|
||||
if($item->equals($i, $checkDamage, $checkTags)){
|
||||
$count -= $i->getCount();
|
||||
@ -174,8 +174,8 @@ abstract class BaseInventory implements Inventory{
|
||||
|
||||
public function all(Item $item){
|
||||
$slots = [];
|
||||
$checkDamage = $item->getDamage() === null ? false : true;
|
||||
$checkTags = $item->getCompoundTag() === null ? false : true;
|
||||
$checkDamage = !$item->hasAnyDamageValue();
|
||||
$checkTags = $item->hasCompoundTag();
|
||||
foreach($this->getContents() as $index => $i){
|
||||
if($item->equals($i, $checkDamage, $checkTags)){
|
||||
$slots[$index] = $i;
|
||||
@ -186,8 +186,8 @@ abstract class BaseInventory implements Inventory{
|
||||
}
|
||||
|
||||
public function remove(Item $item){
|
||||
$checkDamage = $item->getDamage() === null ? false : true;
|
||||
$checkTags = $item->getCompoundTag() === null ? false : true;
|
||||
$checkDamage = !$item->hasAnyDamageValue();
|
||||
$checkTags = $item->hasCompoundTag();
|
||||
|
||||
foreach($this->getContents() as $index => $i){
|
||||
if($item->equals($i, $checkDamage, $checkTags)){
|
||||
@ -198,8 +198,8 @@ abstract class BaseInventory implements Inventory{
|
||||
|
||||
public function first(Item $item){
|
||||
$count = max(1, $item->getCount());
|
||||
$checkDamage = $item->getDamage() === null ? false : true;
|
||||
$checkTags = $item->getCompoundTag() === null ? false : true;
|
||||
$checkDamage = !$item->hasAnyDamageValue();
|
||||
$checkTags = $item->hasCompoundTag();
|
||||
|
||||
foreach($this->getContents() as $index => $i){
|
||||
if($item->equals($i, $checkDamage, $checkTags) and $i->getCount() >= $count){
|
||||
@ -222,8 +222,8 @@ abstract class BaseInventory implements Inventory{
|
||||
|
||||
public function canAddItem(Item $item){
|
||||
$item = clone $item;
|
||||
$checkDamage = $item->getDamage() === null ? false : true;
|
||||
$checkTags = $item->getCompoundTag() === null ? false : true;
|
||||
$checkDamage = !$item->hasAnyDamageValue();
|
||||
$checkTags = $item->hasCompoundTag();
|
||||
for($i = 0; $i < $this->getSize(); ++$i){
|
||||
$slot = $this->getItem($i);
|
||||
if($item->equals($slot, $checkDamage, $checkTags)){
|
||||
@ -322,7 +322,7 @@ abstract class BaseInventory implements Inventory{
|
||||
}
|
||||
|
||||
foreach($itemSlots as $index => $slot){
|
||||
if($slot->equals($item, $slot->getDamage() === null ? false : true, $slot->getCompoundTag() === null ? false : true)){
|
||||
if($slot->equals($item, !$slot->hasAnyDamageValue(), $slot->hasCompoundTag())){
|
||||
$amount = min($item->getCount(), $slot->getCount());
|
||||
$slot->setCount($slot->getCount() - $amount);
|
||||
$item->setCount($item->getCount() - $amount);
|
||||
|
@ -68,7 +68,7 @@ class CraftingManager{
|
||||
$shape = array_chunk($recipe["input"], $recipe["width"]);
|
||||
foreach($shape as $y => $row){
|
||||
foreach($row as $x => $ingredient){
|
||||
$result->addIngredient($x, $y, Item::get($ingredient["id"], ($ingredient["damage"] < 0 ? null : $ingredient["damage"]), $ingredient["count"], $ingredient["nbt"]));
|
||||
$result->addIngredient($x, $y, Item::get($ingredient["id"], ($ingredient["damage"] < 0 ? -1 : $ingredient["damage"]), $ingredient["count"], $ingredient["nbt"]));
|
||||
}
|
||||
}
|
||||
$this->registerRecipe($result);
|
||||
@ -78,7 +78,7 @@ class CraftingManager{
|
||||
case 3:
|
||||
$result = $recipe["output"];
|
||||
$resultItem = Item::get($result["id"], $result["damage"], $result["count"], $result["nbt"]);
|
||||
$this->registerRecipe(new FurnaceRecipe($resultItem, Item::get($recipe["inputId"], $recipe["inputDamage"] ?? null, 1)));
|
||||
$this->registerRecipe(new FurnaceRecipe($resultItem, Item::get($recipe["inputId"], $recipe["inputDamage"] ?? -1, 1)));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -110,7 +110,7 @@ class CraftingManager{
|
||||
*/
|
||||
public function getRecipe(UUID $id){
|
||||
$index = $id->toBinary();
|
||||
return isset($this->recipes[$index]) ? $this->recipes[$index] : null;
|
||||
return $this->recipes[$index] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,7 +154,7 @@ class CraftingManager{
|
||||
foreach($v as $item){
|
||||
if($item !== null){
|
||||
/** @var Item $item */
|
||||
$hash .= $item->getId() . ":" . ($item->getDamage() === null ? "?" : $item->getDamage()) . "x" . $item->getCount() . ",";
|
||||
$hash .= $item->getId() . ":" . ($item->hasAnyDamageValue() ? "?" : $item->getDamage()) . "x" . $item->getCount() . ",";
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ class CraftingManager{
|
||||
$ingredients = $recipe->getIngredientList();
|
||||
usort($ingredients, [$this, "sort"]);
|
||||
foreach($ingredients as $item){
|
||||
$hash .= $item->getId() . ":" . ($item->getDamage() === null ? "?" : $item->getDamage()) . "x" . $item->getCount() . ",";
|
||||
$hash .= $item->getId() . ":" . ($item->hasAnyDamageValue() ? "?" : $item->getDamage()) . "x" . $item->getCount() . ",";
|
||||
}
|
||||
$this->recipeLookup[$result->getId() . ":" . $result->getDamage()][$hash] = $recipe;
|
||||
}
|
||||
@ -184,7 +184,7 @@ class CraftingManager{
|
||||
*/
|
||||
public function registerFurnaceRecipe(FurnaceRecipe $recipe){
|
||||
$input = $recipe->getInput();
|
||||
$this->furnaceRecipes[$input->getId() . ":" . ($input->getDamage() === null ? "?" : $input->getDamage())] = $recipe;
|
||||
$this->furnaceRecipes[$input->getId() . ":" . ($input->hasAnyDamageValue() ? "?" : $input->getDamage())] = $recipe;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -200,7 +200,7 @@ class CraftingManager{
|
||||
$ingredients = $recipe->getIngredientList();
|
||||
usort($ingredients, [$this, "sort"]);
|
||||
foreach($ingredients as $item){
|
||||
$hash .= $item->getId() . ":" . ($item->getDamage() === null ? "?" : $item->getDamage()) . "x" . $item->getCount() . ",";
|
||||
$hash .= $item->getId() . ":" . ($item->hasAnyDamageValue() ? "?" : $item->getDamage()) . "x" . $item->getCount() . ",";
|
||||
}
|
||||
|
||||
if(isset($this->recipeLookup[$idx][$hash])){
|
||||
@ -217,7 +217,7 @@ class CraftingManager{
|
||||
foreach($ingredients as $item){
|
||||
$amount = $item->getCount();
|
||||
foreach($checkInput as $k => $checkItem){
|
||||
if($checkItem->equals($item, $checkItem->getDamage() === null ? false : true, $checkItem->getCompoundTag() === null ? false : true)){
|
||||
if($checkItem->equals($item, !$checkItem->hasAnyDamageValue(), $checkItem->hasCompoundTag())){
|
||||
$remove = min($checkItem->getCount(), $amount);
|
||||
$checkItem->setCount($checkItem->getCount() - $remove);
|
||||
if($checkItem->getCount() === 0){
|
||||
|
@ -87,7 +87,7 @@ class ShapelessRecipe implements Recipe{
|
||||
if($item->getCount() <= 0){
|
||||
break;
|
||||
}
|
||||
if($ingredient->equals($item, $item->getDamage() === null ? false : true, $item->getCompoundTag() === null ? false : true)){
|
||||
if($ingredient->equals($item, !$item->hasAnyDamageValue(), $item->hasCompoundTag())){
|
||||
unset($this->ingredients[$index]);
|
||||
$item->setCount($item->getCount() - 1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user