From 42543040b0533d2cd714412efa29a51b75321bb6 Mon Sep 17 00:00:00 2001 From: Minepolz320 <42765118+Minepolz320@users.noreply.github.com> Date: Sun, 19 Sep 2021 19:01:24 +0500 Subject: Fix GT Tools I tried to fix the tools --- .../gregtech/api/util/GT_ToolHarvestHelper.java | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/main/java/gregtech/api/util/GT_ToolHarvestHelper.java (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_ToolHarvestHelper.java b/src/main/java/gregtech/api/util/GT_ToolHarvestHelper.java new file mode 100644 index 0000000000..271b361da0 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_ToolHarvestHelper.java @@ -0,0 +1,61 @@ +package gregtech.api.util; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; + +public class GT_ToolHarvestHelper { + + public static boolean isAppropriateTool(Block aBlock, byte aMetaData, String... tTools) { + + if (aBlock == null || tTools == null) { + return false; + } + String targetTool = aBlock.getHarvestTool(aMetaData); + return !isStringEmpty(targetTool) && isArrayContains(targetTool, tTools); + } + + public static boolean isAppropriateMaterial(Block aBlock, Material... tMats) { + if (aBlock == null || tMats == null) { + return false; + } + return isArrayContains(aBlock.getMaterial(), tMats); + } + + + public static boolean isSpecialBlock(Block aBlock, Block... tBlocks) { + if (aBlock == null || tBlocks == null) { + return false; + } + return isArrayContains(aBlock, tBlocks); + } + + + public static boolean isArrayContains(T obj, T[] list) { + + if (obj == null || list == null) { + return false; + } + + for (T iObj : list) { + if (obj == iObj || obj.equals(iObj)) { + return true; + } + } + return false; + } + + public static boolean isStringEmpty(String s) { + return s == null || s.length() == 0; + } + + public static boolean hasNull(Object... obj) { + for (Object iObj : obj) { + if (iObj == null) { + return true; + } + } + return false; + } + + +} -- cgit From 9b127d5ab0157bacdb051f55eb2c41908c6df1d8 Mon Sep 17 00:00:00 2001 From: DreamMasterXXL Date: Sat, 25 Sep 2021 21:19:58 +0200 Subject: add 4 slots to Autoclave LV is 1 Slot MV is 2 Slots HV is 3 Slots EV is 4 Slots remove Silicon ebf recipe added new Sio2 recipes --- src/main/java/gregtech/api/enums/Materials.java | 2 +- .../api/interfaces/internal/IGT_RecipeAdder.java | 2 ++ src/main/java/gregtech/api/util/GT_Recipe.java | 2 +- src/main/java/gregtech/common/GT_RecipeAdder.java | 14 ++++++++++++++ .../loaders/postload/GT_MachineRecipeLoader.java | 4 ++++ .../loaders/preload/GT_Loader_MetaTileEntities.java | 10 +++++----- .../gregtech/textures/gui/basicmachines/Autoclave2.png | Bin 0 -> 3074 bytes .../gregtech/textures/gui/basicmachines/Autoclave3.png | Bin 0 -> 3162 bytes .../gregtech/textures/gui/basicmachines/Autoclave4.png | Bin 0 -> 3192 bytes 9 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave2.png create mode 100644 src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave3.png create mode 100644 src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave4.png (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/enums/Materials.java b/src/main/java/gregtech/api/enums/Materials.java index 5de8bb13cb..01216a01f3 100644 --- a/src/main/java/gregtech/api/enums/Materials.java +++ b/src/main/java/gregtech/api/enums/Materials.java @@ -106,7 +106,7 @@ public class Materials implements IColorModulationContainer, ISubTagContainer { public static Materials Rubidium = new Materials( 43, TextureSet.SET_METALLIC , 1.0F, 0, 2, 1|2 |8 |32 , 240, 30, 30, 0, "Rubidium" , "Rubidium" , 0, 0, 312, 0, false, false, 4, 1, 1, Dyes.dyeRed , Element.Rb , Arrays.asList(new TC_AspectStack(TC_Aspects.METALLUM, 2), new TC_AspectStack(TC_Aspects.VITREUS, 1))); public static Materials Samarium = new Materials( 69, TextureSet.SET_METALLIC , 1.0F, 0, 2, 1|2 |8 |32 , 255, 255, 204, 0, "Samarium" , "Samarium" , 0, 0, 1345, 1345, true, false, 4, 1, 1, Dyes.dyeWhite , Element.Sm , Arrays.asList(new TC_AspectStack(TC_Aspects.METALLUM, 2), new TC_AspectStack(TC_Aspects.RADIO, 1), new TC_AspectStack(TC_Aspects.MAGNETO,10))); public static Materials Scandium = new Materials( 27, TextureSet.SET_METALLIC , 1.0F, 0, 2, 1|2 |8 |32 , 255, 255, 255, 0, "Scandium" , "Scandium" , 0, 0, 1814, 1814, true, false, 2, 1, 1, Dyes.dyeYellow , Element.Sc , Arrays.asList(new TC_AspectStack(TC_Aspects.METALLUM, 2), new TC_AspectStack(TC_Aspects.RADIO, 1))); - public static Materials Silicon = new Materials( 20, TextureSet.SET_METALLIC , 1.0F, 0, 2, 1|2 |8 |32 , 60, 60, 80, 0, "Silicon" , "Silicon" , 0, 0, 1687, 1687, true, false, 1, 1, 1, Dyes.dyeBlack , Element.Si , Arrays.asList(new TC_AspectStack(TC_Aspects.METALLUM, 2), new TC_AspectStack(TC_Aspects.TENEBRAE, 1))); + public static Materials Silicon = new Materials( 20, TextureSet.SET_METALLIC , 1.0F, 0, 2, 1|2 |8 |32 , 60, 60, 80, 0, "Silicon" , "Silicon" , 0, 0, 1687, 1687, true, false, 1, 1, 1, Dyes.dyeBlack , Element.Si , Arrays.asList(new TC_AspectStack(TC_Aspects.METALLUM, 2), new TC_AspectStack(TC_Aspects.TENEBRAE, 1))).disableAutoGeneratedBlastFurnaceRecipes(); public static Materials Silver = new Materials( 54, TextureSet.SET_SHINY , 10.0F, 64, 2, 1|2 |8 |32|64|128 , 220, 220, 255, 0, "Silver" , "Silver" , 0, 0, 1234, 0, false, false, 3, 1, 1, Dyes.dyeLightGray , Element.Ag , Arrays.asList(new TC_AspectStack(TC_Aspects.METALLUM, 2), new TC_AspectStack(TC_Aspects.LUCRUM, 1))); public static Materials Sodium = new Materials( 17, TextureSet.SET_METALLIC , 1.0F, 0, 2, 1 |32 , 0, 0, 150, 0, "Sodium" , "Sodium" , 0, 0, 370, 0, false, false, 1, 1, 1, Dyes.dyeBlue , Element.Na , Arrays.asList(new TC_AspectStack(TC_Aspects.VITREUS, 2), new TC_AspectStack(TC_Aspects.LUX, 1))); public static Materials Strontium = new Materials( 44, TextureSet.SET_METALLIC , 1.0F, 0, 2, 1 |8 |32 , 200, 200, 200, 0, "Strontium" , "Strontium" , 0, 0, 1050, 0, false, false, 1, 1, 1, Dyes.dyeLightGray , Element.Sr , Arrays.asList(new TC_AspectStack(TC_Aspects.METALLUM, 2), new TC_AspectStack(TC_Aspects.STRONTIO, 1))); diff --git a/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java b/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java index f500e8027e..818e584db1 100644 --- a/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java +++ b/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java @@ -615,6 +615,8 @@ public interface IGT_RecipeAdder { boolean addAutoclaveSpaceRecipe(ItemStack aInput, ItemStack aCircuit, FluidStack aFluid, ItemStack aOutput, int aChance, int aDuration, int aEUt, boolean aCleanroom); + boolean addAutoclave4Recipe(ItemStack aInput, ItemStack aCircuit, FluidStack aFluidIn, FluidStack aFluidOut, ItemStack[] aOutputs, int[] aChances, int aDuration, int aEUt, boolean aCleanroom); + /** * Adds a Recipe for the Mixer */ diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index f941a86f5c..1e5dae33e3 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -589,7 +589,7 @@ public class GT_Recipe implements Comparable { public static final GT_Recipe_Map sPressRecipes = new GT_Recipe_Map_FormingPress(new HashSet<>(300), "gt.recipe.press", "Forming Press", null, RES_PATH_GUI + "basicmachines/Press", 2, 1, 2, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sLaserEngraverRecipes = new GT_Recipe_Map(new HashSet<>(810), "gt.recipe.laserengraver", "Precision Laser Engraver", null, RES_PATH_GUI + "basicmachines/LaserEngraver", 2, 1, 2, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sMixerRecipes = new GT_Recipe_Map(new HashSet<>(900), "gt.recipe.mixer", "Mixer", null, RES_PATH_GUI + "basicmachines/Mixer2", 9, 1, 1, 0, 1, E, 1, E, true, true); - public static final GT_Recipe_Map sAutoclaveRecipes = new GT_Recipe_Map(new HashSet<>(300), "gt.recipe.autoclave", "Autoclave", null, RES_PATH_GUI + "basicmachines/Autoclave", 2, 1, 1, 1, 1, E, 1, E, true, true); + public static final GT_Recipe_Map sAutoclaveRecipes = new GT_Recipe_Map(new HashSet<>(300), "gt.recipe.autoclave", "Autoclave", null, RES_PATH_GUI + "basicmachines/Autoclave", 2, 4, 1, 1, 1, E, 1, E, true, true); public static final GT_Recipe_Map sElectroMagneticSeparatorRecipes = new GT_Recipe_Map(new HashSet<>(50), "gt.recipe.electromagneticseparator", "Electromagnetic Separator", null, RES_PATH_GUI + "basicmachines/ElectromagneticSeparator", 1, 3, 1, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sPolarizerRecipes = new GT_Recipe_Map(new HashSet<>(300), "gt.recipe.polarizer", "Electromagnetic Polarizer", null, RES_PATH_GUI + "basicmachines/Polarizer", 1, 1, 1, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sMaceratorRecipes = new GT_Recipe_Map_Macerator(new HashSet<>(16600), "gt.recipe.macerator", "Pulverization", null, RES_PATH_GUI + "basicmachines/Macerator4", 1, 4, 1, 0, 1, E, 1, E, true, true); diff --git a/src/main/java/gregtech/common/GT_RecipeAdder.java b/src/main/java/gregtech/common/GT_RecipeAdder.java index cdf3bf38b7..f7439e3e8e 100644 --- a/src/main/java/gregtech/common/GT_RecipeAdder.java +++ b/src/main/java/gregtech/common/GT_RecipeAdder.java @@ -1076,6 +1076,20 @@ public class GT_RecipeAdder implements IGT_RecipeAdder { GT_Recipe.GT_Recipe_Map.sAutoclaveRecipes.addRecipe(true, new ItemStack[]{aInput, aCircuit}, new ItemStack[]{aOutput}, null, new int[]{aChance}, new FluidStack[]{aFluid}, null, aDuration, aEUt, aCleanroom ? -100 : 0); return true; } + @Override + public boolean addAutoclave4Recipe(ItemStack aInput, ItemStack aCircuit, FluidStack aFluidIn, FluidStack aFluidOut, ItemStack[] aOutputs, int[] aChances, int aDuration, int aEUt, boolean aCleanroom) { + if ((aInput == null) || (aFluidIn == null) || (aOutputs == null)) { + return false; + } + if ((aDuration = GregTech_API.sRecipeFile.get("autoclave", aInput, aDuration)) <= 0) { + return false; + } + if (!GT_Mod.gregtechproxy.mEnableCleanroom){ + aCleanroom = false; + } + GT_Recipe.GT_Recipe_Map.sAutoclaveRecipes.addRecipe(true, new ItemStack[] {aInput, aCircuit} , aOutputs, null, aChances, new FluidStack[]{aFluidIn}, new FluidStack[]{aFluidOut}, aDuration, aEUt, aCleanroom ? -200 : 0); + return true; + } @Override public boolean addMixerRecipe(ItemStack aInput1, ItemStack aInput2, ItemStack aInput3, ItemStack aInput4, FluidStack aFluidInput, FluidStack aFluidOutput, ItemStack aOutput, int aDuration, int aEUt) { diff --git a/src/main/java/gregtech/loaders/postload/GT_MachineRecipeLoader.java b/src/main/java/gregtech/loaders/postload/GT_MachineRecipeLoader.java index 43e5d62233..d1eb475b96 100644 --- a/src/main/java/gregtech/loaders/postload/GT_MachineRecipeLoader.java +++ b/src/main/java/gregtech/loaders/postload/GT_MachineRecipeLoader.java @@ -446,6 +446,10 @@ public class GT_MachineRecipeLoader implements Runnable { GT_Values.RA.addAutoclaveRecipe(GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Carbon, 64), Materials.Plastic.getMolten(576L), GT_ModHandler.getIC2Item("carbonFiber", 16L), 10000, 600, 30); GT_Values.RA.addAutoclaveRecipe(GT_OreDictUnificator.get(OrePrefixes.dust, Materials.NetherStar, 1), Materials.UUMatter.getFluid(576L), GT_OreDictUnificator.get(OrePrefixes.gem, Materials.NetherStar, 1), 3333, 72000, 480); + GT_Values.RA.addAutoclave4Recipe(GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Silicon, 1), GT_Utility.getIntegratedCircuit(1), Materials.Water.getFluid(1000L), GT_Values.NF, new ItemStack[]{GT_Values.NI, GT_OreDictUnificator.get(OrePrefixes.dust, Materials.SiliconDioxide, 1)}, new int[]{7500}, 1200, 30, false); + GT_Values.RA.addAutoclave4Recipe(GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Silicon, 1), GT_Utility.getIntegratedCircuit(1), GT_ModHandler.getDistilledWater(500L), GT_Values.NF, new ItemStack[]{GT_Values.NI, GT_OreDictUnificator.get(OrePrefixes.dust, Materials.SiliconDioxide, 1)}, new int[]{9000}, 1200, 30, false); + GT_Values.RA.addSimpleArcFurnaceRecipe(GT_OreDictUnificator.get(OrePrefixes.dust,Materials.Silicon, 1L), Materials.Oxygen.getGas(288L), new ItemStack[]{GT_OreDictUnificator.get(OrePrefixes.dust,Materials.SiliconDioxide,1)}, null, 1200,30); + GT_Values.RA.addAssemblerRecipe(GT_OreDictUnificator.get(OrePrefixes.foil, Materials.PolyvinylChloride,1),ItemList.Paper_Printed_Pages.get(1L),Materials.Glue.getFluid(20L), new ItemStack(Items.written_book,1,0), 32, 8); GT_Values.RA.addAssemblerRecipe(GT_OreDictUnificator.get(OrePrefixes.foil, Materials.PolyvinylChloride,1), GT_OreDictUnificator.get(OrePrefixes.plate, Materials.Paper, 3), Materials.Glue.getFluid(20L), new ItemStack(Items.book,1,0),20,16); GT_Values.RA.addAssemblerRecipe(new ItemStack[]{GT_ModHandler.getIC2Item("carbonMesh", 4L), GT_OreDictUnificator.get(OrePrefixes.foil, Materials.Zinc, 16L), GT_Utility.getIntegratedCircuit(1)}, GT_Values.NF, ItemList.Component_Filter.get(1L), 1600, 30); diff --git a/src/main/java/gregtech/loaders/preload/GT_Loader_MetaTileEntities.java b/src/main/java/gregtech/loaders/preload/GT_Loader_MetaTileEntities.java index c45951a06f..39c9f3dbcb 100644 --- a/src/main/java/gregtech/loaders/preload/GT_Loader_MetaTileEntities.java +++ b/src/main/java/gregtech/loaders/preload/GT_Loader_MetaTileEntities.java @@ -769,11 +769,11 @@ public class GT_Loader_MetaTileEntities implements Runnable {//TODO CHECK CIRCUI ItemList.Machine_EV_ElectromagneticSeparator.set(new GT_MetaTileEntity_BasicMachine_GT_Recipe(564, "basicmachine.electromagneticseparator.tier.04", "Advanced Electromagnetic Separator III", 4, "Separating the magnetic Ores from the rest", GT_Recipe.GT_Recipe_Map.sElectroMagneticSeparatorRecipes, 1, 3, 0, 0, 1, "ElectromagneticSeparator.png", GregTech_API.sSoundList.get(Integer.valueOf(212)), aBoolConst_0, aBoolConst_0, 0, "ELECTROMAGNETIC_SEPARATOR", new Object[]{"VWZ", "WMS", "CWZ", 'M', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.HULL, 'S', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.STICK_ELECTROMAGNETIC, 'Z', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.COIL_ELECTRIC, 'V', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.CONVEYOR, 'C', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.CIRCUIT, 'W', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.WIRE}).getStackForm(1L)); ItemList.Machine_IV_ElectromagneticSeparator.set(new GT_MetaTileEntity_BasicMachine_GT_Recipe(565, "basicmachine.electromagneticseparator.tier.05", "Advanced Electromagnetic Separator IV", 5, "Separating the magnetic Ores from the rest", GT_Recipe.GT_Recipe_Map.sElectroMagneticSeparatorRecipes, 1, 3, 0, 0, 1, "ElectromagneticSeparator.png", GregTech_API.sSoundList.get(Integer.valueOf(212)), aBoolConst_0, aBoolConst_0, 0, "ELECTROMAGNETIC_SEPARATOR", new Object[]{"VWZ", "WMS", "CWZ", 'M', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.HULL, 'S', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.STICK_ELECTROMAGNETIC, 'Z', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.COIL_ELECTRIC, 'V', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.CONVEYOR, 'C', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.CIRCUIT, 'W', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.WIRE}).getStackForm(1L)); - ItemList.Machine_LV_Autoclave.set(new GT_MetaTileEntity_BasicMachine_GT_Recipe(571, "basicmachine.autoclave.tier.01", "Basic Autoclave", 1, "Crystallizing your Dusts", GT_Recipe.GT_Recipe_Map.sAutoclaveRecipes, 2, 1, 8000, 0, 1, "Autoclave.png", "", aBoolConst_0, aBoolConst_0, 0, "AUTOCLAVE", new Object[]{"IGI", "IMI", "CPC", 'M', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.HULL, 'P', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PUMP, 'C', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.CIRCUIT, 'W', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.WIRE, 'I', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PLATE, 'G', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.GLASS}).getStackForm(1L)); - ItemList.Machine_MV_Autoclave.set(new GT_MetaTileEntity_BasicMachine_GT_Recipe(572, "basicmachine.autoclave.tier.02", "Advanced Autoclave", 2, "Crystallizing your Dusts", GT_Recipe.GT_Recipe_Map.sAutoclaveRecipes, 2, 1, 8000, 0, 1, "Autoclave.png", "", aBoolConst_0, aBoolConst_0, 0, "AUTOCLAVE", new Object[]{"IGI", "IMI", "CPC", 'M', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.HULL, 'P', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PUMP, 'C', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.CIRCUIT, 'W', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.WIRE, 'I', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PLATE, 'G', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.GLASS}).getStackForm(1L)); - ItemList.Machine_HV_Autoclave.set(new GT_MetaTileEntity_BasicMachine_GT_Recipe(573, "basicmachine.autoclave.tier.03", "Advanced Autoclave II", 3, "Crystallizing your Dusts", GT_Recipe.GT_Recipe_Map.sAutoclaveRecipes, 2, 1, 8000, 0, 1, "Autoclave.png", "", aBoolConst_0, aBoolConst_0, 0, "AUTOCLAVE", new Object[]{"IGI", "IMI", "CPC", 'M', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.HULL, 'P', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PUMP, 'C', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.CIRCUIT, 'W', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.WIRE, 'I', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PLATE, 'G', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.GLASS}).getStackForm(1L)); - ItemList.Machine_EV_Autoclave.set(new GT_MetaTileEntity_BasicMachine_GT_Recipe(574, "basicmachine.autoclave.tier.04", "Advanced Autoclave III", 4, "Crystallizing your Dusts", GT_Recipe.GT_Recipe_Map.sAutoclaveRecipes, 2, 1, 8000, 0, 1, "Autoclave.png", "", aBoolConst_0, aBoolConst_0, 0, "AUTOCLAVE", new Object[]{"IGI", "IMI", "CPC", 'M', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.HULL, 'P', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PUMP, 'C', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.CIRCUIT, 'W', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.WIRE, 'I', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PLATE, 'G', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.GLASS}).getStackForm(1L)); - ItemList.Machine_IV_Autoclave.set(new GT_MetaTileEntity_BasicMachine_GT_Recipe(575, "basicmachine.autoclave.tier.05", "Advanced Autoclave IV", 5, "Crystallizing your Dusts", GT_Recipe.GT_Recipe_Map.sAutoclaveRecipes, 2, 1, 8000, 0, 1, "Autoclave.png", "", aBoolConst_0, aBoolConst_0, 0, "AUTOCLAVE", new Object[]{"IGI", "IMI", "CPC", 'M', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.HULL, 'P', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PUMP, 'C', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.CIRCUIT, 'W', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.WIRE, 'I', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PLATE, 'G', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.GLASS}).getStackForm(1L)); + ItemList.Machine_LV_Autoclave.set(new GT_MetaTileEntity_BasicMachine_GT_Recipe(571, "basicmachine.autoclave.tier.01", "Basic Autoclave", 1, "Crystallizing your Dusts", GT_Recipe.GT_Recipe_Map.sAutoclaveRecipes, 2, 1, 10000, 0, 1, "Autoclave.png", "", aBoolConst_0, aBoolConst_0, 0, "AUTOCLAVE", new Object[]{"IGI", "IMI", "CPC", 'M', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.HULL, 'P', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PUMP, 'C', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.CIRCUIT, 'W', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.WIRE, 'I', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PLATE, 'G', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.GLASS}).getStackForm(1L)); + ItemList.Machine_MV_Autoclave.set(new GT_MetaTileEntity_BasicMachine_GT_Recipe(572, "basicmachine.autoclave.tier.02", "Advanced Autoclave", 2, "Crystallizing your Dusts", GT_Recipe.GT_Recipe_Map.sAutoclaveRecipes, 2, 2, 20000, 0, 1, "Autoclave2.png", "", aBoolConst_0, aBoolConst_0, 0, "AUTOCLAVE", new Object[]{"IGI", "IMI", "CPC", 'M', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.HULL, 'P', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PUMP, 'C', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.CIRCUIT, 'W', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.WIRE, 'I', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PLATE, 'G', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.GLASS}).getStackForm(1L)); + ItemList.Machine_HV_Autoclave.set(new GT_MetaTileEntity_BasicMachine_GT_Recipe(573, "basicmachine.autoclave.tier.03", "Advanced Autoclave II", 3, "Crystallizing your Dusts", GT_Recipe.GT_Recipe_Map.sAutoclaveRecipes, 2, 3, 30000, 0, 1, "Autoclave3.png", "", aBoolConst_0, aBoolConst_0, 0, "AUTOCLAVE", new Object[]{"IGI", "IMI", "CPC", 'M', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.HULL, 'P', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PUMP, 'C', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.CIRCUIT, 'W', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.WIRE, 'I', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PLATE, 'G', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.GLASS}).getStackForm(1L)); + ItemList.Machine_EV_Autoclave.set(new GT_MetaTileEntity_BasicMachine_GT_Recipe(574, "basicmachine.autoclave.tier.04", "Advanced Autoclave III", 4, "Crystallizing your Dusts", GT_Recipe.GT_Recipe_Map.sAutoclaveRecipes, 2, 4, 40000, 0, 1, "Autoclave4.png", "", aBoolConst_0, aBoolConst_0, 0, "AUTOCLAVE", new Object[]{"IGI", "IMI", "CPC", 'M', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.HULL, 'P', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PUMP, 'C', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.CIRCUIT, 'W', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.WIRE, 'I', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PLATE, 'G', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.GLASS}).getStackForm(1L)); + ItemList.Machine_IV_Autoclave.set(new GT_MetaTileEntity_BasicMachine_GT_Recipe(575, "basicmachine.autoclave.tier.05", "Advanced Autoclave IV", 5, "Crystallizing your Dusts", GT_Recipe.GT_Recipe_Map.sAutoclaveRecipes, 2, 4, 50000, 0, 1, "Autoclave4.png", "", aBoolConst_0, aBoolConst_0, 0, "AUTOCLAVE", new Object[]{"IGI", "IMI", "CPC", 'M', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.HULL, 'P', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PUMP, 'C', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.CIRCUIT, 'W', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.WIRE, 'I', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PLATE, 'G', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.GLASS}).getStackForm(1L)); ItemList.Machine_LV_Mixer.set(new GT_MetaTileEntity_BasicMachine_GT_Recipe(581, "basicmachine.mixer.tier.01", "Basic Mixer", 1, "Will it Blend?", GT_Recipe.GT_Recipe_Map.sMixerRecipes, 6, 1, 16000, 0, 1, "Mixer.png", "", aBoolConst_0, aBoolConst_0, 0, "MIXER", new Object[]{"GRG", "GEG", aTextCableHull, 'M', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.HULL, 'E', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.MOTOR, 'R', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.ROTOR, 'C', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.CIRCUIT, 'G', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.GLASS}).getStackForm(1L)); ItemList.Machine_MV_Mixer.set(new GT_MetaTileEntity_BasicMachine_GT_Recipe(582, "basicmachine.mixer.tier.02", "Advanced Mixer", 2, "Will it Blend?", GT_Recipe.GT_Recipe_Map.sMixerRecipes, 6, 1, 32000, 0, 1, "Mixer.png", "", aBoolConst_0, aBoolConst_0, 0, "MIXER", new Object[]{"GRG", "GEG", aTextCableHull, 'M', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.HULL, 'E', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.MOTOR, 'R', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.ROTOR, 'C', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.CIRCUIT, 'G', GT_MetaTileEntity_BasicMachine_GT_Recipe.X.GLASS}).getStackForm(1L)); diff --git a/src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave2.png b/src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave2.png new file mode 100644 index 0000000000..f51e49403e Binary files /dev/null and b/src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave2.png differ diff --git a/src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave3.png b/src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave3.png new file mode 100644 index 0000000000..4c7ff15604 Binary files /dev/null and b/src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave3.png differ diff --git a/src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave4.png b/src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave4.png new file mode 100644 index 0000000000..7920326c19 Binary files /dev/null and b/src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave4.png differ -- cgit From cd46cdbffeb639d0d53c6211d936254da705e68e Mon Sep 17 00:00:00 2001 From: DreamMasterXXL Date: Sat, 25 Sep 2021 22:15:41 +0200 Subject: fix Autoclave graphic (cherry picked from commit 4544849c1afe7a6aa9a5da370cb98b19bad25c53) --- src/main/java/gregtech/api/util/GT_Recipe.java | 2 +- .../textures/gui/basicmachines/Autoclave3.png | Bin 3162 -> 3116 bytes .../textures/gui/basicmachines/Autoclave4.png | Bin 3192 -> 3188 bytes 3 files changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 1e5dae33e3..c9dc755163 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -589,7 +589,7 @@ public class GT_Recipe implements Comparable { public static final GT_Recipe_Map sPressRecipes = new GT_Recipe_Map_FormingPress(new HashSet<>(300), "gt.recipe.press", "Forming Press", null, RES_PATH_GUI + "basicmachines/Press", 2, 1, 2, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sLaserEngraverRecipes = new GT_Recipe_Map(new HashSet<>(810), "gt.recipe.laserengraver", "Precision Laser Engraver", null, RES_PATH_GUI + "basicmachines/LaserEngraver", 2, 1, 2, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sMixerRecipes = new GT_Recipe_Map(new HashSet<>(900), "gt.recipe.mixer", "Mixer", null, RES_PATH_GUI + "basicmachines/Mixer2", 9, 1, 1, 0, 1, E, 1, E, true, true); - public static final GT_Recipe_Map sAutoclaveRecipes = new GT_Recipe_Map(new HashSet<>(300), "gt.recipe.autoclave", "Autoclave", null, RES_PATH_GUI + "basicmachines/Autoclave", 2, 4, 1, 1, 1, E, 1, E, true, true); + public static final GT_Recipe_Map sAutoclaveRecipes = new GT_Recipe_Map(new HashSet<>(300), "gt.recipe.autoclave", "Autoclave", null, RES_PATH_GUI + "basicmachines/Autoclave4", 2, 4, 1, 1, 1, E, 1, E, true, true); public static final GT_Recipe_Map sElectroMagneticSeparatorRecipes = new GT_Recipe_Map(new HashSet<>(50), "gt.recipe.electromagneticseparator", "Electromagnetic Separator", null, RES_PATH_GUI + "basicmachines/ElectromagneticSeparator", 1, 3, 1, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sPolarizerRecipes = new GT_Recipe_Map(new HashSet<>(300), "gt.recipe.polarizer", "Electromagnetic Polarizer", null, RES_PATH_GUI + "basicmachines/Polarizer", 1, 1, 1, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sMaceratorRecipes = new GT_Recipe_Map_Macerator(new HashSet<>(16600), "gt.recipe.macerator", "Pulverization", null, RES_PATH_GUI + "basicmachines/Macerator4", 1, 4, 1, 0, 1, E, 1, E, true, true); diff --git a/src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave3.png b/src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave3.png index 4c7ff15604..246016646a 100644 Binary files a/src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave3.png and b/src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave3.png differ diff --git a/src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave4.png b/src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave4.png index 7920326c19..f5fc427c18 100644 Binary files a/src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave4.png and b/src/main/resources/assets/gregtech/textures/gui/basicmachines/Autoclave4.png differ -- cgit From e40d83562bd80e57c567fd1f11f0b28108368e7f Mon Sep 17 00:00:00 2001 From: GlodBlock <60341015+GlodBlock@users.noreply.github.com> Date: Sun, 26 Sep 2021 21:02:11 +0800 Subject: preload all FluidContainerData --- src/main/java/gregtech/api/util/GT_Utility.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index be5f978d6e..64a60e8630 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -102,6 +102,7 @@ public class GT_Utility { private static final List sFluidContainerList = new ArrayList<>(); private static final Map sFilledContainerToData = new /*Concurrent*/HashMap<>(); private static final Map> sEmptyContainerToFluidToData = new /*Concurrent*/HashMap<>(); + private static final Map> sFluidToContainers = new HashMap<>(); public static volatile int VERSION = 509; public static boolean TE_CHECK = false, BC_CHECK = false, CHECK_ALL = true, RF_CHECK = false; public static Map sPlayedSoundMap = new /*Concurrent*/HashMap<>(); @@ -918,14 +919,22 @@ public class GT_Utility { public static void reInit() { sFilledContainerToData.clear(); sEmptyContainerToFluidToData.clear(); + sFluidToContainers.clear(); for (FluidContainerData tData : sFluidContainerList) { sFilledContainerToData.put(new GT_ItemStack(tData.filledContainer), tData); Map tFluidToContainer = sEmptyContainerToFluidToData.get(new GT_ItemStack(tData.emptyContainer)); + List tContainers = sFluidToContainers.get(tData.fluid.getFluid()); if (tFluidToContainer == null) { sEmptyContainerToFluidToData.put(new GT_ItemStack(tData.emptyContainer), tFluidToContainer = new /*Concurrent*/HashMap<>()); GregTech_API.sFluidMappings.add(tFluidToContainer); } tFluidToContainer.put(tData.fluid.getFluid(), tData); + if (tContainers == null) { + tContainers = new ArrayList<>(); + tContainers.add(tData.filledContainer); + sFluidToContainers.put(tData.fluid.getFluid(), tContainers); + } + else tContainers.add(tData.filledContainer); } } @@ -933,11 +942,27 @@ public class GT_Utility { sFluidContainerList.add(aData); sFilledContainerToData.put(new GT_ItemStack(aData.filledContainer), aData); Map tFluidToContainer = sEmptyContainerToFluidToData.get(new GT_ItemStack(aData.emptyContainer)); + List tContainers = sFluidToContainers.get(aData.fluid.getFluid()); if (tFluidToContainer == null) { sEmptyContainerToFluidToData.put(new GT_ItemStack(aData.emptyContainer), tFluidToContainer = new /*Concurrent*/HashMap<>()); GregTech_API.sFluidMappings.add(tFluidToContainer); } tFluidToContainer.put(aData.fluid.getFluid(), aData); + if (tContainers == null) { + tContainers = new ArrayList<>(); + tContainers.add(aData.filledContainer); + sFluidToContainers.put(aData.fluid.getFluid(), tContainers); + } + else tContainers.add(aData.filledContainer); + } + + public static List getContainersFromFluid(FluidStack tFluidStack) { + if (tFluidStack != null) { + List tContainers = sFluidToContainers.get(tFluidStack.getFluid()); + if (tContainers == null) return new ArrayList<>(); + return tContainers; + } + return new ArrayList<>(); } public static ItemStack fillFluidContainer(FluidStack aFluid, ItemStack aStack, boolean aRemoveFluidDirectly, boolean aCheckIFluidContainerItems) { -- cgit From 55cc4021bbb655e9ab86d799d9ee9cc803d3d5c4 Mon Sep 17 00:00:00 2001 From: GlodBlock <1356392126@qq.com> Date: Mon, 27 Sep 2021 18:56:42 +0800 Subject: allow VF to accept fluid input --- .../api/interfaces/internal/IGT_RecipeAdder.java | 2 + src/main/java/gregtech/api/util/GT_Recipe.java | 9 +++- src/main/java/gregtech/common/GT_RecipeAdder.java | 24 +++++++++-- .../multi/GT_MetaTileEntity_VacuumFreezer.java | 49 +++++++++++----------- 4 files changed, 55 insertions(+), 29 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java b/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java index f500e8027e..2490b37eb1 100644 --- a/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java +++ b/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java @@ -504,6 +504,8 @@ public interface IGT_RecipeAdder { boolean addVacuumFreezerRecipe(ItemStack aInput1, ItemStack aOutput1, int aDuration, int aEUt); + boolean addVacuumFreezerRecipe(FluidStack aInput1, FluidStack aOutput1, int aDuration, int aEUt); + /** * Adds a Fuel for My Generators * diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index f941a86f5c..9b0bfb970a 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -302,6 +302,13 @@ public class GT_Recipe implements Comparable { } } + public GT_Recipe(FluidStack aInput1, FluidStack aOutput1, int aDuration, int aEUt) { + this(false, null, null, null, null, new FluidStack[]{aInput1}, new FluidStack[]{aOutput1}, Math.max(aDuration, 1), aEUt, 0); + if (mFluidInputs.length > 0 && mFluidOutputs[0] != null) { + GT_Recipe_Map.sVacuumRecipes.addRecipe(this); + } + } + //Dummy GT_Recipe maker... public GT_Recipe(ItemStack[] aInputs, ItemStack[] aOutputs, Object aSpecialItems, int[] aChances, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, int aDuration, int aEUt, int aSpecialValue){ this(true, aInputs, aOutputs, aSpecialItems, aChances, aFluidInputs, aFluidOutputs, aDuration, aEUt, aSpecialValue); @@ -609,7 +616,7 @@ public class GT_Recipe implements Comparable { public static final GT_Recipe_Map sBlastRecipes = new GT_Recipe_Map(new HashSet<>(800), "gt.recipe.blastfurnace", "Blast Furnace", null, RES_PATH_GUI + "basicmachines/Default", 2, 2, 1, 0, 1, "Heat Capacity: ", 1, " K", false, true); public static final GT_Recipe_Map sPrimitiveBlastRecipes = new GT_Recipe_Map(new HashSet<>(200), "gt.recipe.primitiveblastfurnace", "Primitive Blast Furnace", null, RES_PATH_GUI + "basicmachines/Default", 3, 3, 1, 0, 1, E, 1, E, false, true); public static final GT_Recipe_Map sImplosionRecipes = new GT_Recipe_Map(new HashSet<>(900), "gt.recipe.implosioncompressor", "Implosion Compressor", null, RES_PATH_GUI + "basicmachines/Default", 2, 2, 2, 0, 1, E, 1, E, true, true); - public static final GT_Recipe_Map sVacuumRecipes = new GT_Recipe_Map(new HashSet<>(305), "gt.recipe.vacuumfreezer", "Vacuum Freezer", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 1, 0, 1, E, 1, E, false, true); + public static final GT_Recipe_Map sVacuumRecipes = new GT_Recipe_Map(new HashSet<>(305), "gt.recipe.vacuumfreezer", "Vacuum Freezer", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, E, 1, E, false, true); public static final GT_Recipe_Map sChemicalRecipes = new GT_Recipe_Map(new HashSet<>(1170), "gt.recipe.chemicalreactor", "Chemical Reactor", null, RES_PATH_GUI + "basicmachines/ChemicalReactor", 2, 2, 1, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sMultiblockChemicalRecipes = new GT_Recipe_Map_LargeChemicalReactor(); public static final GT_Recipe_Map sDistillationRecipes = new GT_Recipe_Map_DistillationTower(); diff --git a/src/main/java/gregtech/common/GT_RecipeAdder.java b/src/main/java/gregtech/common/GT_RecipeAdder.java index cdf3bf38b7..7e996be264 100644 --- a/src/main/java/gregtech/common/GT_RecipeAdder.java +++ b/src/main/java/gregtech/common/GT_RecipeAdder.java @@ -10,11 +10,8 @@ import gregtech.api.enums.OrePrefixes; import gregtech.api.interfaces.internal.IGT_RecipeAdder; import gregtech.api.objects.GT_FluidStack; import gregtech.api.objects.ItemData; -import gregtech.api.util.GT_ModHandler; -import gregtech.api.util.GT_OreDictUnificator; -import gregtech.api.util.GT_Recipe; +import gregtech.api.util.*; import gregtech.api.util.GT_Recipe.GT_Recipe_AssemblyLine; -import gregtech.api.util.GT_Utility; import gregtech.common.items.GT_IntegratedCircuit_Item; import mods.railcraft.common.blocks.aesthetics.cube.EnumCube; import mods.railcraft.common.items.RailcraftToolItems; @@ -660,6 +657,11 @@ public class GT_RecipeAdder implements IGT_RecipeAdder { return false; } new GT_Recipe(aInput1, aOutput1, aDuration, aEUt, 0);//Since all other methods are taken + FluidStack tInputFluid = GT_Utility.getFluidForFilledItem(aInput1, true); + FluidStack tOutputFluid = GT_Utility.getFluidForFilledItem(aOutput1, true); + if (tInputFluid != null && tOutputFluid != null) { + addVacuumFreezerRecipe(tInputFluid, tOutputFluid, aDuration, aEUt); + } return true; } @@ -672,6 +674,20 @@ public class GT_RecipeAdder implements IGT_RecipeAdder { return false; } new GT_Recipe(aInput1, aOutput1, aDuration); + FluidStack tInputFluid = GT_Utility.getFluidForFilledItem(aInput1, true); + FluidStack tOutputFluid = GT_Utility.getFluidForFilledItem(aOutput1, true); + if (tInputFluid != null && tOutputFluid != null) { + addVacuumFreezerRecipe(tInputFluid, tOutputFluid, aDuration, 120); + } + return true; + } + + @Override + public boolean addVacuumFreezerRecipe(FluidStack aInput1, FluidStack aOutput1, int aDuration, int aEUt) { + if ((aInput1 == null) || (aOutput1 == null)) { + return false; + } + new GT_Recipe(aInput1, aOutput1, aDuration, aEUt); return true; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java index b7f24f7e7a..843f2ff337 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java @@ -14,8 +14,7 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; - -import java.util.ArrayList; +import net.minecraftforge.fluids.FluidStack; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_VACUUM_FREEZER; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_VACUUM_FREEZER_ACTIVE; @@ -49,6 +48,8 @@ public class GT_MetaTileEntity_VacuumFreezer extends GT_MetaTileEntity_CubicMult .addCasingInfo("Frost Proof Machine Casing", 16) .addEnergyHatch("Any casing", 1) .addMaintenanceHatch("Any casing", 1) + .addInputHatch("Any casing", 1) + .addOutputHatch("Any casing", 1) .addInputBus("Any casing", 1) .addOutputBus("Any casing", 1) .toolTipFinisher("Gregtech"); @@ -93,29 +94,29 @@ public class GT_MetaTileEntity_VacuumFreezer extends GT_MetaTileEntity_CubicMult @Override public boolean checkRecipe(ItemStack aStack) { - ArrayList tInputList = getStoredInputs(); - for (ItemStack tInput : tInputList) { - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - - GT_Recipe tRecipe = GT_Recipe.GT_Recipe_Map.sVacuumRecipes.findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], null, tInput); - if (tRecipe != null) { - if (tRecipe.isRecipeInputEqual(true, null, tInput)) { - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - calculateOverclockedNessMulti(tRecipe.mEUt, tRecipe.mDuration, 1, tVoltage); - //In case recipe is too OP for that machine - if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) - return false; - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - this.mOutputItems = new ItemStack[]{tRecipe.getOutput(0)}; - updateSlots(); - return true; + ItemStack[] tInputList = getCompactedInputs(); + FluidStack[] tFluidList = getCompactedFluids(); + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + GT_Recipe tRecipe = getRecipeMap().findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluidList, tInputList); + if (tRecipe != null) { + if (tRecipe.isRecipeInputEqual(true, tFluidList, tInputList)) { + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + calculateOverclockedNessMulti(tRecipe.mEUt, tRecipe.mDuration, 1, tVoltage); + //In case recipe is too OP for that machine + if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) + return false; + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); } + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + this.mOutputItems = new ItemStack[]{tRecipe.getOutput(0)}; + this.mOutputFluids = new FluidStack[]{tRecipe.getFluidOutput(0)}; + updateSlots(); + return true; } } return false; -- cgit From fa411d8339e75f8e4127c07f42cab0563c14cf5b Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Mon, 18 Oct 2021 16:21:21 +0800 Subject: Optimize away potentially expensive NBT copy in getAssociation --- src/main/java/gregtech/api/objects/GT_ItemStack.java | 7 ++++++- src/main/java/gregtech/api/util/GT_OreDictUnificator.java | 2 +- src/main/java/gregtech/api/util/GT_Recipe.java | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/objects/GT_ItemStack.java b/src/main/java/gregtech/api/objects/GT_ItemStack.java index 7284854c5f..3e25454fa1 100644 --- a/src/main/java/gregtech/api/objects/GT_ItemStack.java +++ b/src/main/java/gregtech/api/objects/GT_ItemStack.java @@ -1,5 +1,6 @@ package gregtech.api.objects; +import gregtech.api.enums.GT_Values; import gregtech.api.util.GT_Utility; import net.minecraft.init.Items; import net.minecraft.item.Item; @@ -17,7 +18,11 @@ public class GT_ItemStack { } public GT_ItemStack(ItemStack aStack) { - this(aStack == null ? null : aStack.getItem(), aStack == null ? 0 : aStack.stackSize, aStack == null ? 0 : Items.feather.getDamage(aStack)); + this(aStack, false); + } + + public GT_ItemStack(ItemStack aStack, boolean wildcard) { + this(aStack == null ? null : aStack.getItem(), aStack == null ? 0 : aStack.stackSize, aStack == null ? 0 : wildcard ? GT_Values.W : Items.feather.getDamage(aStack)); } public GT_ItemStack(int aHashCode) { diff --git a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java index 54ef5b2866..6e46517371 100644 --- a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java +++ b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java @@ -315,7 +315,7 @@ public class GT_OreDictUnificator { public static ItemData getItemData(ItemStack aStack) { if (GT_Utility.isStackInvalid(aStack)) return null; ItemData rData = sItemStack2DataMap.get(new GT_ItemStack(aStack)); - if (rData == null) rData = sItemStack2DataMap.get(new GT_ItemStack(GT_Utility.copyMetaData(W, aStack))); + if (rData == null) rData = sItemStack2DataMap.get(new GT_ItemStack(aStack, true)); return rData; } diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index bcd3c193de..6130adfaef 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -800,7 +800,7 @@ public class GT_Recipe implements Comparable { * @return if this Item is a valid Input for any for the Recipes */ public boolean containsInput(ItemStack aStack) { - return aStack != null && (mRecipeItemMap.containsKey(new GT_ItemStack(aStack)) || mRecipeItemMap.containsKey(new GT_ItemStack(GT_Utility.copyMetaData(W, aStack)))); + return aStack != null && (mRecipeItemMap.containsKey(new GT_ItemStack(aStack)) || mRecipeItemMap.containsKey(new GT_ItemStack(aStack, true))); } /** @@ -886,7 +886,7 @@ public class GT_Recipe implements Comparable { if (tRecipes != null) for (GT_Recipe tRecipe : tRecipes) if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)) return tRecipe.mEnabled && aVoltage * mAmperage >= tRecipe.mEUt ? tRecipe : null; - tRecipes = mRecipeItemMap.get(new GT_ItemStack(GT_Utility.copyMetaData(W, tStack))); + tRecipes = mRecipeItemMap.get(new GT_ItemStack(tStack, true)); if (tRecipes != null) for (GT_Recipe tRecipe : tRecipes) if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)) return tRecipe.mEnabled && aVoltage * mAmperage >= tRecipe.mEUt ? tRecipe : null; -- cgit From b2f9e447fbb89f578a9a696a0d60431e9395aef1 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Mon, 18 Oct 2021 22:14:07 +0800 Subject: Further optimization to NEI lookup --- .../java/gregtech/api/items/GT_MetaBase_Item.java | 6 +--- .../gregtech/api/util/GT_OreDictUnificator.java | 35 ++++++++++++---------- .../java/gregtech/nei/GT_NEI_DefaultHandler.java | 16 ++++------ 3 files changed, 26 insertions(+), 31 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/items/GT_MetaBase_Item.java b/src/main/java/gregtech/api/items/GT_MetaBase_Item.java index edc60b45fc..2f6685553e 100644 --- a/src/main/java/gregtech/api/items/GT_MetaBase_Item.java +++ b/src/main/java/gregtech/api/items/GT_MetaBase_Item.java @@ -58,11 +58,7 @@ public abstract class GT_MetaBase_Item extends GT_Generic_Item implements ISpeci */ public final GT_MetaBase_Item addItemBehavior(int aMetaValue, IItemBehaviour aBehavior) { if (aMetaValue < 0 || aMetaValue >= 32766 || aBehavior == null) return this; - ArrayList> tList = mItemBehaviors.get((short) aMetaValue); - if (tList == null) { - tList = new ArrayList>(1); - mItemBehaviors.put((short) aMetaValue, tList); - } + ArrayList> tList = mItemBehaviors.computeIfAbsent((short) aMetaValue, k -> new ArrayList<>(1)); tList.add(aBehavior); return this; } diff --git a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java index 6e46517371..a017cf3bb0 100644 --- a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java +++ b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java @@ -223,26 +223,30 @@ public class GT_OreDictUnificator { 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 getNonUnifiedStacks(Object obj) { - synchronized (sUnificationTable) { - if (sUnificationTable.isEmpty() && !sItemStack2DataMap.isEmpty()) { - for (GT_ItemStack tGTStack0 : sItemStack2DataMap.keySet()) { - ItemStack tStack0 = tGTStack0.toStack(); - ItemStack tStack1 = get(false, tStack0); - if (!GT_Utility.areStacksEqual(tStack0, tStack1)) { - GT_ItemStack tGTStack1 = new GT_ItemStack(tStack1); - List list = sUnificationTable.computeIfAbsent(tGTStack1, k -> new ArrayList<>()); - if (!list.contains(tStack0)) - list.add(tStack0); - } - } - } - } + if (sUnificationTable.isEmpty() && !sItemStack2DataMap.isEmpty()) { + // use something akin to double check lock. this synchronization overhead is causing lag whenever my + // 5900x tries to do NEI lookup + synchronized (sUnificationTable) { + if (sUnificationTable.isEmpty() && !sItemStack2DataMap.isEmpty()) { + for (GT_ItemStack tGTStack0 : sItemStack2DataMap.keySet()) { + ItemStack tStack0 = tGTStack0.toStack(); + ItemStack tStack1 = get_nocopy(false, tStack0); + if (!GT_Utility.areStacksEqual(tStack0, tStack1)) { + GT_ItemStack tGTStack1 = new GT_ItemStack(tStack1); + List list = sUnificationTable.computeIfAbsent(tGTStack1, k -> new ArrayList<>()); + // greg's original code tries to dedupe the list using List#contains, which won't work + // on vanilla ItemStack. I removed it since it never worked and can be slow. + list.add(tStack0); + } + } + } + } + } ItemStack[] aStacks = {}; if (obj instanceof ItemStack) aStacks = new ItemStack[]{(ItemStack) obj}; @@ -257,7 +261,6 @@ public class GT_OreDictUnificator { if (tList != null) { for (ItemStack tStack : tList) { ItemStack tStack1 = GT_Utility.copyAmount(aStack.stackSize, tStack); - tStack1.setTagCompound(aStack.getTagCompound()); rList.add(tStack1); } } diff --git a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java index f28c014bda..2c56766162 100644 --- a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java +++ b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java @@ -11,10 +11,8 @@ import codechicken.nei.recipe.GuiUsageRecipe; import codechicken.nei.recipe.TemplateRecipeHandler; import gregtech.GT_Mod; import gregtech.api.enums.GT_Values; -import gregtech.api.enums.ItemList; import gregtech.api.enums.OrePrefixes; import gregtech.api.gui.GT_GUIContainer_BasicMachine; -import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.ItemData; import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Log; @@ -27,7 +25,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidStack; import org.lwjgl.opengl.GL11; @@ -367,15 +364,14 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { if (this.permutated) { return; } - ArrayList tDisplayStacks = new ArrayList(); + ArrayList tDisplayStacks = new ArrayList<>(); for (ItemStack tStack : this.items) { if (GT_Utility.isStackValid(tStack)) { if (tStack.getItemDamage() == 32767) { List permutations = codechicken.nei.ItemList.itemMap.get(tStack.getItem()); if (!permutations.isEmpty()) { - ItemStack stack; - for (Iterator i$ = permutations.iterator(); i$.hasNext(); tDisplayStacks.add(GT_Utility.copyAmount(tStack.stackSize, stack))) { - stack = (ItemStack) i$.next(); + for (ItemStack permutation : permutations) { + tDisplayStacks.add(GT_Utility.copyAmount(tStack.stackSize, permutation)); } } else { ItemStack base = new ItemStack(tStack.getItem(), tStack.stackSize); @@ -387,7 +383,7 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { } } } - this.items = ((ItemStack[]) tDisplayStacks.toArray(new ItemStack[0])); + this.items = tDisplayStacks.toArray(new ItemStack[0]); if (this.items.length == 0) { this.items = new ItemStack[]{new ItemStack(Blocks.fire)}; } @@ -412,14 +408,14 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { maybeIn = aRecipe.getInputPositionedStacks(); } catch(NullPointerException npe) { maybeIn = null; - GT_Log.err.println("CachedDefaultRecipe - Invalid InputPositionedStacks " + aRecipe.toString()); + GT_Log.err.println("CachedDefaultRecipe - Invalid InputPositionedStacks " + aRecipe); npe.printStackTrace(GT_Log.err); } try { maybeOut = aRecipe.getOutputPositionedStacks(); } catch (NullPointerException npe) { maybeOut = null; - GT_Log.err.println("CachedDefaultRecipe - Invalid OutputPositionedStacks " + aRecipe.toString()); + GT_Log.err.println("CachedDefaultRecipe - Invalid OutputPositionedStacks " + aRecipe); npe.printStackTrace(GT_Log.err); } -- cgit From 2ad55d3e6c3fb7915a12be4291887373522b878f Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Tue, 19 Oct 2021 22:30:24 -0600 Subject: Detect the ore type and replace with that type of cobble --- src/main/java/gregtech/api/util/GT_Utility.java | 51 +++++++++++++++++++++- .../common/blocks/GT_Block_Ores_Abstract.java | 18 ++++++++ .../machines/basic/GT_MetaTileEntity_Miner.java | 29 ++++++++---- .../GT_MetaTileEntity_OreDrillingPlantBase.java | 28 ++++++++---- 4 files changed, 107 insertions(+), 19 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 64a60e8630..36925cbe5b 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -1,6 +1,7 @@ package gregtech.api.util; import cofh.api.transport.IItemDuct; +import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import com.gtnewhorizon.structurelib.alignment.IAlignment; @@ -28,6 +29,7 @@ import gregtech.api.objects.ItemData; import gregtech.api.threads.GT_Runnable_Sound; import gregtech.api.util.extensions.ArrayExt; import gregtech.common.GT_Proxy; +import gregtech.common.blocks.GT_Block_Ores_Abstract; import ic2.api.recipe.IRecipeInput; import ic2.api.recipe.RecipeInputItemStack; import ic2.api.recipe.RecipeInputOreDict; @@ -80,7 +82,9 @@ import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.*; import java.util.Map.Entry; +import java.util.function.Function; import java.util.function.IntFunction; +import java.util.function.Supplier; import static gregtech.GT_Mod.GT_FML_LOGGER; import static gregtech.api.enums.GT_Values.*; @@ -103,6 +107,8 @@ public class GT_Utility { private static final Map sFilledContainerToData = new /*Concurrent*/HashMap<>(); private static final Map> sEmptyContainerToFluidToData = new /*Concurrent*/HashMap<>(); private static final Map> sFluidToContainers = new HashMap<>(); + /** Must use {@code Supplier} here because the ore prefixes have not yet been registered at class load time. */ + private static final Map> sOreToCobble = new HashMap<>(); public static volatile int VERSION = 509; public static boolean TE_CHECK = false, BC_CHECK = false, CHECK_ALL = true, RF_CHECK = false; public static Map sPlayedSoundMap = new /*Concurrent*/HashMap<>(); @@ -117,6 +123,29 @@ public class GT_Utility { GregTech_API.sItemStackMappings.add(sFilledContainerToData); GregTech_API.sItemStackMappings.add(sEmptyContainerToFluidToData); + + // 1 is the magic index to get the cobblestone block. + // See: GT_Block_Stones.java, GT_Block_Granites.java + Function> materialToCobble = + m -> Suppliers.memoize(() -> GT_OreDictUnificator.getOres(OrePrefixes.stone, m).get(1))::get; + sOreToCobble.put( + OrePrefixes.oreBlackgranite, + materialToCobble.apply(Materials.GraniteBlack)); + sOreToCobble.put( + OrePrefixes.oreRedgranite, + materialToCobble.apply(Materials.GraniteRed)); + sOreToCobble.put( + OrePrefixes.oreMarble, + materialToCobble.apply(Materials.Marble)); + sOreToCobble.put( + OrePrefixes.oreBasalt, + materialToCobble.apply(Materials.Basalt)); + sOreToCobble.put( + OrePrefixes.oreNetherrack, + () -> new ItemStack(Blocks.netherrack)); + sOreToCobble.put( + OrePrefixes.oreEndstone, + () -> new ItemStack(Blocks.end_stone)); } public static int safeInt(long number, int margin){ @@ -2733,7 +2762,9 @@ public class GT_Utility { ); public static boolean isOre(Block aBlock, int aMeta) { - return isOre(new ItemStack(aBlock, 1, aMeta)) || ORE_BLOCK_CLASSES.contains(aBlock.getClass().getName()); + return (aBlock instanceof GT_Block_Ores_Abstract) + || isOre(new ItemStack(aBlock, 1, aMeta)) + || ORE_BLOCK_CLASSES.contains(aBlock.getClass().getName()); } public static boolean isOre(ItemStack aStack) { @@ -2744,6 +2775,24 @@ public class GT_Utility { return false; } + /** + * Do NOT mutate the returned {@code ItemStack}! + * We return {@code ItemStack} instead of {@code Block} so that we can include metadata. + */ + public static ItemStack getCobbleForOre(Block ore, short metaData) { + // We need to convert to small ores to regular ores because small ores don't have associated ItemData. + // We take the modulus of the metadata by 16000 because that is the magic number to convert small ores to regular ores. + // See: GT_TileEntity_Ores.java + ItemData association = GT_OreDictUnificator.getAssociation(new ItemStack(Item.getItemFromBlock(ore), 1, metaData % 16000)); + if (association != null) { + Supplier supplier = sOreToCobble.get(association.mPrefix); + if (supplier != null) { + return supplier.get(); + } + } + return new ItemStack(Blocks.cobblestone); + } + public static Optional reverseShapelessRecipe(ItemStack output, Object... aRecipe) { if (output == null) { return Optional.empty(); diff --git a/src/main/java/gregtech/common/blocks/GT_Block_Ores_Abstract.java b/src/main/java/gregtech/common/blocks/GT_Block_Ores_Abstract.java index 48cd41187d..d862e5a555 100644 --- a/src/main/java/gregtech/common/blocks/GT_Block_Ores_Abstract.java +++ b/src/main/java/gregtech/common/blocks/GT_Block_Ores_Abstract.java @@ -12,6 +12,7 @@ import gregtech.api.items.GT_Generic_Block; import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; import gregtech.common.render.GT_Renderer_Block; import net.minecraft.block.Block; import net.minecraft.block.ITileEntityProvider; @@ -20,6 +21,7 @@ import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.boss.EntityDragon; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -134,6 +136,22 @@ public abstract class GT_Block_Ores_Abstract extends GT_Generic_Block implements return aMaterial.getDefaultLocalizedNameForItem(getLocalizedNameFormat(aMaterial)); } + @Override + public boolean onBlockActivated(World aWorld, int aX, int aY, int aZ, EntityPlayer aPlayer, int aSide, float par1, float par2, float par3) { + if (!aPlayer.isSneaking() || !aPlayer.capabilities.isCreativeMode) { + return false; + } + + TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); + if (!(tTileEntity instanceof GT_TileEntity_Ores)) { + return false; + } + + boolean tNatural = (((GT_TileEntity_Ores) tTileEntity).mNatural = !((GT_TileEntity_Ores) tTileEntity).mNatural); + GT_Utility.sendChatToPlayer(aPlayer, "Ore \"mNatural\" flag set to: " + tNatural); + return true; + } + @Override public boolean onBlockEventReceived(World p_149696_1_, int p_149696_2_, int p_149696_3_, int p_149696_4_, int p_149696_5_, int p_149696_6_) { super.onBlockEventReceived(p_149696_1_, p_149696_2_, p_149696_3_, p_149696_4_, p_149696_5_, p_149696_6_); diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java index d93d959955..6d4b160a86 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java @@ -176,18 +176,21 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine { moveOneDown(aBaseMetaTileEntity); } else { ChunkPosition oreBlockPos; - Block block; + int x = 0, y = 0, z = 0; + Block oreBlock; + int oreBlockMetadata = 0; do { oreBlockPos = oreBlockPositions.remove(0); - block = aBaseMetaTileEntity.getBlockOffset(oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ); + oreBlock = aBaseMetaTileEntity.getBlockOffset(oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ); + x = aBaseMetaTileEntity.getXCoord() + oreBlockPos.chunkPosX; + y = aBaseMetaTileEntity.getYCoord() + oreBlockPos.chunkPosY; + z = aBaseMetaTileEntity.getZCoord() + oreBlockPos.chunkPosZ; + oreBlockMetadata = getBaseMetaTileEntity().getWorld().getBlockMetadata(x, y, z); } // someone else might have removed the block - while (block == Blocks.air && !oreBlockPositions.isEmpty()); + while (!GT_Utility.isOre(oreBlock, oreBlockMetadata) && !oreBlockPositions.isEmpty()); - if (block != Blocks.air) { - mineBlock(aBaseMetaTileEntity, block, - aBaseMetaTileEntity.getXCoord() + oreBlockPos.chunkPosX, - aBaseMetaTileEntity.getYCoord() + oreBlockPos.chunkPosY, - aBaseMetaTileEntity.getZCoord() + oreBlockPos.chunkPosZ); + if (GT_Utility.isOre(oreBlock, oreBlockMetadata)) { + mineBlock(aBaseMetaTileEntity, oreBlock, x, y, z); } } } @@ -265,7 +268,15 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine { mOutputItems[0] = drops.get(0); if (drops.size() > 1) mOutputItems[1] = drops.get(1); - aBaseMetaTileEntity.getWorld().setBlock(x, y, z, Blocks.cobblestone); + + short metaData = 0; + TileEntity tTileEntity = getBaseMetaTileEntity().getTileEntity(x, y, z); + if (tTileEntity instanceof GT_TileEntity_Ores) { + metaData = ((GT_TileEntity_Ores) tTileEntity).mMetaData; + } + + ItemStack cobble = GT_Utility.getCobbleForOre(block, metaData); + aBaseMetaTileEntity.getWorld().setBlock(x, y, z, Block.getBlockFromItem(cobble.getItem()), cobble.getItemDamage(), 3); if (debugBlockMiner) GT_Log.out.println("MINER: Mining GT ore block at " + x + " " + y + " " + z); } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java index 1643eb4f8d..50f28a83b4 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java @@ -17,7 +17,6 @@ import gregtech.common.blocks.GT_TileEntity_Ores; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -32,8 +31,6 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import org.lwjgl.input.Keyboard; - import static gregtech.api.enums.GT_Values.VN; public abstract class GT_MetaTileEntity_OreDrillingPlantBase extends GT_MetaTileEntity_DrillerBase { @@ -109,21 +106,34 @@ public abstract class GT_MetaTileEntity_OreDrillingPlantBase extends GT_MetaTile } private boolean processOreList(){ ChunkPosition oreBlockPos = null; + int x = 0, y = 0, z = 0; Block oreBlock = null; + int oreBlockMetadata = 0; - while ((oreBlock == null || oreBlock == Blocks.air) && !oreBlockPositions.isEmpty()) { + while ((oreBlock == null || !GT_Utility.isOre(oreBlock, oreBlockMetadata)) && !oreBlockPositions.isEmpty()) { oreBlockPos = oreBlockPositions.remove(0); - if (GT_Utility.eraseBlockByFakePlayer(getFakePlayer(getBaseMetaTileEntity()), oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ, true)) - oreBlock = getBaseMetaTileEntity().getBlock(oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ); + x = oreBlockPos.chunkPosX; + y = oreBlockPos.chunkPosY; + z = oreBlockPos.chunkPosZ; + if (GT_Utility.eraseBlockByFakePlayer(getFakePlayer(getBaseMetaTileEntity()), x, y, z, true)) + oreBlock = getBaseMetaTileEntity().getBlock(x, y, z); + oreBlockMetadata = getBaseMetaTileEntity().getWorld().getBlockMetadata(x, y, z); } if (!tryConsumeDrillingFluid()) { oreBlockPositions.add(0, oreBlockPos); return false; } - if (oreBlock != null && oreBlock != Blocks.air) { - Collection oreBlockDrops = getBlockDrops(oreBlock, oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ); - getBaseMetaTileEntity().getWorld().setBlock(oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ, Blocks.cobblestone); + if (oreBlock != null && GT_Utility.isOre(oreBlock, oreBlockMetadata)) { + short metaData = 0; + TileEntity tTileEntity = getBaseMetaTileEntity().getTileEntity(x, y, z); + if (tTileEntity instanceof GT_TileEntity_Ores) { + metaData = ((GT_TileEntity_Ores) tTileEntity).mMetaData; + } + + Collection oreBlockDrops = getBlockDrops(oreBlock, x, y, z); + ItemStack cobble = GT_Utility.getCobbleForOre(oreBlock, metaData); + getBaseMetaTileEntity().getWorld().setBlock(x, y, z, Block.getBlockFromItem(cobble.getItem()), cobble.getItemDamage(), 3); mOutputItems = getOutputByDrops(oreBlockDrops); } return true; -- cgit From cbbd2f00df7a0b781a53fd2c7c0b0e5326faedd1 Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Tue, 19 Oct 2021 22:58:21 -0600 Subject: Fix comment grammar --- src/main/java/gregtech/api/util/GT_Utility.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 36925cbe5b..b3f3c6d666 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -2780,7 +2780,7 @@ public class GT_Utility { * We return {@code ItemStack} instead of {@code Block} so that we can include metadata. */ public static ItemStack getCobbleForOre(Block ore, short metaData) { - // We need to convert to small ores to regular ores because small ores don't have associated ItemData. + // We need to convert small ores to regular ores because small ores don't have associated ItemData. // We take the modulus of the metadata by 16000 because that is the magic number to convert small ores to regular ores. // See: GT_TileEntity_Ores.java ItemData association = GT_OreDictUnificator.getAssociation(new ItemStack(Item.getItemFromBlock(ore), 1, metaData % 16000)); -- cgit From 0a5c21841fa3eb0ad581173868a06983e0bc0baf Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Thu, 21 Oct 2021 00:18:55 +0800 Subject: Make Input Bus and Input Hatch to remember recipe map This recipe map is used to filter input. After chunk load, there will be a short delay between event "chunk finished loading" and "multiblock controller sets the recipe map". Not remembering it makes the hatch to temporarily accept arbitrary input until that happens. --- .../implementations/GT_MetaTileEntity_Hatch_Input.java | 14 ++++++++++++++ .../implementations/GT_MetaTileEntity_Hatch_InputBus.java | 3 +++ src/main/java/gregtech/api/util/GT_Recipe.java | 13 +++++++++++++ 3 files changed, 30 insertions(+) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Input.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Input.java index a0fc7abcc7..2ff1e87348 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Input.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Input.java @@ -9,6 +9,7 @@ import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.FluidStack; import static gregtech.api.enums.Textures.BlockIcons.FLUID_IN_SIGN; @@ -65,6 +66,19 @@ public class GT_MetaTileEntity_Hatch_Input extends GT_MetaTileEntity_Hatch { return new GT_MetaTileEntity_Hatch_Input(mName, mTier, mDescriptionArray, mTextures); } + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + if (mRecipeMap != null) + aNBT.setString("recipeMap", mRecipeMap.mUniqueIdentifier); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mRecipeMap = GT_Recipe_Map.sIndexedMappings.getOrDefault(aNBT.getString("recipeMap"), null); + } + @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { if (aBaseMetaTileEntity.isClientSide()) return true; diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java index 96667ddb8c..37a98162b8 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java @@ -169,6 +169,8 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch { aNBT.setBoolean("disableSort", disableSort); aNBT.setBoolean("disableFilter", disableFilter); aNBT.setBoolean("disableLimited", disableLimited); + if (mRecipeMap != null) + aNBT.setString("recipeMap", mRecipeMap.mUniqueIdentifier); } @Override @@ -178,6 +180,7 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch { disableFilter = aNBT.getBoolean("disableFilter"); if(aNBT.hasKey("disableLimited")) disableLimited = aNBT.getBoolean("disableLimited"); + mRecipeMap = GT_Recipe_Map.sIndexedMappings.getOrDefault(aNBT.getString("recipeMap"), null); } @Override diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 6130adfaef..118d1e31a8 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -572,6 +572,10 @@ public class GT_Recipe implements Comparable { * Contains all Recipe Maps */ public static final Collection sMappings = new ArrayList<>(); + /** + * All recipe maps indexed by their {@link #mUniqueIdentifier}. + */ + public static final Map sIndexedMappings = new HashMap<>(); public static final GT_Recipe_Map sOreWasherRecipes = new GT_Recipe_Map(new HashSet<>(500), "gt.recipe.orewasher", "Ore Washing Plant", null, RES_PATH_GUI + "basicmachines/OreWasher", 1, 3, 1, 1, 1, E, 1, E, true, true); public static final GT_Recipe_Map sThermalCentrifugeRecipes = new GT_Recipe_Map(new HashSet<>(1000), "gt.recipe.thermalcentrifuge", "Thermal Centrifuge", null, RES_PATH_GUI + "basicmachines/ThermalCentrifuge", 1, 3, 1, 0, 2, E, 1, E, true, true); @@ -685,6 +689,12 @@ public class GT_Recipe implements Comparable { public final int mUsualInputCount, mUsualOutputCount, mNEISpecialValueMultiplier, mMinimalInputItems, mMinimalInputFluids, mAmperage; public final boolean mNEIAllowed, mShowVoltageAmperageInNEI; + /** + * Unique identifier for this recipe map. Generated from aUnlocalizedName and a few other parameters. + * See constructor for details. + */ + public final String mUniqueIdentifier; + /** * Initialises a new type of Recipe Handler. * @@ -717,6 +727,9 @@ public class GT_Recipe implements Comparable { GregTech_API.sFluidMappings.add(mRecipeFluidMap); GregTech_API.sItemStackMappings.add(mRecipeItemMap); GT_LanguageManager.addStringLocalization(mUnlocalizedName = aUnlocalizedName, aLocalName); + mUniqueIdentifier = String.format("%s_%d_%d_%d_%d_%d", aUnlocalizedName, aAmperage, aUsualInputCount, aUsualOutputCount, aMinimalInputFluids, aMinimalInputItems); + if (sIndexedMappings.put(mUniqueIdentifier, this) != null) + throw new IllegalArgumentException("Duplicate recipe map registered: " + mUniqueIdentifier); } public GT_Recipe addRecipe(boolean aOptimize, ItemStack[] aInputs, ItemStack[] aOutputs, Object aSpecial, int[] aOutputChances, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, int aDuration, int aEUt, int aSpecialValue) { -- cgit From fa848f9e1cf284519080bbb4d454224d71cb7ccb Mon Sep 17 00:00:00 2001 From: GlodBlock <60341015+GlodBlock@users.noreply.github.com> Date: Thu, 21 Oct 2021 19:02:59 +0800 Subject: fix the same unlocalizedName fix https://discord.com/channels/181078474394566657/401118216228831252/900697821450215464 --- src/main/java/gregtech/api/util/GT_Recipe.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 118d1e31a8..96018571e9 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -657,7 +657,7 @@ public class GT_Recipe implements Comparable { 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); public static final GT_Recipe_Map_Fuel sExtremeNaquadahReactorFuels = new GT_Recipe_Map_Fuel(new HashSet<>(1), "gt.recipe.hugenaquadahreactor", "Naquadah Reactor MkIV", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, true); public static final GT_Recipe_Map_Fuel sUltraHugeNaquadahReactorFuels = new GT_Recipe_Map_Fuel(new HashSet<>(1), "gt.recipe.extrahugenaquadahreactor", "Naquadah Reactor MkV", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, true); - public static final GT_Recipe_Map_Fuel sFluidNaquadahReactorFuels = new GT_Recipe_Map_Fuel(new HashSet<>(1), "gt.recipe.fluidnaquadahreactor", "Fluid Naquadah Reactor", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, true); + public static final GT_Recipe_Map_Fuel sFluidNaquadahReactorFuels = new GT_Recipe_Map_Fuel(new HashSet<>(1), "gt.recipe.fluidfuelnaquadahreactor", "Fluid Naquadah Reactor", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, true); public static final GT_Recipe_Map_LargeBoilerFakeFuels sLargeBoilerFakeFuels = new GT_Recipe_Map_LargeBoilerFakeFuels(); /** -- cgit From fda1ee40c41d6e1e4e4bb4d5cba22ea530ebaf8c Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Sat, 23 Oct 2021 21:19:44 -0600 Subject: Try to use locale formatting * Also format some more of the portable scanner's output --- build.properties | 2 +- .../gregtech/api/metatileentity/BaseMetaTileEntity.java | 6 +++--- src/main/java/gregtech/api/util/GT_Utility.java | 13 +++++-------- 3 files changed, 9 insertions(+), 12 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/build.properties b/build.properties index ce66df0e6d..bae670851f 100644 --- a/build.properties +++ b/build.properties @@ -1,6 +1,6 @@ minecraft.version=1.7.10 forge.version=10.13.4.1614-1.7.10 -gt.version=5.09.38.03 +gt.version=5.09.38.04 structurelib.version=1.0.6 ae2.version=rv3-beta-22 applecore.version=1.7.10-1.2.1+107.59407 diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 41203c3ad2..10d5ec774a 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -802,8 +802,8 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE // Uncomment this line to print out tick-by-tick times. //tList.add("tTime " + tTime); } - tList.add("Average CPU load of ~" + (tAverageTime / mTimeStatistics.length) + "ns over " + mTimeStatistics.length + " ticks with worst time of " + tWorstTime + "ns."); - tList.add("Recorded " + mMetaTileEntity.mSoundRequests + " sound requests in " + (mTickTimer - mLastCheckTick) + " ticks." ); + tList.add("Average CPU load of ~" + GT_Utility.formatNumbers(tAverageTime / mTimeStatistics.length) + "ns over " + GT_Utility.formatNumbers(mTimeStatistics.length) + " ticks with worst time of " + GT_Utility.formatNumbers(tWorstTime) + "ns."); + tList.add("Recorded " + GT_Utility.formatNumbers(mMetaTileEntity.mSoundRequests) + " sound requests in " + GT_Utility.formatNumbers(mTickTimer - mLastCheckTick) + " ticks." ); mLastCheckTick = mTickTimer; mMetaTileEntity.mSoundRequests = 0; } @@ -814,7 +814,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE } if (aLogLevel > 0) { if (getSteamCapacity() > 0 && hasSteamEngineUpgrade()) - tList.add(getStoredSteam() + " of " + getSteamCapacity() + " Steam"); + tList.add(GT_Utility.formatNumbers(getStoredSteam()) + " of " + GT_Utility.formatNumbers(getSteamCapacity()) + " Steam"); tList.add("Machine is " + (mActive ? EnumChatFormatting.GREEN+"active"+EnumChatFormatting.RESET : EnumChatFormatting.RED+"inactive"+EnumChatFormatting.RESET)); if (!mHasEnoughEnergy) tList.add(EnumChatFormatting.RED+"ATTENTION: This Device needs more power."+EnumChatFormatting.RESET); diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index b3f3c6d666..16d22be9ef 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -78,7 +78,7 @@ import javax.annotation.Nullable; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.text.DecimalFormat; +import java.text.NumberFormat; import java.text.DecimalFormatSymbols; import java.util.*; import java.util.Map.Entry; @@ -98,7 +98,7 @@ import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation; */ public class GT_Utility { /** Formats a number with group separator and at most 2 fraction digits. */ - private static final DecimalFormat decimalFormat = new DecimalFormat(); + private static final NumberFormat numberFormat = NumberFormat.getInstance(); /** * Forge screwed the Fluid Registry up again, so I make my own, which is also much more efficient than the stupid Stuff over there. @@ -116,10 +116,7 @@ public class GT_Utility { public static UUID defaultUuid = null; // maybe default non-null? UUID.fromString("00000000-0000-0000-0000-000000000000"); static { - DecimalFormatSymbols symbols = decimalFormat.getDecimalFormatSymbols(); - symbols.setGroupingSeparator(' '); - decimalFormat.setDecimalFormatSymbols(symbols); - decimalFormat.setMaximumFractionDigits(2); + numberFormat.setMaximumFractionDigits(2); GregTech_API.sItemStackMappings.add(sFilledContainerToData); GregTech_API.sItemStackMappings.add(sEmptyContainerToFluidToData); @@ -2308,11 +2305,11 @@ public class GT_Utility { } public static String formatNumbers(long aNumber) { - return decimalFormat.format(aNumber); + return numberFormat.format(aNumber); } public static String formatNumbers(double aNumber) { - return decimalFormat.format(aNumber); + return numberFormat.format(aNumber); } /* -- cgit From cd5b3d8f8cbd3ea044753646970797a1ae404e41 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sat, 6 Nov 2021 18:55:31 +0800 Subject: Make GT_LanguageManager injects into correct language --- src/main/java/gregtech/GT_Mod.java | 3 +++ src/main/java/gregtech/api/util/GT_LanguageManager.java | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java index 777cea09e5..8980483f47 100644 --- a/src/main/java/gregtech/GT_Mod.java +++ b/src/main/java/gregtech/GT_Mod.java @@ -450,6 +450,9 @@ public class GT_Mod implements IGT_Mod { GT_Log.out.println("GT_Mod: Generating Lang-File"); GT_LanguageManager.sEnglishFile = new Configuration(new File(aEvent.getModConfigurationDirectory().getParentFile(), "GregTech.lang")); GT_LanguageManager.sEnglishFile.load(); + if (GT_LanguageManager.sEnglishFile.get("EnableLangFile", "UseThisFileAsLanguageFile", false).getBoolean(false)) { + GT_LanguageManager.sLanguage = GT_LanguageManager.sEnglishFile.get("EnableLangFile", "Language", "en_US").getString(); + } Materials.getMaterialsMap().values().parallelStream().filter(Objects::nonNull).forEach(aMaterial -> aMaterial.mLocalizedName = GT_LanguageManager.addStringLocalization("Material." + aMaterial.mName.toLowerCase(), aMaterial.mDefaultLocalName)); diff --git a/src/main/java/gregtech/api/util/GT_LanguageManager.java b/src/main/java/gregtech/api/util/GT_LanguageManager.java index e0c23fce8e..9faa7b11a6 100644 --- a/src/main/java/gregtech/api/util/GT_LanguageManager.java +++ b/src/main/java/gregtech/api/util/GT_LanguageManager.java @@ -16,6 +16,7 @@ import static gregtech.api.enums.GT_Values.E; public class GT_LanguageManager { public static final HashMap TEMPMAP = new HashMap(), BUFFERMAP = new HashMap(), LANGMAP = new HashMap(); public static Configuration sEnglishFile; + public static String sLanguage = "en_US"; public static boolean sUseEnglishFile = false; public static boolean i18nPlaceholder = true; @@ -31,7 +32,7 @@ public class GT_LanguageManager { } } TEMPMAP.put(aKey.trim(), aEnglish); - LanguageRegistry.instance().injectLanguage("en_US", TEMPMAP); + LanguageRegistry.instance().injectLanguage(sLanguage, TEMPMAP); TEMPMAP.clear(); if(sUseEnglishFile && !aWriteIntoLangFile){ if (!LANGMAP.containsKey(aKey)) { -- cgit From 20f1989cc50d6a731e1962e1257004e369f59c0c Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Fri, 12 Nov 2021 17:36:20 +0000 Subject: Update GT_ModHandler.java Fix GT_Tools not going into the IC2 Toolbox. https://media.discordapp.net/attachments/603348502637969419/908770911203758080/2021-11-12_17.29.53.png?width=1277&height=683 --- src/main/java/gregtech/api/util/GT_ModHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java index a910723069..810a204c40 100644 --- a/src/main/java/gregtech/api/util/GT_ModHandler.java +++ b/src/main/java/gregtech/api/util/GT_ModHandler.java @@ -91,7 +91,7 @@ public class GT_ModHandler { public static volatile int VERSION = 509; public static Collection sNativeRecipeClasses = new HashSet<>(), sSpecialRecipeClasses = new HashSet<>(); public static GT_HashSet sNonReplaceableItems = new GT_HashSet<>(); - public static Object sBoxableWrapper = GT_Utility.callConstructor("gregtechmod.api.util.GT_IBoxableWrapper", 0, null, false); + public static Object sBoxableWrapper = new GT_IBoxableWrapper(); private static final Map sExtractorRecipes = new HashMap<>(); private static final Map sMaceratorRecipes = new HashMap<>(); private static final Map sCompressorRecipes = new HashMap<>(); -- cgit From 68c5477284c561f062779e509d509927d6f8d545 Mon Sep 17 00:00:00 2001 From: Martin Robertz Date: Sat, 13 Nov 2021 22:29:16 +0100 Subject: fix 4 slot mixer nei support (cherry picked from commit 6272d6d84052a03cd7d9b3398573527217923907) --- src/main/java/gregtech/api/util/GT_Recipe.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 96018571e9..1f13ff7b82 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -599,7 +599,7 @@ public class GT_Recipe implements Comparable { public static final GT_Recipe_Map sSifterRecipes = new GT_Recipe_Map(new HashSet<>(105), "gt.recipe.sifter", "Sifter", null, RES_PATH_GUI + "basicmachines/Sifter", 1, 9, 1, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sPressRecipes = new GT_Recipe_Map_FormingPress(new HashSet<>(300), "gt.recipe.press", "Forming Press", null, RES_PATH_GUI + "basicmachines/Press", 2, 1, 2, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sLaserEngraverRecipes = new GT_Recipe_Map(new HashSet<>(810), "gt.recipe.laserengraver", "Precision Laser Engraver", null, RES_PATH_GUI + "basicmachines/LaserEngraver", 2, 1, 2, 0, 1, E, 1, E, true, true); - public static final GT_Recipe_Map sMixerRecipes = new GT_Recipe_Map(new HashSet<>(900), "gt.recipe.mixer", "Mixer", null, RES_PATH_GUI + "basicmachines/Mixer2", 9, 1, 1, 0, 1, E, 1, E, true, true); + public static final GT_Recipe_Map sMixerRecipes = new GT_Recipe_Map(new HashSet<>(900), "gt.recipe.mixer", "Mixer", null, RES_PATH_GUI + "basicmachines/Mixer6", 9, 4, 1, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sAutoclaveRecipes = new GT_Recipe_Map(new HashSet<>(300), "gt.recipe.autoclave", "Autoclave", null, RES_PATH_GUI + "basicmachines/Autoclave4", 2, 4, 1, 1, 1, E, 1, E, true, true); public static final GT_Recipe_Map sElectroMagneticSeparatorRecipes = new GT_Recipe_Map(new HashSet<>(50), "gt.recipe.electromagneticseparator", "Electromagnetic Separator", null, RES_PATH_GUI + "basicmachines/ElectromagneticSeparator", 1, 3, 1, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sPolarizerRecipes = new GT_Recipe_Map(new HashSet<>(300), "gt.recipe.polarizer", "Electromagnetic Polarizer", null, RES_PATH_GUI + "basicmachines/Polarizer", 1, 1, 1, 0, 1, E, 1, E, true, true); -- cgit From a73802762161188fbd8539caba4164e4024fdeb3 Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Sun, 14 Nov 2021 18:49:05 -0700 Subject: Add single recipe check --- build.gradle | 2 + build.properties | 2 +- .../GT_MetaTileEntity_MultiBlockBase.java | 24 ++ .../java/gregtech/api/util/GT_LanguageManager.java | 2 + .../gregtech/api/util/GT_Single_Recipe_Check.java | 283 +++++++++++++++++++++ .../multi/GT_MetaTileEntity_PyrolyseOven.java | 49 +++- 6 files changed, 352 insertions(+), 10 deletions(-) create mode 100644 src/main/java/gregtech/api/util/GT_Single_Recipe_Check.java (limited to 'src/main/java/gregtech/api/util') diff --git a/build.gradle b/build.gradle index f92e2a9a82..5f4aad8103 100644 --- a/build.gradle +++ b/build.gradle @@ -109,6 +109,8 @@ dependencies { //Soft Depths (Without this, it wont compile, not needed as library) compileOnly 'commons-io:commons-io:2.4' + compileOnly 'com.google.auto.value:auto-value-annotations:1.8.2' + annotationProcessor 'com.google.auto.value:auto-value:1.8.2' compileOnly "eu.usrv:YAMCore:${config.minecraft.version}-${config.yamcore.version}:deobf" compileOnly "tconstruct:TConstruct:${config.minecraft.version}-${config.tconstruct.version}:deobf" compileOnly "codechicken:Translocator:${config.minecraft.version}-${config.translocators.version}:dev" diff --git a/build.properties b/build.properties index b138ffcf62..ae1d91d310 100644 --- a/build.properties +++ b/build.properties @@ -1,6 +1,6 @@ minecraft.version=1.7.10 forge.version=10.13.4.1614-1.7.10 -gt.version=5.09.38.05 +gt.version=5.09.38.06 structurelib.version=1.0.6 ae2.version=rv3-beta-22 applecore.version=1.7.10-1.2.1+107.59407 diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java index 7a2f1bedac..6369c48f8e 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java @@ -13,6 +13,7 @@ import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gregtech.api.util.GT_Single_Recipe_Check; import gregtech.api.util.GT_Utility; import gregtech.common.GT_Pollution; import gregtech.common.items.GT_MetaGenerated_Tool_01; @@ -43,6 +44,9 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { public int damageFactorLow = 5; public float damageFactorHigh = 0.6f; + public boolean mLockedToSingleRecipe = false; + public GT_Single_Recipe_Check mSingleRecipeCheck = null; + public ArrayList mInputHatches = new ArrayList<>(); public ArrayList mOutputHatches = new ArrayList<>(); public ArrayList mInputBusses = new ArrayList<>(); @@ -81,6 +85,24 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { return aSide != getBaseMetaTileEntity().getFrontFacing(); } + /** Override this if you are a multi-block that has added support for single recipe locking. */ + public boolean supportsSingleRecipeLocking() { + return false; + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (supportsSingleRecipeLocking()) { + mLockedToSingleRecipe = !mLockedToSingleRecipe; + if (mLockedToSingleRecipe) { + GT_Utility.sendChatToPlayer(aPlayer, trans("219","Single recipe locking enabled. Will lock to next recipe.")); + } else { + GT_Utility.sendChatToPlayer(aPlayer, trans("220","Single recipe locking disabled.")); + mSingleRecipeCheck = null; + } + } + } + @Override public boolean isSimpleMachine() { return false; @@ -125,6 +147,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { aNBT.setInteger("mEfficiency", mEfficiency); aNBT.setInteger("mPollution", mPollution); aNBT.setInteger("mRuntime", mRuntime); + aNBT.setBoolean("mLockedToSingleRecipe", mLockedToSingleRecipe); if (mOutputItems != null) { aNBT.setInteger("mOutputItemsLength", mOutputItems.length); @@ -162,6 +185,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { mEfficiency = aNBT.getInteger("mEfficiency"); mPollution = aNBT.getInteger("mPollution"); mRuntime = aNBT.getInteger("mRuntime"); + mLockedToSingleRecipe = aNBT.getBoolean("mLockedToSingleRecipe"); int aOutputItemsLength = aNBT.getInteger("mOutputItemsLength"); if (aOutputItemsLength > 0) { diff --git a/src/main/java/gregtech/api/util/GT_LanguageManager.java b/src/main/java/gregtech/api/util/GT_LanguageManager.java index 9faa7b11a6..767c830f79 100644 --- a/src/main/java/gregtech/api/util/GT_LanguageManager.java +++ b/src/main/java/gregtech/api/util/GT_LanguageManager.java @@ -335,6 +335,8 @@ public class GT_LanguageManager { addStringLocalization("Interaction_DESCRIPTION_Index_216", "Deprecated Recipe"); 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_219", "Single recipe locking enabled. Will lock to next recipe."); + addStringLocalization("Interaction_DESCRIPTION_Index_220", "Single recipe locking disabled."); 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_Single_Recipe_Check.java b/src/main/java/gregtech/api/util/GT_Single_Recipe_Check.java new file mode 100644 index 0000000000..bcf205611e --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_Single_Recipe_Check.java @@ -0,0 +1,283 @@ +package gregtech.api.util; + +import com.google.auto.value.AutoValue; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +import javax.annotation.Nullable; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** Used by machines that are locked to a single recipe, for fast computation. */ +public class GT_Single_Recipe_Check { + private final GT_MetaTileEntity_MultiBlockBase multiBlockBase; + private final GT_Recipe recipe; + private final ImmutableMap itemCost; + private final ImmutableMap fluidCost; + private final int totalItemCost; + private final int totalFluidCost; + + private GT_Single_Recipe_Check( + GT_MetaTileEntity_MultiBlockBase multiBlockBase, + GT_Recipe recipe, + ImmutableMap itemCost, + ImmutableMap fluidCost) { + this.multiBlockBase = multiBlockBase; + this.recipe = recipe; + this.itemCost = itemCost; + this.fluidCost = fluidCost; + + this.totalItemCost = itemCost.values().stream().mapToInt(Integer::intValue).sum(); + this.totalFluidCost = fluidCost.values().stream().mapToInt(Integer::intValue).sum(); + } + + public GT_Recipe getRecipe() { + return recipe; + } + + /** + * Use this method if recipes cannot require more than a single stack of any item or fluid. + * In particular, {@link GT_MetaTileEntity_MultiBlockBase#getCompactedInputs()} and + * {@link GT_MetaTileEntity_MultiBlockBase#getCompactedFluids()} both enforce this single-stack + * restriction, so any multi-block that calls those can use this method. + */ + public boolean checkRecipeInputsSingleStack(boolean consumeInputs) { + Map itemMap = null; + if (totalItemCost > 0) { + itemMap = new HashMap<>(); + for (ItemStack itemStack : multiBlockBase.getStoredInputs()) { + itemMap.merge( + ItemId.createNoCopy(itemStack), itemStack, + (a, b) -> a.stackSize >= b.stackSize ? a : b); + } + + for (Map.Entry entry : itemCost.entrySet()) { + ItemStack itemStack = itemMap.get(entry.getKey()); + if (itemStack == null || itemStack.stackSize < entry.getValue()) { + return false; + } + } + } + + Map fluidMap = null; + if (totalFluidCost > 0) { + fluidMap = new HashMap<>(); + for (FluidStack fluidStack : multiBlockBase.getStoredFluids()) { + fluidMap.merge( + fluidStack.getFluid(), fluidStack, + (a, b) -> a.amount >= b.amount ? a : b); + } + + for (Map.Entry entry : fluidCost.entrySet()) { + FluidStack fluidStack = fluidMap.get(entry.getKey()); + if (fluidStack == null || fluidStack.amount < entry.getValue()) { + return false; + } + } + } + + if (consumeInputs) { + if (totalItemCost > 0) { + for (Map.Entry entry : itemCost.entrySet()) { + itemMap.get(entry.getKey()).stackSize -= entry.getValue(); + } + } + + if (totalFluidCost > 0) { + for (Map.Entry entry : fluidCost.entrySet()) { + fluidMap.get(entry.getKey()).amount -= entry.getValue(); + } + } + } + + return true; + } + + /** + * Use this method if recipes can require more than a single stack of any item or fluid. + * It is less efficient, though. + */ + public boolean checkRecipeInputs(boolean consumeInputs) { + List items = null; + if (totalItemCost > 0) { + items = multiBlockBase.getStoredInputs(); + + Map itemMap = new HashMap<>(); + for (ItemStack itemStack : items) { + itemMap.merge(ItemId.createNoCopy(itemStack), itemStack.stackSize, Integer::sum); + } + + for (Map.Entry entry : itemCost.entrySet()) { + if (itemMap.getOrDefault(entry.getKey(), 0) < entry.getValue()) { + return false; + } + } + } + + List fluids = null; + if (totalFluidCost > 0) { + fluids = multiBlockBase.getStoredFluids(); + + Map fluidMap = new HashMap<>(); + for (FluidStack fluidStack : fluids) { + fluidMap.merge(fluidStack.getFluid(), fluidStack.amount, Integer::sum); + } + + for (Map.Entry entry : fluidCost.entrySet()) { + if (fluidMap.getOrDefault(entry.getKey(), 0) < entry.getValue()) { + return false; + } + } + } + + if (consumeInputs) { + if (totalItemCost > 0) { + int remainingItemCost = totalItemCost; + Map runningItemCost = Maps.newHashMap(itemCost); + for (ItemStack itemStack : items) { + ItemId key = ItemId.createNoCopy(itemStack); + int runningCost = runningItemCost.getOrDefault(key, 0); + int paid = Math.min(itemStack.stackSize, runningCost); + itemStack.stackSize -= paid; + runningItemCost.put(key, runningCost - paid); + + remainingItemCost -= paid; + if (remainingItemCost <= 0) { + break; + } + } + } + + if (totalFluidCost > 0) { + int remainingFluidCost = totalFluidCost; + Map runningFluidCost = Maps.newHashMap(fluidCost); + for (FluidStack fluidStack : fluids) { + Fluid key = fluidStack.getFluid(); + int runningCost = runningFluidCost.getOrDefault(key, 0); + int paid = Math.min(fluidStack.amount, runningCost); + fluidStack.amount -= paid; + runningFluidCost.put(key, runningCost - paid); + + remainingFluidCost -= paid; + if (remainingFluidCost <= 0) { + break; + } + } + } + } + + return true; + } + + private static Map buildItemMap( + GT_MetaTileEntity_MultiBlockBase multiBlockBase) { + Map itemMap = new HashMap<>(); + for (ItemStack itemStack : multiBlockBase.getStoredInputs()) { + itemMap.merge(ItemId.create(itemStack), itemStack.stackSize, Integer::sum); + } + return itemMap; + } + + private static Map buildFluidMap( + GT_MetaTileEntity_MultiBlockBase multiBlockBase) { + Map fluidMap = new HashMap<>(); + for (FluidStack fluidStack : multiBlockBase.getStoredFluids()) { + fluidMap.merge(fluidStack.getFluid(), fluidStack.amount, Integer::sum); + } + return fluidMap; + } + + public static Builder builder(GT_MetaTileEntity_MultiBlockBase multiBlockBase) { + return new Builder(multiBlockBase); + } + + public static final class Builder { + private final GT_MetaTileEntity_MultiBlockBase multiBlockBase; + + // In order to compute which items and fluids are consumed by the recipe, we compare the + // multi-block's items and fluids before and after inputs are consumed by the recipe. + private Map beforeItems; + private Map beforeFluids; + private Map afterItems; + private Map afterFluids; + + private GT_Recipe recipe; + + private Builder(GT_MetaTileEntity_MultiBlockBase multiBlockBase) { + this.multiBlockBase = multiBlockBase; + } + + /** Call this before inputs are consumed by the recipe. */ + public Builder setBefore() { + beforeItems = buildItemMap(multiBlockBase); + beforeFluids = buildFluidMap(multiBlockBase); + return this; + } + + /** Call this after inputs are consumed by the recipe. */ + public Builder setAfter() { + afterItems = buildItemMap(multiBlockBase); + afterFluids = buildFluidMap(multiBlockBase); + return this; + } + + public Builder setRecipe(GT_Recipe recipe) { + this.recipe = recipe; + return this; + } + + public GT_Single_Recipe_Check build() { + ImmutableMap.Builder itemCostBuilder = ImmutableMap.builder(); + for (Map.Entry entry : beforeItems.entrySet()) { + int cost = entry.getValue() - afterItems.getOrDefault(entry.getKey(), 0); + if (cost > 0) { + itemCostBuilder.put(entry.getKey(), cost); + } + } + + ImmutableMap.Builder fluidCostBuilder = ImmutableMap.builder(); + for (Map.Entry entry : beforeFluids.entrySet()) { + int cost = entry.getValue() - afterFluids.getOrDefault(entry.getKey(), 0); + if (cost > 0) { + fluidCostBuilder.put(entry.getKey(), cost); + } + } + + return new GT_Single_Recipe_Check( + multiBlockBase, recipe, itemCostBuilder.build(), fluidCostBuilder.build()); + } + } + + @AutoValue + abstract static class ItemId { + /** This method copies NBT, as it is mutable. */ + private static ItemId create(ItemStack itemStack) { + NBTTagCompound nbt = itemStack.getTagCompound(); + if (nbt != null) { + nbt = (NBTTagCompound) nbt.copy(); + } + + return new AutoValue_GT_Single_Recipe_Check_ItemId( + itemStack.getItem(), itemStack.getItemDamage(), nbt); + } + + /** This method does not copy NBT in order to save time. Make sure not to mutate it! */ + private static ItemId createNoCopy(ItemStack itemStack) { + return new AutoValue_GT_Single_Recipe_Check_ItemId( + itemStack.getItem(), itemStack.getItemDamage(), itemStack.getTagCompound()); + } + + abstract Item item(); + abstract int metaData(); + + @Nullable + abstract NBTTagCompound nbt(); + } +} diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java index ae96b82a23..428931e654 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java @@ -16,6 +16,7 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMul import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Single_Recipe_Check; import gregtech.api.util.GT_Utility; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; @@ -129,19 +130,49 @@ public class GT_MetaTileEntity_PyrolyseOven extends GT_MetaTileEntity_EnhancedMu } @Override - public boolean checkRecipe(ItemStack aStack) { - ItemStack[] tInputs = getCompactedInputs(); - FluidStack[] tFluids = getCompactedFluids(); - - if (tInputs.length <= 0) - return false; + public boolean supportsSingleRecipeLocking() { + return true; + } + @Override + public boolean checkRecipe(ItemStack aStack) { long tVoltage = getMaxInputVoltage(); byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - GT_Recipe tRecipe = GT_Recipe.GT_Recipe_Map.sPyrolyseRecipes.findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids, tInputs); + GT_Recipe tRecipe; - if (tRecipe == null || !tRecipe.isRecipeInputEqual(true, tFluids, tInputs)) - return false; + if (mLockedToSingleRecipe && mSingleRecipeCheck != null) { + if (!mSingleRecipeCheck.checkRecipeInputsSingleStack(true)) { + return false; + } + + tRecipe = mSingleRecipeCheck.getRecipe(); + } else { + GT_Single_Recipe_Check.Builder tSingleRecipeCheckBuilder = null; + if (mLockedToSingleRecipe) { + // We're locked to a single recipe, but haven't built the recipe checker yet. + // Build the checker on next successful recipe. + tSingleRecipeCheckBuilder = GT_Single_Recipe_Check.builder(this); + } + + ItemStack[] tInputs = getCompactedInputs(); + FluidStack[] tFluids = getCompactedFluids(); + + if (tInputs.length <= 0) + return false; + + if (mLockedToSingleRecipe) { + tSingleRecipeCheckBuilder.setBefore(); + } + + tRecipe = GT_Recipe.GT_Recipe_Map.sPyrolyseRecipes.findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids, tInputs); + + if (tRecipe == null || !tRecipe.isRecipeInputEqual(true, tFluids, tInputs)) + return false; + + if (mLockedToSingleRecipe) { + mSingleRecipeCheck = tSingleRecipeCheckBuilder.setAfter().setRecipe(tRecipe).build(); + } + } this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); this.mEfficiencyIncrease = 10000; -- cgit From 199ec48f853f55a78124a5ccbcd00f521de2d3aa Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Tue, 16 Nov 2021 02:00:00 +0800 Subject: underground oil and pollution persistence form rework Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- src/main/java/gregtech/GT_Mod.java | 1 + src/main/java/gregtech/api/enums/GT_Values.java | 4 + .../java/gregtech/api/objects/GT_UO_Dimension.java | 7 + .../gregtech/api/util/GT_ChunkAssociatedData.java | 435 +++++++++++++++++++++ src/main/java/gregtech/api/util/GT_Utility.java | 79 +++- src/main/java/gregtech/common/GT_Pollution.java | 178 ++++++--- src/main/java/gregtech/common/GT_Proxy.java | 75 +--- .../java/gregtech/common/GT_UndergroundOil.java | 267 ++++++++++--- src/main/java/gregtech/common/misc/GT_Command.java | 2 +- 9 files changed, 847 insertions(+), 201 deletions(-) create mode 100644 src/main/java/gregtech/api/util/GT_ChunkAssociatedData.java (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java index 864ef31c8c..44ee615f41 100644 --- a/src/main/java/gregtech/GT_Mod.java +++ b/src/main/java/gregtech/GT_Mod.java @@ -286,6 +286,7 @@ public class GT_Mod implements IGT_Mod { GT_Values.debugBlockMiner = tMainConfig.get(aTextGeneral, "debugBlockMiner", false).getBoolean(false); GT_Values.debugBlockPump = tMainConfig.get(aTextGeneral, "debugBlockPump", false).getBoolean(false); GT_Values.debugEntityCramming = tMainConfig.get(aTextGeneral, "debugEntityCramming", false).getBoolean(false); + GT_Values.debugWorldData = tMainConfig.get(aTextGeneral, "debugWorldData", false).getBoolean(false); GT_Values.oreveinPercentage = tMainConfig.get(aTextGeneral, "oreveinPercentage_100", 100).getInt(100); GT_Values.oreveinAttempts = tMainConfig.get(aTextGeneral, "oreveinAttempts_64", 64).getInt(64); GT_Values.oreveinMaxPlacementAttempts = tMainConfig.get(aTextGeneral, "oreveinMaxPlacementAttempts_8", 8).getInt(8); diff --git a/src/main/java/gregtech/api/enums/GT_Values.java b/src/main/java/gregtech/api/enums/GT_Values.java index f30360ca58..6505c34423 100644 --- a/src/main/java/gregtech/api/enums/GT_Values.java +++ b/src/main/java/gregtech/api/enums/GT_Values.java @@ -271,6 +271,10 @@ public class GT_Values { * Debug parameter for entity cramming reduction */ public static boolean debugEntityCramming = false; + /** + * Debug parameter for {@link gregtech.api.util.GT_ChunkAssociatedData} + */ + public static boolean debugWorldData = false; /** * Number of ticks between sending sound packets to clients for electric machines. Default is 1.5 seconds. Trying to mitigate lag and FPS drops. */ diff --git a/src/main/java/gregtech/api/objects/GT_UO_Dimension.java b/src/main/java/gregtech/api/objects/GT_UO_Dimension.java index 1c090eb9b5..0d05e6d229 100644 --- a/src/main/java/gregtech/api/objects/GT_UO_Dimension.java +++ b/src/main/java/gregtech/api/objects/GT_UO_Dimension.java @@ -39,4 +39,11 @@ public class GT_UO_Dimension { return null; } + public String getUOFluidKey(GT_UO_Fluid uoFluid) { + return fFluids.inverse().get(uoFluid); + } + + public GT_UO_Fluid getUOFluid(String key) { + return fFluids.get(key); + } } diff --git a/src/main/java/gregtech/api/util/GT_ChunkAssociatedData.java b/src/main/java/gregtech/api/util/GT_ChunkAssociatedData.java new file mode 100644 index 0000000000..b28cb429b4 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_ChunkAssociatedData.java @@ -0,0 +1,435 @@ +package gregtech.api.util; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import gregtech.api.enums.GT_Values; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import net.minecraft.world.ChunkCoordIntPair; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.world.WorldEvent; +import org.apache.commons.io.FileUtils; + +import javax.annotation.ParametersAreNonnullByDefault; +import java.io.DataInput; +import java.io.DataInputStream; +import java.io.DataOutput; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.lang.ref.WeakReference; +import java.lang.reflect.Array; +import java.nio.file.AtomicMoveNotSupportedException; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; +import java.util.Arrays; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.function.Function; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * A utility to save all kinds of data that is a function of any chunk. + *

+ * GregTech takes care of saving and loading the data from disk, and an efficient mechanism to locate it. + * Subclass only need to define the exact scheme of each element data (by overriding the three protected abstract method) + *

+ * Oh, there is no limit on how large your data is, though you'd not have the familiar NBT interface, but DataOutput + * should be reasonably common anyway. + *

+ * It should be noted this class is NOT thread safe. + *

+ * Element cannot be null. + *

+ * TODO: Implement automatic region unloading. + * + * @param data element type + * @author glease + */ +@ParametersAreNonnullByDefault +public abstract class GT_ChunkAssociatedData { + private static final Map> instances = new ConcurrentHashMap<>(); + private static final int IO_PARALLELISM = Math.min(8, Math.max(1, Runtime.getRuntime().availableProcessors()) * 2 / 3); + private static final ExecutorService IO_WORKERS = Executors.newWorkStealingPool(IO_PARALLELISM); + private static final Pattern FILE_PATTERN = Pattern.compile("(.+)\\.(-?\\d+)\\.(-?\\d+)\\.dat"); + + static { + // register event handler + new EventHandler(); + } + + protected final String mId; + protected final Class elementtype; + private final int regionLength; + private final int version; + private final boolean saveDefaults; + /** + * Data is stored as a `(world id -> (super region id -> super region data))` hash map. + * where super region's size is determined by regionSize. + * Here it is called super region, to not confuse with vanilla's regions. + */ + private final Map> masterMap = new ConcurrentHashMap<>(); + + /** + * Initialize this instance. + * + * @param aId An arbitrary, but globally unique identifier for what this data is + * @param elementType The class of this element type. Used to create arrays. + * @param regionLength The length of one super region. Each super region will contain {@code regionLength * regionLength} chunks + * @param version An integer marking the version of this data. Useful later when the data's serialized form changed. + */ + protected GT_ChunkAssociatedData(String aId, Class elementType, int regionLength, byte version, boolean saveDefaults) { + if (regionLength * regionLength > Short.MAX_VALUE || regionLength <= 0) + throw new IllegalArgumentException("Region invalid: " + regionLength); + if (!IData.class.isAssignableFrom(elementType)) + throw new IllegalArgumentException("Data type invalid"); + if (aId.contains(".")) + throw new IllegalArgumentException("ID cannot contains dot"); + this.mId = aId; + this.elementtype = elementType; + this.regionLength = regionLength; + this.version = version; + this.saveDefaults = saveDefaults; + if (instances.putIfAbsent(aId, this) != null) + throw new IllegalArgumentException("Duplicate GT_ChunkAssociatedData: " + aId); + } + + private ChunkCoordIntPair getRegionID(int aChunkX, int aChunkZ) { + return new ChunkCoordIntPair(aChunkX / regionLength, aChunkZ / regionLength); + } + + /** + * Get a reference to data of the chunk that tile entity is in. + * The returned reference should be mutable. + */ + public final T get(IGregTechTileEntity tileEntity) { + return get(tileEntity.getWorld(), tileEntity.getXCoord() >> 4, tileEntity.getZCoord() >> 4); + } + + public final T get(Chunk chunk) { + return get(chunk.worldObj, chunk.xPosition, chunk.zPosition); + } + + public final T get(World world, ChunkCoordIntPair coord) { + return get(world, coord.chunkXPos, coord.chunkZPos); + } + + public final T get(World world, int chunkX, int chunkZ) { + SuperRegion region = masterMap.computeIfAbsent(world.provider.dimensionId, ignored -> new ConcurrentHashMap<>()) + .computeIfAbsent(getRegionID(chunkX, chunkZ), c -> new SuperRegion(world, c)); + return region.get(chunkX % regionLength, chunkZ % regionLength); + } + + protected final void set(World world, int chunkX, int chunkZ, T data) { + SuperRegion region = masterMap.computeIfAbsent(world.provider.dimensionId, ignored -> new ConcurrentHashMap<>()) + .computeIfAbsent(getRegionID(chunkX, chunkZ), c -> new SuperRegion(world, c)); + region.set(chunkX % regionLength, chunkZ % regionLength, data); + } + + protected final boolean isCreated(int dimId, int chunkX, int chunkZ) { + Map dimData = masterMap.getOrDefault(dimId, null); + if (dimData == null) return false; + + SuperRegion region = dimData.getOrDefault(getRegionID(chunkX, chunkZ), null); + if (region == null) return false; + + return region.isCreated(chunkX % regionLength, chunkZ % regionLength); + } + + public void clear() { + if (GT_Values.debugWorldData) { + long dirtyRegionCount = masterMap.values().stream() + .flatMap(m -> m.values().stream()) + .filter(SuperRegion::isDirty) + .count(); + if (dirtyRegionCount > 0) + GT_Log.out.println("Clearing ChunkAssociatedData with " + dirtyRegionCount + " regions dirty. Data might have been lost!"); + } + masterMap.clear(); + } + + public void save() { + saveRegions(masterMap.values().stream().flatMap(m -> m.values().stream())); + } + + public void save(World world) { + saveRegions(masterMap.get(world.provider.dimensionId).values().stream()); + } + + private void saveRegions(Stream stream) { + stream.filter(r -> !r.isDirty()) + .map(c -> (Runnable) c::save) + .map(r -> CompletableFuture.runAsync(r, IO_WORKERS)) + .reduce(CompletableFuture::allOf) + .ifPresent(f -> { + try { + f.get(); + } catch (Exception e) { + GT_Log.err.println("Data save error: " + mId); + e.printStackTrace(GT_Log.err); + } + }); + } + + protected abstract void writeElement(DataOutput output, T element, World world, int chunkX, int chunkZ) throws IOException; + + protected abstract T readElement(DataInput input, int version, World world, int chunkX, int chunkZ) throws IOException; + + protected abstract T createElement(World world, int chunkX, int chunkZ); + + /** + * Clear all mappings, regardless of whether they are dirty + */ + public static void clearAll() { + for (GT_ChunkAssociatedData d : instances.values()) d.clear(); + } + + /** + * Save all mappings + */ + public static void saveAll() { + for (GT_ChunkAssociatedData d : instances.values()) d.save(); + } + + /** + * Load data for all chunks for a given world. + * Current data for that world will be discarded. If this is what you intended, call {@link #save(World)} beforehand. + *

+ * Be aware of the memory consumption though. + */ + protected void loadAll(World w) { + if (GT_Values.debugWorldData && masterMap.containsKey(w.provider.dimensionId)) + GT_Log.err.println("Reloading ChunkAssociatedData " + mId + " for world " + w.provider.dimensionId + " discards old data!"); + if (!getSaveDirectory(w).isDirectory()) + // nothing to load... + return; + try { + Map worldData = Files.list(getSaveDirectory(w).toPath()) + .map(f -> { + Matcher matcher = FILE_PATTERN.matcher(f.getFileName().toString()); + return matcher.matches() ? matcher : null; + }) + .filter(Objects::nonNull) + .filter(m -> mId.equals(m.group(1))) + .map(m -> CompletableFuture.supplyAsync(() -> new SuperRegion(w, Integer.parseInt(m.group(2)), Integer.parseInt(m.group(3))), IO_WORKERS)) + .map(f -> { + try { + return f.get(); + } catch (Exception e) { + GT_Log.err.println("Error loading region"); + e.printStackTrace(GT_Log.err); + return null; + } + }) + .filter(Objects::nonNull) + .collect(Collectors.toMap(SuperRegion::getCoord, Function.identity())); + masterMap.put(w.provider.dimensionId, worldData); + } catch (IOException e) { + GT_Log.err.println("Error loading all region"); + e.printStackTrace(GT_Log.err); + } + } + + protected File getSaveDirectory(World w) { + return new File(w.getSaveHandler().getWorldDirectory(), "gregtech"); + } + + public interface IData { + /** + * @return Whether the data is different from chunk default + */ + boolean isSameAsDefault(); + } + + protected final class SuperRegion { + private final T[] data = createData(); + private final File backingStorage; + private final WeakReference world; + private final ChunkCoordIntPair coord; + + private SuperRegion(World world, int chunkX, int chunkZ) { + this.world = new WeakReference<>(world); + this.coord = new ChunkCoordIntPair(chunkX, chunkZ); + backingStorage = new File(getSaveDirectory(world), String.format("%s.%d.%d.dat", mId, chunkX, chunkZ)); + if (backingStorage.isFile()) + load(); + } + + private SuperRegion(World world, ChunkCoordIntPair coord) { + this.world = new WeakReference<>(world); + this.coord = coord; + backingStorage = new File(getSaveDirectory(world), String.format("%s.%d.%d.dat", mId, coord.chunkXPos, coord.chunkZPos)); + if (backingStorage.isFile()) + load(); + } + + @SuppressWarnings("unchecked") + private T[] createData() { + return (T[]) Array.newInstance(elementtype, regionLength * regionLength); + } + + public T get(int subRegionX, int subRegionZ) { + int index = getIndex(subRegionX, subRegionZ); + T datum = data[index]; + if (datum == null) { + World world = Objects.requireNonNull(this.world.get()); + T newElem = createElement(world, coord.chunkXPos * regionLength + subRegionX, coord.chunkZPos * regionLength + subRegionZ); + data[index] = newElem; + return newElem; + } + return datum; + } + + public void set(int subRegionX, int subRegionZ, T data) { + this.data[getIndex(subRegionX, subRegionZ)] = data; + } + + public boolean isCreated(int subRegionX, int subRegionZ) { + return this.data[getIndex(subRegionX, subRegionZ)] == null; + } + + public ChunkCoordIntPair getCoord() { + return coord; + } + + private int getIndex(int subRegionX, int subRegionY) { + return subRegionX * regionLength + subRegionY; + } + + private int getChunkX(int index) { + return index / regionLength + coord.chunkXPos; + } + + private int getChunkZ(int index) { + return index % regionLength + coord.chunkZPos; + } + + public boolean isDirty() { + for (T datum : data) { + if (datum != null && datum.isSameAsDefault()) + return true; + } + return false; + } + + public void save() { + try { + save0(); + } catch (IOException e) { + GT_Log.err.println("Error saving data " + backingStorage.getPath()); + e.printStackTrace(GT_Log.err); + } + } + + private void save0() throws IOException { + if (!isDirty()) + return; + //noinspection ResultOfMethodCallIgnored + backingStorage.getParentFile().mkdirs(); + File tmpFile = getTmpFile(); + World world = Objects.requireNonNull(this.world.get(), "Attempting to save region of another world!"); + try (DataOutputStream output = new DataOutputStream(new FileOutputStream(tmpFile))) { + int ptr = 0; + boolean nullRange = data[0] == null; + // write a magic byte as storage format version + output.writeByte(0); + // write a magic byte as data format version + output.writeByte(version); + output.writeBoolean(nullRange); + while (ptr < data.length) { + // work out how long is this range + int rangeStart = ptr; + while (ptr < data.length && (data[ptr] == null || (!saveDefaults && data[ptr].isSameAsDefault())) == nullRange) + ptr++; + // write range length + output.writeShort(ptr - rangeStart); + if (!nullRange) + // write element data + for (int i = rangeStart; i < ptr; i++) + writeElement(output, data[i], world, getChunkX(ptr), getChunkZ(ptr)); + // or not + nullRange = !nullRange; + } + } + // first try to replace the destination file + // since atomic operation, no need to keep the backup in place + try { + Files.move(tmpFile.toPath(), backingStorage.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE); + } catch (AtomicMoveNotSupportedException ignored) { + // in case some dumb system/jre combination would cause this + // or if **somehow** two file inside the same directory belongs two separate filesystem + FileUtils.copyFile(tmpFile, backingStorage); + } + } + + public void load() { + try { + loadFromFile(backingStorage); + } catch (IOException | RuntimeException e) { + GT_Log.err.println("Primary storage file broken in " + backingStorage.getPath()); + e.printStackTrace(GT_Log.err); + // in case the primary storage is broken + try { + loadFromFile(getTmpFile()); + } catch (IOException | RuntimeException e2) { + GT_Log.err.println("Backup storage file broken in " + backingStorage.getPath()); + e2.printStackTrace(GT_Log.err); + } + } + } + + private void loadFromFile(File file) throws IOException { + World world = Objects.requireNonNull(this.world.get(), "Attempting to load region of another world!"); + try (DataInputStream input = new DataInputStream(new FileInputStream(file))) { + boolean nullRange = input.readBoolean(); + int ptr = 0; + while (ptr != data.length) { + int rangeEnd = ptr + input.readUnsignedShort(); + if (!nullRange) { + for (; ptr < rangeEnd; ptr++) { + data[ptr] = readElement(input, version, world, getChunkX(ptr), getChunkZ(ptr)); + } + } else { + Arrays.fill(data, ptr, rangeEnd, null); + ptr = rangeEnd; + } + } + } + } + + private File getTmpFile() { + return new File(backingStorage.getParentFile(), backingStorage.getName() + ".tmp"); + } + } + + public static class EventHandler { + private EventHandler() { + MinecraftForge.EVENT_BUS.register(this); + } + + @SubscribeEvent + public void onWorldSave(WorldEvent.Save e) { + for (GT_ChunkAssociatedData d : instances.values()) { + d.save(e.world); + } + } + + @SubscribeEvent + public void onWorldUnload(WorldEvent.Unload e) { + for (GT_ChunkAssociatedData d : instances.values()) { + // there is no need to explicitly do a save here + // forge will send a WorldEvent.Save on server thread before this event is distributed + d.masterMap.remove(e.world.provider.dimensionId); + } + } + } +} diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 16d22be9ef..2ae09b6adf 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -12,13 +12,24 @@ import gregtech.api.GregTech_API; import gregtech.api.damagesources.GT_DamageSources; import gregtech.api.damagesources.GT_DamageSources.DamageSourceHotItem; import gregtech.api.enchants.Enchantment_Radioactivity; -import gregtech.api.enums.*; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.SubTag; +import gregtech.api.enums.Textures; +import gregtech.api.enums.ToolDictNames; import gregtech.api.events.BlockScanningEvent; import gregtech.api.interfaces.IBlockContainer; import gregtech.api.interfaces.IDebugableBlock; import gregtech.api.interfaces.IProjectileItem; import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.*; +import gregtech.api.interfaces.tileentity.IBasicEnergyContainer; +import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.interfaces.tileentity.IGregTechDeviceInformation; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.interfaces.tileentity.IMachineProgress; +import gregtech.api.interfaces.tileentity.IUpgradableMachine; import gregtech.api.items.GT_EnergyArmor_Item; import gregtech.api.items.GT_Generic_Item; import gregtech.api.items.GT_MetaGenerated_Tool; @@ -28,7 +39,7 @@ 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 gregtech.common.GT_Pollution; import gregtech.common.blocks.GT_Block_Ores_Abstract; import ic2.api.recipe.IRecipeInput; import ic2.api.recipe.RecipeInputItemStack; @@ -37,7 +48,11 @@ import ic2.api.recipe.RecipeOutput; import net.minecraft.block.Block; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.*; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.EnumCreatureAttribute; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -59,9 +74,14 @@ import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityChest; -import net.minecraft.util.*; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraft.world.WorldServer; +import net.minecraft.world.chunk.Chunk; import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.BlockSnapshot; @@ -70,8 +90,13 @@ import net.minecraftforge.common.util.FakePlayerFactory; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.event.world.BlockEvent; -import net.minecraftforge.fluids.*; +import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidContainerItem; +import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.oredict.OreDictionary; import javax.annotation.Nullable; @@ -79,16 +104,34 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.text.NumberFormat; -import java.text.DecimalFormatSymbols; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; import java.util.function.Function; import java.util.function.IntFunction; import java.util.function.Supplier; import static gregtech.GT_Mod.GT_FML_LOGGER; -import static gregtech.api.enums.GT_Values.*; -import static gregtech.common.GT_Proxy.GTPOLLUTION; +import static gregtech.api.enums.GT_Values.D1; +import static gregtech.api.enums.GT_Values.DW; +import static gregtech.api.enums.GT_Values.E; +import static gregtech.api.enums.GT_Values.GT; +import static gregtech.api.enums.GT_Values.L; +import static gregtech.api.enums.GT_Values.M; +import static gregtech.api.enums.GT_Values.NW; +import static gregtech.api.enums.GT_Values.V; +import static gregtech.api.enums.GT_Values.W; import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation; /** @@ -2186,23 +2229,19 @@ public class GT_Utility { } } + Chunk currentChunk = aWorld.getChunkFromBlockCoords(aX, aZ); if (aPlayer.capabilities.isCreativeMode) { - FluidStack tFluid = undergroundOilReadInformation(aWorld.getChunkFromBlockCoords(aX,aZ));//-# to only read + FluidStack tFluid = undergroundOilReadInformation(currentChunk);//-# to only read if (tFluid!=null) tList.add(EnumChatFormatting.GOLD + tFluid.getLocalizedName() + EnumChatFormatting.RESET + ": " + EnumChatFormatting.YELLOW + formatNumbers(tFluid.amount) + EnumChatFormatting.RESET + " L"); else tList.add(EnumChatFormatting.GOLD + trans("201","Nothing") + EnumChatFormatting.RESET + ": " + EnumChatFormatting.YELLOW + '0' + EnumChatFormatting.RESET + " L"); } // if(aPlayer.capabilities.isCreativeMode){ - int[] chunkData = GT_Proxy.dimensionWiseChunkData.get(aWorld.provider.dimensionId).get(aWorld.getChunkFromBlockCoords(aX,aZ).getChunkCoordIntPair()); - if(chunkData != null){ - if(chunkData[GTPOLLUTION]>0){ - tList.add(trans("202","Pollution in Chunk: ") + EnumChatFormatting.RED + formatNumbers(chunkData[GTPOLLUTION]) + EnumChatFormatting.RESET + trans("203"," gibbl")); - }else{ - tList.add(EnumChatFormatting.GREEN+trans("204","No Pollution in Chunk! HAYO!")+EnumChatFormatting.RESET); - } - }else{ - tList.add(EnumChatFormatting.GREEN+trans("204","No Pollution in Chunk! HAYO!")+EnumChatFormatting.RESET); + if (GT_Pollution.hasPollution(currentChunk)) { + tList.add(trans("202", "Pollution in Chunk: ") + EnumChatFormatting.RED + formatNumbers(GT_Pollution.getPollution(currentChunk)) + EnumChatFormatting.RESET + trans("203", " gibbl")); + } else { + tList.add(EnumChatFormatting.GREEN + trans("204", "No Pollution in Chunk! HAYO!") + EnumChatFormatting.RESET); } try { diff --git a/src/main/java/gregtech/common/GT_Pollution.java b/src/main/java/gregtech/common/GT_Pollution.java index 7b1ad90d52..2a13d692b3 100644 --- a/src/main/java/gregtech/common/GT_Pollution.java +++ b/src/main/java/gregtech/common/GT_Pollution.java @@ -7,6 +7,7 @@ import gregtech.GT_Mod; import gregtech.api.enums.GT_Values; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.net.GT_Packet_Pollution; +import gregtech.api.util.GT_ChunkAssociatedData; import gregtech.api.util.GT_Utility; import net.minecraft.block.Block; import net.minecraft.block.material.Material; @@ -20,30 +21,34 @@ import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.ChunkPosition; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.world.ChunkDataEvent; import net.minecraftforge.event.world.ChunkWatchEvent; +import net.minecraftforge.event.world.WorldEvent; +import javax.annotation.ParametersAreNonnullByDefault; +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import static gregtech.api.objects.XSTR.XSTR_INSTANCE; -import static gregtech.common.GT_Proxy.GTPOLLUTION; -import static gregtech.common.GT_Proxy.dimensionWiseChunkData; import static gregtech.common.GT_Proxy.dimensionWisePollution; -import static gregtech.common.GT_Proxy.getDefaultChunkDataOnCreation; public class GT_Pollution { + private static final Storage STORAGE = new Storage(); /** * Pollution dispersion until effects start: * Calculation: ((Limit * 0.01) + 2000) * (4 <- spreading rate) - * + * * SMOG(500k) 466.7 pollution/sec * Poison(750k) 633,3 pollution/sec * Dying Plants(1mio) 800 pollution/sec * Sour Rain(1.5mio) 1133.3 pollution/sec - * + * * Pollution producers (pollution/sec) * Bronze Boiler(20) * Lava Boiler(20) @@ -69,10 +74,10 @@ public class GT_Pollution { * LV (0%), MV (30%), HV (52%), EV (66%), IV (76%), LuV (84%), ZPM (89%), UV (92%), MAX (95%) */ private List pollutionList = new ArrayList<>();//chunks left to process - private HashMap chunkData;//link to chunk data that is saved/loaded + private final List chunkData = new ArrayList<>();//link to chunk data that is saved/loaded private int operationsPerTick=0;//how much chunks should be processed in each cycle private static final short cycleLen=1200; - private final World aWorld; + private final World world; public static int mPlayerPollution; private static int POLLUTIONPACKET_MINVALUE = 1000; @@ -80,13 +85,7 @@ public class GT_Pollution { private static GT_PollutionEventHandler EVENT_HANDLER; public GT_Pollution(World world){ - aWorld=world; - chunkData=dimensionWiseChunkData.get(aWorld.provider.dimensionId); - if(chunkData==null){ - chunkData=new HashMap<>(1024); - dimensionWiseChunkData.put(world.provider.dimensionId,chunkData); - } - dimensionWisePollution.put(aWorld.provider.dimensionId,this); + this.world = world; if (EVENT_HANDLER == null) { EVENT_HANDLER = new GT_PollutionEventHandler(); @@ -105,7 +104,9 @@ public class GT_Pollution { private void tickPollutionInWorld(int aTickID){//called from method above //gen data set if(aTickID==0){ - pollutionList = new ArrayList<>(chunkData.keySet()); + // make a snapshot of what to work on + // counterintuitive as it seems, but this is the fastest way java collections framework offers us. + pollutionList = new ArrayList<>(chunkData); //set operations per tick if(pollutionList.size()>0) operationsPerTick =(pollutionList.size()/cycleLen); else operationsPerTick=0;//SANity @@ -114,10 +115,9 @@ public class GT_Pollution { for(int chunksProcessed=0;chunksProcessed<=operationsPerTick;chunksProcessed++){ if(pollutionList.size()==0)break;//no more stuff to do ChunkCoordIntPair actualPos=pollutionList.remove(pollutionList.size()-1);//faster - //add default data if missing - if(!chunkData.containsKey(actualPos)) chunkData.put(actualPos,getDefaultChunkDataOnCreation()); //get pollution - int tPollution = chunkData.get(actualPos)[GTPOLLUTION]; + ChunkData currentData = STORAGE.get(world, actualPos); + int tPollution = currentData.getAmount(); //remove some tPollution = (int)(0.9945f*tPollution); //tPollution -= 2000;//This does not really matter... @@ -131,15 +131,14 @@ public class GT_Pollution { tNeighbors[2]=(new ChunkCoordIntPair(actualPos.chunkXPos,actualPos.chunkZPos+1)); tNeighbors[3]=(new ChunkCoordIntPair(actualPos.chunkXPos,actualPos.chunkZPos-1)); for(ChunkCoordIntPair neighborPosition : tNeighbors){ - if(!chunkData.containsKey(neighborPosition)) chunkData.put(neighborPosition,getDefaultChunkDataOnCreation()); - - int neighborPollution = chunkData.get(neighborPosition)[GTPOLLUTION]; - if(neighborPollution*6 < tPollution*5){//METHEMATICS... + ChunkData neighbor = STORAGE.get(world, neighborPosition); + int neighborPollution = neighbor.getAmount(); + if(neighborPollution*6 < tPollution*5){//MATHEMATICS... int tDiff = tPollution - neighborPollution; tDiff = tDiff/20; neighborPollution = GT_Utility.safeInt((long)neighborPollution+tDiff);//tNPol += tDiff; tPollution -= tDiff; - chunkData.get(neighborPosition)[GTPOLLUTION] = neighborPollution; + neighbor.setAmount(neighborPollution); } } @@ -148,7 +147,7 @@ public class GT_Pollution { //Smog filter TODO if(tPollution > GT_Mod.gregtechproxy.mPollutionSmogLimit) { AxisAlignedBB chunk = AxisAlignedBB.getBoundingBox(actualPos.chunkXPos << 4, 0, actualPos.chunkZPos << 4, (actualPos.chunkXPos << 4) + 16, 256, (actualPos.chunkZPos << 4) + 16); - List tEntitys = aWorld.getEntitiesWithinAABB(EntityLivingBase.class, chunk); + List tEntitys = world.getEntitiesWithinAABB(EntityLivingBase.class, chunk); for (EntityLivingBase tEnt : tEntitys) { if (tEnt instanceof EntityPlayerMP && ((EntityPlayerMP) tEnt).capabilities.isCreativeMode) continue; @@ -194,18 +193,18 @@ public class GT_Pollution { int x = (actualPos.chunkXPos << 4) + XSTR_INSTANCE.nextInt(16); int y = 60 + (-f + XSTR_INSTANCE.nextInt(f * 2 + 1)); int z = (actualPos.chunkZPos << 4) + XSTR_INSTANCE.nextInt(16); - damageBlock(aWorld, x, y, z, tPollution > GT_Mod.gregtechproxy.mPollutionSourRainLimit); + damageBlock(world, x, y, z, tPollution > GT_Mod.gregtechproxy.mPollutionSourRainLimit); } } } } } //Write new pollution to Hashmap !!! - chunkData.get(actualPos)[GTPOLLUTION] = tPollution; + currentData.setAmount(tPollution); //Send new value to players nearby if (tPollution > POLLUTIONPACKET_MINVALUE) { - NetworkRegistry.TargetPoint point = new NetworkRegistry.TargetPoint(aWorld.provider.dimensionId, (actualPos.chunkXPos << 4), 64, (actualPos.chunkZPos << 4), 256); + NetworkRegistry.TargetPoint point = new NetworkRegistry.TargetPoint(world.provider.dimensionId, (actualPos.chunkXPos << 4), 64, (actualPos.chunkZPos << 4), 256); GT_Values.NW.sendToAllAround(new GT_Packet_Pollution(actualPos, tPollution), point); } } @@ -266,19 +265,8 @@ public class GT_Pollution { } public static void addPollution(Chunk ch, int aPollution){ - if(!GT_Mod.gregtechproxy.mPollution)return; - HashMap dataMap=dimensionWiseChunkData.get(ch.worldObj.provider.dimensionId); - if(dataMap==null){ - dataMap=new HashMap<>(1024); - dimensionWiseChunkData.put(ch.worldObj.provider.dimensionId,dataMap); - } - int[] dataArr=dataMap.get(ch.getChunkCoordIntPair()); - if(dataArr==null){ - dataArr=getDefaultChunkDataOnCreation(); - dataMap.put(ch.getChunkCoordIntPair(),dataArr); - } - dataArr[GTPOLLUTION]+=aPollution; - if(dataArr[GTPOLLUTION]<0)dataArr[GTPOLLUTION]=0; + if(!GT_Mod.gregtechproxy.mPollution || aPollution == 0)return; + STORAGE.get(ch).changeAmount(aPollution); } public static int getPollution(IGregTechTileEntity te){ @@ -288,18 +276,19 @@ public class GT_Pollution { public static int getPollution(Chunk ch){ if(!GT_Mod.gregtechproxy.mPollution) return 0; - HashMap dataMap=dimensionWiseChunkData.get(ch.worldObj.provider.dimensionId); - if(dataMap==null || dataMap.get(ch.getChunkCoordIntPair())==null) return 0; - return dataMap.get(ch.getChunkCoordIntPair())[GTPOLLUTION]; + return STORAGE.get(ch).getAmount(); + } + + public static boolean hasPollution(Chunk ch) { + if (!GT_Mod.gregtechproxy.mPollution) + return false; + return STORAGE.isCreated(ch.worldObj, ch.getChunkCoordIntPair()) && STORAGE.get(ch).getAmount() > 0; } public static int getPollution(ChunkCoordIntPair aCh, int aDim) { if (!GT_Mod.gregtechproxy.mPollution) return 0; - HashMap dataMap = dimensionWiseChunkData.get(aDim); - if (dataMap == null || dataMap.get(aCh) == null) - return 0; - return dataMap.get(aCh)[GTPOLLUTION]; + return STORAGE.get(DimensionManager.getWorld(aDim), aCh.chunkXPos, aCh.chunkZPos).getAmount(); } //Add compatibility with old code @@ -310,15 +299,100 @@ public class GT_Pollution { addPollution(aWorld.getChunkFromBlockCoords(aPos.chunkPosX,aPos.chunkPosZ),aPollution); } - public class GT_PollutionEventHandler { + static void migrate(ChunkDataEvent.Load e) { + addPollution(e.getChunk(), e.getData().getInteger("GTPOLLUTION")); + } + + public static class GT_PollutionEventHandler { @SubscribeEvent public void chunkWatch(ChunkWatchEvent.Watch event) { - if(!GT_Mod.gregtechproxy.mPollution) return; - if (chunkData.containsKey(event.chunk)) { - int pollution = chunkData.get(event.chunk)[GTPOLLUTION]; + if (!GT_Mod.gregtechproxy.mPollution) return; + World world = event.player.worldObj; + if (STORAGE.isCreated(world, event.chunk)) { + int pollution = STORAGE.get(world, event.chunk).getAmount(); if (pollution > POLLUTIONPACKET_MINVALUE) GT_Values.NW.sendToPlayer(new GT_Packet_Pollution(event.chunk, pollution), event.player); } } + + @SubscribeEvent + public void onWorldLoad(WorldEvent.Load e) { + // super class loads everything lazily. We force it to load them all. + STORAGE.loadAll(e.world); + } + } + + @ParametersAreNonnullByDefault + private static final class Storage extends GT_ChunkAssociatedData { + private Storage() { + super("Pollution", ChunkData.class, 64, (byte) 0, false); + } + + @Override + protected void writeElement(DataOutput output, ChunkData element, World world, int chunkX, int chunkZ) throws IOException { + output.writeInt(element.getAmount()); + } + + @Override + protected ChunkData readElement(DataInput input, int version, World world, int chunkX, int chunkZ) throws IOException { + ChunkData data = new ChunkData(input.readInt()); + getChunkData(world).add(new ChunkCoordIntPair(chunkX, chunkZ)); + return data; + } + + private List getChunkData(World world) { + return dimensionWisePollution.computeIfAbsent(world.provider.dimensionId, i -> new GT_Pollution(world)).chunkData; + } + + @Override + protected ChunkData createElement(World world, int chunkX, int chunkZ) { + return new ChunkData(); + } + + @Override + public void loadAll(World w) { + super.loadAll(w); + } + + public void set(World world, ChunkCoordIntPair coord, ChunkData data) { + set(world, coord.chunkXPos, coord.chunkZPos, data); + getChunkData(world).add(coord); + } + + public boolean isCreated(World world, ChunkCoordIntPair coord) { + return isCreated(world.provider.dimensionId, coord.chunkXPos, coord.chunkZPos); + } + } + + private static final class ChunkData implements GT_ChunkAssociatedData.IData { + public int amount; + + private ChunkData() { + this(0); + } + + private ChunkData(int amount) { + this.amount = amount; + } + + /** + * Current pollution amount. + */ + public int getAmount() { + return amount; + } + + public void setAmount(int amount) { + this.amount = Math.max(amount, 0); + } + + public void changeAmount(int delta) { + this.amount = Math.max(amount + delta, 0); + } + + @Override + public boolean isSameAsDefault() { + return amount == 0; + } } } diff --git a/src/main/java/gregtech/common/GT_Proxy.java b/src/main/java/gregtech/common/GT_Proxy.java index ed99c1e3c0..a1706ee6e9 100644 --- a/src/main/java/gregtech/common/GT_Proxy.java +++ b/src/main/java/gregtech/common/GT_Proxy.java @@ -709,8 +709,8 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { } public void onServerAboutToStart(){ - dimensionWiseChunkData.clear();//!!! IMPORTANT for map switching... dimensionWisePollution.clear();//!!! IMPORTANT for map switching... + GT_ChunkAssociatedData.clearAll(); } public void onServerStarting() { @@ -776,6 +776,7 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { } catch (Throwable e) {e.printStackTrace(GT_Log.err);} } this.mUniverse = null; + //GT_ChunkAssociatedData.saveAll(); todo: figure out if this is needed } @SubscribeEvent @@ -1981,87 +1982,25 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { } + @Deprecated public static final HashMap> dimensionWiseChunkData = new HashMap<>(16);//stores chunk data that is loaded/saved public static final HashMap dimensionWisePollution = new HashMap<>(16);//stores GT_Polluttors objects public static final byte GTOIL=3,GTOILFLUID=2,GTPOLLUTION=1,GTMETADATA=0,NOT_LOADED=0,LOADED=1;//consts - //@Deprecated - //public static final HashMap chunkData = new HashMap<>(0); - - private static final byte oilVer=(byte)20;//non zero plz //TO get default's fast + @Deprecated public static int[] getDefaultChunkDataOnCreation(){ return new int[]{NOT_LOADED,0,-1,-1}; } + @Deprecated public static int[] getDefaultChunkDataOnLoad(){ return new int[]{LOADED,0,-1,-1}; } - @SubscribeEvent - public void handleChunkSaveEvent(ChunkDataEvent.Save event) {//ALWAYS SAVE FROM THE HASH MAP DATA - HashMap chunkData=dimensionWiseChunkData.get(event.world.provider.dimensionId); - if(chunkData==null) return;//no dim info stored - - int[] tInts = chunkData.get(event.getChunk().getChunkCoordIntPair()); - if(tInts==null) return;//no chunk data stored - //assuming len of this array 4 - if(tInts[3]>=0)event.getData().setInteger("GTOIL", tInts[GTOIL]); - else event.getData().removeTag("GTOIL"); - if(tInts[2]>=0)event.getData().setInteger("GTOILFLUID", tInts[GTOILFLUID]); - else event.getData().removeTag("GTOILFLUID"); - if(tInts[1]>0)event.getData().setInteger("GTPOLLUTION", tInts[GTPOLLUTION]); - else event.getData().removeTag("GTPOLLUTION"); - event.getData().setByte("GTOILVER", oilVer);//version mark - } - @SubscribeEvent public void handleChunkLoadEvent(ChunkDataEvent.Load event) { - final int worldID=event.world.provider.dimensionId; - HashMap chunkData = dimensionWiseChunkData.computeIfAbsent(worldID, k -> new HashMap<>(1024)); - if (dimensionWisePollution.get(worldID) == null) - dimensionWisePollution.put(worldID, new GT_Pollution(event.world)); - - int[] tInts = chunkData.get(event.getChunk().getChunkCoordIntPair()); - if (tInts == null) { - //NOT LOADED and NOT PROCESSED by pollution algorithms - //regular load - tInts = getDefaultChunkDataOnLoad(); - - if (event.getData().getByte("GTOILVER") == oilVer) { - if (event.getData().hasKey("GTOIL")) - tInts[GTOIL] = event.getData().getInteger("GTOIL"); - if (event.getData().hasKey("GTOILFLUID")) - tInts[GTOILFLUID] = event.getData().getInteger("GTOILFLUID"); - } - - tInts[GTPOLLUTION] = event.getData().getInteger("GTPOLLUTION");//Defaults to 0 - - //store in HASH MAP if has useful data - if (tInts[GTPOLLUTION] > 0 || tInts[GTOIL] >= 0 || tInts[GTOILFLUID] >= 0) - chunkData.put(event.getChunk().getChunkCoordIntPair(), tInts); - } else if (tInts[GTMETADATA] == NOT_LOADED) {//was NOT loaded from chunk save game data - //NOT LOADED but generated - //append load - if (event.getData().getByte("GTOILVER") == oilVer) { - if (tInts[GTOIL] < 0 && event.getData().hasKey("GTOIL"))//if was not yet initialized - tInts[GTOIL] = event.getData().getInteger("GTOIL"); - - if (tInts[GTOILFLUID] < 0 && event.getData().hasKey("GTOILFLUID"))//if was not yet initialized - tInts[GTOILFLUID] = event.getData().getInteger("GTOILFLUID"); - } else { - tInts[GTOIL] = -1; - tInts[GTOILFLUID] = -1; - } - - tInts[GTPOLLUTION] += event.getData().getInteger("GTPOLLUTION");//Defaults to 0, add stored pollution to data - tInts[GTMETADATA] = LOADED;//mark as = loaded - //store in HASHMAP - - chunkData.put(event.getChunk().getChunkCoordIntPair(), tInts); - }//else if(tInts[0]==1){ - ////Already loaded chunk data - ////DO NOTHING - this chunk data was already loaded and stored in hash map - //} + GT_UndergroundOil.migrate(event); + GT_Pollution.migrate(event); } @SubscribeEvent diff --git a/src/main/java/gregtech/common/GT_UndergroundOil.java b/src/main/java/gregtech/common/GT_UndergroundOil.java index 1f45b5fca9..cc6771dc90 100644 --- a/src/main/java/gregtech/common/GT_UndergroundOil.java +++ b/src/main/java/gregtech/common/GT_UndergroundOil.java @@ -5,22 +5,29 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.GT_UO_Dimension; import gregtech.api.objects.GT_UO_Fluid; import gregtech.api.objects.XSTR; -import net.minecraft.world.ChunkCoordIntPair; +import gregtech.api.util.GT_ChunkAssociatedData; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; -import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.event.world.ChunkDataEvent; +import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; -import java.util.HashMap; +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.Objects; +import java.util.WeakHashMap; import static gregtech.api.objects.XSTR.XSTR_INSTANCE; -import static gregtech.common.GT_Proxy.*; /** * Created by Tec on 29.04.2017. */ public class GT_UndergroundOil { public static final short DIVIDER=5000; + private static final GT_UndergroundOilStore STORAGE = new GT_UndergroundOilStore(); public static FluidStack undergroundOilReadInformation(IGregTechTileEntity te){ return undergroundOil(te.getWorld().getChunkFromBlockCoords(te.getXCoord(),te.getZCoord()),-1); @@ -37,81 +44,221 @@ public class GT_UndergroundOil { //Returns whole content for information purposes -> when drainSpeedCoefficient < 0 //Else returns extracted fluidStack if amount > 0, or null otherwise public static FluidStack undergroundOil(Chunk chunk, float readOrDrainCoefficient) { - World aWorld = chunk.worldObj; - int dimensionId=aWorld.provider.dimensionId; - GT_UO_Dimension dimension=GT_Mod.gregtechproxy.mUndergroundOil.GetDimension(dimensionId); - if(dimension==null) return null; - - //Read hash map - HashMap chunkData = dimensionWiseChunkData.get(dimensionId); - if(chunkData==null){ - chunkData=new HashMap<>(1024); - dimensionWiseChunkData.put(dimensionId,chunkData); - } - - int[] tInts = chunkData.get(chunk.getChunkCoordIntPair()); - - if(tInts==null) tInts=getDefaultChunkDataOnCreation();//init if null - else if(tInts[GTOIL]==0){//FAST stop - //can return 0 amount stack for info :D - return readOrDrainCoefficient>=0 ? null : new FluidStack(FluidRegistry.getFluid(tInts[GTOILFLUID]),0); - } - - //GEN IT TO GET OBJECT... - final XSTR tRandom = new XSTR(aWorld.getSeed() + dimensionId * 2 + - (chunk.getChunkCoordIntPair().chunkXPos>>3) + - 8267 * (chunk.getChunkCoordIntPair().chunkZPos>>3)); - - GT_UO_Fluid uoFluid = dimension.getRandomFluid(tRandom); - - //Fluid stack holder - FluidStack fluidInChunk; - - //Set fluid stack from uoFluid - if (uoFluid == null || uoFluid.getFluid()==null){ - tInts[GTOILFLUID]=Integer.MAX_VALUE;//null fluid pointer... kind of - tInts[GTOIL]=0; - chunkData.put(chunk.getChunkCoordIntPair(),tInts);//update hash map + ChunkData chunkData = STORAGE.get(chunk); + if (chunkData.getVein() == null || chunkData.getFluid() == null) // nothing here... return null; - } else { - if(tInts[GTOILFLUID]== uoFluid.getFluid().getID()){//if stored fluid matches uoFluid - fluidInChunk = new FluidStack(uoFluid.getFluid(),tInts[GTOIL]); - }else{ - fluidInChunk = new FluidStack(uoFluid.getFluid(), uoFluid.getRandomAmount(tRandom)); - fluidInChunk.amount=(int)((float)fluidInChunk.amount*(0.75f+(XSTR_INSTANCE.nextFloat()/2f)));//Randomly change amounts by +/- 25% - } - tInts[GTOIL]=fluidInChunk.amount; - tInts[GTOILFLUID]=fluidInChunk.getFluidID(); - } - //do stuff on it if needed + FluidStack fluidInChunk = new FluidStack(chunkData.getFluid(), 0); if(readOrDrainCoefficient>=0){ - int fluidExtracted=(int)Math.floor(fluidInChunk.amount * (double) readOrDrainCoefficient / DIVIDER); - double averageDecrease=uoFluid.DecreasePerOperationAmount * (double)readOrDrainCoefficient; + int fluidExtracted = (int) Math.floor(chunkData.getAmount() * (double) readOrDrainCoefficient / DIVIDER); + double averageDecrease = chunkData.getVein().DecreasePerOperationAmount * (double) readOrDrainCoefficient; int decrease=(int)Math.ceil(averageDecrease); - if(fluidExtracted<=0 || fluidInChunk.amount<=decrease){//decrease - here it is max value of extraction for easy check - fluidInChunk=null; - tInts[GTOIL]=0;//so in next access it will stop way above + if (fluidExtracted <= 0 || chunkData.amount <= decrease) {//decrease - here it is max value of extraction for easy check + chunkData.setAmount(0); }else{ fluidInChunk.amount = fluidExtracted;//give appropriate amount - if(XSTR_INSTANCE.nextFloat()<(decrease-averageDecrease)) decrease--;//use XSTR_INSTANCE to "subtract double from int" + if (XSTR_INSTANCE.nextFloat() < (decrease - averageDecrease)) + decrease--;//use XSTR_INSTANCE to "subtract double from int" //ex. // averageDecrease=3.9 // decrease= ceil from 3.9 = 4 // decrease-averageDecrease=0.1 -> chance to subtract 1 // if XSTR_INSTANCE is < chance then subtract 1 - tInts[GTOIL]-=decrease;//diminish amount, "randomly" adjusted to double value (averageDecrease) + chunkData.changeAmount(-decrease);//diminish amount, "randomly" adjusted to double value (averageDecrease) } }else{//just get info if(fluidInChunk.amount<=DIVIDER){ fluidInChunk.amount=0;//return informative stack - tInts[GTOIL]=0;//so in next access it will stop way above + chunkData.setAmount(0); }else{ fluidInChunk.amount=fluidInChunk.amount/DIVIDER;//give moderate extraction speed } } - - chunkData.put(chunk.getChunkCoordIntPair(),tInts);//update hash map return fluidInChunk; } + + static void migrate(ChunkDataEvent.Load e) { + if (e.getData().hasKey("GTOIL") && e.getData().hasKey("GTOILFLUID")) { + ChunkData chunkData = STORAGE.get(e.getChunk()); + Fluid fluid = chunkData.getFluid(); + if (fluid != null && fluid.getID() == e.getData().getInteger("GTOIL")) + chunkData.setAmount(Math.min(chunkData.getAmount(), e.getData().getInteger("GTOILFLUID"))); + } + } + + /** + * Revamped UO store. + *

+ * Primary functionality: + * + *

    + *
  • Decouple data storage with chunk, making it possible to pump oil from unloaded chunks
  • + *
  • Regen detection. If fluid generation config is changed, chunk fluid will be regenerated.
  • + *
+ * + *

Serialized form

+ *

+ * Since the exact file layout is controlled by the super class, here we only concern how each chunk's data is written. + *

Form A: Empty Chunk

+ *
    + *
  1. 4 bytes of 0
  2. + *
+ * + *

Form B: Normal Chunk

+ *
    + *
  1. 4 bytes unsigned integer. Vein Hash.
  2. + *
  3. UTF string. Vein Key.
  4. + *
  5. 4 bytes signed integer. Fluid amount.
  6. + *
+ * + * @author glease + */ + @ParametersAreNonnullByDefault + private static class GT_UndergroundOilStore extends GT_ChunkAssociatedData { + private static final GT_UndergroundOil.ChunkData NIL_FLUID_STACK = new GT_UndergroundOil.ChunkData(-1, null, null, false); + private static final WeakHashMap hashes = new WeakHashMap<>(); + + private GT_UndergroundOilStore() { + super("UO", GT_UndergroundOil.ChunkData.class, 64, (byte) 0, false); + } + + @Override + protected void writeElement(DataOutput output, ChunkData element, World world, int chunkX, int chunkZ) throws IOException { + /* see class javadoc for explanation */ + output.writeInt(element.getVeinHash()); + if (element.getVeinKey() == null) return; + output.writeUTF(element.getVeinKey()); + if (element.getAmount() > 0 && element.getFluid() != null) { + output.writeInt(element.getAmount()); + } else { + output.writeInt(-1); + } + } + + @Override + protected GT_UndergroundOil.ChunkData readElement(DataInput input, int version, World world, int chunkX, int chunkZ) throws IOException { + /* see class javadoc for explanation */ + if (version != 0) + throw new IOException("Region file corrupted"); + GT_UndergroundOil.ChunkData pristine = createElement(world, chunkX, chunkZ); + int hash = input.readInt(); + String veinKey = hash != 0 ? input.readUTF() : null; + int amount = hash != 0 ? input.readInt() : -1; + if (hash != pristine.veinHash || !Objects.equals(veinKey, pristine.getVeinKey())) { + // vein config changed. use regen-ed data. + return pristine; + } + if (hash == 0) + return NIL_FLUID_STACK; + return new GT_UndergroundOil.ChunkData(amount, GT_Mod.gregtechproxy.mUndergroundOil.GetDimension(world.provider.dimensionId).getUOFluid(veinKey), veinKey); + } + + @Override + protected GT_UndergroundOil.ChunkData createElement(World world, int chunkX, int chunkZ) { + int dimensionId = world.provider.dimensionId; + GT_UO_Dimension dimension = GT_Mod.gregtechproxy.mUndergroundOil.GetDimension(dimensionId); + if (dimension == null) return NIL_FLUID_STACK; + // prepare RNG 🙏 🙏 🙏 + final XSTR tRandom = new XSTR(world.getSeed() + dimensionId * 2L + (chunkX >> 3) + 8267L * (chunkZ >> 3)); + GT_UO_Fluid uoFluid = dimension.getRandomFluid(tRandom); + // nothing here :( + if (uoFluid == null || uoFluid.getFluid() == null) return NIL_FLUID_STACK; + // offset each chunk's fluid amount by +-25% + int amount = (int) ((float) uoFluid.getRandomAmount(tRandom) * (0.75f + (XSTR_INSTANCE.nextFloat() / 2f))); + return new GT_UndergroundOil.ChunkData(amount, uoFluid, dimension.getUOFluidKey(uoFluid), false); + } + + private static int hash(@Nullable GT_UO_Fluid fluid) { + if (fluid == null) + return 0; + int result = fluid.Registry.hashCode(); + result = 31 * result + fluid.MaxAmount; + result = 31 * result + fluid.MinAmount; + result = 31 * result + fluid.Chance; + result = 31 * result + fluid.DecreasePerOperationAmount; + return result == 0 ? 1 : result; + } + + } + + /** + * Represent the amount of fluid in a given chunk. + */ + private static final class ChunkData implements GT_ChunkAssociatedData.IData { + private final Fluid fluid; + @Nullable + private final GT_UO_Fluid vein; + private final String veinKey; + private final int veinHash; + private int amount; + private boolean dirty; + + private ChunkData(int amount, GT_UO_Fluid veinKey, String veinID) { + this(amount, veinKey, veinID, true); + } + + private ChunkData(int amount, @Nullable GT_UO_Fluid vein, @Nullable String veinKey, boolean dirty) { + this.amount = amount; + this.vein = vein; + this.dirty = dirty; + if (vein == null) { + fluid = null; + this.veinKey = null; + veinHash = 0; + } else { + fluid = vein.getFluid(); + this.veinKey = veinKey; + veinHash = GT_UndergroundOilStore.hashes.computeIfAbsent(vein, GT_UndergroundOilStore::hash); + } + } + + /** + * The current fluid type. {@code null} if vein is generated to be empty. + */ + @Nullable + public Fluid getFluid() { + return fluid; + } + + /** + * Current fluid amount. Might be 0 if empty. Cannot be negative + */ + public int getAmount() { + return amount; + } + + public void setAmount(int amount) { + if (this.amount != amount) + dirty = true; + this.amount = Math.max(0, amount); + } + + public void changeAmount(int delta) { + if (delta != 0) + dirty = true; + this.amount = Math.max(0, amount - delta); + } + + @Nullable + public GT_UO_Fluid getVein() { + return vein; + } + + /** + * The vein ID. Might be null if generated to be empty. + */ + @Nullable + public String getVeinKey() { + return veinKey; + } + + public int getVeinHash() { + return veinHash; + } + + @Override + public boolean isSameAsDefault() { + return dirty; + } + } } diff --git a/src/main/java/gregtech/common/misc/GT_Command.java b/src/main/java/gregtech/common/misc/GT_Command.java index 13e26353d8..4f6f77ea70 100644 --- a/src/main/java/gregtech/common/misc/GT_Command.java +++ b/src/main/java/gregtech/common/misc/GT_Command.java @@ -61,7 +61,7 @@ public final class GT_Command extends CommandBase { } else if (test.equals("toggle")) { String test1 = ss[1].trim(); Stream.of("D1", "D2", "debugCleanroom", "debugDriller", "debugBlockPump", "debugBlockMiner", "debugWorldGen", "debugEntityCramming", - "debugOrevein", "debugSmallOres", "debugStones", "debugChunkloaders", "debugMulti") + "debugOrevein", "debugSmallOres", "debugStones", "debugChunkloaders", "debugMulti", "debugWorldData") .filter(s -> test1.isEmpty() || s.startsWith(test1)) .forEach(l::add); -- cgit From 9c933933f1d5e99fc618d2e6d5f07238ccb51ba3 Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Mon, 15 Nov 2021 17:40:00 -0700 Subject: Fully optimize PA check --- .../gregtech/api/util/GT_Single_Recipe_Check.java | 33 ++-- .../GT_Single_Recipe_Check_Processing_Array.java | 212 +++++++++++++++++++++ .../multi/GT_MetaTileEntity_ProcessingArray.java | 39 ++-- 3 files changed, 241 insertions(+), 43 deletions(-) create mode 100644 src/main/java/gregtech/api/util/GT_Single_Recipe_Check_Processing_Array.java (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Single_Recipe_Check.java b/src/main/java/gregtech/api/util/GT_Single_Recipe_Check.java index bcf205611e..469f2d64a1 100644 --- a/src/main/java/gregtech/api/util/GT_Single_Recipe_Check.java +++ b/src/main/java/gregtech/api/util/GT_Single_Recipe_Check.java @@ -17,14 +17,15 @@ import java.util.Map; /** Used by machines that are locked to a single recipe, for fast computation. */ public class GT_Single_Recipe_Check { - private final GT_MetaTileEntity_MultiBlockBase multiBlockBase; - private final GT_Recipe recipe; - private final ImmutableMap itemCost; - private final ImmutableMap fluidCost; - private final int totalItemCost; - private final int totalFluidCost; - - private GT_Single_Recipe_Check( + protected final GT_MetaTileEntity_MultiBlockBase multiBlockBase; + protected final GT_Recipe recipe; + protected final ImmutableMap itemCost; + protected final ImmutableMap fluidCost; + + protected final int totalItemCost; + protected final int totalFluidCost; + + protected GT_Single_Recipe_Check( GT_MetaTileEntity_MultiBlockBase multiBlockBase, GT_Recipe recipe, ImmutableMap itemCost, @@ -176,7 +177,7 @@ public class GT_Single_Recipe_Check { return true; } - private static Map buildItemMap( + protected static Map buildItemMap( GT_MetaTileEntity_MultiBlockBase multiBlockBase) { Map itemMap = new HashMap<>(); for (ItemStack itemStack : multiBlockBase.getStoredInputs()) { @@ -185,7 +186,7 @@ public class GT_Single_Recipe_Check { return itemMap; } - private static Map buildFluidMap( + protected static Map buildFluidMap( GT_MetaTileEntity_MultiBlockBase multiBlockBase) { Map fluidMap = new HashMap<>(); for (FluidStack fluidStack : multiBlockBase.getStoredFluids()) { @@ -256,9 +257,9 @@ public class GT_Single_Recipe_Check { } @AutoValue - abstract static class ItemId { + protected abstract static class ItemId { /** This method copies NBT, as it is mutable. */ - private static ItemId create(ItemStack itemStack) { + protected static ItemId create(ItemStack itemStack) { NBTTagCompound nbt = itemStack.getTagCompound(); if (nbt != null) { nbt = (NBTTagCompound) nbt.copy(); @@ -269,15 +270,15 @@ public class GT_Single_Recipe_Check { } /** This method does not copy NBT in order to save time. Make sure not to mutate it! */ - private static ItemId createNoCopy(ItemStack itemStack) { + protected static ItemId createNoCopy(ItemStack itemStack) { return new AutoValue_GT_Single_Recipe_Check_ItemId( itemStack.getItem(), itemStack.getItemDamage(), itemStack.getTagCompound()); } - abstract Item item(); - abstract int metaData(); + protected abstract Item item(); + protected abstract int metaData(); @Nullable - abstract NBTTagCompound nbt(); + protected abstract NBTTagCompound nbt(); } } diff --git a/src/main/java/gregtech/api/util/GT_Single_Recipe_Check_Processing_Array.java b/src/main/java/gregtech/api/util/GT_Single_Recipe_Check_Processing_Array.java new file mode 100644 index 0000000000..225e0bd723 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_Single_Recipe_Check_Processing_Array.java @@ -0,0 +1,212 @@ +package gregtech.api.util; + +import com.google.common.collect.ImmutableMap; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** Processing Array-specialized version of {@link gregtech.api.util.GT_Single_Recipe_Check}. */ +public class GT_Single_Recipe_Check_Processing_Array extends GT_Single_Recipe_Check { + protected final int recipeAmperage; + + /** + * The machine type that the locked recipe is for. + * We will not allow running with other machines. + */ + protected final ItemStack machineStack; + + protected GT_Single_Recipe_Check_Processing_Array( + GT_MetaTileEntity_MultiBlockBase multiBlockBase, + GT_Recipe recipe, + ImmutableMap itemCost, + ImmutableMap fluidCost, + int recipeAmperage, + ItemStack machineStack) { + super(multiBlockBase, recipe, itemCost, fluidCost); + + this.recipeAmperage = recipeAmperage; + this.machineStack = machineStack; + } + + public int getRecipeAmperage() { + return recipeAmperage; + } + + @Override + public boolean checkRecipeInputsSingleStack(boolean consumeInputs) { + throw new UnsupportedOperationException("Use checkRecipeInputs(boolean, int) instead."); + } + + @Override + public boolean checkRecipeInputs(boolean consumeInputs) { + throw new UnsupportedOperationException("Use checkRecipeInputs(boolean, int) instead."); + } + + /** Returns the number of parallel recipes, or 0 if recipe is not satisfied at all. */ + public int checkRecipeInputs(boolean consumeInputs, int maxParallel) { + if (!GT_Utility.areStacksEqual(machineStack, multiBlockBase.mInventory[1])) { + // Machine stack was modified. This is not allowed, so stop processing. + return 0; + } + int parallel = maxParallel; + + List items = null; + if (totalItemCost > 0) { + items = multiBlockBase.getStoredInputs(); + + Map itemMap = new HashMap<>(); + for (ItemStack itemStack : items) { + itemMap.merge(ItemId.createNoCopy(itemStack), itemStack.stackSize, Integer::sum); + } + + for (Map.Entry entry : itemCost.entrySet()) { + parallel = Math.min(parallel, itemMap.getOrDefault(entry.getKey(), 0) / entry.getValue()); + if (parallel <= 0) { + return 0; + } + } + } + + List fluids = null; + if (totalFluidCost > 0) { + fluids = multiBlockBase.getStoredFluids(); + + Map fluidMap = new HashMap<>(); + for (FluidStack fluidStack : fluids) { + fluidMap.merge(fluidStack.getFluid(), fluidStack.amount, Integer::sum); + } + + for (Map.Entry entry : fluidCost.entrySet()) { + parallel = Math.min(parallel, fluidMap.getOrDefault(entry.getKey(), 0) / entry.getValue()); + if (parallel <= 0) { + return 0; + } + } + } + + final int finalParallel = parallel; + if (consumeInputs) { + if (totalItemCost > 0) { + int remainingItemCost = totalItemCost * finalParallel; + Map runningItemCost = + itemCost.entrySet().stream() + .collect( + Collectors.toMap( + Map.Entry::getKey, + entry -> entry.getValue() * finalParallel)); + + for (ItemStack itemStack : items) { + ItemId key = ItemId.createNoCopy(itemStack); + int runningCost = runningItemCost.getOrDefault(key, 0); + int paid = Math.min(itemStack.stackSize, runningCost); + itemStack.stackSize -= paid; + runningItemCost.put(key, runningCost - paid); + + remainingItemCost -= paid; + if (remainingItemCost <= 0) { + break; + } + } + } + + if (totalFluidCost > 0) { + int remainingFluidCost = totalFluidCost * finalParallel; + Map runningFluidCost = + fluidCost.entrySet().stream() + .collect( + Collectors.toMap( + Map.Entry::getKey, + entry -> entry.getValue() * finalParallel)); + + for (FluidStack fluidStack : fluids) { + Fluid key = fluidStack.getFluid(); + int runningCost = runningFluidCost.getOrDefault(key, 0); + int paid = Math.min(fluidStack.amount, runningCost); + fluidStack.amount -= paid; + runningFluidCost.put(key, runningCost - paid); + + remainingFluidCost -= paid; + if (remainingFluidCost <= 0) { + break; + } + } + } + } + + return finalParallel; + } + + public static Builder processingArrayBuilder(GT_MetaTileEntity_MultiBlockBase multiBlockBase) { + return new Builder(multiBlockBase); + } + + public static final class Builder { + private final GT_MetaTileEntity_MultiBlockBase multiBlockBase; + + // In order to compute which items and fluids are consumed by the recipe, we compare the + // multi-block's items and fluids before and after inputs are consumed by the recipe. + private Map beforeItems; + private Map beforeFluids; + private Map afterItems; + private Map afterFluids; + + private GT_Recipe recipe; + private int recipeAmperage; + + private Builder(GT_MetaTileEntity_MultiBlockBase multiBlockBase) { + this.multiBlockBase = multiBlockBase; + } + + /** Call this before inputs are consumed by the recipe. */ + public Builder setBefore() { + beforeItems = buildItemMap(multiBlockBase); + beforeFluids = buildFluidMap(multiBlockBase); + return this; + } + + /** Call this after inputs are consumed by the recipe. */ + public Builder setAfter() { + afterItems = buildItemMap(multiBlockBase); + afterFluids = buildFluidMap(multiBlockBase); + return this; + } + + public Builder setRecipe(GT_Recipe recipe) { + this.recipe = recipe; + return this; + } + + public Builder setRecipeAmperage(int recipeAmperage) { + this.recipeAmperage = recipeAmperage; + return this; + } + + public GT_Single_Recipe_Check_Processing_Array build() { + ImmutableMap.Builder itemCostBuilder = ImmutableMap.builder(); + for (Map.Entry entry : beforeItems.entrySet()) { + int cost = entry.getValue() - afterItems.getOrDefault(entry.getKey(), 0); + if (cost > 0) { + itemCostBuilder.put(entry.getKey(), cost); + } + } + + ImmutableMap.Builder fluidCostBuilder = ImmutableMap.builder(); + for (Map.Entry entry : beforeFluids.entrySet()) { + int cost = entry.getValue() - afterFluids.getOrDefault(entry.getKey(), 0); + if (cost > 0) { + fluidCostBuilder.put(entry.getKey(), cost); + } + } + + return new GT_Single_Recipe_Check_Processing_Array( + multiBlockBase, recipe, itemCostBuilder.build(), fluidCostBuilder.build(), + recipeAmperage, multiBlockBase.mInventory[1].copy()); + } + } +} \ No newline at end of file diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java index d5649ab0e4..a48f63c60a 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java @@ -19,7 +19,7 @@ import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_ProcessingArray_Manager; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; -import gregtech.api.util.GT_Single_Recipe_Check; +import gregtech.api.util.GT_Single_Recipe_Check_Processing_Array; import gregtech.api.util.GT_Utility; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; @@ -51,12 +51,6 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_CubicMu private boolean mSeparate = false; private String mMachineName = ""; - /** If locked to a single recipe, the locked recipe's amperage. */ - private int mSingleRecipeAmperage; - - /** If locked to a single recipe, the single-block machines that were used to run that single recipe. */ - private ItemStack mSingleRecipeMachineStack; - public GT_MetaTileEntity_ProcessingArray(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); } @@ -245,24 +239,12 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_CubicMu } public boolean processLockedRecipe() { - if (!GT_Utility.areStacksEqual(mSingleRecipeMachineStack, mInventory[1])) { - // Machine stack was modified. This is not allowed, so stop processing. - return false; - } + GT_Single_Recipe_Check_Processing_Array tSingleRecipeCheck = (GT_Single_Recipe_Check_Processing_Array) mSingleRecipeCheck; int machines = Math.min(64, mInventory[1].stackSize << mMult); //Upped max Cap to 64 - int i = 0; - for (; i < machines; i++) { - // TODO we should create a separate single recipe check class just for PAs. - // This class can memorize the amperage and machine stack for us, as well as compute - // the max number of runs in a single iteration over the inputs, rather than requiring - // one iteration per machine in the stack. But let's do that after we've tested this. - if (!mSingleRecipeCheck.checkRecipeInputs(true)) { - break; - } - } + int parallel = tSingleRecipeCheck.checkRecipeInputs(true, machines); - return processRecipeOutputs(mSingleRecipeCheck.getRecipe(), mSingleRecipeAmperage, i); + return processRecipeOutputs(tSingleRecipeCheck.getRecipe(), tSingleRecipeCheck.getRecipeAmperage(), parallel); } public boolean processRecipe(ItemStack[] tInputs, FluidStack[] tFluids, GT_Recipe.GT_Recipe_Map map) { @@ -273,11 +255,11 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_CubicMu !isValidForLowGravity(tRecipe, getBaseMetaTileEntity().getWorld().provider.dimensionId)) return false; - GT_Single_Recipe_Check.Builder tSingleRecipeCheckBuilder = null; + GT_Single_Recipe_Check_Processing_Array.Builder tSingleRecipeCheckBuilder = null; if (mLockedToSingleRecipe) { // We're locked to a single recipe, but haven't built the recipe checker yet. // Build the checker on next successful recipe. - tSingleRecipeCheckBuilder = GT_Single_Recipe_Check.builder(this).setBefore(); + tSingleRecipeCheckBuilder = GT_Single_Recipe_Check_Processing_Array.processingArrayBuilder(this).setBefore(); } boolean recipeLocked = false; @@ -289,9 +271,12 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_CubicMu break; } else if (mLockedToSingleRecipe && !recipeLocked) { // We want to lock to a single run of the recipe. - mSingleRecipeCheck = tSingleRecipeCheckBuilder.setAfter().setRecipe(tRecipe).build(); - mSingleRecipeAmperage = map.mAmperage; - mSingleRecipeMachineStack = mInventory[1].copy(); + mSingleRecipeCheck = + tSingleRecipeCheckBuilder + .setAfter() + .setRecipe(tRecipe) + .setRecipeAmperage(map.mAmperage) + .build(); recipeLocked = true; } } -- cgit From 53e01ab8e1a7a75453f06f7fea5f5c76c09d03a3 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Tue, 16 Nov 2021 13:02:46 +0000 Subject: Implemented groundwork for fixing Data Stick exploiting. --- .../gregtech/api/util/GT_AssemblyLineUtils.java | 374 +++++++++++++++++++++ 1 file changed, 374 insertions(+) create mode 100644 src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java b/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java new file mode 100644 index 0000000000..17a7583ebe --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java @@ -0,0 +1,374 @@ +package gregtech.api.util; + +import static gregtech.GT_Mod.GT_FML_LOGGER; + +import cpw.mods.fml.common.FMLCommonHandler; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.ItemList; +import gregtech.api.util.GT_Recipe.GT_Recipe_AssemblyLine; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import net.minecraftforge.fluids.FluidStack; +import scala.actors.threadpool.Arrays; + +public class GT_AssemblyLineUtils { + + /** + * Checks the DataStick for deprecated/invalid recipes, updating them as required. + * @param aDataStick - The DataStick to process + * @return Is this DataStick now valid with a current recipe? + */ + public static boolean processDataStick(ItemStack aDataStick) { + if (!isItemDataStick(aDataStick)) { + return false; + } + if (doesDataStickNeedUpdate(aDataStick)) { + ItemStack aStickOutput = getDataStickOutput(aDataStick); + if (aStickOutput != null) { + GT_Recipe_AssemblyLine aIntendedRecipe = findAssemblyLineRecipeByOutput(aStickOutput); + if (aIntendedRecipe != null) { + return setAssemblyLineRecipeOnDataStick(aDataStick, aIntendedRecipe); + } + } + return false; + } + return true; + } + + /** + * Finds an Assembly Line recipe from a DataStick. + * @param aDataStick - The DataStick to check. + * @return The GT_Recipe_AssemblyLine recipe contained on the DataStick, if any. + */ + public static GT_Recipe_AssemblyLine findAssemblyLineRecipeFromDataStick(ItemStack aDataStick) { + if (!isItemDataStick(aDataStick)) { + return null; + } + ItemStack[] aInputs = new ItemStack[15]; + ItemStack[] aOutputs = new ItemStack[1]; + FluidStack[] aFluidInputs = new FluidStack[4]; + boolean aFoundRecipe = false; + + NBTTagCompound aTag = aDataStick.getTagCompound(); + if (aTag == null) { + return null; + } + + for (int i = 0; i < 15; i++) { + int count = aTag.getInteger("a" + i); + if (!aTag.hasKey("" + i) && count <= 0) { + continue; + } + + boolean flag = true; + if (count > 0) { + for (int j = 0; j < count; j++) { + aInputs[i] = GT_Utility.loadItem(aTag, "a" + i + ":" + j); + if (aInputs[i] == null) { + continue; + } + if (GT_Values.D1) { + GT_FML_LOGGER.info("Item " + i + " : " + aInputs[i].getUnlocalizedName()); + } + flag = false; + break; + } + } + if (flag) { + aInputs[i] = GT_Utility.loadItem(aTag, "" + i); + if (aInputs[i] == null) { + flag = false; + continue; + } + if (GT_Values.D1) { + GT_FML_LOGGER.info("Item " + i + " : " + aInputs[i].getUnlocalizedName()); + } + flag = false; + } + if (GT_Values.D1) { + GT_FML_LOGGER.info(i + (flag ? " not accepted" : " accepted")); + } + } + + if (GT_Values.D1) GT_FML_LOGGER.info("All Items done, start fluid check"); + for (int i = 0; i < 4; i++) { + if (!aTag.hasKey("f" + i)) continue; + aFluidInputs[i] = GT_Utility.loadFluid(aTag, "f" + i); + if (aFluidInputs[i] == null) continue; + if (GT_Values.D1) { + GT_FML_LOGGER.info("Fluid " + i + " " + aFluidInputs[i].getUnlocalizedName()); + } + if (GT_Values.D1) { + GT_FML_LOGGER.info(i + " accepted"); + } + } + + if (GT_Values.D1) { + GT_FML_LOGGER.info("Input accepted, check other values"); + } + aOutputs = new ItemStack[]{GT_Utility.loadItem(aTag, "output")}; + if (!aTag.hasKey("output") || !aTag.hasKey("time") || aTag.getInteger("time") <= 0 || !aTag.hasKey("eu") || aOutputs[0] == null || !GT_Utility.isStackValid(aOutputs[0])) { + return null; + } + if (GT_Values.D1) { + GT_FML_LOGGER.info("Find Data Stick recipe"); + } + aFoundRecipe = true; + + if (aFoundRecipe) { + int aTime = aTag.getInteger("time"); + int aEU = aTag.getInteger("eu"); + for (GT_Recipe_AssemblyLine aRecipe : GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes) { + if (aRecipe.mEUt == aEU && aRecipe.mDuration == aTime) { + if (GT_Utility.areStacksEqual(aOutputs[0], aRecipe.mOutput, true)) { + if (Arrays.equals(aRecipe.mInputs, aInputs) && Arrays.equals(aRecipe.mFluidInputs, aFluidInputs)) { + return aRecipe; + } + } + } + } + } + return null; + } + + + /** + * Finds a GT_Recipe_AssemblyLine based on the expected output ItemStack. + * @param aOutput - The Output of a GT_Recipe_AssemblyLine. + * @return First found GT_Recipe_AssemblyLine with matching output. + */ + public static GT_Recipe_AssemblyLine findAssemblyLineRecipeByOutput(ItemStack aOutput) { + for (GT_Recipe_AssemblyLine aRecipe : GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes) { + ItemStack aRecipeOutput = aRecipe.mOutput; + if (GT_Utility.areStacksEqual(aRecipeOutput, aOutput)) { + return aRecipe; + } + } + return null; + } + + + /** + * Get the Output ItemStack from a Data Stick. + * @param aDataStick - The Data Stick to check. + * @return Output ItemStack contained on the Data Stick. + */ + public static ItemStack getDataStickOutput(ItemStack aDataStick) { + if (doesDataStickHaveOutput(aDataStick)) { + ItemStack aOutput = GT_Utility.loadItem(aDataStick.getTagCompound(), "output"); + return aOutput; + } + return null; + } + + /** + * @param aDataStick - The Data Stick to check. + * @return Does this Data Stick have a valid output ItemStack? + */ + public static boolean doesDataStickHaveOutput(ItemStack aDataStick) { + if (isItemDataStick(aDataStick) && aDataStick.hasTagCompound() && aDataStick.getTagCompound().hasKey("output")) { + return true; + } + return false; + } + + /** + * @param aDataStick - The Data Stick to check. + * @return Does this Data Stick need recipe data updated. + */ + public static boolean doesDataStickNeedUpdate(ItemStack aDataStick) { + if (isItemDataStick(aDataStick) && doesDataStickHaveRecipeHash(aDataStick)) { + String aStickHash = getHashFromDataStack(aDataStick); + if (isValidHash(aStickHash) && doesDataStickHaveOutput(aDataStick)) { + ItemStack aStickOutput = getDataStickOutput(aDataStick); + GT_Recipe_AssemblyLine aIntendedRecipe = findAssemblyLineRecipeByOutput(aStickOutput); + if (aStickHash.equals(generateRecipeHash(aIntendedRecipe))) { + return false; + } + } + } + return true; + } + + /** + * @param aDataStick - The Data Stick to check. + * @return Does this have a Recipe Hash String at all? + */ + public static boolean doesDataStickHaveRecipeHash(ItemStack aDataStick) { + if (isItemDataStick(aDataStick) && aDataStick.hasTagCompound()) { + NBTTagCompound aNBT = aDataStick.getTagCompound(); + if (aNBT.hasKey("Data.Recipe.Hash")) { + return true; + } + } + return false; + } + + /** + * @param aDataStick - The Data Stick to procces. + * @return The stored Recipe Hash String on the Data Stick, will return an invalid Hash if one is not found.

+ * Check with isValidHash().

+ * Will not return Null. + */ + public static String getHashFromDataStack(ItemStack aDataStick) { + if (isItemDataStick(aDataStick) && aDataStick.hasTagCompound()) { + NBTTagCompound aNBT = aDataStick.getTagCompound(); + if (aNBT.hasKey("Data.Recipe.Hash")) { + return aNBT.getString("Data.Recipe.Hash"); + + } + } + return "Invalid.Recipe.Hash"; + } + + /** + * + * @param aDataStick - The Data Stick to update. + * @param aRecipeHash - The Recipe Hash String to update with. + * @return Did we update the Recipe Hash String on the Data Stick? + */ + public static boolean writeRecipeHashToDataStick(ItemStack aDataStick, String aRecipeHash) { + if (isItemDataStick(aDataStick) && aDataStick.hasTagCompound()) { + NBTTagCompound aNBT = aDataStick.getTagCompound(); + aNBT.setString("Data.Recipe.Hash", aRecipeHash); + aDataStick.setTagCompound(aNBT); + return true; + } + return false; + } + + /** + * @param aRecipe - The recipe to generate a Recipe Hash String from. + * @return The Recipe Hash String. + */ + public static String generateRecipeHash(GT_Recipe_AssemblyLine aRecipe) { + String aHash = "Invalid.Recipe.Hash"; + if (aRecipe != null) { + aHash = "Hash."+aRecipe.hashCode(); + } + return aHash; + } + + /** + * @param aHash - Recipe hash String, may be null but will just be treated as invalid. + * @return Is this Recipe Hash String valid? + */ + public static boolean isValidHash(String aHash) { + if (aHash != null && aHash.length() > 0) { + if (!aHash.equals("Invalid.Recipe.Hash") && aHash.contains("Hash.")) { + return true; + } + } + return false; + } + + /** + * @param aStack - The ItemStack to check. + * @return Is this ItemStack a Data Stick? + */ + public static boolean isItemDataStick(ItemStack aStack) { + return GT_Utility.isStackValid(aStack) && ItemList.Tool_DataStick.isStackEqual(aStack, false, true); + } + + /** + * + * @param aDataStick - The Data Stick to update. + * @param aNewRecipe - The New GT_Recipe_AssemblyLine recipe to update it with. + * @return Did we set the new recipe data & Recipe Hash String on the Data Stick? + */ + public static boolean setAssemblyLineRecipeOnDataStick(ItemStack aDataStick, GT_Recipe_AssemblyLine aNewRecipe) { + if (isItemDataStick(aDataStick)) { + String s = aNewRecipe.mOutput.getDisplayName(); + if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { + s = GT_Assemblyline_Server.lServerNames.get(aNewRecipe.mOutput.getDisplayName()); + if (s == null) + s = aNewRecipe.mOutput.getDisplayName(); + } + + //remove possible old NBTTagCompound + aDataStick.setTagCompound(new NBTTagCompound()); + GT_Utility.ItemNBT.setBookTitle(aDataStick, s + " Construction Data"); + + NBTTagCompound tNBT = aDataStick.getTagCompound(); + if (tNBT == null) { + tNBT = new NBTTagCompound(); + } + + tNBT.setTag("output", aNewRecipe.mOutput.writeToNBT(new NBTTagCompound())); + tNBT.setInteger("time", aNewRecipe.mDuration); + tNBT.setInteger("eu", aNewRecipe.mEUt); + for (int i = 0; i < aNewRecipe.mInputs.length; i++) { + tNBT.setTag("" + i, aNewRecipe.mInputs[i].writeToNBT(new NBTTagCompound())); + } + for (int i = 0; i < aNewRecipe.mOreDictAlt.length; i++) { + if (aNewRecipe.mOreDictAlt[i] != null && aNewRecipe.mOreDictAlt[i].length > 0) { + tNBT.setInteger("a" + i, aNewRecipe.mOreDictAlt[i].length); + for (int j = 0; j < aNewRecipe.mOreDictAlt[i].length; j++) { + tNBT.setTag("a" + i + ":" + j, aNewRecipe.mOreDictAlt[i][j].writeToNBT(new NBTTagCompound())); + } + } + } + for (int i = 0; i < aNewRecipe.mFluidInputs.length; i++) { + tNBT.setTag("f" + i, aNewRecipe.mFluidInputs[i].writeToNBT(new NBTTagCompound())); + } + tNBT.setString("author", "Assembling Line Recipe Generator"); + NBTTagList tNBTList = new NBTTagList(); + s = aNewRecipe.mOutput.getDisplayName(); + if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { + s = GT_Assemblyline_Server.lServerNames.get(aNewRecipe.mOutput.getDisplayName()); + if (s == null) + s = aNewRecipe.mOutput.getDisplayName(); + } + tNBTList.appendTag(new NBTTagString("Construction plan for " + aNewRecipe.mOutput.stackSize + " " + s + ". Needed EU/t: " + aNewRecipe.mEUt + " Production time: " + (aNewRecipe.mDuration / 20))); + for (int i = 0; i < aNewRecipe.mInputs.length; i++) { + if (aNewRecipe.mOreDictAlt[i] != null) { + int count = 0; + StringBuilder tBuilder = new StringBuilder("Input Bus " + (i + 1) + ": "); + for (ItemStack tStack : aNewRecipe.mOreDictAlt[i]) { + if (tStack != null) { + s = tStack.getDisplayName(); + if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { + s = GT_Assemblyline_Server.lServerNames.get(tStack.getDisplayName()); + if (s == null) + s = tStack.getDisplayName(); + } + + + tBuilder.append(count == 0 ? "" : "\nOr ").append(tStack.stackSize).append(" ").append(s); + count++; + } + } + if (count > 0) tNBTList.appendTag(new NBTTagString(tBuilder.toString())); + } else if (aNewRecipe.mInputs[i] != null) { + s = aNewRecipe.mInputs[i].getDisplayName(); + if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { + s = GT_Assemblyline_Server.lServerNames.get(aNewRecipe.mInputs[i].getDisplayName()); + if (s == null) + s = aNewRecipe.mInputs[i].getDisplayName(); + } + tNBTList.appendTag(new NBTTagString("Input Bus " + (i + 1) + ": " + aNewRecipe.mInputs[i].stackSize + " " + s)); + } + } + for (int i = 0; i < aNewRecipe.mFluidInputs.length; i++) { + if (aNewRecipe.mFluidInputs[i] != null) { + s = aNewRecipe.mFluidInputs[i].getLocalizedName(); + if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { + s = GT_Assemblyline_Server.lServerNames.get(aNewRecipe.mFluidInputs[i].getLocalizedName()); + if (s == null) + s = aNewRecipe.mFluidInputs[i].getLocalizedName(); + } + tNBTList.appendTag(new NBTTagString("Input Hatch " + (i + 1) + ": " + aNewRecipe.mFluidInputs[i].amount + "L " + s)); + } + } + tNBT.setTag("pages", tNBTList); + aDataStick.setTagCompound(tNBT); + // Set recipe hash + writeRecipeHashToDataStick(aDataStick, generateRecipeHash(aNewRecipe)); + return true; + } + return false; + } + +} -- cgit From 4e2689d152f50a90e8c32c1229038d6e75e288ce Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Tue, 16 Nov 2021 13:24:56 +0000 Subject: Cleaned up the class a little. Added Caching to Assembly Line output lookups. --- .../gregtech/api/util/GT_AssemblyLineUtils.java | 107 ++++++++++++--------- 1 file changed, 64 insertions(+), 43 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java b/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java index 17a7583ebe..b423bfa91e 100644 --- a/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java +++ b/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java @@ -2,9 +2,12 @@ package gregtech.api.util; import static gregtech.GT_Mod.GT_FML_LOGGER; +import java.util.HashMap; + import cpw.mods.fml.common.FMLCommonHandler; import gregtech.api.enums.GT_Values; import gregtech.api.enums.ItemList; +import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.GT_Recipe.GT_Recipe_AssemblyLine; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -15,6 +18,11 @@ import scala.actors.threadpool.Arrays; public class GT_AssemblyLineUtils { + /** + * A cache of + */ + private static HashMap sRecipeCacheByOutput = new HashMap(); + /** * Checks the DataStick for deprecated/invalid recipes, updating them as required. * @param aDataStick - The DataStick to process @@ -140,27 +148,60 @@ public class GT_AssemblyLineUtils { * @return First found GT_Recipe_AssemblyLine with matching output. */ public static GT_Recipe_AssemblyLine findAssemblyLineRecipeByOutput(ItemStack aOutput) { + if (aOutput == null) { + return null; + } + + // Check the cache + GT_ItemStack aCacheStack = new GT_ItemStack(aOutput); + GT_Recipe_AssemblyLine aRecipeFromCache = sRecipeCacheByOutput.get(aCacheStack); + if (aRecipeFromCache != null) { + return aRecipeFromCache; + } + + // Iterate all recipes and return the first matching based on Output. for (GT_Recipe_AssemblyLine aRecipe : GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes) { ItemStack aRecipeOutput = aRecipe.mOutput; if (GT_Utility.areStacksEqual(aRecipeOutput, aOutput)) { + // Cache it to prevent future iterations of all recipes + sRecipeCacheByOutput.put(aCacheStack, aRecipe); return aRecipe; } } return null; } + /** + * @param aRecipe - The recipe to generate a Recipe Hash String from. + * @return The Recipe Hash String. + */ + public static String generateRecipeHash(GT_Recipe_AssemblyLine aRecipe) { + String aHash = "Invalid.Recipe.Hash"; + if (aRecipe != null) { + aHash = "Hash."+aRecipe.hashCode(); + } + return aHash; + } /** - * Get the Output ItemStack from a Data Stick. - * @param aDataStick - The Data Stick to check. - * @return Output ItemStack contained on the Data Stick. + * @param aHash - Recipe hash String, may be null but will just be treated as invalid. + * @return Is this Recipe Hash String valid? */ - public static ItemStack getDataStickOutput(ItemStack aDataStick) { - if (doesDataStickHaveOutput(aDataStick)) { - ItemStack aOutput = GT_Utility.loadItem(aDataStick.getTagCompound(), "output"); - return aOutput; + public static boolean isValidHash(String aHash) { + if (aHash != null && aHash.length() > 0) { + if (!aHash.equals("Invalid.Recipe.Hash") && aHash.contains("Hash.")) { + return true; + } } - return null; + return false; + } + + /** + * @param aStack - The ItemStack to check. + * @return Is this ItemStack a Data Stick? + */ + public static boolean isItemDataStick(ItemStack aStack) { + return GT_Utility.isStackValid(aStack) && ItemList.Tool_DataStick.isStackEqual(aStack, false, true); } /** @@ -206,6 +247,19 @@ public class GT_AssemblyLineUtils { return false; } + /** + * Get the Output ItemStack from a Data Stick. + * @param aDataStick - The Data Stick to check. + * @return Output ItemStack contained on the Data Stick. + */ + public static ItemStack getDataStickOutput(ItemStack aDataStick) { + if (doesDataStickHaveOutput(aDataStick)) { + ItemStack aOutput = GT_Utility.loadItem(aDataStick.getTagCompound(), "output"); + return aOutput; + } + return null; + } + /** * @param aDataStick - The Data Stick to procces. * @return The stored Recipe Hash String on the Data Stick, will return an invalid Hash if one is not found.

@@ -229,7 +283,7 @@ public class GT_AssemblyLineUtils { * @param aRecipeHash - The Recipe Hash String to update with. * @return Did we update the Recipe Hash String on the Data Stick? */ - public static boolean writeRecipeHashToDataStick(ItemStack aDataStick, String aRecipeHash) { + public static boolean setRecipeHashOnDataStick(ItemStack aDataStick, String aRecipeHash) { if (isItemDataStick(aDataStick) && aDataStick.hasTagCompound()) { NBTTagCompound aNBT = aDataStick.getTagCompound(); aNBT.setString("Data.Recipe.Hash", aRecipeHash); @@ -239,39 +293,6 @@ public class GT_AssemblyLineUtils { return false; } - /** - * @param aRecipe - The recipe to generate a Recipe Hash String from. - * @return The Recipe Hash String. - */ - public static String generateRecipeHash(GT_Recipe_AssemblyLine aRecipe) { - String aHash = "Invalid.Recipe.Hash"; - if (aRecipe != null) { - aHash = "Hash."+aRecipe.hashCode(); - } - return aHash; - } - - /** - * @param aHash - Recipe hash String, may be null but will just be treated as invalid. - * @return Is this Recipe Hash String valid? - */ - public static boolean isValidHash(String aHash) { - if (aHash != null && aHash.length() > 0) { - if (!aHash.equals("Invalid.Recipe.Hash") && aHash.contains("Hash.")) { - return true; - } - } - return false; - } - - /** - * @param aStack - The ItemStack to check. - * @return Is this ItemStack a Data Stick? - */ - public static boolean isItemDataStick(ItemStack aStack) { - return GT_Utility.isStackValid(aStack) && ItemList.Tool_DataStick.isStackEqual(aStack, false, true); - } - /** * * @param aDataStick - The Data Stick to update. @@ -365,7 +386,7 @@ public class GT_AssemblyLineUtils { tNBT.setTag("pages", tNBTList); aDataStick.setTagCompound(tNBT); // Set recipe hash - writeRecipeHashToDataStick(aDataStick, generateRecipeHash(aNewRecipe)); + setRecipeHashOnDataStick(aDataStick, generateRecipeHash(aNewRecipe)); return true; } return false; -- cgit From 670b3044c2f8d55af0b2f98f5578a78d7567a837 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Tue, 16 Nov 2021 13:32:24 +0000 Subject: Improved caching. --- .../gregtech/api/util/GT_AssemblyLineUtils.java | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java b/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java index b423bfa91e..bf10b93ce8 100644 --- a/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java +++ b/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java @@ -19,9 +19,13 @@ import scala.actors.threadpool.Arrays; public class GT_AssemblyLineUtils { /** - * A cache of + * A cache of Recipes using the Output as Key. */ private static HashMap sRecipeCacheByOutput = new HashMap(); + /** + * A cache of Recipes using the Recipe Hash String as Key. + */ + private static HashMap sRecipeCacheByRecipeHash = new HashMap(); /** * Checks the DataStick for deprecated/invalid recipes, updating them as required. @@ -63,6 +67,14 @@ public class GT_AssemblyLineUtils { if (aTag == null) { return null; } + + //Get From Cache + if (doesDataStickHaveRecipeHash(aDataStick)) { + GT_Recipe_AssemblyLine aRecipeFromCache = sRecipeCacheByRecipeHash.get(getHashFromDataStack(aDataStick)); + if (aRecipeFromCache != null) { + return aRecipeFromCache; + } + } for (int i = 0; i < 15; i++) { int count = aTag.getInteger("a" + i); @@ -131,7 +143,11 @@ public class GT_AssemblyLineUtils { for (GT_Recipe_AssemblyLine aRecipe : GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes) { if (aRecipe.mEUt == aEU && aRecipe.mDuration == aTime) { if (GT_Utility.areStacksEqual(aOutputs[0], aRecipe.mOutput, true)) { - if (Arrays.equals(aRecipe.mInputs, aInputs) && Arrays.equals(aRecipe.mFluidInputs, aFluidInputs)) { + if (Arrays.equals(aRecipe.mInputs, aInputs) && Arrays.equals(aRecipe.mFluidInputs, aFluidInputs)) { + // Cache it + String aRecipeHash = generateRecipeHash(aRecipe); + sRecipeCacheByRecipeHash.put(aRecipeHash, aRecipe); + sRecipeCacheByOutput.put(new GT_ItemStack(aRecipe.mOutput), aRecipe); return aRecipe; } } @@ -165,6 +181,7 @@ public class GT_AssemblyLineUtils { if (GT_Utility.areStacksEqual(aRecipeOutput, aOutput)) { // Cache it to prevent future iterations of all recipes sRecipeCacheByOutput.put(aCacheStack, aRecipe); + sRecipeCacheByRecipeHash.put(generateRecipeHash(aRecipe), aRecipe); return aRecipe; } } -- cgit From a40b1e3b79709baa60ae2ced9ab57279c065cb7d Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Tue, 16 Nov 2021 17:33:54 +0000 Subject: Implemented use of GT_AssemblyLineUtils for the Scanner and Assembly line. Cleaned up Assembly Line recipe handling code. Cleaned up Scanner AL recipe handling code. Cleaned up GT_AssemblyLineUtils a touch and added a little more debugging. (Turn D1 on in GT) --- .../gregtech/api/util/GT_AssemblyLineUtils.java | 86 ++++++--- .../machines/basic/GT_MetaTileEntity_Scanner.java | 97 ++-------- .../multi/GT_MetaTileEntity_AssemblyLine.java | 207 ++++++++++----------- 3 files changed, 167 insertions(+), 223 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java b/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java index bf10b93ce8..f35f1962d1 100644 --- a/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java +++ b/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java @@ -27,6 +27,8 @@ public class GT_AssemblyLineUtils { */ private static HashMap sRecipeCacheByRecipeHash = new HashMap(); + + /** * Checks the DataStick for deprecated/invalid recipes, updating them as required. * @param aDataStick - The DataStick to process @@ -49,25 +51,35 @@ public class GT_AssemblyLineUtils { return true; } + /** * Finds an Assembly Line recipe from a DataStick. * @param aDataStick - The DataStick to check. * @return The GT_Recipe_AssemblyLine recipe contained on the DataStick, if any. */ public static GT_Recipe_AssemblyLine findAssemblyLineRecipeFromDataStick(ItemStack aDataStick) { + return findAssemblyLineRecipeFromDataStick(aDataStick, false); + } + + /** + * Finds an Assembly Line recipe from a DataStick. + * @param aDataStick - The DataStick to check. + * @param aReturnBuiltRecipe - Do we return a GT_Recipe_AssemblyLine built from the data on the Data Stick instead of searching the Recipe Map? + * @return The GT_Recipe_AssemblyLine recipe contained on the DataStick, if any. + */ + public static GT_Recipe_AssemblyLine findAssemblyLineRecipeFromDataStick(ItemStack aDataStick, boolean aReturnBuiltRecipe) { if (!isItemDataStick(aDataStick)) { return null; } ItemStack[] aInputs = new ItemStack[15]; ItemStack[] aOutputs = new ItemStack[1]; FluidStack[] aFluidInputs = new FluidStack[4]; - boolean aFoundRecipe = false; NBTTagCompound aTag = aDataStick.getTagCompound(); if (aTag == null) { return null; } - + //Get From Cache if (doesDataStickHaveRecipeHash(aDataStick)) { GT_Recipe_AssemblyLine aRecipeFromCache = sRecipeCacheByRecipeHash.get(getHashFromDataStack(aDataStick)); @@ -112,7 +124,9 @@ public class GT_AssemblyLineUtils { } } - if (GT_Values.D1) GT_FML_LOGGER.info("All Items done, start fluid check"); + if (GT_Values.D1) { + GT_FML_LOGGER.info("All Items done, start fluid check"); + } for (int i = 0; i < 4; i++) { if (!aTag.hasKey("f" + i)) continue; aFluidInputs[i] = GT_Utility.loadFluid(aTag, "f" + i); @@ -124,35 +138,36 @@ public class GT_AssemblyLineUtils { GT_FML_LOGGER.info(i + " accepted"); } } - - if (GT_Values.D1) { - GT_FML_LOGGER.info("Input accepted, check other values"); - } aOutputs = new ItemStack[]{GT_Utility.loadItem(aTag, "output")}; if (!aTag.hasKey("output") || !aTag.hasKey("time") || aTag.getInteger("time") <= 0 || !aTag.hasKey("eu") || aOutputs[0] == null || !GT_Utility.isStackValid(aOutputs[0])) { return null; } if (GT_Values.D1) { - GT_FML_LOGGER.info("Find Data Stick recipe"); + GT_FML_LOGGER.info("Found Data Stick recipe"); } - aFoundRecipe = true; - - if (aFoundRecipe) { - int aTime = aTag.getInteger("time"); - int aEU = aTag.getInteger("eu"); - for (GT_Recipe_AssemblyLine aRecipe : GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes) { - if (aRecipe.mEUt == aEU && aRecipe.mDuration == aTime) { - if (GT_Utility.areStacksEqual(aOutputs[0], aRecipe.mOutput, true)) { - if (Arrays.equals(aRecipe.mInputs, aInputs) && Arrays.equals(aRecipe.mFluidInputs, aFluidInputs)) { - // Cache it - String aRecipeHash = generateRecipeHash(aRecipe); - sRecipeCacheByRecipeHash.put(aRecipeHash, aRecipe); - sRecipeCacheByOutput.put(new GT_ItemStack(aRecipe.mOutput), aRecipe); - return aRecipe; - } + + int aTime = aTag.getInteger("time"); + int aEU = aTag.getInteger("eu"); + + // Try build a recipe instance + if (aReturnBuiltRecipe) { + GT_Recipe_AssemblyLine aBuiltRecipe = new GT_Recipe_AssemblyLine(null, 0, aInputs, aFluidInputs, aOutputs[0], aTime, aEU); + return aBuiltRecipe; + } + + + for (GT_Recipe_AssemblyLine aRecipe : GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes) { + if (aRecipe.mEUt == aEU && aRecipe.mDuration == aTime) { + if (GT_Utility.areStacksEqual(aOutputs[0], aRecipe.mOutput, true)) { + if (Arrays.equals(aRecipe.mInputs, aInputs) && Arrays.equals(aRecipe.mFluidInputs, aFluidInputs)) { + // Cache it + String aRecipeHash = generateRecipeHash(aRecipe); + sRecipeCacheByRecipeHash.put(aRecipeHash, aRecipe); + sRecipeCacheByOutput.put(new GT_ItemStack(aRecipe.mOutput), aRecipe); + return aRecipe; } } - } + } } return null; } @@ -167,14 +182,14 @@ public class GT_AssemblyLineUtils { if (aOutput == null) { return null; } - + // Check the cache GT_ItemStack aCacheStack = new GT_ItemStack(aOutput); GT_Recipe_AssemblyLine aRecipeFromCache = sRecipeCacheByOutput.get(aCacheStack); if (aRecipeFromCache != null) { return aRecipeFromCache; } - + // Iterate all recipes and return the first matching based on Output. for (GT_Recipe_AssemblyLine aRecipe : GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes) { ItemStack aRecipeOutput = aRecipe.mOutput; @@ -321,13 +336,26 @@ public class GT_AssemblyLineUtils { String s = aNewRecipe.mOutput.getDisplayName(); if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { s = GT_Assemblyline_Server.lServerNames.get(aNewRecipe.mOutput.getDisplayName()); - if (s == null) + if (s == null) { s = aNewRecipe.mOutput.getDisplayName(); + } + } + + String aHash = generateRecipeHash(aNewRecipe); + if (GT_Values.D1) { + GT_Recipe_AssemblyLine aOldRecipe = findAssemblyLineRecipeFromDataStick(aDataStick, true); + GT_FML_LOGGER.info("Updating data stick: "+aDataStick.getDisplayName()+" | Old Recipe Hash: "+generateRecipeHash(aOldRecipe)+", New Recipe Hash: "+aHash); } + //remove possible old NBTTagCompound aDataStick.setTagCompound(new NBTTagCompound()); - GT_Utility.ItemNBT.setBookTitle(aDataStick, s + " Construction Data"); + if (GT_Values.D1) { + GT_Utility.ItemNBT.setBookTitle(aDataStick, s + " Construction Data ("+aHash+")"); + } + else { + GT_Utility.ItemNBT.setBookTitle(aDataStick, s + " Construction Data"); + } NBTTagCompound tNBT = aDataStick.getTagCompound(); if (tNBT == null) { @@ -403,7 +431,7 @@ public class GT_AssemblyLineUtils { tNBT.setTag("pages", tNBTList); aDataStick.setTagCompound(tNBT); // Set recipe hash - setRecipeHashOnDataStick(aDataStick, generateRecipeHash(aNewRecipe)); + setRecipeHashOnDataStick(aDataStick, aHash); return true; } return false; diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Scanner.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Scanner.java index 48eeb6c8fb..1573c951eb 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Scanner.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Scanner.java @@ -254,6 +254,7 @@ public class GT_MetaTileEntity_Scanner extends GT_MetaTileEntity_BasicMachine { if (failScanner) { return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; } + String s = tRecipe.mOutput.getDisplayName(); if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { @@ -262,95 +263,19 @@ public class GT_MetaTileEntity_Scanner extends GT_MetaTileEntity_BasicMachine { s = tRecipe.mOutput.getDisplayName(); } this.mOutputItems[0] = GT_Utility.copyAmount(1L, getSpecialSlot()); - //remove possible old NBTTagCompound - this.mOutputItems[0].setTagCompound(new NBTTagCompound()); - GT_Utility.ItemNBT.setBookTitle(this.mOutputItems[0], s + " Construction Data"); - - NBTTagCompound tNBT = this.mOutputItems[0].getTagCompound(); - if (tNBT == null) { - tNBT = new NBTTagCompound(); - } - - tNBT.setTag("output", tRecipe.mOutput.writeToNBT(new NBTTagCompound())); - tNBT.setInteger("time", tRecipe.mDuration); - tNBT.setInteger("eu", tRecipe.mEUt); - for (int i = 0; i < tRecipe.mInputs.length; i++) { - tNBT.setTag("" + i, tRecipe.mInputs[i].writeToNBT(new NBTTagCompound())); - } - for (int i = 0; i < tRecipe.mOreDictAlt.length; i++) { - if (tRecipe.mOreDictAlt[i] != null && tRecipe.mOreDictAlt[i].length > 0) { - tNBT.setInteger("a" + i, tRecipe.mOreDictAlt[i].length); - for (int j = 0; j < tRecipe.mOreDictAlt[i].length; j++) { - tNBT.setTag("a" + i + ":" + j, tRecipe.mOreDictAlt[i][j].writeToNBT(new NBTTagCompound())); - } - } - } - for (int i = 0; i < tRecipe.mFluidInputs.length; i++) { - tNBT.setTag("f" + i, tRecipe.mFluidInputs[i].writeToNBT(new NBTTagCompound())); - } - tNBT.setString("author", "Assembling Line Recipe Generator"); - NBTTagList tNBTList = new NBTTagList(); - s = tRecipe.mOutput.getDisplayName(); - if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { - s = GT_Assemblyline_Server.lServerNames.get(tRecipe.mOutput.getDisplayName()); - if (s == null) - s = tRecipe.mOutput.getDisplayName(); - } - tNBTList.appendTag(new NBTTagString("Construction plan for " + tRecipe.mOutput.stackSize + " " + s + ". Needed EU/t: " + tRecipe.mEUt + " Production time: " + (tRecipe.mDuration / 20))); - for (int i = 0; i < tRecipe.mInputs.length; i++) { - if (tRecipe.mOreDictAlt[i] != null) { - int count = 0; - StringBuilder tBuilder = new StringBuilder("Input Bus " + (i + 1) + ": "); - for (ItemStack tStack : tRecipe.mOreDictAlt[i]) { - if (tStack != null) { - s = tStack.getDisplayName(); - if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { - s = GT_Assemblyline_Server.lServerNames.get(tStack.getDisplayName()); - if (s == null) - s = tStack.getDisplayName(); - } - + - tBuilder.append(count == 0 ? "" : "\nOr ").append(tStack.stackSize).append(" ").append(s); - count++; - } - } - if (count > 0) tNBTList.appendTag(new NBTTagString(tBuilder.toString())); - } else if (tRecipe.mInputs[i] != null) { - s = tRecipe.mInputs[i].getDisplayName(); - if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { - s = GT_Assemblyline_Server.lServerNames.get(tRecipe.mInputs[i].getDisplayName()); - if (s == null) - s = tRecipe.mInputs[i].getDisplayName(); - } - tNBTList.appendTag(new NBTTagString("Input Bus " + (i + 1) + ": " + tRecipe.mInputs[i].stackSize + " " + s)); - } - } - for (int i = 0; i < tRecipe.mFluidInputs.length; i++) { - if (tRecipe.mFluidInputs[i] != null) { - s = tRecipe.mFluidInputs[i].getLocalizedName(); - if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { - s = GT_Assemblyline_Server.lServerNames.get(tRecipe.mFluidInputs[i].getLocalizedName()); - if (s == null) - s = tRecipe.mFluidInputs[i].getLocalizedName(); - } - tNBTList.appendTag(new NBTTagString("Input Hatch " + (i + 1) + ": " + tRecipe.mFluidInputs[i].amount + "L " + s)); - } + // Use Assline Utils + if (GT_AssemblyLineUtils.setAssemblyLineRecipeOnDataStick(this.mOutputItems[0], tRecipe)) { + aStack.stackSize -= 1; + calculateOverclockedNess(30, tRecipe.mResearchTime); + //In case recipe is too OP for that machine + if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) + return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; + getSpecialSlot().stackSize -= 1; + return 2; } - tNBT.setTag("pages", tNBTList); - - this.mOutputItems[0].setTagCompound(tNBT); - // Add Recipe Hash String to Data stick. - GT_AssemblyLineUtils.setRecipeHashOnDataStick(this.mOutputItems[0], GT_AssemblyLineUtils.generateRecipeHash(tRecipe)); - - aStack.stackSize -= 1; - calculateOverclockedNess(30, tRecipe.mResearchTime); - //In case recipe is too OP for that machine - if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) - return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; - getSpecialSlot().stackSize -= 1; - return 2; } } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java index 060c086741..c2460213c8 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java @@ -20,6 +20,7 @@ import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_AssemblyLineUtils; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Recipe.GT_Recipe_AssemblyLine; import gregtech.api.util.GT_Utility; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; @@ -157,123 +158,111 @@ public class GT_MetaTileEntity_AssemblyLine extends GT_MetaTileEntity_EnhancedMu @Override public boolean checkRecipe(ItemStack aStack) { - if (GT_Values.D1) - GT_FML_LOGGER.info("Start ALine recipe check"); + if (GT_Values.D1) { + GT_FML_LOGGER.info("Start ALine recipe check"); + } ArrayList tDataStickList = getDataItems(2); - if (tDataStickList.isEmpty()) return false; - if (GT_Values.D1) - GT_FML_LOGGER.info("Stick accepted, " + tDataStickList.size() + " Data Sticks found"); + if (tDataStickList.isEmpty()) { + return false; + } + if (GT_Values.D1) { + GT_FML_LOGGER.info("Stick accepted, " + tDataStickList.size() + " Data Sticks found"); + } - ItemStack[] tStack = new ItemStack[15]; - FluidStack[] tFluids = new FluidStack[4]; + ItemStack[] tStack = null; + FluidStack[] tFluids = null; boolean findRecipe = false; - nextDS: + + nextDataStick: for (ItemStack tDataStick : tDataStickList) { - NBTTagCompound tTag = tDataStick.getTagCompound(); - if (tTag == null) - continue; + GT_Recipe_AssemblyLine aFoundRecipe = GT_AssemblyLineUtils.findAssemblyLineRecipeFromDataStick(tDataStick); + + // Check if the recipe on the data stick is the current recipe for it's given output, if not we update it and continue to next. + if (!GT_AssemblyLineUtils.processDataStick(tDataStick)) { + continue; + } + + tStack = aFoundRecipe.mInputs; + tFluids = aFoundRecipe.mFluidInputs; + + // So here we check against the recipe found on the data stick. + // If we run into missing buses/hatches or bad inputs, we go to the next data stick. + // This check only happens if we have a valid up to date data stick. + + // Check Inputs allign + int aItemCount = aFoundRecipe.mInputs.length; for (int i = 0; i < 15; i++) { - int count = tTag.getInteger("a" + i); - if (!tTag.hasKey("" + i) && count <= 0) - continue; - if (mInputBusses.get(i) == null) { - continue nextDS; - } - - ItemStack stackInSlot = mInputBusses.get(i).getBaseMetaTileEntity().getStackInSlot(0); - boolean flag = true; - if (count > 0) { - for (int j = 0; j < count; j++) { - tStack[i] = GT_Utility.loadItem(tTag, "a" + i + ":" + j); - if (tStack[i] == null) continue; - if (GT_Values.D1) - GT_FML_LOGGER.info("Item " + i + " : " + tStack[i].getUnlocalizedName()); - if (GT_Utility.areStacksEqual(tStack[i], stackInSlot, true) && tStack[i].stackSize <= stackInSlot.stackSize) { - flag = false; - break; - } - } - } - if (flag) { - tStack[i] = GT_Utility.loadItem(tTag, "" + i); - if (tStack[i] == null) { - flag = false; - continue; - } - if (GT_Values.D1) - GT_FML_LOGGER.info("Item " + i + " : " + tStack[i].getUnlocalizedName()); - if (GT_Utility.areStacksEqual(tStack[i], stackInSlot, true) && tStack[i].stackSize <= stackInSlot.stackSize) { - flag = false; + if (i >= aItemCount) { + continue; + } + else { + if (mInputBusses.get(i) == null) { + continue nextDataStick; } - } - if (GT_Values.D1) - GT_FML_LOGGER.info(i + (flag ? " not accepted" : " accepted")); - if (flag) - continue nextDS; - } - - if (GT_Values.D1) GT_FML_LOGGER.info("All Items done, start fluid check"); - for (int i = 0; i < 4; i++) { - if (!tTag.hasKey("f" + i)) continue; - tFluids[i] = GT_Utility.loadFluid(tTag, "f" + i); - if (tFluids[i] == null) continue; - if (GT_Values.D1) - GT_FML_LOGGER.info("Fluid " + i + " " + tFluids[i].getUnlocalizedName()); - if (mInputHatches.get(i) == null) { - continue nextDS; - } - FluidStack fluidInHatch = mInputHatches.get(i).mFluid; - if (!GT_Utility.areFluidsEqual(fluidInHatch, tFluids[i], true) || fluidInHatch.amount < tFluids[i].amount) { - if (GT_Values.D1) - GT_FML_LOGGER.info(i + " not accepted"); - continue nextDS; - } - if (GT_Values.D1) - GT_FML_LOGGER.info(i + " accepted"); - } - - if (GT_Values.D1) - GT_FML_LOGGER.info("Input accepted, check other values"); - if (!tTag.hasKey("output")) - continue; - mOutputItems = new ItemStack[]{GT_Utility.loadItem(tTag, "output")}; - if (mOutputItems[0] == null || !GT_Utility.isStackValid(mOutputItems[0])) - continue; - - if (!tTag.hasKey("time")) - continue; - int tMaxProgressTime = tTag.getInteger("time"); - if (tMaxProgressTime <= 0) - continue; - - if (!tTag.hasKey("eu")) - continue; - - if (GT_Values.D1) GT_FML_LOGGER.info("Check overclock"); - - calculateOverclockedNessMulti(tTag.getInteger("eu"), tMaxProgressTime, 1, getMaxInputVoltage()); - //In case recipe is too OP for that machine - if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) { - if (GT_Values.D1) GT_FML_LOGGER.info("Recipe too OP"); - continue; + else { + ItemStack stackInSlot = mInputBusses.get(i).getBaseMetaTileEntity().getStackInSlot(0); + if (!GT_Utility.areStacksEqual(tStack[i], stackInSlot, true) || tStack[i].stackSize <= stackInSlot.stackSize) { + continue nextDataStick; + } + if (GT_Values.D1) { + GT_FML_LOGGER.info("Item: " + i + " accepted"); + } + } + } } - - if (GT_Values.D1) GT_FML_LOGGER.info("Find avaiable recipe"); - // Check data stick is valid. - if (GT_AssemblyLineUtils.processDataStick(tDataStick)) { - findRecipe = true; + // Check Fluid Inputs allign + int aFluidCount = aFoundRecipe.mFluidInputs.length; + for (int i = 0; i < 4; i++){ + if (i >= aFluidCount) { + continue; + } + else { + if (mInputHatches.get(i) == null) { + continue nextDataStick; + } + else { + FluidStack fluidInHatch = mInputHatches.get(i).mFluid; + if (!GT_Utility.areFluidsEqual(fluidInHatch, tFluids[i], true) || fluidInHatch.amount < tFluids[i].amount) { + continue nextDataStick; + } + if (GT_Values.D1) { + GT_FML_LOGGER.info("Fluid:" + i + " accepted"); + } + } + } } - - break; + + if (GT_Values.D1) { + GT_FML_LOGGER.info("Check overclock"); + } + calculateOverclockedNessMulti(aFoundRecipe.mEUt, aFoundRecipe.mDuration, 1, getMaxInputVoltage()); + //In case recipe is too OP for that machine + if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) { + if (GT_Values.D1) { + GT_FML_LOGGER.info("Recipe too OP"); + } + continue; + } + if (GT_Values.D1) { + GT_FML_LOGGER.info("Find available recipe"); + } + findRecipe = true; + } + + // Best not to run this recipe. + if (!findRecipe || tStack == null || tStack.length <= 0 || tFluids == null || tFluids.length <= 0) { + return false; } - if (!findRecipe) return false; - if (GT_Values.D1) GT_FML_LOGGER.info("All checked start consuming inputs"); + if (GT_Values.D1) { + GT_FML_LOGGER.info("All checked start consuming inputs"); + } for (int i = 0; i < 15; i++) { - if (tStack[i] == null) - continue; + if (tStack[i] == null) { + continue; + } ItemStack stackInSlot = mInputBusses.get(i).getBaseMetaTileEntity().getStackInSlot(0); stackInSlot.stackSize -= tStack[i].stackSize; } @@ -287,13 +276,15 @@ public class GT_MetaTileEntity_AssemblyLine extends GT_MetaTileEntity_EnhancedMu } } - if (this.mEUt > 0) - this.mEUt = -this.mEUt; + if (this.mEUt > 0) { + this.mEUt = -this.mEUt; + } this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); this.mEfficiencyIncrease = 10000; updateSlots(); - if (GT_Values.D1) - GT_FML_LOGGER.info("Recipe sucessfull"); + if (GT_Values.D1) { + GT_FML_LOGGER.info("Recipe sucessfull"); + } return true; } -- cgit From 3f29e8c504ed163b7df9c4fb02a58d51ce2b878c Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Tue, 16 Nov 2021 05:32:32 +0800 Subject: convert cover data storage to a full nbt tag Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- build.properties | 2 +- src/main/java/gregtech/GT_Mod.java | 2 +- src/main/java/gregtech/api/GregTech_API.java | 45 +- .../metatileentity/IMetaTileEntityItemPipe.java | 8 +- .../api/interfaces/tileentity/ICoverable.java | 28 ++ .../api/metatileentity/BaseMetaPipeEntity.java | 213 +++++---- .../api/metatileentity/BaseMetaTileEntity.java | 161 ++++--- .../api/metatileentity/MetaPipeEntity.java | 20 +- .../api/metatileentity/MetaTileEntity.java | 4 +- .../implementations/GT_MetaPipeEntity_Cable.java | 14 +- .../implementations/GT_MetaPipeEntity_Fluid.java | 20 +- .../implementations/GT_MetaPipeEntity_Item.java | 16 +- .../GT_MetaTileEntity_BasicMachine.java | 6 +- .../GT_MetaTileEntity_BasicMachine_Bronze.java | 2 +- .../GT_MetaTileEntity_Hatch_InputBus.java | 2 +- .../GT_MetaTileEntity_Hatch_Output.java | 4 +- .../api/net/GT_Packet_TileEntityCover.java | 3 +- .../api/net/GT_Packet_TileEntityCoverGUI.java | 46 +- .../api/net/GT_Packet_TileEntityCoverNew.java | 113 +++++ .../java/gregtech/api/util/GT_CoverBehavior.java | 202 +++++++-- .../gregtech/api/util/GT_CoverBehavior_New.java | 480 +++++++++++++++++++++ src/main/java/gregtech/api/util/GT_Utility.java | 2 +- .../gregtech/api/util/ISerializableObject.java | 107 +++++ src/main/java/gregtech/common/GT_Network.java | 2 +- .../java/gregtech/common/covers/GT_Cover_Arm.java | 11 + .../common/covers/GT_Cover_FluidRegulator.java | 13 + .../common/covers/GT_Cover_Fluidfilter.java | 256 ++++++----- .../common/covers/GT_Cover_ItemFilter.java | 21 +- .../gregtech/common/covers/GT_Cover_ItemMeter.java | 18 +- .../covers/GT_Cover_RedstoneWirelessBase.java | 19 +- .../common/covers/GT_Cover_SolarPanel.java | 24 ++ .../boilers/GT_MetaTileEntity_Boiler.java | 2 +- .../GT_MetaTileEntity_PrimitiveBlastFurnace.java | 2 +- 33 files changed, 1531 insertions(+), 337 deletions(-) create mode 100644 src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverNew.java create mode 100644 src/main/java/gregtech/api/util/GT_CoverBehavior_New.java create mode 100644 src/main/java/gregtech/api/util/ISerializableObject.java (limited to 'src/main/java/gregtech/api/util') diff --git a/build.properties b/build.properties index b138ffcf62..e9f4359805 100644 --- a/build.properties +++ b/build.properties @@ -1,6 +1,6 @@ minecraft.version=1.7.10 forge.version=10.13.4.1614-1.7.10 -gt.version=5.09.38.05 +gt.version=5.09.39.00 structurelib.version=1.0.6 ae2.version=rv3-beta-22 applecore.version=1.7.10-1.2.1+107.59407 diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java index 44ee615f41..fc7b17e0c6 100644 --- a/src/main/java/gregtech/GT_Mod.java +++ b/src/main/java/gregtech/GT_Mod.java @@ -115,7 +115,7 @@ import static gregtech.api.enums.GT_Values.MOD_ID_FR; " after:TConstruct;" + " after:Translocator;") public class GT_Mod implements IGT_Mod { - public static final int VERSION = 509, SUBVERSION = 33; + public static final int VERSION = 509, SUBVERSION = 39; public static final int TOTAL_VERSION = calculateTotalGTVersion(VERSION, SUBVERSION); public static final int REQUIRED_IC2 = 624; @Mod.Instance("gregtech") diff --git a/src/main/java/gregtech/api/GregTech_API.java b/src/main/java/gregtech/api/GregTech_API.java index fe48f6506f..0d321423fc 100644 --- a/src/main/java/gregtech/api/GregTech_API.java +++ b/src/main/java/gregtech/api/GregTech_API.java @@ -113,7 +113,7 @@ public class GregTech_API { /** * The List of Cover Behaviors for the Covers */ - public static final Map sCoverBehaviors = new ConcurrentHashMap<>(); + public static final Map> sCoverBehaviors = new ConcurrentHashMap<>(); /** * The List of Circuit Behaviors for the Redstone Circuit Block */ @@ -615,6 +615,10 @@ public class GregTech_API { } public static void registerCover(ItemStack aStack, ITexture aCover, GT_CoverBehavior aBehavior) { + registerCover(aStack, aCover, (GT_CoverBehavior_New) aBehavior); + } + + public static void registerCover(ItemStack aStack, ITexture aCover, GT_CoverBehavior_New aBehavior) { if (!sCovers.containsKey(new GT_ItemStack(aStack))) sCovers.put(new GT_ItemStack(aStack), aCover == null || !aCover.isValidTexture() ? Textures.BlockIcons.ERROR_RENDERING[0] : aCover); if (aBehavior != null) @@ -622,6 +626,10 @@ public class GregTech_API { } public static void registerCoverBehavior(ItemStack aStack, GT_CoverBehavior aBehavior) { + registerCoverBehavior(aStack, (GT_CoverBehavior_New) aBehavior); + } + + public static void registerCoverBehavior(ItemStack aStack, GT_CoverBehavior_New aBehavior) { sCoverBehaviors.put(new GT_ItemStack(aStack), aBehavior == null ? sDefaultBehavior : aBehavior); } @@ -631,6 +639,15 @@ public class GregTech_API { * @param aBehavior can be null */ public static void registerCover(Collection aStackList, ITexture aCover, GT_CoverBehavior aBehavior) { + registerCover(aStackList, aCover, aBehavior); + } + + /** + * Registers multiple Cover Items. I use that for the OreDict Functionality. + * + * @param aBehavior can be null + */ + public static void registerCover(Collection aStackList, ITexture aCover, GT_CoverBehavior_New aBehavior) { if (aCover.isValidTexture()) aStackList.forEach(tStack -> GregTech_API.registerCover(tStack, aCover, aBehavior)); } @@ -638,10 +655,24 @@ public class GregTech_API { /** * returns a Cover behavior, guaranteed to not return null after preload */ + @Deprecated public static GT_CoverBehavior getCoverBehavior(ItemStack aStack) { if (aStack == null || aStack.getItem() == null) return sNoBehavior; - GT_CoverBehavior rCover = sCoverBehaviors.get(new GT_ItemStack(aStack)); + GT_CoverBehavior_New rCover = sCoverBehaviors.get(new GT_ItemStack(aStack)); + if (!(rCover instanceof GT_CoverBehavior) || rCover == null) + return sDefaultBehavior; + return (GT_CoverBehavior) rCover; + } + + /** + * returns a Cover behavior, guaranteed to not return null after preload + * @return + */ + public static GT_CoverBehavior_New getCoverBehaviorNew(ItemStack aStack) { + if (aStack == null || aStack.getItem() == null) + return sNoBehavior; + GT_CoverBehavior_New rCover = sCoverBehaviors.get(new GT_ItemStack(aStack)); if (rCover == null) return sDefaultBehavior; return rCover; @@ -650,12 +681,22 @@ public class GregTech_API { /** * returns a Cover behavior, guaranteed to not return null */ + @Deprecated public static GT_CoverBehavior getCoverBehavior(int aStack) { if (aStack == 0) return sNoBehavior; return getCoverBehavior(GT_Utility.intToStack(aStack)); } + /** + * returns a Cover behavior, guaranteed to not return null + */ + public static GT_CoverBehavior_New getCoverBehaviorNew(int aStack) { + if (aStack == 0) + return sNoBehavior; + return getCoverBehaviorNew(GT_Utility.intToStack(aStack)); + } + /** * Register a Wrench to be usable on GregTech Machines. * The Wrench MUST have some kind of Durability unlike certain Buildcraft Wrenches. diff --git a/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntityItemPipe.java b/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntityItemPipe.java index f136f4f32b..d40a6026dc 100644 --- a/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntityItemPipe.java +++ b/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntityItemPipe.java @@ -59,7 +59,7 @@ public interface IMetaTileEntityItemPipe extends IMetaTileEntity { continue; j = GT_Utility.getOppositeSide(i); if (aSuckItems) { - if (aBaseMetaTileEntity.getCoverBehaviorAtSide(i).letsItemsIn(i, aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getCoverDataAtSide(i), -2, aBaseMetaTileEntity)) { + if (aBaseMetaTileEntity.getCoverBehaviorAtSideNew(i).letsItemsIn(i, aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getCoverDataAtSideNew(i), -2, aBaseMetaTileEntity)) { IGregTechTileEntity tItemPipe = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(i); if (aBaseMetaTileEntity.getColorization() >= 0) { byte tColor = tItemPipe.getColorization(); @@ -69,13 +69,13 @@ public interface IMetaTileEntityItemPipe extends IMetaTileEntity { } if (tItemPipe instanceof BaseMetaPipeEntity) { IMetaTileEntity tMetaTileEntity = tItemPipe.getMetaTileEntity(); - if (tMetaTileEntity instanceof IMetaTileEntityItemPipe && tItemPipe.getCoverBehaviorAtSide(j).letsItemsOut(j, tItemPipe.getCoverIDAtSide(j), tItemPipe.getCoverDataAtSide(j), -2, tItemPipe)) { + if (tMetaTileEntity instanceof IMetaTileEntityItemPipe && tItemPipe.getCoverBehaviorAtSideNew(j).letsItemsOut(j, tItemPipe.getCoverIDAtSide(j), tItemPipe.getCoverDataAtSideNew(j), -2, tItemPipe)) { scanPipes((IMetaTileEntityItemPipe) tMetaTileEntity, aMap, aStep, aSuckItems, aIgnoreCapacity); } } } } else { - if (aBaseMetaTileEntity.getCoverBehaviorAtSide(i).letsItemsOut(i, aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getCoverDataAtSide(i), -2, aBaseMetaTileEntity)) { + if (aBaseMetaTileEntity.getCoverBehaviorAtSideNew(i).letsItemsOut(i, aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getCoverDataAtSideNew(i), -2, aBaseMetaTileEntity)) { IGregTechTileEntity tItemPipe = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(i); if (tItemPipe != null) { if (aBaseMetaTileEntity.getColorization() >= 0) { @@ -86,7 +86,7 @@ public interface IMetaTileEntityItemPipe extends IMetaTileEntity { } if (tItemPipe instanceof BaseMetaPipeEntity) { IMetaTileEntity tMetaTileEntity = tItemPipe.getMetaTileEntity(); - if (tMetaTileEntity instanceof IMetaTileEntityItemPipe && tItemPipe.getCoverBehaviorAtSide(j).letsItemsIn(j, tItemPipe.getCoverIDAtSide(j), tItemPipe.getCoverDataAtSide(j), -2, tItemPipe)) { + if (tMetaTileEntity instanceof IMetaTileEntityItemPipe && tItemPipe.getCoverBehaviorAtSideNew(j).letsItemsIn(j, tItemPipe.getCoverIDAtSide(j), tItemPipe.getCoverDataAtSideNew(j), -2, tItemPipe)) { scanPipes((IMetaTileEntityItemPipe) tMetaTileEntity, aMap, aStep, aSuckItems, aIgnoreCapacity); } } diff --git a/src/main/java/gregtech/api/interfaces/tileentity/ICoverable.java b/src/main/java/gregtech/api/interfaces/tileentity/ICoverable.java index 560d47c595..47be175ead 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/ICoverable.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/ICoverable.java @@ -1,6 +1,9 @@ package gregtech.api.interfaces.tileentity; import gregtech.api.util.GT_CoverBehavior; +import gregtech.api.util.GT_CoverBehavior_New; +import gregtech.api.util.ISerializableObject; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; public interface ICoverable extends IRedstoneTileEntity, IHasInventory, IBasicEnergyContainer { @@ -10,20 +13,36 @@ public interface ICoverable extends IRedstoneTileEntity, IHasInventory, IBasicEn boolean dropCover(byte aSide, byte aDroppedSide, boolean aForced); + @Deprecated void setCoverDataAtSide(byte aSide, int aData); + default void setCoverDataAtSide(byte aSide, ISerializableObject aData) { + if (aData instanceof ISerializableObject.LegacyCoverData) + setCoverDataAtSide(aSide, ((ISerializableObject.LegacyCoverData) aData).get()); + } + void setCoverIDAtSide(byte aSide, int aID); void setCoverItemAtSide(byte aSide, ItemStack aCover); + @Deprecated int getCoverDataAtSide(byte aSide); + default ISerializableObject getCoverDataAtSideNew(byte aSide) { + return new ISerializableObject.LegacyCoverData(getCoverDataAtSide(aSide)); + } + int getCoverIDAtSide(byte aSide); ItemStack getCoverItemAtSide(byte aSide); + @Deprecated GT_CoverBehavior getCoverBehaviorAtSide(byte aSide); + default GT_CoverBehavior_New getCoverBehaviorAtSideNew(byte aSide) { + return getCoverBehaviorAtSide(aSide); + } + /** * For use by the regular MetaTileEntities. Returns the Cover Manipulated input Redstone. * Don't use this if you are a Cover Behavior. Only for MetaTileEntities. @@ -46,4 +65,13 @@ public interface ICoverable extends IRedstoneTileEntity, IHasInventory, IBasicEn * Receiving a packet with cover data. */ void receiveCoverData(byte coverSide, int coverID, int coverData); + + /** + * Receiving a packet with cover data. + * @param aPlayer the player who made the change + */ + default void receiveCoverData(byte aCoverSide, int aCoverID, ISerializableObject aCoverData, EntityPlayerMP aPlayer) { + if (aCoverData instanceof ISerializableObject.LegacyCoverData) + receiveCoverData(aCoverSide, aCoverID, ((ISerializableObject.LegacyCoverData) aCoverData).get()); + } } diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java index c2465c1a53..af14f9a9fe 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java @@ -1,5 +1,14 @@ package gregtech.api.metatileentity; +import static gregtech.GT_Mod.GT_FML_LOGGER; +import static gregtech.api.enums.GT_Values.NW; +import static gregtech.api.metatileentity.BaseMetaTileEntity.COVER_DATA_NBT_KEYS; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.Textures; @@ -11,16 +20,22 @@ import gregtech.api.interfaces.metatileentity.IConnectable; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.interfaces.tileentity.IPipeRenderedTileEntity; -import gregtech.api.metatileentity.BaseMetaTileEntity.ClientEvents; import gregtech.api.net.GT_Packet_TileEntity; import gregtech.api.objects.GT_ItemStack; -import gregtech.api.util.*; +import gregtech.api.util.GT_CoverBehavior; +import gregtech.api.util.GT_CoverBehavior_New; +import gregtech.api.util.GT_Log; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.ISerializableObject; import gregtech.common.GT_Client; import gregtech.common.covers.GT_Cover_Fluidfilter; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -32,27 +47,18 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - -import static gregtech.GT_Mod.GT_FML_LOGGER; -import static gregtech.api.enums.GT_Values.NW; - /** * NEVER INCLUDE THIS FILE IN YOUR MOD!!! *

* This is the main TileEntity for EVERYTHING. */ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileEntity, IPipeRenderedTileEntity { - private final GT_CoverBehavior[] mCoverBehaviors = new GT_CoverBehavior[]{GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior}; + private final GT_CoverBehavior_New[] mCoverBehaviors = new GT_CoverBehavior_New[]{GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior}; public byte mConnections = IConnectable.NO_CONNECTION; protected MetaPipeEntity mMetaTileEntity; private byte[] mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; - private int[] mCoverSides = new int[]{0, 0, 0, 0, 0, 0}; - private int[] mCoverData = new int[]{0, 0, 0, 0, 0, 0}; - private final int[] mTimeStatistics = new int[GregTech_API.TICKS_FOR_LAG_AVERAGING]; + private int[] mCoverSides = new int[]{0, 0, 0, 0, 0, 0}, mTimeStatistics = new int[GregTech_API.TICKS_FOR_LAG_AVERAGING]; + private ISerializableObject[] mCoverData = new ISerializableObject[6]; private boolean mInventoryChanged = false, mWorkUpdate = false, mWorks = true, mNeedsUpdate = true, mNeedsBlockUpdate = true, mSendClientData = false; private final boolean mCheckConnections = false; private byte mColor = 0, oColor = 0, mStrongRedstone = 0, oStrongRedstone = 0, oRedstoneData = 63, oTextureData = 0, oUpdateData = 0, mLagWarningCount = 0; @@ -92,27 +98,18 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE } try { aNBT.setInteger("mID", mID); - aNBT.setIntArray("mCoverData", mCoverData); + for (int i = 0; i < mCoverData.length; i++) { + if (mCoverData[i] != null) + aNBT.setTag(COVER_DATA_NBT_KEYS[i], mCoverData[i].saveDataToNBT()); + } aNBT.setIntArray("mCoverSides", mCoverSides); aNBT.setByteArray("mRedstoneSided", mSidedRedstone); aNBT.setByte("mConnections", mConnections); aNBT.setByte("mColor", mColor); aNBT.setByte("mStrongRedstone", mStrongRedstone); aNBT.setBoolean("mWorks", !mWorks); - - for(int i=0;i < mCoverData.length; i++) { - if (GregTech_API.getCoverBehavior(mCoverSides[i]) instanceof GT_Cover_Fluidfilter) { - final int fluidId = mCoverData[i] >>> 3; - final Fluid fluid = FluidRegistry.getFluid(fluidId); - if(fluid != null) { - final String fluidName = FluidRegistry.getFluidName(fluid); - aNBT.setString(String.format("fluidFilter%d", i), fluidName); - } - } - } - } catch (Throwable e) { - GT_Log.err.println("Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk whould've been corrupted by now, but I prevented that. Please report immediately to GregTech Intergalactical!!!"); + GT_Log.err.println("Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk would've been corrupted by now, but I prevented that. Please report immediately to GregTech Intergalactical!!!"); e.printStackTrace(GT_Log.err); } try { @@ -158,28 +155,61 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE if (aID <= 0) mID = (short) aNBT.getInteger("mID"); else mID = aID; mCoverSides = aNBT.getIntArray("mCoverSides"); - mCoverData = aNBT.getIntArray("mCoverData"); mSidedRedstone = aNBT.getByteArray("mRedstoneSided"); mConnections = aNBT.getByte("mConnections"); mColor = aNBT.getByte("mColor"); mStrongRedstone = aNBT.getByte("mStrongRedstone"); mWorks = !aNBT.getBoolean("mWorks"); - if (mCoverData.length != 6) mCoverData = new int[]{0, 0, 0, 0, 0, 0}; if (mCoverSides.length != 6) mCoverSides = new int[]{0, 0, 0, 0, 0, 0}; + // check old form of data + mCoverData = null; + if (aNBT.hasKey("mCoverData", 11)) { + int[] tOldData = aNBT.getIntArray("mCoverData"); + if (tOldData.length == 6) + mCoverData = Arrays.stream(tOldData).mapToObj(ISerializableObject.LegacyCoverData::new).toArray(ISerializableObject[]::new); + } + // if no old data + if (mCoverData == null) { + mCoverData = new ISerializableObject[6]; + for (byte i = 0; i<6; i++) { + GT_CoverBehavior_New tBehavior = getCoverBehaviorAtSideNew(i); + if (tBehavior == null) + continue; + mCoverData[i] = tBehavior.createDataObject(); + if (aNBT.hasKey(COVER_DATA_NBT_KEYS[i])) + mCoverData[i].loadDataFromNBT(aNBT.getTag(COVER_DATA_NBT_KEYS[i])); + } + } if (mSidedRedstone.length != 6) mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; - for (byte i = 0; i < 6; i++) { - mCoverBehaviors[i] = GregTech_API.getCoverBehavior(mCoverSides[i]); - if(mCoverBehaviors[i] instanceof GT_Cover_Fluidfilter) { - final String filterKey = String.format("fluidFilter%d", i); - if (aNBT.hasKey(filterKey)) { - mCoverData[i] = (mCoverData[i] & 7) | (FluidRegistry.getFluidID(aNBT.getString(filterKey)) << 3); + for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehaviorNew(mCoverSides[i]); + + // check old form of data + mCoverData = new ISerializableObject[6]; + if (aNBT.hasKey("mCoverData", 11) && aNBT.getIntArray("mCoverData").length == 6) { + int[] tOldData = aNBT.getIntArray("mCoverData"); + for (int i = 0; i < tOldData.length; i++) { + if(mCoverBehaviors[i] instanceof GT_Cover_Fluidfilter) { + final String filterKey = String.format("fluidFilter%d", i); + if (aNBT.hasKey(filterKey)) { + mCoverData[i] = mCoverBehaviors[i].createDataObject((tOldData[i] & 7) | (FluidRegistry.getFluidID(aNBT.getString(filterKey)) << 3)); + } + } else if (mCoverBehaviors[i] != null && mCoverBehaviors[i] != GregTech_API.sNoBehavior) { + mCoverData[i] = mCoverBehaviors[i].createDataObject(tOldData[i]); } } + } else { + // no old data + for (byte i = 0; i<6; i++) { + if (mCoverBehaviors[i] == null) + continue; + if (aNBT.hasKey(COVER_DATA_NBT_KEYS[i])) + mCoverData[i] = mCoverBehaviors[i].createDataObject(aNBT.getTag(COVER_DATA_NBT_KEYS[i])); + else + mCoverData[i] = mCoverBehaviors[i].createDataObject(); + } } - - if (mID != 0 && createNewMetatileEntity(mID)) { NBTTagList tItemList = aNBT.getTagList("Inventory", 10); for (int i = 0; i < tItemList.tagCount(); i++) { @@ -199,11 +229,11 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE } } - if (mCoverData.length != 6) mCoverData = new int[]{0, 0, 0, 0, 0, 0}; + if (mCoverData == null || mCoverData.length != 6) mCoverData = new ISerializableObject[6]; if (mCoverSides.length != 6) mCoverSides = new int[]{0, 0, 0, 0, 0, 0}; if (mSidedRedstone.length != 6) mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; - for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehavior(mCoverSides[i]); + for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehaviorNew(mCoverSides[i]); } private boolean createNewMetatileEntity(short aID) { @@ -271,7 +301,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE for (byte i = (byte) (tCode - 2); i < 6; i++) if (getCoverIDAtSide(i) != 0) { tCode++; - GT_CoverBehavior tCover = getCoverBehaviorAtSide(i); + GT_CoverBehavior_New tCover = getCoverBehaviorAtSideNew(i); int tCoverTickRate = tCover.getTickRate(i, getCoverIDAtSide(i), mCoverData[i], this); if (tCoverTickRate > 0 && mTickTimer % tCoverTickRate == 0) { byte tRedstone = tCover.isRedstoneSensitive(i, getCoverIDAtSide(i), mCoverData[i], this, mTickTimer) ? getInputRedstoneSignal(i) : 0; @@ -298,7 +328,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE if (isServerSide()) { if (mTickTimer == 10) { for (byte i = 0; i < 6; i++) - mCoverBehaviors[i] = GregTech_API.getCoverBehavior(mCoverSides[i]); + mCoverBehaviors[i] = GregTech_API.getCoverBehaviorNew(mCoverSides[i]); issueBlockUpdate(); joinEnet(); } @@ -326,15 +356,12 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE } if (mTickTimer > 10) { - if (mConnections != oTextureData) - sendBlockEvent(ClientEvents.CHANGE_COMMON_DATA, oTextureData = mConnections); + if (mConnections != oTextureData) sendBlockEvent((byte) 0, oTextureData = mConnections); byte tData = mMetaTileEntity.getUpdateData(); - if (tData != oUpdateData) - sendBlockEvent(ClientEvents.CHANGE_CUSTOM_DATA, oUpdateData = tData); - if (mColor != oColor) sendBlockEvent(ClientEvents.CHANGE_COLOR, oColor = mColor); + if (tData != oUpdateData) sendBlockEvent((byte) 1, oUpdateData = tData); + if (mColor != oColor) sendBlockEvent((byte) 2, oColor = mColor); tData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) | ((mSidedRedstone[2] > 0) ? 4 : 0) | ((mSidedRedstone[3] > 0) ? 8 : 0) | ((mSidedRedstone[4] > 0) ? 16 : 0) | ((mSidedRedstone[5] > 0) ? 32 : 0)); - if (tData != oRedstoneData) - sendBlockEvent(ClientEvents.CHANGE_REDSTONE_OUTPUT, oRedstoneData = tData); + if (tData != oRedstoneData) sendBlockEvent((byte) 3, oRedstoneData = tData); } if (mNeedsBlockUpdate) { @@ -384,7 +411,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE mCoverSides[4] = aCover4; mCoverSides[5] = aCover5; - for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehavior(mCoverSides[i]); + for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehaviorNew(mCoverSides[i]); receiveClientEvent(0, aTextureData); receiveClientEvent(1, aUpdateData); @@ -497,6 +524,12 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE setCoverDataAtSide(coverSide, coverData); } + @Override + public void receiveCoverData(byte aCoverSide, int aCoverID, ISerializableObject aCoverData, EntityPlayerMP aPlayer) { + if ((aCoverSide >= 0 && aCoverSide < 6) && (mCoverSides[aCoverSide] == aCoverID)) + setCoverDataAtSide(aCoverSide, aCoverData); + } + @Override public byte getStrongestRedstone() { return (byte) Math.max(getInternalInputRedstoneSignal((byte) 0), Math.max(getInternalInputRedstoneSignal((byte) 1), Math.max(getInternalInputRedstoneSignal((byte) 2), Math.max(getInternalInputRedstoneSignal((byte) 3), Math.max(getInternalInputRedstoneSignal((byte) 4), getInternalInputRedstoneSignal((byte) 5)))))); @@ -869,7 +902,8 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE if (mStrongRedstone > 0) tNBT.setByte("mStrongRedstone", mStrongRedstone); for (byte i = 0; i < mCoverSides.length; i++) { if (mCoverSides[i] != 0) { - tNBT.setIntArray("mCoverData", mCoverData); + if (mCoverData[i] != null) // this really shouldn't be null if a cover is there already, but whatever + tNBT.setTag(COVER_DATA_NBT_KEYS[i], mCoverData[i].saveDataToNBT()); tNBT.setIntArray("mCoverSides", mCoverSides); break; } @@ -909,13 +943,13 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sScrewdriverList)) { if (getCoverIDAtSide(aSide) == 0 && getCoverIDAtSide(tSide) != 0) { if (GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 200, aPlayer)) { - setCoverDataAtSide(tSide, getCoverBehaviorAtSide(tSide).onCoverScrewdriverclick(tSide, getCoverIDAtSide(tSide), getCoverDataAtSide(tSide), this, aPlayer, 0.5F, 0.5F, 0.5F)); + setCoverDataAtSide(tSide, getCoverBehaviorAtSideNew(tSide).onCoverScrewdriverClick(tSide, getCoverIDAtSide(tSide), getCoverDataAtSideNew(tSide), this, aPlayer, 0.5F, 0.5F, 0.5F)); mMetaTileEntity.onScrewdriverRightClick(tSide, aPlayer, aX, aY, aZ); GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(100), 1.0F, -1, xCoord, yCoord, zCoord); } } else { if (GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer)) { - setCoverDataAtSide(aSide, getCoverBehaviorAtSide(aSide).onCoverScrewdriverclick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this, aPlayer, aX, aY, aZ)); + setCoverDataAtSide(aSide, getCoverBehaviorAtSideNew(aSide).onCoverScrewdriverClick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this, aPlayer, aX, aY, aZ)); mMetaTileEntity.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(100), 1.0F, -1, xCoord, yCoord, zCoord); } @@ -968,7 +1002,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE if (getCoverIDAtSide(coverSide) == 0) { if (GregTech_API.sCovers.containsKey(new GT_ItemStack(tCurrentItem))) { - if (GregTech_API.getCoverBehavior(tCurrentItem).isCoverPlaceable(coverSide, new GT_ItemStack(tCurrentItem), this) && + if (GregTech_API.getCoverBehaviorNew(tCurrentItem).isCoverPlaceable(coverSide, new GT_ItemStack(tCurrentItem), this) && mMetaTileEntity.allowCoverOnSide(coverSide, new GT_ItemStack(tCurrentItem))) { setCoverItemAtSide(coverSide, tCurrentItem); @@ -989,14 +1023,14 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE } else if (aPlayer.isSneaking()) { //Sneak click, no tool -> open cover config or turn back. aSide = (getCoverIDAtSide(aSide) == 0) ? GT_Utility.determineWrenchingSide(aSide, aX, aY, aZ) : aSide; - return getCoverIDAtSide(aSide) > 0 && getCoverBehaviorAtSide(aSide).onCoverShiftRightclick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this, aPlayer); + return getCoverIDAtSide(aSide) > 0 && getCoverBehaviorAtSideNew(aSide).onCoverShiftRightClick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this, aPlayer); } - if (getCoverBehaviorAtSide(aSide).onCoverRightclick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this, aPlayer, aX, aY, aZ)) + if (getCoverBehaviorAtSideNew(aSide).onCoverRightClick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this, aPlayer, aX, aY, aZ)) return true; } - if (!getCoverBehaviorAtSide(aSide).isGUIClickable(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this)) + if (!getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this)) return false; try { @@ -1053,7 +1087,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE */ @Override public int[] getAccessibleSlotsFromSide(int aSide) { - if (canAccessData() && (getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSide((byte) aSide), -1, this) || getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSide((byte) aSide), -1, this))) + if (canAccessData() && (getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSideNew((byte) aSide), -1, this) || getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSideNew((byte) aSide), -1, this))) return mMetaTileEntity.getAccessibleSlotsFromSide(aSide); return new int[0]; } @@ -1063,7 +1097,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE */ @Override public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { - return canAccessData() && getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSide((byte) aSide), aIndex, this) && mMetaTileEntity.canInsertItem(aIndex, aStack, aSide); + return canAccessData() && getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSideNew((byte) aSide), aIndex, this) && mMetaTileEntity.canInsertItem(aIndex, aStack, aSide); } /** @@ -1071,7 +1105,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE */ @Override public boolean canExtractItem(int aIndex, ItemStack aStack, int aSide) { - return canAccessData() && getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSide((byte) aSide), aIndex, this) && mMetaTileEntity.canExtractItem(aIndex, aStack, aSide); + return canAccessData() && getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSideNew((byte) aSide), aIndex, this) && mMetaTileEntity.canExtractItem(aIndex, aStack, aSide); } @Override @@ -1081,7 +1115,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE @Override public byte getInternalInputRedstoneSignal(byte aSide) { - return (byte) (getCoverBehaviorAtSide(aSide).getRedstoneInput(aSide, getInputRedstoneSignal(aSide), getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this) & 15); + return (byte) (getCoverBehaviorAtSide(aSide).getRedstoneInput(aSide, getInputRedstoneSignal(aSide), getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this) & 15); } @Override @@ -1091,12 +1125,12 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE @Override public byte getOutputRedstoneSignal(byte aSide) { - return (byte) (getCoverBehaviorAtSide(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this) || (getCoverBehaviorAtSide(aSide).letsRedstoneGoOut(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this)) ? mSidedRedstone[aSide] & 15 : 0); + return (byte) (getCoverBehaviorAtSideNew(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this) || (getCoverBehaviorAtSideNew(aSide).letsRedstoneGoOut(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this)) ? mSidedRedstone[aSide] & 15 : 0); } @Override public void setInternalOutputRedstoneSignal(byte aSide, byte aStrength) { - if (!getCoverBehaviorAtSide(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this)) + if (!getCoverBehaviorAtSideNew(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this)) setOutputRedstoneSignal(aSide, aStrength); } @@ -1159,16 +1193,19 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE } @Override + @Deprecated public GT_CoverBehavior getCoverBehaviorAtSide(byte aSide) { - return aSide >= 0 && aSide < mCoverBehaviors.length ? mCoverBehaviors[aSide] : GregTech_API.sNoBehavior; + if (aSide >= 0 && aSide < mCoverBehaviors.length && mCoverBehaviors[aSide] instanceof GT_CoverBehavior) + return (GT_CoverBehavior) mCoverBehaviors[aSide]; + return GregTech_API.sNoBehavior; } @Override public void setCoverIDAtSide(byte aSide, int aID) { if (aSide >= 0 && aSide < 6) { mCoverSides[aSide] = aID; - mCoverData[aSide] = 0; - mCoverBehaviors[aSide] = GregTech_API.getCoverBehavior(aID); + mCoverBehaviors[aSide] = GregTech_API.getCoverBehaviorNew(aID); + mCoverData[aSide] = mCoverBehaviors[aSide].createDataObject(); issueCoverUpdate(aSide); issueBlockUpdate(); } @@ -1176,7 +1213,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE @Override public void setCoverItemAtSide(byte aSide, ItemStack aCover) { - GregTech_API.getCoverBehavior(aCover).placeCover(aSide, aCover, this); + GregTech_API.getCoverBehaviorNew(aCover).placeCover(aSide, aCover, this); } @Override @@ -1201,16 +1238,35 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE } @Override + @Deprecated public void setCoverDataAtSide(byte aSide, int aData) { - if (aSide >= 0 && aSide < 6) mCoverData[aSide] = aData; + if (aSide >= 0 && aSide < 6 && mCoverData[aSide] instanceof ISerializableObject.LegacyCoverData) + mCoverData[aSide] = new ISerializableObject.LegacyCoverData(aData); } @Override + @Deprecated public int getCoverDataAtSide(byte aSide) { - if (aSide >= 0 && aSide < 6) return mCoverData[aSide]; + if (aSide >= 0 && aSide < 6 && mCoverData[aSide] instanceof ISerializableObject.LegacyCoverData) + return ((ISerializableObject.LegacyCoverData) mCoverData[aSide]).get(); return 0; } + @Override + public void setCoverDataAtSide(byte aSide, ISerializableObject aData) { + mCoverData[aSide] = aData; + } + + @Override + public ISerializableObject getCoverDataAtSideNew(byte aSide) { + return mCoverData[aSide]; + } + + @Override + public GT_CoverBehavior_New getCoverBehaviorAtSideNew(byte aSide) { + return mCoverBehaviors[aSide]; + } + @Override public void setLightValue(byte aLightValue) { // @@ -1228,8 +1284,8 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE @Override public boolean dropCover(byte aSide, byte aDroppedSide, boolean aForced) { - if (getCoverBehaviorAtSide(aSide).onCoverRemoval(aSide, getCoverIDAtSide(aSide), mCoverData[aSide], this, aForced) || aForced) { - ItemStack tStack = getCoverBehaviorAtSide(aSide).getDrop(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this); + if (getCoverBehaviorAtSideNew(aSide).onCoverRemoval(aSide, getCoverIDAtSide(aSide), mCoverData[aSide], this, aForced) || aForced) { + ItemStack tStack = getCoverBehaviorAtSideNew(aSide).getDrop(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this); if (tStack != null) { tStack.setTagCompound(null); EntityItem tEntity = new EntityItem(worldObj, getOffsetX(aDroppedSide, 1) + 0.5, getOffsetY(aDroppedSide, 1) + 0.5, getOffsetZ(aDroppedSide, 1) + 0.5, tStack); @@ -1323,12 +1379,15 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE if (tTileEntity != null && !mMetaTileEntity.isConnectedAtSide((byte) aSide.ordinal())) return false; - if (isFill && mMetaTileEntity.isLiquidInput((byte) aSide.ordinal()) - && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), aFluid, this)) + if(isFill && mMetaTileEntity.isLiquidInput((byte) aSide.ordinal()) + && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), aFluid, this)) return true; - return !isFill && mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) - && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), aFluid, this); + if (!isFill && mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) + && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()),aFluid, this)) + return true; + + return false; } @Override @@ -1371,8 +1430,8 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE if (canAccessData() && (aSide == ForgeDirection.UNKNOWN || (mMetaTileEntity.isLiquidInput((byte) aSide.ordinal()) - && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), null, this)) - || (mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), null, this)) + && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), null, this)) + || (mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), null, this)) // Doesn't need to be connected to get Tank Info -- otherwise things can't connect ) ) diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 10d5ec774a..7bea6dbe6e 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -40,6 +40,7 @@ import net.minecraft.block.BlockFire; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -74,23 +75,22 @@ import static gregtech.api.objects.XSTR.XSTR_INSTANCE; * This is the main TileEntity for EVERYTHING. */ @Optional.InterfaceList(value = { - @Optional.Interface(iface = "appeng.api.networking.security.IActionHost", modid = "appliedenergistics2", striprefs = true), - @Optional.Interface(iface = "appeng.me.helpers.IGridProxyable", modid = "appliedenergistics2", striprefs = true)}) + @Optional.Interface(iface = "appeng.api.networking.security.IActionHost", modid = "appliedenergistics2", striprefs = true), + @Optional.Interface(iface = "appeng.me.helpers.IGridProxyable", modid = "appliedenergistics2", striprefs = true)}) public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileEntity, IActionHost, IGridProxyable, IAlignmentProvider, IConstructableProvider { - private final GT_CoverBehavior[] mCoverBehaviors = new GT_CoverBehavior[]{GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior}; + static final String[] COVER_DATA_NBT_KEYS = Arrays.stream(ForgeDirection.VALID_DIRECTIONS).mapToInt(Enum::ordinal).mapToObj(i -> "mCoverData" + i).toArray(String[]::new); + private final GT_CoverBehavior_New[] mCoverBehaviors = new GT_CoverBehavior_New[]{GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior}; protected MetaTileEntity mMetaTileEntity; protected long mStoredEnergy = 0, mStoredSteam = 0; protected int mAverageEUInputIndex = 0, mAverageEUOutputIndex = 0; protected boolean mReleaseEnergy = false; protected long[] mAverageEUInput = new long[]{0, 0, 0, 0, 0}, mAverageEUOutput = new long[]{0, 0, 0, 0, 0}; - private final boolean[] mActiveEUInputs = new boolean[]{false, false, false, false, false, false}; - private final boolean[] mActiveEUOutputs = new boolean[]{false, false, false, false, false, false}; + private boolean[] mActiveEUInputs = new boolean[]{false, false, false, false, false, false}, mActiveEUOutputs = new boolean[]{false, false, false, false, false, false}; private byte[] mSidedRedstone = new byte[]{15, 15, 15, 15, 15, 15}; - private int[] mCoverSides = new int[]{0, 0, 0, 0, 0, 0}; - private int[] mCoverData = new int[]{0, 0, 0, 0, 0, 0}; - private final int[] mTimeStatistics = new int[GregTech_API.TICKS_FOR_LAG_AVERAGING]; + private int[] mCoverSides = new int[]{0, 0, 0, 0, 0, 0}, mTimeStatistics = new int[GregTech_API.TICKS_FOR_LAG_AVERAGING]; + private ISerializableObject[] mCoverData = new ISerializableObject[6]; private boolean mHasEnoughEnergy = true, mRunningThroughTick = false, mInputDisabled = false, mOutputDisabled = false, mMuffler = false, mLockUpgrade = false, mActive = false, mRedstone = false, mWorkUpdate = false, mSteamConverter = false, mInventoryChanged = false, mWorks = true, mNeedsUpdate = true, mNeedsBlockUpdate = true, mSendClientData = false, oRedstone = false; - private byte mColor = 0, oColor = 0, oStrongRedstone = 0, mStrongRedstone = 0, oRedstoneData = 63, oTextureData = 0, oUpdateData = 0, oTexturePage = 0, oLightValueClient = -1, oLightValue = -1, mLightValue = 0, mOtherUpgrades = 0, mFacing = 0, oFacing = 0, mWorkData = 0; + private byte mColor = 0, oColor = 0, oStrongRedstone = 0, mStrongRedstone = 0, oRedstoneData = 63, oTextureData = 0, oUpdateData = 0, oTexturePage=0, oLightValueClient = -1, oLightValue = -1, mLightValue = 0, mOtherUpgrades = 0, mFacing = 0, oFacing = 0, mWorkData = 0; private int mDisplayErrorCode = 0, oX = 0, oY = 0, oZ = 0, mTimeStatisticsIndex = 0, mLagWarningCount = 0; private short mID = 0; public long mTickTimer = 0; @@ -139,7 +139,10 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE aNBT.setInteger("mID", mID); aNBT.setLong("mStoredSteam", mStoredSteam); aNBT.setLong("mStoredEnergy", mStoredEnergy); - aNBT.setIntArray("mCoverData", mCoverData); + for (int i = 0; i < mCoverData.length; i++) { + if (mCoverData[i] != null) + aNBT.setTag(COVER_DATA_NBT_KEYS[i], mCoverData[i].saveDataToNBT()); + } aNBT.setIntArray("mCoverSides", mCoverSides); aNBT.setByteArray("mRedstoneSided", mSidedRedstone); aNBT.setByte("mColor", mColor); @@ -230,19 +233,37 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE mOutputDisabled = aNBT.getBoolean("mOutputDisabled"); mOtherUpgrades = (byte) (aNBT.getByte("mOtherUpgrades") + aNBT.getByte("mBatteries") + aNBT.getByte("mLiBatteries")); mCoverSides = aNBT.getIntArray("mCoverSides"); - mCoverData = aNBT.getIntArray("mCoverData"); mSidedRedstone = aNBT.getByteArray("mRedstoneSided"); mRecipeStuff = aNBT.getCompoundTag("GT.CraftingComponents"); int nbtVersion = aNBT.getInteger("nbtVersion"); - if (mCoverData.length != 6) mCoverData = new int[]{0, 0, 0, 0, 0, 0}; if (mCoverSides.length != 6) mCoverSides = new int[]{0, 0, 0, 0, 0, 0}; if (mSidedRedstone.length != 6) if (hasValidMetaTileEntity() && mMetaTileEntity.hasSidedRedstoneOutputBehavior()) mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; else mSidedRedstone = new byte[]{15, 15, 15, 15, 15, 15}; - for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehavior(mCoverSides[i]); + for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehaviorNew(mCoverSides[i]); + + // check legacy data + mCoverData = new ISerializableObject[6]; + if (aNBT.hasKey("mCoverData", 11) && aNBT.getIntArray("mCoverData").length == 6) { + int[] tOldData = aNBT.getIntArray("mCoverData"); + for (int i = 0; i < tOldData.length; i++) { + if (mCoverBehaviors[i] != null) + mCoverData[i] = mCoverBehaviors[i].createDataObject(tOldData[i]); + } + } else { + // no old data + for (byte i = 0; i<6; i++) { + if (mCoverBehaviors[i] == null) + continue; + if (aNBT.hasKey(COVER_DATA_NBT_KEYS[i])) + mCoverData[i] = mCoverBehaviors[i].createDataObject(aNBT.getTag(COVER_DATA_NBT_KEYS[i])); + else + mCoverData[i] = mCoverBehaviors[i].createDataObject(); + } + } if (mID != 0 && createNewMetatileEntity(mID)) { NBTTagList tItemList = aNBT.getTagList("Inventory", 10); @@ -264,14 +285,14 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE } } - if (mCoverData.length != 6) mCoverData = new int[]{0, 0, 0, 0, 0, 0}; + if (mCoverData == null || mCoverData.length != 6) mCoverData = new ISerializableObject[6]; if (mCoverSides.length != 6) mCoverSides = new int[]{0, 0, 0, 0, 0, 0}; if (mSidedRedstone.length != 6) if (hasValidMetaTileEntity() && mMetaTileEntity.hasSidedRedstoneOutputBehavior()) mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; else mSidedRedstone = new byte[]{15, 15, 15, 15, 15, 15}; - for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehavior(mCoverSides[i]); + for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehaviorNew(mCoverSides[i]); } private boolean createNewMetatileEntity(short aID) { @@ -380,7 +401,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE for (byte i = (byte) (tCode - 2); i < 6; i++) if (getCoverIDAtSide(i) != 0) { tCode++; - GT_CoverBehavior tCover = getCoverBehaviorAtSide(i); + GT_CoverBehavior_New tCover = getCoverBehaviorAtSideNew(i); int tCoverTickRate = tCover.getTickRate(i, getCoverIDAtSide(i), mCoverData[i], this); if (tCoverTickRate > 0 && mTickTimer % tCoverTickRate == 0) { byte tRedstone = tCover.isRedstoneSensitive(i, getCoverIDAtSide(i), mCoverData[i], this, mTickTimer) ? getInputRedstoneSignal(i) : 0; @@ -414,7 +435,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE if (aSideServer) { if (mRedstone != oRedstone || mTickTimer == 10) { for (byte i = 0; i < 6; i++) - mCoverBehaviors[i] = GregTech_API.getCoverBehavior(mCoverSides[i]); + mCoverBehaviors[i] = GregTech_API.getCoverBehaviorNew(mCoverSides[i]); oRedstone = mRedstone; issueBlockUpdate(); } @@ -492,7 +513,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE if (GregTech_API.sMachineRainExplosions && worldObj.isRaining() && getBiome().rainfall > 0) { if (getRandomNumber(10) == 0) { try{ - GT_Mod.achievements.issueAchievement(this.getWorldObj().getPlayerEntityByName(mOwnerName), "badweather"); + GT_Mod.instance.achievements.issueAchievement(this.getWorldObj().getPlayerEntityByName(mOwnerName), "badweather"); }catch(Exception e){ } @@ -508,9 +529,9 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE return; } if (GregTech_API.sMachineThunderExplosions && worldObj.isThundering() && getBiome().rainfall > 0 && getRandomNumber(3) == 0) { - try { - GT_Mod.achievements.issueAchievement(this.getWorldObj().getPlayerEntityByName(mOwnerName), "badweather"); - }catch(Exception e){ + try{ + GT_Mod.instance.achievements.issueAchievement(this.getWorldObj().getPlayerEntityByName(mOwnerName), "badweather"); + }catch(Exception e){ } GT_Log.exp.println("Machine at: "+ this.getXCoord()+" | "+ this.getYCoord()+" | "+ this.getZCoord()+" DIMID: " +this.worldObj.provider.dimensionId + " explosion due to Thunderstorm!"); @@ -678,7 +699,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE mCoverSides[4] = aCover4; mCoverSides[5] = aCover5; - for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehavior(mCoverSides[i]); + for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehaviorNew(mCoverSides[i]); receiveClientEvent(ClientEvents.CHANGE_COMMON_DATA, aTextureData); receiveClientEvent(ClientEvents.CHANGE_CUSTOM_DATA, aUpdateData & 0x7F); @@ -702,7 +723,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE mCoverSides[4] = aCover4; mCoverSides[5] = aCover5; - for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehavior(mCoverSides[i]); + for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehaviorNew(mCoverSides[i]); receiveClientEvent(ClientEvents.CHANGE_COMMON_DATA, aTextureData); receiveClientEvent(ClientEvents.CHANGE_CUSTOM_DATA, aUpdateData & 0x7F); @@ -850,6 +871,12 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE setCoverDataAtSide(coverSide, coverData); } + @Override + public void receiveCoverData(byte aCoverSide, int aCoverID, ISerializableObject aCoverData, EntityPlayerMP aPlayer) { + if ((aCoverSide >= 0 && aCoverSide < 6) && (mCoverSides[aCoverSide] == aCoverID)) + setCoverDataAtSide(aCoverSide, aCoverData); + } + @Override public byte getStrongestRedstone() { return (byte) Math.max(getInternalInputRedstoneSignal((byte) 0), Math.max(getInternalInputRedstoneSignal((byte) 1), Math.max(getInternalInputRedstoneSignal((byte) 2), Math.max(getInternalInputRedstoneSignal((byte) 3), Math.max(getInternalInputRedstoneSignal((byte) 4), getInternalInputRedstoneSignal((byte) 5)))))); @@ -1028,7 +1055,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE @Override public boolean increaseProgress(int aProgressAmountInTicks) { - return canAccessData() && mMetaTileEntity.increaseProgress(aProgressAmountInTicks) != aProgressAmountInTicks; + return canAccessData() ? mMetaTileEntity.increaseProgress(aProgressAmountInTicks) != aProgressAmountInTicks : false; } @Override @@ -1252,7 +1279,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE private boolean isEnergyInputSide(byte aSide) { if (aSide >= 0 && aSide < 6) { - if (!getCoverBehaviorAtSide(aSide).letsEnergyIn(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this)) + if (!getCoverBehaviorAtSideNew(aSide).letsEnergyIn(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this)) return false; if (isInvalid() || mReleaseEnergy) return false; if (canAccessData() && mMetaTileEntity.isElectric() && mMetaTileEntity.isEnetInput()) @@ -1263,7 +1290,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE private boolean isEnergyOutputSide(byte aSide) { if (aSide >= 0 && aSide < 6) { - if (!getCoverBehaviorAtSide(aSide).letsEnergyOut(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this)) + if (!getCoverBehaviorAtSideNew(aSide).letsEnergyOut(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this)) return false; if (isInvalid() || mReleaseEnergy) return mReleaseEnergy; if (canAccessData() && mMetaTileEntity.isElectric() && mMetaTileEntity.isEnetOutput()) @@ -1413,7 +1440,8 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE if (mStrongRedstone > 0) tNBT.setByte("mStrongRedstone", mStrongRedstone); for (byte i = 0; i < mCoverSides.length; i++) { if (mCoverSides[i] != 0) { - tNBT.setIntArray("mCoverData", mCoverData); + if (mCoverData[i] != null) // this really shouldn't be null if a cover is there already, but whatever + tNBT.setTag(COVER_DATA_NBT_KEYS[i], mCoverData[i].saveDataToNBT()); tNBT.setIntArray("mCoverSides", mCoverSides); break; } @@ -1433,12 +1461,12 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE //Configure Cover, sneak can also be: screwdriver, wrench, side cutter, soldering iron if (aPlayer.isSneaking()) { byte tSide = (getCoverIDAtSide(aSide) == 0) ? GT_Utility.determineWrenchingSide(aSide, aX, aY, aZ) : aSide; - return (getCoverBehaviorAtSide(tSide).hasCoverGUI()); - } else if (getCoverBehaviorAtSide(aSide).onCoverRightclickClient(aSide, this, aPlayer, aX, aY, aZ)) { + return (getCoverBehaviorAtSideNew(tSide).hasCoverGUI()); + } else if (getCoverBehaviorAtSideNew(aSide).onCoverRightclickClient(aSide, this, aPlayer, aX, aY, aZ)) { return true; } - if (!getCoverBehaviorAtSide(aSide).isGUIClickable(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this)) + if (!getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this)) return false; } if (isServerSide()) { @@ -1465,7 +1493,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sScrewdriverList)) { if (GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 200, aPlayer)) { - setCoverDataAtSide(aSide, getCoverBehaviorAtSide(aSide).onCoverScrewdriverclick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this, aPlayer, aX, aY, aZ)); + setCoverDataAtSide(aSide, getCoverBehaviorAtSideNew(aSide).onCoverScrewdriverClick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this, aPlayer, aX, aY, aZ)); mMetaTileEntity.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(100), 1.0F, -1, xCoord, yCoord, zCoord); } @@ -1529,7 +1557,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE if (getCoverIDAtSide(coverSide) == 0) { if (GregTech_API.sCovers.containsKey(new GT_ItemStack(tCurrentItem))) { - if (GregTech_API.getCoverBehavior(tCurrentItem).isCoverPlaceable(coverSide, new GT_ItemStack(tCurrentItem), this) && + if (GregTech_API.getCoverBehaviorNew(tCurrentItem).isCoverPlaceable(coverSide, new GT_ItemStack(tCurrentItem), this) && mMetaTileEntity.allowCoverOnSide(coverSide, new GT_ItemStack(tCurrentItem))) { setCoverItemAtSide(coverSide, tCurrentItem); @@ -1550,13 +1578,13 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE } else if (aPlayer.isSneaking()) { //Sneak click, no tool -> open cover config if possible. aSide = (getCoverIDAtSide(aSide) == 0) ? GT_Utility.determineWrenchingSide(aSide, aX, aY, aZ) : aSide; - return getCoverIDAtSide(aSide) > 0 && getCoverBehaviorAtSide(aSide).onCoverShiftRightclick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this, aPlayer); + return getCoverIDAtSide(aSide) > 0 && getCoverBehaviorAtSideNew(aSide).onCoverShiftRightClick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this, aPlayer); } - if (getCoverBehaviorAtSide(aSide).onCoverRightclick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this, aPlayer, aX, aY, aZ)) + if (getCoverBehaviorAtSideNew(aSide).onCoverRightClick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this, aPlayer, aX, aY, aZ)) return true; - if (!getCoverBehaviorAtSide(aSide).isGUIClickable(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this)) + if (!getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this)) return false; if (isUpgradable() && tCurrentItem != null) {/* @@ -1645,7 +1673,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE */ @Override public int[] getAccessibleSlotsFromSide(int aSide) { - if (canAccessData() && (getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSide((byte) aSide), -1, this) || getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSide((byte) aSide), -1, this))) + if (canAccessData() && (getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSideNew((byte) aSide), -1, this) || getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSideNew((byte) aSide), -1, this))) return mMetaTileEntity.getAccessibleSlotsFromSide(aSide); return new int[0]; } @@ -1655,7 +1683,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE */ @Override public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { - return canAccessData() && (mRunningThroughTick || !mInputDisabled) && getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSide((byte) aSide), aIndex, this) && mMetaTileEntity.canInsertItem(aIndex, aStack, aSide); + return canAccessData() && (mRunningThroughTick || !mInputDisabled) && getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSideNew((byte) aSide), aIndex, this) && mMetaTileEntity.canInsertItem(aIndex, aStack, aSide); } /** @@ -1663,7 +1691,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE */ @Override public boolean canExtractItem(int aIndex, ItemStack aStack, int aSide) { - return canAccessData() && (mRunningThroughTick || !mOutputDisabled) && getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSide((byte) aSide), aIndex, this) && mMetaTileEntity.canExtractItem(aIndex, aStack, aSide); + return canAccessData() && (mRunningThroughTick || !mOutputDisabled) && getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSideNew((byte) aSide), aIndex, this) && mMetaTileEntity.canExtractItem(aIndex, aStack, aSide); } @Override @@ -1673,7 +1701,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE @Override public byte getInternalInputRedstoneSignal(byte aSide) { - return (byte) (getCoverBehaviorAtSide(aSide).getRedstoneInput(aSide, getInputRedstoneSignal(aSide), getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this) & 15); + return (byte) (getCoverBehaviorAtSideNew(aSide).getRedstoneInput(aSide, getInputRedstoneSignal(aSide), getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this) & 15); } @Override @@ -1683,7 +1711,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE @Override public byte getOutputRedstoneSignal(byte aSide) { - return getCoverBehaviorAtSide(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this) ? mSidedRedstone[aSide] : getGeneralRS(aSide); + return getCoverBehaviorAtSideNew(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this) ? mSidedRedstone[aSide] : getGeneralRS(aSide); } public byte getGeneralRS(byte aSide){ @@ -1693,7 +1721,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE @Override public void setInternalOutputRedstoneSignal(byte aSide, byte aStrength) { - if (!getCoverBehaviorAtSide(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this)) + if (!getCoverBehaviorAtSideNew(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this)) setOutputRedstoneSignal(aSide, aStrength); } @@ -1779,16 +1807,19 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE } @Override + @Deprecated public GT_CoverBehavior getCoverBehaviorAtSide(byte aSide) { - return aSide >= 0 && aSide < mCoverBehaviors.length ? mCoverBehaviors[aSide] : GregTech_API.sNoBehavior; + if (aSide >= 0 && aSide < mCoverBehaviors.length && mCoverBehaviors[aSide] instanceof GT_CoverBehavior) + return (GT_CoverBehavior) mCoverBehaviors[aSide]; + return GregTech_API.sNoBehavior; } @Override public void setCoverIDAtSide(byte aSide, int aID) { if (aSide >= 0 && aSide < 6) { mCoverSides[aSide] = aID; - mCoverData[aSide] = 0; - mCoverBehaviors[aSide] = GregTech_API.getCoverBehavior(aID); + mCoverBehaviors[aSide] = GregTech_API.getCoverBehaviorNew(aID); + mCoverData[aSide] = mCoverBehaviors[aSide].createDataObject(); issueCoverUpdate(aSide); issueBlockUpdate(); } @@ -1796,7 +1827,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE @Override public void setCoverItemAtSide(byte aSide, ItemStack aCover) { - GregTech_API.getCoverBehavior(aCover).placeCover(aSide, aCover, this); + GregTech_API.getCoverBehaviorNew(aCover).placeCover(aSide, aCover, this); } @Override @@ -1821,16 +1852,34 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE } @Override + @Deprecated public void setCoverDataAtSide(byte aSide, int aData) { - if (aSide >= 0 && aSide < 6) mCoverData[aSide] = aData; + if (aSide >= 0 && aSide < 6) mCoverData[aSide] = new ISerializableObject.LegacyCoverData(aData); } @Override + @Deprecated public int getCoverDataAtSide(byte aSide) { - if (aSide >= 0 && aSide < 6) return mCoverData[aSide]; + if (aSide >= 0 && aSide < 6 && mCoverData[aSide] instanceof ISerializableObject.LegacyCoverData) + return ((ISerializableObject.LegacyCoverData) mCoverData[aSide]).get(); return 0; } + @Override + public void setCoverDataAtSide(byte aSide, ISerializableObject aData) { + mCoverData[aSide] = aData; + } + + @Override + public ISerializableObject getCoverDataAtSideNew(byte aSide) { + return mCoverData[aSide]; + } + + @Override + public GT_CoverBehavior_New getCoverBehaviorAtSideNew(byte aSide) { + return mCoverBehaviors[aSide]; + } + public byte getLightValue() { return mLightValue; } @@ -1860,8 +1909,8 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE @Override public boolean dropCover(byte aSide, byte aDroppedSide, boolean aForced) { - if (getCoverBehaviorAtSide(aSide).onCoverRemoval(aSide, getCoverIDAtSide(aSide), mCoverData[aSide], this, aForced) || aForced) { - ItemStack tStack = getCoverBehaviorAtSide(aSide).getDrop(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this); + if (getCoverBehaviorAtSideNew(aSide).onCoverRemoval(aSide, getCoverIDAtSide(aSide), mCoverData[aSide], this, aForced) || aForced) { + ItemStack tStack = getCoverBehaviorAtSideNew(aSide).getDrop(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this); if (tStack != null) { tStack.setTagCompound(null); EntityItem tEntity = new EntityItem(worldObj, getOffsetX(aDroppedSide, 1) + 0.5, getOffsetY(aDroppedSide, 1) + 0.5, getOffsetZ(aDroppedSide, 1) + 0.5, tStack); @@ -1976,7 +2025,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE aSide == ForgeDirection.UNKNOWN || ( mMetaTileEntity.isLiquidInput((byte) aSide.ordinal()) && - getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), aFluid == null ? null : aFluid.getFluid(), this) + getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), aFluid == null ? null : aFluid.getFluid(), this) ) ) ) @@ -1992,7 +2041,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE aSide == ForgeDirection.UNKNOWN || ( mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && - getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), mMetaTileEntity.getFluid() == null ? null : mMetaTileEntity.getFluid().getFluid(), this) + getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), mMetaTileEntity.getFluid() == null ? null : mMetaTileEntity.getFluid().getFluid(), this) ) ) ) @@ -2008,7 +2057,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE aSide == ForgeDirection.UNKNOWN || ( mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && - getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), aFluid == null ? null : aFluid.getFluid(), this) + getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), aFluid == null ? null : aFluid.getFluid(), this) ) ) ) @@ -2024,7 +2073,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE aSide == ForgeDirection.UNKNOWN || ( mMetaTileEntity.isLiquidInput((byte) aSide.ordinal()) && - getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), aFluid, this) + getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), aFluid, this) ) ) ) @@ -2040,7 +2089,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE aSide == ForgeDirection.UNKNOWN || ( mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && - getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), aFluid, this) + getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), aFluid, this) ) ) ) @@ -2055,8 +2104,8 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE aSide == ForgeDirection.UNKNOWN || ( mMetaTileEntity.isLiquidInput((byte) aSide.ordinal()) && - getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), null, this)) || (mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && - getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), null, this) + getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), null, this)) || (mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && + getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), null, this) ) ) ) diff --git a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java index 99e018ecdf..23d6017a6a 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java @@ -178,7 +178,10 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable { if (difference > 1.05 && difference < 1.4) { aSide = 5; } - boolean tCovered = aSide < 6 && mBaseMetaTileEntity.getCoverIDAtSide(aSide) > 0; + boolean tCovered = false; + if (aSide < 6 && mBaseMetaTileEntity.getCoverIDAtSide(aSide) > 0) { + tCovered = true; + } if(isConnectedAtSide(aSide)){ tCovered = true; } @@ -518,9 +521,9 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable { public int[] getAccessibleSlotsFromSide(int aSide) { ArrayList tList = new ArrayList(); IGregTechTileEntity tTileEntity = getBaseMetaTileEntity(); - boolean tSkip = tTileEntity.getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSide((byte) aSide), -2, tTileEntity) || tTileEntity.getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSide((byte) aSide), -2, tTileEntity); + boolean tSkip = tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), -2, tTileEntity) || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), -2, tTileEntity); for (int i = 0; i < getSizeInventory(); i++) - if (isValidSlot(i) && (tSkip || tTileEntity.getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSide((byte) aSide), i, tTileEntity) || tTileEntity.getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSide((byte) aSide), i, tTileEntity))) + if (isValidSlot(i) && (tSkip || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), i, tTileEntity) || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), i, tTileEntity))) tList.add(i); int[] rArray = new int[tList.size()]; for (int i = 0; i < rArray.length; i++) rArray[i] = tList.get(i); @@ -766,7 +769,7 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable { if (tTileEntity instanceof IColoredTileEntity) { if (getBaseMetaTileEntity().getColorization() >= 0) { byte tColor = ((IColoredTileEntity) tTileEntity).getColorization(); - return tColor < 0 || tColor == getBaseMetaTileEntity().getColorization(); + if (tColor >= 0 && tColor != getBaseMetaTileEntity().getColorization()) return false; } } @@ -781,9 +784,9 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable { final IGregTechTileEntity baseMetaTile = getBaseMetaTileEntity(); if (baseMetaTile == null || !baseMetaTile.isServerSide()) return 0; - final GT_CoverBehavior coverBehavior = baseMetaTile.getCoverBehaviorAtSide(aSide); - final int coverId = baseMetaTile.getCoverIDAtSide(aSide), - coverData = baseMetaTile.getCoverDataAtSide(aSide); + final GT_CoverBehavior_New coverBehavior = baseMetaTile.getCoverBehaviorAtSideNew(aSide); + final int coverId = baseMetaTile.getCoverIDAtSide(aSide); + ISerializableObject coverData = baseMetaTile.getCoverDataAtSideNew(aSide); boolean alwaysLookConnected = coverBehavior.alwaysLookConnected(aSide, coverId, coverData, baseMetaTile); boolean letsIn = letsIn(coverBehavior, aSide, coverId, coverData, baseMetaTile); @@ -853,6 +856,9 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable { public boolean letsIn(GT_CoverBehavior coverBehavior, byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return false; } public boolean letsOut(GT_CoverBehavior coverBehavior, byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return false; } + public boolean letsIn(GT_CoverBehavior_New coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { return false; } + public boolean letsOut(GT_CoverBehavior_New coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { return false; } + public boolean canConnect(byte aSide, TileEntity tTileEntity) { return false; } public boolean getGT6StyleConnection() { return false; } diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java index e1a8d65149..9e8865c3fa 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java @@ -714,9 +714,9 @@ public abstract class MetaTileEntity implements IMetaTileEntity { public int[] getAccessibleSlotsFromSide(int aSide) { ArrayList tList = new ArrayList(); IGregTechTileEntity tTileEntity = getBaseMetaTileEntity(); - boolean tSkip = tTileEntity.getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSide((byte) aSide), -2, tTileEntity) || tTileEntity.getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSide((byte) aSide), -2, tTileEntity); + boolean tSkip = tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), -2, tTileEntity) || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), -2, tTileEntity); for (int i = 0; i < getSizeInventory(); i++) - if (isValidSlot(i) && (tSkip || tTileEntity.getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSide((byte) aSide), i, tTileEntity) || tTileEntity.getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSide((byte) aSide), i, tTileEntity))) + if (isValidSlot(i) && (tSkip || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), i, tTileEntity) || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), i, tTileEntity))) tList.add(i); int[] rArray = new int[tList.size()]; for (int i = 0; i < rArray.length; i++) rArray[i] = tList.get(i); diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java index 439cacff91..99eda0e159 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java @@ -159,7 +159,7 @@ public class GT_MetaPipeEntity_Cable extends MetaPipeEntity implements IMetaTile public long injectEnergyUnits(byte aSide, long aVoltage, long aAmperage) { if (!isConnectedAtSide(aSide) && aSide != 6) return 0; - if (!getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide).letsEnergyIn(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSide(aSide), getBaseMetaTileEntity())) + if (!getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).letsEnergyIn(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSideNew(aSide), getBaseMetaTileEntity())) return 0; HashSet nul = null; return transferElectricity(aSide, aVoltage, aAmperage,nul); @@ -254,11 +254,21 @@ public class GT_MetaPipeEntity_Cable extends MetaPipeEntity implements IMetaTile return coverBehavior.letsEnergyOut(aSide, aCoverID, aCoverVariable, aTileEntity); } + @Override + public boolean letsIn(GT_CoverBehavior_New coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return coverBehavior.letsEnergyIn(aSide, aCoverID, aCoverVariable, aTileEntity); + } + + @Override + public boolean letsOut(GT_CoverBehavior_New coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return coverBehavior.letsEnergyOut(aSide, aCoverID, aCoverVariable, aTileEntity); + } + @Override public boolean canConnect(byte aSide, TileEntity tTileEntity) { final IGregTechTileEntity baseMetaTile = getBaseMetaTileEntity(); - final GT_CoverBehavior coverBehavior = baseMetaTile.getCoverBehaviorAtSide(aSide); + final GT_CoverBehavior_New coverBehavior = baseMetaTile.getCoverBehaviorAtSideNew(aSide); final byte tSide = GT_Utility.getOppositeSide(aSide); final ForgeDirection tDir = ForgeDirection.getOrientation(tSide); diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java index 128f6fa916..8c59823370 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java @@ -15,8 +15,10 @@ import gregtech.api.metatileentity.BaseMetaPipeEntity; import gregtech.api.metatileentity.MetaPipeEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_CoverBehavior; +import gregtech.api.util.GT_CoverBehavior_New; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_Utility; +import gregtech.api.util.ISerializableObject; import gregtech.api.util.WorldSpawnedEventBuilder; import gregtech.common.GT_Client; import gregtech.common.covers.GT_Cover_Drain; @@ -345,8 +347,8 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity { final IGregTechTileEntity gTank = tTank instanceof IGregTechTileEntity ? (IGregTechTileEntity) tTank : null; if (isConnectedAtSide(aSide) && tTank != null && (mLastReceivedFrom & (1 << aSide)) == 0 && - getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide).letsFluidOut(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSide(aSide), tFluid.getFluid(), getBaseMetaTileEntity()) && - (gTank == null || gTank.getCoverBehaviorAtSide(tSide).letsFluidIn(tSide, gTank.getCoverIDAtSide(tSide), gTank.getCoverDataAtSide(tSide), tFluid.getFluid(), gTank))) { + getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).letsFluidOut(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSideNew(aSide), tFluid.getFluid(), getBaseMetaTileEntity()) && + (gTank == null || gTank.getCoverBehaviorAtSideNew(tSide).letsFluidIn(tSide, gTank.getCoverIDAtSide(tSide), gTank.getCoverDataAtSideNew(tSide), tFluid.getFluid(), gTank))) { if (tTank.fill(ForgeDirection.getOrientation(tSide), tFluid, false) > 0) { tTanks.add(new MutableTriple<>(tTank, ForgeDirection.getOrientation(tSide), 0)); } @@ -419,6 +421,16 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity { return coverBehavior.letsFluidOut(aSide, aCoverID, aCoverVariable, null, aTileEntity); } + @Override + public boolean letsIn(GT_CoverBehavior_New coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return coverBehavior.letsFluidIn(aSide, aCoverID, aCoverVariable, null, aTileEntity); + } + + @Override + public boolean letsOut(GT_CoverBehavior_New coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return coverBehavior.letsFluidOut(aSide, aCoverID, aCoverVariable, null, aTileEntity); + } + @Override public boolean canConnect(byte aSide, TileEntity tTileEntity) { if (tTileEntity == null) @@ -429,7 +441,7 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity { if (baseMetaTile == null) return false; - final GT_CoverBehavior coverBehavior = baseMetaTile.getCoverBehaviorAtSide(aSide); + final GT_CoverBehavior_New coverBehavior = baseMetaTile.getCoverBehaviorAtSideNew(aSide); final IGregTechTileEntity gTileEntity = (tTileEntity instanceof IGregTechTileEntity) ? (IGregTechTileEntity) tTileEntity : null; if (coverBehavior instanceof GT_Cover_Drain || (GregTech_API.mTConstruct && isTConstructFaucet(tTileEntity))) @@ -442,7 +454,7 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity { if (tInfo != null) { return tInfo.length > 0 || (GregTech_API.mTranslocator && isTranslocator(tTileEntity)) - || gTileEntity != null && gTileEntity.getCoverBehaviorAtSide(tSide) instanceof GT_Cover_FluidRegulator; + || gTileEntity != null && gTileEntity.getCoverBehaviorAtSideNew(tSide) instanceof GT_Cover_FluidRegulator; } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java index edec79fe65..212a0e4acb 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java @@ -13,7 +13,9 @@ import gregtech.api.metatileentity.BaseMetaPipeEntity; import gregtech.api.metatileentity.MetaPipeEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_CoverBehavior; +import gregtech.api.util.GT_CoverBehavior_New; import gregtech.api.util.GT_Utility; +import gregtech.api.util.ISerializableObject; import gregtech.common.GT_Client; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -215,6 +217,16 @@ public class GT_MetaPipeEntity_Item extends MetaPipeEntity implements IMetaTileE return coverBehavior.letsItemsOut(aSide, aCoverID, aCoverVariable, -1, aTileEntity); } + @Override + public boolean letsIn(GT_CoverBehavior_New coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return coverBehavior.letsItemsIn(aSide, aCoverID, aCoverVariable, -1, aTileEntity); + } + + @Override + public boolean letsOut(GT_CoverBehavior_New coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return coverBehavior.letsItemsOut(aSide, aCoverID, aCoverVariable, -1, aTileEntity); + } + @Override public boolean canConnect(byte aSide, TileEntity tTileEntity) { if (tTileEntity == null) return false; @@ -271,7 +283,7 @@ public class GT_MetaPipeEntity_Item extends MetaPipeEntity implements IMetaTileE @Override public boolean insertItemStackIntoTileEntity(Object aSender, byte aSide) { - if (getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide).letsItemsOut(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSide(aSide), -1, getBaseMetaTileEntity())) { + if (getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).letsItemsOut(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSideNew(aSide), -1, getBaseMetaTileEntity())) { TileEntity tInventory = getBaseMetaTileEntity().getTileEntityAtSide(aSide); if (tInventory != null && !(tInventory instanceof BaseMetaPipeEntity)) { if ((!(tInventory instanceof TileEntityHopper) && !(tInventory instanceof TileEntityDispenser)) || getBaseMetaTileEntity().getMetaIDAtSide(aSide) != GT_Utility.getOppositeSide(aSide)) { @@ -320,7 +332,7 @@ public class GT_MetaPipeEntity_Item extends MetaPipeEntity implements IMetaTileE @Override public int[] getAccessibleSlotsFromSide(int aSide) { IGregTechTileEntity tTileEntity = getBaseMetaTileEntity(); - boolean tAllow = tTileEntity.getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSide((byte) aSide), -2, tTileEntity) || tTileEntity.getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSide((byte) aSide), -2, tTileEntity); + boolean tAllow = tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), -2, tTileEntity) || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), -2, tTileEntity); if (tAllow) { if (cacheSides == null) cacheSides = super.getAccessibleSlotsFromSide(aSide); diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java index 7c15137691..56d58d533c 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java @@ -10,6 +10,7 @@ import gregtech.api.interfaces.metatileentity.IMachineCallback; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.GT_ItemStack; import gregtech.api.render.TextureFactory; +import gregtech.api.util.GT_CoverBehavior_New; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Recipe; @@ -823,8 +824,9 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B @Override public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCoverID) { - return (aSide != mMainFacing || GregTech_API.getCoverBehavior(aCoverID.toStack()).isGUIClickable(aSide, GT_Utility.stackToInt(aCoverID.toStack()), 0, getBaseMetaTileEntity())); - } + if (aSide != mMainFacing) return true; + GT_CoverBehavior_New tBehavior = GregTech_API.getCoverBehaviorNew(aCoverID.toStack()); + return tBehavior.isGUIClickable(aSide, GT_Utility.stackToInt(aCoverID.toStack()), tBehavior.createDataObject(), getBaseMetaTileEntity());} @Override public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java index 3cdb26c9e1..d573c6bfd1 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java @@ -186,7 +186,7 @@ public abstract class GT_MetaTileEntity_BasicMachine_Bronze extends GT_MetaTileE @Override public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCoverID) { - return GregTech_API.getCoverBehavior(aCoverID.toStack()).isSimpleCover() && super.allowCoverOnSide(aSide, aCoverID); + return GregTech_API.getCoverBehaviorNew(aCoverID.toStack()).isSimpleCover() && super.allowCoverOnSide(aSide, aCoverID); } public float getSteamDamage() { diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java index 37a98162b8..4de809c19b 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java @@ -185,7 +185,7 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch { @Override public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (!getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSide(aSide), getBaseMetaTileEntity())) + if (!getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSideNew(aSide), getBaseMetaTileEntity())) return; if (aPlayer.isSneaking()) { if(disableSort) { diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java index 7c518dbd2d..26448cd931 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java @@ -202,7 +202,7 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch { @Override public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (!getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSide(aSide), getBaseMetaTileEntity())) + if (!getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSideNew(aSide), getBaseMetaTileEntity())) return; if (aPlayer.isSneaking()) { mMode = (byte) ((mMode + 9) % 10); @@ -269,7 +269,7 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch { } private boolean tryToLockHatch(EntityPlayer aPlayer, byte aSide) { - if (!getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSide(aSide), getBaseMetaTileEntity())) + if (!getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSideNew(aSide), getBaseMetaTileEntity())) return false; if (!isFluidLocked()) return false; diff --git a/src/main/java/gregtech/api/net/GT_Packet_TileEntityCover.java b/src/main/java/gregtech/api/net/GT_Packet_TileEntityCover.java index 29220e05ab..8035030f19 100644 --- a/src/main/java/gregtech/api/net/GT_Packet_TileEntityCover.java +++ b/src/main/java/gregtech/api/net/GT_Packet_TileEntityCover.java @@ -10,9 +10,8 @@ import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; /** - * Client -> Server: Update cover data + * Client -> Server: Update cover data. use this only if you are using the legacy data storage */ - public class GT_Packet_TileEntityCover extends GT_Packet_New { protected int mX; protected short mY; diff --git a/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverGUI.java b/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverGUI.java index 2a8091144d..e5cb184339 100644 --- a/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverGUI.java +++ b/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverGUI.java @@ -1,9 +1,11 @@ package gregtech.api.net; import com.google.common.io.ByteArrayDataInput; +import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.util.ISerializableObject; import gregtech.common.GT_Proxy; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; @@ -16,14 +18,14 @@ import net.minecraft.world.World; /** * Server -> Client: Show GUI */ - public class GT_Packet_TileEntityCoverGUI extends GT_Packet_New { protected int mX; protected short mY; protected int mZ; protected byte side; - protected int coverID, coverData, dimID, playerID; + protected int coverID, dimID, playerID; + protected ISerializableObject coverData; public GT_Packet_TileEntityCoverGUI() { super(true); @@ -37,12 +39,25 @@ public class GT_Packet_TileEntityCoverGUI extends GT_Packet_New { this.side = coverSide; this.coverID = coverID; - this.coverData = coverData; + this.coverData = new ISerializableObject.LegacyCoverData(coverData); this.dimID = dimID; this.playerID = playerID; } + public GT_Packet_TileEntityCoverGUI(int mX, short mY, int mZ, byte coverSide, int coverID, ISerializableObject coverData, int dimID, int playerID) { + super(false); + this.mX = mX; + this.mY = mY; + this.mZ = mZ; + + this.side = coverSide; + this.coverID = coverID; + this.coverData = coverData; + this.dimID = dimID; + this.playerID = playerID; + } + public GT_Packet_TileEntityCoverGUI(byte side, int coverID, int coverData, ICoverable tile, EntityPlayerMP aPlayer) { super(false); @@ -53,7 +68,7 @@ public class GT_Packet_TileEntityCoverGUI extends GT_Packet_New { this.side = side; this.coverID = coverID; - this.coverData = coverData; + this.coverData = new ISerializableObject.LegacyCoverData(coverData); this.dimID = tile.getWorld().provider.dimensionId; this.playerID = aPlayer.getEntityId(); @@ -67,11 +82,25 @@ public class GT_Packet_TileEntityCoverGUI extends GT_Packet_New { this.side = coverSide; this.coverID = coverID; - this.coverData = coverData; + this.coverData = new ISerializableObject.LegacyCoverData(coverData); this.dimID = tile.getWorld().provider.dimensionId; } + public GT_Packet_TileEntityCoverGUI(byte side, int coverID, ISerializableObject coverData, ICoverable tile, EntityPlayerMP aPlayer) { + super(false); + this.mX = tile.getXCoord(); + this.mY = tile.getYCoord(); + this.mZ = tile.getZCoord(); + + this.side = side; + this.coverID = coverID; + this.coverData = coverData.copy(); // make a copy so we don't get a race condition + + this.dimID = tile.getWorld().provider.dimensionId; + this.playerID = aPlayer.getEntityId(); + } + @Override public byte getPacketID() { return 7; @@ -85,7 +114,7 @@ public class GT_Packet_TileEntityCoverGUI extends GT_Packet_New { aOut.writeByte(side); aOut.writeInt(coverID); - aOut.writeInt(coverData); + coverData.writeToByteBuf(aOut); aOut.writeInt(dimID); aOut.writeInt(playerID); @@ -93,14 +122,15 @@ public class GT_Packet_TileEntityCoverGUI extends GT_Packet_New { @Override public GT_Packet_New decode(ByteArrayDataInput aData) { + int coverID; return new GT_Packet_TileEntityCoverGUI( aData.readInt(), aData.readShort(), aData.readInt(), aData.readByte(), - aData.readInt(), - aData.readInt(), + coverID = aData.readInt(), + GregTech_API.getCoverBehaviorNew(coverID).createDataObject().readFromPacket(aData, null), aData.readInt(), aData.readInt()); diff --git a/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverNew.java b/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverNew.java new file mode 100644 index 0000000000..f600fb1d82 --- /dev/null +++ b/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverNew.java @@ -0,0 +1,113 @@ +package gregtech.api.net; + +import com.google.common.io.ByteArrayDataInput; +import gregtech.api.GregTech_API; +import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.util.ISerializableObject; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.INetHandler; +import net.minecraft.network.NetHandlerPlayServer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.DimensionManager; + +/** + * Client -> Server: Update cover data + */ + +public class GT_Packet_TileEntityCoverNew extends GT_Packet_New { + protected int mX; + protected short mY; + protected int mZ; + + protected byte side; + protected int coverID, dimID; + protected ISerializableObject coverData; + + protected EntityPlayerMP mPlayer; + + public GT_Packet_TileEntityCoverNew() { + super(true); + } + + public GT_Packet_TileEntityCoverNew(int mX, short mY, int mZ, byte coverSide, int coverID, ISerializableObject coverData, int dimID) { + super(false); + this.mX = mX; + this.mY = mY; + this.mZ = mZ; + + this.side = coverSide; + this.coverID = coverID; + this.coverData = coverData; + + this.dimID = dimID; + } + public GT_Packet_TileEntityCoverNew(byte coverSide, int coverID, ISerializableObject coverData, ICoverable tile) { + super(false); + this.mX = tile.getXCoord(); + this.mY = tile.getYCoord(); + this.mZ = tile.getZCoord(); + + this.side = coverSide; + this.coverID = coverID; + this.coverData = coverData; + + this.dimID = tile.getWorld().provider.dimensionId; + } + + @Override + public byte getPacketID() { + return 11; + } + + @Override + public void setINetHandler(INetHandler aHandler) { + if (aHandler instanceof NetHandlerPlayServer) { + mPlayer = ((NetHandlerPlayServer) aHandler).playerEntity; + } + } + + @Override + public void encode(ByteBuf aOut) { + aOut.writeInt(mX); + aOut.writeShort(mY); + aOut.writeInt(mZ); + + aOut.writeByte(side); + aOut.writeInt(coverID); + coverData.writeToByteBuf(aOut); + + aOut.writeInt(dimID); + } + + @Override + public GT_Packet_New decode(ByteArrayDataInput aData) { + int coverId; + return new GT_Packet_TileEntityCoverNew( + aData.readInt(), + aData.readShort(), + aData.readInt(), + + aData.readByte(), + coverId = aData.readInt(), + GregTech_API.getCoverBehaviorNew(coverId).createDataObject().readFromPacket(aData, mPlayer), + + aData.readInt()); + } + + @Override + public void process(IBlockAccess aWorld) { + if (mPlayer == null) // impossible, but who knows + return; + World world = DimensionManager.getWorld(dimID); + if (world != null) { + TileEntity tile = world.getTileEntity(mX, mY, mZ); + if (tile instanceof IGregTechTileEntity && !((IGregTechTileEntity) tile).isDead()) { + ((IGregTechTileEntity) tile).receiveCoverData(side, coverID, coverData, mPlayer); + } + } + } +} diff --git a/src/main/java/gregtech/api/util/GT_CoverBehavior.java b/src/main/java/gregtech/api/util/GT_CoverBehavior.java index 14c8cc1308..db68a50cd2 100644 --- a/src/main/java/gregtech/api/util/GT_CoverBehavior.java +++ b/src/main/java/gregtech/api/util/GT_CoverBehavior.java @@ -3,21 +3,179 @@ package gregtech.api.util; import gregtech.api.enums.GT_Values; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.net.GT_Packet_TileEntityCoverGUI; -import gregtech.api.objects.GT_ItemStack; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; +import net.minecraft.world.World; import net.minecraftforge.fluids.Fluid; import static gregtech.api.enums.GT_Values.E; /** - * For Covers with a special behavior. + * For Covers with a special behavior. Has fixed storage format of 4 byte. Not very convenient... */ -public abstract class GT_CoverBehavior { +public abstract class GT_CoverBehavior extends GT_CoverBehavior_New { public EntityPlayer lastPlayer = null; + public GT_CoverBehavior() { + super(ISerializableObject.LegacyCoverData.class); + } + + private static int convert(ISerializableObject.LegacyCoverData data) { + return data == null ? 0 : data.get(); + } + + // region bridge the parent call to legacy calls + + @Override + public final ISerializableObject.LegacyCoverData createDataObject() { + return new ISerializableObject.LegacyCoverData(); + } + + @Override + public ISerializableObject.LegacyCoverData createDataObject(int aLegacyData) { + return new ISerializableObject.LegacyCoverData(aLegacyData); + } + + @Override + protected boolean isRedstoneSensitiveImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, long aTimer) { + return isRedstoneSensitive(aSide, aCoverID, aCoverVariable.get(), aTileEntity, aTimer); + } + + @Override + protected ISerializableObject.LegacyCoverData doCoverThingsImpl(byte aSide, byte aInputRedstone, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, long aTimer) { + if (aCoverVariable == null) + aCoverVariable = new ISerializableObject.LegacyCoverData(); + aCoverVariable.set(doCoverThings(aSide, aInputRedstone, aCoverID, aCoverVariable.get(), aTileEntity, aTimer)); + return aCoverVariable; + } + + @Override + protected boolean onCoverRightClickImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + return onCoverRightclick(aSide, aCoverID, convert(aCoverVariable), aTileEntity, aPlayer, aX, aY, aZ); + } + + @Override + protected ISerializableObject.LegacyCoverData onCoverScrewdriverClickImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aCoverVariable == null) + aCoverVariable = new ISerializableObject.LegacyCoverData(); + aCoverVariable.set(onCoverScrewdriverclick(aSide, aCoverID, convert(aCoverVariable), aTileEntity, aPlayer, aX, aY, aZ)); + return aCoverVariable; + } + + @Override + protected boolean onCoverShiftRightClickImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer) { + return onCoverShiftRightclick(aSide, aCoverID, convert(aCoverVariable), aTileEntity, aPlayer); + } + + @Override + protected Object getClientGUIImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, World aWorld) { + return getClientGUI(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + } + + @Override + protected boolean onCoverRemovalImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, boolean aForced) { + return onCoverRemoval(aSide, aCoverID, convert(aCoverVariable), aTileEntity, aForced); + } + + @Override + protected String getDescriptionImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return getDescription(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + } + + @Override + protected float getBlastProofLevelImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return getBlastProofLevel(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + } + + @Override + protected boolean letsRedstoneGoInImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return letsRedstoneGoIn(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + } + + @Override + protected boolean letsRedstoneGoOutImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return letsRedstoneGoOut(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + } + + @Override + protected boolean letsFibreGoInImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return letsFibreGoIn(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + } + + @Override + protected boolean letsFibreGoOutImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return letsFibreGoOut(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + } + + @Override + protected boolean letsEnergyInImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return letsEnergyIn(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + } + + @Override + protected boolean letsEnergyOutImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return letsEnergyOut(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + } + + @Override + protected boolean letsFluidInImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return letsFluidIn(aSide, aCoverID, convert(aCoverVariable), aFluid, aTileEntity); + } + + @Override + protected boolean letsFluidOutImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return letsFluidOut(aSide, aCoverID, convert(aCoverVariable), aFluid, aTileEntity); + } + + @Override + protected boolean letsItemsInImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, int aSlot, ICoverable aTileEntity) { + return letsItemsIn(aSide, aCoverID, convert(aCoverVariable), aSlot, aTileEntity); + } + + @Override + protected boolean letsItemsOutImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, int aSlot, ICoverable aTileEntity) { + return letsItemsOut(aSide, aCoverID, convert(aCoverVariable), aSlot, aTileEntity); + } + + @Override + protected boolean isGUIClickableImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return isGUIClickable(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + } + + @Override + protected boolean manipulatesSidedRedstoneOutputImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return manipulatesSidedRedstoneOutput(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + } + + @Override + protected boolean alwaysLookConnectedImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return alwaysLookConnected(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + } + + @Override + protected byte getRedstoneInputImpl(byte aSide, byte aInputRedstone, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return getRedstoneInput(aSide, aInputRedstone, aCoverID, convert(aCoverVariable), aTileEntity); + } + + @Override + protected int getTickRateImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return getTickRate(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + } + + @Override + protected byte getLensColorImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return getLensColor(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + } + + @Override + protected ItemStack getDropImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return getDrop(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + } + + // endregion + public boolean isRedstoneSensitive(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { return true; } @@ -38,15 +196,6 @@ public abstract class GT_CoverBehavior { return false; } - /** - * Called when someone rightclicks this Cover Client Side - *

- * return true, if something actually happens. - */ - public boolean onCoverRightclickClient(byte aSide, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { - return false; - } - /** * Called when someone rightclicks this Cover with a Screwdriver. Doesn't call @onCoverRightclick in this Case. *

@@ -68,21 +217,10 @@ public abstract class GT_CoverBehavior { return false; } - public boolean hasCoverGUI() { - return false; - } - public Object getClientGUI(byte aSide, int aCoverID, int coverData, ICoverable aTileEntity) { return null; } - /** - * Checks if the Cover can be placed on this. - */ - public boolean isCoverPlaceable(byte aSide, GT_ItemStack aStack, ICoverable aTileEntity) { - return true; - } - /** * Removes the Cover if this returns true, or if aForced is true. * Doesn't get called when the Machine Block is getting broken, only if you break the Cover away from the Machine. @@ -218,13 +356,6 @@ public abstract class GT_CoverBehavior { return 0; } - /** - * If this is a simple Cover, which can also be used on Bronze Machines and similar. - */ - public boolean isSimpleCover() { - return false; - } - /** * The MC Color of this Lens. -1 for no Color (meaning this isn't a Lens then). */ @@ -238,15 +369,4 @@ public abstract class GT_CoverBehavior { public ItemStack getDrop(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return GT_OreDictUnificator.get(true, aTileEntity.getCoverItemAtSide(aSide)); } - - /** - * @return sets the Cover upon placement. - */ - public void placeCover(byte aSide, ItemStack aCover, ICoverable aTileEntity) { - aTileEntity.setCoverIDAtSide(aSide, GT_Utility.stackToInt(aCover)); - } - - public String trans(String aNr, String aEnglish){ - return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_"+aNr, aEnglish, false); - } } diff --git a/src/main/java/gregtech/api/util/GT_CoverBehavior_New.java b/src/main/java/gregtech/api/util/GT_CoverBehavior_New.java new file mode 100644 index 0000000000..4dafcbe931 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_CoverBehavior_New.java @@ -0,0 +1,480 @@ +package gregtech.api.util; + +import gregtech.api.enums.GT_Values; +import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.net.GT_Packet_TileEntityCoverGUI; +import gregtech.api.objects.GT_ItemStack; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.world.World; +import net.minecraftforge.fluids.Fluid; + +import static gregtech.api.enums.GT_Values.E; + +/** + * For Covers with a special behavior. + */ +public abstract class GT_CoverBehavior_New { + + public EntityPlayer lastPlayer = null; + private final Class typeToken; + + protected GT_CoverBehavior_New(Class typeToken) { + this.typeToken = typeToken; + } + + public abstract T createDataObject(int aLegacyData); + + public abstract T createDataObject(); + + public T createDataObject(NBTBase aNBT) { + T ret = createDataObject(); + ret.loadDataFromNBT(aNBT); + return ret; + } + + public final T cast(ISerializableObject aData) { + if (typeToken.isInstance(aData)) + return forceCast(aData); + return null; + } + + private T forceCast(ISerializableObject aData) { + return typeToken.cast(aData); + } + + // region facade + + public final boolean isRedstoneSensitive(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, long aTimer) { + return isRedstoneSensitiveImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aTimer); + } + + /** + * Called by updateEntity inside the covered TileEntity. aCoverVariable is the Value you returned last time. + */ + public final T doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, long aTimer) { + return doCoverThingsImpl(aSide, aInputRedstone, aCoverID, forceCast(aCoverVariable), aTileEntity, aTimer); + } + + /** + * Called when someone rightclicks this Cover. + *

+ * return true, if something actually happens. + */ + public final boolean onCoverRightClick(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + return onCoverRightClickImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer, aX, aY, aZ); + } + + /** + * Called when someone rightclicks this Cover with a Screwdriver. Doesn't call @onCoverRightclick in this Case. + *

+ * return the new Value of the Cover Variable + */ + public final T onCoverScrewdriverClick(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + return onCoverScrewdriverClickImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer, aX, aY, aZ); + } + + /** + * Called when someone shift-rightclicks this Cover with no tool. Doesn't call @onCoverRightclick in this Case. + */ + public final boolean onCoverShiftRightClick(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer) { + return onCoverShiftRightClickImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer); + } + + public final Object getClientGUI(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, World aWorld) { + return getClientGUIImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer, aWorld); + } + + /** + * Removes the Cover if this returns true, or if aForced is true. + * Doesn't get called when the Machine Block is getting broken, only if you break the Cover away from the Machine. + */ + public final boolean onCoverRemoval(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, boolean aForced) { + return onCoverRemovalImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aForced); + } + + /** + * Gives a small Text for the status of the Cover. + */ + public final String getDescription(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return getDescriptionImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * How Blast Proof the Cover is. 30 is normal. + */ + public final float getBlastProofLevel(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return getBlastProofLevelImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * If it lets RS-Signals into the Block + *

+ * This is just Informative so that Machines know if their Redstone Input is blocked or not + */ + public final boolean letsRedstoneGoIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return letsRedstoneGoInImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * If it lets RS-Signals out of the Block + */ + public final boolean letsRedstoneGoOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return letsRedstoneGoOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * If it lets Fibre-Signals into the Block + *

+ * This is just Informative so that Machines know if their Redstone Input is blocked or not + */ + public final boolean letsFibreGoIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return letsFibreGoInImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * If it lets Fibre-Signals out of the Block + */ + public final boolean letsFibreGoOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return letsFibreGoOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * If it lets Energy into the Block + */ + public final boolean letsEnergyIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return letsEnergyInImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * If it lets Energy out of the Block + */ + public final boolean letsEnergyOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return letsEnergyOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * If it lets Liquids into the Block, aFluid can be null meaning if this is generally allowing Fluids or not. + */ + public final boolean letsFluidIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return letsFluidInImpl(aSide, aCoverID, forceCast(aCoverVariable), aFluid, aTileEntity); + } + + /** + * If it lets Liquids out of the Block, aFluid can be null meaning if this is generally allowing Fluids or not. + */ + public final boolean letsFluidOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return letsFluidOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aFluid, aTileEntity); + } + + /** + * If it lets Items into the Block, aSlot = -1 means if it is generally accepting Items (return false for no eraction at all), aSlot = -2 means if it would accept for all Slots Impl(return true to skip the Checks for each Slot). + */ + public final boolean letsItemsIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, int aSlot, ICoverable aTileEntity) { + return letsItemsInImpl(aSide, aCoverID, forceCast(aCoverVariable), aSlot, aTileEntity); + } + + /** + * If it lets Items out of the Block, aSlot = -1 means if it is generally accepting Items (return false for no eraction at all), aSlot = -2 means if it would accept for all Slots Impl(return true to skip the Checks for each Slot). + */ + public final boolean letsItemsOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, int aSlot, ICoverable aTileEntity) { + return letsItemsOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aSlot, aTileEntity); + } + + /** + * If it lets you rightclick the Machine normally + */ + public final boolean isGUIClickable(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return isGUIClickableImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * Needs to return true for Covers, which have a Redstone Output on their Facing. + */ + public final boolean manipulatesSidedRedstoneOutput(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return manipulatesSidedRedstoneOutputImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * if this Cover should let Pipe Connections look connected even if it is not the case. + */ + public final boolean alwaysLookConnected(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return alwaysLookConnectedImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * Called to determine the incoming Redstone Signal of a Machine. + * Returns the original Redstone per default. + * The Cover should @letsRedstoneGoIn or the aInputRedstone Parameter is always 0. + */ + public final byte getRedstoneInput(byte aSide, byte aInputRedstone, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return getRedstoneInputImpl(aSide, aInputRedstone, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * Gets the Tick Rate for doCoverThings of the Cover + *

+ * 0 = No Ticks! Yes, 0 is Default, you have to override this + */ + public final int getTickRate(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return getTickRateImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + + /** + * The MC Color of this Lens. -1 for no Color (meaning this isn't a Lens then). + */ + public final byte getLensColor(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return getLensColorImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * @return the ItemStack dropped by this Cover + */ + public final ItemStack getDrop(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return getDropImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + // endregion + + // region impl + + protected boolean isRedstoneSensitiveImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, long aTimer) { + return true; + } + + /** + * Called by updateEntity inside the covered TileEntity. aCoverVariable is the Value you returned last time. + */ + protected T doCoverThingsImpl(byte aSide, byte aInputRedstone, int aCoverID, T aCoverVariable, ICoverable aTileEntity, long aTimer) { + return aCoverVariable; + } + + /** + * Called when someone rightclicks this Cover. + *

+ * return true, if something actually happens. + */ + protected boolean onCoverRightClickImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + return false; + } + + /** + * Called when someone rightclicks this Cover with a Screwdriver. Doesn't call @onCoverRightclick in this Case. + *

+ * return the new Value of the Cover Variable + */ + protected T onCoverScrewdriverClickImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + return aCoverVariable; + } + + /** + * Called when someone shift-rightclicks this Cover with no tool. Doesn't call @onCoverRightclick in this Case. + */ + protected boolean onCoverShiftRightClickImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer) { + if (hasCoverGUI() && aPlayer instanceof EntityPlayerMP) { + lastPlayer = aPlayer; + GT_Values.NW.sendToPlayer(new GT_Packet_TileEntityCoverGUI(aSide, aCoverID, aCoverVariable, aTileEntity, (EntityPlayerMP) aPlayer), (EntityPlayerMP) aPlayer); + return true; + } + return false; + } + + protected Object getClientGUIImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, World aWorld) { + return null; + } + + /** + * Removes the Cover if this returns true, or if aForced is true. + * Doesn't get called when the Machine Block is getting broken, only if you break the Cover away from the Machine. + */ + protected boolean onCoverRemovalImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, boolean aForced) { + return true; + } + + /** + * Gives a small Text for the status of the Cover. + */ + protected String getDescriptionImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return E; + } + + /** + * How Blast Proof the Cover is. 30 is normal. + */ + protected float getBlastProofLevelImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return 10.0F; + } + + /** + * If it lets RS-Signals into the Block + *

+ * This is just Informative so that Machines know if their Redstone Input is blocked or not + */ + protected boolean letsRedstoneGoInImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets RS-Signals out of the Block + */ + protected boolean letsRedstoneGoOutImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Fibre-Signals into the Block + *

+ * This is just Informative so that Machines know if their Redstone Input is blocked or not + */ + protected boolean letsFibreGoInImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Fibre-Signals out of the Block + */ + protected boolean letsFibreGoOutImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Energy into the Block + */ + protected boolean letsEnergyInImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Energy out of the Block + */ + protected boolean letsEnergyOutImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Liquids into the Block, aFluid can be null meaning if this is generally allowing Fluids or not. + */ + protected boolean letsFluidInImpl(byte aSide, int aCoverID, T aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Liquids out of the Block, aFluid can be null meaning if this is generally allowing Fluids or not. + */ + protected boolean letsFluidOutImpl(byte aSide, int aCoverID, T aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Items into the Block, aSlot = -1 means if it is generally accepting Items (return false for no Interaction at all), aSlot = -2 means if it would accept for all Slots (return true to skip the Checks for each Slot). + */ + protected boolean letsItemsInImpl(byte aSide, int aCoverID, T aCoverVariable, int aSlot, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Items out of the Block, aSlot = -1 means if it is generally accepting Items (return false for no Interaction at all), aSlot = -2 means if it would accept for all Slots (return true to skip the Checks for each Slot). + */ + protected boolean letsItemsOutImpl(byte aSide, int aCoverID, T aCoverVariable, int aSlot, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets you rightclick the Machine normally + */ + protected boolean isGUIClickableImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * Needs to return true for Covers, which have a Redstone Output on their Facing. + */ + protected boolean manipulatesSidedRedstoneOutputImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * if this Cover should let Pipe Connections look connected even if it is not the case. + */ + protected boolean alwaysLookConnectedImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * Called to determine the incoming Redstone Signal of a Machine. + * Returns the original Redstone per default. + * The Cover should @letsRedstoneGoIn or the aInputRedstone Parameter is always 0. + */ + protected byte getRedstoneInputImpl(byte aSide, byte aInputRedstone, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return letsRedstoneGoIn(aSide, aCoverID, aCoverVariable, aTileEntity) ? aInputRedstone : 0; + } + + /** + * Gets the Tick Rate for doCoverThings of the Cover + *

+ * 0 = No Ticks! Yes, 0 is Default, you have to override this + */ + protected int getTickRateImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return 0; + } + + + /** + * The MC Color of this Lens. -1 for no Color (meaning this isn't a Lens then). + */ + protected byte getLensColorImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return -1; + } + + /** + * @return the ItemStack dropped by this Cover + */ + protected ItemStack getDropImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return GT_OreDictUnificator.get(true, aTileEntity.getCoverItemAtSide(aSide)); + } + + //endregion + + // region no data + + /** + * Checks if the Cover can be placed on this. + */ + public boolean isCoverPlaceable(byte aSide, GT_ItemStack aStack, ICoverable aTileEntity) { + return true; + } + + public boolean hasCoverGUI() { + return false; + } + + /** + * Called when someone rightclicks this Cover Client Side + *

+ * return true, if something actually happens. + */ + public boolean onCoverRightclickClient(byte aSide, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + return false; + } + + /** + * If this is a simple Cover, which can also be used on Bronze Machines and similar. + */ + public boolean isSimpleCover() { + return false; + } + + /** + * sets the Cover upon placement. + */ + public void placeCover(byte aSide, ItemStack aCover, ICoverable aTileEntity) { + aTileEntity.setCoverIDAtSide(aSide, GT_Utility.stackToInt(aCover)); + } + + public String trans(String aNr, String aEnglish) { + return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_" + aNr, aEnglish, false); + } + // endregion +} diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 2ae09b6adf..08b10e4fdf 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -2157,7 +2157,7 @@ public class GT_Utility { try { if (tTileEntity instanceof ICoverable) { rEUAmount += 300; - String tString = ((ICoverable) tTileEntity).getCoverBehaviorAtSide((byte) aSide).getDescription((byte) aSide, ((ICoverable) tTileEntity).getCoverIDAtSide((byte) aSide), ((ICoverable) tTileEntity).getCoverDataAtSide((byte) aSide), (ICoverable) tTileEntity); + String tString = ((ICoverable) tTileEntity).getCoverBehaviorAtSideNew((byte) aSide).getDescription((byte) aSide, ((ICoverable) tTileEntity).getCoverIDAtSide((byte) aSide), ((ICoverable) tTileEntity).getCoverDataAtSideNew((byte) aSide), (ICoverable) tTileEntity); if (tString != null && !tString.equals(E)) tList.add(tString); } } catch (Throwable e) { diff --git a/src/main/java/gregtech/api/util/ISerializableObject.java b/src/main/java/gregtech/api/util/ISerializableObject.java new file mode 100644 index 0000000000..1a38aee5f7 --- /dev/null +++ b/src/main/java/gregtech/api/util/ISerializableObject.java @@ -0,0 +1,107 @@ +package gregtech.api.util; + +import com.google.common.io.ByteArrayDataInput; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagInt; + +import javax.annotation.Nonnull; + +/** + * We could well have used {@link java.io.Serializable}, but that's too slow and should generally be avoided + */ +public interface ISerializableObject { + + @Nonnull + ISerializableObject copy(); + + @Nonnull + NBTBase saveDataToNBT(); + + /** + * Write data to given ByteBuf + * The data saved this way is intended to be stored for short amount of time over network. + * DO NOT store it to disks. + */ + // the NBT is an unfortunate piece of tech. everything uses it but its API is not as efficient as could be + void writeToByteBuf(ByteBuf aBuf); + + void loadDataFromNBT(NBTBase aNBT); + + /** + * Read data from given parameter and return this. + * The data read this way is intended to be stored for short amount of time over network. + */ + // the NBT is an unfortunate piece of tech. everything uses it but its API is not as efficient as could be + @Nonnull + ISerializableObject readFromPacket(ByteArrayDataInput aBuf, EntityPlayerMP aPlayer); + + final class LegacyCoverData implements ISerializableObject { + private int mData; + + public LegacyCoverData() { + } + + public LegacyCoverData(int mData) { + this.mData = mData; + } + + @Override + @Nonnull + public ISerializableObject copy() { + return new LegacyCoverData(mData); + } + + @Override + @Nonnull + public NBTBase saveDataToNBT() { + return new NBTTagInt(mData); + } + + @Override + public void writeToByteBuf(ByteBuf aBuf) { + aBuf.writeInt(mData); + } + + @Override + public void loadDataFromNBT(NBTBase aNBT) { + mData = aNBT instanceof NBTBase.NBTPrimitive ? ((NBTBase.NBTPrimitive) aNBT).func_150287_d() : 0; + } + + @Override + @Nonnull + public ISerializableObject readFromPacket(ByteArrayDataInput aBuf, EntityPlayerMP aPlayer) { + mData = aBuf.readInt(); + return this; + } + + public int get() { + return mData; + } + + public void set(int mData) { + this.mData = mData; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + LegacyCoverData that = (LegacyCoverData) o; + + return mData == that.mData; + } + + @Override + public int hashCode() { + return mData; + } + + @Override + public String toString() { + return String.valueOf(mData); + } + } +} diff --git a/src/main/java/gregtech/common/GT_Network.java b/src/main/java/gregtech/common/GT_Network.java index c9c57676ad..97e511aba4 100644 --- a/src/main/java/gregtech/common/GT_Network.java +++ b/src/main/java/gregtech/common/GT_Network.java @@ -36,7 +36,7 @@ public class GT_Network extends MessageToMessageCodec public GT_Network() { this.mChannel = NetworkRegistry.INSTANCE.newChannel("GregTech", this, new HandlerShared()); - this.mSubChannels = new GT_Packet[]{new GT_Packet_TileEntity(), new GT_Packet_Sound(), new GT_Packet_Block_Event(), new GT_Packet_Ores(), new GT_Packet_Pollution(), new MessageSetFlaskCapacity(), new GT_Packet_TileEntityCover(), new GT_Packet_TileEntityCoverGUI(), new MessageUpdateFluidDisplayItem(), new GT_Packet_ClientPreference(), new GT_Packet_WirelessRedstoneCover()}; + this.mSubChannels = new GT_Packet[]{new GT_Packet_TileEntity(), new GT_Packet_Sound(), new GT_Packet_Block_Event(), new GT_Packet_Ores(), new GT_Packet_Pollution(), new MessageSetFlaskCapacity(), new GT_Packet_TileEntityCover(), new GT_Packet_TileEntityCoverGUI(), new MessageUpdateFluidDisplayItem(), new GT_Packet_ClientPreference(), new GT_Packet_WirelessRedstoneCover(), new GT_Packet_TileEntityCoverNew()}; } @Override diff --git a/src/main/java/gregtech/common/covers/GT_Cover_Arm.java b/src/main/java/gregtech/common/covers/GT_Cover_Arm.java index ed60929719..c64aaa16a1 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_Arm.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_Arm.java @@ -11,6 +11,7 @@ import gregtech.api.interfaces.tileentity.IMachineProgress; import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; +import gregtech.api.util.ISerializableObject; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; @@ -111,6 +112,16 @@ public class GT_Cover_Arm extends GT_CoverBehavior { } @Override + protected boolean onCoverRightClickImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + int step = (GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ)[0] >= 0.5F) ? 1 : -1; + int tCoverVariable = getNewVar(aCoverVariable.get(), step); + sendMessageToPlayer(aPlayer, tCoverVariable); + aCoverVariable.set(tCoverVariable); + return true; + } + + @Override + @SuppressWarnings("deprecation") public boolean onCoverRightclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { int step = (GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ)[0] >= 0.5F) ? 1 : -1; aCoverVariable = getNewVar(aCoverVariable, step); diff --git a/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java b/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java index a53545802a..83a8f20ea9 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java @@ -9,6 +9,7 @@ import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; +import gregtech.api.util.ISerializableObject; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.common.util.ForgeDirection; @@ -136,6 +137,18 @@ public class GT_Cover_FluidRegulator extends GT_CoverBehavior { } @Override + protected boolean onCoverRightClickImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ)[0] >= 0.5F) { + aCoverVariable.set(adjustSpeed(aPlayer, aCoverVariable.get(), 1)); + } else { + aCoverVariable.set(adjustSpeed(aPlayer, aCoverVariable.get(), -1)); + } + aTileEntity.setCoverDataAtSide(aSide, aCoverVariable); + return true; + } + + @Override + @SuppressWarnings("deprecation") public boolean onCoverRightclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { if (GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ)[0] >= 0.5F) { diff --git a/src/main/java/gregtech/common/covers/GT_Cover_Fluidfilter.java b/src/main/java/gregtech/common/covers/GT_Cover_Fluidfilter.java index 7aab35ddaa..dce38d4f1f 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_Fluidfilter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_Fluidfilter.java @@ -1,22 +1,33 @@ package gregtech.common.covers; +import com.google.common.io.ByteArrayDataInput; import gregtech.api.enums.GT_Values; import gregtech.api.gui.GT_GUICover; import gregtech.api.gui.widgets.GT_GuiFakeItemButton; import gregtech.api.gui.widgets.GT_GuiIcon; import gregtech.api.gui.widgets.GT_GuiIconButton; import gregtech.api.interfaces.tileentity.ICoverable; -import gregtech.api.net.GT_Packet_TileEntityCover; -import gregtech.api.util.GT_CoverBehavior; +import gregtech.api.net.GT_Packet_TileEntityCoverNew; +import gregtech.api.util.GT_CoverBehavior_New; import gregtech.api.util.GT_Utility; +import gregtech.api.util.ISerializableObject; +import io.netty.buffer.ByteBuf; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.*; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import javax.annotation.Nonnull; import static gregtech.api.enums.GT_Values.E; -public class GT_Cover_Fluidfilter extends GT_CoverBehavior { +public class GT_Cover_Fluidfilter extends GT_CoverBehavior_New { // Uses the lower 3 bits of the cover variable, so we have 8 options to work with (0-7) private final int FILTER_INPUT_DENY_OUTPUT = 0; // 000 @@ -28,99 +39,115 @@ public class GT_Cover_Fluidfilter extends GT_CoverBehavior { private final int ANY_INPUT_FILTER_OUTPUT = 6; // 110 private final int ANY_INPUT_INVERT_OUTPUT = 7; // 111 + public GT_Cover_Fluidfilter() { + super(FluidFilterData.class); + } + + @Override + public FluidFilterData createDataObject() { + return new FluidFilterData(-1, 0); + } + + @Override + public FluidFilterData createDataObject(int aLegacyData) { + return new FluidFilterData(aLegacyData >>> 3, aLegacyData & 0x7); + } + @Override - public String getDescription(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { - int aFilterMode = aCoverVariable & 7; - int aFilterFluid = aCoverVariable >>> 3; - final Fluid fluid = FluidRegistry.getFluid(aFilterFluid); - if(fluid == null) return E; - + protected String getDescriptionImpl(byte aSide, int aCoverID, FluidFilterData aCoverVariable, ICoverable aTileEntity) { + final Fluid fluid = FluidRegistry.getFluid(aCoverVariable.mFluidID); + if (fluid == null) return E; + final FluidStack sFluid = new FluidStack(fluid, 1000); - return(String.format("Filtering Fluid: %s Mode: %s", sFluid.getLocalizedName(), getFilterMode(aFilterMode))); + return (String.format("Filtering Fluid: %s Mode: %s", sFluid.getLocalizedName(), getFilterMode(aCoverVariable.mFilterMode))); } @Override - public boolean isRedstoneSensitive(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { + protected boolean isRedstoneSensitiveImpl(byte aSide, int aCoverID, FluidFilterData aCoverVariable, ICoverable aTileEntity, long aTimer) { return false; } @Override - public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { + protected FluidFilterData doCoverThingsImpl(byte aSide, byte aInputRedstone, int aCoverID, FluidFilterData aCoverVariable, ICoverable aTileEntity, long aTimer) { return aCoverVariable; } public String getFilterMode(int aFilterMode) { - switch(aFilterMode) { - case FILTER_INPUT_DENY_OUTPUT: return(trans("043", "Filter input, Deny output")); - case INVERT_INPUT_DENY_OUTPUT: return(trans("044", "Invert input, Deny output")); - case FILTER_INPUT_ANY_OUTPUT: return(trans("045", "Filter input, Permit any output")); - case INVERT_INPUT_ANY_OUTPUT: return(trans("046", "Invert input, Permit any output")); - case DENY_INPUT_FILTER_OUTPUT: return(trans("219", "Deny input, Filter output")); - case DENY_INPUT_INVERT_OUTPUT: return(trans("220", "Deny input, Invert output")); - case ANY_INPUT_FILTER_OUTPUT: return(trans("221", "Permit any input, Filter output")); - case ANY_INPUT_INVERT_OUTPUT: return(trans("222", "Permit any input, Invert output")); - default: return("UNKNOWN"); + switch (aFilterMode) { + case FILTER_INPUT_DENY_OUTPUT: + return (trans("043", "Filter input, Deny output")); + case INVERT_INPUT_DENY_OUTPUT: + return (trans("044", "Invert input, Deny output")); + case FILTER_INPUT_ANY_OUTPUT: + return (trans("045", "Filter input, Permit any output")); + case INVERT_INPUT_ANY_OUTPUT: + return (trans("046", "Invert input, Permit any output")); + case DENY_INPUT_FILTER_OUTPUT: + return (trans("219", "Deny input, Filter output")); + case DENY_INPUT_INVERT_OUTPUT: + return (trans("220", "Deny input, Invert output")); + case ANY_INPUT_FILTER_OUTPUT: + return (trans("221", "Permit any input, Filter output")); + case ANY_INPUT_INVERT_OUTPUT: + return (trans("222", "Permit any input, Invert output")); + default: + return ("UNKNOWN"); } } @Override - public int onCoverScrewdriverclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { - int aFilterMode = aCoverVariable & 7; - aCoverVariable ^= aFilterMode; - aFilterMode = (aFilterMode + (aPlayer.isSneaking()? -1 : 1)) % 8; - if (aFilterMode < 0) { - aFilterMode = 7; + protected FluidFilterData onCoverScrewdriverClickImpl(byte aSide, int aCoverID, FluidFilterData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + aCoverVariable.mFilterMode = (aCoverVariable.mFilterMode + (aPlayer.isSneaking() ? -1 : 1)) % 8; + if (aCoverVariable.mFilterMode < 0) { + aCoverVariable.mFilterMode = 7; } - GT_Utility.sendChatToPlayer(aPlayer, getFilterMode(aFilterMode)); - - aCoverVariable|=aFilterMode; + GT_Utility.sendChatToPlayer(aPlayer, getFilterMode(aCoverVariable.mFilterMode)); return aCoverVariable; } @Override - public boolean onCoverRightclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { - //GT_FML_LOGGER.info("rightclick"); + protected boolean onCoverRightClickImpl(byte aSide, int aCoverID, FluidFilterData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { if ( ((aX > 0.375D) && (aX < 0.625D)) || - ((aSide > 3) && ((aY > 0.375D) && (aY < 0.625D))) || - ((aSide < 2) && ((aZ > 0.375D) && (aZ < 0.625D))) || - (aSide == 2) || - (aSide == 3) + ((aSide > 3) && ((aY > 0.375D) && (aY < 0.625D))) || + ((aSide < 2) && ((aZ > 0.375D) && (aZ < 0.625D))) || + (aSide == 2) || + (aSide == 3) ) { ItemStack tStack = aPlayer.inventory.getCurrentItem(); if (tStack == null) return true; - FluidStack tFluid = FluidContainerRegistry.getFluidForFilledItem(tStack); + FluidStack tFluid = GT_Utility.getFluidForFilledItem(tStack, true); if (tFluid != null) { int aFluid = tFluid.getFluidID(); - aCoverVariable = (aCoverVariable & 7) | (aFluid << 3); + aCoverVariable.mFluidID = aFluid; aTileEntity.setCoverDataAtSide(aSide, aCoverVariable); FluidStack sFluid = new FluidStack(FluidRegistry.getFluid(aFluid), 1000); GT_Utility.sendChatToPlayer(aPlayer, trans("047", "Filter Fluid: ") + sFluid.getLocalizedName()); - } else if (tStack.getItem() instanceof IFluidContainerItem) { - IFluidContainerItem tContainer = (IFluidContainerItem) tStack.getItem(); - if (tContainer.getFluid(tStack) != null) { - int aFluid = tContainer.getFluid(tStack).getFluidID(); - aCoverVariable = (aCoverVariable & 7) | (aFluid << 3); - aTileEntity.setCoverDataAtSide(aSide, aCoverVariable); - FluidStack sFluid = new FluidStack(FluidRegistry.getFluid(aFluid), 1000); - GT_Utility.sendChatToPlayer(aPlayer, trans("047", "Filter Fluid: ") + sFluid.getLocalizedName()); - } } return true; } return false; } - + + @Override + protected boolean letsFluidInImpl(byte aSide, int aCoverID, FluidFilterData aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return isFluidAllowed(aCoverVariable, aFluid); + } + @Override - public boolean letsFluidIn(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + protected boolean letsFluidOutImpl(byte aSide, int aCoverID, FluidFilterData aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return isFluidAllowed(aCoverVariable, aFluid); + } + + protected boolean isFluidAllowed(FluidFilterData aCoverVariable, Fluid aFluid) { if (aFluid == null) return true; - int aFilterMode = aCoverVariable & 7; - int aFilterFluid = aCoverVariable >>> 3; + int aFilterMode = aCoverVariable.mFilterMode; + int aFilterFluid = aCoverVariable.mFluidID; if (aFilterMode == DENY_INPUT_FILTER_OUTPUT || aFilterMode == DENY_INPUT_INVERT_OUTPUT) return false; @@ -130,36 +157,18 @@ public class GT_Cover_Fluidfilter extends GT_CoverBehavior { return aFilterMode == FILTER_INPUT_DENY_OUTPUT || aFilterMode == FILTER_INPUT_ANY_OUTPUT; else return aFilterMode == INVERT_INPUT_DENY_OUTPUT || aFilterMode == INVERT_INPUT_ANY_OUTPUT; - } - - @Override - public boolean letsFluidOut(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { - if (aFluid == null) return true; - int aFilterMode = aCoverVariable & 7; - int aFilterFluid = aCoverVariable >>> 3; - - if (aFilterMode == FILTER_INPUT_DENY_OUTPUT || aFilterMode == INVERT_INPUT_DENY_OUTPUT) - return false; - else if (aFilterMode == FILTER_INPUT_ANY_OUTPUT || aFilterMode == INVERT_INPUT_ANY_OUTPUT) - return true; - else if (aFluid.getID() == aFilterFluid) - return aFilterMode == DENY_INPUT_FILTER_OUTPUT || aFilterMode == ANY_INPUT_FILTER_OUTPUT; - else - return aFilterMode == DENY_INPUT_INVERT_OUTPUT || aFilterMode == ANY_INPUT_INVERT_OUTPUT; - - } - @Override - public boolean alwaysLookConnected(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + protected boolean alwaysLookConnectedImpl(byte aSide, int aCoverID, FluidFilterData aCoverVariable, ICoverable aTileEntity) { return true; } @Override - public int getTickRate(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + protected int getTickRateImpl(byte aSide, int aCoverID, FluidFilterData aCoverVariable, ICoverable aTileEntity) { return 0; } + /** * GUI Stuff */ @@ -170,14 +179,14 @@ public class GT_Cover_Fluidfilter extends GT_CoverBehavior { } @Override - public Object getClientGUI(byte aSide, int aCoverID, int coverData, ICoverable aTileEntity) { + protected Object getClientGUIImpl(byte aSide, int aCoverID, FluidFilterData coverData, ICoverable aTileEntity, EntityPlayer aPlayer, World aWorld) { return new GT_FluidFilterGUICover(aSide, aCoverID, coverData, aTileEntity); } private class GT_FluidFilterGUICover extends GT_GUICover { private final byte side; private final int coverID; - private int coverVariable; + private final FluidFilterData coverVariable; private final GT_GuiFakeItemButton fluidFilterButton; protected String fluidFilterName; @@ -186,8 +195,7 @@ public class GT_Cover_Fluidfilter extends GT_CoverBehavior { private static final int spaceX = 18; private static final int spaceY = 18; - public GT_FluidFilterGUICover(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) - { + public GT_FluidFilterGUICover(byte aSide, int aCoverID, FluidFilterData aCoverVariable, ICoverable aTileEntity) { super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); this.side = aSide; this.coverID = aCoverID; @@ -201,35 +209,38 @@ public class GT_Cover_Fluidfilter extends GT_CoverBehavior { b = new GT_GuiIconButton(this, 4, startX + spaceX*0, startY+spaceY*1, GT_GuiIcon.WHITELIST).setTooltipText(trans("236","Whitelist Fluid")); b = new GT_GuiIconButton(this, 5, startX + spaceX*1, startY+spaceY*1, GT_GuiIcon.BLACKLIST).setTooltipText(trans("237","Blacklist Fluid")); - fluidFilterButton = new GT_GuiFakeItemButton(this, startX, startY+spaceY*3+2, GT_GuiIcon.SLOT_DARKGRAY); + fluidFilterButton = new GT_GuiFakeItemButton(this, startX, startY + spaceY * 3 + 2, GT_GuiIcon.SLOT_DARKGRAY); } - private int getNewCoverVariable(int id) { + private int getNewFilterMode(int id) { switch (id) { case 0: - return (coverVariable & ~0x7) | (coverVariable & 0x3); + return (coverVariable.mFilterMode & 0x3); case 1: - return (coverVariable & ~0x7) | (coverVariable | 0x4); + return (coverVariable.mFilterMode | 0x4); case 2: - return (coverVariable & ~0x7) | (coverVariable & 0x5); + return (coverVariable.mFilterMode & 0x5); case 3: - return (coverVariable & ~0x7) | (coverVariable | 0x2); + return (coverVariable.mFilterMode | 0x2); case 4: - return (coverVariable & ~0x7) | (coverVariable & 0x6); + return (coverVariable.mFilterMode & 0x6); case 5: - return (coverVariable & ~0x7) | (coverVariable | 0x1); + return (coverVariable.mFilterMode | 0x1); } - return coverVariable; + return coverVariable.mFilterMode; } private boolean getClickable(int id) { switch (id) { - case 0: case 1: - return (coverVariable>>2 & 0x1) != (id & 0x1); - case 2: case 3: - return (coverVariable>>1 & 0x1) != (id & 0x1); - case 4: case 5: - return (coverVariable & 0x1) != (id & 0x1); + case 0: + case 1: + return (coverVariable.mFilterMode >> 2 & 0x1) != (id & 0x1); + case 2: + case 3: + return (coverVariable.mFilterMode >> 1 & 0x1) != (id & 0x1); + case 4: + case 5: + return (coverVariable.mFilterMode & 0x1) != (id & 0x1); } return false; } @@ -250,15 +261,15 @@ public class GT_Cover_Fluidfilter extends GT_CoverBehavior { } @Override - public void buttonClicked(GuiButton btn){ - if (getClickable(btn.id)){ - coverVariable = getNewCoverVariable(btn.id); - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile)); + public void buttonClicked(GuiButton btn) { + if (getClickable(btn.id)) { + coverVariable.mFilterMode = (byte) getNewFilterMode(btn.id); + GT_Values.NW.sendToServer(new GT_Packet_TileEntityCoverNew(side, coverID, coverVariable, tile)); } updateButtons(); } - private void updateButtons(){ + private void updateButtons() { GT_GuiIconButton b; for (Object o : buttonList) { if (o instanceof GT_GuiIconButton) { @@ -277,7 +288,7 @@ public class GT_Cover_Fluidfilter extends GT_CoverBehavior { } } } - Fluid f = FluidRegistry.getFluid(coverVariable >>> 3); + Fluid f = FluidRegistry.getFluid(coverVariable.mFluidID); if (f != null) { ItemStack item = GT_Utility.getFluidDisplayStack(f); if (item != null) { @@ -290,4 +301,51 @@ public class GT_Cover_Fluidfilter extends GT_CoverBehavior { fluidFilterName = trans("224", "Filter Empty"); } } + + public static class FluidFilterData implements ISerializableObject { + private int mFluidID; + private int mFilterMode; + + public FluidFilterData(int mFluidID, int mFilterMode) { + this.mFluidID = mFluidID; + this.mFilterMode = mFilterMode; + } + + @Override + @Nonnull + public ISerializableObject copy() { + return new FluidFilterData(mFluidID, mFilterMode); + } + + @Override + @Nonnull + public NBTBase saveDataToNBT() { + NBTTagCompound tNBT = new NBTTagCompound(); + tNBT.setInteger("mFilterMode", mFilterMode); + tNBT.setString("mFluid", FluidRegistry.getFluid(mFluidID).getName()); + return tNBT; + } + + @Override + public void writeToByteBuf(ByteBuf aBuf) { + aBuf.writeByte(mFilterMode).writeInt(mFluidID); + } + + @Override + public void loadDataFromNBT(NBTBase aNBT) { + if (aNBT instanceof NBTTagCompound) { + NBTTagCompound tNBT = (NBTTagCompound) aNBT; + mFilterMode = tNBT.getByte("mFilterMod"); + mFluidID = FluidRegistry.getFluidID(tNBT.getString("mFluid")); + } + } + + @Override + @Nonnull + public ISerializableObject readFromPacket(ByteArrayDataInput aBuf, EntityPlayerMP aPlayer) { + mFilterMode = aBuf.readByte(); + mFluidID = aBuf.readInt(); + return this; + } + } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java b/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java index 99003e18e0..97f989035d 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java @@ -9,6 +9,7 @@ import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; +import gregtech.api.util.ISerializableObject; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -18,7 +19,9 @@ import net.minecraftforge.fluids.Fluid; import java.util.Collections; import java.util.List; -import static gregtech.api.util.GT_Utility.*; +import static gregtech.api.util.GT_Utility.intToStack; +import static gregtech.api.util.GT_Utility.moveMultipleItemStacks; +import static gregtech.api.util.GT_Utility.stackToInt; public class GT_Cover_ItemFilter extends GT_CoverBehavior { @@ -52,6 +55,22 @@ public class GT_Cover_ItemFilter extends GT_CoverBehavior { } @Override + protected boolean onCoverRightClickImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + ItemStack tStack = aPlayer.inventory.getCurrentItem(); + int tCoverVariable = aCoverVariable.get() & 1; + if (tStack != null) { + tCoverVariable = (stackToInt(tStack) << 1) + tCoverVariable; + aCoverVariable.set(tCoverVariable); + GT_Utility.sendChatToPlayer(aPlayer, trans("301", "Item Filter: ") + tStack.getDisplayName()); + } else { + aCoverVariable.set(tCoverVariable); + GT_Utility.sendChatToPlayer(aPlayer, trans("300", "Filter Cleared!")); + } + return true; + } + + @Override + @SuppressWarnings("deprecation") public boolean onCoverRightclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ){ ItemStack tStack = aPlayer.inventory.getCurrentItem(); if (tStack != null){ diff --git a/src/main/java/gregtech/common/covers/GT_Cover_ItemMeter.java b/src/main/java/gregtech/common/covers/GT_Cover_ItemMeter.java index f1c1bc7df7..0bd90745a4 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_ItemMeter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_ItemMeter.java @@ -6,13 +6,10 @@ import gregtech.api.gui.widgets.GT_GuiFakeItemButton; import gregtech.api.gui.widgets.GT_GuiIcon; import gregtech.api.gui.widgets.GT_GuiIconCheckButton; import gregtech.api.gui.widgets.GT_GuiIntegerTextBox; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.ICoverable; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; -import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_OutputBus_ME; import gregtech.common.tileentities.storage.GT_MetaTileEntity_DigitalChestBase; import net.minecraft.client.gui.GuiButton; @@ -46,22 +43,13 @@ public class GT_Cover_ItemMeter extends GT_CoverBehavior { long tMax = 0; long tUsed = 0; - IMetaTileEntity mte = ((IGregTechTileEntity)aTileEntity).getMetaTileEntity(); - if (mte instanceof GT_MetaTileEntity_DigitalChestBase) { - GT_MetaTileEntity_DigitalChestBase dc = (GT_MetaTileEntity_DigitalChestBase)mte; + if (aTileEntity instanceof GT_MetaTileEntity_DigitalChestBase) { + GT_MetaTileEntity_DigitalChestBase dc = (GT_MetaTileEntity_DigitalChestBase)aTileEntity; tMax = dc.getMaxItemCount(); // currently it is limited by int, but there is not much reason for that ItemStack[] inv = dc.getStoredItemData(); if (inv != null && inv.length > 1 && inv[1] != null) tUsed = inv[1].stackSize; - } - else if (mte instanceof GT_MetaTileEntity_Hatch_OutputBus_ME) { - if (((GT_MetaTileEntity_Hatch_OutputBus_ME)mte).isLastOutputFailed()) - { - tMax = 64; - tUsed = 64; - } - } - else { + } else { int[] tSlots = (aCoverVariable & SLOT_MASK) > 0 ? new int[] {(aCoverVariable & SLOT_MASK) - 1} : aTileEntity.getAccessibleSlotsFromSide(aSide); diff --git a/src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java b/src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java index 577cff3d7a..62f8d3550b 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java @@ -12,6 +12,7 @@ import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.net.GT_Packet_WirelessRedstoneCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; +import gregtech.api.util.ISerializableObject; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.fluids.Fluid; @@ -25,14 +26,26 @@ public abstract class GT_Cover_RedstoneWirelessBase extends GT_CoverBehavior { @Override public boolean onCoverRemoval(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, boolean aForced) { - GregTech_API.sWirelessRedstone.put(Integer.valueOf(aCoverVariable), Byte.valueOf((byte) 0)); + GregTech_API.sWirelessRedstone.put(aCoverVariable, (byte) 0); return true; } @Override + protected boolean onCoverRightClickImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (((aX > 0.375D) && (aX < 0.625D)) || ((aSide > 3) && ((aY > 0.375D) && (aY < 0.625D)))) { + GregTech_API.sWirelessRedstone.put(aCoverVariable.get(), (byte) 0); + aCoverVariable.set((aCoverVariable.get() & (PRIVATE_MASK | CHECKBOX_MASK)) | (((Integer)GT_Utility.stackToInt(aPlayer.inventory.getCurrentItem())).hashCode() & PUBLIC_MASK)); + GT_Utility.sendChatToPlayer(aPlayer, trans("081", "Frequency: ") + aCoverVariable); + return true; + } + return false; + } + + @Override + @SuppressWarnings("deprecation") public boolean onCoverRightclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { if (((aX > 0.375D) && (aX < 0.625D)) || ((aSide > 3) && ((aY > 0.375D) && (aY < 0.625D)))) { - GregTech_API.sWirelessRedstone.put(Integer.valueOf(aCoverVariable), Byte.valueOf((byte) 0)); + GregTech_API.sWirelessRedstone.put(aCoverVariable, (byte) 0); int val = GT_Utility.stackToInt(aPlayer.inventory.getCurrentItem()) * (1 + aPlayer.inventory.getCurrentItem().getItemDamage()); @@ -48,7 +61,7 @@ public abstract class GT_Cover_RedstoneWirelessBase extends GT_CoverBehavior { @Override public int onCoverScrewdriverclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { if (((aX > 0.375D) && (aX < 0.625D)) || ((aSide <= 3) || (((aY > 0.375D) && (aY < 0.625D)) || ((((aZ <= 0.375D) || (aZ >= 0.625D))))))) { - GregTech_API.sWirelessRedstone.put(Integer.valueOf(aCoverVariable), Byte.valueOf((byte) 0)); + GregTech_API.sWirelessRedstone.put(aCoverVariable, (byte) 0); float[] tCoords = GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ); short tAdjustVal = 0; diff --git a/src/main/java/gregtech/common/covers/GT_Cover_SolarPanel.java b/src/main/java/gregtech/common/covers/GT_Cover_SolarPanel.java index ae1b73b8cb..09a9d5ab69 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_SolarPanel.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_SolarPanel.java @@ -3,6 +3,7 @@ package gregtech.common.covers; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; +import gregtech.api.util.ISerializableObject; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; @@ -58,6 +59,29 @@ public class GT_Cover_SolarPanel extends GT_CoverBehavior { } @Override + protected boolean onCoverRightClickImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if(aPlayer.capabilities.isCreativeMode){ + GT_Utility.sendChatToPlayer(aPlayer,"Cleaned solar panel from "+(aCoverVariable.get()>>2)+"% dirt"); + aCoverVariable.set(aCoverVariable.get() & 0x3); + return true; + } + for(int i=0;i>2)+"% dirt"); + aCoverVariable.set(aCoverVariable.get() & 0x3); + return true; + } + } + GT_Utility.sendChatToPlayer(aPlayer,"You need water bucket in inventory to clean the panel."); + return false; + } + + @Override + @SuppressWarnings("deprecation") public boolean onCoverRightclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { if(aPlayer.capabilities.isCreativeMode){ GT_Utility.sendChatToPlayer(aPlayer,"Cleaned solar panel from "+(aCoverVariable>>2)+"% dirt"); diff --git a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler.java b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler.java index 4fb9deb5b4..96b991e767 100644 --- a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler.java +++ b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler.java @@ -175,7 +175,7 @@ public abstract class GT_MetaTileEntity_Boiler extends GT_MetaTileEntity_BasicTa @Override public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCover) { - return GregTech_API.getCoverBehavior(aCover.toStack()).isSimpleCover(); + return GregTech_API.getCoverBehaviorNew(aCover.toStack()).isSimpleCover(); } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PrimitiveBlastFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PrimitiveBlastFurnace.java index eab4e9c896..61fb394841 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PrimitiveBlastFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PrimitiveBlastFurnace.java @@ -114,7 +114,7 @@ public abstract class GT_MetaTileEntity_PrimitiveBlastFurnace extends MetaTileEn @Override public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCoverID) { - return (GregTech_API.getCoverBehavior(aCoverID.toStack()).isSimpleCover()) && (super.allowCoverOnSide(aSide, aCoverID)); + return (GregTech_API.getCoverBehaviorNew(aCoverID.toStack()).isSimpleCover()) && (super.allowCoverOnSide(aSide, aCoverID)); } @Override -- cgit From ea9df088740cf44d8f77275b17f519127750bf4f Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Tue, 16 Nov 2021 06:46:29 +0800 Subject: convert ItemFilter to use NBTTagCompound storage Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../api/gui/widgets/GT_GuiIconCheckButton.java | 12 +- .../gregtech/api/util/ISerializableObject.java | 41 ++++ .../common/covers/GT_Cover_ItemFilter.java | 214 +++++++++++---------- 3 files changed, 166 insertions(+), 101 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiIconCheckButton.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiIconCheckButton.java index 010ac78654..e7b6b9971d 100644 --- a/src/main/java/gregtech/api/gui/widgets/GT_GuiIconCheckButton.java +++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiIconCheckButton.java @@ -3,13 +3,22 @@ package gregtech.api.gui.widgets; import gregtech.api.interfaces.IGuiScreen; public class GT_GuiIconCheckButton extends GT_GuiIconButton { - private GT_GuiIcon checkedIcon, normalIcon; + private final GT_GuiIcon checkedIcon; + private final GT_GuiIcon normalIcon; + private final String checkedTooltip; + private final String normalTooltip; private boolean checked = false; public GT_GuiIconCheckButton(IGuiScreen gui, int id, int x, int y, GT_GuiIcon checkedIcon, GT_GuiIcon normalIcon) { + this(gui, id, x, y, checkedIcon, normalIcon, null, null); + } + + public GT_GuiIconCheckButton(IGuiScreen gui, int id, int x, int y, GT_GuiIcon checkedIcon, GT_GuiIcon normalIcon, String checkedTooltip, String normalTooltip) { super(gui, id, x, y, normalIcon); this.checkedIcon = checkedIcon; this.normalIcon = normalIcon; + this.checkedTooltip = checkedTooltip; + this.normalTooltip = normalTooltip; } @Override @@ -27,6 +36,7 @@ public class GT_GuiIconCheckButton extends GT_GuiIconButton { public void setChecked(boolean checked) { super.setIcon(checked ? checkedIcon : normalIcon); + super.setTooltipText(checked ? checkedTooltip : normalTooltip); this.checked = checked; } } diff --git a/src/main/java/gregtech/api/util/ISerializableObject.java b/src/main/java/gregtech/api/util/ISerializableObject.java index 1a38aee5f7..4ca5b1e543 100644 --- a/src/main/java/gregtech/api/util/ISerializableObject.java +++ b/src/main/java/gregtech/api/util/ISerializableObject.java @@ -3,10 +3,16 @@ package gregtech.api.util; import com.google.common.io.ByteArrayDataInput; import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTSizeTracker; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagInt; import javax.annotation.Nonnull; +import java.io.IOException; /** * We could well have used {@link java.io.Serializable}, but that's too slow and should generally be avoided @@ -37,6 +43,41 @@ public interface ISerializableObject { @Nonnull ISerializableObject readFromPacket(ByteArrayDataInput aBuf, EntityPlayerMP aPlayer); + /** + * Reverse engineered and adapted {@link cpw.mods.fml.common.network.ByteBufUtils#readTag(ByteBuf)} + * Given buffer must contain a serialized NBTTagCompound in minecraft encoding + */ + static NBTTagCompound readCompoundTagFromGreggyByteBuf(ByteArrayDataInput aBuf) { + short size = aBuf.readShort(); + if (size < 0) + return null; + else { + byte[] buf = new byte[size]; // this is shit, how many copies have we been doing? + aBuf.readFully(buf); + try { + return CompressedStreamTools.func_152457_a(buf, new NBTSizeTracker(2097152L)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + /** + * Reverse engineered and adapted {@link cpw.mods.fml.common.network.ByteBufUtils#readItemStack(ByteBuf)} + * Given buffer must contain a serialized ItemStack in minecraft encoding + */ + static ItemStack readItemStackFromGreggyByteBuf(ByteArrayDataInput aBuf) { + ItemStack stack = null; + short id = aBuf.readShort(); + if (id >= 0) { + byte size = aBuf.readByte(); + short meta = aBuf.readShort(); + stack = new ItemStack(Item.getItemById(id), size, meta); + stack.stackTagCompound = readCompoundTagFromGreggyByteBuf(aBuf); + } + return stack; + } + final class LegacyCoverData implements ISerializableObject { private int mData; diff --git a/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java b/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java index 97f989035d..ab7aeee861 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java @@ -1,153 +1,142 @@ package gregtech.common.covers; +import com.google.common.io.ByteArrayDataInput; +import cpw.mods.fml.common.network.ByteBufUtils; import gregtech.api.enums.GT_Values; import gregtech.api.gui.GT_GUICover; import gregtech.api.gui.widgets.GT_GuiFakeItemButton; import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconButton; +import gregtech.api.gui.widgets.GT_GuiIconCheckButton; import gregtech.api.interfaces.tileentity.ICoverable; -import gregtech.api.net.GT_Packet_TileEntityCover; -import gregtech.api.util.GT_CoverBehavior; +import gregtech.api.net.GT_Packet_TileEntityCoverNew; +import gregtech.api.util.GT_CoverBehavior_New; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; +import io.netty.buffer.ByteBuf; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.Constants; import net.minecraftforge.fluids.Fluid; +import javax.annotation.Nonnull; import java.util.Collections; import java.util.List; import static gregtech.api.util.GT_Utility.intToStack; import static gregtech.api.util.GT_Utility.moveMultipleItemStacks; -import static gregtech.api.util.GT_Utility.stackToInt; -public class GT_Cover_ItemFilter extends GT_CoverBehavior { +public class GT_Cover_ItemFilter extends GT_CoverBehavior_New { private final boolean mExport; - public GT_Cover_ItemFilter(boolean isExport){ + public GT_Cover_ItemFilter(boolean isExport) { + super(ItemFilterData.class); this.mExport = isExport; } @Override - public boolean isRedstoneSensitive(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { + public ItemFilterData createDataObject(int aLegacyData) { + return new ItemFilterData((aLegacyData & 0x1) == 0, intToStack(aLegacyData >>> 1)); + } + + @Override + public ItemFilterData createDataObject() { + return new ItemFilterData(); + } + + @Override + protected boolean isRedstoneSensitiveImpl(byte aSide, int aCoverID, ItemFilterData aCoverVariable, ICoverable aTileEntity, long aTimer) { return false; } @Override - public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { + protected ItemFilterData doCoverThingsImpl(byte aSide, byte aInputRedstone, int aCoverID, ItemFilterData aCoverVariable, ICoverable aTileEntity, long aTimer) { TileEntity tTileEntity = aTileEntity.getTileEntityAtSide(aSide); Object fromEntity = mExport ? aTileEntity : tTileEntity, toEntity = !mExport ? aTileEntity : tTileEntity; byte fromSide = !mExport ? GT_Utility.getOppositeSide(aSide) : aSide, toSide = mExport ? GT_Utility.getOppositeSide(aSide) : aSide; - int FilterId = aCoverVariable >>> 1; - List Filter = Collections.singletonList(intToStack(FilterId)); + List Filter = Collections.singletonList(aCoverVariable.mFilter); - boolean isWhiteList = (aCoverVariable & 1) != 0; - - moveMultipleItemStacks(fromEntity, toEntity, fromSide , toSide, Filter, isWhiteList, (byte) 64, (byte) 1, (byte) 64, (byte) 1,64); + moveMultipleItemStacks(fromEntity, toEntity, fromSide, toSide, Filter, aCoverVariable.mWhitelist, (byte) 64, (byte) 1, (byte) 64, (byte) 1, 64); return aCoverVariable; } @Override - protected boolean onCoverRightClickImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + protected boolean onCoverRightClickImpl(byte aSide, int aCoverID, ItemFilterData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { ItemStack tStack = aPlayer.inventory.getCurrentItem(); - int tCoverVariable = aCoverVariable.get() & 1; if (tStack != null) { - tCoverVariable = (stackToInt(tStack) << 1) + tCoverVariable; - aCoverVariable.set(tCoverVariable); + aCoverVariable.mFilter = tStack; GT_Utility.sendChatToPlayer(aPlayer, trans("301", "Item Filter: ") + tStack.getDisplayName()); } else { - aCoverVariable.set(tCoverVariable); + aCoverVariable.mFilter = null; GT_Utility.sendChatToPlayer(aPlayer, trans("300", "Filter Cleared!")); } return true; } @Override - @SuppressWarnings("deprecation") - public boolean onCoverRightclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ){ - ItemStack tStack = aPlayer.inventory.getCurrentItem(); - if (tStack != null){ - aCoverVariable = (stackToInt(tStack) << 1) + (aCoverVariable & 1); - aTileEntity.setCoverDataAtSide(aSide, aCoverVariable); - GT_Utility.sendChatToPlayer(aPlayer, trans("301", "Item Filter: ") + tStack.getDisplayName()); - } - else{ - aCoverVariable = aCoverVariable & 1; - aTileEntity.setCoverDataAtSide(aSide, aCoverVariable); - GT_Utility.sendChatToPlayer(aPlayer, trans("300", "Filter Cleared!")); - } - return true; - } - - @Override - public int onCoverScrewdriverclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { - int mode = aCoverVariable & 1; - if (mode == 1) mode = 0; - else mode = 1; - if (mode == 1){ - GT_Utility.sendChatToPlayer(aPlayer, trans("124", "Blacklist Mode")); - } - else{ - GT_Utility.sendChatToPlayer(aPlayer, trans("125", "Whitelist Mode")); - } - aCoverVariable = (aCoverVariable & ~0x1) + mode; + protected ItemFilterData onCoverScrewdriverClickImpl(byte aSide, int aCoverID, ItemFilterData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + aCoverVariable.mWhitelist = !aCoverVariable.mWhitelist; + GT_Utility.sendChatToPlayer(aPlayer, aCoverVariable.mWhitelist ? trans("125", "Whitelist Mode") : trans("124", "Blacklist Mode")); return aCoverVariable; } @Override - public boolean letsRedstoneGoIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + protected boolean letsRedstoneGoInImpl(byte aSide, int aCoverID, ItemFilterData aCoverVariable, ICoverable aTileEntity) { return true; } @Override - public boolean letsRedstoneGoOut(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + protected boolean letsRedstoneGoOutImpl(byte aSide, int aCoverID, ItemFilterData aCoverVariable, ICoverable aTileEntity) { return true; } @Override - public boolean letsEnergyIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + protected boolean letsEnergyInImpl(byte aSide, int aCoverID, ItemFilterData aCoverVariable, ICoverable aTileEntity) { return true; } @Override - public boolean letsEnergyOut(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + protected boolean letsEnergyOutImpl(byte aSide, int aCoverID, ItemFilterData aCoverVariable, ICoverable aTileEntity) { return true; } @Override - public boolean letsFluidIn(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + protected boolean letsFluidInImpl(byte aSide, int aCoverID, ItemFilterData aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { return false; } @Override - public boolean letsFluidOut(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + protected boolean letsFluidOutImpl(byte aSide, int aCoverID, ItemFilterData aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { return false; } @Override - public boolean letsItemsIn(byte aSide, int aCoverID, int aCoverVariable, int aSlot, ICoverable aTileEntity) { + protected boolean letsItemsInImpl(byte aSide, int aCoverID, ItemFilterData aCoverVariable, int aSlot, ICoverable aTileEntity) { return true; } @Override - public boolean letsItemsOut(byte aSide, int aCoverID, int aCoverVariable, int aSlot, ICoverable aTileEntity) { + protected boolean letsItemsOutImpl(byte aSide, int aCoverID, ItemFilterData aCoverVariable, int aSlot, ICoverable aTileEntity) { return true; } @Override - public boolean alwaysLookConnected(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + protected boolean alwaysLookConnectedImpl(byte aSide, int aCoverID, ItemFilterData aCoverVariable, ICoverable aTileEntity) { return true; } @Override - public int getTickRate(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + protected int getTickRateImpl(byte aSide, int aCoverID, ItemFilterData aCoverVariable, ICoverable aTileEntity) { return 1; } @@ -161,14 +150,68 @@ public class GT_Cover_ItemFilter extends GT_CoverBehavior { } @Override - public Object getClientGUI(byte aSide, int aCoverID, int coverData, ICoverable aTileEntity) { - return new GT_Cover_ItemFilter.GUI(aSide, aCoverID, coverData, aTileEntity); + protected Object getClientGUIImpl(byte aSide, int aCoverID, ItemFilterData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, World aWorld) { + return new GT_Cover_ItemFilter.GUI(aSide, aCoverID, aCoverVariable, aTileEntity); + } + + public static class ItemFilterData implements ISerializableObject { + private boolean mWhitelist; + private ItemStack mFilter; + + public ItemFilterData() { + } + + public ItemFilterData(boolean mWhitelist, ItemStack mFilter) { + this.mWhitelist = mWhitelist; + this.mFilter = mFilter; + } + + @Nonnull + @Override + public ISerializableObject copy() { + return new ItemFilterData(mWhitelist, mFilter); + } + + @Nonnull + @Override + public NBTBase saveDataToNBT() { + NBTTagCompound tag = new NBTTagCompound(); + tag.setBoolean("mWhitelist", mWhitelist); + if (mFilter != null) + tag.setTag("mFilter", mFilter.writeToNBT(new NBTTagCompound())); + return tag; + } + + @Override + public void writeToByteBuf(ByteBuf aBuf) { + aBuf.writeBoolean(mWhitelist); + ByteBufUtils.writeItemStack(aBuf, mFilter); + } + + @Override + public void loadDataFromNBT(NBTBase aNBT) { + NBTTagCompound tag = (NBTTagCompound) aNBT; + mWhitelist = tag.getBoolean("mWhitelist"); + if (tag.hasKey("mFilter", Constants.NBT.TAG_COMPOUND)) + mFilter = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("mFilter")); + else + mFilter = null; + } + + @Nonnull + @Override + public ISerializableObject readFromPacket(ByteArrayDataInput aBuf, EntityPlayerMP aPlayer) { + mWhitelist = aBuf.readBoolean(); + mFilter = ISerializableObject.readItemStackFromGreggyByteBuf(aBuf); + return this; + } } private class GUI extends GT_GUICover { private final byte side; private final int coverID; - private int coverVariable; + private final GT_GuiIconCheckButton btnMode; + private final ItemFilterData coverVariable; private final GT_GuiFakeItemButton itemFilterButtons; private static final int startX = 10; @@ -176,17 +219,15 @@ public class GT_Cover_ItemFilter extends GT_CoverBehavior { private static final int spaceX = 18; private static final int spaceY = 18; - public GUI(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public GUI(byte aSide, int aCoverID, ItemFilterData aCoverVariable, ICoverable aTileEntity) { super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); this.side = aSide; this.coverID = aCoverID; this.coverVariable = aCoverVariable; - GT_GuiIconButton b; - b = new GT_GuiIconButton(this, 0, startX + spaceX*0, startY+spaceY*0, GT_GuiIcon.WHITELIST).setTooltipText(trans("125","Whitelist Mode")); - b = new GT_GuiIconButton(this, 1, startX + spaceX*1, startY+spaceY*0, GT_GuiIcon.BLACKLIST).setTooltipText(trans("124","Blacklist Mode")); + btnMode = new GT_GuiIconCheckButton(this, 0, startX + spaceX * 0, startY + spaceY * 0, GT_GuiIcon.WHITELIST, GT_GuiIcon.BLACKLIST, trans("125", "Whitelist Mode"), trans("124", "Blacklist Mode")); - itemFilterButtons = new GT_GuiFakeItemButton(this ,startX + spaceX*0, startY+spaceY*2, GT_GuiIcon.SLOT_GRAY); + itemFilterButtons = new GT_GuiFakeItemButton(this, startX + spaceX * 0, startY + spaceY * 2, GT_GuiIcon.SLOT_GRAY); } @Override @@ -202,46 +243,19 @@ public class GT_Cover_ItemFilter extends GT_CoverBehavior { } @Override - public void buttonClicked(GuiButton btn){ - if (getClickable(btn.id)){ - coverVariable = getNewCoverVariable(btn.id); - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile)); + public void buttonClicked(GuiButton btn) { + if (btn == btnMode) { + if (coverVariable.mWhitelist != btnMode.isChecked()) { + coverVariable.mWhitelist = btnMode.isChecked(); + GT_Values.NW.sendToServer(new GT_Packet_TileEntityCoverNew(side, coverID, coverVariable, tile)); + } } updateButtons(); } - private void updateButtons(){ - GuiButton b; - for (Object o : buttonList) { - b = (GuiButton) o; - b.enabled = getClickable(b.id); - } - ItemStack tItemStack = intToStack(coverVariable >>> 1); - if (tItemStack != null){ - itemFilterButtons.setItem(tItemStack); - return; - } - itemFilterButtons.setItem(null); - } - - private int getNewCoverVariable(int id) { - switch (id) { - case 0: - return coverVariable & ~0x1; - case 1: - return coverVariable | 0x1; - } - return coverVariable; - } - - private boolean getClickable(int id) { - switch (id) { - case 0: - return (0x1 & coverVariable) != 0; - case 1: - return (0x1 & coverVariable) == 0; - } - return false; + private void updateButtons() { + btnMode.setChecked(coverVariable.mWhitelist); + itemFilterButtons.setItem(coverVariable.mFilter); } } } -- cgit From 44b9f91081c628b28f8ca6dd8f2ac94b7d52d374 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Tue, 16 Nov 2021 07:03:45 +0800 Subject: put my names on it somehow Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- src/main/java/gregtech/api/util/GT_CoverBehavior_New.java | 2 ++ src/main/java/gregtech/api/util/ISerializableObject.java | 2 ++ 2 files changed, 4 insertions(+) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_CoverBehavior_New.java b/src/main/java/gregtech/api/util/GT_CoverBehavior_New.java index 4dafcbe931..3e2c2f856f 100644 --- a/src/main/java/gregtech/api/util/GT_CoverBehavior_New.java +++ b/src/main/java/gregtech/api/util/GT_CoverBehavior_New.java @@ -15,6 +15,8 @@ import static gregtech.api.enums.GT_Values.E; /** * For Covers with a special behavior. + * + * @author glease */ public abstract class GT_CoverBehavior_New { diff --git a/src/main/java/gregtech/api/util/ISerializableObject.java b/src/main/java/gregtech/api/util/ISerializableObject.java index 4ca5b1e543..51fa40e55a 100644 --- a/src/main/java/gregtech/api/util/ISerializableObject.java +++ b/src/main/java/gregtech/api/util/ISerializableObject.java @@ -16,6 +16,8 @@ import java.io.IOException; /** * We could well have used {@link java.io.Serializable}, but that's too slow and should generally be avoided + * + * @author glease */ public interface ISerializableObject { -- cgit From 449f9506ee48a19fd89a632779f30bc999a69b9e Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Wed, 17 Nov 2021 11:17:55 +0800 Subject: Rename GT_CoverBehavior_New to GT_CoverBehaviorBase Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- src/main/java/gregtech/api/GregTech_API.java | 20 +- .../metatileentity/IMetaTileEntityItemPipe.java | 8 +- .../api/interfaces/tileentity/ICoverable.java | 6 +- .../api/metatileentity/BaseMetaPipeEntity.java | 44 +- .../api/metatileentity/BaseMetaTileEntity.java | 50 +-- .../api/metatileentity/MetaPipeEntity.java | 12 +- .../api/metatileentity/MetaTileEntity.java | 4 +- .../implementations/GT_MetaPipeEntity_Cable.java | 9 +- .../implementations/GT_MetaPipeEntity_Fluid.java | 12 +- .../implementations/GT_MetaPipeEntity_Item.java | 10 +- .../GT_MetaTileEntity_BasicMachine.java | 4 +- .../GT_MetaTileEntity_Hatch_InputBus.java | 2 +- .../GT_MetaTileEntity_Hatch_Output.java | 4 +- .../java/gregtech/api/util/GT_CoverBehavior.java | 2 +- .../gregtech/api/util/GT_CoverBehaviorBase.java | 482 +++++++++++++++++++++ .../gregtech/api/util/GT_CoverBehavior_New.java | 482 --------------------- src/main/java/gregtech/api/util/GT_Utility.java | 13 +- .../common/covers/GT_Cover_Fluidfilter.java | 4 +- .../common/covers/GT_Cover_ItemFilter.java | 4 +- 19 files changed, 581 insertions(+), 591 deletions(-) create mode 100644 src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java delete mode 100644 src/main/java/gregtech/api/util/GT_CoverBehavior_New.java (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/GregTech_API.java b/src/main/java/gregtech/api/GregTech_API.java index 0d321423fc..ff875c4884 100644 --- a/src/main/java/gregtech/api/GregTech_API.java +++ b/src/main/java/gregtech/api/GregTech_API.java @@ -113,7 +113,7 @@ public class GregTech_API { /** * The List of Cover Behaviors for the Covers */ - public static final Map> sCoverBehaviors = new ConcurrentHashMap<>(); + public static final Map> sCoverBehaviors = new ConcurrentHashMap<>(); /** * The List of Circuit Behaviors for the Redstone Circuit Block */ @@ -615,10 +615,10 @@ public class GregTech_API { } public static void registerCover(ItemStack aStack, ITexture aCover, GT_CoverBehavior aBehavior) { - registerCover(aStack, aCover, (GT_CoverBehavior_New) aBehavior); + registerCover(aStack, aCover, (GT_CoverBehaviorBase) aBehavior); } - public static void registerCover(ItemStack aStack, ITexture aCover, GT_CoverBehavior_New aBehavior) { + public static void registerCover(ItemStack aStack, ITexture aCover, GT_CoverBehaviorBase aBehavior) { if (!sCovers.containsKey(new GT_ItemStack(aStack))) sCovers.put(new GT_ItemStack(aStack), aCover == null || !aCover.isValidTexture() ? Textures.BlockIcons.ERROR_RENDERING[0] : aCover); if (aBehavior != null) @@ -626,10 +626,10 @@ public class GregTech_API { } public static void registerCoverBehavior(ItemStack aStack, GT_CoverBehavior aBehavior) { - registerCoverBehavior(aStack, (GT_CoverBehavior_New) aBehavior); + registerCoverBehavior(aStack, (GT_CoverBehaviorBase) aBehavior); } - public static void registerCoverBehavior(ItemStack aStack, GT_CoverBehavior_New aBehavior) { + public static void registerCoverBehavior(ItemStack aStack, GT_CoverBehaviorBase aBehavior) { sCoverBehaviors.put(new GT_ItemStack(aStack), aBehavior == null ? sDefaultBehavior : aBehavior); } @@ -647,7 +647,7 @@ public class GregTech_API { * * @param aBehavior can be null */ - public static void registerCover(Collection aStackList, ITexture aCover, GT_CoverBehavior_New aBehavior) { + public static void registerCover(Collection aStackList, ITexture aCover, GT_CoverBehaviorBase aBehavior) { if (aCover.isValidTexture()) aStackList.forEach(tStack -> GregTech_API.registerCover(tStack, aCover, aBehavior)); } @@ -659,7 +659,7 @@ public class GregTech_API { public static GT_CoverBehavior getCoverBehavior(ItemStack aStack) { if (aStack == null || aStack.getItem() == null) return sNoBehavior; - GT_CoverBehavior_New rCover = sCoverBehaviors.get(new GT_ItemStack(aStack)); + GT_CoverBehaviorBase rCover = sCoverBehaviors.get(new GT_ItemStack(aStack)); if (!(rCover instanceof GT_CoverBehavior) || rCover == null) return sDefaultBehavior; return (GT_CoverBehavior) rCover; @@ -669,10 +669,10 @@ public class GregTech_API { * returns a Cover behavior, guaranteed to not return null after preload * @return */ - public static GT_CoverBehavior_New getCoverBehaviorNew(ItemStack aStack) { + public static GT_CoverBehaviorBase getCoverBehaviorNew(ItemStack aStack) { if (aStack == null || aStack.getItem() == null) return sNoBehavior; - GT_CoverBehavior_New rCover = sCoverBehaviors.get(new GT_ItemStack(aStack)); + GT_CoverBehaviorBase rCover = sCoverBehaviors.get(new GT_ItemStack(aStack)); if (rCover == null) return sDefaultBehavior; return rCover; @@ -691,7 +691,7 @@ public class GregTech_API { /** * returns a Cover behavior, guaranteed to not return null */ - public static GT_CoverBehavior_New getCoverBehaviorNew(int aStack) { + public static GT_CoverBehaviorBase getCoverBehaviorNew(int aStack) { if (aStack == 0) return sNoBehavior; return getCoverBehaviorNew(GT_Utility.intToStack(aStack)); diff --git a/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntityItemPipe.java b/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntityItemPipe.java index d40a6026dc..90933b501f 100644 --- a/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntityItemPipe.java +++ b/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntityItemPipe.java @@ -59,7 +59,7 @@ public interface IMetaTileEntityItemPipe extends IMetaTileEntity { continue; j = GT_Utility.getOppositeSide(i); if (aSuckItems) { - if (aBaseMetaTileEntity.getCoverBehaviorAtSideNew(i).letsItemsIn(i, aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getCoverDataAtSideNew(i), -2, aBaseMetaTileEntity)) { + if (aBaseMetaTileEntity.getCoverBehaviorAtSideNew(i).letsItemsIn(i, aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getComplexCoverDataAtSide(i), -2, aBaseMetaTileEntity)) { IGregTechTileEntity tItemPipe = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(i); if (aBaseMetaTileEntity.getColorization() >= 0) { byte tColor = tItemPipe.getColorization(); @@ -69,13 +69,13 @@ public interface IMetaTileEntityItemPipe extends IMetaTileEntity { } if (tItemPipe instanceof BaseMetaPipeEntity) { IMetaTileEntity tMetaTileEntity = tItemPipe.getMetaTileEntity(); - if (tMetaTileEntity instanceof IMetaTileEntityItemPipe && tItemPipe.getCoverBehaviorAtSideNew(j).letsItemsOut(j, tItemPipe.getCoverIDAtSide(j), tItemPipe.getCoverDataAtSideNew(j), -2, tItemPipe)) { + if (tMetaTileEntity instanceof IMetaTileEntityItemPipe && tItemPipe.getCoverBehaviorAtSideNew(j).letsItemsOut(j, tItemPipe.getCoverIDAtSide(j), tItemPipe.getComplexCoverDataAtSide(j), -2, tItemPipe)) { scanPipes((IMetaTileEntityItemPipe) tMetaTileEntity, aMap, aStep, aSuckItems, aIgnoreCapacity); } } } } else { - if (aBaseMetaTileEntity.getCoverBehaviorAtSideNew(i).letsItemsOut(i, aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getCoverDataAtSideNew(i), -2, aBaseMetaTileEntity)) { + if (aBaseMetaTileEntity.getCoverBehaviorAtSideNew(i).letsItemsOut(i, aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getComplexCoverDataAtSide(i), -2, aBaseMetaTileEntity)) { IGregTechTileEntity tItemPipe = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(i); if (tItemPipe != null) { if (aBaseMetaTileEntity.getColorization() >= 0) { @@ -86,7 +86,7 @@ public interface IMetaTileEntityItemPipe extends IMetaTileEntity { } if (tItemPipe instanceof BaseMetaPipeEntity) { IMetaTileEntity tMetaTileEntity = tItemPipe.getMetaTileEntity(); - if (tMetaTileEntity instanceof IMetaTileEntityItemPipe && tItemPipe.getCoverBehaviorAtSideNew(j).letsItemsIn(j, tItemPipe.getCoverIDAtSide(j), tItemPipe.getCoverDataAtSideNew(j), -2, tItemPipe)) { + if (tMetaTileEntity instanceof IMetaTileEntityItemPipe && tItemPipe.getCoverBehaviorAtSideNew(j).letsItemsIn(j, tItemPipe.getCoverIDAtSide(j), tItemPipe.getComplexCoverDataAtSide(j), -2, tItemPipe)) { scanPipes((IMetaTileEntityItemPipe) tMetaTileEntity, aMap, aStep, aSuckItems, aIgnoreCapacity); } } diff --git a/src/main/java/gregtech/api/interfaces/tileentity/ICoverable.java b/src/main/java/gregtech/api/interfaces/tileentity/ICoverable.java index 47be175ead..ebfae9d90e 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/ICoverable.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/ICoverable.java @@ -1,7 +1,7 @@ package gregtech.api.interfaces.tileentity; import gregtech.api.util.GT_CoverBehavior; -import gregtech.api.util.GT_CoverBehavior_New; +import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.ISerializableObject; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; @@ -28,7 +28,7 @@ public interface ICoverable extends IRedstoneTileEntity, IHasInventory, IBasicEn @Deprecated int getCoverDataAtSide(byte aSide); - default ISerializableObject getCoverDataAtSideNew(byte aSide) { + default ISerializableObject getComplexCoverDataAtSide(byte aSide) { return new ISerializableObject.LegacyCoverData(getCoverDataAtSide(aSide)); } @@ -39,7 +39,7 @@ public interface ICoverable extends IRedstoneTileEntity, IHasInventory, IBasicEn @Deprecated GT_CoverBehavior getCoverBehaviorAtSide(byte aSide); - default GT_CoverBehavior_New getCoverBehaviorAtSideNew(byte aSide) { + default GT_CoverBehaviorBase getCoverBehaviorAtSideNew(byte aSide) { return getCoverBehaviorAtSide(aSide); } diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java index af14f9a9fe..475bee8eb9 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java @@ -23,7 +23,7 @@ import gregtech.api.interfaces.tileentity.IPipeRenderedTileEntity; import gregtech.api.net.GT_Packet_TileEntity; import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.GT_CoverBehavior; -import gregtech.api.util.GT_CoverBehavior_New; +import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_OreDictUnificator; @@ -53,7 +53,7 @@ import net.minecraftforge.fluids.*; * This is the main TileEntity for EVERYTHING. */ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileEntity, IPipeRenderedTileEntity { - private final GT_CoverBehavior_New[] mCoverBehaviors = new GT_CoverBehavior_New[]{GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior}; + private final GT_CoverBehaviorBase[] mCoverBehaviors = new GT_CoverBehaviorBase[]{GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior}; public byte mConnections = IConnectable.NO_CONNECTION; protected MetaPipeEntity mMetaTileEntity; private byte[] mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; @@ -173,7 +173,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE if (mCoverData == null) { mCoverData = new ISerializableObject[6]; for (byte i = 0; i<6; i++) { - GT_CoverBehavior_New tBehavior = getCoverBehaviorAtSideNew(i); + GT_CoverBehaviorBase tBehavior = getCoverBehaviorAtSideNew(i); if (tBehavior == null) continue; mCoverData[i] = tBehavior.createDataObject(); @@ -301,7 +301,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE for (byte i = (byte) (tCode - 2); i < 6; i++) if (getCoverIDAtSide(i) != 0) { tCode++; - GT_CoverBehavior_New tCover = getCoverBehaviorAtSideNew(i); + GT_CoverBehaviorBase tCover = getCoverBehaviorAtSideNew(i); int tCoverTickRate = tCover.getTickRate(i, getCoverIDAtSide(i), mCoverData[i], this); if (tCoverTickRate > 0 && mTickTimer % tCoverTickRate == 0) { byte tRedstone = tCover.isRedstoneSensitive(i, getCoverIDAtSide(i), mCoverData[i], this, mTickTimer) ? getInputRedstoneSignal(i) : 0; @@ -943,13 +943,13 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sScrewdriverList)) { if (getCoverIDAtSide(aSide) == 0 && getCoverIDAtSide(tSide) != 0) { if (GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 200, aPlayer)) { - setCoverDataAtSide(tSide, getCoverBehaviorAtSideNew(tSide).onCoverScrewdriverClick(tSide, getCoverIDAtSide(tSide), getCoverDataAtSideNew(tSide), this, aPlayer, 0.5F, 0.5F, 0.5F)); + setCoverDataAtSide(tSide, getCoverBehaviorAtSideNew(tSide).onCoverScrewdriverClick(tSide, getCoverIDAtSide(tSide), getComplexCoverDataAtSide(tSide), this, aPlayer, 0.5F, 0.5F, 0.5F)); mMetaTileEntity.onScrewdriverRightClick(tSide, aPlayer, aX, aY, aZ); GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(100), 1.0F, -1, xCoord, yCoord, zCoord); } } else { if (GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer)) { - setCoverDataAtSide(aSide, getCoverBehaviorAtSideNew(aSide).onCoverScrewdriverClick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this, aPlayer, aX, aY, aZ)); + setCoverDataAtSide(aSide, getCoverBehaviorAtSideNew(aSide).onCoverScrewdriverClick(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this, aPlayer, aX, aY, aZ)); mMetaTileEntity.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(100), 1.0F, -1, xCoord, yCoord, zCoord); } @@ -1023,14 +1023,14 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE } else if (aPlayer.isSneaking()) { //Sneak click, no tool -> open cover config or turn back. aSide = (getCoverIDAtSide(aSide) == 0) ? GT_Utility.determineWrenchingSide(aSide, aX, aY, aZ) : aSide; - return getCoverIDAtSide(aSide) > 0 && getCoverBehaviorAtSideNew(aSide).onCoverShiftRightClick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this, aPlayer); + return getCoverIDAtSide(aSide) > 0 && getCoverBehaviorAtSideNew(aSide).onCoverShiftRightClick(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this, aPlayer); } - if (getCoverBehaviorAtSideNew(aSide).onCoverRightClick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this, aPlayer, aX, aY, aZ)) + if (getCoverBehaviorAtSideNew(aSide).onCoverRightClick(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this, aPlayer, aX, aY, aZ)) return true; } - if (!getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this)) + if (!getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this)) return false; try { @@ -1087,7 +1087,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE */ @Override public int[] getAccessibleSlotsFromSide(int aSide) { - if (canAccessData() && (getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSideNew((byte) aSide), -1, this) || getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSideNew((byte) aSide), -1, this))) + if (canAccessData() && (getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getComplexCoverDataAtSide((byte) aSide), -1, this) || getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getComplexCoverDataAtSide((byte) aSide), -1, this))) return mMetaTileEntity.getAccessibleSlotsFromSide(aSide); return new int[0]; } @@ -1097,7 +1097,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE */ @Override public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { - return canAccessData() && getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSideNew((byte) aSide), aIndex, this) && mMetaTileEntity.canInsertItem(aIndex, aStack, aSide); + return canAccessData() && getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getComplexCoverDataAtSide((byte) aSide), aIndex, this) && mMetaTileEntity.canInsertItem(aIndex, aStack, aSide); } /** @@ -1105,7 +1105,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE */ @Override public boolean canExtractItem(int aIndex, ItemStack aStack, int aSide) { - return canAccessData() && getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSideNew((byte) aSide), aIndex, this) && mMetaTileEntity.canExtractItem(aIndex, aStack, aSide); + return canAccessData() && getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getComplexCoverDataAtSide((byte) aSide), aIndex, this) && mMetaTileEntity.canExtractItem(aIndex, aStack, aSide); } @Override @@ -1115,7 +1115,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE @Override public byte getInternalInputRedstoneSignal(byte aSide) { - return (byte) (getCoverBehaviorAtSide(aSide).getRedstoneInput(aSide, getInputRedstoneSignal(aSide), getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this) & 15); + return (byte) (getCoverBehaviorAtSide(aSide).getRedstoneInput(aSide, getInputRedstoneSignal(aSide), getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this) & 15); } @Override @@ -1125,12 +1125,12 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE @Override public byte getOutputRedstoneSignal(byte aSide) { - return (byte) (getCoverBehaviorAtSideNew(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this) || (getCoverBehaviorAtSideNew(aSide).letsRedstoneGoOut(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this)) ? mSidedRedstone[aSide] & 15 : 0); + return (byte) (getCoverBehaviorAtSideNew(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this) || (getCoverBehaviorAtSideNew(aSide).letsRedstoneGoOut(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this)) ? mSidedRedstone[aSide] & 15 : 0); } @Override public void setInternalOutputRedstoneSignal(byte aSide, byte aStrength) { - if (!getCoverBehaviorAtSideNew(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this)) + if (!getCoverBehaviorAtSideNew(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this)) setOutputRedstoneSignal(aSide, aStrength); } @@ -1258,12 +1258,12 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE } @Override - public ISerializableObject getCoverDataAtSideNew(byte aSide) { + public ISerializableObject getComplexCoverDataAtSide(byte aSide) { return mCoverData[aSide]; } @Override - public GT_CoverBehavior_New getCoverBehaviorAtSideNew(byte aSide) { + public GT_CoverBehaviorBase getCoverBehaviorAtSideNew(byte aSide) { return mCoverBehaviors[aSide]; } @@ -1285,7 +1285,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE @Override public boolean dropCover(byte aSide, byte aDroppedSide, boolean aForced) { if (getCoverBehaviorAtSideNew(aSide).onCoverRemoval(aSide, getCoverIDAtSide(aSide), mCoverData[aSide], this, aForced) || aForced) { - ItemStack tStack = getCoverBehaviorAtSideNew(aSide).getDrop(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this); + ItemStack tStack = getCoverBehaviorAtSideNew(aSide).getDrop(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this); if (tStack != null) { tStack.setTagCompound(null); EntityItem tEntity = new EntityItem(worldObj, getOffsetX(aDroppedSide, 1) + 0.5, getOffsetY(aDroppedSide, 1) + 0.5, getOffsetZ(aDroppedSide, 1) + 0.5, tStack); @@ -1380,11 +1380,11 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE return false; if(isFill && mMetaTileEntity.isLiquidInput((byte) aSide.ordinal()) - && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), aFluid, this)) + && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getComplexCoverDataAtSide((byte) aSide.ordinal()), aFluid, this)) return true; if (!isFill && mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) - && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()),aFluid, this)) + && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getComplexCoverDataAtSide((byte) aSide.ordinal()),aFluid, this)) return true; return false; @@ -1430,8 +1430,8 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE if (canAccessData() && (aSide == ForgeDirection.UNKNOWN || (mMetaTileEntity.isLiquidInput((byte) aSide.ordinal()) - && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), null, this)) - || (mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), null, this)) + && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getComplexCoverDataAtSide((byte) aSide.ordinal()), null, this)) + || (mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getComplexCoverDataAtSide((byte) aSide.ordinal()), null, this)) // Doesn't need to be connected to get Tank Info -- otherwise things can't connect ) ) diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 7bea6dbe6e..a56c0020a3 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -79,7 +79,7 @@ import static gregtech.api.objects.XSTR.XSTR_INSTANCE; @Optional.Interface(iface = "appeng.me.helpers.IGridProxyable", modid = "appliedenergistics2", striprefs = true)}) public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileEntity, IActionHost, IGridProxyable, IAlignmentProvider, IConstructableProvider { static final String[] COVER_DATA_NBT_KEYS = Arrays.stream(ForgeDirection.VALID_DIRECTIONS).mapToInt(Enum::ordinal).mapToObj(i -> "mCoverData" + i).toArray(String[]::new); - private final GT_CoverBehavior_New[] mCoverBehaviors = new GT_CoverBehavior_New[]{GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior}; + private final GT_CoverBehaviorBase[] mCoverBehaviors = new GT_CoverBehaviorBase[]{GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior}; protected MetaTileEntity mMetaTileEntity; protected long mStoredEnergy = 0, mStoredSteam = 0; protected int mAverageEUInputIndex = 0, mAverageEUOutputIndex = 0; @@ -401,7 +401,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE for (byte i = (byte) (tCode - 2); i < 6; i++) if (getCoverIDAtSide(i) != 0) { tCode++; - GT_CoverBehavior_New tCover = getCoverBehaviorAtSideNew(i); + GT_CoverBehaviorBase tCover = getCoverBehaviorAtSideNew(i); int tCoverTickRate = tCover.getTickRate(i, getCoverIDAtSide(i), mCoverData[i], this); if (tCoverTickRate > 0 && mTickTimer % tCoverTickRate == 0) { byte tRedstone = tCover.isRedstoneSensitive(i, getCoverIDAtSide(i), mCoverData[i], this, mTickTimer) ? getInputRedstoneSignal(i) : 0; @@ -1279,7 +1279,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE private boolean isEnergyInputSide(byte aSide) { if (aSide >= 0 && aSide < 6) { - if (!getCoverBehaviorAtSideNew(aSide).letsEnergyIn(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this)) + if (!getCoverBehaviorAtSideNew(aSide).letsEnergyIn(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this)) return false; if (isInvalid() || mReleaseEnergy) return false; if (canAccessData() && mMetaTileEntity.isElectric() && mMetaTileEntity.isEnetInput()) @@ -1290,7 +1290,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE private boolean isEnergyOutputSide(byte aSide) { if (aSide >= 0 && aSide < 6) { - if (!getCoverBehaviorAtSideNew(aSide).letsEnergyOut(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this)) + if (!getCoverBehaviorAtSideNew(aSide).letsEnergyOut(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this)) return false; if (isInvalid() || mReleaseEnergy) return mReleaseEnergy; if (canAccessData() && mMetaTileEntity.isElectric() && mMetaTileEntity.isEnetOutput()) @@ -1466,7 +1466,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE return true; } - if (!getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this)) + if (!getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this)) return false; } if (isServerSide()) { @@ -1493,7 +1493,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sScrewdriverList)) { if (GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 200, aPlayer)) { - setCoverDataAtSide(aSide, getCoverBehaviorAtSideNew(aSide).onCoverScrewdriverClick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this, aPlayer, aX, aY, aZ)); + setCoverDataAtSide(aSide, getCoverBehaviorAtSideNew(aSide).onCoverScrewdriverClick(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this, aPlayer, aX, aY, aZ)); mMetaTileEntity.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(100), 1.0F, -1, xCoord, yCoord, zCoord); } @@ -1578,13 +1578,13 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE } else if (aPlayer.isSneaking()) { //Sneak click, no tool -> open cover config if possible. aSide = (getCoverIDAtSide(aSide) == 0) ? GT_Utility.determineWrenchingSide(aSide, aX, aY, aZ) : aSide; - return getCoverIDAtSide(aSide) > 0 && getCoverBehaviorAtSideNew(aSide).onCoverShiftRightClick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this, aPlayer); + return getCoverIDAtSide(aSide) > 0 && getCoverBehaviorAtSideNew(aSide).onCoverShiftRightClick(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this, aPlayer); } - if (getCoverBehaviorAtSideNew(aSide).onCoverRightClick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this, aPlayer, aX, aY, aZ)) + if (getCoverBehaviorAtSideNew(aSide).onCoverRightClick(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this, aPlayer, aX, aY, aZ)) return true; - if (!getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this)) + if (!getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this)) return false; if (isUpgradable() && tCurrentItem != null) {/* @@ -1673,7 +1673,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE */ @Override public int[] getAccessibleSlotsFromSide(int aSide) { - if (canAccessData() && (getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSideNew((byte) aSide), -1, this) || getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSideNew((byte) aSide), -1, this))) + if (canAccessData() && (getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getComplexCoverDataAtSide((byte) aSide), -1, this) || getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getComplexCoverDataAtSide((byte) aSide), -1, this))) return mMetaTileEntity.getAccessibleSlotsFromSide(aSide); return new int[0]; } @@ -1683,7 +1683,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE */ @Override public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { - return canAccessData() && (mRunningThroughTick || !mInputDisabled) && getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSideNew((byte) aSide), aIndex, this) && mMetaTileEntity.canInsertItem(aIndex, aStack, aSide); + return canAccessData() && (mRunningThroughTick || !mInputDisabled) && getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getComplexCoverDataAtSide((byte) aSide), aIndex, this) && mMetaTileEntity.canInsertItem(aIndex, aStack, aSide); } /** @@ -1691,7 +1691,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE */ @Override public boolean canExtractItem(int aIndex, ItemStack aStack, int aSide) { - return canAccessData() && (mRunningThroughTick || !mOutputDisabled) && getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSideNew((byte) aSide), aIndex, this) && mMetaTileEntity.canExtractItem(aIndex, aStack, aSide); + return canAccessData() && (mRunningThroughTick || !mOutputDisabled) && getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getComplexCoverDataAtSide((byte) aSide), aIndex, this) && mMetaTileEntity.canExtractItem(aIndex, aStack, aSide); } @Override @@ -1701,7 +1701,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE @Override public byte getInternalInputRedstoneSignal(byte aSide) { - return (byte) (getCoverBehaviorAtSideNew(aSide).getRedstoneInput(aSide, getInputRedstoneSignal(aSide), getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this) & 15); + return (byte) (getCoverBehaviorAtSideNew(aSide).getRedstoneInput(aSide, getInputRedstoneSignal(aSide), getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this) & 15); } @Override @@ -1711,7 +1711,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE @Override public byte getOutputRedstoneSignal(byte aSide) { - return getCoverBehaviorAtSideNew(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this) ? mSidedRedstone[aSide] : getGeneralRS(aSide); + return getCoverBehaviorAtSideNew(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this) ? mSidedRedstone[aSide] : getGeneralRS(aSide); } public byte getGeneralRS(byte aSide){ @@ -1721,7 +1721,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE @Override public void setInternalOutputRedstoneSignal(byte aSide, byte aStrength) { - if (!getCoverBehaviorAtSideNew(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this)) + if (!getCoverBehaviorAtSideNew(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this)) setOutputRedstoneSignal(aSide, aStrength); } @@ -1871,12 +1871,12 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE } @Override - public ISerializableObject getCoverDataAtSideNew(byte aSide) { + public ISerializableObject getComplexCoverDataAtSide(byte aSide) { return mCoverData[aSide]; } @Override - public GT_CoverBehavior_New getCoverBehaviorAtSideNew(byte aSide) { + public GT_CoverBehaviorBase getCoverBehaviorAtSideNew(byte aSide) { return mCoverBehaviors[aSide]; } @@ -1910,7 +1910,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE @Override public boolean dropCover(byte aSide, byte aDroppedSide, boolean aForced) { if (getCoverBehaviorAtSideNew(aSide).onCoverRemoval(aSide, getCoverIDAtSide(aSide), mCoverData[aSide], this, aForced) || aForced) { - ItemStack tStack = getCoverBehaviorAtSideNew(aSide).getDrop(aSide, getCoverIDAtSide(aSide), getCoverDataAtSideNew(aSide), this); + ItemStack tStack = getCoverBehaviorAtSideNew(aSide).getDrop(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this); if (tStack != null) { tStack.setTagCompound(null); EntityItem tEntity = new EntityItem(worldObj, getOffsetX(aDroppedSide, 1) + 0.5, getOffsetY(aDroppedSide, 1) + 0.5, getOffsetZ(aDroppedSide, 1) + 0.5, tStack); @@ -2025,7 +2025,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE aSide == ForgeDirection.UNKNOWN || ( mMetaTileEntity.isLiquidInput((byte) aSide.ordinal()) && - getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), aFluid == null ? null : aFluid.getFluid(), this) + getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getComplexCoverDataAtSide((byte) aSide.ordinal()), aFluid == null ? null : aFluid.getFluid(), this) ) ) ) @@ -2041,7 +2041,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE aSide == ForgeDirection.UNKNOWN || ( mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && - getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), mMetaTileEntity.getFluid() == null ? null : mMetaTileEntity.getFluid().getFluid(), this) + getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getComplexCoverDataAtSide((byte) aSide.ordinal()), mMetaTileEntity.getFluid() == null ? null : mMetaTileEntity.getFluid().getFluid(), this) ) ) ) @@ -2057,7 +2057,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE aSide == ForgeDirection.UNKNOWN || ( mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && - getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), aFluid == null ? null : aFluid.getFluid(), this) + getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getComplexCoverDataAtSide((byte) aSide.ordinal()), aFluid == null ? null : aFluid.getFluid(), this) ) ) ) @@ -2073,7 +2073,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE aSide == ForgeDirection.UNKNOWN || ( mMetaTileEntity.isLiquidInput((byte) aSide.ordinal()) && - getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), aFluid, this) + getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getComplexCoverDataAtSide((byte) aSide.ordinal()), aFluid, this) ) ) ) @@ -2089,7 +2089,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE aSide == ForgeDirection.UNKNOWN || ( mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && - getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), aFluid, this) + getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getComplexCoverDataAtSide((byte) aSide.ordinal()), aFluid, this) ) ) ) @@ -2104,8 +2104,8 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE aSide == ForgeDirection.UNKNOWN || ( mMetaTileEntity.isLiquidInput((byte) aSide.ordinal()) && - getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), null, this)) || (mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && - getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSideNew((byte) aSide.ordinal()), null, this) + getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getComplexCoverDataAtSide((byte) aSide.ordinal()), null, this)) || (mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && + getCoverBehaviorAtSideNew((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getComplexCoverDataAtSide((byte) aSide.ordinal()), null, this) ) ) ) diff --git a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java index 23d6017a6a..73a33fb9eb 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java @@ -521,9 +521,9 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable { public int[] getAccessibleSlotsFromSide(int aSide) { ArrayList tList = new ArrayList(); IGregTechTileEntity tTileEntity = getBaseMetaTileEntity(); - boolean tSkip = tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), -2, tTileEntity) || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), -2, tTileEntity); + boolean tSkip = tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getComplexCoverDataAtSide((byte) aSide), -2, tTileEntity) || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getComplexCoverDataAtSide((byte) aSide), -2, tTileEntity); for (int i = 0; i < getSizeInventory(); i++) - if (isValidSlot(i) && (tSkip || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), i, tTileEntity) || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), i, tTileEntity))) + if (isValidSlot(i) && (tSkip || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getComplexCoverDataAtSide((byte) aSide), i, tTileEntity) || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getComplexCoverDataAtSide((byte) aSide), i, tTileEntity))) tList.add(i); int[] rArray = new int[tList.size()]; for (int i = 0; i < rArray.length; i++) rArray[i] = tList.get(i); @@ -784,9 +784,9 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable { final IGregTechTileEntity baseMetaTile = getBaseMetaTileEntity(); if (baseMetaTile == null || !baseMetaTile.isServerSide()) return 0; - final GT_CoverBehavior_New coverBehavior = baseMetaTile.getCoverBehaviorAtSideNew(aSide); + final GT_CoverBehaviorBase coverBehavior = baseMetaTile.getCoverBehaviorAtSideNew(aSide); final int coverId = baseMetaTile.getCoverIDAtSide(aSide); - ISerializableObject coverData = baseMetaTile.getCoverDataAtSideNew(aSide); + ISerializableObject coverData = baseMetaTile.getComplexCoverDataAtSide(aSide); boolean alwaysLookConnected = coverBehavior.alwaysLookConnected(aSide, coverId, coverData, baseMetaTile); boolean letsIn = letsIn(coverBehavior, aSide, coverId, coverData, baseMetaTile); @@ -856,8 +856,8 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable { public boolean letsIn(GT_CoverBehavior coverBehavior, byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return false; } public boolean letsOut(GT_CoverBehavior coverBehavior, byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return false; } - public boolean letsIn(GT_CoverBehavior_New coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { return false; } - public boolean letsOut(GT_CoverBehavior_New coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { return false; } + public boolean letsIn(GT_CoverBehaviorBase coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { return false; } + public boolean letsOut(GT_CoverBehaviorBase coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { return false; } public boolean canConnect(byte aSide, TileEntity tTileEntity) { return false; } public boolean getGT6StyleConnection() { return false; } diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java index 9e8865c3fa..b3c25ff345 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java @@ -714,9 +714,9 @@ public abstract class MetaTileEntity implements IMetaTileEntity { public int[] getAccessibleSlotsFromSide(int aSide) { ArrayList tList = new ArrayList(); IGregTechTileEntity tTileEntity = getBaseMetaTileEntity(); - boolean tSkip = tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), -2, tTileEntity) || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), -2, tTileEntity); + boolean tSkip = tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getComplexCoverDataAtSide((byte) aSide), -2, tTileEntity) || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getComplexCoverDataAtSide((byte) aSide), -2, tTileEntity); for (int i = 0; i < getSizeInventory(); i++) - if (isValidSlot(i) && (tSkip || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), i, tTileEntity) || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), i, tTileEntity))) + if (isValidSlot(i) && (tSkip || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getComplexCoverDataAtSide((byte) aSide), i, tTileEntity) || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getComplexCoverDataAtSide((byte) aSide), i, tTileEntity))) tList.add(i); int[] rArray = new int[tList.size()]; for (int i = 0; i < rArray.length; i++) rArray[i] = tList.get(i); diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java index 99eda0e159..2764eeb07e 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java @@ -1,7 +1,6 @@ package gregtech.api.metatileentity.implementations; import cofh.api.energy.IEnergyReceiver; -import com.google.common.collect.Sets; import cpw.mods.fml.common.Loader; import gregtech.GT_Mod; import gregtech.api.GregTech_API; @@ -159,7 +158,7 @@ public class GT_MetaPipeEntity_Cable extends MetaPipeEntity implements IMetaTile public long injectEnergyUnits(byte aSide, long aVoltage, long aAmperage) { if (!isConnectedAtSide(aSide) && aSide != 6) return 0; - if (!getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).letsEnergyIn(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSideNew(aSide), getBaseMetaTileEntity())) + if (!getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).letsEnergyIn(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getComplexCoverDataAtSide(aSide), getBaseMetaTileEntity())) return 0; HashSet nul = null; return transferElectricity(aSide, aVoltage, aAmperage,nul); @@ -255,12 +254,12 @@ public class GT_MetaPipeEntity_Cable extends MetaPipeEntity implements IMetaTile } @Override - public boolean letsIn(GT_CoverBehavior_New coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + public boolean letsIn(GT_CoverBehaviorBase coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { return coverBehavior.letsEnergyIn(aSide, aCoverID, aCoverVariable, aTileEntity); } @Override - public boolean letsOut(GT_CoverBehavior_New coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + public boolean letsOut(GT_CoverBehaviorBase coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { return coverBehavior.letsEnergyOut(aSide, aCoverID, aCoverVariable, aTileEntity); } @@ -268,7 +267,7 @@ public class GT_MetaPipeEntity_Cable extends MetaPipeEntity implements IMetaTile @Override public boolean canConnect(byte aSide, TileEntity tTileEntity) { final IGregTechTileEntity baseMetaTile = getBaseMetaTileEntity(); - final GT_CoverBehavior_New coverBehavior = baseMetaTile.getCoverBehaviorAtSideNew(aSide); + final GT_CoverBehaviorBase coverBehavior = baseMetaTile.getCoverBehaviorAtSideNew(aSide); final byte tSide = GT_Utility.getOppositeSide(aSide); final ForgeDirection tDir = ForgeDirection.getOrientation(tSide); diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java index 8c59823370..8479477d12 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java @@ -15,7 +15,7 @@ import gregtech.api.metatileentity.BaseMetaPipeEntity; import gregtech.api.metatileentity.MetaPipeEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_CoverBehavior; -import gregtech.api.util.GT_CoverBehavior_New; +import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; @@ -347,8 +347,8 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity { final IGregTechTileEntity gTank = tTank instanceof IGregTechTileEntity ? (IGregTechTileEntity) tTank : null; if (isConnectedAtSide(aSide) && tTank != null && (mLastReceivedFrom & (1 << aSide)) == 0 && - getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).letsFluidOut(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSideNew(aSide), tFluid.getFluid(), getBaseMetaTileEntity()) && - (gTank == null || gTank.getCoverBehaviorAtSideNew(tSide).letsFluidIn(tSide, gTank.getCoverIDAtSide(tSide), gTank.getCoverDataAtSideNew(tSide), tFluid.getFluid(), gTank))) { + getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).letsFluidOut(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getComplexCoverDataAtSide(aSide), tFluid.getFluid(), getBaseMetaTileEntity()) && + (gTank == null || gTank.getCoverBehaviorAtSideNew(tSide).letsFluidIn(tSide, gTank.getCoverIDAtSide(tSide), gTank.getComplexCoverDataAtSide(tSide), tFluid.getFluid(), gTank))) { if (tTank.fill(ForgeDirection.getOrientation(tSide), tFluid, false) > 0) { tTanks.add(new MutableTriple<>(tTank, ForgeDirection.getOrientation(tSide), 0)); } @@ -422,12 +422,12 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity { } @Override - public boolean letsIn(GT_CoverBehavior_New coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + public boolean letsIn(GT_CoverBehaviorBase coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { return coverBehavior.letsFluidIn(aSide, aCoverID, aCoverVariable, null, aTileEntity); } @Override - public boolean letsOut(GT_CoverBehavior_New coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + public boolean letsOut(GT_CoverBehaviorBase coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { return coverBehavior.letsFluidOut(aSide, aCoverID, aCoverVariable, null, aTileEntity); } @@ -441,7 +441,7 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity { if (baseMetaTile == null) return false; - final GT_CoverBehavior_New coverBehavior = baseMetaTile.getCoverBehaviorAtSideNew(aSide); + final GT_CoverBehaviorBase coverBehavior = baseMetaTile.getCoverBehaviorAtSideNew(aSide); final IGregTechTileEntity gTileEntity = (tTileEntity instanceof IGregTechTileEntity) ? (IGregTechTileEntity) tTileEntity : null; if (coverBehavior instanceof GT_Cover_Drain || (GregTech_API.mTConstruct && isTConstructFaucet(tTileEntity))) diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java index 212a0e4acb..e316a44c80 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java @@ -13,7 +13,7 @@ import gregtech.api.metatileentity.BaseMetaPipeEntity; import gregtech.api.metatileentity.MetaPipeEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_CoverBehavior; -import gregtech.api.util.GT_CoverBehavior_New; +import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; import gregtech.common.GT_Client; @@ -218,12 +218,12 @@ public class GT_MetaPipeEntity_Item extends MetaPipeEntity implements IMetaTileE } @Override - public boolean letsIn(GT_CoverBehavior_New coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + public boolean letsIn(GT_CoverBehaviorBase coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { return coverBehavior.letsItemsIn(aSide, aCoverID, aCoverVariable, -1, aTileEntity); } @Override - public boolean letsOut(GT_CoverBehavior_New coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + public boolean letsOut(GT_CoverBehaviorBase coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { return coverBehavior.letsItemsOut(aSide, aCoverID, aCoverVariable, -1, aTileEntity); } @@ -283,7 +283,7 @@ public class GT_MetaPipeEntity_Item extends MetaPipeEntity implements IMetaTileE @Override public boolean insertItemStackIntoTileEntity(Object aSender, byte aSide) { - if (getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).letsItemsOut(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSideNew(aSide), -1, getBaseMetaTileEntity())) { + if (getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).letsItemsOut(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getComplexCoverDataAtSide(aSide), -1, getBaseMetaTileEntity())) { TileEntity tInventory = getBaseMetaTileEntity().getTileEntityAtSide(aSide); if (tInventory != null && !(tInventory instanceof BaseMetaPipeEntity)) { if ((!(tInventory instanceof TileEntityHopper) && !(tInventory instanceof TileEntityDispenser)) || getBaseMetaTileEntity().getMetaIDAtSide(aSide) != GT_Utility.getOppositeSide(aSide)) { @@ -332,7 +332,7 @@ public class GT_MetaPipeEntity_Item extends MetaPipeEntity implements IMetaTileE @Override public int[] getAccessibleSlotsFromSide(int aSide) { IGregTechTileEntity tTileEntity = getBaseMetaTileEntity(); - boolean tAllow = tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), -2, tTileEntity) || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSideNew((byte) aSide), -2, tTileEntity); + boolean tAllow = tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getComplexCoverDataAtSide((byte) aSide), -2, tTileEntity) || tTileEntity.getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getComplexCoverDataAtSide((byte) aSide), -2, tTileEntity); if (tAllow) { if (cacheSides == null) cacheSides = super.getAccessibleSlotsFromSide(aSide); diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java index 56d58d533c..e8cac808dd 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java @@ -10,7 +10,7 @@ import gregtech.api.interfaces.metatileentity.IMachineCallback; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.GT_ItemStack; import gregtech.api.render.TextureFactory; -import gregtech.api.util.GT_CoverBehavior_New; +import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Recipe; @@ -825,7 +825,7 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B @Override public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCoverID) { if (aSide != mMainFacing) return true; - GT_CoverBehavior_New tBehavior = GregTech_API.getCoverBehaviorNew(aCoverID.toStack()); + GT_CoverBehaviorBase tBehavior = GregTech_API.getCoverBehaviorNew(aCoverID.toStack()); return tBehavior.isGUIClickable(aSide, GT_Utility.stackToInt(aCoverID.toStack()), tBehavior.createDataObject(), getBaseMetaTileEntity());} @Override diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java index 4de809c19b..2b7e50519d 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java @@ -185,7 +185,7 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch { @Override public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (!getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSideNew(aSide), getBaseMetaTileEntity())) + if (!getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getComplexCoverDataAtSide(aSide), getBaseMetaTileEntity())) return; if (aPlayer.isSneaking()) { if(disableSort) { diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java index 26448cd931..d848b06b07 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java @@ -202,7 +202,7 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch { @Override public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (!getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSideNew(aSide), getBaseMetaTileEntity())) + if (!getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getComplexCoverDataAtSide(aSide), getBaseMetaTileEntity())) return; if (aPlayer.isSneaking()) { mMode = (byte) ((mMode + 9) % 10); @@ -269,7 +269,7 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch { } private boolean tryToLockHatch(EntityPlayer aPlayer, byte aSide) { - if (!getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSideNew(aSide), getBaseMetaTileEntity())) + if (!getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getComplexCoverDataAtSide(aSide), getBaseMetaTileEntity())) return false; if (!isFluidLocked()) return false; diff --git a/src/main/java/gregtech/api/util/GT_CoverBehavior.java b/src/main/java/gregtech/api/util/GT_CoverBehavior.java index db68a50cd2..9972331eb3 100644 --- a/src/main/java/gregtech/api/util/GT_CoverBehavior.java +++ b/src/main/java/gregtech/api/util/GT_CoverBehavior.java @@ -14,7 +14,7 @@ import static gregtech.api.enums.GT_Values.E; /** * For Covers with a special behavior. Has fixed storage format of 4 byte. Not very convenient... */ -public abstract class GT_CoverBehavior extends GT_CoverBehavior_New { +public abstract class GT_CoverBehavior extends GT_CoverBehaviorBase { public EntityPlayer lastPlayer = null; diff --git a/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java b/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java new file mode 100644 index 0000000000..50ef2632d9 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java @@ -0,0 +1,482 @@ +package gregtech.api.util; + +import gregtech.api.enums.GT_Values; +import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.net.GT_Packet_TileEntityCoverGUI; +import gregtech.api.objects.GT_ItemStack; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.world.World; +import net.minecraftforge.fluids.Fluid; + +import static gregtech.api.enums.GT_Values.E; + +/** + * For Covers with a special behavior. + * + * @author glease + */ +public abstract class GT_CoverBehaviorBase { + + public EntityPlayer lastPlayer = null; + private final Class typeToken; + + protected GT_CoverBehaviorBase(Class typeToken) { + this.typeToken = typeToken; + } + + public abstract T createDataObject(int aLegacyData); + + public abstract T createDataObject(); + + public T createDataObject(NBTBase aNBT) { + T ret = createDataObject(); + ret.loadDataFromNBT(aNBT); + return ret; + } + + public final T cast(ISerializableObject aData) { + if (typeToken.isInstance(aData)) + return forceCast(aData); + return null; + } + + private T forceCast(ISerializableObject aData) { + return typeToken.cast(aData); + } + + // region facade + + public final boolean isRedstoneSensitive(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, long aTimer) { + return isRedstoneSensitiveImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aTimer); + } + + /** + * Called by updateEntity inside the covered TileEntity. aCoverVariable is the Value you returned last time. + */ + public final T doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, long aTimer) { + return doCoverThingsImpl(aSide, aInputRedstone, aCoverID, forceCast(aCoverVariable), aTileEntity, aTimer); + } + + /** + * Called when someone rightclicks this Cover. + *

+ * return true, if something actually happens. + */ + public final boolean onCoverRightClick(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + return onCoverRightClickImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer, aX, aY, aZ); + } + + /** + * Called when someone rightclicks this Cover with a Screwdriver. Doesn't call @onCoverRightclick in this Case. + *

+ * return the new Value of the Cover Variable + */ + public final T onCoverScrewdriverClick(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + return onCoverScrewdriverClickImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer, aX, aY, aZ); + } + + /** + * Called when someone shift-rightclicks this Cover with no tool. Doesn't call @onCoverRightclick in this Case. + */ + public final boolean onCoverShiftRightClick(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer) { + return onCoverShiftRightClickImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer); + } + + public final Object getClientGUI(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, World aWorld) { + return getClientGUIImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer, aWorld); + } + + /** + * Removes the Cover if this returns true, or if aForced is true. + * Doesn't get called when the Machine Block is getting broken, only if you break the Cover away from the Machine. + */ + public final boolean onCoverRemoval(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, boolean aForced) { + return onCoverRemovalImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aForced); + } + + /** + * Gives a small Text for the status of the Cover. + */ + public final String getDescription(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return getDescriptionImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * How Blast Proof the Cover is. 30 is normal. + */ + public final float getBlastProofLevel(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return getBlastProofLevelImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * If it lets RS-Signals into the Block + *

+ * This is just Informative so that Machines know if their Redstone Input is blocked or not + */ + public final boolean letsRedstoneGoIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return letsRedstoneGoInImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * If it lets RS-Signals out of the Block + */ + public final boolean letsRedstoneGoOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return letsRedstoneGoOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * If it lets Fibre-Signals into the Block + *

+ * This is just Informative so that Machines know if their Redstone Input is blocked or not + */ + public final boolean letsFibreGoIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return letsFibreGoInImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * If it lets Fibre-Signals out of the Block + */ + public final boolean letsFibreGoOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return letsFibreGoOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * If it lets Energy into the Block + */ + public final boolean letsEnergyIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return letsEnergyInImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * If it lets Energy out of the Block + */ + public final boolean letsEnergyOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return letsEnergyOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * If it lets Liquids into the Block, aFluid can be null meaning if this is generally allowing Fluids or not. + */ + public final boolean letsFluidIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return letsFluidInImpl(aSide, aCoverID, forceCast(aCoverVariable), aFluid, aTileEntity); + } + + /** + * If it lets Liquids out of the Block, aFluid can be null meaning if this is generally allowing Fluids or not. + */ + public final boolean letsFluidOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return letsFluidOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aFluid, aTileEntity); + } + + /** + * If it lets Items into the Block, aSlot = -1 means if it is generally accepting Items (return false for no eraction at all), aSlot = -2 means if it would accept for all Slots Impl(return true to skip the Checks for each Slot). + */ + public final boolean letsItemsIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, int aSlot, ICoverable aTileEntity) { + return letsItemsInImpl(aSide, aCoverID, forceCast(aCoverVariable), aSlot, aTileEntity); + } + + /** + * If it lets Items out of the Block, aSlot = -1 means if it is generally accepting Items (return false for no eraction at all), aSlot = -2 means if it would accept for all Slots Impl(return true to skip the Checks for each Slot). + */ + public final boolean letsItemsOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, int aSlot, ICoverable aTileEntity) { + return letsItemsOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aSlot, aTileEntity); + } + + /** + * If it lets you rightclick the Machine normally + */ + public final boolean isGUIClickable(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return isGUIClickableImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * Needs to return true for Covers, which have a Redstone Output on their Facing. + */ + public final boolean manipulatesSidedRedstoneOutput(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return manipulatesSidedRedstoneOutputImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * if this Cover should let Pipe Connections look connected even if it is not the case. + */ + public final boolean alwaysLookConnected(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return alwaysLookConnectedImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * Called to determine the incoming Redstone Signal of a Machine. + * Returns the original Redstone per default. + * The Cover should @letsRedstoneGoIn or the aInputRedstone Parameter is always 0. + */ + public final byte getRedstoneInput(byte aSide, byte aInputRedstone, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return getRedstoneInputImpl(aSide, aInputRedstone, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * Gets the Tick Rate for doCoverThings of the Cover + *

+ * 0 = No Ticks! Yes, 0 is Default, you have to override this + */ + public final int getTickRate(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return getTickRateImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + + /** + * The MC Color of this Lens. -1 for no Color (meaning this isn't a Lens then). + */ + public final byte getLensColor(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return getLensColorImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** + * @return the ItemStack dropped by this Cover + */ + public final ItemStack getDrop(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return getDropImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + // endregion + + // region impl + + protected boolean isRedstoneSensitiveImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, long aTimer) { + return true; + } + + /** + * Called by updateEntity inside the covered TileEntity. aCoverVariable is the Value you returned last time. + */ + protected T doCoverThingsImpl(byte aSide, byte aInputRedstone, int aCoverID, T aCoverVariable, ICoverable aTileEntity, long aTimer) { + return aCoverVariable; + } + + /** + * Called when someone rightclicks this Cover. + *

+ * return true, if something actually happens. + */ + protected boolean onCoverRightClickImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + return false; + } + + /** + * Called when someone rightclicks this Cover with a Screwdriver. Doesn't call @onCoverRightclick in this Case. + *

+ * return the new Value of the Cover Variable + */ + protected T onCoverScrewdriverClickImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + return aCoverVariable; + } + + /** + * Called when someone shift-rightclicks this Cover with no tool. Doesn't call @onCoverRightclick in this Case. + */ + protected boolean onCoverShiftRightClickImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer) { + if (hasCoverGUI() && aPlayer instanceof EntityPlayerMP) { + lastPlayer = aPlayer; + GT_Values.NW.sendToPlayer(new GT_Packet_TileEntityCoverGUI(aSide, aCoverID, aCoverVariable, aTileEntity, (EntityPlayerMP) aPlayer), (EntityPlayerMP) aPlayer); + return true; + } + return false; + } + + protected Object getClientGUIImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, World aWorld) { + return null; + } + + /** + * Removes the Cover if this returns true, or if aForced is true. + * Doesn't get called when the Machine Block is getting broken, only if you break the Cover away from the Machine. + */ + protected boolean onCoverRemovalImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, boolean aForced) { + return true; + } + + /** + * Gives a small Text for the status of the Cover. + */ + protected String getDescriptionImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return E; + } + + /** + * How Blast Proof the Cover is. 30 is normal. + */ + protected float getBlastProofLevelImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return 10.0F; + } + + /** + * If it lets RS-Signals into the Block + *

+ * This is just Informative so that Machines know if their Redstone Input is blocked or not + */ + protected boolean letsRedstoneGoInImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets RS-Signals out of the Block + */ + protected boolean letsRedstoneGoOutImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Fibre-Signals into the Block + *

+ * This is just Informative so that Machines know if their Redstone Input is blocked or not + */ + protected boolean letsFibreGoInImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Fibre-Signals out of the Block + */ + protected boolean letsFibreGoOutImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Energy into the Block + */ + protected boolean letsEnergyInImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Energy out of the Block + */ + protected boolean letsEnergyOutImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Liquids into the Block, aFluid can be null meaning if this is generally allowing Fluids or not. + */ + protected boolean letsFluidInImpl(byte aSide, int aCoverID, T aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Liquids out of the Block, aFluid can be null meaning if this is generally allowing Fluids or not. + */ + protected boolean letsFluidOutImpl(byte aSide, int aCoverID, T aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Items into the Block, aSlot = -1 means if it is generally accepting Items (return false for no Interaction at all), aSlot = -2 means if it would accept for all Slots (return true to skip the Checks for each Slot). + */ + protected boolean letsItemsInImpl(byte aSide, int aCoverID, T aCoverVariable, int aSlot, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Items out of the Block, aSlot = -1 means if it is generally accepting Items (return false for no Interaction at all), aSlot = -2 means if it would accept for all Slots (return true to skip the Checks for each Slot). + */ + protected boolean letsItemsOutImpl(byte aSide, int aCoverID, T aCoverVariable, int aSlot, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets you rightclick the Machine normally + */ + protected boolean isGUIClickableImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * Needs to return true for Covers, which have a Redstone Output on their Facing. + */ + protected boolean manipulatesSidedRedstoneOutputImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * if this Cover should let Pipe Connections look connected even if it is not the case. + */ + protected boolean alwaysLookConnectedImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * Called to determine the incoming Redstone Signal of a Machine. + * Returns the original Redstone per default. + * The Cover should @letsRedstoneGoIn or the aInputRedstone Parameter is always 0. + */ + protected byte getRedstoneInputImpl(byte aSide, byte aInputRedstone, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return letsRedstoneGoIn(aSide, aCoverID, aCoverVariable, aTileEntity) ? aInputRedstone : 0; + } + + /** + * Gets the Tick Rate for doCoverThings of the Cover + *

+ * 0 = No Ticks! Yes, 0 is Default, you have to override this + */ + protected int getTickRateImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return 0; + } + + + /** + * The MC Color of this Lens. -1 for no Color (meaning this isn't a Lens then). + */ + protected byte getLensColorImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return -1; + } + + /** + * @return the ItemStack dropped by this Cover + */ + protected ItemStack getDropImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return GT_OreDictUnificator.get(true, aTileEntity.getCoverItemAtSide(aSide)); + } + + //endregion + + // region no data + + /** + * Checks if the Cover can be placed on this. + */ + public boolean isCoverPlaceable(byte aSide, GT_ItemStack aStack, ICoverable aTileEntity) { + return true; + } + + public boolean hasCoverGUI() { + return false; + } + + /** + * Called when someone rightclicks this Cover Client Side + *

+ * return true, if something actually happens. + */ + public boolean onCoverRightclickClient(byte aSide, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + return false; + } + + /** + * If this is a simple Cover, which can also be used on Bronze Machines and similar. + */ + public boolean isSimpleCover() { + return false; + } + + /** + * sets the Cover upon placement. + */ + public void placeCover(byte aSide, ItemStack aCover, ICoverable aTileEntity) { + aTileEntity.setCoverIDAtSide(aSide, GT_Utility.stackToInt(aCover)); + } + + public String trans(String aNr, String aEnglish) { + return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_" + aNr, aEnglish, false); + } + // endregion +} diff --git a/src/main/java/gregtech/api/util/GT_CoverBehavior_New.java b/src/main/java/gregtech/api/util/GT_CoverBehavior_New.java deleted file mode 100644 index 3e2c2f856f..0000000000 --- a/src/main/java/gregtech/api/util/GT_CoverBehavior_New.java +++ /dev/null @@ -1,482 +0,0 @@ -package gregtech.api.util; - -import gregtech.api.enums.GT_Values; -import gregtech.api.interfaces.tileentity.ICoverable; -import gregtech.api.net.GT_Packet_TileEntityCoverGUI; -import gregtech.api.objects.GT_ItemStack; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTBase; -import net.minecraft.world.World; -import net.minecraftforge.fluids.Fluid; - -import static gregtech.api.enums.GT_Values.E; - -/** - * For Covers with a special behavior. - * - * @author glease - */ -public abstract class GT_CoverBehavior_New { - - public EntityPlayer lastPlayer = null; - private final Class typeToken; - - protected GT_CoverBehavior_New(Class typeToken) { - this.typeToken = typeToken; - } - - public abstract T createDataObject(int aLegacyData); - - public abstract T createDataObject(); - - public T createDataObject(NBTBase aNBT) { - T ret = createDataObject(); - ret.loadDataFromNBT(aNBT); - return ret; - } - - public final T cast(ISerializableObject aData) { - if (typeToken.isInstance(aData)) - return forceCast(aData); - return null; - } - - private T forceCast(ISerializableObject aData) { - return typeToken.cast(aData); - } - - // region facade - - public final boolean isRedstoneSensitive(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, long aTimer) { - return isRedstoneSensitiveImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aTimer); - } - - /** - * Called by updateEntity inside the covered TileEntity. aCoverVariable is the Value you returned last time. - */ - public final T doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, long aTimer) { - return doCoverThingsImpl(aSide, aInputRedstone, aCoverID, forceCast(aCoverVariable), aTileEntity, aTimer); - } - - /** - * Called when someone rightclicks this Cover. - *

- * return true, if something actually happens. - */ - public final boolean onCoverRightClick(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { - return onCoverRightClickImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer, aX, aY, aZ); - } - - /** - * Called when someone rightclicks this Cover with a Screwdriver. Doesn't call @onCoverRightclick in this Case. - *

- * return the new Value of the Cover Variable - */ - public final T onCoverScrewdriverClick(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { - return onCoverScrewdriverClickImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer, aX, aY, aZ); - } - - /** - * Called when someone shift-rightclicks this Cover with no tool. Doesn't call @onCoverRightclick in this Case. - */ - public final boolean onCoverShiftRightClick(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer) { - return onCoverShiftRightClickImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer); - } - - public final Object getClientGUI(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, World aWorld) { - return getClientGUIImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer, aWorld); - } - - /** - * Removes the Cover if this returns true, or if aForced is true. - * Doesn't get called when the Machine Block is getting broken, only if you break the Cover away from the Machine. - */ - public final boolean onCoverRemoval(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, boolean aForced) { - return onCoverRemovalImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aForced); - } - - /** - * Gives a small Text for the status of the Cover. - */ - public final String getDescription(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return getDescriptionImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); - } - - /** - * How Blast Proof the Cover is. 30 is normal. - */ - public final float getBlastProofLevel(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return getBlastProofLevelImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); - } - - /** - * If it lets RS-Signals into the Block - *

- * This is just Informative so that Machines know if their Redstone Input is blocked or not - */ - public final boolean letsRedstoneGoIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return letsRedstoneGoInImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); - } - - /** - * If it lets RS-Signals out of the Block - */ - public final boolean letsRedstoneGoOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return letsRedstoneGoOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); - } - - /** - * If it lets Fibre-Signals into the Block - *

- * This is just Informative so that Machines know if their Redstone Input is blocked or not - */ - public final boolean letsFibreGoIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return letsFibreGoInImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); - } - - /** - * If it lets Fibre-Signals out of the Block - */ - public final boolean letsFibreGoOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return letsFibreGoOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); - } - - /** - * If it lets Energy into the Block - */ - public final boolean letsEnergyIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return letsEnergyInImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); - } - - /** - * If it lets Energy out of the Block - */ - public final boolean letsEnergyOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return letsEnergyOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); - } - - /** - * If it lets Liquids into the Block, aFluid can be null meaning if this is generally allowing Fluids or not. - */ - public final boolean letsFluidIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { - return letsFluidInImpl(aSide, aCoverID, forceCast(aCoverVariable), aFluid, aTileEntity); - } - - /** - * If it lets Liquids out of the Block, aFluid can be null meaning if this is generally allowing Fluids or not. - */ - public final boolean letsFluidOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { - return letsFluidOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aFluid, aTileEntity); - } - - /** - * If it lets Items into the Block, aSlot = -1 means if it is generally accepting Items (return false for no eraction at all), aSlot = -2 means if it would accept for all Slots Impl(return true to skip the Checks for each Slot). - */ - public final boolean letsItemsIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, int aSlot, ICoverable aTileEntity) { - return letsItemsInImpl(aSide, aCoverID, forceCast(aCoverVariable), aSlot, aTileEntity); - } - - /** - * If it lets Items out of the Block, aSlot = -1 means if it is generally accepting Items (return false for no eraction at all), aSlot = -2 means if it would accept for all Slots Impl(return true to skip the Checks for each Slot). - */ - public final boolean letsItemsOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, int aSlot, ICoverable aTileEntity) { - return letsItemsOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aSlot, aTileEntity); - } - - /** - * If it lets you rightclick the Machine normally - */ - public final boolean isGUIClickable(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return isGUIClickableImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); - } - - /** - * Needs to return true for Covers, which have a Redstone Output on their Facing. - */ - public final boolean manipulatesSidedRedstoneOutput(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return manipulatesSidedRedstoneOutputImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); - } - - /** - * if this Cover should let Pipe Connections look connected even if it is not the case. - */ - public final boolean alwaysLookConnected(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return alwaysLookConnectedImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); - } - - /** - * Called to determine the incoming Redstone Signal of a Machine. - * Returns the original Redstone per default. - * The Cover should @letsRedstoneGoIn or the aInputRedstone Parameter is always 0. - */ - public final byte getRedstoneInput(byte aSide, byte aInputRedstone, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return getRedstoneInputImpl(aSide, aInputRedstone, aCoverID, forceCast(aCoverVariable), aTileEntity); - } - - /** - * Gets the Tick Rate for doCoverThings of the Cover - *

- * 0 = No Ticks! Yes, 0 is Default, you have to override this - */ - public final int getTickRate(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return getTickRateImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); - } - - - /** - * The MC Color of this Lens. -1 for no Color (meaning this isn't a Lens then). - */ - public final byte getLensColor(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return getLensColorImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); - } - - /** - * @return the ItemStack dropped by this Cover - */ - public final ItemStack getDrop(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return getDropImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); - } - // endregion - - // region impl - - protected boolean isRedstoneSensitiveImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, long aTimer) { - return true; - } - - /** - * Called by updateEntity inside the covered TileEntity. aCoverVariable is the Value you returned last time. - */ - protected T doCoverThingsImpl(byte aSide, byte aInputRedstone, int aCoverID, T aCoverVariable, ICoverable aTileEntity, long aTimer) { - return aCoverVariable; - } - - /** - * Called when someone rightclicks this Cover. - *

- * return true, if something actually happens. - */ - protected boolean onCoverRightClickImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { - return false; - } - - /** - * Called when someone rightclicks this Cover with a Screwdriver. Doesn't call @onCoverRightclick in this Case. - *

- * return the new Value of the Cover Variable - */ - protected T onCoverScrewdriverClickImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { - return aCoverVariable; - } - - /** - * Called when someone shift-rightclicks this Cover with no tool. Doesn't call @onCoverRightclick in this Case. - */ - protected boolean onCoverShiftRightClickImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer) { - if (hasCoverGUI() && aPlayer instanceof EntityPlayerMP) { - lastPlayer = aPlayer; - GT_Values.NW.sendToPlayer(new GT_Packet_TileEntityCoverGUI(aSide, aCoverID, aCoverVariable, aTileEntity, (EntityPlayerMP) aPlayer), (EntityPlayerMP) aPlayer); - return true; - } - return false; - } - - protected Object getClientGUIImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, World aWorld) { - return null; - } - - /** - * Removes the Cover if this returns true, or if aForced is true. - * Doesn't get called when the Machine Block is getting broken, only if you break the Cover away from the Machine. - */ - protected boolean onCoverRemovalImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, boolean aForced) { - return true; - } - - /** - * Gives a small Text for the status of the Cover. - */ - protected String getDescriptionImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return E; - } - - /** - * How Blast Proof the Cover is. 30 is normal. - */ - protected float getBlastProofLevelImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return 10.0F; - } - - /** - * If it lets RS-Signals into the Block - *

- * This is just Informative so that Machines know if their Redstone Input is blocked or not - */ - protected boolean letsRedstoneGoInImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return false; - } - - /** - * If it lets RS-Signals out of the Block - */ - protected boolean letsRedstoneGoOutImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return false; - } - - /** - * If it lets Fibre-Signals into the Block - *

- * This is just Informative so that Machines know if their Redstone Input is blocked or not - */ - protected boolean letsFibreGoInImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return false; - } - - /** - * If it lets Fibre-Signals out of the Block - */ - protected boolean letsFibreGoOutImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return false; - } - - /** - * If it lets Energy into the Block - */ - protected boolean letsEnergyInImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return false; - } - - /** - * If it lets Energy out of the Block - */ - protected boolean letsEnergyOutImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return false; - } - - /** - * If it lets Liquids into the Block, aFluid can be null meaning if this is generally allowing Fluids or not. - */ - protected boolean letsFluidInImpl(byte aSide, int aCoverID, T aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { - return false; - } - - /** - * If it lets Liquids out of the Block, aFluid can be null meaning if this is generally allowing Fluids or not. - */ - protected boolean letsFluidOutImpl(byte aSide, int aCoverID, T aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { - return false; - } - - /** - * If it lets Items into the Block, aSlot = -1 means if it is generally accepting Items (return false for no Interaction at all), aSlot = -2 means if it would accept for all Slots (return true to skip the Checks for each Slot). - */ - protected boolean letsItemsInImpl(byte aSide, int aCoverID, T aCoverVariable, int aSlot, ICoverable aTileEntity) { - return false; - } - - /** - * If it lets Items out of the Block, aSlot = -1 means if it is generally accepting Items (return false for no Interaction at all), aSlot = -2 means if it would accept for all Slots (return true to skip the Checks for each Slot). - */ - protected boolean letsItemsOutImpl(byte aSide, int aCoverID, T aCoverVariable, int aSlot, ICoverable aTileEntity) { - return false; - } - - /** - * If it lets you rightclick the Machine normally - */ - protected boolean isGUIClickableImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return false; - } - - /** - * Needs to return true for Covers, which have a Redstone Output on their Facing. - */ - protected boolean manipulatesSidedRedstoneOutputImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return false; - } - - /** - * if this Cover should let Pipe Connections look connected even if it is not the case. - */ - protected boolean alwaysLookConnectedImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return false; - } - - /** - * Called to determine the incoming Redstone Signal of a Machine. - * Returns the original Redstone per default. - * The Cover should @letsRedstoneGoIn or the aInputRedstone Parameter is always 0. - */ - protected byte getRedstoneInputImpl(byte aSide, byte aInputRedstone, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return letsRedstoneGoIn(aSide, aCoverID, aCoverVariable, aTileEntity) ? aInputRedstone : 0; - } - - /** - * Gets the Tick Rate for doCoverThings of the Cover - *

- * 0 = No Ticks! Yes, 0 is Default, you have to override this - */ - protected int getTickRateImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return 0; - } - - - /** - * The MC Color of this Lens. -1 for no Color (meaning this isn't a Lens then). - */ - protected byte getLensColorImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return -1; - } - - /** - * @return the ItemStack dropped by this Cover - */ - protected ItemStack getDropImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return GT_OreDictUnificator.get(true, aTileEntity.getCoverItemAtSide(aSide)); - } - - //endregion - - // region no data - - /** - * Checks if the Cover can be placed on this. - */ - public boolean isCoverPlaceable(byte aSide, GT_ItemStack aStack, ICoverable aTileEntity) { - return true; - } - - public boolean hasCoverGUI() { - return false; - } - - /** - * Called when someone rightclicks this Cover Client Side - *

- * return true, if something actually happens. - */ - public boolean onCoverRightclickClient(byte aSide, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { - return false; - } - - /** - * If this is a simple Cover, which can also be used on Bronze Machines and similar. - */ - public boolean isSimpleCover() { - return false; - } - - /** - * sets the Cover upon placement. - */ - public void placeCover(byte aSide, ItemStack aCover, ICoverable aTileEntity) { - aTileEntity.setCoverIDAtSide(aSide, GT_Utility.stackToInt(aCover)); - } - - public String trans(String aNr, String aEnglish) { - return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_" + aNr, aEnglish, false); - } - // endregion -} diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 08b10e4fdf..a07868ec68 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -104,16 +104,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; import java.util.Objects; import java.util.Optional; @@ -2157,7 +2148,7 @@ public class GT_Utility { try { if (tTileEntity instanceof ICoverable) { rEUAmount += 300; - String tString = ((ICoverable) tTileEntity).getCoverBehaviorAtSideNew((byte) aSide).getDescription((byte) aSide, ((ICoverable) tTileEntity).getCoverIDAtSide((byte) aSide), ((ICoverable) tTileEntity).getCoverDataAtSideNew((byte) aSide), (ICoverable) tTileEntity); + String tString = ((ICoverable) tTileEntity).getCoverBehaviorAtSideNew((byte) aSide).getDescription((byte) aSide, ((ICoverable) tTileEntity).getCoverIDAtSide((byte) aSide), ((ICoverable) tTileEntity).getComplexCoverDataAtSide((byte) aSide), (ICoverable) tTileEntity); if (tString != null && !tString.equals(E)) tList.add(tString); } } catch (Throwable e) { diff --git a/src/main/java/gregtech/common/covers/GT_Cover_Fluidfilter.java b/src/main/java/gregtech/common/covers/GT_Cover_Fluidfilter.java index dce38d4f1f..99836c1d99 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_Fluidfilter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_Fluidfilter.java @@ -8,7 +8,7 @@ import gregtech.api.gui.widgets.GT_GuiIcon; import gregtech.api.gui.widgets.GT_GuiIconButton; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.net.GT_Packet_TileEntityCoverNew; -import gregtech.api.util.GT_CoverBehavior_New; +import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; import io.netty.buffer.ByteBuf; @@ -27,7 +27,7 @@ import javax.annotation.Nonnull; import static gregtech.api.enums.GT_Values.E; -public class GT_Cover_Fluidfilter extends GT_CoverBehavior_New { +public class GT_Cover_Fluidfilter extends GT_CoverBehaviorBase { // Uses the lower 3 bits of the cover variable, so we have 8 options to work with (0-7) private final int FILTER_INPUT_DENY_OUTPUT = 0; // 000 diff --git a/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java b/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java index ab7aeee861..88ef51dd01 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java @@ -9,7 +9,7 @@ import gregtech.api.gui.widgets.GT_GuiIcon; import gregtech.api.gui.widgets.GT_GuiIconCheckButton; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.net.GT_Packet_TileEntityCoverNew; -import gregtech.api.util.GT_CoverBehavior_New; +import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; import io.netty.buffer.ByteBuf; @@ -31,7 +31,7 @@ import java.util.List; import static gregtech.api.util.GT_Utility.intToStack; import static gregtech.api.util.GT_Utility.moveMultipleItemStacks; -public class GT_Cover_ItemFilter extends GT_CoverBehavior_New { +public class GT_Cover_ItemFilter extends GT_CoverBehaviorBase { private final boolean mExport; -- cgit From 2419eb0491d8648cbd1aef159b897fa953ca558a Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Wed, 17 Nov 2021 22:18:47 +0800 Subject: Fix NPE and math bugs Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- src/main/java/gregtech/api/util/GT_ChunkAssociatedData.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_ChunkAssociatedData.java b/src/main/java/gregtech/api/util/GT_ChunkAssociatedData.java index b28cb429b4..bd9148b516 100644 --- a/src/main/java/gregtech/api/util/GT_ChunkAssociatedData.java +++ b/src/main/java/gregtech/api/util/GT_ChunkAssociatedData.java @@ -126,13 +126,13 @@ public abstract class GT_ChunkAssociatedData new ConcurrentHashMap<>()) .computeIfAbsent(getRegionID(chunkX, chunkZ), c -> new SuperRegion(world, c)); - return region.get(chunkX % regionLength, chunkZ % regionLength); + return region.get(Math.floorMod(chunkX, regionLength), Math.floorMod(chunkZ, regionLength)); } protected final void set(World world, int chunkX, int chunkZ, T data) { SuperRegion region = masterMap.computeIfAbsent(world.provider.dimensionId, ignored -> new ConcurrentHashMap<>()) .computeIfAbsent(getRegionID(chunkX, chunkZ), c -> new SuperRegion(world, c)); - region.set(chunkX % regionLength, chunkZ % regionLength, data); + region.set(Math.floorMod(chunkX, regionLength), Math.floorMod(chunkZ, regionLength), data); } protected final boolean isCreated(int dimId, int chunkX, int chunkZ) { @@ -142,7 +142,7 @@ public abstract class GT_ChunkAssociatedData map = masterMap.get(world.provider.dimensionId); + if (map != null) + saveRegions(map.values().stream()); } private void saveRegions(Stream stream) { -- cgit From 25d664c62e4b658f1bc3c41706488ab351fec2db Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Wed, 17 Nov 2021 15:59:38 +0000 Subject: Added hashCode and equals overrides to GT_Recipe_AssemblyLine. --- src/main/java/gregtech/api/util/GT_Recipe.java | 71 ++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 1f13ff7b82..ec5a062a11 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -564,6 +564,77 @@ public class GT_Recipe implements Comparable { mEUt = aEUt; mOreDictAlt = aAlt; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + GT_ItemStack[] thisInputs = new GT_ItemStack[this.mInputs.length]; + int inputHash = Arrays.deepHashCode(thisInputs); + int inputFluidHash = Arrays.deepHashCode(this.mFluidInputs); + GT_ItemStack thisOutput = new GT_ItemStack(mOutput); + GT_ItemStack thisResearch = new GT_ItemStack(mResearchItem); + result = prime * result + inputFluidHash; + result = prime * result + inputHash; + result = prime * result + Objects.hash( + mDuration, mEUt, + thisOutput, + thisResearch, + mResearchTime + ); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof GT_Recipe_AssemblyLine)) { + return false; + } + GT_Recipe_AssemblyLine other = (GT_Recipe_AssemblyLine) obj; + if (this.mInputs.length != other.mInputs.length) { + return false; + } + if (this.mFluidInputs.length != other.mFluidInputs.length) { + return false; + } + // Check Outputs Match + GT_ItemStack output1 = new GT_ItemStack(this.mOutput); + GT_ItemStack output2 = new GT_ItemStack(other.mOutput); + if (!output1.equals(output2)) { + return false; + } + // Check Scanned Item Match + GT_ItemStack scan1 = new GT_ItemStack(this.mResearchItem); + GT_ItemStack scan2 = new GT_ItemStack(other.mResearchItem); + if (!scan1.equals(scan2)) { + return false; + } + // Check Items Match + GT_ItemStack[] thisInputs = new GT_ItemStack[this.mInputs.length]; + GT_ItemStack[] otherInputs = new GT_ItemStack[other.mInputs.length]; + for (int i=0;i Date: Thu, 18 Nov 2021 09:36:34 +0000 Subject: Actually add items to the Input Array that is hashed. --- src/main/java/gregtech/api/util/GT_Recipe.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index ec5a062a11..770a8747d9 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -570,6 +570,9 @@ public class GT_Recipe implements Comparable { final int prime = 31; int result = 1; GT_ItemStack[] thisInputs = new GT_ItemStack[this.mInputs.length]; + for (int i=0;i Date: Thu, 18 Nov 2021 10:16:23 +0000 Subject: Factor in stack sizes for Hashing. --- src/main/java/gregtech/api/util/GT_Recipe.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 770a8747d9..2c5b2df5bf 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -570,21 +570,25 @@ public class GT_Recipe implements Comparable { final int prime = 31; int result = 1; GT_ItemStack[] thisInputs = new GT_ItemStack[this.mInputs.length]; + int totalInputStackSize = 0; for (int i=0;i Date: Sat, 20 Nov 2021 00:18:45 -0700 Subject: Fix GT_Recipe_Map_Fuel not handling fuel recipes correctly This fixes the GT++ semi-fluid generator --- src/main/java/gregtech/api/util/GT_Recipe.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 1f13ff7b82..e2f6883bb9 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -1045,6 +1045,10 @@ public class GT_Recipe implements Comparable { tFluid.amount = 0; mRecipesByFluidInput.put(tFluid.getUnlocalizedName(), aRecipe); } + } else if ((aRecipe.mInputs == null || GT_Utility.getNonnullElementCount(aRecipe.mInputs) == 0) && + aRecipe.mFluidInputs != null && GT_Utility.getNonnullElementCount(aRecipe.mFluidInputs) == 1 && + aRecipe.mFluidInputs[0] != null) { + mRecipesByFluidInput.put(aRecipe.mFluidInputs[0].getUnlocalizedName(), aRecipe); } return aRecipe; } -- cgit