diff --git a/src/main/java/mekanism/client/gui/GuiFactory.java b/src/main/java/mekanism/client/gui/GuiFactory.java index d41d80a3b..7ae50bad6 100644 --- a/src/main/java/mekanism/client/gui/GuiFactory.java +++ b/src/main/java/mekanism/client/gui/GuiFactory.java @@ -76,8 +76,8 @@ public class GuiFactory extends GuiMekanismTile { + ": " + tileEntity.gasTank.getStored() : LangUtils.localize("gui.none"), xAxis, yAxis); } else if (tileEntity.getRecipeType() == RecipeType.INFUSING) { drawHoveringText( - tileEntity.infuseStored.type != null ? tileEntity.infuseStored.type.getLocalizedName() + ": " - + tileEntity.infuseStored.amount : LangUtils.localize("gui.empty"), xAxis, yAxis); + tileEntity.infuseStored.getType() != null ? tileEntity.infuseStored.getType().getLocalizedName() + ": " + + tileEntity.infuseStored.getAmount() : LangUtils.localize("gui.empty"), xAxis, yAxis); } } super.drawGuiContainerForegroundLayer(mouseX, mouseY); @@ -116,7 +116,7 @@ public class GuiFactory extends GuiMekanismTile { } } else if (tileEntity.getRecipeType() == RecipeType.INFUSING) { if (tileEntity.getScaledInfuseLevel(160) > 0) { - displayGauge(8, 78, tileEntity.getScaledInfuseLevel(160), 5, tileEntity.infuseStored.type.sprite); + displayGauge(8, 78, tileEntity.getScaledInfuseLevel(160), 5, tileEntity.infuseStored.getType().sprite); } } super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); diff --git a/src/main/java/mekanism/client/gui/GuiMetallurgicInfuser.java b/src/main/java/mekanism/client/gui/GuiMetallurgicInfuser.java index a38276def..276e0fad1 100644 --- a/src/main/java/mekanism/client/gui/GuiMetallurgicInfuser.java +++ b/src/main/java/mekanism/client/gui/GuiMetallurgicInfuser.java @@ -71,8 +71,8 @@ public class GuiMetallurgicInfuser extends GuiMekanismTile= 7 && xAxis <= 11 && yAxis >= 17 && yAxis <= 69) { drawHoveringText( - tileEntity.infuseStored.type != null ? tileEntity.infuseStored.type.getLocalizedName() + ": " - + tileEntity.infuseStored.amount : LangUtils.localize("gui.empty"), xAxis, yAxis); + tileEntity.infuseStored.getType() != null ? tileEntity.infuseStored.getType().getLocalizedName() + ": " + + tileEntity.infuseStored.getAmount() : LangUtils.localize("gui.empty"), xAxis, yAxis); } super.drawGuiContainerForegroundLayer(mouseX, mouseY); } @@ -84,11 +84,11 @@ public class GuiMetallurgicInfuser extends GuiMekanismTile inputStacks = Collections.singletonList(recipe.recipeInput.inputStack); - List infuseStacks = MetallurgicInfuserRecipeCategory.getInfuseStacks(recipe.getInput().infuse.type); + List infuseStacks = MetallurgicInfuserRecipeCategory.getInfuseStacks(recipe.getInput().infuse.getType()); ingredients.setInput(VanillaTypes.ITEM, recipe.recipeInput.inputStack); ingredients.setInputLists(VanillaTypes.ITEM, Arrays.asList(inputStacks, infuseStacks)); ingredients.setOutput(VanillaTypes.ITEM, recipe.recipeOutput.output); @@ -37,7 +37,7 @@ public class MetallurgicInfuserRecipeWrapper implements IRecipeWrapper { public void drawInfo(Minecraft mc, int recipeWidth, int recipeHeight, int mouseX, int mouseY) { if (mc.currentScreen != null) { mc.renderEngine.bindTexture(MekanismRenderer.getBlocksTexture()); - mc.currentScreen.drawTexturedModalRect(2, 2, recipe.getInput().infuse.type.sprite, 4, 52); + mc.currentScreen.drawTexturedModalRect(2, 2, recipe.getInput().infuse.getType().sprite, 4, 52); } } @@ -45,7 +45,7 @@ public class MetallurgicInfuserRecipeWrapper implements IRecipeWrapper { public List getTooltipStrings(int mouseX, int mouseY) { if (mouseX >= 2 && mouseX < 6 && mouseY >= 2 && mouseY < 54) { InfuseStorage infuse = recipe.getInput().infuse; - return Collections.singletonList(infuse.type.getLocalizedName() + ": " + infuse.amount); + return Collections.singletonList(infuse.getType().getLocalizedName() + ": " + infuse.getAmount()); } return Collections.emptyList(); } diff --git a/src/main/java/mekanism/common/InfuseStorage.java b/src/main/java/mekanism/common/InfuseStorage.java index 4ccf5ba1a..263fc5937 100644 --- a/src/main/java/mekanism/common/InfuseStorage.java +++ b/src/main/java/mekanism/common/InfuseStorage.java @@ -1,5 +1,6 @@ package mekanism.common; +import mekanism.api.infuse.InfuseObject; import mekanism.api.infuse.InfuseRegistry; import mekanism.api.infuse.InfuseType; import mekanism.common.base.ISustainedData; @@ -8,9 +9,9 @@ import net.minecraft.item.ItemStack; public class InfuseStorage implements ISustainedData { - public InfuseType type; + private InfuseType type; - public int amount; + private int amount; public InfuseStorage() { } @@ -30,6 +31,32 @@ public class InfuseStorage implements ISustainedData { } else if (type == storage.type) { amount = 0; } + if (amount <= 0) { + type = null; + amount = 0; + } + } + + public void increase(InfuseStorage input) { + if (type == null) { + type = input.type; + amount = input.amount; + } else if (type == input.type) { + amount += input.amount; + } else { + Mekanism.logger.error("Tried to increase infusion storage with an incompatible type", new Exception()); + } + } + + public void increase(InfuseObject input) { + if (type == null) { + type = input.type; + amount = input.stored; + } else if (type == input.type) { + amount += input.stored; + } else { + Mekanism.logger.error("Tried to increase infusion storage with an incompatible type", new Exception()); + } } @Override @@ -52,4 +79,30 @@ public class InfuseStorage implements ISustainedData { amount = 0; } } -} + + public InfuseType getType() { + return amount == 0 ? null : type; + } + + public InfuseStorage setType(InfuseType type) { + this.type = type; + return this; + } + + public int getAmount() { + return type == null ? 0 : amount; + } + + public InfuseStorage setAmount(int amount) { + if (amount < 0) { + throw new IllegalArgumentException("Amount must be positive"); + } + this.amount = amount; + return this; + } + + public void setEmpty() { + this.amount = 0; + this.type = null; + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/base/IFactory.java b/src/main/java/mekanism/common/base/IFactory.java index d2b48331b..b2a2beb93 100644 --- a/src/main/java/mekanism/common/base/IFactory.java +++ b/src/main/java/mekanism/common/base/IFactory.java @@ -168,7 +168,7 @@ public interface IFactory { } else if (fuelType == MachineFuelType.CHANCE) { return getChanceRecipe(slotStack); } else if (this == INFUSING) { - if (infuse.type != null) { + if (infuse.getType() != null) { return RecipeHandler.getMetallurgicInfuserRecipe(new InfusionInput(infuse, slotStack)); } else { for (Entry entry : Recipe.METALLURGIC_INFUSER.get() diff --git a/src/main/java/mekanism/common/integration/crafttweaker/commands/MekRecipesCommand.java b/src/main/java/mekanism/common/integration/crafttweaker/commands/MekRecipesCommand.java index 02cdc0342..2357ce1f8 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/commands/MekRecipesCommand.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/commands/MekRecipesCommand.java @@ -173,8 +173,8 @@ public class MekRecipesCommand extends CraftTweakerCommand { type = Recipe.METALLURGIC_INFUSER; for (MetallurgicInfuserRecipe recipe : Recipe.METALLURGIC_INFUSER.get().values()) { CraftTweakerAPI.logCommand(String.format("mods.mekanism.infuser.addRecipe(%s, %s, %s, %s)", - recipe.getInput().infuse.type, - recipe.getInput().infuse.amount, + recipe.getInput().infuse.getType(), + recipe.getInput().infuse.getAmount(), RecipeInfoHelper.getItemName(recipe.getInput().inputStack), RecipeInfoHelper.getItemName(recipe.getOutput().output) )); diff --git a/src/main/java/mekanism/common/integration/crafttweaker/helpers/IngredientHelper.java b/src/main/java/mekanism/common/integration/crafttweaker/helpers/IngredientHelper.java index 5e0162bfe..552d9949b 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/helpers/IngredientHelper.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/helpers/IngredientHelper.java @@ -110,7 +110,7 @@ public class IngredientHelper { } else if (in instanceof InfusionInput) { InfusionInput input = (InfusionInput) in; return matches(input.inputStack, toMatch.getIngredient()) && (toMatch.getInfuseType().isEmpty() || toMatch - .getInfuseType().equalsIgnoreCase(input.infuse.type.name)); + .getInfuseType().equalsIgnoreCase(input.infuse.getType().name)); } else if (in instanceof IntegerInput) { IntegerInput input = (IntegerInput) in; return input.ingredient == toMatch.getAmount(); diff --git a/src/main/java/mekanism/common/inventory/container/ContainerFactory.java b/src/main/java/mekanism/common/inventory/container/ContainerFactory.java index 77d1bc982..5be7dab36 100644 --- a/src/main/java/mekanism/common/inventory/container/ContainerFactory.java +++ b/src/main/java/mekanism/common/inventory/container/ContainerFactory.java @@ -109,7 +109,7 @@ public class ContainerFactory extends ContainerMekanism { return ItemStack.EMPTY; } } else if (tileEntity.getRecipeType() == RecipeType.INFUSING && InfuseRegistry.getObject(slotStack) != null - && (tileEntity.infuseStored.type == null || tileEntity.infuseStored.type == InfuseRegistry + && (tileEntity.infuseStored.getType() == null || tileEntity.infuseStored.getType() == InfuseRegistry .getObject(slotStack).type)) { if (transferExtraSlot(slotID, slotStack)) { return ItemStack.EMPTY; diff --git a/src/main/java/mekanism/common/inventory/container/ContainerMetallurgicInfuser.java b/src/main/java/mekanism/common/inventory/container/ContainerMetallurgicInfuser.java index bf76723b8..80228a1ac 100644 --- a/src/main/java/mekanism/common/inventory/container/ContainerMetallurgicInfuser.java +++ b/src/main/java/mekanism/common/inventory/container/ContainerMetallurgicInfuser.java @@ -31,8 +31,8 @@ public class ContainerMetallurgicInfuser extends ContainerMekanism { public ItemStack inputStack = ItemStack.EMPTY; public InfusionInput(InfuseStorage storage, ItemStack itemStack) { - infuse = new InfuseStorage(storage.type, storage.amount); + infuse = new InfuseStorage(storage.getType(), storage.getAmount()); inputStack = itemStack; } @@ -47,12 +47,12 @@ public class InfusionInput extends MachineInput { @Override public InfusionInput copy() { - return new InfusionInput(infuse.type, infuse.amount, inputStack.copy()); + return new InfusionInput(infuse.getType(), infuse.getAmount(), inputStack.copy()); } @Override public boolean isValid() { - return infuse.type != null && !inputStack.isEmpty(); + return infuse.getType() != null && !inputStack.isEmpty(); } public boolean use(NonNullList inventory, int index, InfuseStorage infuseStorage, boolean deplete) { @@ -70,7 +70,7 @@ public class InfusionInput extends MachineInput { @Override public int hashIngredients() { - return infuse.type.unlocalizedName.hashCode() << 8 | StackUtils.hashItemStack(inputStack); + return infuse.getType().unlocalizedName.hashCode() << 8 | StackUtils.hashItemStack(inputStack); } @Override @@ -79,7 +79,7 @@ public class InfusionInput extends MachineInput { return !other.isValid(); } - return infuse.type == other.infuse.type && MachineInput.inputItemMatches(inputStack, other.inputStack); + return infuse.getType() == other.infuse.getType() && MachineInput.inputItemMatches(inputStack, other.inputStack); } @Override diff --git a/src/main/java/mekanism/common/tile/TileEntityFactory.java b/src/main/java/mekanism/common/tile/TileEntityFactory.java index 98fec4c5c..65ebb0ea8 100644 --- a/src/main/java/mekanism/common/tile/TileEntityFactory.java +++ b/src/main/java/mekanism/common/tile/TileEntityFactory.java @@ -342,11 +342,6 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt } } - if (infuseStored.amount <= 0) { - infuseStored.amount = 0; - infuseStored.type = null; - } - lastUsage = prev - getEnergy(); prevEnergy = getEnergy(); } @@ -479,7 +474,7 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt }*/ else if (cached.recipeInput instanceof InfusionInput) { InfusionInput infusionInput = (InfusionInput) cached.recipeInput; recipeInput = infusionInput.inputStack; - secondaryMatch = infuseStored.amount == 0 || infuseStored.type == infusionInput.infuse.type; + secondaryMatch = infuseStored.getAmount() == 0 || infuseStored.getType() == infusionInput.infuse.getType(); } //If there is no cached item input or it doesn't match our fallback // then it is an out of date cache so we compare against the new one @@ -536,13 +531,11 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt inventory.get(4).shrink(1); } } else if (recipeType == RecipeType.INFUSING) { - if (InfuseRegistry.getObject(inventory.get(4)) != null) { - InfuseObject infuse = InfuseRegistry.getObject(inventory.get(4)); - - if (infuseStored.type == null || infuseStored.type == infuse.type) { - if (infuseStored.amount + infuse.stored <= maxInfuse) { - infuseStored.amount += infuse.stored; - infuseStored.type = infuse.type; + InfuseObject pendingInfusionInput = InfuseRegistry.getObject(inventory.get(4)); + if (pendingInfusionInput != null) { + if (infuseStored.getType() == null || infuseStored.getType() == pendingInfusionInput.type) { + if (infuseStored.getAmount() + pendingInfusionInput.stored <= maxInfuse) { + infuseStored.increase(pendingInfusionInput); inventory.get(4).shrink(1); } } @@ -620,8 +613,8 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt } else if (recipeType.getFuelType() == MachineFuelType.DOUBLE) { return recipeType.hasRecipeForExtra(itemstack); } else if (recipeType == RecipeType.INFUSING) { - return InfuseRegistry.getObject(itemstack) != null && (infuseStored.type == null - || infuseStored.type == InfuseRegistry.getObject(itemstack).type); + return InfuseRegistry.getObject(itemstack) != null && (infuseStored.getType() == null + || infuseStored.getType() == InfuseRegistry.getObject(itemstack).type); } } @@ -633,7 +626,7 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt } public int getScaledInfuseLevel(int i) { - return infuseStored.amount * i / maxInfuse; + return infuseStored.getAmount() * i / maxInfuse; } public int getScaledGasLevel(int i) { @@ -765,8 +758,7 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt sorting = !sorting; } else if (type == 1) { gasTank.setGas(null); - infuseStored.amount = 0; - infuseStored.type = null; + infuseStored.setEmpty(); } return; @@ -782,9 +774,12 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt sorting = dataStream.readBoolean(); upgraded = dataStream.readBoolean(); lastUsage = dataStream.readDouble(); - infuseStored.amount = dataStream.readInt(); - if (infuseStored.amount > 0) { - infuseStored.type = InfuseRegistry.get(PacketHandler.readString(dataStream)); + int amount = dataStream.readInt(); + if (amount > 0) { + infuseStored.setAmount(amount); + infuseStored.setType(InfuseRegistry.get(PacketHandler.readString(dataStream))); + } else { + infuseStored.setEmpty(); } if (recipeType != oldRecipe) { @@ -816,8 +811,11 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt upgradeComponent.setSupported(Upgrade.GAS, recipeType.fuelEnergyUpgrades()); recipeTicks = nbtTags.getInteger("recipeTicks"); sorting = nbtTags.getBoolean("sorting"); - infuseStored.amount = nbtTags.getInteger("infuseStored"); - infuseStored.type = InfuseRegistry.get(nbtTags.getString("type")); + int amount = nbtTags.getInteger("infuseStored"); + if (amount != 0) { + infuseStored.setAmount(amount); + infuseStored.setType(InfuseRegistry.get(nbtTags.getString("type"))); + } for (int i = 0; i < tier.processes; i++) { progress[i] = nbtTags.getInteger("progress" + i); @@ -834,10 +832,9 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt nbtTags.setInteger("recipeType", recipeType.ordinal()); nbtTags.setInteger("recipeTicks", recipeTicks); nbtTags.setBoolean("sorting", sorting); - nbtTags.setInteger("infuseStored", infuseStored.amount); - - if (infuseStored.type != null) { - nbtTags.setString("type", infuseStored.type.name); + if (infuseStored.getType() != null) { + nbtTags.setString("type", infuseStored.getType().name); + nbtTags.setInteger("infuseStored", infuseStored.getAmount()); } else { nbtTags.setString("type", "null"); } @@ -861,9 +858,9 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt data.add(upgraded); data.add(lastUsage); - data.add(infuseStored.amount); - if (infuseStored.amount > 0) { - data.add(infuseStored.type.name); + data.add(infuseStored.getAmount()); + if (infuseStored.getAmount() > 0) { + data.add(infuseStored.getType().name); } data.add(progress); diff --git a/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java b/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java index 28e78d05a..25eec1ccb 100644 --- a/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java +++ b/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java @@ -87,13 +87,11 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i ChargeUtils.discharge(4, this); if (!inventory.get(1).isEmpty()) { - if (InfuseRegistry.getObject(inventory.get(1)) != null) { - InfuseObject infuse = InfuseRegistry.getObject(inventory.get(1)); - - if (infuseStored.type == null || infuseStored.type == infuse.type) { - if (infuseStored.amount + infuse.stored <= MAX_INFUSE) { - infuseStored.amount += infuse.stored; - infuseStored.type = infuse.type; + InfuseObject pendingInfuseInput = InfuseRegistry.getObject(inventory.get(1)); + if (pendingInfuseInput != null) { + if (infuseStored.getType() == null || infuseStored.getType() == pendingInfuseInput.type) { + if (infuseStored.getAmount() + pendingInfuseInput.stored <= MAX_INFUSE) { + infuseStored.increase(pendingInfuseInput); inventory.get(1).shrink(1); } } @@ -122,11 +120,6 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i operatingTicks = 0; } - if (infuseStored.amount <= 0) { - infuseStored.amount = 0; - infuseStored.type = null; - } - prevEnergy = getEnergy(); } } @@ -207,13 +200,13 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i if (slotID == 3) { return false; } else if (slotID == 1) { - return InfuseRegistry.getObject(itemstack) != null && (infuseStored.type == null - || infuseStored.type == InfuseRegistry.getObject(itemstack).type); + return InfuseRegistry.getObject(itemstack) != null && (infuseStored.getType() == null + || infuseStored.getType() == InfuseRegistry.getObject(itemstack).type); } else if (slotID == 0) { return itemstack.getItem() == MekanismItems.SpeedUpgrade || itemstack.getItem() == MekanismItems.EnergyUpgrade; } else if (slotID == 2) { - if (infuseStored.type != null) { + if (infuseStored.getType() != null) { return RecipeHandler.getMetallurgicInfuserRecipe(new InfusionInput(infuseStored, itemstack)) != null; } else { return Recipe.METALLURGIC_INFUSER.get().keySet().stream() @@ -242,15 +235,18 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i } public int getScaledInfuseLevel(int i) { - return infuseStored.amount * i / MAX_INFUSE; + return infuseStored.getAmount() * i / MAX_INFUSE; } @Override public void readFromNBT(NBTTagCompound nbtTags) { super.readFromNBT(nbtTags); - infuseStored.amount = nbtTags.getInteger("infuseStored"); - infuseStored.type = InfuseRegistry.get(nbtTags.getString("type")); + int amount = nbtTags.getInteger("infuseStored"); + if (amount != 0) { + infuseStored.setAmount(amount); + infuseStored.setType(InfuseRegistry.get(nbtTags.getString("type"))); + } } @Nonnull @@ -258,10 +254,9 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i public NBTTagCompound writeToNBT(NBTTagCompound nbtTags) { super.writeToNBT(nbtTags); - nbtTags.setInteger("infuseStored", infuseStored.amount); - - if (infuseStored.type != null) { - nbtTags.setString("type", infuseStored.type.name); + if (infuseStored.getType() != null) { + nbtTags.setString("type", infuseStored.getType().name); + nbtTags.setInteger("infuseStored", infuseStored.getAmount()); } else { nbtTags.setString("type", "null"); } @@ -274,16 +269,19 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i @Override public void handlePacketData(ByteBuf dataStream) { if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { - infuseStored.amount = dataStream.readInt(); + infuseStored.setAmount(dataStream.readInt()); return; } super.handlePacketData(dataStream); if (FMLCommonHandler.instance().getEffectiveSide().isClient()) { - infuseStored.amount = dataStream.readInt(); - if (infuseStored.amount > 0) { - infuseStored.type = InfuseRegistry.get(PacketHandler.readString(dataStream)); + int amount = dataStream.readInt(); + if (amount > 0) { + infuseStored.setAmount(amount); + infuseStored.setType(InfuseRegistry.get(PacketHandler.readString(dataStream))); + } else { + infuseStored.setEmpty(); } } } @@ -292,9 +290,9 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i public TileNetworkList getNetworkedData(TileNetworkList data) { super.getNetworkedData(data); - data.add(infuseStored.amount); - if (infuseStored.amount > 0) { - data.add(infuseStored.type.name); + data.add(infuseStored.getAmount()); + if (infuseStored.getAmount() > 0) { + data.add(infuseStored.getType().name); } return data; @@ -323,7 +321,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i case 6: return new Object[]{infuseStored}; case 7: - return new Object[]{MAX_INFUSE - infuseStored.amount}; + return new Object[]{MAX_INFUSE - infuseStored.getAmount()}; default: throw new NoSuchMethodException(); } diff --git a/src/main/resources/assets/mekanism/gui/guimetallurgicinfuser.png b/src/main/resources/assets/mekanism/gui/guimetallurgicinfuser.png index a8d748691..df1edd647 100644 Binary files a/src/main/resources/assets/mekanism/gui/guimetallurgicinfuser.png and b/src/main/resources/assets/mekanism/gui/guimetallurgicinfuser.png differ