Permalink
Browse files

Tweaks to item checking. Better debug outputs.

  • Loading branch information...
me4502 committed Apr 10, 2017
1 parent 6ce7bd6 commit d5867b6ba42c0465639722ae889286ecb5efba95
@@ -1,5 +1,6 @@
package com.sk89q.craftbook.mechanics.crafting;
+import com.google.common.base.*;
import com.sk89q.craftbook.AbstractCraftBookMechanic;
import com.sk89q.craftbook.LocalPlayer;
import com.sk89q.craftbook.bukkit.CraftBookPlugin;
@@ -141,8 +142,10 @@ public void prepareCraft(PrepareItemCraftEvent event) {
for(ItemStack it : tests) {
- if(!ItemUtil.isStackValid(it))
+ if(!ItemUtil.isStackValid(it)) {
+ CraftBookPlugin.logDebugMessage("Invalid item in recipe: " + com.google.common.base.Objects.toStringHelper(it).toString(), "advanced-data");
continue;
+ }
for(CraftingItemStack cit : tests2) {
if(ItemUtil.areBaseItemsIdentical(cit.getItemStack(), it)) {
@@ -337,7 +337,7 @@ public static boolean areItemMetaIdentical(ItemMeta meta, ItemMeta meta2) {
public static boolean areItemsIdentical(ItemStack item, ItemStack item2) {
if(!isStackValid(item) || !isStackValid(item2)) {
- CraftBookPlugin.logDebugMessage("An invalid item was compared", "item-checks");
+ CraftBookPlugin.logDebugMessage("An invalid item was compared. Was first? " + isStackValid(item), "item-checks");
return !isStackValid(item) && !isStackValid(item2);
}
else {
@@ -374,7 +374,17 @@ public static boolean areBaseItemsIdentical(ItemStack item, ItemStack item2) {
}
public static boolean isStackValid(ItemStack item) {
- return item != null && item.getAmount() > 0 && item.getTypeId() > 0;
+ if (item == null) {
+ CraftBookPlugin.logDebugMessage("item-checks", "Item is null.");
+ return false;
+ } else if (item.getAmount() <= 0) {
+ CraftBookPlugin.logDebugMessage("item-checks", "Item has amount of " + item.getAmount());
+ return false;
+ } else if (item.getTypeId() <= 0) {
+ CraftBookPlugin.logDebugMessage("item-checks", "Item has type ID of " + item.getTypeId());
+ return false;
+ }
+ return true;
}
/**
@@ -663,16 +673,16 @@ public static ItemStack getSmallestStackOfType(ItemStack[] stacks, ItemStack ite
public static ItemStack makeItemValid(ItemStack invalid) {
if(invalid == null)
- return null;
+ return new ItemStack(Material.STONE);
ItemStack valid = invalid.clone();
if(valid.getDurability() < 0)
valid.setDurability((short) 0);
- if(valid.getData().getData() < 0)
- valid.getData().setData((byte) 0);
if(valid.getType() == null || valid.getType() == Material.PISTON_MOVING_PIECE)
valid.setType(Material.STONE);
+ if(valid.getData().getData() < 0)
+ valid.setData(new MaterialData(valid.getType().getId(), (byte) 0));
if(valid.getAmount() < 1)
valid.setAmount(1);

0 comments on commit d5867b6

Please sign in to comment.