From d246612148b9b6dfaa4dfabd399f077ea0544096 Mon Sep 17 00:00:00 2001
From: Glease <4586901+Glease@users.noreply.github.com>
Date: Wed, 23 Feb 2022 13:03:46 +0800
Subject: Consolidate boro glass stuff into a real API (#95)
* Consolidate boro glass stuff into a real API
* pull in changes from ExampleMod
* Fix underflow
* attempt to fix build
Former-commit-id: 2413c93bc2bb5ab32a0e8078dbcf01a4b23b1f7d
---
.../bartworks/API/BorosilicateGlass.java | 152 +++++++++++++++++++++
.../bartworks/ASM/BWCoreTransformer.java | 3 +
.../bartworks/common/items/BW_ItemBlocks.java | 7 +-
.../mega/GT_TileEntity_MegaBlastFurnace.java | 20 +--
.../mega/GT_TileEntity_MegaChemicalReactor.java | 66 +++------
.../multis/mega/GT_TileEntity_MegaOilCracker.java | 70 ++--------
.../bartimaeusnek/bartworks/util/BW_Util.java | 26 ++--
7 files changed, 200 insertions(+), 144 deletions(-)
create mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/API/BorosilicateGlass.java
(limited to 'src/main/java/com')
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/API/BorosilicateGlass.java b/src/main/java/com/github/bartimaeusnek/bartworks/API/BorosilicateGlass.java
new file mode 100644
index 0000000000..e4714d059d
--- /dev/null
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/API/BorosilicateGlass.java
@@ -0,0 +1,152 @@
+package com.github.bartimaeusnek.bartworks.API;
+
+import com.gtnewhorizon.structurelib.structure.IStructureElement;
+import cpw.mods.fml.common.registry.GameRegistry;
+import net.minecraft.block.Block;
+import org.apache.commons.lang3.tuple.Pair;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.BiConsumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy;
+import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlockAdder;
+import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlockAnyMeta;
+import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlocksTiered;
+
+/**
+ * API for bartworks borosilicate glass.
+ *
+ * You might have noticed this API does not expose any Block instance, but only IStructureElements. This is in case we
+ * add more glass blocks later, and we run out of meta id for only one block.
+ *
+ * IStructureElements returned from this class should not have its methods called before the game start.
+ */
+public class BorosilicateGlass {
+
+ private static Block block;
+ private static List> representatives;
+
+ private static Block getGlassBlock() {
+ if (block == null)
+ block = GameRegistry.findBlock("bartworks", "BW_GlasBlocks");
+ return block;
+ }
+
+ private static List> getRepresentatives() {
+ if (representatives == null) {
+ ArrayList> ret = new ArrayList<>();
+ Block block = getGlassBlock();
+ ret.add(Pair.of(block, 0));
+ ret.add(Pair.of(block, 1));
+ ret.add(Pair.of(block, 2));
+ ret.add(Pair.of(block, 3));
+ ret.add(Pair.of(block, 4));
+ ret.add(Pair.of(block, 5));
+ ret.add(Pair.of(block, 13));
+ ret.add(Pair.of(block, 14));
+ representatives = ret;
+ }
+ return representatives;
+ }
+
+ private static byte checkWithinBound(byte val, byte lo, byte hi) {
+ return val > hi || val < lo ? -1 : val;
+ }
+
+ /**
+ * Check if there is at least one type of boroglass in that tier.
+ */
+ public static boolean hasGlassInTier(int tier) {
+ return tier >= 3 && tier <= 10;
+ }
+
+ /**
+ * Get a structure element for a certain tier of borosilicate glass. DOES NOT accept other glass like reinforced glass, magic mirror, vanilla glass, etc.
+ *
+ * Use this if you just want boroglass here and doesn't care what tier it is.
+ */
+ public static IStructureElement ofBoroGlass(int tier) {
+ if (!hasGlassInTier(tier)) throw new IllegalArgumentException();
+ return lazy(t -> {
+ Pair pair = getRepresentatives().get(tier - 3);
+ return ofBlockAdder((t1, block1, meta) -> getTier(block1, meta) == tier, pair.getKey(), pair.getValue());
+ });
+ }
+
+ /**
+ * Get a structure element for any kind of borosilicate glass. DOES NOT accept other glass like reinforced glass, magic mirror, vanilla glass, etc.
+ *
+ * Use this if you just want boroglass here and doesn't care what tier it is.
+ */
+ public static IStructureElement ofBoroGlassAnyTier() {
+ return lazy(t -> ofBlockAnyMeta(getGlassBlock()));
+ }
+
+ /**
+ * Get a structure element for borosilicate glass. DOES NOT accept other glass like reinforced glass, magic mirror, vanilla glass, etc.
+ *
+ * This assumes you want all glass used to be of the same tier.
+ *
+ * NOTE: This will accept the basic boron glass (HV tier) as well. You might not want this. Use the other overload to filter this out.
+ *
+ * @param initialValue the value set before structure check started
+ */
+ public static IStructureElement ofBoroGlass(byte initialValue, BiConsumer setter, Function getter) {
+ return lazy(t -> ofBlocksTiered(BorosilicateGlass::getTier, getRepresentatives(), initialValue, setter, getter));
+ }
+
+ /**
+ * Get a structure element for borosilicate glass. DOES NOT accept other glass like reinforced glass, magic mirror, vanilla glass, etc.
+ *
+ * @param initialValue the value set before structure check started
+ * @param minTier minimal accepted tier. inclusive. must be greater than 0.
+ * @param maxTier maximal accepted tier. inclusive.
+ */
+ public static IStructureElement ofBoroGlass(byte initialValue, byte minTier, byte maxTier, BiConsumer setter, Function getter) {
+ if (minTier > maxTier || minTier < 0) throw new IllegalArgumentException();
+ return lazy(t -> ofBlocksTiered(
+ (block1, meta) -> checkWithinBound(getTier(block1, meta), minTier, maxTier),
+ getRepresentatives().stream().skip(Math.max(minTier - 3, 0)).limit(maxTier - minTier + 1).collect(Collectors.toList()),
+ initialValue,
+ setter,
+ getter
+ ));
+ }
+
+ /**
+ * Get the tier of this borosilicate glass. DOES NOT consider other glass like reinforced glass, magic mirror, vanilla glass, etc.
+ */
+ public static byte getTier(Block block, int meta) {
+ byte ret;
+ switch (meta) {
+ case 1:
+ ret = 4;
+ break;
+ case 2:
+ case 12:
+ ret = 5;
+ break;
+ case 3:
+ ret = 6;
+ break;
+ case 4:
+ ret = 7;
+ break;
+ case 5:
+ ret = 8;
+ break;
+ case 13:
+ ret = 9;
+ break;
+ case 14:
+ ret = 10;
+ break;
+ default:
+ ret = 3;
+ }
+ return block == getGlassBlock() ? ret : -1;
+ }
+}
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/ASM/BWCoreTransformer.java b/src/main/java/com/github/bartimaeusnek/bartworks/ASM/BWCoreTransformer.java
index 4ea3582bd1..223a067ce6 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/ASM/BWCoreTransformer.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/ASM/BWCoreTransformer.java
@@ -296,6 +296,9 @@ public class BWCoreTransformer implements IClassTransformer {
toPatch.instructions.add(new VarInsnNode(ALOAD,2));
toPatch.instructions.add(new MethodInsnNode(INVOKESTATIC,"com/github/bartimaeusnek/bartworks/ASM/BWCoreStaticReplacementMethodes","findCachedMatchingRecipe","(Lnet/minecraft/inventory/InventoryCrafting;Lnet/minecraft/world/World;)Lnet/minecraft/item/ItemStack;",false));
toPatch.instructions.add(new InsnNode(ARETURN));
+ toPatch.localVariables.clear();
+ toPatch.maxStack = 2;
+ toPatch.maxLocals = 3;
break scase;
}
}
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/items/BW_ItemBlocks.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/items/BW_ItemBlocks.java
index e0c172f1cd..a136cfd34b 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/common/items/BW_ItemBlocks.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/items/BW_ItemBlocks.java
@@ -22,6 +22,7 @@
package com.github.bartimaeusnek.bartworks.common.items;
+import com.github.bartimaeusnek.bartworks.API.BorosilicateGlass;
import com.github.bartimaeusnek.bartworks.API.ITileAddsInformation;
import com.github.bartimaeusnek.bartworks.MainMod;
import com.github.bartimaeusnek.bartworks.common.blocks.BW_GlasBlocks;
@@ -69,8 +70,10 @@ public class BW_ItemBlocks extends ItemBlock {
@SideOnly(Side.CLIENT)
@SuppressWarnings("unchecked")
public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean aF3_H) {
- if (this.field_150939_a instanceof BW_GlasBlocks)
- aList.add(StatCollector.translateToLocal("tooltip.glas.0.name") + " " + BW_ColorUtil.getColorForTier(BW_Util.getTierFromGlasMeta(aStack.getItemDamage())) + GT_Values.VN[BW_Util.getTierFromGlasMeta(aStack.getItemDamage())]);
+ byte tier = BorosilicateGlass.getTier(this.field_150939_a, aStack.getItemDamage());
+ if (tier >= 0) {
+ aList.add(StatCollector.translateToLocal("tooltip.glas.0.name") + " " + BW_ColorUtil.getColorForTier(tier) + GT_Values.VN[tier]);
+ }
if (this.field_150939_a instanceof ITileAddsInformation) {
aList.addAll(Arrays.asList(((ITileAddsInformation) this.field_150939_a).getInfoData()));
}
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaBlastFurnace.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaBlastFurnace.java
index f9263f140a..b204f30502 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaBlastFurnace.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaBlastFurnace.java
@@ -22,6 +22,7 @@
package com.github.bartimaeusnek.bartworks.common.tileentities.multis.mega;
+import com.github.bartimaeusnek.bartworks.API.BorosilicateGlass;
import com.github.bartimaeusnek.bartworks.API.LoaderReference;
import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler;
import com.github.bartimaeusnek.bartworks.common.loaders.ItemRegistry;
@@ -77,7 +78,7 @@ public class GT_TileEntity_MegaBlastFurnace extends GT_MetaTileEntity_ElectricBl
.addElement('t', ofHatchAdderOptional(GT_TileEntity_MegaBlastFurnace::addOutputHatchToTopList, CASING_INDEX, 1, GregTech_API.sBlockCasings1, CASING_INDEX))
.addElement('m', ofHatchAdder(GT_TileEntity_MegaBlastFurnace::addMufflerToMachineList, CASING_INDEX, 2))
.addElement('C', ofCoil(GT_TileEntity_MegaBlastFurnace::setCoilLevel, GT_MetaTileEntity_ElectricBlastFurnace::getCoilLevel))
- .addElement('g', ofBlockAdder(GT_TileEntity_MegaBlastFurnace::addGlas, ItemRegistry.bw_glasses[0], 1))
+ .addElement('g', BorosilicateGlass.ofBoroGlass((byte) 0, (byte) 1, Byte.MAX_VALUE, (te, t) -> te.glasTier = t, te -> te.glasTier))
.addElement('b', ofHatchAdderOptional(GT_TileEntity_MegaBlastFurnace::addBottomHatch, CASING_INDEX, 3, GregTech_API.sBlockCasings1, CASING_INDEX))
.build();
@@ -163,9 +164,7 @@ public class GT_TileEntity_MegaBlastFurnace extends GT_MetaTileEntity_ElectricBl
return tt;
}
- @SuppressWarnings("rawtypes")
public ArrayList