Cleanup a bit of infusion code (#5493)

* Cleanup a bit of infusion code

* Empty item stacks already return 0 for their count

* Go back to not assuming null and empty tag are the same

* Reorder which order the arguments are passed to equalsWildcard for consistency with the rest of the class as it is a symmetrical method anyways
This commit is contained in:
Richard Freimer authored and GitHub committed 2019-05-27 12:51:50 -04:00
1 parent eb2de11b72
commit 72951d2c66
7 files changed
+54 -40

No files matched your search

+34 -26
View File
@@ -455,18 +455,41 @@ public class Mekanism {
RecipeHandler.addPrecisionSawmillRecipe(new ItemStack(Blocks.CRAFTING_TABLE), new ItemStack(Blocks.PLANKS, 4));
}
//Metallurgic Infuser Recipes
if (MekanismConfig.current().general.machinesManager.isEnabled(MachineType.METALLURGIC_INFUSER)) {
RecipeHandler.addMetallurgicInfuserRecipe(InfuseRegistry.get("CARBON"), 10, new ItemStack(Items.IRON_INGOT), new ItemStack(MekanismItems.EnrichedIron));
RecipeHandler.addMetallurgicInfuserRecipe(InfuseRegistry.get("CARBON"), 10, new ItemStack(MekanismItems.EnrichedIron), new ItemStack(MekanismItems.OtherDust, 1, 1));
RecipeHandler.addMetallurgicInfuserRecipe(InfuseRegistry.get("REDSTONE"), 10, new ItemStack(Items.IRON_INGOT), new ItemStack(MekanismItems.EnrichedAlloy));
RecipeHandler.addMetallurgicInfuserRecipe(InfuseRegistry.get("FUNGI"), 10, new ItemStack(Blocks.DIRT), new ItemStack(Blocks.MYCELIUM));
RecipeHandler.addMetallurgicInfuserRecipe(InfuseRegistry.get("BIO"), 10, new ItemStack(Blocks.COBBLESTONE), new ItemStack(Blocks.MOSSY_COBBLESTONE));
RecipeHandler.addMetallurgicInfuserRecipe(InfuseRegistry.get("BIO"), 10, new ItemStack(Blocks.STONEBRICK, 1, 0), new ItemStack(Blocks.STONEBRICK, 1, 1));
RecipeHandler.addMetallurgicInfuserRecipe(InfuseRegistry.get("BIO"), 10, new ItemStack(Blocks.SAND), new ItemStack(Blocks.DIRT));
RecipeHandler.addMetallurgicInfuserRecipe(InfuseRegistry.get("BIO"), 10, new ItemStack(Blocks.DIRT), new ItemStack(Blocks.DIRT, 1, 2));
RecipeHandler.addMetallurgicInfuserRecipe(InfuseRegistry.get("DIAMOND"), 10, new ItemStack(MekanismItems.EnrichedAlloy), new ItemStack(MekanismItems.ReinforcedAlloy));
RecipeHandler.addMetallurgicInfuserRecipe(InfuseRegistry.get("OBSIDIAN"), 10, new ItemStack(MekanismItems.ReinforcedAlloy), new ItemStack(MekanismItems.AtomicAlloy));
InfuseType carbon = InfuseRegistry.get("CARBON");
InfuseType bio = InfuseRegistry.get("BIO");
InfuseType redstone = InfuseRegistry.get("REDSTONE");
InfuseType fungi = InfuseRegistry.get("FUNGI");
InfuseType diamond = InfuseRegistry.get("DIAMOND");
InfuseType obsidian = InfuseRegistry.get("OBSIDIAN");
//Infuse objects
InfuseRegistry.registerInfuseObject(new ItemStack(MekanismItems.BioFuel), new InfuseObject(bio, 5));
InfuseRegistry.registerInfuseObject(new ItemStack(Items.COAL, 1, 0), new InfuseObject(carbon, 10));
InfuseRegistry.registerInfuseObject(new ItemStack(Items.COAL, 1, 1), new InfuseObject(carbon, 20));
InfuseRegistry.registerInfuseObject(new ItemStack(Blocks.COAL_BLOCK, 1, 0), new InfuseObject(carbon, 90));
InfuseRegistry.registerInfuseObject(new ItemStack(MekanismBlocks.BasicBlock, 1, 3), new InfuseObject(carbon, 180));
InfuseRegistry.registerInfuseObject(new ItemStack(MekanismItems.CompressedCarbon), new InfuseObject(carbon, 80));
InfuseRegistry.registerInfuseObject(new ItemStack(Items.REDSTONE), new InfuseObject(redstone, 10));
InfuseRegistry.registerInfuseObject(new ItemStack(Blocks.REDSTONE_BLOCK), new InfuseObject(redstone, 90));
InfuseRegistry.registerInfuseObject(new ItemStack(MekanismItems.CompressedRedstone), new InfuseObject(redstone, 80));
InfuseRegistry.registerInfuseObject(new ItemStack(Blocks.RED_MUSHROOM), new InfuseObject(fungi, 10));
InfuseRegistry.registerInfuseObject(new ItemStack(Blocks.BROWN_MUSHROOM), new InfuseObject(fungi, 10));
InfuseRegistry.registerInfuseObject(new ItemStack(MekanismItems.CompressedDiamond), new InfuseObject(diamond, 80));
InfuseRegistry.registerInfuseObject(new ItemStack(MekanismItems.CompressedObsidian), new InfuseObject(obsidian, 80));
//Metallurgic Infuser Recipes
RecipeHandler.addMetallurgicInfuserRecipe(carbon, 10, new ItemStack(Items.IRON_INGOT), new ItemStack(MekanismItems.EnrichedIron));
RecipeHandler.addMetallurgicInfuserRecipe(carbon, 10, new ItemStack(MekanismItems.EnrichedIron), new ItemStack(MekanismItems.OtherDust, 1, 1));
RecipeHandler.addMetallurgicInfuserRecipe(redstone, 10, new ItemStack(Items.IRON_INGOT), new ItemStack(MekanismItems.EnrichedAlloy));
RecipeHandler.addMetallurgicInfuserRecipe(fungi, 10, new ItemStack(Blocks.DIRT), new ItemStack(Blocks.MYCELIUM));
RecipeHandler.addMetallurgicInfuserRecipe(bio, 10, new ItemStack(Blocks.COBBLESTONE), new ItemStack(Blocks.MOSSY_COBBLESTONE));
RecipeHandler.addMetallurgicInfuserRecipe(bio, 10, new ItemStack(Blocks.STONEBRICK, 1, 0), new ItemStack(Blocks.STONEBRICK, 1, 1));
RecipeHandler.addMetallurgicInfuserRecipe(bio, 10, new ItemStack(Blocks.SAND), new ItemStack(Blocks.DIRT));
RecipeHandler.addMetallurgicInfuserRecipe(bio, 10, new ItemStack(Blocks.DIRT), new ItemStack(Blocks.DIRT, 1, 2));
RecipeHandler.addMetallurgicInfuserRecipe(diamond, 10, new ItemStack(MekanismItems.EnrichedAlloy), new ItemStack(MekanismItems.ReinforcedAlloy));
RecipeHandler.addMetallurgicInfuserRecipe(obsidian, 10, new ItemStack(MekanismItems.ReinforcedAlloy), new ItemStack(MekanismItems.AtomicAlloy));
}
//Chemical Infuser Recipes
@@ -528,21 +551,6 @@ public class Mekanism {
RecipeHandler.addSolarNeutronRecipe(new GasStack(MekanismFluids.Lithium, 1), new GasStack(MekanismFluids.Tritium, 1));
}
//Infuse objects
InfuseRegistry.registerInfuseObject(new ItemStack(MekanismItems.BioFuel), new InfuseObject(InfuseRegistry.get("BIO"), 5));
InfuseRegistry.registerInfuseObject(new ItemStack(Items.COAL, 1, 0), new InfuseObject(InfuseRegistry.get("CARBON"), 10));
InfuseRegistry.registerInfuseObject(new ItemStack(Items.COAL, 1, 1), new InfuseObject(InfuseRegistry.get("CARBON"), 20));
InfuseRegistry.registerInfuseObject(new ItemStack(Blocks.COAL_BLOCK, 1, 0), new InfuseObject(InfuseRegistry.get("CARBON"), 90));
InfuseRegistry.registerInfuseObject(new ItemStack(MekanismBlocks.BasicBlock, 1, 3), new InfuseObject(InfuseRegistry.get("CARBON"), 180));
InfuseRegistry.registerInfuseObject(new ItemStack(MekanismItems.CompressedCarbon), new InfuseObject(InfuseRegistry.get("CARBON"), 80));
InfuseRegistry.registerInfuseObject(new ItemStack(Items.REDSTONE), new InfuseObject(InfuseRegistry.get("REDSTONE"), 10));
InfuseRegistry.registerInfuseObject(new ItemStack(Blocks.REDSTONE_BLOCK), new InfuseObject(InfuseRegistry.get("REDSTONE"), 90));
InfuseRegistry.registerInfuseObject(new ItemStack(MekanismItems.CompressedRedstone), new InfuseObject(InfuseRegistry.get("REDSTONE"), 80));
InfuseRegistry.registerInfuseObject(new ItemStack(Blocks.RED_MUSHROOM), new InfuseObject(InfuseRegistry.get("FUNGI"), 10));
InfuseRegistry.registerInfuseObject(new ItemStack(Blocks.BROWN_MUSHROOM), new InfuseObject(InfuseRegistry.get("FUNGI"), 10));
InfuseRegistry.registerInfuseObject(new ItemStack(MekanismItems.CompressedDiamond), new InfuseObject(InfuseRegistry.get("DIAMOND"), 80));
InfuseRegistry.registerInfuseObject(new ItemStack(MekanismItems.CompressedObsidian), new InfuseObject(InfuseRegistry.get("OBSIDIAN"), 80));
//Fuel Gases
FuelHandler.addGas(MekanismFluids.Hydrogen, 1, MekanismConfig.current().general.FROM_H2.val());
}
@@ -44,7 +44,7 @@ public class StackSearcher {
for (slotCount = slotCount - 1; slotCount >= 0; slotCount--) {
ItemStack stack = inventory.extractItem(slotCount, max, true);
if (!stack.isEmpty() && StackUtils.equalsWildcardWithNBT(stack, type)) {
int current = !ret.getStack().isEmpty() ? ret.getStack().getCount() : 0;
int current = ret.getStack().getCount();
if (current + stack.getCount() <= max) {
ret.appendStack(slotCount, stack.copy());
} else {
@@ -9,6 +9,7 @@ import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.infuse.InfuseObject;
import mekanism.api.infuse.InfuseRegistry;
import mekanism.api.infuse.InfuseType;
import mekanism.common.Mekanism;
import mekanism.common.MekanismFluids;
import mekanism.common.MekanismItems;
@@ -270,8 +271,9 @@ public final class OreDictManager {
}
}
InfuseType tinInfuseType = InfuseRegistry.get("TIN");
for (ItemStack ingot : OreDictionary.getOres("ingotCopper")) {
RecipeHandler.addMetallurgicInfuserRecipe(InfuseRegistry.get("TIN"), 10, StackUtils.size(ingot, 3),
RecipeHandler.addMetallurgicInfuserRecipe(tinInfuseType, 10, StackUtils.size(ingot, 3),
new ItemStack(MekanismItems.Ingot, 4, 2));
}
@@ -279,8 +281,9 @@ public final class OreDictManager {
RecipeHandler.addCrusherRecipe(StackUtils.size(ingot, 1), new ItemStack(MekanismItems.OtherDust, 1, 5));
}
InfuseType redstoneInfuseType = InfuseRegistry.get("REDSTONE");
for (ItemStack ingot : OreDictionary.getOres("ingotOsmium")) {
RecipeHandler.addMetallurgicInfuserRecipe(InfuseRegistry.get("REDSTONE"), 10, StackUtils.size(ingot, 1),
RecipeHandler.addMetallurgicInfuserRecipe(redstoneInfuseType, 10, StackUtils.size(ingot, 1),
new ItemStack(MekanismItems.ControlCircuit, 1, 0));
}
@@ -360,18 +363,19 @@ public final class OreDictManager {
RecipeHandler.addChemicalOxidizerRecipe(StackUtils.size(dust, 1), new GasStack(MekanismFluids.Lithium, 100));
}
InfuseType diamondInfuseType = InfuseRegistry.get("DIAMOND");
for (ItemStack dust : OreDictionary.getOres("dustObsidian")) {
RecipeHandler.addCombinerRecipe(StackUtils.size(dust, 4), new ItemStack(Blocks.COBBLESTONE), new ItemStack(Blocks.OBSIDIAN));
RecipeHandler.addMetallurgicInfuserRecipe(InfuseRegistry.get("DIAMOND"), 10, StackUtils.size(dust, 1),
RecipeHandler.addMetallurgicInfuserRecipe(diamondInfuseType, 10, StackUtils.size(dust, 1),
new ItemStack(MekanismItems.OtherDust, 1, 5));
}
for (ItemStack dust : OreDictionary.getOres("dustDiamond")) {
InfuseRegistry.registerInfuseObject(dust, new InfuseObject(InfuseRegistry.get("DIAMOND"), 10));
InfuseRegistry.registerInfuseObject(dust, new InfuseObject(diamondInfuseType, 10));
}
for (ItemStack dust : OreDictionary.getOres("dustTin")) {
InfuseRegistry.registerInfuseObject(dust, new InfuseObject(InfuseRegistry.get("TIN"), 10));
InfuseRegistry.registerInfuseObject(dust, new InfuseObject(tinInfuseType, 10));
}
for (ItemStack ore : OreDictionary.getOres("treeSapling")) {
@@ -119,7 +119,7 @@ public class BinRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements IRec
int size = inv.getItemCount();
ItemStack testRemove = inv.removeStack();
int newCount = size - (!testRemove.isEmpty() ? testRemove.getCount() : 0);
int newCount = size - testRemove.getCount();
if (inv.getTier() == BinTier.CREATIVE) {
newCount = size;
}
@@ -55,9 +55,10 @@ public class InfusionInput extends MachineInput<InfusionInput> implements IWildI
}
public boolean use(NonNullList<ItemStack> inventory, int index, InfuseStorage infuseStorage, boolean deplete) {
if (inputContains(inventory.get(index), inputStack) && infuseStorage.contains(infuse)) {
ItemStack stack = inventory.get(index);
if (inputContains(stack, inputStack) && infuseStorage.contains(infuse)) {
if (deplete) {
inventory.set(index, StackUtils.subtract(inventory.get(index), inputStack));
inventory.set(index, StackUtils.subtract(stack, inputStack));
infuseStorage.subtract(infuse);
}
return true;
@@ -47,9 +47,9 @@ public abstract class MachineInput<INPUT extends MachineInput<INPUT>> {
private static boolean inputItemMatchesDefault(ItemStack container, ItemStack contained) {
if (OreDictCache.getOreDictName(container).contains("treeSapling")) {
return StackUtils.equalsWildcard(contained, container);
return StackUtils.equalsWildcard(container, contained);
}
return StackUtils.equalsWildcardWithNBT(contained, container) && container.getCount() >= contained.getCount();
return StackUtils.equalsWildcardWithNBT(container, contained) && container.getCount() >= contained.getCount();
}
@Override
@@ -84,13 +84,14 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i
super.onUpdate();
if (!world.isRemote) {
ChargeUtils.discharge(4, this);
if (!inventory.get(1).isEmpty()) {
InfuseObject pendingInfuseInput = InfuseRegistry.getObject(inventory.get(1));
ItemStack infuseInput = inventory.get(1);
if (!infuseInput.isEmpty()) {
InfuseObject pendingInfuseInput = InfuseRegistry.getObject(infuseInput);
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);
infuseInput.shrink(1);
}
}
}