diff options
Diffstat (limited to 'src/main/java/gregtech/api')
8 files changed, 140 insertions, 40 deletions
diff --git a/src/main/java/gregtech/api/enums/OrePrefixes.java b/src/main/java/gregtech/api/enums/OrePrefixes.java index 3aaea29f28..606d12c832 100644 --- a/src/main/java/gregtech/api/enums/OrePrefixes.java +++ b/src/main/java/gregtech/api/enums/OrePrefixes.java @@ -1,6 +1,7 @@ package gregtech.api.enums; import com.google.common.base.Objects; +import com.google.common.collect.ImmutableList; import gregtech.api.GregTech_API; import gregtech.api.enums.TC_Aspects.TC_AspectStack; import gregtech.api.interfaces.ICondition; @@ -319,8 +320,22 @@ public enum OrePrefixes { bars("Bars", "", "", false, false, false, false, false, false, false, false, false, false, 0, -1, 64, -1), bar("Bars", "", "", false, false, false, false, false, false, false, false, false, false, 0, -1, 64, -1), toolHeadMallet("Mallet Heads", "", " Mallet Head", true, true, false, false, false, false, true, true, false, false, B[6], M * 6, 16, 127), // Reverse Head consisting out of 6 Ingots. - handleMallet("Mallet Handle", "", " Handle", true, true, false, false, false, false, true, true, false, false, B[1] | B[2], M / 2, 64, 126); // Reverse Stick made of half an Ingot. Introduced by Eloraam - + handleMallet("Mallet Handle", "", " Handle", true, true, false, false, false, false, true, true, false, false, B[1] | B[2], M / 2, 64, 126), // Reverse Stick made of half an Ingot. Introduced by Eloraam + + // Cracked fluids + cellHydroCracked1("Cells", "Lightly Hydro-Cracked ", " Cell", true, true, true, true, false, false, false, true, false, false, 0, M * 1, 64, 30), + cellHydroCracked2("Cells", "Moderately Hydro-Cracked ", " Cell", true, true, true, true, false, false, false, true, false, false, 0, M * 1, 64, 30), + cellHydroCracked3("Cells", "Severely Hydro-Cracked ", " Cell", true, true, true, true, false, false, false, true, false, false, 0, M * 1, 64, 30), + cellSteamCracked1("Cells", "Lightly Steam-Cracked ", " Cell", true, true, true, true, false, false, false, true, false, false, 0, M * 1, 64, 30), + cellSteamCracked2("Cells", "Moderately Steam-Cracked ", " Cell", true, true, true, true, false, false, false, true, false, false, 0, M * 1, 64, 30), + cellSteamCracked3("Cells", "Severely Steam-Cracked ", " Cell", true, true, true, true, false, false, false, true, false, false, 0, M * 1, 64, 30); + + public static final ImmutableList<OrePrefixes> CELL_TYPES = + ImmutableList.of( + cell, cellMolten, cellPlasma, + cellHydroCracked1, cellHydroCracked2, cellHydroCracked3, + cellSteamCracked1, cellSteamCracked2, cellSteamCracked3); + public static volatile int VERSION = 509; static { @@ -528,9 +543,7 @@ public enum OrePrefixes { cableGt01.mSecondaryMaterial = new MaterialStack(Materials.Rubber, plate.mMaterialAmount); bucket.mSecondaryMaterial = new MaterialStack(Materials.Iron, ingot.mMaterialAmount * 3); bucketClay.mSecondaryMaterial = new MaterialStack(Materials.Clay, dust.mMaterialAmount * 5); - cell.mSecondaryMaterial = new MaterialStack(Materials.Tin, plate.mMaterialAmount * 2); - cellPlasma.mSecondaryMaterial = new MaterialStack(Materials.Tin, plate.mMaterialAmount * 2); - cellMolten.mSecondaryMaterial = new MaterialStack(Materials.Tin, plate.mMaterialAmount * 2); + CELL_TYPES.forEach(prefix -> prefix.mSecondaryMaterial = new MaterialStack(Materials.Tin, plate.mMaterialAmount * 2)); oreRedgranite.mSecondaryMaterial = new MaterialStack(Materials.GraniteRed, dust.mMaterialAmount); oreBlackgranite.mSecondaryMaterial = new MaterialStack(Materials.GraniteBlack, dust.mMaterialAmount); oreNetherrack.mSecondaryMaterial = new MaterialStack(Materials.Netherrack, dust.mMaterialAmount); @@ -983,7 +996,6 @@ public enum OrePrefixes { return mLocalizedMaterialPre + OrePrefixes.gem.getDefaultLocalNameFormatForItem(aMaterial); case crateGtPlate: return mLocalizedMaterialPre + OrePrefixes.plate.getDefaultLocalNameFormatForItem(aMaterial); - case cellMolten: } switch (aMaterial.mName) { case "Glass": diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java index 48d1bd8a18..57f7073e24 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java @@ -245,16 +245,17 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity public boolean solidFuelOverride(ItemStack stack) { //this could be used for a coal generator for example aswell... ItemData association = GT_OreDictUnificator.getAssociation(stack); - //if it is a gregtech Item, make sure its not a VOLUMETRIC_FLASK, cell, motlen cell or plasma cell, else do vanilla checks - return association != null ? !OrePrefixes.cell.equals(association.mPrefix) && - !OrePrefixes.cellMolten.equals(association.mPrefix) && - !OrePrefixes.cellPlasma.equals(association.mPrefix) && - !GT_Utility.areStacksEqual(ItemList.VOLUMETRIC_FLASK.get(1L), stack, true) : - stack != null && //when the stack is null its not a solid - stack.getItem() != null && //when the item in the stack is null its not a solid - !(stack.getItem() instanceof IFluidContainerItem) && //when the item is a fluid container its not a solid... - !(stack.getItem() instanceof IFluidHandler) && //when the item is a fluid handler its not a solid... - !stack.getItem().getUnlocalizedName().contains("bucket"); //since we cant really check for buckets... + //if it is a gregtech Item, make sure its not a VOLUMETRIC_FLASK or any type of cell, else do vanilla checks + if (association != null) { + return !OrePrefixes.CELL_TYPES.contains(association.mPrefix) && + !GT_Utility.areStacksEqual(ItemList.VOLUMETRIC_FLASK.get(1L), stack, true); + } else { + return stack != null && //when the stack is null its not a solid + stack.getItem() != null && //when the item in the stack is null its not a solid + !(stack.getItem() instanceof IFluidContainerItem) && //when the item is a fluid container its not a solid... + !(stack.getItem() instanceof IFluidHandler) && //when the item is a fluid handler its not a solid... + !stack.getItem().getUnlocalizedName().contains("bucket"); //since we cant really check for buckets... + } } public abstract int getPollution(); diff --git a/src/main/java/gregtech/api/objects/iterators/MergedIterator.java b/src/main/java/gregtech/api/objects/iterators/MergedIterator.java new file mode 100644 index 0000000000..77fac8d22f --- /dev/null +++ b/src/main/java/gregtech/api/objects/iterators/MergedIterator.java @@ -0,0 +1,30 @@ +package gregtech.api.objects.iterators; + +import java.util.Iterator; + +public class MergedIterator<T> implements Iterator<T> { + private final Iterator<T>[] inners; + private int current; + + @SafeVarargs + public MergedIterator(Iterator<T>... iterators) { + inners = iterators; + current = 0; + } + + public boolean hasNext() { + while (current < inners.length && !inners[current].hasNext()) { + current++; + } + + return current < inners.length; + } + + public T next() { + while (current < inners.length && !inners[current].hasNext()) { + current++; + } + + return inners[current].next(); + } +} diff --git a/src/main/java/gregtech/api/util/GT_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java index ac9f7bd3d4..a910723069 100644 --- a/src/main/java/gregtech/api/util/GT_ModHandler.java +++ b/src/main/java/gregtech/api/util/GT_ModHandler.java @@ -2008,7 +2008,22 @@ public class GT_ModHandler { public static int getCapsuleCellContainerCount(ItemStack aStack) { if (aStack == null) return 0; - return GT_Utility.areStacksEqual(GT_Utility.getContainerForFilledItem(aStack, true), ItemList.Cell_Empty.get(1)) || OrePrefixes.cell.contains(aStack) || OrePrefixes.cellMolten.contains(aStack) || OrePrefixes.cellPlasma.contains(aStack) || GT_Utility.areStacksEqual(aStack, getIC2Item("waterCell", 1, W)) ? 1 : 0; + + if (GT_Utility.areStacksEqual(GT_Utility.getContainerForFilledItem(aStack, true), ItemList.Cell_Empty.get(1))) { + return 1; + } + + if (GT_Utility.areStacksEqual(aStack, getIC2Item("waterCell", 1, W))) { + return 1; + } + + for (OrePrefixes cellType : OrePrefixes.CELL_TYPES) { + if (cellType.contains(aStack)) { + return 1; + } + } + + return 0; } public static class RecipeBits { diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index e10d58cd75..4059c6cd92 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -9,6 +9,7 @@ import gregtech.api.objects.GT_FluidStack; import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.ItemData; import gregtech.api.objects.MaterialStack; +import gregtech.api.util.extensions.ArrayExt; import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Replicator; import gregtech.nei.GT_NEI_DefaultHandler.FixedPositionedStack; import ic2.core.Ic2Items; @@ -23,7 +24,6 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidContainerItem; import java.util.*; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; import static gregtech.api.enums.GT_Values.*; @@ -97,7 +97,8 @@ public class GT_Recipe implements Comparable<GT_Recipe> { mEnabled = aRecipe.mEnabled; mHidden = aRecipe.mHidden; } - protected GT_Recipe(boolean aOptimize, ItemStack[] aInputs, ItemStack[] aOutputs, Object aSpecialItems, int[] aChances, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, int aDuration, int aEUt, int aSpecialValue) { + + public GT_Recipe(boolean aOptimize, ItemStack[] aInputs, ItemStack[] aOutputs, Object aSpecialItems, int[] aChances, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, int aDuration, int aEUt, int aSpecialValue) { if (aInputs == null) aInputs = new ItemStack[0]; if (aOutputs == null) @@ -111,10 +112,10 @@ public class GT_Recipe implements Comparable<GT_Recipe> { if (aChances.length < aOutputs.length) aChances = Arrays.copyOf(aChances, aOutputs.length); - aInputs = GT_Utility.getArrayListWithoutTrailingNulls(aInputs).toArray(new ItemStack[0]); - aOutputs = GT_Utility.getArrayListWithoutTrailingNulls(aOutputs).toArray(new ItemStack[0]); - aFluidInputs = GT_Utility.getArrayListWithoutNulls(aFluidInputs).toArray(new FluidStack[0]); - aFluidOutputs = GT_Utility.getArrayListWithoutNulls(aFluidOutputs).toArray(new FluidStack[0]); + aInputs = ArrayExt.withoutTrailingNulls(aInputs, ItemStack[]::new); + aOutputs = ArrayExt.withoutTrailingNulls(aOutputs, ItemStack[]::new); + aFluidInputs = ArrayExt.withoutNulls(aFluidInputs, FluidStack[]::new); + aFluidOutputs = ArrayExt.withoutNulls(aFluidOutputs, FluidStack[]::new); GT_OreDictUnificator.setStackArray(true, aInputs); GT_OreDictUnificator.setStackArray(true, aOutputs); @@ -1629,12 +1630,12 @@ public class GT_Recipe implements Comparable<GT_Recipe> { } } - - public static class GT_Recipe_Map_LargeChemicalReactor extends GT_Recipe_Map{ - private static int TOTAL_INPUT_COUNT = 6; - private static int OUTPUT_COUNT = 2; - private static int FLUID_OUTPUT_COUNT = 4; - + + public static class GT_Recipe_Map_LargeChemicalReactor extends GT_Recipe_Map { + private static final int TOTAL_INPUT_COUNT = 6; + private static final int OUTPUT_COUNT = 2; + private static final int FLUID_OUTPUT_COUNT = 4; + public GT_Recipe_Map_LargeChemicalReactor() { super(new HashSet<>(1000), "gt.recipe.largechemicalreactor", "Large Chemical Reactor", null, RES_PATH_GUI + "basicmachines/Default", 2, OUTPUT_COUNT, 0, 0, 1, E, 1, E, true, true); } @@ -1650,7 +1651,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> { if (aInputs == null) { aInputs = new ItemStack[0]; } else { - aInputs = GT_Utility.getArrayListWithoutTrailingNulls(aInputs).toArray(new ItemStack[0]); + aInputs = ArrayExt.withoutTrailingNulls(aInputs, ItemStack[]::new); } for (ItemStack input : aInputs) { @@ -1690,7 +1691,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> { if (aOutputs == null) { aOutputs = new ItemStack[0]; } else { - aOutputs = GT_Utility.getArrayListWithoutTrailingNulls(aOutputs).toArray(new ItemStack[0]); + aOutputs = ArrayExt.withoutTrailingNulls(aOutputs, ItemStack[]::new); } for (ItemStack output : aOutputs) { @@ -1736,9 +1737,9 @@ public class GT_Recipe implements Comparable<GT_Recipe> { for (int i = 0; i < itemLimit; i++, j++) { if (this.mInputs == null || (this.mInputs[i] == null && (i == 0 && itemLimit == 1))) { if (this.mOutputs != null && this.mOutputs.length > 0 && this.mOutputs[0] != null) - GT_Log.out.println("recipe " + this.toString() + " Output 0:" + this.mOutputs[0].getDisplayName() + " has errored!"); + GT_Log.out.println("recipe " + this + " Output 0:" + this.mOutputs[0].getDisplayName() + " has errored!"); else - GT_Log.out.println("recipe " + this.toString() + " has errored!"); + GT_Log.out.println("recipe " + this + " has errored!"); new Exception("Recipe Fixme").printStackTrace(GT_Log.out); } @@ -1753,9 +1754,9 @@ public class GT_Recipe implements Comparable<GT_Recipe> { for (int i = 0; i < fluidLimit; i++, j++) { if (this.mFluidInputs == null || this.mFluidInputs[i] == null) { if (this.mOutputs != null && this.mOutputs.length > 0 && this.mOutputs[0] != null) - GT_Log.out.println("recipe " + this.toString() + " Output 0:" + this.mOutputs[0].getDisplayName() + " has errored!"); + GT_Log.out.println("recipe " + this + " Output 0:" + this.mOutputs[0].getDisplayName() + " has errored!"); else - GT_Log.out.println("recipe " + this.toString() + " has errored!"); + GT_Log.out.println("recipe " + this + " has errored!"); new Exception("Recipe Fixme").printStackTrace(GT_Log.out); } diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 12ec2427ce..94195d76ce 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -24,6 +24,7 @@ import gregtech.api.net.GT_Packet_Sound; import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.ItemData; import gregtech.api.threads.GT_Runnable_Sound; +import gregtech.api.util.extensions.ArrayExt; import gregtech.common.GT_Proxy; import ic2.api.recipe.IRecipeInput; import ic2.api.recipe.RecipeInputItemStack; @@ -81,6 +82,7 @@ import java.text.DecimalFormatSymbols; import java.text.NumberFormat; import java.util.*; import java.util.Map.Entry; +import java.util.function.IntFunction; import static gregtech.GT_Mod.GT_FML_LOGGER; import static gregtech.api.enums.GT_Values.*; @@ -1236,6 +1238,9 @@ public class GT_Utility { return false; } + /** + * Note: use {@link ArrayExt#withoutNulls(Object[], IntFunction)} if you want an array as a result. + */ public static <T> ArrayList<T> getArrayListWithoutNulls(T... aArray) { if (aArray == null) return new ArrayList<>(); ArrayList<T> rList = new ArrayList<>(Arrays.asList(aArray)); @@ -1243,6 +1248,9 @@ public class GT_Utility { return rList; } + /** + * Note: use {@link ArrayExt#withoutTrailingNulls(Object[], IntFunction)} if you want an array as a result. + */ public static <T> ArrayList<T> getArrayListWithoutTrailingNulls(T... aArray) { if (aArray == null) return new ArrayList<>(); ArrayList<T> rList = new ArrayList<>(Arrays.asList(aArray)); diff --git a/src/main/java/gregtech/api/util/extensions/ArrayExt.java b/src/main/java/gregtech/api/util/extensions/ArrayExt.java index faa01cb368..51486bc036 100644 --- a/src/main/java/gregtech/api/util/extensions/ArrayExt.java +++ b/src/main/java/gregtech/api/util/extensions/ArrayExt.java @@ -32,15 +32,36 @@ public class ArrayExt { return objects; } + @SuppressWarnings("ForLoopReplaceableByForEach") + public static <T> T[] withoutNulls(T[] array, IntFunction<T[]> arrayFactory) { + int count = 0; + for (int i = 0; i < array.length; i++) { + if (array[i] != null) { + count++; + } + } + + T[] newArr = arrayFactory.apply(count); + if (count == 0) return newArr; + + int j = 0; + for (int i = 0; i < array.length; i++) { + if (array[i] != null) { + newArr[j] = array[i]; + j++; + } + } + + return newArr; + } + public static <T> T[] withoutTrailingNulls(T[] array, IntFunction<T[]> arrayFactory) { int firstNull = -1; - for (int i = 0; i < array.length; i++) { + for (int i = array.length - 1; i >= 0; i--) { if (array[i] == null) { - if (firstNull == -1) { - firstNull = i; - } + firstNull = i; } else { - firstNull = -1; + break; } } diff --git a/src/main/java/gregtech/api/util/extensions/IteratorExt.java b/src/main/java/gregtech/api/util/extensions/IteratorExt.java new file mode 100644 index 0000000000..d59bb298a4 --- /dev/null +++ b/src/main/java/gregtech/api/util/extensions/IteratorExt.java @@ -0,0 +1,12 @@ +package gregtech.api.util.extensions; + +import gregtech.api.objects.iterators.MergedIterator; + +import java.util.Iterator; + +public class IteratorExt { + @SafeVarargs + public static <T> Iterator<T> merge(Iterator<T>... iterators) { + return new MergedIterator<>(iterators); + } +} |