aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/GoodGenerator/util
diff options
context:
space:
mode:
authorGlodBlock <1356392126@qq.com>2021-08-16 22:46:40 +0800
committerGlodBlock <1356392126@qq.com>2021-08-16 22:46:40 +0800
commitc6daf6b4d70ccde55c2a944036cb13656966e991 (patch)
treefe57ed6b65ed9e4c601445eff0627e19fdb0a586 /src/main/java/GoodGenerator/util
parent845cce81a82e1cfd9d404fa1b13490acff96bf35 (diff)
downloadGT5-Unofficial-c6daf6b4d70ccde55c2a944036cb13656966e991.tar.gz
GT5-Unofficial-c6daf6b4d70ccde55c2a944036cb13656966e991.tar.bz2
GT5-Unofficial-c6daf6b4d70ccde55c2a944036cb13656966e991.zip
add Neutron Activator related blocks
Diffstat (limited to 'src/main/java/GoodGenerator/util')
-rw-r--r--src/main/java/GoodGenerator/util/CharExchanger.java79
-rw-r--r--src/main/java/GoodGenerator/util/StructureHelper.java61
2 files changed, 138 insertions, 2 deletions
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 <BR>
+ * "<" : 2 <BR>
+ * "==" : 13 <BR>
+ * "!=" : 14 <BR>
+ * ">=" : 11 <BR>
+ * "<=" : 12 <BR>
+ * 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 <T>IStructureElement<T> addFrame(Materials aMaterials) {
+ return new IStructureElement<T>() {
+
+ 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;
+ }
+ };
+ }
+
+}