diff options
Diffstat (limited to 'src/main/java/gregtech/api/util')
6 files changed, 606 insertions, 21 deletions
diff --git a/src/main/java/gregtech/api/util/GT_LanguageManager.java b/src/main/java/gregtech/api/util/GT_LanguageManager.java index b44b6ffa40..c87e0f7417 100644 --- a/src/main/java/gregtech/api/util/GT_LanguageManager.java +++ b/src/main/java/gregtech/api/util/GT_LanguageManager.java @@ -323,7 +323,7 @@ public class GT_LanguageManager { addStringLocalization("Interaction_DESCRIPTION_Index_214", "Connected"); addStringLocalization("Interaction_DESCRIPTION_Index_215", "Disconnected"); addStringLocalization("Interaction_DESCRIPTION_Index_216", "Deprecated Recipe"); - addStringLocalization("Interaction_DESCRIPTION_Index_217", "Stocking mode. Keeps this many items in destination input slots."); + addStringLocalization("Interaction_DESCRIPTION_Index_217", "Stocking mode. Keeps this many items in destination input slots. This mode can be server unfriendly."); addStringLocalization("Interaction_DESCRIPTION_Index_218", "Transfer size mode. Add exactly this many items in destination input slots as long as there is room."); addStringLocalization("Interaction_DESCRIPTION_Index_500", "Fitting: Loose - More Flow"); addStringLocalization("Interaction_DESCRIPTION_Index_501", "Fitting: Tight - More Efficiency"); diff --git a/src/main/java/gregtech/api/util/GT_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java index e195bf9b02..5cfcac0a89 100644 --- a/src/main/java/gregtech/api/util/GT_ModHandler.java +++ b/src/main/java/gregtech/api/util/GT_ModHandler.java @@ -1,5 +1,7 @@ package gregtech.api.util; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.registry.GameRegistry; import gregtech.GT_Mod; @@ -122,6 +124,7 @@ public class GT_ModHandler { public static List<Integer> sSingleNonBlockDamagableRecipeList_warntOutput = new ArrayList<Integer>(50); public static List<Integer> sVanillaRecipeList_warntOutput = new ArrayList<Integer>(50); public static final List<IRecipe> sSingleNonBlockDamagableRecipeList_verified = new ArrayList<IRecipe>(1000); + private static Cache<GT_ItemStack, ItemStack> sSmeltingRecipeCache = CacheBuilder.newBuilder().maximumSize(1000).build(); static { sNativeRecipeClasses.add(ShapedRecipes.class.getName()); @@ -1565,8 +1568,14 @@ public class GT_ModHandler { * Used in my own Furnace. */ public static ItemStack getSmeltingOutput(ItemStack aInput, boolean aRemoveInput, ItemStack aOutputSlot) { - if (aInput == null || aInput.stackSize < 1) return null; - ItemStack rStack = GT_OreDictUnificator.get(FurnaceRecipes.smelting().getSmeltingResult(aInput)); + if (aInput == null || aInput.stackSize < 1) + return null; + ItemStack rStack = null; + try { + rStack = sSmeltingRecipeCache.get(new GT_ItemStack(aInput), () -> GT_OreDictUnificator.get(FurnaceRecipes.smelting().getSmeltingResult(aInput))); + } catch (Exception ignored){ + } + if (rStack != null && (aOutputSlot == null || (GT_Utility.areStacksEqual(rStack, aOutputSlot) && rStack.stackSize + aOutputSlot.stackSize <= aOutputSlot.getMaxStackSize()))) { if (aRemoveInput) aInput.stackSize--; return rStack; @@ -1676,7 +1685,7 @@ public class GT_ModHandler { int tTier = ((ic2.api.item.IElectricItem) aStack.getItem()).getTier(aStack); if (tTier < 0 || tTier == aTier || aTier == Integer.MAX_VALUE) { if (!aIgnoreLimit && tTier >= 0) - aCharge = (int) Math.min(aCharge, V[Math.max(0, Math.min(V.length - 1, tTier))]); + aCharge = (int) Math.min(aCharge, V[Math.max(0, Math.min(V.length - 1, tTier))] + B[Math.max(0, Math.min(V.length - 1, tTier))]); if (aCharge > 0) { // int rCharge = Math.max(0, ic2.api.item.ElectricItem.manager.discharge(aStack, aCharge + (aCharge * 4 > aTier ? aTier : 0), tTier, T, aSimulate)); int rCharge = (int) Math.max(0, ic2.api.item.ElectricItem.manager.discharge(aStack, aCharge + (aCharge * 4 > aTier ? aTier : 0), tTier, true, !aIgnoreDischargability, aSimulate)); diff --git a/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java b/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java new file mode 100644 index 0000000000..e30fe5d606 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java @@ -0,0 +1,348 @@ +package gregtech.api.util; + +import java.util.LinkedList; +import java.util.List; + +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; + +/** + * This makes it easier to build multi tooltips, with a standardized format. <br> + * Info section order should be:<br> + * addMachineType<br> + * addInfo, for what it does, special notes, etc.<br> + * addSeparator, if you need it<br> + * addPollutionAmount<br> + * <br> + * Structure order should be:<br> + * beginStructureBlock<br> + * addController<br> + * addCasingInfo<br> + * addOtherStructurePart, for secondary structure block info (pipes, coils, etc)<br> + * addEnergyHatch/addDynamoHatch<br> + * addMaintenanceHatch<br> + * addMufflerHatch<br> + * addInputBus/addInputHatch/addOutputBus/addOutputHatch, in that order<br> + * Use addStructureInfo for any comments on nonstandard structure info wherever needed + * <br> + * toolTipFinisher goes at the very end<br> + * <br> + * Originally created by kekzdealer + */ +public class GT_Multiblock_Tooltip_Builder { + private static final String TAB = " "; + private static final String COLON = ": "; + + private final List<String> iLines; + private final List<String> sLines; + + private String[] iArray; + private String[] sArray; + + //Localized tooltips + private static final String TT_machineType = StatCollector.translateToLocal("GT5U.MBTT.MachineType"); + private static final String TT_dimensions = StatCollector.translateToLocal("GT5U.MBTT.Dimensions"); + private static final String TT_hollow = StatCollector.translateToLocal("GT5U.MBTT.Hollow"); + private static final String TT_structure = StatCollector.translateToLocal("GT5U.MBTT.Structure"); + private static final String TT_controller = StatCollector.translateToLocal("GT5U.MBTT.Controller"); + private static final String TT_minimum = StatCollector.translateToLocal("GT5U.MBTT.Minimum"); + private static final String TT_maintenancehatch = StatCollector.translateToLocal("GT5U.MBTT.MaintenanceHatch"); + private static final String TT_energyhatch = StatCollector.translateToLocal("GT5U.MBTT.EnergyHatch"); + private static final String TT_dynamohatch = StatCollector.translateToLocal("GT5U.MBTT.DynamoHatch"); + private static final String TT_mufflerhatch = StatCollector.translateToLocal("GT5U.MBTT.MufflerHatch"); + private static final String TT_inputbus = StatCollector.translateToLocal("GT5U.MBTT.InputBus"); + private static final String TT_inputhatch = StatCollector.translateToLocal("GT5U.MBTT.InputHatch"); + private static final String TT_outputbus = StatCollector.translateToLocal("GT5U.MBTT.OutputBus"); + private static final String TT_outputhatch = StatCollector.translateToLocal("GT5U.MBTT.OutputHatch"); + private static final String TT_causes = StatCollector.translateToLocal("GT5U.MBTT.Causes"); + private static final String TT_pps = StatCollector.translateToLocal("GT5U.MBTT.PPS"); + private static final String TT_hold = StatCollector.translateToLocal("GT5U.MBTT.Hold"); + private static final String TT_todisplay = StatCollector.translateToLocal("GT5U.MBTT.Display"); + private static final String TT_mod = StatCollector.translateToLocal("GT5U.MBTT.Mod"); + + public GT_Multiblock_Tooltip_Builder() { + iLines = new LinkedList<>(); + sLines = new LinkedList<>(); + } + + /** + * Add a line telling you what the machine type is. Usually, this will be the name of a SB version.<br> + * Machine Type: machine + * + * @param machine + * Name of the machine type + * + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addMachineType(String machine) { + iLines.add(TT_machineType + COLON + EnumChatFormatting.YELLOW + machine + EnumChatFormatting.RESET); + return this; + } + + /** + * Add a basic line of information about this structure + * + * @param info + * The line to be added. + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addInfo(String info) { + iLines.add(info); + return this; + } + + /** + * Add a separator line like this:<br> + * ----------------------------------------- + * + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addSeparator() { + iLines.add("-----------------------------------------"); + return this; + } + + /** + * Add a line telling you what the machine type is. Usually, this will be the name of a SB version.<br> + * Machine Type: machine + * + * @param machine + * Name of the machine type + * + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addPollutionAmount(int pollution) { + iLines.add(TT_causes + COLON + EnumChatFormatting.DARK_PURPLE + pollution + " " + EnumChatFormatting.GRAY + TT_pps); + return this; + } + + /** + * Begin adding structural information by adding a line about the structure's dimensions + * and then inserting a "Structure:" line. + * + * @param w + * Structure width. + * @param h + * Structure height. + * @param l + * Structure depth/length. + * @param hollow + * T/F, adds a (hollow) comment if true + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder beginStructureBlock(int w, int h, int l, boolean hollow) { + if (hollow) { + sLines.add(TT_dimensions + COLON + w + "x" + h + "x" + l + " (WxHxL) " + TT_hollow); + } + else { + sLines.add(TT_dimensions + COLON + w + "x" + h + "x" + l + " (WxHxL)"); + } + sLines.add(TT_structure + COLON); + return this; + } + + /** + * Begin adding structural information by adding a line about the structure's dimensions<br> + * and then inserting a "Structure:" line. Variable version displays min and max + * + * @param wmin + * Structure min width. + * @param wmax + * Structure max width. + * @param hmin + * Structure min height. + * @param hmax + * Structure max height. + * @param lmin + * Structure min depth/length. + * @param lmax + * Structure max depth/length. + * @param hollow + * T/F, adds a (hollow) comment if true + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder beginVariableStructureBlock(int wmin, int wmax, int hmin, int hmax, int lmin, int lmax, boolean hollow) { + if (hollow) { + sLines.add(TT_dimensions + COLON + wmin + "-" + wmax + "x" + hmin + "-" + hmax + "x" + lmin + "-" + lmax + " (WxHxL) " + TT_hollow); + } + else { + sLines.add(TT_dimensions + COLON + wmin + "-" + wmax + "x" + hmin + "-" + hmax + "x" + lmin + "-" + lmax + " (WxHxL)"); + } + sLines.add(TT_structure + COLON); + return this; + } + + /** + * Add a line of information about the structure:<br> + * (indent)Controller: info + * @param info + * Positional information. + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addController(String info) { + sLines.add(TAB + TT_controller + COLON + info); + return this; + } + + /** + * Add a line of information about the structure:<br> + * (indent)minCountx casingName (minimum) + * @param casingName + * Name of the Casing. + * @param minCount + * Minimum needed for valid structure check. + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addCasingInfo(String casingName, int minCount) { + sLines.add(TAB + minCount +"x " + casingName + " " + TT_minimum); + return this; + } + + /** + * Use this method to add a structural part that isn't covered by the other methods.<br> + * (indent)name: info + * @param name + * Name of the hatch or other component. + * @param info + * Positional information. + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addOtherStructurePart(String name, String info) { + sLines.add(TAB + name + COLON + info); + return this; + } + + /** + * Add a line of information about the structure:<br> + * (indent)Maintenance Hatch: info + * @param info + * Positional information. + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addMaintenanceHatch(String info) { + sLines.add(TAB + TT_maintenancehatch + COLON + info); + return this; + } + + /** + * Add a line of information about the structure:<br> + * (indent)Muffler Hatch: info + * @param info + * Location where the hatch goes + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addMufflerHatch(String info) { + sLines.add(TAB + TT_mufflerhatch + COLON + info); + return this; + } + + /** + * Add a line of information about the structure:<br> + * (indent)Energy Hatch: info + * @param info + * Positional information. + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addEnergyHatch(String info) { + sLines.add(TAB + TT_energyhatch + COLON + info); + return this; + } + + /** + * Add a line of information about the structure:<br> + * (indent)Dynamo Hatch: info + * @param info + * Positional information. + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addDynamoHatch(String info) { + sLines.add(TAB + TT_dynamohatch + COLON + info); + return this; + } + + /** + * Add a line of information about the structure:<br> + * (indent)Input Bus: info + * @param info + * Location where the bus goes + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addInputBus(String info) { + sLines.add(TAB + TT_inputbus + COLON + info); + return this; + } + + /** + * Add a line of information about the structure:<br> + * (indent)Input Hatch: info + * @param info + * Location where the hatch goes + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addInputHatch(String info) { + sLines.add(TAB + TT_inputhatch + COLON + info); + return this; + } + + /** + * Add a line of information about the structure:<br> + * (indent)Output Bus: info + * @param info + * Location where the bus goes + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addOutputBus(String info) { + sLines.add(TAB + TT_outputbus + COLON + info); + return this; + } + + /** + * Add a line of information about the structure:<br> + * (indent)Output Hatch: info + * @param info + * Location where the bus goes + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addOutputHatch(String info) { + sLines.add(TAB + TT_outputhatch + COLON + info); + return this; + } + + /** + * Use this method to add non-standard structural info.<br> + * (indent)info + * @param info + * The line to be added. + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addStructureInfo(String info) { + sLines.add(TAB + info); + return this; + } + + /** + * Call at the very end.<br> + * Adds a final line with the mod name and information on how to display the structure guidelines.<br> + * Ends the building process. + * + * @param mod + * Name of the mod that adds this multiblock machine + */ + public void toolTipFinisher(String mod) { + iLines.add(TT_hold + " " + EnumChatFormatting.BOLD + "[LSHIFT]" + EnumChatFormatting.RESET + EnumChatFormatting.GRAY + " " + TT_todisplay); + iLines.add(TT_mod + COLON + EnumChatFormatting.GREEN + mod + EnumChatFormatting.GRAY); + iArray = new String[iLines.size()]; + sArray = new String[sLines.size()]; + iLines.toArray(iArray); + sLines.toArray(sArray); + } + + public String[] getInformation() { + return iArray; + } + + public String[] getStructureInformation() { + return sArray; + } + +} diff --git a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java index 9d9b45cecf..188af9cfaa 100644 --- a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java +++ b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java @@ -156,6 +156,59 @@ public class GT_OreDictUnificator { return GT_Utility.copyAmount(aStack.stackSize, rStack); } + /** Doesn't copy the returned stack or set quantity. Be careful and do not mutate it; + * intended only to optimize comparisons */ + static ItemStack get_nocopy(boolean aUseBlackList, ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack)) return null; + ItemData tPrefixMaterial = getAssociation(aStack); + ItemStack rStack = null; + if (tPrefixMaterial == null || !tPrefixMaterial.hasValidPrefixMaterialData() || (aUseBlackList && tPrefixMaterial.mBlackListed)) + return aStack; + if (aUseBlackList && !GregTech_API.sUnificationEntriesRegistered && isBlacklisted(aStack)) { + tPrefixMaterial.mBlackListed = true; + return aStack; + } + if (tPrefixMaterial.mUnificationTarget == null) + tPrefixMaterial.mUnificationTarget = sName2StackMap.get(tPrefixMaterial.toString()); + rStack = tPrefixMaterial.mUnificationTarget; + if (GT_Utility.isStackInvalid(rStack)) return aStack; + assert rStack != null; + rStack.setTagCompound(aStack.getTagCompound()); + return rStack; + } + + /** Compares the first argument against an already-unificated second argument as if + * aUseBlackList was both true and false. */ + public static boolean isInputStackEqual(ItemStack aStack, ItemStack unified_tStack) { + boolean alreadyCompared = false; + if (GT_Utility.isStackInvalid(aStack)) return false; + ItemData tPrefixMaterial = getAssociation(aStack); + ItemStack rStack = null; + if (tPrefixMaterial == null || !tPrefixMaterial.hasValidPrefixMaterialData()) + return GT_Utility.areStacksEqual(aStack, unified_tStack, true); + else if(tPrefixMaterial.mBlackListed) { + if (GT_Utility.areStacksEqual(aStack, unified_tStack, true)) + return true; + else + alreadyCompared = true; + } + if (!alreadyCompared && !GregTech_API.sUnificationEntriesRegistered && isBlacklisted(aStack)) { + tPrefixMaterial.mBlackListed = true; + if (GT_Utility.areStacksEqual(aStack, unified_tStack, true)) + return true; + else + alreadyCompared = true; + } + if (tPrefixMaterial.mUnificationTarget == null) + tPrefixMaterial.mUnificationTarget = sName2StackMap.get(tPrefixMaterial.toString()); + rStack = tPrefixMaterial.mUnificationTarget; + if (GT_Utility.isStackInvalid(rStack)) + return !alreadyCompared && GT_Utility.areStacksEqual(aStack, unified_tStack, true); + assert rStack != null; + rStack.setTagCompound(aStack.getTagCompound()); + return GT_Utility.areStacksEqual(rStack, unified_tStack, true); + } + public static List<ItemStack> getNonUnifiedStacks(Object obj) { synchronized (sUnificationTable) { if (sUnificationTable.isEmpty() && !sItemStack2DataMap.isEmpty()) { diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index db8ecf73b6..537d92b365 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -23,6 +23,7 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidContainerItem; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; import static gregtech.api.enums.GT_Values.*; @@ -388,11 +389,12 @@ public class GT_Recipe implements Comparable<GT_Recipe> { if (mInputs.length > 0 && aInputs == null) return false; for (ItemStack tStack : mInputs) { - if (tStack != null) { + ItemStack unified_tStack = GT_OreDictUnificator.get_nocopy(true, tStack); + if (unified_tStack != null) { amt = tStack.stackSize; boolean temp = true; for (ItemStack aStack : aInputs) { - if ((GT_Utility.areUnificationsEqual(aStack, tStack, true) || GT_Utility.areUnificationsEqual(GT_OreDictUnificator.get(false, aStack), tStack, true))) { + if (GT_OreDictUnificator.isInputStackEqual(aStack, unified_tStack)) { if (GTppRecipeHelper) {//remove once the fix is out if (GT_Utility.areStacksEqual(aStack, Ic2Items.FluidCell.copy(), true) || GT_Utility.areStacksEqual(aStack, ItemList.Tool_DataStick.get(1L), true) || GT_Utility.areStacksEqual(aStack, ItemList.Tool_DataOrb.get(1L), true)) { if (!GT_Utility.areStacksEqual(aStack, tStack, false)) @@ -613,12 +615,13 @@ public class GT_Recipe implements Comparable<GT_Recipe> { public static final GT_Recipe_Map sHammerRecipes = new GT_Recipe_Map(new HashSet<>(3800), "gt.recipe.hammer", "Forge Hammer", null, RES_PATH_GUI + "basicmachines/Hammer", 1, 1, 1, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sAmplifiers = new GT_Recipe_Map(new HashSet<>(2), "gt.recipe.uuamplifier", "Amplifabricator", null, RES_PATH_GUI + "basicmachines/Amplifabricator", 1, 0, 1, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sMassFabFakeRecipes = new GT_Recipe_Map(new HashSet<>(2), "gt.recipe.massfab", "Mass Fabrication", null, RES_PATH_GUI + "basicmachines/Massfabricator", 1, 0, 1, 0, 10, E, 1, E, true, true); - public static final GT_Recipe_Map_Fuel sDieselFuels = new GT_Recipe_Map_Fuel(new HashSet<>(20), "gt.recipe.dieselgeneratorfuel", "Diesel Generator Fuel", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, true); + public static final GT_Recipe_Map_Fuel sDieselFuels = new GT_Recipe_Map_Fuel(new HashSet<>(20), "gt.recipe.dieselgeneratorfuel", "Combustion Generator Fuels", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, true); + public static final GT_Recipe_Map_Fuel sExtremeDieselFuels = new GT_Recipe_Map_Fuel(new HashSet<>(20), "gt.recipe.extremedieselgeneratorfuel", "Extreme Diesel Engine Fuel", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, true); public static final GT_Recipe_Map_Fuel sTurbineFuels = new GT_Recipe_Map_Fuel(new HashSet<>(25), "gt.recipe.gasturbinefuel", "Gas Turbine Fuel", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, true); - public static final GT_Recipe_Map_Fuel sHotFuels = new GT_Recipe_Map_Fuel(new HashSet<>(10), "gt.recipe.thermalgeneratorfuel", "Thermal Generator Fuel", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, false); + public static final GT_Recipe_Map_Fuel sHotFuels = new GT_Recipe_Map_Fuel(new HashSet<>(10), "gt.recipe.thermalgeneratorfuel", "Thermal Generator Fuels", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, false); public static final GT_Recipe_Map_Fuel sDenseLiquidFuels = new GT_Recipe_Map_Fuel(new HashSet<>(15), "gt.recipe.semifluidboilerfuels", "Semifluid Boiler Fuels", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, true); public static final GT_Recipe_Map_Fuel sPlasmaFuels = new GT_Recipe_Map_Fuel(new HashSet<>(100), "gt.recipe.plasmageneratorfuels", "Plasma Generator Fuels", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, true); - public static final GT_Recipe_Map_Fuel sMagicFuels = new GT_Recipe_Map_Fuel(new HashSet<>(100), "gt.recipe.magicfuels", "Magic Energy Absorber", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, true); + public static final GT_Recipe_Map_Fuel sMagicFuels = new GT_Recipe_Map_Fuel(new HashSet<>(100), "gt.recipe.magicfuels", "Magic Energy Absorber Fuels", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, true); public static final GT_Recipe_Map_Fuel sSmallNaquadahReactorFuels = new GT_Recipe_Map_Fuel(new HashSet<>(1), "gt.recipe.smallnaquadahreactor", "Naquadah Reactor MkI", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, true); public static final GT_Recipe_Map_Fuel sLargeNaquadahReactorFuels = new GT_Recipe_Map_Fuel(new HashSet<>(1), "gt.recipe.largenaquadahreactor", "Naquadah Reactor MkII", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, true); public static final GT_Recipe_Map_Fuel sHugeNaquadahReactorFuels = new GT_Recipe_Map_Fuel(new HashSet<>(1), "gt.recipe.fluidnaquadahreactor", "Naquadah Reactor MkIII", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, true); @@ -1838,15 +1841,19 @@ public class GT_Recipe implements Comparable<GT_Recipe> { } public GT_Recipe addFakeRecipe(boolean aCheckForCollisions, ItemStack[] aInputs, ItemStack[] aOutputs, Object aSpecial, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, int aDuration, int aEUt, int aSpecialValue) { + AtomicInteger ai = new AtomicInteger(); Optional.ofNullable(GT_OreDictUnificator.getAssociation(aOutputs[0])) .map(itemData -> itemData.mMaterial) .map(materialsStack -> materialsStack.mMaterial) .map(materials -> materials.mElement) .map(Element::getMass) .ifPresent(e -> - aFluidInputs[0].amount = (int) GT_MetaTileEntity_Replicator.cubicFluidMultiplier(e) + { + aFluidInputs[0].amount = (int) GT_MetaTileEntity_Replicator.cubicFluidMultiplier(e); + ai.set(GT_Utility.safeInt(aFluidInputs[0].amount * 512L, 1)); + } ); - return addFakeRecipe(aCheckForCollisions, new GT_Recipe(false, aInputs, aOutputs, aSpecial, null, aFluidInputs, aFluidOutputs, aDuration, aEUt, aSpecialValue)); + return addFakeRecipe(aCheckForCollisions, new GT_Recipe(false, aInputs, aOutputs, aSpecial, null, aFluidInputs, aFluidOutputs, ai.get(), aEUt, aSpecialValue)); } } diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 8584e849bb..05e0874e7a 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -65,6 +65,7 @@ import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.fluids.*; import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; +import net.minecraftforge.oredict.OreDictionary; import java.lang.reflect.Constructor; import java.lang.reflect.Field; @@ -522,6 +523,109 @@ public class GT_Utility { } /** + * moves multiple stacks from Inv-Side to Inv-Side + * + * @return the Amount of moved Items + */ + + public static int moveMultipleItemStacks(Object aTileEntity1, Object aTileEntity2, byte aGrabFrom, byte aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce,int aStackAmount) { + if (aTileEntity1 instanceof IInventory) + return moveMultipleItemStacks((IInventory) aTileEntity1, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce,aStackAmount, true); + return 0; + } + + public static int moveMultipleItemStacks(IInventory aTileEntity1, Object aTileEntity2, byte aGrabFrom, byte aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce,int aMaxStackTransfer, boolean aDoCheckChests) { + if (aTileEntity1 == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce || aMaxStackTransfer == 0) + return 0; + int tGrabInventorySize = aTileEntity1.getSizeInventory(); + if (aTileEntity2 instanceof IInventory) + { + IInventory tPutInventory = (IInventory) aTileEntity2; + int tPutInventorySize = tPutInventory.getSizeInventory(); + int tFirstsValidSlot = 0,tStacksMoved = 0,tTotalItemsMoved = 0; + for (int tGrabSlot = 0;tGrabSlot<tGrabInventorySize;tGrabSlot++) + { + //ItemStack tInventoryStack : mInventory + int tMovedItems; + do { + tMovedItems = 0; + ItemStack tGrabStack = aTileEntity1.getStackInSlot(tGrabSlot); + if (listContainsItem(aFilter, tGrabStack, true, aInvertFilter) && + (tGrabStack.stackSize >= aMinMoveAtOnce && isAllowedToTakeFromSlot(aTileEntity1, tGrabSlot, aGrabFrom, tGrabStack))) { + int tStackSize = tGrabStack.stackSize; + + for (int tPutSlot = tFirstsValidSlot; tPutSlot < tPutInventorySize; tPutSlot++) { + if (isAllowedToPutIntoSlot(tPutInventory, tPutSlot, aPutTo, tGrabStack, (byte) 64)) { + int tMoved = moveStackFromSlotAToSlotB(aTileEntity1, tPutInventory, tGrabSlot, tPutSlot, aMaxTargetStackSize, aMinTargetStackSize, (byte) (aMaxMoveAtOnce - tMovedItems), aMinMoveAtOnce); + tTotalItemsMoved += tMoved; + tMovedItems += tMoved; + if (tMovedItems == tStackSize) + break; + } + } + if (tMovedItems > 0) { + if (++tStacksMoved >= aMaxStackTransfer) + return tTotalItemsMoved; + } + } + } while (tGrabInventorySize == 2 && tMovedItems > 0); //to suport draweres and barrels + } + if (aDoCheckChests && aTileEntity1 instanceof TileEntityChest) { + TileEntityChest tTileEntity1 = (TileEntityChest) aTileEntity1; + int tAmount = 0; + int maxStackTransfer = aMaxStackTransfer - tStacksMoved; + if (tTileEntity1.adjacentChestXNeg != null) { + tAmount = moveMultipleItemStacks(tTileEntity1.adjacentChestXNeg, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce,maxStackTransfer, false); + } else if (tTileEntity1.adjacentChestZNeg != null) { + tAmount = moveMultipleItemStacks(tTileEntity1.adjacentChestZNeg, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce,maxStackTransfer, false); + } else if (tTileEntity1.adjacentChestXPos != null) { + tAmount = moveMultipleItemStacks(tTileEntity1.adjacentChestXPos, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce,maxStackTransfer, false); + } else if (tTileEntity1.adjacentChestZPos != null) { + tAmount = moveMultipleItemStacks(tTileEntity1.adjacentChestZPos, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce,maxStackTransfer, false); + } + if (tAmount != 0) return tAmount+tTotalItemsMoved; + } + + if (aDoCheckChests && aTileEntity2 instanceof TileEntityChest) { + TileEntityChest tTileEntity2 = (TileEntityChest) aTileEntity2; + if (tTileEntity2.adjacentChestChecked) { + int tAmount = 0; + int maxStackTransfer = aMaxStackTransfer - tStacksMoved; + if (tTileEntity2.adjacentChestXNeg != null) { + tAmount = moveMultipleItemStacks(aTileEntity1, tTileEntity2.adjacentChestXNeg, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce,maxStackTransfer, false); + } else if (tTileEntity2.adjacentChestZNeg != null) { + tAmount = moveMultipleItemStacks(aTileEntity1, tTileEntity2.adjacentChestZNeg, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce,maxStackTransfer, false); + } else if (tTileEntity2.adjacentChestXPos != null) { + tAmount = moveMultipleItemStacks(aTileEntity1, tTileEntity2.adjacentChestXPos, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce,maxStackTransfer, false); + } else if (tTileEntity2.adjacentChestZPos != null) { + tAmount = moveMultipleItemStacks(aTileEntity1, tTileEntity2.adjacentChestZPos, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce,maxStackTransfer, false); + } + if (tAmount != 0) return tAmount+tTotalItemsMoved; + } + } + + return tTotalItemsMoved; + + } + //there should be a function to transfer more then 1 stack in a pipe + //ut i dont see any ways to improve it too much work for what it is worth + int[] tGrabSlots = new int[tGrabInventorySize]; + for (int i = 0; i < tGrabInventorySize; i++) { + tGrabSlots[i] = i; + } + int tTotalItemsMoved = 0; + for (int i = 0; i < tGrabInventorySize; i++) { + int tMoved = moveStackIntoPipe(aTileEntity1, aTileEntity2, tGrabSlots, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, aDoCheckChests); + if (tMoved == 0) + return tTotalItemsMoved; + else + tTotalItemsMoved += tMoved; + } + return 0; + } + + + /** * Moves Stack from Inv-Side to Inv-Side. * * @return the Amount of moved Items @@ -538,7 +642,7 @@ public class GT_Utility { private static byte moveOneItemStack(IInventory aTileEntity1, Object aTileEntity2, byte aGrabFrom, byte aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce, boolean aDoCheckChests) { if (aTileEntity1 == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce) return 0; - + int[] tGrabSlots = null; if (aTileEntity1 instanceof ISidedInventory) tGrabSlots = ((ISidedInventory) aTileEntity1).getAccessibleSlotsFromSide(aGrabFrom); @@ -547,7 +651,7 @@ public class GT_Utility { for (int i = 0; i < tGrabSlots.length; i++) tGrabSlots[i] = i; } - if (aTileEntity2 != null && aTileEntity2 instanceof IInventory) { + if (aTileEntity2 instanceof IInventory) { int[] tPutSlots = null; if (aTileEntity2 instanceof ISidedInventory) tPutSlots = ((ISidedInventory) aTileEntity2).getAccessibleSlotsFromSide(aPutTo); @@ -559,15 +663,14 @@ public class GT_Utility { for (int i = 0; i < tGrabSlots.length; i++) { byte tMovedItemCount = 0; - for (int j = 0; j < tPutSlots.length; j++) { - if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(tGrabSlots[i]), true, aInvertFilter)) { - if (isAllowedToTakeFromSlot(aTileEntity1, tGrabSlots[i], aGrabFrom, aTileEntity1.getStackInSlot(tGrabSlots[i]))) { - if (isAllowedToPutIntoSlot((IInventory) aTileEntity2, tPutSlots[j], aPutTo, aTileEntity1.getStackInSlot(tGrabSlots[i]), aMaxTargetStackSize)) { - tMovedItemCount += moveStackFromSlotAToSlotB(aTileEntity1, (IInventory) aTileEntity2, tGrabSlots[i], tPutSlots[j], aMaxTargetStackSize, aMinTargetStackSize, (byte) (aMaxMoveAtOnce - tMovedItemCount), aMinMoveAtOnce); - if (tMovedItemCount >= aMaxMoveAtOnce) { + ItemStack tGrabStack = aTileEntity1.getStackInSlot(tGrabSlots[i]); + if (listContainsItem(aFilter, tGrabStack, true, aInvertFilter)) { + if (tGrabStack.stackSize >= aMinMoveAtOnce && isAllowedToTakeFromSlot(aTileEntity1, tGrabSlots[i], aGrabFrom, tGrabStack)) { + for (int j = 0; j < tPutSlots.length; j++) { + if (isAllowedToPutIntoSlot((IInventory) aTileEntity2, tPutSlots[j], aPutTo, tGrabStack, aMaxTargetStackSize)) { + tMovedItemCount += moveStackFromSlotAToSlotB(aTileEntity1, (IInventory) aTileEntity2, tGrabSlots[i], tPutSlots[j], aMaxTargetStackSize, aMinTargetStackSize, (byte) (aMaxMoveAtOnce - tMovedItemCount), aMinMoveAtOnce); + if (tMovedItemCount >= aMaxMoveAtOnce ||(tMovedItemCount > 0 && aMaxTargetStackSize < 64)) return tMovedItemCount; - - } } } } @@ -665,6 +768,64 @@ public class GT_Utility { return 0; } + /** + * Moves Stack from Inv-Side to Inv-Slot. + * + * @return the Amount of moved Items + */ + public static byte moveFromSlotToSide(IInventory fromTile, Object toTile, int aGrabFrom, byte aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce, boolean aDoCheckChests) { + if (fromTile == null || aGrabFrom < 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce) + return 0; + + if (!listContainsItem(aFilter, fromTile.getStackInSlot(aGrabFrom), true, aInvertFilter) || + !isAllowedToTakeFromSlot(fromTile, aGrabFrom, (byte) 6, fromTile.getStackInSlot(aGrabFrom))) + return 0; + + if (toTile instanceof IInventory) { + int[] tPutSlots = null; + if (toTile instanceof ISidedInventory) + tPutSlots = ((ISidedInventory) toTile).getAccessibleSlotsFromSide(aPutTo); + + if (tPutSlots == null) { + tPutSlots = new int[((IInventory) toTile).getSizeInventory()]; + for (int i = 0; i < tPutSlots.length; i++) tPutSlots[i] = i; + } + + byte tMovedItemCount = 0; + for (int tPutSlot : tPutSlots) { + if (isAllowedToPutIntoSlot((IInventory) toTile, tPutSlot, aPutTo, fromTile.getStackInSlot(aGrabFrom), aMaxTargetStackSize)) { + tMovedItemCount += moveStackFromSlotAToSlotB(fromTile, (IInventory) toTile, aGrabFrom, tPutSlot, aMaxTargetStackSize, aMinTargetStackSize, (byte) (aMaxMoveAtOnce - tMovedItemCount), aMinMoveAtOnce); + if (tMovedItemCount >= aMaxMoveAtOnce) { + return tMovedItemCount; + + } + } + } + if (tMovedItemCount > 0) return tMovedItemCount; + + if (aDoCheckChests && toTile instanceof TileEntityChest) { + TileEntityChest tTileEntity2 = (TileEntityChest) toTile; + if (tTileEntity2.adjacentChestChecked) { + if (tTileEntity2.adjacentChestXNeg != null) { + tMovedItemCount = moveFromSlotToSide(fromTile, tTileEntity2.adjacentChestXNeg, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); + } else if (tTileEntity2.adjacentChestZNeg != null) { + tMovedItemCount = moveFromSlotToSide(fromTile, tTileEntity2.adjacentChestZNeg, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); + } else if (tTileEntity2.adjacentChestXPos != null) { + tMovedItemCount = moveFromSlotToSide(fromTile, tTileEntity2.adjacentChestXPos, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); + } else if (tTileEntity2.adjacentChestZPos != null) { + tMovedItemCount = moveFromSlotToSide(fromTile, tTileEntity2.adjacentChestZPos, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); + } + if (tMovedItemCount > 0) return tMovedItemCount; + } + } + } + return moveStackIntoPipe(fromTile, toTile, new int[]{aGrabFrom}, (byte) 6, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, aDoCheckChests); + } + + public static byte moveFromSlotToSide(IInventory fromTile, Object toTile, int aGrabFrom, byte aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { + return moveFromSlotToSide(fromTile, toTile, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, true); + } + public static boolean listContainsItem(Collection<ItemStack> aList, ItemStack aStack, boolean aTIfListEmpty, boolean aInvertFilter) { if (aStack == null || aStack.stackSize < 1) return false; if (aList == null) return aTIfListEmpty; @@ -2432,5 +2593,12 @@ public class GT_Utility { public static boolean isPartOfOrePrefix(ItemStack aStack, OrePrefixes aPrefix){ return GT_OreDictUnificator.getAssociation(aStack) != null ? GT_OreDictUnificator.getAssociation(aStack).mPrefix.equals(aPrefix) : false; } + public static boolean isOre(ItemStack aStack) { + for (int id: OreDictionary.getOreIDs(aStack)) { + if (OreDictionary.getOreName(id).startsWith("ore")) + return true; + } + return false; + } } |