From c6daf6b4d70ccde55c2a944036cb13656966e991 Mon Sep 17 00:00:00 2001 From: GlodBlock <1356392126@qq.com> Date: Mon, 16 Aug 2021 22:46:40 +0800 Subject: add Neutron Activator related blocks --- .../java/GoodGenerator/util/CharExchanger.java | 79 +++++++++++++++++++++- .../java/GoodGenerator/util/StructureHelper.java | 61 +++++++++++++++++ 2 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 src/main/java/GoodGenerator/util/StructureHelper.java (limited to 'src/main/java/GoodGenerator/util') diff --git a/src/main/java/GoodGenerator/util/CharExchanger.java b/src/main/java/GoodGenerator/util/CharExchanger.java index afd5a49999..e2b95c040b 100644 --- a/src/main/java/GoodGenerator/util/CharExchanger.java +++ b/src/main/java/GoodGenerator/util/CharExchanger.java @@ -1,8 +1,83 @@ package GoodGenerator.util; public class CharExchanger { + public static char shifter(int unicode){ - char c = (char)unicode; - return c; + return (char)unicode; + } + + public static boolean isValidCompareExpressChar(char c) { + return Character.isDigit(c) || c == '<' || c == '>' || c == '=' || c == '!'; + } + + public static boolean isValidCompareExpress(String exp) { + if (exp.length() < 2) return false; + for (char c: exp.toCharArray()) + if (!isValidCompareExpressChar(c)) return false; + char c1 = exp.charAt(0), c2 = exp.charAt(1); + String subExp = "" + c1; + if (!Character.isDigit(c2)) subExp = subExp + c2; + switch (subExp) { + case ">": + case "<": + case ">=": + case "<=": + case "==": + case "!=": + break; + default: return false; + } + if (exp.length() == subExp.length()) return false; + for (int i = subExp.length(); i < exp.length(); i ++) { + if (!Character.isDigit(exp.charAt(i))) return false; + } + return true; + } + + /** + * ">" : 1
+ * "<" : 2
+ * "==" : 13
+ * "!=" : 14
+ * ">=" : 11
+ * "<=" : 12
+ * INVALID : -1 + */ + public static int getOperator(String exp){ + char c1, c2; + int ret; + if (exp.length() < 1) return -1; + c1 = exp.charAt(0); + switch (c1) { + case '>': ret = 1;break; + case '<': ret = 2;break; + case '=': ret = 3;break; + case '!': ret = 4;break; + default: return -1; + } + if (exp.length() > 1) c2 = exp.charAt(1); + else return ret; + if (c2 == '=') { + ret += 10; + } + return ret; + } + + public static boolean compareExpression(String exp, int num) { + int op = getOperator(exp); + String NumExp = exp; + String[] opChar = new String[]{">", "<", "<=", ">=", "==", "!="}; + if (op == -1) throw new IllegalArgumentException(); + for (String re: opChar) NumExp = NumExp.replace(re, ""); + int num2 = Integer.getInteger(NumExp); + switch (op) { + case 1: return num > num2; + case 2: return num < num2; + case 13: return num == num2; + case 14: return num != num2; + case 11: return num >= num2; + case 12: return num <= num2; + default: return false; + } } } diff --git a/src/main/java/GoodGenerator/util/StructureHelper.java b/src/main/java/GoodGenerator/util/StructureHelper.java new file mode 100644 index 0000000000..2c5feadab8 --- /dev/null +++ b/src/main/java/GoodGenerator/util/StructureHelper.java @@ -0,0 +1,61 @@ +package GoodGenerator.util; + +import com.github.technus.tectech.TecTech; +import com.github.technus.tectech.mechanics.structure.IStructureElement; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.metatileentity.BaseMetaPipeEntity; +import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Frame; +import gregtech.api.util.GT_OreDictUnificator; +import net.minecraft.init.Items; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +import java.util.Arrays; + +public class StructureHelper { + + public static IStructureElement addFrame(Materials aMaterials) { + return new IStructureElement() { + + private IIcon[] mIcons; + + @Override + public boolean check(T t, World world, int x, int y, int z) { + TileEntity tBlock = world.getTileEntity(x, y, z); + if (tBlock instanceof BaseMetaPipeEntity) { + BaseMetaPipeEntity tFrame = (BaseMetaPipeEntity) tBlock; + if (tFrame.isInvalidTileEntity()) return false; + if (tFrame.getMetaTileEntity() instanceof GT_MetaPipeEntity_Frame) { + return ((GT_MetaPipeEntity_Frame) tFrame.getMetaTileEntity()).mMaterial == aMaterials; + } + } + return false; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + if (mIcons == null) { + mIcons = new IIcon[6]; + Arrays.fill(mIcons, aMaterials.mIconSet.mTextures[OrePrefixes.frameGt.mTextureIndex].getIcon()); + } + TecTech.proxy.hint_particle_tinted(world, x, y, z, mIcons, aMaterials.mRGBa); + return true; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + ItemStack tFrame = GT_OreDictUnificator.get(OrePrefixes.frameGt, aMaterials, 1); + if (tFrame.getItem() instanceof ItemBlock) { + ItemBlock tFrameStackItem = (ItemBlock) tFrame.getItem(); + return tFrameStackItem.placeBlockAt(tFrame, null, world, x, y, z, 6, 0, 0, 0, Items.feather.getDamage(tFrame)); + } + return false; + } + }; + } + +} -- cgit