Upgraded gas item recipe integration greatly, should make things much smoother.
This commit is contained in:
parent
377fff30ca
commit
63970a29ea
12 changed files with 124 additions and 29 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -297,7 +297,7 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, IE
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isMetadataSpecific()
|
||||
public boolean isMetadataSpecific(ItemStack itemStack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -271,4 +271,10 @@ public class ItemBlockGasTank extends ItemBlock implements IGasItem, ISustainedI
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMetadataSpecific(ItemStack itemStack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1062,7 +1062,7 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isMetadataSpecific()
|
||||
public boolean isMetadataSpecific(ItemStack itemStack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -208,7 +208,7 @@ public class ItemEnergized extends ItemMekanism implements IEnergizedItem, ISpec
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isMetadataSpecific()
|
||||
public boolean isMetadataSpecific(ItemStack itemStack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -247,7 +247,7 @@ public class ItemFreeRunners extends ItemArmor implements IEnergizedItem, ISpeci
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isMetadataSpecific()
|
||||
public boolean isMetadataSpecific(ItemStack itemStack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -406,7 +406,7 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, ISp
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isMetadataSpecific()
|
||||
public boolean isMetadataSpecific(ItemStack itemStack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue