diff --git a/src/main/java/mekanism/api/energy/IEnergizedItem.java b/src/main/java/mekanism/api/energy/IEnergizedItem.java index 5b784de70..b67254597 100644 --- a/src/main/java/mekanism/api/energy/IEnergizedItem.java +++ b/src/main/java/mekanism/api/energy/IEnergizedItem.java @@ -55,5 +55,5 @@ public interface IEnergizedItem * Returns whether or not this item contains metadata-specific subtypes instead of using metadata for damage display. * @return if the item contains metadata-specific subtypes */ - public boolean isMetadataSpecific(); + public boolean isMetadataSpecific(ItemStack itemStack); } diff --git a/src/main/java/mekanism/api/gas/IGasItem.java b/src/main/java/mekanism/api/gas/IGasItem.java index 04231cd81..9c7d33230 100644 --- a/src/main/java/mekanism/api/gas/IGasItem.java +++ b/src/main/java/mekanism/api/gas/IGasItem.java @@ -72,4 +72,10 @@ public interface IGasItem * @return maximum gas */ public int getMaxGas(ItemStack itemstack); + + /** + * Returns whether or not this item contains metadata-specific subtypes instead of using metadata for damage display. + * @return if the item contains metadata-specific subtypes + */ + public boolean isMetadataSpecific(ItemStack itemstack); } diff --git a/src/main/java/mekanism/client/nei/MekanismRecipeHandler.java b/src/main/java/mekanism/client/nei/MekanismRecipeHandler.java index cdb1df989..78f373cc7 100644 --- a/src/main/java/mekanism/client/nei/MekanismRecipeHandler.java +++ b/src/main/java/mekanism/client/nei/MekanismRecipeHandler.java @@ -5,6 +5,7 @@ import java.util.Collection; import java.util.List; import mekanism.api.energy.IEnergizedItem; +import mekanism.api.gas.IGasItem; import mekanism.common.IEnergyCube; import mekanism.common.IFactory; import mekanism.common.block.BlockMachine.MachineType; @@ -13,6 +14,7 @@ import mekanism.common.util.MekanismUtils; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; +import net.minecraftforge.oredict.OreDictionary; import codechicken.nei.PositionedStack; import codechicken.nei.recipe.ShapedRecipeHandler; @@ -83,50 +85,64 @@ public class MekanismRecipeHandler extends ShapedRecipeHandler } } - public static boolean areItemsEqual(ItemStack stack1, ItemStack stack2) + public static boolean areItemsEqual(ItemStack target, ItemStack input) { - if(stack1 == null && stack2 != null || stack1 != null && stack2 == null) + if(target == null && input != null || target != null && input == null) { return false; } - else if(stack1 == null && stack2 == null) + else if(target == null && input == null) { return true; } - if(stack1.getItem() != stack2.getItem()) + if(target.getItem() != input.getItem()) { return false; } - if(!(stack1.getItem() instanceof IEnergizedItem) && !(stack2.getItem() instanceof IEnergizedItem)) + if(!(target.getItem() instanceof IEnergizedItem) && !(input.getItem() instanceof IEnergizedItem) && !(target.getItem() instanceof IGasItem) && !(input.getItem() instanceof IGasItem)) { - if(stack1.getItemDamage() != stack2.getItemDamage()) + if(target.getItemDamage() != input.getItemDamage() && target.getItemDamage() != OreDictionary.WILDCARD_VALUE) { return false; } } else { - if(((IEnergizedItem)stack1.getItem()).isMetadataSpecific() && ((IEnergizedItem)stack2.getItem()).isMetadataSpecific()) + if(target.getItem() instanceof IEnergizedItem && input.getItem() instanceof IEnergizedItem) { - if(stack1.getItemDamage() != stack2.getItemDamage()) + if(((IEnergizedItem)target.getItem()).isMetadataSpecific(target) && ((IEnergizedItem)input.getItem()).isMetadataSpecific(input)) { - return false; + if(target.getItemDamage() != input.getItemDamage() && target.getItemDamage() != OreDictionary.WILDCARD_VALUE) + { + return false; + } + } + } + + if(target.getItem() instanceof IGasItem && input.getItem() instanceof IGasItem) + { + if(((IGasItem)target.getItem()).isMetadataSpecific(target) && ((IGasItem)input.getItem()).isMetadataSpecific(input)) + { + if(target.getItemDamage() != input.getItemDamage() && target.getItemDamage() != OreDictionary.WILDCARD_VALUE) + { + return false; + } } } - if(stack1.getItem() instanceof IEnergyCube && stack2.getItem() instanceof IEnergyCube) + if(target.getItem() instanceof IEnergyCube && input.getItem() instanceof IEnergyCube) { - if(((IEnergyCube)stack1.getItem()).getEnergyCubeTier(stack1) != ((IEnergyCube)stack2.getItem()).getEnergyCubeTier(stack2)) + if(((IEnergyCube)target.getItem()).getEnergyCubeTier(target) != ((IEnergyCube)input.getItem()).getEnergyCubeTier(input)) { return false; } } - else if(stack1.getItem() instanceof IFactory && stack2.getItem() instanceof IFactory) + else if(target.getItem() instanceof IFactory && input.getItem() instanceof IFactory) { - if(isFactory(stack1) && isFactory(stack2)) + if(isFactory(target) && isFactory(input)) { - if(((IFactory)stack1.getItem()).getRecipeType(stack1) != ((IFactory)stack2.getItem()).getRecipeType(stack2)) + if(((IFactory)target.getItem()).getRecipeType(target) != ((IFactory)input.getItem()).getRecipeType(input)) { return false; } diff --git a/src/main/java/mekanism/common/item/ItemBlockEnergyCube.java b/src/main/java/mekanism/common/item/ItemBlockEnergyCube.java index fd18c495c..0db6c6306 100644 --- a/src/main/java/mekanism/common/item/ItemBlockEnergyCube.java +++ b/src/main/java/mekanism/common/item/ItemBlockEnergyCube.java @@ -297,7 +297,7 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, IE } @Override - public boolean isMetadataSpecific() + public boolean isMetadataSpecific(ItemStack itemStack) { return false; } diff --git a/src/main/java/mekanism/common/item/ItemBlockGasTank.java b/src/main/java/mekanism/common/item/ItemBlockGasTank.java index 53483d91c..ccc49843a 100644 --- a/src/main/java/mekanism/common/item/ItemBlockGasTank.java +++ b/src/main/java/mekanism/common/item/ItemBlockGasTank.java @@ -271,4 +271,10 @@ public class ItemBlockGasTank extends ItemBlock implements IGasItem, ISustainedI return null; } + + @Override + public boolean isMetadataSpecific(ItemStack itemStack) + { + return false; + } } diff --git a/src/main/java/mekanism/common/item/ItemBlockMachine.java b/src/main/java/mekanism/common/item/ItemBlockMachine.java index ca77c099b..cf58f8e56 100644 --- a/src/main/java/mekanism/common/item/ItemBlockMachine.java +++ b/src/main/java/mekanism/common/item/ItemBlockMachine.java @@ -1062,7 +1062,7 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec } @Override - public boolean isMetadataSpecific() + public boolean isMetadataSpecific(ItemStack itemStack) { return true; } diff --git a/src/main/java/mekanism/common/item/ItemEnergized.java b/src/main/java/mekanism/common/item/ItemEnergized.java index a096e0c96..e134f4c1a 100644 --- a/src/main/java/mekanism/common/item/ItemEnergized.java +++ b/src/main/java/mekanism/common/item/ItemEnergized.java @@ -208,7 +208,7 @@ public class ItemEnergized extends ItemMekanism implements IEnergizedItem, ISpec } @Override - public boolean isMetadataSpecific() + public boolean isMetadataSpecific(ItemStack itemStack) { return false; } diff --git a/src/main/java/mekanism/common/item/ItemFreeRunners.java b/src/main/java/mekanism/common/item/ItemFreeRunners.java index 9b4f15331..e54bf4760 100644 --- a/src/main/java/mekanism/common/item/ItemFreeRunners.java +++ b/src/main/java/mekanism/common/item/ItemFreeRunners.java @@ -247,7 +247,7 @@ public class ItemFreeRunners extends ItemArmor implements IEnergizedItem, ISpeci } @Override - public boolean isMetadataSpecific() + public boolean isMetadataSpecific(ItemStack itemStack) { return false; } diff --git a/src/main/java/mekanism/common/item/ItemJetpack.java b/src/main/java/mekanism/common/item/ItemJetpack.java index 30828c42c..5814587a2 100644 --- a/src/main/java/mekanism/common/item/ItemJetpack.java +++ b/src/main/java/mekanism/common/item/ItemJetpack.java @@ -184,6 +184,12 @@ public class ItemJetpack extends ItemArmor implements IGasItem, ISpecialArmor return stored; } + + @Override + public boolean isMetadataSpecific(ItemStack itemStack) + { + return false; + } public JetpackMode getMode(ItemStack stack) { diff --git a/src/main/java/mekanism/common/item/ItemScubaTank.java b/src/main/java/mekanism/common/item/ItemScubaTank.java index d5ebff70b..7a830ed55 100644 --- a/src/main/java/mekanism/common/item/ItemScubaTank.java +++ b/src/main/java/mekanism/common/item/ItemScubaTank.java @@ -218,6 +218,12 @@ public class ItemScubaTank extends ItemArmor implements IGasItem itemstack.stackTagCompound.setTag("stored", gasStack.write(new NBTTagCompound())); } } + + @Override + public boolean isMetadataSpecific(ItemStack itemStack) + { + return false; + } public ItemStack getEmptyItem() { diff --git a/src/main/java/mekanism/common/recipe/MekanismRecipe.java b/src/main/java/mekanism/common/recipe/MekanismRecipe.java index 801a6afd7..93f265090 100644 --- a/src/main/java/mekanism/common/recipe/MekanismRecipe.java +++ b/src/main/java/mekanism/common/recipe/MekanismRecipe.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.HashMap; import mekanism.api.energy.IEnergizedItem; +import mekanism.api.gas.GasStack; +import mekanism.api.gas.IGasItem; import mekanism.common.IEnergyCube; import mekanism.common.IFactory; import mekanism.common.IUpgradeManagement; @@ -148,17 +150,56 @@ public class MekanismRecipe implements IRecipe { ItemStack itemstack = inv.getStackInSlot(i); - if(itemstack != null) + if(itemstack != null && itemstack.getItem() instanceof IEnergizedItem) { - if(itemstack.getItem() instanceof IEnergizedItem) - { - energyFound += ((IEnergizedItem)itemstack.getItem()).getEnergy(itemstack); - } + energyFound += ((IEnergizedItem)itemstack.getItem()).getEnergy(itemstack); } } ((IEnergizedItem)toReturn.getItem()).setEnergy(toReturn, Math.min(((IEnergizedItem)toReturn.getItem()).getMaxEnergy(toReturn), energyFound)); } + + if(toReturn.getItem() instanceof IGasItem) + { + GasStack gasFound = null; + + for(int i = 0; i < 9; i++) + { + ItemStack itemstack = inv.getStackInSlot(i); + + if(itemstack != null && itemstack.getItem() instanceof IGasItem) + { + GasStack stored = ((IGasItem)itemstack.getItem()).getGas(itemstack); + + if(stored != null) + { + if(!((IGasItem)toReturn.getItem()).canReceiveGas(toReturn, stored.getGas())) + { + return null; + } + + if(gasFound == null) + { + gasFound = stored; + } + else { + if(gasFound.getGas() != stored.getGas()) + { + return null; + } + + gasFound.amount += stored.amount; + } + } + } + } + + if(gasFound != null) + { + gasFound.amount = Math.min(((IGasItem)toReturn.getItem()).getMaxGas(toReturn), gasFound.amount); + ((IGasItem)toReturn.getItem()).setGas(toReturn, gasFound); + } + } if(toReturn.getItem() instanceof IUpgradeManagement && ((IUpgradeManagement)toReturn.getItem()).supportsUpgrades(toReturn)) { @@ -290,7 +331,7 @@ public class MekanismRecipe implements IRecipe return false; } - if(!(target.getItem() instanceof IEnergizedItem) && !(input.getItem() instanceof IEnergizedItem)) + if(!(target.getItem() instanceof IEnergizedItem) && !(input.getItem() instanceof IEnergizedItem) && !(target.getItem() instanceof IGasItem) && !(input.getItem() instanceof IGasItem)) { if(target.getItemDamage() != input.getItemDamage() && target.getItemDamage() != OreDictionary.WILDCARD_VALUE) { @@ -298,11 +339,25 @@ public class MekanismRecipe implements IRecipe } } else { - if(((IEnergizedItem)target.getItem()).isMetadataSpecific() && ((IEnergizedItem)input.getItem()).isMetadataSpecific()) + if(target.getItem() instanceof IEnergizedItem && input.getItem() instanceof IEnergizedItem) { - if(target.getItemDamage() != input.getItemDamage() && target.getItemDamage() != OreDictionary.WILDCARD_VALUE) + if(((IEnergizedItem)target.getItem()).isMetadataSpecific(target) && ((IEnergizedItem)input.getItem()).isMetadataSpecific(input)) { - return false; + if(target.getItemDamage() != input.getItemDamage() && target.getItemDamage() != OreDictionary.WILDCARD_VALUE) + { + return false; + } + } + } + + if(target.getItem() instanceof IGasItem && input.getItem() instanceof IGasItem) + { + if(((IGasItem)target.getItem()).isMetadataSpecific(target) && ((IGasItem)input.getItem()).isMetadataSpecific(input)) + { + if(target.getItemDamage() != input.getItemDamage() && target.getItemDamage() != OreDictionary.WILDCARD_VALUE) + { + return false; + } } } diff --git a/src/main/java/mekanism/generators/common/item/ItemBlockGenerator.java b/src/main/java/mekanism/generators/common/item/ItemBlockGenerator.java index 8db4b54ac..b77d80072 100644 --- a/src/main/java/mekanism/generators/common/item/ItemBlockGenerator.java +++ b/src/main/java/mekanism/generators/common/item/ItemBlockGenerator.java @@ -406,7 +406,7 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, ISp } @Override - public boolean isMetadataSpecific() + public boolean isMetadataSpecific(ItemStack itemStack) { return true; }