diff options
author | Tec <daniel112092@gmail.com> | 2019-03-11 18:53:03 +0100 |
---|---|---|
committer | Tec <daniel112092@gmail.com> | 2019-03-11 18:53:03 +0100 |
commit | b6a1228f33e2ab68edcd819bef23753ae0ec2a01 (patch) | |
tree | 43ad8e993a98a584e8269568e3de0ace2fb2c1e5 | |
parent | 9fcaa9ecac5b76ad51ef2541efcf21cbc77d2f3d (diff) | |
parent | 212ae6295324b48980702d9098ea5e727802955d (diff) | |
download | GT5-Unofficial-b6a1228f33e2ab68edcd819bef23753ae0ec2a01.tar.gz GT5-Unofficial-b6a1228f33e2ab68edcd819bef23753ae0ec2a01.tar.bz2 GT5-Unofficial-b6a1228f33e2ab68edcd819bef23753ae0ec2a01.zip |
Merge branch 'betterParametrizers' into BassAddons
# Conflicts:
# build.properties
# src/main/java/com/github/technus/tectech/Util.java
# src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java
# src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_computer.java
# src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_junction.java
# src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_switch.java
# src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_microwave.java
# src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java
# src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_Container_MultiMachineEM.java
# src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_GUIContainer_MultiMachineEM.java
# src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java
# src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/LedStatus.java
# src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_Centrifuge.java
# src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_ElectromagneticSeparator.java
# src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/GT_MetaTileEntity_EM_machine.java
47 files changed, 1664 insertions, 1336 deletions
diff --git a/src/main/java/com/github/technus/tectech/Util.java b/src/main/java/com/github/technus/tectech/Util.java index 7a5366f337..f15c07cd19 100644 --- a/src/main/java/com/github/technus/tectech/Util.java +++ b/src/main/java/com/github/technus/tectech/Util.java @@ -2,6 +2,7 @@ package com.github.technus.tectech; import com.github.technus.tectech.thing.casing.TT_Container_Casings; import com.github.technus.tectech.thing.metaTileEntity.IFrontRotation; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; import cpw.mods.fml.common.registry.GameRegistry; import gregtech.api.GregTech_API; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -13,6 +14,8 @@ import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; import net.minecraft.init.Items; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.ICrafting; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -82,6 +85,22 @@ public final class Util { return result.toString(); } + public static String longBitsToShortString(long number) { + StringBuilder result = new StringBuilder(16); + + for (int i = 63; i >= 0; i--) { + int mask = 1 << i; + result.append((number & mask) != 0 ? ":" : "."); + + if (i % 8 == 0) { + result.append('|'); + } + } + result.replace(result.length() - 1, result.length(), ""); + + return result.toString(); + } + //region junk /* //Check Machine Structure based on string[][] (effectively char[][][]), ond offset of the controller @@ -371,14 +390,14 @@ public final class Util { */ //endregion + //Check Machine Structure based on string[][] (effectively char[][][]), ond offset of the controller //This only checks for REGULAR BLOCKS! public static boolean StructureCheckerExtreme( String[][] structure,//0-9 casing, +- air no air, A... ignore 'A'-CHAR-1 blocks Block[] blockType,//use numbers 0-9 for casing types byte[] blockMeta,//use numbers 0-9 for casing types - Method adder, - String[] addingMethods, + HatchAdder[] addingMethods, short[] casingTextures, Block[] blockTypeFallback,//use numbers 0-9 for casing types byte[] blockMetaFallback,//use numbers 0-9 for casing types @@ -589,28 +608,22 @@ public final class Util { } return false; } - } else if ((pointer = block - ' ') >= 0) { + } else //noinspection ConstantConditions + if ((pointer = block - ' ') >= 0) { igt = aBaseMetaTileEntity.getIGregTechTileEntity(x, y, z); - try { - if (igt == null || !(boolean) adder.invoke(imt, addingMethods[pointer], igt, casingTextures[pointer])) { - if (world.getBlock(x, y, z) != blockTypeFallback[pointer]) { - if (DEBUG_MODE) { - TecTech.LOGGER.info("Fallback-struct-block-error " + x + ' ' + y + ' ' + z + " / " + a + ' ' + b + ' ' + c + " / " + world.getBlock(x, y, z).getUnlocalizedName() + ' ' + (blockTypeFallback[pointer] == null ? "null" : blockTypeFallback[pointer].getUnlocalizedName())); - } - return false; - } - if (world.getBlockMetadata(x, y, z) != blockMetaFallback[pointer]) { - if (DEBUG_MODE) { - TecTech.LOGGER.info("Fallback-Struct-meta-id-error " + x + ' ' + y + ' ' + z + " / " + a + ' ' + b + ' ' + c + " / " + world.getBlockMetadata(x, y, z) + ' ' + blockMetaFallback[pointer]); - } - return false; + if (igt == null || !addingMethods[pointer].apply(igt, casingTextures[pointer])) { + if (world.getBlock(x, y, z) != blockTypeFallback[pointer]) { + if (DEBUG_MODE) { + TecTech.LOGGER.info("Fallback-struct-block-error " + x + ' ' + y + ' ' + z + " / " + a + ' ' + b + ' ' + c + " / " + world.getBlock(x, y, z).getUnlocalizedName() + ' ' + (blockTypeFallback[pointer] == null ? "null" : blockTypeFallback[pointer].getUnlocalizedName())); } + return false; } - } catch (InvocationTargetException | IllegalAccessException e) { - if (DEBUG_MODE) { - e.printStackTrace(); + if (world.getBlockMetadata(x, y, z) != blockMetaFallback[pointer]) { + if (DEBUG_MODE) { + TecTech.LOGGER.info("Fallback-Struct-meta-id-error " + x + ' ' + y + ' ' + z + " / " + a + ' ' + b + ' ' + c + " / " + world.getBlockMetadata(x, y, z) + ' ' + blockMetaFallback[pointer]); + } + return false; } - return false; } } } @@ -1302,18 +1315,18 @@ public final class Util { return (testedValue & setBits) == setBits; } - public static class TT_ItemStack implements Comparable<TT_ItemStack> { + public static class ItemStack_NoNBT implements Comparable<ItemStack_NoNBT> { public final Item mItem; public final int mStackSize; public final int mMetaData; - public TT_ItemStack(Item aItem, long aStackSize, long aMetaData) { + public ItemStack_NoNBT(Item aItem, long aStackSize, long aMetaData) { this.mItem = aItem; this.mStackSize = (byte) ((int) aStackSize); this.mMetaData = (short) ((int) aMetaData); } - public TT_ItemStack(ItemStack aStack) { + public ItemStack_NoNBT(ItemStack aStack) { if (aStack == null) { mItem = null; mStackSize = mMetaData = 0; @@ -1325,7 +1338,7 @@ public final class Util { } @Override - public int compareTo(TT_ItemStack o) { + public int compareTo(ItemStack_NoNBT o) { if (mMetaData > o.mMetaData) return 1; if (mMetaData < o.mMetaData) return -1; if (mStackSize > o.mStackSize) return 1; @@ -1340,10 +1353,10 @@ public final class Util { @Override public boolean equals(Object aStack) { return aStack == this || - (aStack instanceof TT_ItemStack && - ((mItem == ((TT_ItemStack) aStack).mItem) || ((TT_ItemStack) aStack).mItem.getUnlocalizedName().equals(this.mItem.getUnlocalizedName())) && - ((TT_ItemStack) aStack).mStackSize == this.mStackSize && - ((TT_ItemStack) aStack).mMetaData == this.mMetaData); + (aStack instanceof ItemStack_NoNBT && + ((mItem == ((ItemStack_NoNBT) aStack).mItem) || ((ItemStack_NoNBT) aStack).mItem.getUnlocalizedName().equals(this.mItem.getUnlocalizedName())) && + ((ItemStack_NoNBT) aStack).mStackSize == this.mStackSize && + ((ItemStack_NoNBT) aStack).mMetaData == this.mMetaData); } @Override @@ -1366,4 +1379,70 @@ public final class Util { e.printStackTrace(); } } + + public static double receiveDouble(double previousValue, int startIndex, int index, int value){ + return Double.longBitsToDouble(receiveLong(Double.doubleToLongBits(previousValue),startIndex,index,value)); + } + + public static long receiveLong(long previousValue, int startIndex, int index, int value){ + value &=0xFFFF; + switch (index-startIndex){ + case 0: + previousValue&= 0xFFFF_FFFF_FFFF_0000L; + previousValue|=value; + break; + case 1: + previousValue&=0xFFFF_FFFF_0000_FFFFL; + previousValue|=value<<16; + break; + case 2: + previousValue&=0xFFFF_0000_FFFF_FFFFL; + previousValue|=(long)value<<32; + break; + case 3: + previousValue&=0x0000_FFFF_FFFF_FFFFL; + previousValue|=(long)value<<48; + break; + } + return previousValue; + } + + public static void sendDouble(double value,Container container, ICrafting crafter,int startIndex){ + sendLong(Double.doubleToLongBits(value),container,crafter,startIndex); + } + + public static void sendLong(long value,Container container, ICrafting crafter,int startIndex){ + crafter.sendProgressBarUpdate(container, startIndex++, (int)(value & 0xFFFFL)); + crafter.sendProgressBarUpdate(container, startIndex++, (int)((value & 0xFFFF0000L)>>>16)); + crafter.sendProgressBarUpdate(container, startIndex++, (int)((value & 0xFFFF00000000L)>>>32)); + crafter.sendProgressBarUpdate(container, startIndex, (int)((value & 0xFFFF000000000000L)>>>48)); + } + + public static float receiveFloat(float previousValue, int startIndex, int index, int value){ + return Float.intBitsToFloat(receiveInteger(Float.floatToIntBits(previousValue),startIndex,index,value)); + } + + public static int receiveInteger(int previousValue, int startIndex, int index, int value){ + value &=0xFFFF; + switch (index-startIndex){ + case 0: + previousValue&= 0xFFFF_0000; + previousValue|=value; + break; + case 1: + previousValue&=0x0000_FFFF; + previousValue|=value<<16; + break; + } + return previousValue; + } + + public static void sendFloat(float value,Container container, ICrafting crafter,int startIndex){ + sendInteger(Float.floatToIntBits(value),container,crafter,startIndex); + } + + public static void sendInteger(int value,Container container, ICrafting crafter,int startIndex){ + crafter.sendProgressBarUpdate(container, startIndex++, (int)(value & 0xFFFFL)); + crafter.sendProgressBarUpdate(container, startIndex, (value & 0xFFFF0000)>>>16); + } } diff --git a/src/main/java/com/github/technus/tectech/compatibility/dreamcraft/DreamCraftRecipeLoader.java b/src/main/java/com/github/technus/tectech/compatibility/dreamcraft/DreamCraftRecipeLoader.java index 210dd4421e..d9ddb3d0e0 100644 --- a/src/main/java/com/github/technus/tectech/compatibility/dreamcraft/DreamCraftRecipeLoader.java +++ b/src/main/java/com/github/technus/tectech/compatibility/dreamcraft/DreamCraftRecipeLoader.java @@ -980,22 +980,22 @@ public class DreamCraftRecipeLoader implements Runnable { } private void register_machine_EM_behaviours(){ - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(5),ItemList.Machine_IV_Centrifuge.get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(6),getItemContainer("CentrifugeLuV").get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(7),getItemContainer("CentrifugeZPM").get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(8),getItemContainer("CentrifugeUV").get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(9),getItemContainer("CentrifugeUHV").get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(10),getItemContainer("CentrifugeUEV").get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(11),getItemContainer("CentrifugeUIV").get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(12),getItemContainer("CentrifugeUMV").get(1)); - - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(5),ItemList.Machine_IV_ElectromagneticSeparator.get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(6),getItemContainer("ElectromagneticSeparatorLuV").get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(7),getItemContainer("ElectromagneticSeparatorZPM").get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(8),getItemContainer("ElectromagneticSeparatorUV").get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(9),getItemContainer("ElectromagneticSeparatorUHV").get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(10),getItemContainer("ElectromagneticSeparatorUEV").get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(11),getItemContainer("ElectromagneticSeparatorUIV").get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(12),getItemContainer("ElectromagneticSeparatorUMV").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(5),ItemList.Machine_IV_Centrifuge.get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(6),getItemContainer("CentrifugeLuV").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(7),getItemContainer("CentrifugeZPM").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(8),getItemContainer("CentrifugeUV").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(9),getItemContainer("CentrifugeUHV").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(10),getItemContainer("CentrifugeUEV").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(11),getItemContainer("CentrifugeUIV").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(12),getItemContainer("CentrifugeUMV").get(1)); + + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(5),ItemList.Machine_IV_ElectromagneticSeparator.get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(6),getItemContainer("ElectromagneticSeparatorLuV").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(7),getItemContainer("ElectromagneticSeparatorZPM").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(8),getItemContainer("ElectromagneticSeparatorUV").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(9),getItemContainer("ElectromagneticSeparatorUHV").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(10),getItemContainer("ElectromagneticSeparatorUEV").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(11),getItemContainer("ElectromagneticSeparatorUIV").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(12),getItemContainer("ElectromagneticSeparatorUMV").get(1)); } } diff --git a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaDequantizer.java b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaDequantizer.java index 84cd28b7c9..6cec48c41f 100644 --- a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaDequantizer.java +++ b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaDequantizer.java @@ -10,6 +10,7 @@ import com.github.technus.tectech.thing.casing.TT_Container_Casings; import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.multi.GT_MetaTileEntity_EM_quantizer; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -45,7 +46,10 @@ public class GT_MetaTileEntity_EM_essentiaDequantizer extends GT_MetaTileEntity_ }; private static final Block[] blockType = new Block[]{QuantumGlassBlock.INSTANCE, sBlockCasingsTT, sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMeta = new byte[]{0,0,4,8}; - private static final String[] addingMethods = new String[]{"addClassicToMachineList", "addElementalInputToMachineList", "addElementalMufflerToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{ + this::addClassicToMachineList, + this::addElementalInputToMachineList, + this::addElementalMufflerToMachineList}; private static final short[] casingTextures = new short[]{textureOffset, textureOffset + 4, textureOffset + 4}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT, sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{0, 4, 4}; diff --git a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaQuantizer.java b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaQuantizer.java index d45060c758..fd56305d5f 100644 --- a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaQuantizer.java +++ b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaQuantizer.java @@ -10,6 +10,7 @@ import com.github.technus.tectech.thing.casing.TT_Container_Casings; import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.multi.GT_MetaTileEntity_EM_quantizer; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -45,7 +46,10 @@ public class GT_MetaTileEntity_EM_essentiaQuantizer extends GT_MetaTileEntity_Mu }; private static final Block[] blockType = new Block[]{QuantumGlassBlock.INSTANCE, sBlockCasingsTT, sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMeta = new byte[]{0,4,0,8}; - private static final String[] addingMethods = new String[]{"addClassicToMachineList", "addElementalOutputToMachineList", "addElementalMufflerToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{ + this::addClassicToMachineList, + this::addElementalOutputToMachineList, + this::addElementalMufflerToMachineList}; private static final short[] casingTextures = new short[]{textureOffset, textureOffset+4, textureOffset + 4}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT, sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{0, 4, 4}; diff --git a/src/main/java/com/github/technus/tectech/loader/recipe/BloodyRecipeLoader.java b/src/main/java/com/github/technus/tectech/loader/recipe/BloodyRecipeLoader.java index 6e3a95aaad..fc2cc455de 100644 --- a/src/main/java/com/github/technus/tectech/loader/recipe/BloodyRecipeLoader.java +++ b/src/main/java/com/github/technus/tectech/loader/recipe/BloodyRecipeLoader.java @@ -570,38 +570,38 @@ public class BloodyRecipeLoader implements Runnable { } private void register_machine_EM_behaviours(){ - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(6),ItemList.Machine_IV_Centrifuge.get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(6),ItemList.Machine_IV_Centrifuge.get(1)); try { - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(7),ItemList.valueOf("Machine_LuV_Centrifuge").get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(8),ItemList.valueOf("Machine_ZPM_Centrifuge").get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(9),ItemList.valueOf("Machine_UV_Centrifuge").get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(10),ItemList.valueOf("Machine_UV_Centrifuge").get(4)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(11),ItemList.valueOf("Machine_UV_Centrifuge").get(16)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(12),ItemList.valueOf("Machine_UV_Centrifuge").get(64)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(7),ItemList.valueOf("Machine_LuV_Centrifuge").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(8),ItemList.valueOf("Machine_ZPM_Centrifuge").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(9),ItemList.valueOf("Machine_UV_Centrifuge").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(10),ItemList.valueOf("Machine_UV_Centrifuge").get(4)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(11),ItemList.valueOf("Machine_UV_Centrifuge").get(16)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(12),ItemList.valueOf("Machine_UV_Centrifuge").get(64)); }catch (IllegalArgumentException|NullPointerException e){ - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(7),ItemList.Machine_IV_Centrifuge.get(2)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(8),ItemList.Machine_IV_Centrifuge.get(4)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(9),ItemList.Machine_IV_Centrifuge.get(8)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(10),ItemList.Machine_IV_Centrifuge.get(16)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(11),ItemList.Machine_IV_Centrifuge.get(32)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_Centrifuge(12),ItemList.Machine_IV_Centrifuge.get(64)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(7),ItemList.Machine_IV_Centrifuge.get(2)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(8),ItemList.Machine_IV_Centrifuge.get(4)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(9),ItemList.Machine_IV_Centrifuge.get(8)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(10),ItemList.Machine_IV_Centrifuge.get(16)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(11),ItemList.Machine_IV_Centrifuge.get(32)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_Centrifuge(12),ItemList.Machine_IV_Centrifuge.get(64)); } - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(6),ItemList.Machine_IV_ElectromagneticSeparator.get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(6),ItemList.Machine_IV_ElectromagneticSeparator.get(1)); try { - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(7),ItemList.valueOf("Machine_LuV_ElectromagneticSeparator").get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(8),ItemList.valueOf("Machine_ZPM_ElectromagneticSeparator").get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(9),ItemList.valueOf("Machine_UV_ElectromagneticSeparator").get(1)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(10),ItemList.valueOf("Machine_UV_ElectromagneticSeparator").get(4)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(11),ItemList.valueOf("Machine_UV_ElectromagneticSeparator").get(16)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(12),ItemList.valueOf("Machine_UV_ElectromagneticSeparator").get(64)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(7),ItemList.valueOf("Machine_LuV_ElectromagneticSeparator").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(8),ItemList.valueOf("Machine_ZPM_ElectromagneticSeparator").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(9),ItemList.valueOf("Machine_UV_ElectromagneticSeparator").get(1)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(10),ItemList.valueOf("Machine_UV_ElectromagneticSeparator").get(4)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(11),ItemList.valueOf("Machine_UV_ElectromagneticSeparator").get(16)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(12),ItemList.valueOf("Machine_UV_ElectromagneticSeparator").get(64)); }catch (IllegalArgumentException|NullPointerException e){ - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(7),ItemList.Machine_IV_ElectromagneticSeparator.get(2)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(8),ItemList.Machine_IV_ElectromagneticSeparator.get(4)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(9),ItemList.Machine_IV_ElectromagneticSeparator.get(8)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(10),ItemList.Machine_IV_ElectromagneticSeparator.get(16)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(11),ItemList.Machine_IV_ElectromagneticSeparator.get(32)); - GT_MetaTileEntity_EM_machine.registerBehaviour(new Behaviour_ElectromagneticSeparator(12),ItemList.Machine_IV_ElectromagneticSeparator.get(64)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(7),ItemList.Machine_IV_ElectromagneticSeparator.get(2)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(8),ItemList.Machine_IV_ElectromagneticSeparator.get(4)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(9),ItemList.Machine_IV_ElectromagneticSeparator.get(8)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(10),ItemList.Machine_IV_ElectromagneticSeparator.get(16)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(11),ItemList.Machine_IV_ElectromagneticSeparator.get(32)); + GT_MetaTileEntity_EM_machine.registerBehaviour(()->new Behaviour_ElectromagneticSeparator(12),ItemList.Machine_IV_ElectromagneticSeparator.get(64)); } } } diff --git a/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java b/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java index 292d446bc4..30751bc961 100644 --- a/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java +++ b/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java @@ -6,7 +6,6 @@ import com.github.technus.tectech.compatibility.thaumcraft.thing.metaTileEntity. import com.github.technus.tectech.compatibility.thaumcraft.thing.metaTileEntity.multi.GT_MetaTileEntity_EM_essentiaQuantizer;
import com.github.technus.tectech.thing.metaTileEntity.hatch.*;
import com.github.technus.tectech.thing.metaTileEntity.multi.*;
-import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM;
import com.github.technus.tectech.thing.metaTileEntity.multi.em_machine.GT_MetaTileEntity_EM_machine;
import com.github.technus.tectech.thing.metaTileEntity.pipe.GT_MetaTileEntity_Pipe_Data;
import com.github.technus.tectech.thing.metaTileEntity.pipe.GT_MetaTileEntity_Pipe_EM;
@@ -349,12 +348,7 @@ public class MachineLoader implements Runnable { // MetaTE init
// ===================================================================================================
- GT_MetaTileEntity_MultiblockBase_EM.run();
GT_MetaTileEntity_Hatch_Rack.run();
- GT_MetaTileEntity_Hatch_Capacitor.run();
- GT_MetaTileEntity_EM_computer.run();
- GT_MetaTileEntity_EM_research.run();
- GT_MetaTileEntity_EM_dataBank.run();
GT_MetaTileEntity_TM_teslaCoil.run();
GT_MetaTileEntity_DataReader.run();
diff --git a/src/main/java/com/github/technus/tectech/thing/item/ParametrizerMemoryCard.java b/src/main/java/com/github/technus/tectech/thing/item/ParametrizerMemoryCard.java index 035b049a99..dafc425163 100644 --- a/src/main/java/com/github/technus/tectech/thing/item/ParametrizerMemoryCard.java +++ b/src/main/java/com/github/technus/tectech/thing/item/ParametrizerMemoryCard.java @@ -57,19 +57,13 @@ public final class ParametrizerMemoryCard extends Item { if (aStack.getItemDamage() == 1) { //write to parametrizer parametrizer.param = tNBT.getInteger("param"); - if (parametrizer.setUsingFloats(tNBT.getBoolean("usesFloats"))) { - parametrizer.value0i = (int) Float.intBitsToFloat(tNBT.getInteger("value0i")); - parametrizer.value1i = (int) Float.intBitsToFloat(tNBT.getInteger("value1i")); - } else { - parametrizer.value0i = tNBT.getInteger("value0i"); - parametrizer.value1i = tNBT.getInteger("value1i"); - } + parametrizer.value0D = tNBT.getDouble("value0D"); + parametrizer.value1D = tNBT.getDouble("value1D"); } else { //read from parametrizer tNBT.setInteger("param", parametrizer.param); - tNBT.setBoolean("usesFloats", parametrizer.isUsingFloats()); - tNBT.setInteger("value0i", parametrizer.value0i); - tNBT.setInteger("value1i", parametrizer.value1i); + tNBT.setDouble("value0D", parametrizer.value0D); + tNBT.setDouble("value1D", parametrizer.value1D); } return true; }else if(metaTE instanceof GT_MetaTileEntity_MultiblockBase_EM){ @@ -79,16 +73,10 @@ public final class ParametrizerMemoryCard extends Item { } NBTTagCompound tNBT = aStack.getTagCompound(); if(aStack.getItemDamage()== 1){ - //write to base - if(tNBT.getBoolean("usesFloats")){ - base.setParameterPairIn_ClearOut(tNBT.getInteger("param"),true - ,Float.intBitsToFloat(tNBT.getInteger("value0i")) - ,Float.intBitsToFloat(tNBT.getInteger("value1i"))); - }else{ - base.setParameterPairIn_ClearOut(tNBT.getInteger("param"),false - ,tNBT.getInteger("value0i") - ,tNBT.getInteger("value1i")); - } + base.parametrization.trySetParameters( + tNBT.getInteger("param"), + tNBT.getDouble("value0D"), + tNBT.getDouble("value1D")); return true; } } @@ -125,17 +113,15 @@ public final class ParametrizerMemoryCard extends Item { } aList.add(EnumChatFormatting.BLUE + "Sneak right click to lock/unlock"); - int temp; + long temp; if(tNBT!=null && tNBT.hasKey("param")) { aList.add("Hatch ID: "+EnumChatFormatting.AQUA + tNBT.getInteger("param")); - temp=tNBT.getInteger("value0i"); - aList.add("Value 0|I: "+EnumChatFormatting.AQUA + temp); - aList.add("Value 0|F: "+EnumChatFormatting.AQUA + Float.intBitsToFloat(temp)); - aList.add("Value 0|B: "+EnumChatFormatting.AQUA + Util.intBitsToShortString(temp)); - temp=tNBT.getInteger("value1i"); - aList.add("Value 1|I: "+EnumChatFormatting.AQUA + temp); - aList.add("Value 1|F: "+EnumChatFormatting.AQUA + Float.intBitsToFloat(temp)); - aList.add("Value 1|B: "+EnumChatFormatting.AQUA + Util.intBitsToShortString(temp)); + temp=tNBT.getInteger("value0D"); + aList.add("Value 0D: "+EnumChatFormatting.AQUA + temp); + aList.add("Value 0B: "+EnumChatFormatting.AQUA + Util.longBitsToShortString(Double.doubleToLongBits(temp))); + temp=tNBT.getInteger("value1D"); + aList.add("Value 1D: "+EnumChatFormatting.AQUA + temp); + aList.add("Value 1B: "+EnumChatFormatting.AQUA + Util.longBitsToShortString(Double.doubleToLongBits(temp))); aList.add("Uses Floats: "+(tNBT.getBoolean("usesFloats")?EnumChatFormatting.GREEN+"TRUE":EnumChatFormatting.RED+"FALSE")); } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Param.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Param.java index 2a2812368b..a4a713626c 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Param.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Param.java @@ -26,13 +26,12 @@ import net.minecraftforge.fluids.FluidStack; * Created by danie_000 on 15.12.2016. */ public class GT_MetaTileEntity_Hatch_Param extends GT_MetaTileEntity_Hatch { - private boolean usesFloat = false; public int pointer = 0; public int param = -1; - public int value0i = 0; - public int value1i = 0; - public int input0i = 0; - public int input1i = 0; + public double value0D = 0; + public double value1D = 0; + public double input0D = 0; + public double input1D = 0; private static Textures.BlockIcons.CustomIcon ScreenON; private static Textures.BlockIcons.CustomIcon ScreenOFF; @@ -105,15 +104,12 @@ public class GT_MetaTileEntity_Hatch_Param extends GT_MetaTileEntity_Hatch { @Override public String[] getInfoData() { - if(mTier>7) { - return new String[]{"Parametrizer ID: " + EnumChatFormatting.GREEN + param, "Value 0I: " + EnumChatFormatting.AQUA + value0i, "Value 0FB: " + EnumChatFormatting.AQUA + Float.intBitsToFloat(value0i) + ' ' + Util.intBitsToShortString(value0i), "Value 1I: " + EnumChatFormatting.BLUE + value1i, "Value 1FB: " + EnumChatFormatting.BLUE + Float.intBitsToFloat(value1i) + ' ' + Util.intBitsToShortString(value1i), "Input 0I: " + EnumChatFormatting.GOLD + input0i, "Input 0FB: " + EnumChatFormatting.GOLD + Float.intBitsToFloat(input0i) + ' ' + Util.intBitsToShortString(input0i), "Input 1I: " + EnumChatFormatting.YELLOW + input1i, "Input 1FB: " + EnumChatFormatting.YELLOW + Float.intBitsToFloat(input1i) + ' ' + Util.intBitsToShortString(input1i),}; - } return new String[]{ "Parametrizer ID: " + EnumChatFormatting.GREEN + param, - "Value 0I: " + EnumChatFormatting.AQUA + value0i, - "Value 1I: " + EnumChatFormatting.BLUE + value1i, - "Input 0I: " + EnumChatFormatting.GOLD + input0i, - "Input 1I: " + EnumChatFormatting.YELLOW + input1i, + "Value 0D: " + EnumChatFormatting.AQUA + value0D, + "Value 1D: " + EnumChatFormatting.BLUE + value1D, + "Input 0D: " + EnumChatFormatting.GOLD + input0D, + "Input 1D: " + EnumChatFormatting.YELLOW + input1D, }; } @@ -135,24 +131,41 @@ public class GT_MetaTileEntity_Hatch_Param extends GT_MetaTileEntity_Hatch { @Override public void saveNBTData(NBTTagCompound aNBT) { super.saveNBTData(aNBT); - aNBT.setBoolean("eFloats", usesFloat); aNBT.setInteger("ePointer", pointer); - aNBT.setInteger("eValue0i", value0i); - aNBT.setInteger("eValue1i", value1i); - aNBT.setInteger("eInput0i", value0i); - aNBT.setInteger("eInput1i", value1i); + aNBT.setDouble("eValue0D", value0D); + aNBT.setDouble("eValue1D", value1D); + aNBT.setDouble("eInput0D", input0D); + aNBT.setDouble("eInput1D", input1D); aNBT.setInteger("eParam", param); } @Override public void loadNBTData(NBTTagCompound aNBT) { super.loadNBTData(aNBT); - usesFloat = aNBT.getBoolean("eFloats"); pointer = aNBT.getInteger("ePointer"); - value0i=aNBT.getInteger("eValue0i"); - value1i=aNBT.getInteger("eValue1i"); - value0i=aNBT.getInteger("eInput0i"); - value1i=aNBT.getInteger("eInput1i"); + if(aNBT.hasKey("eFloats") || + aNBT.hasKey("eValue0i") || + aNBT.hasKey("eValue1i") || + aNBT.hasKey("eInput0i") || + aNBT.hasKey("eInput1i")){ + boolean usesFloat = aNBT.getBoolean("eFloats"); + if(usesFloat){ + value0D=Float.intBitsToFloat(aNBT.getInteger("eValue0i")); + value1D=Float.intBitsToFloat(aNBT.getInteger("eValue1i")); + input0D=Float.intBitsToFloat(aNBT.getInteger("eInput0i")); + input1D=Float.intBitsToFloat(aNBT.getInteger("eInput1i")); + }else { + value0D=aNBT.getInteger("eValue0i"); + value1D=aNBT.getInteger("eValue1i"); + input0D=aNBT.getInteger("eInput0i"); + input1D=aNBT.getInteger("eInput1i"); + } + }else{ + value0D=aNBT.getDouble("eValue0D"); + value1D=aNBT.getDouble("eValue1D"); + input0D=aNBT.getDouble("eInput0D"); + input1D=aNBT.getDouble("eInput1D"); + } param = aNBT.getInteger("eParam"); } @@ -198,17 +211,4 @@ public class GT_MetaTileEntity_Hatch_Param extends GT_MetaTileEntity_Hatch { EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + "E=mine*craft\u00b2" }; } - - public boolean isUsingFloats() { - return mTier > 7 && usesFloat; - } - - //returns - succeded - public boolean setUsingFloats(boolean value){ - if(mTier>7){ - usesFloat=value; - return true; - } - return !value; - } } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_Container_Param.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_Container_Param.java index fec3be6e20..f9c53090ff 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_Container_Param.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_Container_Param.java @@ -1,6 +1,7 @@ package com.github.technus.tectech.thing.metaTileEntity.hatch.gui; import com.github.technus.tectech.TecTech; +import com.github.technus.tectech.Util; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_Param; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -15,10 +16,10 @@ import net.minecraft.item.ItemStack; public class GT_Container_Param extends GT_ContainerMetaTile_Machine { public int param = 0; - public int value0f = 0; - public int value1f = 0; - public int input0f = 0; - public int input1f = 0; + public double value0f = 0; + public double value1f = 0; + public double input0f = 0; + public double input1f = 0; public GT_Container_Param(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { super(aInventoryPlayer, aTileEntity); @@ -61,53 +62,53 @@ public class GT_Container_Param extends GT_ContainerMetaTile_Machine { paramH.param -= aShifthold == 1 ? 16 : 4; break; case 1: - paramH.value0i -= aShifthold == 1 ? 4096 : 256; + paramH.value0D -= aShifthold == 1 ? 4096 : 256; break; case 2: - paramH.value1i -= aShifthold == 1 ? 4096 : 256; + paramH.value1D -= aShifthold == 1 ? 4096 : 256; break; case 3: - paramH.value0i >>= aShifthold == 1 ? 16 : 4; - paramH.value1i >>= aShifthold == 1 ? 16 : 4; + paramH.value0D /= aShifthold == 1 ? 4096 : 256; + paramH.value1D /= aShifthold == 1 ? 4096 : 256; break; case 4: paramH.param -= aShifthold == 1 ? 2 : 1; break; case 5: - paramH.value0i -= aShifthold == 1 ? 16 : 1; + paramH.value0D -= aShifthold == 1 ? 16 : 1; break; case 6: - paramH.value1i -= aShifthold == 1 ? 16 : 1; + paramH.value1D -= aShifthold == 1 ? 16 : 1; break; case 7: - paramH.value0i >>= aShifthold == 1 ? 2 : 1; - paramH.value1i >>= aShifthold == 1 ? 2 : 1; + paramH.value0D /= aShifthold == 1 ? 16 : 2; + paramH.value1D /= aShifthold == 1 ? 16 : 2; break; case 8: paramH.param += aShifthold == 1 ? 16 : 4; break; case 9: - paramH.value0i += aShifthold == 1 ? 4096 : 256; + paramH.value0D += aShifthold == 1 ? 4096 : 256; break; case 10: - paramH.value1i += aShifthold == 1 ? 4096 : 256; + paramH.value1D += aShifthold == 1 ? 4096 : 256; break; case 11: - paramH.value0i <<= aShifthold == 1 ? 16 : 4; - paramH.value1i <<= aShifthold == 1 ? 16 : 4; + paramH.value0D *= aShifthold == 1 ? 4096 : 256; + paramH.value1D *= aShifthold == 1 ? 4096 : 256; break; case 12: paramH.param += aShifthold == 1 ? 2 : 1; break; case 13: - paramH.value0i += aShifthold == 1 ? 16 : 1; + paramH.value0D += aShifthold == 1 ? 16 : 1; break; case 14: - paramH.value1i += aShifthold == 1 ? 16 : 1; + paramH.value1D += aShifthold == 1 ? 16 : 1; break; case 15: - paramH.value0i <<= aShifthold == 1 ? 2 : 1; - paramH.value1i <<= aShifthold == 1 ? 2 : 1; + paramH.value0D *= aShifthold == 1 ? 16 : 2; + paramH.value1D *= aShifthold == 1 ? 16 : 2; break; default: doStuff = false; @@ -132,23 +133,18 @@ public class GT_Container_Param extends GT_ContainerMetaTile_Machine { return; } param = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).param; - value0f = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).value0i; - value1f = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).value1i; - input0f = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).input0i; - input1f = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).input1i; + value0f = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).value0D; + value1f = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).value1D; + input0f = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).input0D; + input1f = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).input1D; for (Object crafter : crafters) { ICrafting var1 = (ICrafting) crafter; - var1.sendProgressBarUpdate(this, 100, param & 0xFFFF); - var1.sendProgressBarUpdate(this, 101, param >>> 16); - var1.sendProgressBarUpdate(this, 102, value0f & 0xFFFF); - var1.sendProgressBarUpdate(this, 103, value0f >>> 16); - var1.sendProgressBarUpdate(this, 104, value1f & 0xFFFF); - var1.sendProgressBarUpdate(this, 105, value1f >>> 16); - var1.sendProgressBarUpdate(this, 106, input0f & 0xFFFF); - var1.sendProgressBarUpdate(this, 107, input0f >>> 16); - var1.sendProgressBarUpdate(this, 108, input1f & 0xFFFF); - var1.sendProgressBarUpdate(this, 109, input1f >>> 16); + Util.sendInteger(param,this,var1,100); + Util.sendDouble(value0f,this,var1,102); + Util.sendDouble(value1f,this,var1, 106); + Util.sendDouble(input0f,this,var1, 110); + Util.sendDouble(input1f,this,var1, 114); } } @@ -158,34 +154,32 @@ public class GT_Container_Param extends GT_ContainerMetaTile_Machine { super.updateProgressBar(par1, par2); switch (par1) { case 100: - param = param & 0xFFFF0000 | par2; - return; case 101: - param = param & 0xFFFF | par2 << 16; + param=Util.receiveInteger(param,100,par1,par2); return; case 102: - value0f = value0f & 0xFFFF0000 | par2; - break; case 103: - value0f = value0f & 0xFFFF | par2 << 16; - break; case 104: - value1f = value1f & 0xFFFF0000 | par2; - break; case 105: - value1f = value1f & 0xFFFF | par2 << 16; - break; + value0f=Util.receiveDouble(value0f,102,par1,par2); + return; case 106: - input0f = input0f & 0xFFFF0000 | par2; - break; case 107: - input0f = input0f & 0xFFFF | par2 << 16; - break; case 108: - input1f = input1f & 0xFFFF0000 | par2; - return; case 109: - input1f = input1f & 0xFFFF | par2 << 16; + value1f=Util.receiveDouble(value1f,106,par1,par2); + return; + case 110: + case 111: + case 112: + case 113: + input0f=Util.receiveDouble(input0f,110,par1,par2); + return; + case 114: + case 115: + case 116: + case 117: + input1f=Util.receiveDouble(input1f,114,par1,par2); return; default: } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_Container_ParamAdv.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_Container_ParamAdv.java index 90d8a26d1c..3ce8b59fd0 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_Container_ParamAdv.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_Container_ParamAdv.java @@ -1,6 +1,7 @@ package com.github.technus.tectech.thing.metaTileEntity.hatch.gui; import com.github.technus.tectech.TecTech; +import com.github.technus.tectech.Util; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_Param; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -14,13 +15,12 @@ import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; public class GT_Container_ParamAdv extends GT_ContainerMetaTile_Machine { - public boolean usesFloats = false; public int pointer=0; public int param = 0; - public int value1f = 0; - public int value0f = 0; - public int input0f = 0; - public int input1f = 0; + public double value1f = 0; + public double value0f = 0; + public double input0f = 0; + public double input1f = 0; public GT_Container_ParamAdv(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { super(aInventoryPlayer, aTileEntity); @@ -60,7 +60,6 @@ public class GT_Container_ParamAdv extends GT_ContainerMetaTile_Machine { GT_MetaTileEntity_Hatch_Param paramH = (GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity(); int columnPointer=paramH.pointer &0xff; boolean secondRow=(paramH.pointer &0x0100)!=0; - boolean showInts=!paramH.isUsingFloats(); switch (aSlotIndex) { case 0: paramH.param -= aShifthold == 1 ? 16 : 4; @@ -82,15 +81,19 @@ public class GT_Container_ParamAdv extends GT_ContainerMetaTile_Machine { case 3: if (aShifthold == 1) { if (secondRow) { - paramH.value1i = 0xFFFFFFFF; + paramH.value1D = Double.longBitsToDouble(0xFFFF_FFFF_FFFF_FFFFL); } else { - paramH.value0i = 0xFFFFFFFF; + paramH.value0D = Double.longBitsToDouble(0xFFFF_FFFF_FFFF_FFFFL); } } else { if (secondRow) { - paramH.value1i |= 1 << columnPointer; + long temp=Double.doubleToLongBits(paramH.value1D); + temp |= 1 << columnPointer; + paramH.value1D=Double.longBitsToDouble(temp); } else { - paramH.value0i |= 1 << columnPointer; + long temp=Double.doubleToLongBits(paramH.value0D); + temp |= 1 << columnPointer; + paramH.value0D=Double.longBitsToDouble(temp); } } break; @@ -114,15 +117,19 @@ public class GT_Container_ParamAdv extends GT_ContainerMetaTile_Machine { case 7: if (aShifthold == 1) { if (secondRow) { - paramH.value1i = 0; + paramH.value1D = Double.longBitsToDouble(0); } else { - paramH.value0i = 0; + paramH.value0D = Double.longBitsToDouble(0); } } else { if (secondRow) { - paramH.value1i &= ~(1 << columnPointer); + long temp=Double.doubleToLongBits(paramH.value1D); + temp &= ~(1 << columnPointer); + paramH.value1D=Double.longBitsToDouble(temp); } else { - paramH.value0i &= ~(1 << columnPointer); + long temp=Double.doubleToLongBits(paramH.value0D); + temp &= ~(1 << columnPointer); + paramH.value0D=Double.longBitsToDouble(temp); } } break; @@ -144,7 +151,8 @@ public class GT_Container_ParamAdv extends GT_ContainerMetaTile_Machine { } break; case 11: - showInts ^= true; + paramH.value0D=paramH.input0D; + paramH.value1D=paramH.input1D; break; case 12: paramH.param += aShifthold == 1 ? 2 : 1; @@ -166,15 +174,19 @@ public class GT_Container_ParamAdv extends GT_ContainerMetaTile_Machine { case 15: if (aShifthold == 1) { if (secondRow) { - paramH.value1i ^= 0xFFFFFFFF; + paramH.value1D = Double.longBitsToDouble(~Double.doubleToLongBits(paramH.value1D)); } else { - paramH.value0i ^= 0xFFFFFFFF; + paramH.value0D = Double.longBitsToDouble(~Double.doubleToLongBits(paramH.value1D)); } } else { if (secondRow) { - paramH.value1i ^= 1 << columnPointer; + long temp=Double.doubleToLongBits(paramH.value1D); + temp ^= 1 << columnPointer; + paramH.value1D=Double.longBitsToDouble(temp); } else { - paramH.value0i ^= 1 << columnPointer; + long temp=Double.doubleToLongBits(paramH.value0D); + temp ^= 1 << columnPointer; + paramH.value0D=Double.longBitsToDouble(temp); } } break; @@ -190,7 +202,6 @@ public class GT_Container_ParamAdv extends GT_ContainerMetaTile_Machine { columnPointer = 0; } paramH.pointer=secondRow?columnPointer+0x100:columnPointer; - paramH.setUsingFloats(!showInts); if (paramH.param > 9) { paramH.param = 9; } else if (paramH.param < -1) { @@ -208,27 +219,20 @@ public class GT_Container_ParamAdv extends GT_ContainerMetaTile_Machine { return; } param = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).param; - value0f = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).value0i; - value1f = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).value1i; - input0f = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).input0i; - input1f = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).input1i; + value0f = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).value0D; + value1f = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).value1D; + input0f = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).input0D; + input1f = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).input1D; pointer = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).pointer; - usesFloats =((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).isUsingFloats(); for (Object crafter : crafters) { ICrafting var1 = (ICrafting) crafter; - var1.sendProgressBarUpdate(this, 100, param & 0xFFFF); - var1.sendProgressBarUpdate(this, 101, param >>> 16); - var1.sendProgressBarUpdate(this, 102, value0f & 0xFFFF); - var1.sendProgressBarUpdate(this, 103, value0f >>> 16); - var1.sendProgressBarUpdate(this, 104, value1f & 0xFFFF); - var1.sendProgressBarUpdate(this, 105, value1f >>> 16); - var1.sendProgressBarUpdate(this, 106, input0f & 0xFFFF); - var1.sendProgressBarUpdate(this, 107, input0f >>> 16); - var1.sendProgressBarUpdate(this, 108, input1f & 0xFFFF); - var1.sendProgressBarUpdate(this, 109, input1f >>> 16); - var1.sendProgressBarUpdate(this, 110, pointer); - var1.sendProgressBarUpdate(this, 111, usesFloats ? 1 : 0); + Util.sendInteger(param,this,var1,100); + Util.sendDouble(value0f,this,var1,102); + Util.sendDouble(value1f,this,var1, 106); + Util.sendDouble(input0f,this,var1, 110); + Util.sendDouble(input1f,this,var1, 114); + Util.sendInteger(pointer,this,var1,118); } } @@ -238,39 +242,37 @@ public class GT_Container_ParamAdv extends GT_ContainerMetaTile_Machine { super.updateProgressBar(par1, par2); switch (par1) { case 100: - param = param & 0xFFFF0000 | par2; - return; case 101: - param = param & 0xFFFF | par2 << 16; + param=Util.receiveInteger(param,100,par1,par2); return; case 102: - value0f = value0f & 0xFFFF0000 | par2; - break; case 103: - value0f = value0f & 0xFFFF | par2 << 16; - break; case 104: - value1f = value1f & 0xFFFF0000 | par2; - break; case 105: - value1f = value1f & 0xFFFF | par2 << 16; - break; + value0f=Util.receiveDouble(value0f,102,par1,par2); + return; case 106: - input0f = input0f & 0xFFFF0000 | par2; - break; case 107: - input0f = input0f & 0xFFFF | par2 << 16; - break; case 108: - input1f = input1f & 0xFFFF0000 | par2; - return; case 109: - input1f = input1f & 0xFFFF | par2 << 16; + value1f=Util.receiveDouble(value1f,106,par1,par2); return; case 110: - pointer = par2 & 0xFFFF; case 111: - usesFloats = par2 != 0; + case 112: + case 113: + input0f=Util.receiveDouble(input0f,110,par1,par2); + return; + case 114: + case 115: + case 116: + case 117: + input1f=Util.receiveDouble(input1f,114,par1,par2); + return; + case 118: + case 119: + pointer=Util.receiveInteger(pointer,118,par1,par2); + return; default: } } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_GUIContainer_Param.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_GUIContainer_Param.java index d9502333d8..015c3742cd 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_GUIContainer_Param.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_GUIContainer_Param.java @@ -4,6 +4,7 @@ import com.github.technus.tectech.Util; import gregtech.api.gui.GT_GUIContainerMetaTile_Machine; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.InventoryPlayer; +import org.lwjgl.opengl.GL11; import java.util.Locale; @@ -20,12 +21,15 @@ public class GT_GUIContainer_Param extends GT_GUIContainerMetaTile_Machine { if (mContainer != null) { proxy.renderUnicodeString("Parameters: " + ((GT_Container_Param) mContainer).param, 46, 7, 167, 0xffffff); Locale locale= Locale.getDefault(); - proxy.renderUnicodeString("\u24EA\u2b07" + String.format(locale, "%+d", ((GT_Container_Param) mContainer).input0f), 46, 16, 167, 0x22ddff); - proxy.renderUnicodeString("\u2460\u2b07" + String.format(locale, "%+d", ((GT_Container_Param) mContainer).input1f), 46, 24, 167, 0x00ffff); - proxy.renderUnicodeString("\u24EA\u2b06" + String.format(locale, "%+d", ((GT_Container_Param) mContainer).value0f), 46, 33, 167, 0x00bbff); - proxy.renderUnicodeString("\u2460\u2b06" + String.format(locale, "%+d", ((GT_Container_Param) mContainer).value1f), 46, 41, 167, 0x0077ff); - proxy.renderUnicodeString("\u24EA\u2b06" + Util.intBitsToShortString(((GT_Container_Param) mContainer).value0f), 46, 50, 167, 0x00bbff); - proxy.renderUnicodeString("\u2460\u2b06" + Util.intBitsToShortString(((GT_Container_Param) mContainer).value1f), 46, 58, 167, 0x0077ff); + proxy.renderUnicodeString("\u24EA\u2b07" + String.format(locale, "%+.5E", ((GT_Container_Param) mContainer).input0f), 46, 16, 167, 0x22ddff); + proxy.renderUnicodeString("\u2460\u2b07" + String.format(locale, "%+.5E", ((GT_Container_Param) mContainer).input1f), 46, 24, 167, 0x00ffff); + proxy.renderUnicodeString("\u24EA\u2b06" + String.format(locale, "%+.5E", ((GT_Container_Param) mContainer).value0f), 46, 33, 167, 0x00bbff); + proxy.renderUnicodeString("\u2460\u2b06" + String.format(locale, "%+.5E", ((GT_Container_Param) mContainer).value1f), 46, 41, 167, 0x0077ff); + GL11.glPushMatrix(); + GL11.glScalef(.5f,.5f,.5f); + proxy.renderUnicodeString("\u24EA\u2b06" + Util.longBitsToShortString(Double.doubleToLongBits(((GT_Container_Param) mContainer).value0f)), 92, 100, 334, 0x00bbff); + proxy.renderUnicodeString("\u2460\u2b06" + Util.longBitsToShortString(Double.doubleToLongBits(((GT_Container_Param) mContainer).value1f)), 92, 116, 334, 0x0077ff); + GL11.glPopMatrix(); } else { proxy.renderUnicodeString("Parameters", 46, 7, 167, 0xffffff); } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_GUIContainer_ParamAdv.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_GUIContainer_ParamAdv.java index 245ec91b20..0e89e00303 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_GUIContainer_ParamAdv.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_GUIContainer_ParamAdv.java @@ -4,6 +4,7 @@ import com.github.technus.tectech.Util; import gregtech.api.gui.GT_GUIContainerMetaTile_Machine; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.InventoryPlayer; +import org.lwjgl.opengl.GL11; import java.util.Locale; @@ -12,27 +13,23 @@ import static gregtech.api.enums.GT_Values.RES_PATH_GUI; public class GT_GUIContainer_ParamAdv extends GT_GUIContainerMetaTile_Machine { public GT_GUIContainer_ParamAdv(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(new GT_Container_ParamAdv(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "ParametrizerAdv.png"); + super(new GT_Container_Param(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "ParametrizerAdv.png"); } @Override protected void drawGuiContainerForegroundLayer(int par1, int par2) { if (mContainer != null) { proxy.renderUnicodeString("Parameters X: " + ((GT_Container_ParamAdv) mContainer).param, 46, 7, 167, 0xffffff); - Locale locale= Locale.getDefault(); - if (((GT_Container_ParamAdv) mContainer).usesFloats) { - proxy.renderUnicodeString("\u24EA\u2b07" + String.format(locale, "%+.5E", Float.intBitsToFloat(((GT_Container_ParamAdv) mContainer).input0f)), 46, 16, 167, 0x22ddff); - proxy.renderUnicodeString("\u2460\u2b07" + String.format(locale, "%+.5E", Float.intBitsToFloat(((GT_Container_ParamAdv) mContainer).input1f)), 46, 24, 167, 0x00ffff); - proxy.renderUnicodeString("\u24EA\u2b06" + String.format(locale, "%+.5E", Float.intBitsToFloat(((GT_Container_ParamAdv) mContainer).value0f)), 46, 33, 167, 0x00bbff); - proxy.renderUnicodeString("\u2460\u2b06" + String.format(locale, "%+.5E", Float.intBitsToFloat(((GT_Container_ParamAdv) mContainer).value1f)), 46, 41, 167, 0x0077ff); - } else { - proxy.renderUnicodeString("\u24EA\u2b07" + String.format(locale, "%+d", ((GT_Container_ParamAdv) mContainer).input0f), 46, 16, 167, 0x22ddff); - proxy.renderUnicodeString("\u2460\u2b07" + String.format(locale, "%+d", ((GT_Container_ParamAdv) mContainer).input1f), 46, 24, 167, 0x00ffff); - proxy.renderUnicodeString("\u24EA\u2b06" + String.format(locale, "%+d", ((GT_Container_ParamAdv) mContainer).value0f), 46, 33, 167, 0x00bbff); - proxy.renderUnicodeString("\u2460\u2b06" + String.format(locale, "%+d", ((GT_Container_ParamAdv) mContainer).value1f), 46, 41, 167, 0x0077ff); - } - proxy.renderUnicodeString("\u24EA\u2b06" + Util.intBitsToShortString(((GT_Container_ParamAdv) mContainer).value0f), 46, 50, 167, 0x00bbff); - proxy.renderUnicodeString("\u2460\u2b06" + Util.intBitsToShortString(((GT_Container_ParamAdv) mContainer).value1f), 46, 58, 167, 0x0077ff); + Locale locale = Locale.getDefault(); + proxy.renderUnicodeString("\u24EA\u2b07" + String.format(locale, "%+.5E", (((GT_Container_ParamAdv) mContainer).input0f)), 46, 16, 167, 0x22ddff); + proxy.renderUnicodeString("\u2460\u2b07" + String.format(locale, "%+.5E", (((GT_Container_ParamAdv) mContainer).input1f)), 46, 24, 167, 0x00ffff); + proxy.renderUnicodeString("\u24EA\u2b06" + String.format(locale, "%+.5E", (((GT_Container_ParamAdv) mContainer).value0f)), 46, 33, 167, 0x00bbff); + proxy.renderUnicodeString("\u2460\u2b06" + String.format(locale, "%+.5E", (((GT_Container_ParamAdv) mContainer).value1f)), 46, 41, 167, 0x0077ff); + GL11.glPushMatrix(); + GL11.glScalef(.5f,.5f,.5f); + proxy.renderUnicodeString("\u24EA\u2b06" + Util.longBitsToShortString(Double.doubleToLongBits(((GT_Container_ParamAdv) mContainer).value0f)), 92, 100, 334, 0x00bbff); + proxy.renderUnicodeString("\u2460\u2b06" + Util.longBitsToShortString(Double.doubleToLongBits(((GT_Container_ParamAdv) mContainer).value1f)), 92, 116, 334, 0x0077ff); + GL11.glPopMatrix(); proxy.renderUnicodeString("Pointer " + Integer.toHexString(((GT_Container_ParamAdv) mContainer).pointer | 0x10000).substring(1), 46, 66, 167, 0x0033ff); } else { proxy.renderUnicodeString("Parameters X", 46, 7, 167, 0xffffff); diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_annihilation.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_annihilation.java index be9ff21e58..2ee110be4c 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_annihilation.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_annihilation.java @@ -4,6 +4,7 @@ import com.github.technus.tectech.CommonValues; import com.github.technus.tectech.thing.block.QuantumGlassBlock; import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; import com.github.technus.tectech.thing.metaTileEntity.multi.base.render.TT_RenderedTexture; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -44,7 +45,7 @@ public class GT_MetaTileEntity_EM_annihilation extends GT_MetaTileEntity_Multibl }; private static final Block[] blockType = new Block[]{sBlockCasingsTT, sBlockCasingsTT, sBlockCasingsTT ,sBlockCasingsTT, QuantumGlassBlock.INSTANCE, sBlockCasingsTT}; private static final byte[] blockMeta = new byte[]{4, 5, 12, 6, 0, 10}; - private static final String[] addingMethods = new String[]{"addClassicToMachineList", "addElementalToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{this::addClassicToMachineList, this::addElementalToMachineList}; private static final short[] casingTextures = new short[]{textureOffset, textureOffset + 4}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{0, 4}; diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_bhg.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_bhg.java index 15e9628b7a..7b662814a6 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_bhg.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_bhg.java @@ -4,6 +4,7 @@ import com.github.technus.tectech.CommonValues; import com.github.technus.tectech.thing.block.QuantumGlassBlock; import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; import com.github.technus.tectech.thing.metaTileEntity.multi.base.render.TT_RenderedTexture; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -73,7 +74,7 @@ public class GT_MetaTileEntity_EM_bhg extends GT_MetaTileEntity_MultiblockBase_E }; private static final Block[] blockType = new Block[]{sBlockCasingsTT,sBlockCasingsTT,sBlockCasingsTT,sBlockCasingsTT,sBlockCasingsTT}; private static final byte[] blockMeta = new byte[]{12, 13, 14, 10, 11}; - private static final String[] addingMethods = new String[]{"addClassicToMachineList", "addElementalToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{this::addClassicToMachineList, this::addElementalToMachineList}; private static final short[] casingTextures = new short[]{textureOffset, textureOffset + 4}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{0, 4}; diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_collider.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_collider.java index 471870b13b..06f1866826 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_collider.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_collider.java @@ -16,6 +16,10 @@ import com.github.technus.tectech.thing.casing.TT_Container_Casings; import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_InputElemental; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.Parameters; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.NameFunction; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.StatusFunction; import com.github.technus.tectech.thing.metaTileEntity.multi.base.render.TT_RenderedTexture; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -37,6 +41,7 @@ import static com.github.technus.tectech.Util.StructureBuilderExtreme; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.textureOffset; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.texturePage; import static com.github.technus.tectech.thing.casing.TT_Container_Casings.sBlockCasingsTT; +import static com.github.technus.tectech.thing.metaTileEntity.multi.base.LedStatus.*; /** * Created by danie_000 on 17.12.2016. @@ -47,13 +52,12 @@ public class GT_MetaTileEntity_EM_collider extends GT_MetaTileEntity_MultiblockB private static Textures.BlockIcons.CustomIcon ScreenON_Slave; private static Textures.BlockIcons.CustomIcon ScreenOFF_Slave; - private static double MASS_TO_EU_PARTIAL,MASS_TO_EU_INSTANT; + protected static final byte FUSE_MODE=0, COLLIDE_MODE =1; + private static double MASS_TO_EU_INSTANT; private static int STARTUP_COST,KEEPUP_COST; - private long plasmaEnergy; - public static void setValues(int heliumPlasmaValue){ - MASS_TO_EU_PARTIAL = heliumPlasmaValue / 1.75893000478707E07;//mass diff + double MASS_TO_EU_PARTIAL = heliumPlasmaValue / 1.75893000478707E07;//mass diff MASS_TO_EU_INSTANT = MASS_TO_EU_PARTIAL * 20; STARTUP_COST=-heliumPlasmaValue*10000; KEEPUP_COST=-heliumPlasmaValue; @@ -266,8 +270,38 @@ public class GT_MetaTileEntity_EM_collider extends GT_MetaTileEntity_MultiblockB protected byte eTier = 0; protected cElementalInstanceStack stack; + private long plasmaEnergy; + + //region parameters + protected Parameters.Group.ParameterIn mode; + private static final StatusFunction<GT_MetaTileEntity_EM_collider> MODE_STATUS = (base_EM, p)->{ + if(base_EM.isMaster()){ + double mode=p.get(); + if (mode == FUSE_MODE || mode == COLLIDE_MODE) { + return STATUS_OK; + } else if (mode > 1) { + return STATUS_TOO_HIGH; + } else if (mode < 0) { + return STATUS_TOO_LOW; + } + return STATUS_WRONG; + } + return STATUS_UNUSED; + }; + private static final NameFunction<GT_MetaTileEntity_EM_collider> MODE_NAME = (base_EM, p)->{ + if(base_EM.isMaster()){ + double mode=p.get(); + if(mode==FUSE_MODE){ + return "Mode: Fuse"; + }else if(mode==COLLIDE_MODE){ + return "Mode: Collide"; + } + return "Mode: Undefined"; + } + return "Currently Slaves..."; + }; + //endregion - protected static final byte FUSE_MODE=0, COLLIDE_MODE =1; protected boolean started=false; //region Structure @@ -305,7 +339,11 @@ public class GT_MetaTileEntity_EM_collider extends GT_MetaTileEntity_MultiblockB }; private static final byte[] blockMeta1 = new byte[]{4, 7, 4, 0, 4, 8}; private static final byte[] blockMeta2 = new byte[]{4, 7, 5, 0, 6, 9}; - private static final String[] addingMethods = new String[]{"addClassicToMachineList", "addElementalInputToMachineList", "addElementalOutputToMachineList", "addElementalMufflerToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{ + this::addClassicToMachineList, + this::addElementalInputToMachineList, + this::addElementalOutputToMachineList, + this::addElementalMufflerToMachineList}; private static final short[] casingTextures = new short[]{textureOffset, textureOffset + 4, textureOffset + 4, textureOffset + 4}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT, sBlockCasingsTT, sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{0, 4, 4, 4}; @@ -328,6 +366,12 @@ public class GT_MetaTileEntity_EM_collider extends GT_MetaTileEntity_MultiblockB } @Override + protected void parametersInstantiation_EM() { + Parameters.Group hatch_0=parametrization.getGroup(0); + mode=hatch_0.makeInParameter(0,FUSE_MODE, MODE_NAME, MODE_STATUS); + } + + @Override public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_EM_collider(mName); } @@ -438,18 +482,9 @@ public class GT_MetaTileEntity_EM_collider extends GT_MetaTileEntity_MultiblockB } @Override - public void parametersOutAndStatusesWrite_EM(boolean machineBusy) { + public void parametersStatusesWrite_EM(boolean machineBusy) { if(isMaster()) { - double mode = getParameterIn(0, 0); - if (mode == FUSE_MODE || mode == COLLIDE_MODE) { - setStatusOfParameterIn(0, 0, STATUS_OK); - } else if (mode > 1) { - setStatusOfParameterIn(0, 0, STATUS_TOO_HIGH); - } else if (mode < 0) { - setStatusOfParameterIn(0, 0, STATUS_TOO_LOW); - }else{ - setStatusOfParameterIn(0,0,STATUS_WRONG); - } + super.parametersStatusesWrite_EM(machineBusy); } } @@ -599,7 +634,7 @@ public class GT_MetaTileEntity_EM_collider extends GT_MetaTileEntity_MultiblockB return; } if (isMaster()) { - switch (getParameterInInt(0,0)){ + switch ((int)mode.get()){ case FUSE_MODE: makeEU(fuse(partner)); break; diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_computer.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_computer.java index 5cc249e700..66b67236de 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_computer.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_computer.java @@ -10,6 +10,11 @@ import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_H import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_OutputData; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_Rack; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.LedStatus; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.Parameters; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.NameFunction; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.StatusFunction; import com.github.technus.tectech.thing.metaTileEntity.multi.base.render.TT_RenderedTexture; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -30,10 +35,10 @@ import java.util.ArrayList; import static com.github.technus.tectech.CommonValues.V; import static com.github.technus.tectech.Util.StructureBuilderExtreme; -import static com.github.technus.tectech.loader.TecTechConfig.DEBUG_MODE; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.textureOffset; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.texturePage; import static com.github.technus.tectech.thing.casing.TT_Container_Casings.sBlockCasingsTT; +import static com.github.technus.tectech.thing.metaTileEntity.multi.base.LedStatus.*; /** * Created by danie_000 on 17.12.2016. @@ -42,8 +47,31 @@ public class GT_MetaTileEntity_EM_computer extends GT_MetaTileEntity_MultiblockB private static Textures.BlockIcons.CustomIcon ScreenOFF; private static Textures.BlockIcons.CustomIcon ScreenON; + //region parameters + protected Parameters.Group.ParameterIn overclock,overvolt; + protected Parameters.Group.ParameterOut maxCurrentTemp,availableData; + private static final NameFunction<GT_MetaTileEntity_EM_computer> OC_NAME = (base, p)-> "Overclock ratio"; + private static final NameFunction<GT_MetaTileEntity_EM_computer> OV_NAME = (base,p)-> "Overvoltage ratio"; + private static final NameFunction<GT_MetaTileEntity_EM_computer> MAX_TEMP_NAME = (base,p)-> "Current max. heat"; + private static final NameFunction<GT_MetaTileEntity_EM_computer> COMPUTE_NAME = (base,p)-> "Produced computation"; + private static final StatusFunction<GT_MetaTileEntity_EM_computer> OC_STATUS= + (base,p)->LedStatus.fromLimitsInclusiveOuterBoundary(p.get(),0,1,1,3); + private static final StatusFunction<GT_MetaTileEntity_EM_computer> OV_STATUS= + (base,p)->LedStatus.fromLimitsInclusiveOuterBoundary(p.get(),.7,.8,1.2,2); + private static final StatusFunction<GT_MetaTileEntity_EM_computer> MAX_TEMP_STATUS= + (base,p)->LedStatus.fromLimitsInclusiveOuterBoundary(p.get(),-10000,0,0,5000); + private static final StatusFunction<GT_MetaTileEntity_EM_computer> COMPUTE_STATUS=(base,p)->{ + if(base.eAvailableData<0){ + return STATUS_TOO_LOW; + } + if(base.eAvailableData==0){ + return STATUS_NEUTRAL; + } + return STATUS_OK; + }; + //endregion + private final ArrayList<GT_MetaTileEntity_Hatch_Rack> eRacks = new ArrayList<>(); - private int maxCurrentTemp = 0; //region Structure private static final String[][] front = new String[][]{{"A ", "A ", "A. ", "A ",},}; @@ -52,7 +80,7 @@ public class GT_MetaTileEntity_EM_computer extends GT_MetaTileEntity_MultiblockB private static final String[][] slice = new String[][]{{"-01", "A!2", "A!2", "-01",},}; private static final Block[] blockType = new Block[]{sBlockCasingsTT, sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMeta = new byte[]{2, 1, 3}; - private static final String[] addingMethods = new String[]{"addToMachineList", "addRackToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{this::addToMachineList, this::addRackToMachineList}; private static final short[] casingTextures = new short[]{textureOffset + 1, textureOffset + 3}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{1, 3}; @@ -76,6 +104,15 @@ public class GT_MetaTileEntity_EM_computer extends GT_MetaTileEntity_MultiblockB } @Override + protected void parametersInstantiation_EM() { + Parameters.Group hatch_0=parametrization.getGroup(0); + overclock=hatch_0.makeInParameter(0,1,OC_NAME,OC_STATUS); + overvolt=hatch_0.makeInParameter(1,1,OV_NAME,OV_STATUS); + maxCurrentTemp=hatch_0.makeOutParameter(0,0,MAX_TEMP_NAME,MAX_TEMP_STATUS); + availableData=hatch_0.makeOutParameter(1,0,COMPUTE_NAME,COMPUTE_STATUS); + } + + @Override @SideOnly(Side.CLIENT) protected ResourceLocation getActivitySound(){ return GT_MetaTileEntity_EM_switch.activitySound; @@ -104,14 +141,15 @@ public class GT_MetaTileEntity_EM_computer extends GT_MetaTileEntity_MultiblockB @Override public boolean checkRecipe_EM(ItemStack itemStack) { + parametrization.setToDefaults(false,true); eAvailableData = 0; - maxCurrentTemp = 0; - double overClockRatio= getParameterIn(0,0); - double overVoltageRatio= getParameterIn(0,1); + double maxTemp=0; + double overClockRatio= overclock.get(); + double overVoltageRatio= overvolt.get(); if(Double.isNaN(overClockRatio) || Double.isNaN(overVoltageRatio)) { return false; } - if(overClockRatio>0 && overVoltageRatio>=0.7f && overClockRatio<=3 && overVoltageRatio<=2){ + if(overclock.getStatus(true).isOk && overvolt.getStatus(true).isOk){ float eut=V[8] * (float)overVoltageRatio * (float)overClockRatio; if(eut<Integer.MAX_VALUE-7) { mEUt = -(int) eut; @@ -126,8 +164,8 @@ public class GT_MetaTileEntity_EM_computer extends GT_MetaTileEntity_MultiblockB if (!GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(rack)) { continue; } - if (rack.heat > maxCurrentTemp) { - maxCurrentTemp = rack.heat; + if (rack.heat > maxTemp) { + maxTemp=rack.heat; } rackComputation = rack.tickComponents((float) overClockRatio, (float) overVoltageRatio); if (rackComputation > 0) { @@ -149,6 +187,8 @@ public class GT_MetaTileEntity_EM_computer extends GT_MetaTileEntity_MultiblockB eAmpereFlow = 1 + (thingsActive >> 2); mMaxProgresstime = 20; mEfficiencyIncrease = 10000; + maxCurrentTemp.set(maxTemp); + availableData.set(eAvailableData); return true; } else { eAvailableData=0; @@ -156,6 +196,8 @@ public class GT_MetaTileEntity_EM_computer extends GT_MetaTileEntity_MultiblockB eAmpereFlow = 1; mMaxProgresstime = 20; mEfficiencyIncrease = 10000; + maxCurrentTemp.set(maxTemp); + availableData.set(eAvailableData); return true; } } @@ -199,68 +241,6 @@ public class GT_MetaTileEntity_EM_computer extends GT_MetaTileEntity_MultiblockB } } - @Override - protected void parametersLoadDefault_EM() { - setParameterPairIn_ClearOut(0, false, 1, 1); - } - - @Override - public void parametersOutAndStatusesWrite_EM(boolean machineBusy) { - double ocRatio = getParameterIn(0, 0); - if (ocRatio < 0) { - setStatusOfParameterIn(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - } else if (ocRatio < 1) { - setStatusOfParameterIn(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_LOW); - } else if (ocRatio == 1) { - setStatusOfParameterIn(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - } else if (ocRatio <= 3) { - setStatusOfParameterIn(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_HIGH); - } else if (Double.isNaN(ocRatio)) { - setStatusOfParameterIn(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - } else { - setStatusOfParameterIn(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - } - - double ovRatio = getParameterIn(0, 1); - if (ovRatio < 0.7f) { - setStatusOfParameterIn(0, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - } else if (ovRatio < 0.8f) { - setStatusOfParameterIn(0, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_LOW); - } else if (ovRatio <= 1.2f) { - setStatusOfParameterIn(0, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - } else if (ovRatio <= 2) { - setStatusOfParameterIn(0, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_HIGH); - } else if (Double.isNaN(ovRatio)) { - setStatusOfParameterIn(0, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - } else { - setStatusOfParameterIn(0, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - } - - setParameterOut(0, 0, maxCurrentTemp); - setParameterOut(0, 1, eAvailableData); - - if (maxCurrentTemp < -10000) { - setStatusOfParameterOut(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - } else if (maxCurrentTemp < 0) { - setStatusOfParameterOut(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_LOW); - } else if (maxCurrentTemp == 0) { - setStatusOfParameterOut(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - } else if (maxCurrentTemp <= 5000) { - setStatusOfParameterOut(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_HIGH); - } else { - setStatusOfParameterOut(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - } - - if (!machineBusy) { - setStatusOfParameterOut(0, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_NEUTRAL); - } else if (eAvailableData <= 0) { - setStatusOfParameterOut(0, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - } else { - setStatusOfParameterOut(0, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - } - } - - @Override//Had a crash bug with breaking a rack and then the multi public void onRemoval() { super.onRemoval(); @@ -373,14 +353,4 @@ public class GT_MetaTileEntity_EM_computer extends GT_MetaTileEntity_MultiblockB } return false; } - - public static void run() { - try { - adderMethodMap.put("addRackToMachineList", GT_MetaTileEntity_EM_computer.class.getMethod("addRackToMachineList", IGregTechTileEntity.class, int.class)); - } catch (NoSuchMethodException e) { - if (DEBUG_MODE) { - e.printStackTrace(); - } - } - } } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_crafting.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_crafting.java index c48f1fdbfe..fc152140fa 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_crafting.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_crafting.java @@ -4,6 +4,7 @@ import com.github.technus.tectech.CommonValues; import com.github.technus.tectech.thing.block.QuantumGlassBlock; import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; import com.github.technus.tectech.thing.metaTileEntity.multi.base.render.TT_RenderedTexture; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -45,7 +46,7 @@ public class GT_MetaTileEntity_EM_crafting extends GT_MetaTileEntity_MultiblockB }; private static final Block[] blockType = new Block[]{sBlockCasingsTT, sBlockCasingsTT, sBlockCasingsTT , QuantumGlassBlock.INSTANCE, sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMeta = new byte[]{4, 10, 5, 0, 6, 9}; - private static final String[] addingMethods = new String[]{"addClassicToMachineList", "addElementalToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{this::addClassicToMachineList, this::addElementalToMachineList}; private static final short[] casingTextures = new short[]{textureOffset, textureOffset + 4}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{0, 4}; diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_dataBank.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_dataBank.java index da2e06c873..b5f4d92872 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_dataBank.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_dataBank.java @@ -2,7 +2,6 @@ package com.github.technus.tectech.thing.metaTileEntity.multi; import com.github.technus.tectech.CommonValues; import com.github.technus.tectech.Reference; -import com.github.technus.tectech.loader.TecTechConfig; import com.github.technus.tectech.mechanics.dataTransport.InventoryDataPacket; import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_InputDataItems; @@ -10,6 +9,7 @@ import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_H import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_Container_MultiMachineEM; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_GUIContainer_MultiMachineEM; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; import com.github.technus.tectech.thing.metaTileEntity.multi.base.render.TT_RenderedTexture; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -45,7 +45,7 @@ public class GT_MetaTileEntity_EM_dataBank extends GT_MetaTileEntity_MultiblockB }; private static final Block[] blockType = new Block[]{sBlockCasingsTT,sBlockCasingsTT}; private static final byte[] blockMeta = new byte[]{2,1}; - private static final String[] addingMethods = new String[]{"addClassicToMachineList","addDataBankHatchToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{this::addClassicToMachineList,this::addDataBankHatchToMachineList}; private static final short[] casingTextures = new short[]{textureOffset,textureOffset+1}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT,sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{0,1}; @@ -113,16 +113,6 @@ public class GT_MetaTileEntity_EM_dataBank extends GT_MetaTileEntity_MultiblockB } @Override - protected void parametersLoadDefault_EM() { - for(int i=0;i<10;i++){ - setStatusOfParameterIn(i,0,STATUS_UNUSED); - setStatusOfParameterIn(i,1,STATUS_UNUSED); - setStatusOfParameterOut(i,0,STATUS_UNUSED); - setStatusOfParameterOut(i,1,STATUS_UNUSED); - } - } - - @Override public boolean checkRecipe_EM(ItemStack itemStack) { if (eDataAccessHatches.size() > 0 && eStacksDataOutputs.size() > 0) { mEUt = -(int) V[7]; @@ -185,14 +175,4 @@ public class GT_MetaTileEntity_EM_dataBank extends GT_MetaTileEntity_MultiblockB } return false; } - - public static void run(){ - try { - adderMethodMap.put("addDataBankHatchToMachineList", GT_MetaTileEntity_EM_dataBank.class.getMethod("addDataBankHatchToMachineList", IGregTechTileEntity.class, int.class)); - } catch (NoSuchMethodException e) { - if (TecTechConfig.DEBUG_MODE) { - e.printStackTrace(); - } - } - } } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_decay.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_decay.java index 71a6b70dfb..b52637d220 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_decay.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_decay.java @@ -7,6 +7,10 @@ import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyMulti; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_InputElemental; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.Parameters; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.NameFunction; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.StatusFunction; import com.github.technus.tectech.thing.metaTileEntity.multi.base.render.TT_RenderedTexture; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -28,6 +32,8 @@ import static com.github.technus.tectech.Util.StructureBuilderExtreme; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.textureOffset; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.texturePage; import static com.github.technus.tectech.thing.casing.TT_Container_Casings.sBlockCasingsTT; +import static com.github.technus.tectech.thing.metaTileEntity.multi.base.LedStatus.STATUS_OK; +import static com.github.technus.tectech.thing.metaTileEntity.multi.base.LedStatus.STATUS_TOO_LOW; /** * Created by danie_000 on 17.12.2016. @@ -40,6 +46,17 @@ public class GT_MetaTileEntity_EM_decay extends GT_MetaTileEntity_MultiblockBase private static final double MASS_TO_EU_PARTIAL = ConfigUtil.getFloat(MainConfig.get(), "balance/energy/generator/nuclear") * 3_000_000.0 / URANIUM_INGOT_MASS_DIFF; private static final double MASS_TO_EU_INSTANT= MASS_TO_EU_PARTIAL *20; + //region parameters + protected Parameters.Group.ParameterIn ampereFlow; + private static final NameFunction<GT_MetaTileEntity_EM_decay> FLOW_NAME= (base, p)->"Ampere divider"; + private static final StatusFunction<GT_MetaTileEntity_EM_decay> FLOW_STATUS= (base, p)->{ + if(base.eAmpereFlow<=0){ + return STATUS_TOO_LOW; + } + return STATUS_OK; + }; + //endregion + //region structure private static final String[][] shape = new String[][]{ {"0C0","A ","A . ","A ","0C0",}, @@ -54,7 +71,7 @@ public class GT_MetaTileEntity_EM_decay extends GT_MetaTileEntity_MultiblockBase }; private static final Block[] blockType = new Block[]{sBlockCasingsTT, sBlockCasingsTT, sBlockCasingsTT ,sBlockCasingsTT}; private static final byte[] blockMeta = new byte[]{4, 5, 8, 6}; - private static final String[] addingMethods = new String[]{"addClassicToMachineList", "addElementalToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{this::addClassicToMachineList, this::addElementalToMachineList}; private static final short[] casingTextures = new short[]{textureOffset, textureOffset + 4}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{0, 4}; @@ -74,6 +91,12 @@ public class GT_MetaTileEntity_EM_decay extends GT_MetaTileEntity_MultiblockBase } @Override + protected void parametersInstantiation_EM() { + Parameters.Group hatch_0=parametrization.getGroup(0, true); + ampereFlow=hatch_0.makeInParameter(0,1,FLOW_NAME,FLOW_STATUS); + } + + @Override public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_EM_decay(mName); } @@ -157,9 +180,12 @@ public class GT_MetaTileEntity_EM_decay extends GT_MetaTileEntity_MultiblockBase float preMass=outputEM[0].getMass(); outputEM[0].tickContent(1,0,1); double energyDose=((preMass-outputEM[0].getMass())* MASS_TO_EU_PARTIAL); - mEUt=(int)(energyDose/getParameterInInt(0,0)); - eAmpereFlow=getParameterInInt(0,0); - + eAmpereFlow=(long) ampereFlow.get(); + if (eAmpereFlow <= 0) { + mEUt=0; + return false; + } + mEUt=(int)(energyDose/eAmpereFlow); return outputEM[0].hasStacks(); } @@ -191,17 +217,17 @@ public class GT_MetaTileEntity_EM_decay extends GT_MetaTileEntity_MultiblockBase return new String[]{ "Progress:", EnumChatFormatting.GREEN + Integer.toString(mProgresstime / 20) + EnumChatFormatting.RESET + " s / " + - EnumChatFormatting.YELLOW + Integer.toString(mMaxProgresstime / 20) + EnumChatFormatting.RESET + " s", + EnumChatFormatting.YELLOW + mMaxProgresstime / 20 + EnumChatFormatting.RESET + " s", "Energy Hatches:", EnumChatFormatting.GREEN + Long.toString(storedEnergy) + EnumChatFormatting.RESET + " EU / " + - EnumChatFormatting.YELLOW + Long.toString(maxEnergy) + EnumChatFormatting.RESET + " EU", + EnumChatFormatting.YELLOW + maxEnergy + EnumChatFormatting.RESET + " EU", (mEUt <= 0 ? "Probably uses: " : "Probably makes: ") + - EnumChatFormatting.RED + Integer.toString(Math.abs(mEUt)) + EnumChatFormatting.RESET + " EU/t at " + + EnumChatFormatting.RED + Math.abs(mEUt) + EnumChatFormatting.RESET + " EU/t at " + EnumChatFormatting.RED + eAmpereFlow + EnumChatFormatting.RESET + " A", "Tier Rating: " + EnumChatFormatting.YELLOW + VN[getMaxEnergyInputTier_EM()] + EnumChatFormatting.RESET + " / " + EnumChatFormatting.GREEN + VN[getMinEnergyInputTier_EM()] + EnumChatFormatting.RESET + " Amp Rating: " + EnumChatFormatting.GREEN + eMaxAmpereFlow + EnumChatFormatting.RESET + " A", "Problems: " + EnumChatFormatting.RED + (getIdealStatus() - getRepairStatus()) + EnumChatFormatting.RESET + - " Efficiency: " + EnumChatFormatting.YELLOW + Float.toString(mEfficiency / 100.0F) + EnumChatFormatting.RESET + " %", + " Efficiency: " + EnumChatFormatting.YELLOW + mEfficiency / 100.0F + EnumChatFormatting.RESET + " %", "PowerPass: " + EnumChatFormatting.BLUE + ePowerPass + EnumChatFormatting.RESET + " SafeVoid: " + EnumChatFormatting.BLUE + eSafeVoid, "Computation: " + EnumChatFormatting.GREEN + eAvailableData + EnumChatFormatting.RESET + " / " + EnumChatFormatting.YELLOW + eRequiredData + EnumChatFormatting.RESET, diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_dequantizer.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_dequantizer.java index 5f102c94ab..a837c6a0a2 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_dequantizer.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_dequantizer.java @@ -10,6 +10,7 @@ import com.github.technus.tectech.thing.block.QuantumGlassBlock; import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_InputElemental; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -46,7 +47,10 @@ public class GT_MetaTileEntity_EM_dequantizer extends GT_MetaTileEntity_Multiblo }; private static final Block[] blockType = new Block[]{sBlockCasingsTT, sBlockCasingsTT, QuantumGlassBlock.INSTANCE}; private static final byte[] blockMeta = new byte[]{0, 4, 0}; - private static final String[] addingMethods = new String[]{"addClassicToMachineList", "addElementalInputToMachineList", "addElementalMufflerToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{ + this::addClassicToMachineList, + this::addElementalInputToMachineList, + this::addElementalMufflerToMachineList}; private static final short[] casingTextures = new short[]{textureOffset, textureOffset + 4, textureOffset + 4}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT, sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{0, 4, 4}; diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_infuser.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_infuser.java index c6eb10c94a..54d14ded92 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_infuser.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_infuser.java @@ -8,6 +8,7 @@ import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_Container_MultiMachineEM; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_GUIContainer_MultiMachineEM; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -39,7 +40,7 @@ public class GT_MetaTileEntity_EM_infuser extends GT_MetaTileEntity_MultiblockBa }; private static final Block[] blockType = new Block[]{sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMeta = new byte[]{7, 4}; - private static final String[] addingMethods = new String[]{"addClassicToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{this::addClassicToMachineList}; private static final short[] casingTextures = new short[]{textureOffset}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{0}; diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_junction.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_junction.java index bd8ed9c6bb..c1248820b3 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_junction.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_junction.java @@ -5,8 +5,13 @@ import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_InputElemental; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_OutputElemental; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.Parameters; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.NameFunction; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.StatusFunction; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.util.GT_Utility; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; @@ -15,6 +20,8 @@ import static com.github.technus.tectech.CommonValues.V; import static com.github.technus.tectech.Util.StructureBuilderExtreme; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.textureOffset; import static com.github.technus.tectech.thing.casing.TT_Container_Casings.sBlockCasingsTT; +import static com.github.technus.tectech.thing.metaTileEntity.multi.base.LedStatus.*; +import static gregtech.api.enums.GT_Values.E; /** * Created by danie_000 on 17.12.2016. @@ -28,9 +35,16 @@ public class GT_MetaTileEntity_EM_junction extends GT_MetaTileEntity_MultiblockB {"!!!", "!0!", "!!!",}, {"!!!", "!!!", "!!!",}, }; - private static final Block[] blockType = new Block[]{sBlockCasingsTT}; - private static final byte[] blockMeta = new byte[]{4}; - private static final String[] addingMethods = new String[]{"addClassicToMachineList", "addElementalToMachineList"}; + private static final String[][] shapeBig = new String[][]{ + {E, "A ", "A . ", "A ",}, + {"A!!!", "!000!", "!010!", "!000!", "A!!!",}, + {"!!!!!", "!000!", "!000!", "!000!", "!!!!!",}, + {"A!!!", "!000!", "!000!", "!000!", "A!!!",}, + {"A!!!", "!!!!!", "!!!!!", "!!!!!", "A!!!",}, + }; + private static final Block[] blockType = new Block[]{sBlockCasingsTT,sBlockCasingsTT}; + private static final byte[] blockMeta = new byte[]{4,5}; + private final HatchAdder[] addingMethods = new HatchAdder[]{this::addClassicToMachineList, this::addElementalToMachineList}; private static final short[] casingTextures = new short[]{textureOffset, textureOffset + 4}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{0, 4}; @@ -41,6 +55,36 @@ public class GT_MetaTileEntity_EM_junction extends GT_MetaTileEntity_MultiblockB }; //endregion + //region parameters + private static final NameFunction<GT_MetaTileEntity_EM_junction> ROUTE_NAME= + (base,p)->(p.parameterId()==0?"Source ":"Destination ")+p.hatchId(); + private static final StatusFunction<GT_MetaTileEntity_EM_junction> SRC_STATUS = + (base,p)-> { + double v = p.get(); + if (Double.isNaN(v)) return STATUS_WRONG; + v=(int)v; + if (v < 0) return STATUS_TOO_LOW; + if (v == 0) return STATUS_NEUTRAL; + if (v >= base.eInputHatches.size()) return STATUS_TOO_HIGH; + return STATUS_OK; + }; + private static final StatusFunction<GT_MetaTileEntity_EM_junction> DST_STATUS = + (base,p)->{ + if(base.src[p.hatchId()].getStatus(false)== STATUS_OK){ + double v = p.get(); + if (Double.isNaN(v)) return STATUS_WRONG; + v=(int)v; + if (v < 0) return STATUS_TOO_LOW; + if (v == 0) return STATUS_LOW; + if (v >= base.eInputHatches.size()) return STATUS_TOO_HIGH; + return STATUS_OK; + } + return STATUS_NEUTRAL; + }; + protected Parameters.Group.ParameterIn[] src; + protected Parameters.Group.ParameterIn[] dst; + //endregion + public GT_MetaTileEntity_EM_junction(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); } @@ -50,13 +94,30 @@ public class GT_MetaTileEntity_EM_junction extends GT_MetaTileEntity_MultiblockB } @Override + protected void parametersInstantiation_EM() { + src=new Parameters.Group.ParameterIn[10]; + dst=new Parameters.Group.ParameterIn[10]; + for (int i = 0; i < 10; i++) { + Parameters.Group hatch = parametrization.getGroup(i); + src[i] = hatch.makeInParameter(0, i, ROUTE_NAME, SRC_STATUS); + dst[i] = hatch.makeInParameter(1, i, ROUTE_NAME, DST_STATUS); + } + } + + @Override public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_EM_junction(mName); } @Override public boolean checkMachine_EM(IGregTechTileEntity iGregTechTileEntity, ItemStack itemStack) { - return structureCheck_EM(shape, blockType, blockMeta, addingMethods, casingTextures, blockTypeFallback, blockMetaFallback, 1, 1, 0); + int meta=iGregTechTileEntity.getMetaIDAtSide(GT_Utility.getOppositeSide(iGregTechTileEntity.getFrontFacing())); + if(meta==4){ + return structureCheck_EM(shape, blockType, blockMeta, addingMethods, casingTextures, blockTypeFallback, blockMetaFallback, 1, 1, 0); + }else if(meta==5){ + return structureCheck_EM(shapeBig, blockType, blockMeta, addingMethods, casingTextures, blockTypeFallback, blockMetaFallback, 2, 2, 0); + } + return false; } @Override @@ -79,38 +140,6 @@ public class GT_MetaTileEntity_EM_junction extends GT_MetaTileEntity_MultiblockB } @Override - public void parametersOutAndStatusesWrite_EM(boolean machineBusy) { - double src, dest; - for (int i = 0; i < 10; i++) { - src = getParameterIn(i, 0); - if (src <= 0) { - setStatusOfParameterIn(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_NEUTRAL); - } else if (src > eInputHatches.size()) { - setStatusOfParameterIn(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_NEUTRAL); - } else if (Double.isNaN(src)) { - setStatusOfParameterIn(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_NEUTRAL); - } else { - setStatusOfParameterIn(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - dest = getParameterIn(i, 1); - if (dest < 0) { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - } else if (dest == 0) { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_LOW); - } else if (dest > eOutputHatches.size()) { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - } else if (Double.isNaN(dest)) { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - } else { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - } - } - } - } - - @Override public boolean checkRecipe_EM(ItemStack itemStack) { for (GT_MetaTileEntity_Hatch_InputElemental in : eInputHatches) { if (in.getContainerHandler().hasStacks()) { @@ -126,18 +155,18 @@ public class GT_MetaTileEntity_EM_junction extends GT_MetaTileEntity_MultiblockB @Override public void outputAfterRecipe_EM() { - double src,dest; + double src,dst; for (int i = 0; i < 10; i++) { - src= getParameterIn(i,0); - dest= getParameterIn(i,1); - if(Double.isNaN(src) || Double.isNaN(dest)) { + src= this.src[i].get(); + dst= this.dst[i].get(); + if(Double.isNaN(src) || Double.isNaN(dst)) { continue; } int inIndex = (int)src - 1; if (inIndex < 0 || inIndex >= eInputHatches.size()) { continue; } - int outIndex = (int)dest - 1; + int outIndex = (int)dst - 1; GT_MetaTileEntity_Hatch_InputElemental in = eInputHatches.get(inIndex); if (outIndex == -1) {//param==0 -> null the content cleanHatchContentEM_EM(in); diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_quantizer.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_quantizer.java index a5a3f451ea..381df4b893 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_quantizer.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_quantizer.java @@ -13,6 +13,7 @@ import com.github.technus.tectech.mechanics.elementalMatter.core.transformations import com.github.technus.tectech.thing.block.QuantumGlassBlock; import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.GregTech_API; @@ -52,7 +53,10 @@ public class GT_MetaTileEntity_EM_quantizer extends GT_MetaTileEntity_Multiblock }; private static final Block[] blockType = new Block[]{sBlockCasingsTT, sBlockCasingsTT, QuantumGlassBlock.INSTANCE}; private static final byte[] blockMeta = new byte[]{4, 0, 0}; - private static final String[] addingMethods = new String[]{"addClassicToMachineList", "addElementalOutputToMachineList", "addElementalMufflerToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{ + this::addClassicToMachineList, + this::addElementalOutputToMachineList, + this::addElementalMufflerToMachineList}; private static final short[] casingTextures = new short[]{textureOffset, textureOffset + 4, textureOffset + 4}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT, sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{0, 4, 4}; diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_research.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_research.java index 377291f59a..88b24d11ae 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_research.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_research.java @@ -1,12 +1,12 @@ package com.github.technus.tectech.thing.metaTileEntity.multi; import com.github.technus.tectech.CommonValues; -import com.github.technus.tectech.loader.TecTechConfig; import com.github.technus.tectech.recipe.TT_recipe; import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyMulti; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_Holder; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; import com.github.technus.tectech.thing.metaTileEntity.multi.base.render.TT_RenderedTexture; import cpw.mods.fml.common.registry.GameRegistry; import gregtech.api.enums.ItemList; @@ -66,7 +66,7 @@ public class GT_MetaTileEntity_EM_research extends GT_MetaTileEntity_MultiblockB }; private static final Block[] blockType = new Block[]{sBlockCasingsTT, sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMeta = new byte[]{1, 3, 2}; - private static final String[] addingMethods = new String[]{"addClassicToMachineList", "addHolderToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{this::addClassicToMachineList, this::addHolderToMachineList}; private static final short[] casingTextures = new short[]{textureOffset + 1, textureOffset + 3}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT, Blocks.air}; private static final byte[] blockMetaFallback = new byte[]{1, 0}; @@ -490,16 +490,6 @@ public class GT_MetaTileEntity_EM_research extends GT_MetaTileEntity_MultiblockB return false; } - public static void run() { - try { - adderMethodMap.put("addHolderToMachineList", GT_MetaTileEntity_EM_research.class.getMethod("addHolderToMachineList", IGregTechTileEntity.class, int.class)); - } catch (NoSuchMethodException e) { - if (TecTechConfig.DEBUG_MODE) { - e.printStackTrace(); - } - } - } - @Override public int getInventoryStackLimit() { return 1; diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_scanner.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_scanner.java index b2711530ed..2461fc5534 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_scanner.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_scanner.java @@ -14,6 +14,11 @@ import com.github.technus.tectech.thing.item.ElementalDefinitionScanStorage_EM; import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyMulti; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.LedStatus; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.Parameters; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.NameFunction; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.StatusFunction; import gregtech.api.enums.ItemList; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -57,6 +62,24 @@ public class GT_MetaTileEntity_EM_scanner extends GT_MetaTileEntity_MultiblockBa private long totalComputationRemaining, totalComputationRequired; private int[] scanComplexity; + //region parameters + private static final NameFunction<GT_MetaTileEntity_EM_scanner> CONFIG_NAME= + (base,p)->"Config at Depth: "+(p.hatchId()*2+p.parameterId()); + private static final StatusFunction<GT_MetaTileEntity_EM_scanner> CONFIG_STATUS= + (base,p)->{ + double v=p.get(); + if(Double.isNaN(v)){ + return LedStatus.STATUS_WRONG; + } + v=(int)v; + if(v==0) return LedStatus.STATUS_NEUTRAL; + if(v>=SCAN_GET_CLASS_TYPE) return LedStatus.STATUS_TOO_HIGH; + if(v<0) return LedStatus.STATUS_TOO_LOW; + return LedStatus.STATUS_OK; + }; + protected Parameters.Group.ParameterIn[] scanConfiguration; + //endregion + //region structure private static final String[][] shape = new String[][]{ {" ", " 222 ", " 2.2 ", " 222 ", " ",}, @@ -70,11 +93,11 @@ public class GT_MetaTileEntity_EM_scanner extends GT_MetaTileEntity_MultiblockBa }; private static final Block[] blockType = new Block[]{sBlockCasingsTT, QuantumGlassBlock.INSTANCE, sBlockCasingsTT}; private static final byte[] blockMeta = new byte[]{4, 0, 0}; - private static final String[] addingMethods = new String[]{ - "addClassicToMachineList", - "addElementalInputToMachineList", - "addElementalOutputToMachineList", - "addElementalMufflerToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{ + this::addClassicToMachineList, + this::addElementalInputToMachineList, + this::addElementalOutputToMachineList, + this::addElementalMufflerToMachineList}; private static final short[] casingTextures = new short[]{textureOffset, textureOffset + 4, textureOffset + 4, textureOffset + 4}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT, sBlockCasingsTT, sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{0, 4, 4, 4}; @@ -98,6 +121,16 @@ public class GT_MetaTileEntity_EM_scanner extends GT_MetaTileEntity_MultiblockBa } @Override + protected void parametersInstantiation_EM() { + scanConfiguration=new Parameters.Group.ParameterIn[20]; + for (int i = 0; i < 10; i++) { + Parameters.Group hatch = parametrization.getGroup(i); + scanConfiguration[i*2] = hatch.makeInParameter(0, 0, CONFIG_NAME, CONFIG_STATUS); + scanConfiguration[i*2+1] = hatch.makeInParameter(0, 0, CONFIG_NAME, CONFIG_STATUS); + } + } + + @Override public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_EM_scanner(mName); } @@ -248,7 +281,7 @@ public class GT_MetaTileEntity_EM_scanner extends GT_MetaTileEntity_MultiblockBa cleanStackEM_EM(stackEM); researchEM.remove(stackEM.definition); } - if(eRecipe!=null && scannerRecipe!=null){//make sure it werks + if(eRecipe!=null && scannerRecipe!=null){//todo make sure it werks totalComputationRequired = totalComputationRemaining = scannerRecipe.mDuration * 20L; mMaxProgresstime = 20;//const mEfficiencyIncrease = 10000; @@ -272,9 +305,8 @@ public class GT_MetaTileEntity_EM_scanner extends GT_MetaTileEntity_MultiblockBa //get depth scan complexity array { int[] scanComplexityTemp = new int[20]; - for (int i = 0; i < 10; i++) { - scanComplexityTemp[i] = getParameterInInt(i, 0); - scanComplexityTemp[i + 10] = getParameterInInt(i, 1); + for (int i = 0; i < 20; i++) { + scanComplexityTemp[i]=(int)scanConfiguration[i].get(); } int maxDepth = 0; for (int i = 0; i < 20; i++) { @@ -418,20 +450,20 @@ public class GT_MetaTileEntity_EM_scanner extends GT_MetaTileEntity_MultiblockBa return new String[]{ "Energy Hatches:", EnumChatFormatting.GREEN + Long.toString(storedEnergy) + EnumChatFormatting.RESET + " EU / " + - EnumChatFormatting.YELLOW + Long.toString(maxEnergy) + EnumChatFormatting.RESET + " EU", + EnumChatFormatting.YELLOW + maxEnergy + EnumChatFormatting.RESET + " EU", (mEUt <= 0 ? "Probably uses: " : "Probably makes: ") + - EnumChatFormatting.RED + Integer.toString(Math.abs(mEUt)) + EnumChatFormatting.RESET + " EU/t at " + + EnumChatFormatting.RED + Math.abs(mEUt) + EnumChatFormatting.RESET + " EU/t at " + EnumChatFormatting.RED + eAmpereFlow + EnumChatFormatting.RESET + " A", "Tier Rating: " + EnumChatFormatting.YELLOW + VN[getMaxEnergyInputTier_EM()] + EnumChatFormatting.RESET + " / " + EnumChatFormatting.GREEN + VN[getMinEnergyInputTier_EM()] + EnumChatFormatting.RESET + " Amp Rating: " + EnumChatFormatting.GREEN + eMaxAmpereFlow + EnumChatFormatting.RESET + " A", "Problems: " + EnumChatFormatting.RED + (getIdealStatus() - getRepairStatus()) + EnumChatFormatting.RESET + - " Efficiency: " + EnumChatFormatting.YELLOW + Float.toString(mEfficiency / 100.0F) + EnumChatFormatting.RESET + " %", + " Efficiency: " + EnumChatFormatting.YELLOW + mEfficiency / 100.0F + EnumChatFormatting.RESET + " %", "PowerPass: " + EnumChatFormatting.BLUE + ePowerPass + EnumChatFormatting.RESET + " SafeVoid: " + EnumChatFormatting.BLUE + eSafeVoid, "Computation Available: " + EnumChatFormatting.GREEN + eAvailableData +EnumChatFormatting.RESET+" / "+EnumChatFormatting.YELLOW + eRequiredData + EnumChatFormatting.RESET, "Computation Remaining:", EnumChatFormatting.GREEN + Long.toString(totalComputationRemaining / 20L) + EnumChatFormatting.RESET + " / " + - EnumChatFormatting.YELLOW + Long.toString(totalComputationRequired / 20L) + EnumChatFormatting.YELLOW + totalComputationRequired / 20L }; } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_stabilizer.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_stabilizer.java index ce16d939cd..2386619e7e 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_stabilizer.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_stabilizer.java @@ -4,6 +4,7 @@ import com.github.technus.tectech.CommonValues; import com.github.technus.tectech.thing.block.QuantumGlassBlock; import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.block.Block; @@ -28,7 +29,7 @@ public class GT_MetaTileEntity_EM_stabilizer extends GT_MetaTileEntity_Multibloc }; private static final Block[] blockType = new Block[]{sBlockCasingsTT, QuantumGlassBlock.INSTANCE, sBlockCasingsTT ,sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMeta = new byte[]{4, 0, 5, 6, 9}; - private static final String[] addingMethods = new String[]{"addClassicToMachineList", "addElementalToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{this::addClassicToMachineList, this::addElementalToMachineList}; private static final short[] casingTextures = new short[]{textureOffset, textureOffset + 4}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{0, 4}; diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_switch.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_switch.java index 1ddb655105..276d0f2f74 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_switch.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_switch.java @@ -8,6 +8,10 @@ import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_InputData; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_OutputData; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.Parameters; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.NameFunction; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.StatusFunction; import com.github.technus.tectech.thing.metaTileEntity.multi.base.render.TT_RenderedTexture; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -25,6 +29,7 @@ import static com.github.technus.tectech.Util.StructureBuilderExtreme; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.textureOffset; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.texturePage; import static com.github.technus.tectech.thing.casing.TT_Container_Casings.sBlockCasingsTT; +import static com.github.technus.tectech.thing.metaTileEntity.multi.base.LedStatus.*; /** * Created by danie_000 on 17.12.2016. @@ -38,7 +43,7 @@ public class GT_MetaTileEntity_EM_switch extends GT_MetaTileEntity_MultiblockBas }; private static final Block[] blockType = new Block[]{sBlockCasingsTT}; private static final byte[] blockMeta = new byte[]{3}; - private static final String[] addingMethods = new String[]{"addClassicToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{this::addClassicToMachineList}; private static final short[] casingTextures = new short[]{textureOffset+1}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{1}; @@ -48,6 +53,34 @@ public class GT_MetaTileEntity_EM_switch extends GT_MetaTileEntity_MultiblockBas }; //endregion + //region parameters + private static final NameFunction<GT_MetaTileEntity_EM_switch> ROUTE_NAME= + (base,p)->(p.parameterId()==0?"Destination ":"Weight ")+p.hatchId(); + private static final StatusFunction<GT_MetaTileEntity_EM_switch> WEI_STATUS = + (base,p)-> { + double v=p.get(); + if (Double.isNaN(v)) return STATUS_WRONG; + if(v<0) return STATUS_TOO_LOW; + if(v==0) return STATUS_LOW; + if(Double.isInfinite(v)) return STATUS_HIGH; + return STATUS_OK; + }; + private static final StatusFunction<GT_MetaTileEntity_EM_switch> DST_STATUS = + (base,p)->{ + if(base.weight[p.hatchId()].getStatus(false).isOk) { + double v = p.get(); + if (Double.isNaN(v)) return STATUS_WRONG; + v = (int) v; + if (v <= 0) return STATUS_TOO_LOW; + if (v >= base.eOutputHatches.size()) return STATUS_TOO_HIGH; + return STATUS_OK; + } + return STATUS_NEUTRAL; + }; + protected Parameters.Group.ParameterIn[] dst; + protected Parameters.Group.ParameterIn[] weight; + //endregion + public GT_MetaTileEntity_EM_switch(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); } @@ -56,6 +89,17 @@ public class GT_MetaTileEntity_EM_switch extends GT_MetaTileEntity_MultiblockBas super(aName); } + @Override + protected void parametersInstantiation_EM() { + dst=new Parameters.Group.ParameterIn[10]; + weight =new Parameters.Group.ParameterIn[10]; + for (int i = 0; i < 10; i++) { + Parameters.Group hatch = parametrization.getGroup(i); + dst[i] = hatch.makeInParameter(0, i, ROUTE_NAME, DST_STATUS); + weight[i] = hatch.makeInParameter(1,0, ROUTE_NAME, WEI_STATUS); + } + } + public final static ResourceLocation activitySound=new ResourceLocation(Reference.MODID+":fx_hi_freq"); @Override @@ -116,12 +160,10 @@ public class GT_MetaTileEntity_EM_switch extends GT_MetaTileEntity_MultiblockBas public void outputAfterRecipe_EM() { if (!eOutputData.isEmpty()) { double total = 0; - double dest; double weight; for (int i = 0; i < 10; i++) {//each param pair - dest= getParameterIn(i,1); - weight= getParameterIn(i,0); - if (weight > 0 && dest >= 0) { + weight= this.weight[i].get(); + if (weight > 0 && dst[i].get() >= 0) { total += weight;//Total weighted div } } @@ -143,9 +185,10 @@ public class GT_MetaTileEntity_EM_switch extends GT_MetaTileEntity_MultiblockBas long remaining = pack.getContent(); + double dest; for (int i = 0; i < 10; i++) { - dest= getParameterIn(i,1); - weight= getParameterIn(i,0); + dest= dst[i].get(); + weight= this.weight[i].get(); if (weight > 0 && dest >= 0) { int outIndex = (int)dest - 1; if (outIndex < 0 || outIndex >= eOutputData.size()) { @@ -177,35 +220,6 @@ public class GT_MetaTileEntity_EM_switch extends GT_MetaTileEntity_MultiblockBas } @Override - public void parametersOutAndStatusesWrite_EM(boolean machineBusy) { - double weight, dest; - for (int i = 0; i < 10; i++) { - weight = getParameterIn(i, 0); - if (weight < 0) { - setStatusOfParameterIn(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_NEUTRAL); - } else if (Double.isNaN(weight)) { - setStatusOfParameterIn(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_NEUTRAL); - } else { - setStatusOfParameterIn(i, 0, weight==0?STATUS_LOW:GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - dest = getParameterIn(i, 1); - if (dest < 0) { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - } else if (dest == 0) { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_LOW); - } else if (dest > eOutputData.size()) { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - } else if (Double.isNaN(dest)) { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - } else { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - } - } - } - } - - @Override public String[] getDescription() { return new String[]{ CommonValues.TEC_MARK_EM, diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_transformer.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_transformer.java index 4584e86122..65f2301e41 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_transformer.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_transformer.java @@ -6,6 +6,7 @@ import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_Container_MultiMachineEM; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_GUIContainer_MultiMachineEM; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; import com.github.technus.tectech.thing.metaTileEntity.multi.base.render.TT_RenderedTexture; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -37,7 +38,7 @@ public class GT_MetaTileEntity_EM_transformer extends GT_MetaTileEntity_Multiblo }; private static final Block[] blockType = new Block[]{sBlockCasings1}; private static final byte[] blockMeta = new byte[]{15}; - private static final String[] addingMethods = new String[]{"addEnergyIOToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{this::addEnergyIOToMachineList}; private static final short[] casingTextures = new short[]{textureOffset}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{0}; diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_wormhole.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_wormhole.java index 5e60f59807..50070972ca 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_wormhole.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_wormhole.java @@ -4,6 +4,7 @@ import com.github.technus.tectech.CommonValues; import com.github.technus.tectech.thing.block.QuantumGlassBlock; import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; import com.github.technus.tectech.thing.metaTileEntity.multi.base.render.TT_RenderedTexture; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -45,7 +46,7 @@ public class GT_MetaTileEntity_EM_wormhole extends GT_MetaTileEntity_MultiblockB }; private static final Block[] blockType = new Block[]{sBlockCasingsTT, sBlockCasingsTT, QuantumGlassBlock.INSTANCE ,sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMeta = new byte[]{12, 10, 0, 5, 11}; - private static final String[] addingMethods = new String[]{"addClassicToMachineList", "addElementalToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{this::addClassicToMachineList, this::addElementalToMachineList}; private static final short[] casingTextures = new short[]{textureOffset, textureOffset + 4}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{0, 4}; diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_microwave.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_microwave.java index 7e3a51da4f..7894a7fa37 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_microwave.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_microwave.java @@ -3,9 +3,9 @@ package com.github.technus.tectech.thing.metaTileEntity.multi; import com.github.technus.tectech.CommonValues; import com.github.technus.tectech.Reference; import com.github.technus.tectech.thing.metaTileEntity.IConstructable; -import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_Container_MultiMachineEM; -import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_GUIContainer_MultiMachineEM; -import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.*; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.NameFunction; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.StatusFunction; import com.github.technus.tectech.thing.metaTileEntity.multi.base.render.TT_RenderedTexture; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; @@ -19,7 +19,6 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.EnumChatFormatting; @@ -28,14 +27,13 @@ import java.util.HashSet; import static com.github.technus.tectech.Util.StructureBuilderExtreme; import static com.github.technus.tectech.loader.MainLoader.microwaving; +import static com.github.technus.tectech.thing.metaTileEntity.multi.base.LedStatus.*; import static gregtech.api.GregTech_API.sBlockCasings4; /** * Created by danie_000 on 17.12.2016. */ public class GT_MetaTileEntity_TM_microwave extends GT_MetaTileEntity_MultiblockBase_EM implements IConstructable { - public static final int POWER_SETTING_DEFAULT=1000, TIMER_SETTING_DEFAULT=360; - private int powerSetting,timerSetting,timerValue; private boolean hasBeenPausedThisCycle=false; //region Structure @@ -50,7 +48,7 @@ public class GT_MetaTileEntity_TM_microwave extends GT_MetaTileEntity_Multiblock private static final Block[] blockType = new Block[]{sBlockCasings4}; private static final byte[] blockMeta = new byte[]{1}; - private static final String[] addingMethods = new String[]{"addClassicToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{this::addClassicToMachineList}; private static final short[] casingTextures = new short[]{49}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasings4}; private static final byte[] blockMetaFallback = new byte[]{1}; @@ -61,6 +59,25 @@ public class GT_MetaTileEntity_TM_microwave extends GT_MetaTileEntity_Multiblock }; //endregion + //region parameters + protected Parameters.Group.ParameterIn powerSetting,timerSetting; + protected Parameters.Group.ParameterOut timerValue,remainingTime; + private static final NameFunction<GT_MetaTileEntity_TM_microwave> POWER_NAME = (base, p)-> "Power setting"; + private static final NameFunction<GT_MetaTileEntity_TM_microwave> TIMER_SETTING_NAME = (base, p)-> "Timer setting"; + private static final NameFunction<GT_MetaTileEntity_TM_microwave> TIMER_REMAINING_NAME = (base, p)-> "Timer remaining"; + private static final NameFunction<GT_MetaTileEntity_TM_microwave> TIMER_VALUE_NAME = (base,p)-> "Timer value"; + private static final StatusFunction<GT_MetaTileEntity_TM_microwave> POWER_STATUS= + (base,p)-> LedStatus.fromLimitsInclusiveOuterBoundary(p.get(),300,1000,1000,Double.POSITIVE_INFINITY); + private static final StatusFunction<GT_MetaTileEntity_TM_microwave> TIMER_STATUS=(base,p)->{ + double value=p.get(); + if(Double.isNaN(value)) return STATUS_WRONG; + value=(int)value; + if(value<=0) return STATUS_TOO_LOW; + if(value>3000) return STATUS_TOO_HIGH; + return STATUS_OK; + }; + //endregion + public GT_MetaTileEntity_TM_microwave(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); } @@ -70,12 +87,18 @@ public class GT_MetaTileEntity_TM_microwave extends GT_MetaTileEntity_Multiblock } @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_TM_microwave(mName); + protected void parametersInstantiation_EM() { + Parameters.Group hatch_0=parametrization.getGroup(0, true); + powerSetting=hatch_0.makeInParameter(0,1000, POWER_NAME,POWER_STATUS); + timerSetting=hatch_0.makeInParameter(1,360, TIMER_SETTING_NAME,TIMER_STATUS); + timerValue=hatch_0.makeOutParameter(0,0,TIMER_VALUE_NAME,TIMER_STATUS); + remainingTime=hatch_0.makeOutParameter(1,360,TIMER_REMAINING_NAME,TIMER_STATUS); } @Override - public void onRemoval(){}//Literally stops this machine from exploding if you break it with some power left, it doesn't deal with any EM ffs + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_TM_microwave(mName); + } @Override public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { @@ -125,13 +148,14 @@ public class GT_MetaTileEntity_TM_microwave extends GT_MetaTileEntity_Multiblock @Override public boolean checkRecipe_EM(ItemStack itemStack) { hasBeenPausedThisCycle =false; - if(powerSetting<300 || timerSetting<=0 || timerSetting>3000) { + if((int)powerSetting.get()<300 || timerSetting.get()<=0 || timerSetting.get()>3000) { return false; } - if (timerValue <= 0) { - timerValue=timerSetting; + if (remainingTime.get() <= 0) { + remainingTime.set(timerSetting.get()); + timerValue.set(0); } - mEUt = -(powerSetting >> 1); + mEUt = -((int)powerSetting.get() >> 1); eAmpereFlow = 1; mMaxProgresstime = 20; mEfficiencyIncrease = 10000; @@ -143,7 +167,8 @@ public class GT_MetaTileEntity_TM_microwave extends GT_MetaTileEntity_Multiblock if(hasBeenPausedThisCycle) { return;//skip timer and actions if paused } - timerValue--; + timerValue.set(timerValue.get()+1); + remainingTime.set(timerSetting.get()-timerValue.get()); IGregTechTileEntity mte=getBaseMetaTileEntity(); double[] xyzOffsets= getTranslatedOffsets(0,-1,2); double xPos=mte.getXCoord()+0.5f+xyzOffsets[0]; @@ -155,12 +180,12 @@ public class GT_MetaTileEntity_TM_microwave extends GT_MetaTileEntity_Multiblock for(int i=0;i<3;i++){//gets ABS from translated to get expansion values if(xyzExpansion[i]<0)xyzExpansion[i]=-xyzExpansion[i]; } - + int power=(int)powerSetting.get(); int damagingFactor = - Math.min(powerSetting >> 6,8)+ - Math.min(powerSetting >> 8,24)+ - Math.min(powerSetting >> 12,48)+ - (powerSetting >> 18); + Math.min(power >> 6,8)+ + Math.min(power >> 8,24)+ + Math.min(power >> 12,48)+ + (power >> 18); ArrayList<ItemStack> itemsToOutput=new ArrayList<>(); HashSet<Entity> tickedStuff=new HashSet<>(); @@ -196,60 +221,15 @@ public class GT_MetaTileEntity_TM_microwave extends GT_MetaTileEntity_Multiblock damagingFactor>>=1; } while(damagingFactor>0); - mOutputItems= itemsToOutput.toArray(new ItemStack[itemsToOutput.size()]); + mOutputItems= itemsToOutput.toArray(new ItemStack[0]); - if(timerValue<=0) { + if(remainingTime.get() <=0) { mte.getWorld().playSoundEffect(xPos,yPos,zPos, Reference.MODID+":microwave_ding", 1, 1); stopMachine(); } } @Override - protected void parametersLoadDefault_EM() { - powerSetting = POWER_SETTING_DEFAULT; - timerSetting = TIMER_SETTING_DEFAULT; - setParameterPairIn_ClearOut(0,false, POWER_SETTING_DEFAULT, TIMER_SETTING_DEFAULT); - } - - @Override - protected void parametersInRead_EM() { - powerSetting = (int) getParameterIn(0, 0); - timerSetting = (int) getParameterIn(0, 1); - } - - @Override - public void parametersOutAndStatusesWrite_EM(boolean machineBusy) { - double powerParameter = getParameterIn(0, 0); - if (powerParameter < 300) { - setStatusOfParameterIn(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - } else if (powerParameter < 1000) { - setStatusOfParameterIn(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_LOW); - } else if (powerParameter == 1000) { - setStatusOfParameterIn(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - } else if (powerParameter == Double.POSITIVE_INFINITY) { - setStatusOfParameterIn(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - } else if (Double.isNaN(powerParameter)) { - setStatusOfParameterIn(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - } else { - setStatusOfParameterOut(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_HIGH); - } - - double timerParameter = getParameterIn(0, 1); - if (timerParameter <= 1) { - setStatusOfParameterIn(0, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - } else if (timerParameter <= 3000) { - setStatusOfParameterIn(0, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - } else if (Double.isNaN(timerParameter)) { - setStatusOfParameterIn(0, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - } else { - setStatusOfParameterIn(0, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - } - - setParameterOut(0, 0, timerValue); - setParameterOut(0, 1, timerSetting - timerValue); - } - - @Override public boolean onRunningTick(ItemStack aStack) { if(eSafeVoid) { hasBeenPausedThisCycle = true; @@ -260,19 +240,8 @@ public class GT_MetaTileEntity_TM_microwave extends GT_MetaTileEntity_Multiblock @Override public void stopMachine() { super.stopMachine(); - timerValue=0; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setInteger("eTimerVal", timerValue); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - timerValue = aNBT.getInteger("eTimerVal"); + remainingTime.set(timerSetting.get()); + timerValue.set(0); } @Override diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_Container_MultiMachineEM.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_Container_MultiMachineEM.java index 91b2635001..ea22e3c23c 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_Container_MultiMachineEM.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_Container_MultiMachineEM.java @@ -1,6 +1,7 @@ package com.github.technus.tectech.thing.metaTileEntity.multi.base; import com.github.technus.tectech.TecTech; +import com.github.technus.tectech.Util; import gregtech.api.gui.GT_ContainerMetaTile_Machine; import gregtech.api.gui.GT_Slot_Holo; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -11,8 +12,10 @@ import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; public class GT_Container_MultiMachineEM extends GT_ContainerMetaTile_Machine { - public byte[] eParamsInStatus = new byte[20];//unused 0,G ok 1, B too low 2, R too high 3, Y blink dangerous 4,5 - public byte[] eParamsOutStatus = new byte[20]; + public LedStatus[] eParamsInStatus = LedStatus.makeArray(20,LedStatus.STATUS_UNDEFINED); + public LedStatus[] eParamsOutStatus = LedStatus.makeArray(20,LedStatus.STATUS_UNDEFINED); + public double[] eParamsIn = new double[20];//number I from parametrizers + public double[] eParamsOut = new double[20];//number O to parametrizers public byte eCertainMode = 5, eCertainStatus = 127; public boolean ePowerPass = false, eSafeVoid = false, allowedToWork = false; public final boolean ePowerPassButton, eSafeVoidButton, allowedToWorkButton; @@ -106,8 +109,10 @@ public class GT_Container_MultiMachineEM extends GT_ContainerMetaTile_Machine { if (mTileEntity.isClientSide() || mTileEntity.getMetaTileEntity() == null || eParamsInStatus == null) { return; } - eParamsInStatus = ((GT_MetaTileEntity_MultiblockBase_EM) mTileEntity.getMetaTileEntity()).eParamsInStatus; - eParamsOutStatus = ((GT_MetaTileEntity_MultiblockBase_EM) mTileEntity.getMetaTileEntity()).eParamsOutStatus; + eParamsInStatus = ((GT_MetaTileEntity_MultiblockBase_EM) mTileEntity.getMetaTileEntity()).parametrization.eParamsInStatus; + eParamsOutStatus = ((GT_MetaTileEntity_MultiblockBase_EM) mTileEntity.getMetaTileEntity()).parametrization.eParamsOutStatus; + eParamsIn= ((GT_MetaTileEntity_MultiblockBase_EM) mTileEntity.getMetaTileEntity()).parametrization.iParamsIn; + eParamsOut= ((GT_MetaTileEntity_MultiblockBase_EM) mTileEntity.getMetaTileEntity()).parametrization.iParamsOut; eCertainMode = ((GT_MetaTileEntity_MultiblockBase_EM) mTileEntity.getMetaTileEntity()).eCertainMode; eCertainStatus = ((GT_MetaTileEntity_MultiblockBase_EM) mTileEntity.getMetaTileEntity()).eCertainStatus; ePowerPass = ((GT_MetaTileEntity_MultiblockBase_EM) mTileEntity.getMetaTileEntity()).ePowerPass; @@ -116,12 +121,15 @@ public class GT_Container_MultiMachineEM extends GT_ContainerMetaTile_Machine { for (Object crafter : crafters) { ICrafting var1 = (ICrafting) crafter; - int i = 100; - for (int j = 0; j < eParamsInStatus.length; j++) { - var1.sendProgressBarUpdate(this, i++, eParamsInStatus[j] | eParamsOutStatus[j] << 8); + for (int i=100, j = 0; j < eParamsInStatus.length; j++) { + var1.sendProgressBarUpdate(this, i++, (eParamsInStatus[j].getOrdinalByte() | (eParamsOutStatus[j].getOrdinalByte() << 8))); } - var1.sendProgressBarUpdate(this, 120, eCertainMode | eCertainStatus << 8); + var1.sendProgressBarUpdate(this, 120, eCertainMode | (eCertainStatus << 8)); var1.sendProgressBarUpdate(this, 121, (ePowerPass ? 1 : 0) + (eSafeVoid ? 2 : 0) + (allowedToWork ? 4 : 0)); + for(int i=124,k=204,j=0;j<20;j++,i+=4,k+=4) { + Util.sendDouble(eParamsOut[j], this, var1, i); + Util.sendDouble(eParamsIn[j], this, var1, k); + } } } @@ -132,8 +140,8 @@ public class GT_Container_MultiMachineEM extends GT_ContainerMetaTile_Machine { return; } if (par1 >= 100 && par1 < 120) { - eParamsInStatus[par1 - 100] = (byte) (par2 & 0xff); - eParamsOutStatus[par1 - 100] = (byte) (par2 >>> 8); + eParamsInStatus[par1 - 100] = LedStatus.getStatus ((byte) (par2 & 0xff)); + eParamsOutStatus[par1 - 100] = LedStatus.getStatus ((byte) (par2 >>> 8)); } else if (par1 == 120) { eCertainMode = (byte) (par2 & 0xff); eCertainStatus = (byte) (par2 >>> 8); @@ -141,6 +149,12 @@ public class GT_Container_MultiMachineEM extends GT_ContainerMetaTile_Machine { ePowerPass = (par2 & 1) == 1; eSafeVoid = (par2 & 2) == 2; allowedToWork = (par2 & 4) == 4; + } else if(par1>=130 && par1<210){ + int pos=(par1-130)>>2; + eParamsIn[pos]=Util.receiveDouble(eParamsIn[pos],par1&0xFFFFFFFC,par1,par2); + }else if(par1>=210 && par1<290){ + int pos=(par1-210)>>2; + eParamsIn[pos]=Util.receiveDouble(eParamsIn[pos],par1&0xFFFFFFFC,par1,par2); } } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_GUIContainer_MultiMachineEM.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_GUIContainer_MultiMachineEM.java index 40285cc5e7..94e2d0af8d 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_GUIContainer_MultiMachineEM.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_GUIContainer_MultiMachineEM.java @@ -12,7 +12,6 @@ import org.lwjgl.opengl.GL12; import java.util.List; -import static com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM.*; import static gregtech.api.enums.GT_Values.RES_PATH_GUI; /** @@ -23,9 +22,11 @@ public class GT_GUIContainer_MultiMachineEM extends GT_GUIContainerMetaTile_Mach private String mName; private static byte counter = 0; private final boolean ePowerPassButton, eSafeVoidButton, allowedToWorkButton; + private final GT_Container_MultiMachineEM mContainer; public GT_GUIContainer_MultiMachineEM(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName, String aTextureFile, boolean enablePowerPass, boolean enableSafeVoid, boolean enablePowerButton) { super(new GT_Container_MultiMachineEM(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "multimachines/" + (aTextureFile == null ? "MultiblockDisplay" : aTextureFile)); + mContainer=(GT_Container_MultiMachineEM)super.mContainer; mName = aName; ePowerPassButton=enablePowerPass; eSafeVoidButton=enableSafeVoid; @@ -36,6 +37,7 @@ public class GT_GUIContainer_MultiMachineEM extends GT_GUIContainerMetaTile_Mach public GT_GUIContainer_MultiMachineEM(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName, String aTextureFile) { super(new GT_Container_MultiMachineEM(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "multimachines/" + (aTextureFile == null ? "MultiblockDisplay" : aTextureFile)); + mContainer=(GT_Container_MultiMachineEM)super.mContainer; mName = aName; ePowerPassButton=eSafeVoidButton=allowedToWorkButton=true; ySize= 192; @@ -57,36 +59,36 @@ public class GT_GUIContainer_MultiMachineEM extends GT_GUIContainerMetaTile_Mach fontRendererObj.drawString(mName, 7, 8, 16448255); if (mContainer != null) { - if ((((GT_Container_MultiMachineEM) mContainer).mDisplayErrorCode & 1) != 0) { + if ((mContainer.mDisplayErrorCode & 1) != 0) { fontRendererObj.drawString("Pipe is loose.", 7, 16, 16448255); } - if ((((GT_Container_MultiMachineEM) mContainer).mDisplayErrorCode & 2) != 0) { + if ((mContainer.mDisplayErrorCode & 2) != 0) { fontRendererObj.drawString("Screws are loose.", 7, 24, 16448255); } - if ((((GT_Container_MultiMachineEM) mContainer).mDisplayErrorCode & 4) != 0) { + if ((mContainer.mDisplayErrorCode & 4) != 0) { fontRendererObj.drawString("Something is stuck.", 7, 32, 16448255); } - if ((((GT_Container_MultiMachineEM) mContainer).mDisplayErrorCode & 8) != 0) { + if ((mContainer.mDisplayErrorCode & 8) != 0) { fontRendererObj.drawString("Plating is dented.", 7, 40, 16448255); } - if ((((GT_Container_MultiMachineEM) mContainer).mDisplayErrorCode & 16) != 0) { + if ((mContainer.mDisplayErrorCode & 16) != 0) { fontRendererObj.drawString("Circuitry burned out.", 7, 48, 16448255); } - if ((((GT_Container_MultiMachineEM) mContainer).mDisplayErrorCode & 32) != 0) { + if ((mContainer.mDisplayErrorCode & 32) != 0) { fontRendererObj.drawString("That doesn't belong there.", 7, 56, 16448255); } - if ((((GT_Container_MultiMachineEM) mContainer).mDisplayErrorCode & 64) != 0) { + if ((mContainer.mDisplayErrorCode & 64) != 0) { fontRendererObj.drawString("Incomplete Structure.", 7, 64, 16448255); } - if ((((GT_Container_MultiMachineEM) mContainer).mDisplayErrorCode & 128) != 0) { + if ((mContainer.mDisplayErrorCode & 128) != 0) { fontRendererObj.drawString("Too Uncertain.", 7, 72, 16448255); } - if ((((GT_Container_MultiMachineEM) mContainer).mDisplayErrorCode & 256) != 0) { + if ((mContainer.mDisplayErrorCode & 256) != 0) { fontRendererObj.drawString("Invalid Parameters.", 7, 80, 16448255); } - if (((GT_Container_MultiMachineEM) mContainer).mDisplayErrorCode == 0) { - if (((GT_Container_MultiMachineEM) mContainer).mActive == 0) { + if (mContainer.mDisplayErrorCode == 0) { + if (mContainer.mActive == 0) { fontRendererObj.drawString("Soft Hammer or press Button", 7, 16, 16448255); fontRendererObj.drawString("to (re-)start the Machine", 7, 24, 16448255); fontRendererObj.drawString("if it doesn't start.", 7, 32, 16448255); @@ -103,41 +105,41 @@ public class GT_GUIContainer_MultiMachineEM extends GT_GUIContainerMetaTile_Mach int x = (width - xSize) / 2; int y = (height - ySize) / 2; drawTexturedModalRect(x, y, 0, 0, xSize, ySize); - if (mContainer != null && ((GT_Container_MultiMachineEM) mContainer).eParamsInStatus != null) { + if (mContainer != null && mContainer.eParamsInStatus != null) { counter = (byte) ((1 + counter) % 6); GL11.glColor4f(1f, 1f, 1f, 1f); x+= 173; if(!ePowerPassButton) { drawTexturedModalRect(x, y + 115, 231, 23, 18, 18); - } else if (((GT_Container_MultiMachineEM) mContainer).ePowerPass) { + } else if (mContainer.ePowerPass) { drawTexturedModalRect(x, y + 115, 207, 23, 18, 18); } if(!eSafeVoidButton) { drawTexturedModalRect(x, y + 132, 231, 41, 18, 18); - } else if (((GT_Container_MultiMachineEM) mContainer).eSafeVoid) { + } else if (mContainer.eSafeVoid) { drawTexturedModalRect(x, y + 132, 207, 41, 18, 18); } if(!allowedToWorkButton) { drawTexturedModalRect(x, y + 147, 231, 57, 18, 18); - } else if (((GT_Container_MultiMachineEM) mContainer).allowedToWork) { + } else if (mContainer.allowedToWork) { drawTexturedModalRect(x, y + 147, 207, 57, 18, 18); } x -= 162; y += 96; for (int i = 0; i < 20; ) { byte hatch = (byte) (i >>> 1); - LEDdrawP(x, y, i, 0, ((GT_Container_MultiMachineEM) mContainer).eParamsInStatus[hatch]); - LEDdrawP(x, y, i++, 1, ((GT_Container_MultiMachineEM) mContainer).eParamsOutStatus[hatch]); - LEDdrawP(x, y, i, 0, ((GT_Container_MultiMachineEM) mContainer).eParamsInStatus[hatch + 10]); - LEDdrawP(x, y, i++, 1, ((GT_Container_MultiMachineEM) mContainer).eParamsOutStatus[hatch + 10]); + LEDdrawP(x, y, i, 0, mContainer.eParamsInStatus[hatch]); + LEDdrawP(x, y, i++, 1, mContainer.eParamsOutStatus[hatch]); + LEDdrawP(x, y, i, 0, mContainer.eParamsInStatus[hatch + 10]); + LEDdrawP(x, y, i++, 1, mContainer.eParamsOutStatus[hatch + 10]); } short rU = 207, Vs = 77; x += 162; - byte state = ((GT_Container_MultiMachineEM) mContainer).eCertainStatus; - switch (((GT_Container_MultiMachineEM) mContainer).eCertainMode) { + byte state = mContainer.eCertainStatus; + switch (mContainer.eCertainMode) { case 1://ooo oxo ooo drawTexturedModalRect(x + 6, y + 6, rU + (state == 0 ? 30 : 6), @@ -200,7 +202,7 @@ public class GT_GUIContainer_MultiMachineEM extends GT_GUIContainerMetaTile_Mach } } - private void LEDdrawP(int x, int y, int i, int j, byte status) { + private void LEDdrawP(int x, int y, int i, int j, LedStatus status) { int v = 192, su = 8, sv = 6, u = 11; switch (status) { case STATUS_WRONG: //fallthrough @@ -230,7 +232,30 @@ public class GT_GUIContainer_MultiMachineEM extends GT_GUIContainerMetaTile_Mach case STATUS_HIGH:// too high drawTexturedModalRect(x + su * i, y + sv * j, u + su * i, v + sv * (6 + j), su, sv); break; + case STATUS_NEUTRAL: + if(counter<3){ + GL11.glColor4f(.85f, .9f, .95f, 1.0F); + drawTexturedModalRect(x + su * i, y + sv * j, 212, 96, su+2, sv+2); + GL11.glColor4f(1f, 1f, 1f, 1f); + }else { + GL11.glColor4f(.8f, .9f, 1f, 1.0F); + drawTexturedModalRect(x + su * i, y + sv * j, 212, 96, su+2, sv+2); + GL11.glColor4f(1f, 1f, 1f, 1f); + } + break; + case STATUS_UNDEFINED: + if(counter<3) { + GL11.glColor4f(.5f, .1f, .15f, 1.0F); + drawTexturedModalRect(x + su * i, y + sv * j, 212, 96, su + 2, sv + 2); + GL11.glColor4f(1f, 1f, 1f, 1f); + }else { + GL11.glColor4f(0f, .1f, .2f, 1.0F); + drawTexturedModalRect(x + su * i, y + sv * j, 212, 96, su + 2, sv + 2); + GL11.glColor4f(1f, 1f, 1f, 1f); + } + break; case STATUS_UNUSED: + default: if (GregTech_API.sColoredGUI && this.mContainer.mTileEntity != null) { int tColor = this.mContainer.mTileEntity.getColorization() & 15; if (tColor < ItemDye.field_150922_c.length) { @@ -253,6 +278,11 @@ public class GT_GUIContainer_MultiMachineEM extends GT_GUIContainerMetaTile_Mach if(mContainer.mTileEntity!=null){ IMetaTileEntity mte=mContainer.mTileEntity.getMetaTileEntity(); if(mte instanceof GT_MetaTileEntity_MultiblockBase_EM){ + Parameters parametrization=((GT_MetaTileEntity_MultiblockBase_EM)mte).parametrization; + parametrization.eParamsInStatus=mContainer.eParamsInStatus; + parametrization.eParamsOutStatus=mContainer.eParamsOutStatus; + parametrization.iParamsIn=mContainer.eParamsIn; + parametrization.iParamsOut=mContainer.eParamsOut; int su = 8, sv = 6, u=11,v=96; if(x<u || y<v) return; v+=sv; @@ -260,15 +290,15 @@ public class GT_GUIContainer_MultiMachineEM extends GT_GUIContainerMetaTile_Mach for(int param=0;param<2;param++){ if(x<(u+=su)){ if(y<v){ - if(((GT_Container_MultiMachineEM) mContainer).eParamsInStatus[hatch + (10*param)]==STATUS_UNUSED){ - return; - } + //if(mContainer.eParamsInStatus[hatch + (10*param)]==STATUS_UNUSED){ + // return; + //} hoveringText(((GT_MetaTileEntity_MultiblockBase_EM) mte).getFullLedDescriptionIn(hatch,param), renderPosX, renderPosY, fontRendererObj); return; }else if(y>=v && y<v+sv){ - if(((GT_Container_MultiMachineEM) mContainer).eParamsOutStatus[hatch + (10*param)]==STATUS_UNUSED){ - return; - } + //if(mContainer.eParamsOutStatus[hatch + (10*param)]==STATUS_UNUSED){ + // return; + //} hoveringText(((GT_MetaTileEntity_MultiblockBase_EM) mte).getFullLedDescriptionOut(hatch,param), renderPosX, renderPosY, fontRendererObj); return; } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java index ebcc0ef622..b91d932ebd 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java @@ -35,11 +35,7 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fluids.FluidStack; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; import static com.github.technus.tectech.CommonValues.*; import static com.github.technus.tectech.Util.StructureCheckerExtreme; @@ -57,12 +53,6 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt public static final FluidStack[] nothingF = new FluidStack[0]; //endregion - //region Reflection based hatch adding... - //Example how to add custom method is in computer and research station - protected static final Map<String, Method> adderMethodMap = new HashMap<>(); - private static Method adderMethod; - //endregion - //region Client side variables (static - one per class) //Front icon holders - static so it is default one for my blocks @@ -95,25 +85,8 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt protected ArrayList<GT_MetaTileEntity_Hatch_InputData> eInputData = new ArrayList<>(); protected ArrayList<GT_MetaTileEntity_Hatch_OutputData> eOutputData = new ArrayList<>(); - //endregion - - //region PARAMETERS! GO AWAY and use proper get/set methods - // 0 and 10 are from first parametrizer - // 1 and 11 are from second etc... - - private final int[] iParamsIn = new int[20];//number I from parametrizers - private final int[] iParamsOut = new int[20];//number O to parametrizers - private final boolean[] bParamsAreFloats = new boolean[10]; - - final byte[] eParamsInStatus = new byte[20];//LED status for I - final byte[] eParamsOutStatus = new byte[20];//LED status for O - public static final byte STATUS_UNUSED =7, STATUS_NEUTRAL = 0, - STATUS_TOO_LOW = 1, STATUS_LOW = 2, - STATUS_WRONG = 3, STATUS_OK = 4, - STATUS_TOO_HIGH = 5, STATUS_HIGH = 6; - // 0,2,4,6 - ok - // 1,3,5 - nok - + //region parameters + public final Parameters parametrization; //endregion //region Control variables @@ -168,12 +141,16 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt protected GT_MetaTileEntity_MultiblockBase_EM(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); - parametersLoadDefault_EM(); + parametrization=new Parameters(this); + parametersInstantiation_EM(); + parametrization.setToDefaults(true,true); } protected GT_MetaTileEntity_MultiblockBase_EM(String aName) { super(aName); - parametersLoadDefault_EM(); + parametrization=new Parameters(this); + parametersInstantiation_EM(); + parametrization.setToDefaults(true,true); } //region SUPER STRUCT @@ -386,12 +363,12 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt String[][] structure,//0-9 casing, +- air no air, a-z ignore Block[] blockType,//use numbers 0-9 for casing types byte[] blockMeta,//use numbers 0-9 for casing types - String[] addingMethods, + HatchAdder[] addingMethods, short[] casingTextures, Block[] blockTypeFallback,//use numbers 0-9 for casing types byte[] blockMetaFallback,//use numbers 0-9 for casing types int horizontalOffset, int verticalOffset, int depthOffset) { - return StructureCheckerExtreme(structure, blockType, blockMeta, adderMethod, addingMethods, casingTextures, blockTypeFallback, blockMetaFallback, + return StructureCheckerExtreme(structure, blockType, blockMeta, addingMethods, casingTextures, blockTypeFallback, blockMetaFallback, horizontalOffset, verticalOffset, depthOffset, getBaseMetaTileEntity(), this, !mMachine); } @@ -446,7 +423,6 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt } } } - //endregion //region tooltip and scanner result @@ -465,6 +441,13 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt EnumChatFormatting.AQUA+paramID + EnumChatFormatting.YELLOW+ ":"+ EnumChatFormatting.AQUA+"I"); + list.add(EnumChatFormatting.WHITE+"Value: "+ + EnumChatFormatting.AQUA+parametrization.getIn(hatchNo,paramID)); + try{ + list.add(parametrization.groups[hatchNo].parameterIn[paramID].getBrief()); + }catch (NullPointerException|IndexOutOfBoundsException e){ + list.add("Unused"); + } return list; } @@ -482,6 +465,13 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt EnumChatFormatting.AQUA+paramID + EnumChatFormatting.YELLOW+ ":"+ EnumChatFormatting.AQUA+"O"); + list.add(EnumChatFormatting.WHITE+"Value: "+ + EnumChatFormatting.AQUA+parametrization.getOut(hatchNo,paramID)); + try{ + list.add(parametrization.groups[hatchNo].parameterOut[paramID].getBrief()); + }catch (NullPointerException|IndexOutOfBoundsException e){ + list.add("Unused"); + } return list; } @@ -521,17 +511,17 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt return new String[]{ "Progress:", EnumChatFormatting.GREEN + Integer.toString(mProgresstime / 20) + EnumChatFormatting.RESET + " s / " + - EnumChatFormatting.YELLOW + Integer.toString(mMaxProgresstime / 20) + EnumChatFormatting.RESET + " s", + EnumChatFormatting.YELLOW + mMaxProgresstime / 20 + EnumChatFormatting.RESET + " s", "Energy Hatches:", EnumChatFormatting.GREEN + Long.toString(storedEnergy) + EnumChatFormatting.RESET + " EU / " + - EnumChatFormatting.YELLOW + Long.toString(maxEnergy) + EnumChatFormatting.RESET + " EU", - (mEUt <= 0 ? "Probably uses: " : "Probably makes: ") + - EnumChatFormatting.RED + Integer.toString(Math.abs(mEUt)) + EnumChatFormatting.RESET + " EU/t at " + + EnumChatFormatting.YELLOW + maxEnergy + EnumChatFormatting.RESET + " EU", + (mEUt*eAmpereFlow <= 0 ? "Probably uses: " : "Probably makes: ") + + EnumChatFormatting.RED + Math.abs(mEUt) + EnumChatFormatting.RESET + " EU/t at " + EnumChatFormatting.RED + eAmpereFlow + EnumChatFormatting.RESET + " A", "Tier Rating: " + EnumChatFormatting.YELLOW + VN[getMaxEnergyInputTier_EM()] + EnumChatFormatting.RESET + " / " + EnumChatFormatting.GREEN + VN[getMinEnergyInputTier_EM()] + EnumChatFormatting.RESET + " Amp Rating: " + EnumChatFormatting.GREEN + eMaxAmpereFlow + EnumChatFormatting.RESET + " A", "Problems: " + EnumChatFormatting.RED + (getIdealStatus() - getRepairStatus()) + EnumChatFormatting.RESET + - " Efficiency: " + EnumChatFormatting.YELLOW + Float.toString(mEfficiency / 100.0F) + EnumChatFormatting.RESET + " %", + " Efficiency: " + EnumChatFormatting.YELLOW + mEfficiency / 100.0F + EnumChatFormatting.RESET + " %", "PowerPass: " + EnumChatFormatting.BLUE + ePowerPass + EnumChatFormatting.RESET + " SafeVoid: " + EnumChatFormatting.BLUE + eSafeVoid, "Computation: " + EnumChatFormatting.GREEN + eAvailableData + EnumChatFormatting.RESET + " / " + EnumChatFormatting.YELLOW + eRequiredData + EnumChatFormatting.RESET @@ -635,80 +625,6 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt //endregion - //region PARAMETERS AND STATUSES - actually use it to work with parameters in other overrides - - public final boolean setParameterPairIn_ClearOut(int hatchNo, boolean usesFloats, double value0, double value1) { - if (mMaxProgresstime > 0) { - return false; - } - bParamsAreFloats[hatchNo] = usesFloats; - if (usesFloats) { - iParamsIn[hatchNo] = Float.floatToIntBits((float) value0); - iParamsIn[hatchNo + 10] = Float.floatToIntBits((float) value1); - } else { - iParamsIn[hatchNo] = (int) value0; - iParamsIn[hatchNo + 10] = (int) value1; - } - iParamsOut[hatchNo] = 0; - iParamsOut[hatchNo + 10] = 0; - return true; - } - - public final boolean isParametrizerUsingFloat(int hatchNo){ - return bParamsAreFloats[hatchNo]; - } - - public final double getParameterIn(int hatchNo, int paramID){ - return bParamsAreFloats[hatchNo]?Float.intBitsToFloat(iParamsIn[hatchNo+10*paramID]):iParamsIn[hatchNo+10*paramID]; - } - - public final int getParameterInInt(int hatchNo, int paramID){ - if(bParamsAreFloats[hatchNo]) { - return (int) Float.intBitsToFloat(iParamsIn[hatchNo + 10 * paramID]); - } - return iParamsIn[hatchNo+10*paramID]; - } - - //public final int getParameterInIntRaw(int hatchNo, int paramID){ - // return iParamsIn[hatchNo+10*paramID]; - //} - - //public final float getParameterInFloatRaw(int hatchNo, int paramID){ - // return Float.intBitsToFloat(iParamsIn[hatchNo+10*paramID]); - //} - - public final void setParameterOut(int hatchNo, int paramID, double value){ - if(bParamsAreFloats[hatchNo]) { - iParamsOut[hatchNo+10*paramID]=Float.floatToIntBits((float) value); - }else{ - iParamsOut[hatchNo+10*paramID]=(int)value; - } - } - - //public final boolean setParameterOutInt(int hatchNo, int paramID, int value){ - // if(bParamsAreFloats[hatchNo]) return false; - // iParamsOut[hatchNo+10*paramID]=value; - // return true; - //} - - //public final boolean setParameterOutFloat(int hatchNo, int paramID, float value){ - // if(bParamsAreFloats[hatchNo]) { - // iParamsOut[hatchNo + 10 * paramID] = Float.floatToIntBits(value); - // return true; - // } - // return false; - //} - - public final void setStatusOfParameterIn(int hatchNo, int paramID, byte status){ - eParamsInStatus[hatchNo+10*paramID]=status; - } - - public final void setStatusOfParameterOut(int hatchNo, int paramID, byte status){ - eParamsOutStatus[hatchNo+10*paramID]=status; - } - - //endregion - //region Methods to maybe override (if u implement certain stuff) /** @@ -791,30 +707,43 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt } /** - * loads default parameters in CONSTRUCTOR! CALLED ONCE on creation, don't call it in your classes + * instantiate parameters in CONSTRUCTOR! CALLED ONCE on creation, don't call it in your classes */ - protected void parametersLoadDefault_EM(){ - //load default parameters with setParameterPairIn_ClearOut - } - - /** - * This is called automatically when there was parameters data update, copy it to your variables for safe storage - * although the base code only downloads the values from parametrizers when machines is NOT OPERATING - * - * good place to get Parameters - */ - protected void parametersInRead_EM(){} + protected void parametersInstantiation_EM(){} /** * It is automatically called OFTEN * update status of parameters in guis (and "machine state" if u wish) - * Called before check recipe, before outputting, and every second the machine is active + * Called before check recipe, before outputting, and every second the machine is complete * - * good place for set Parameters + * good place to update parameter statuses, default implementation handles it well * * @param machineBusy is machine doing SHIT */ - public void parametersOutAndStatusesWrite_EM(boolean machineBusy){} + protected void parametersStatusesWrite_EM(boolean machineBusy) {//todo unimplement? + if(!machineBusy){ + for (Parameters.Group.ParameterIn parameterIn : parametrization.parameterInArrayList) { + if (parameterIn != null) { + parameterIn.updateStatus(); + } + } + }else{ + for (Parameters.Group hatch:parametrization.groups){ + if(hatch!=null && hatch.updateWhileRunning){ + for (Parameters.Group.ParameterIn in:hatch.parameterIn) { + if(in!=null){ + in.updateStatus(); + } + } + } + } + } + for (Parameters.Group.ParameterOut parameterOut : parametrization.parameterOutArrayList) { + if (parameterOut != null) { + parameterOut.updateStatus(); + } + } + } /** * For extra types of hatches initiation, LOOK HOW IT IS CALLED! in onPostTick @@ -946,32 +875,26 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt } NBTTagCompound paramI = new NBTTagCompound(); - for (int i = 0; i < iParamsIn.length; i++) { - paramI.setInteger(Integer.toString(i), iParamsIn[i]); + for (int i = 0; i < parametrization.iParamsIn.length; i++) { + paramI.setDouble(Integer.toString(i), parametrization.iParamsIn[i]); } - aNBT.setTag("eParamsIn", paramI); + aNBT.setTag("eParamsInD", paramI); NBTTagCompound paramO = new NBTTagCompound(); - for (int i = 0; i < iParamsOut.length; i++) { - paramO.setInteger(Integer.toString(i), iParamsOut[i]); - } - aNBT.setTag("eParamsOut", paramO); - - NBTTagCompound paramB = new NBTTagCompound(); - for (int i = 0; i < bParamsAreFloats.length; i++) { - paramB.setBoolean(Integer.toString(i), bParamsAreFloats[i]); + for (int i = 0; i < parametrization.iParamsOut.length; i++) { + paramO.setDouble(Integer.toString(i), parametrization.iParamsOut[i]); } - aNBT.setTag("eParamsB", paramB); + aNBT.setTag("eParamsOutD", paramO); NBTTagCompound paramIs = new NBTTagCompound(); - for (int i = 0; i < eParamsInStatus.length; i++) { - paramIs.setByte(Integer.toString(i), eParamsInStatus[i]); + for (int i = 0; i < parametrization.eParamsInStatus.length; i++) { + paramIs.setByte(Integer.toString(i), parametrization.eParamsInStatus[i].getOrdinalByte()); } aNBT.setTag("eParamsInS", paramIs); NBTTagCompound paramOs = new NBTTagCompound(); - for (int i = 0; i < eParamsOutStatus.length; i++) { - paramOs.setByte(Integer.toString(i), eParamsOutStatus[i]); + for (int i = 0; i < parametrization.eParamsOutStatus.length; i++) { + paramOs.setByte(Integer.toString(i), parametrization.eParamsOutStatus[i].getOrdinalByte()); } aNBT.setTag("eParamsOutS", paramOs); } @@ -1038,29 +961,38 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt outputEM = null; } - NBTTagCompound paramI = aNBT.getCompoundTag("eParamsIn"); - for (int i = 0; i < iParamsIn.length; i++) { - iParamsIn[i] = paramI.getInteger(Integer.toString(i)); - } - - NBTTagCompound paramO = aNBT.getCompoundTag("eParamsOut"); - for (int i = 0; i < iParamsOut.length; i++) { - iParamsOut[i] = paramO.getInteger(Integer.toString(i)); - } - - NBTTagCompound paramB = aNBT.getCompoundTag("eParamsB"); - for (int i = 0; i < bParamsAreFloats.length; i++) { - bParamsAreFloats[i] = paramB.getBoolean(Integer.toString(i)); + if(aNBT.hasKey("eParamsIn") && aNBT.hasKey("eParamsOut") && aNBT.hasKey("eParamsB")){ + NBTTagCompound paramI = aNBT.getCompoundTag("eParamsIn"); + NBTTagCompound paramO = aNBT.getCompoundTag("eParamsOut"); + NBTTagCompound paramB = aNBT.getCompoundTag("eParamsB"); + for (int i = 0; i < 10; i++) { + if(paramB.getBoolean(Integer.toString(i))){ + parametrization.iParamsIn[i] = Float.intBitsToFloat(paramI.getInteger(Integer.toString(i))); + parametrization.iParamsOut[i] =Float.intBitsToFloat(paramO.getInteger(Integer.toString(i))); + }else { + parametrization.iParamsIn[i] = paramI.getInteger(Integer.toString(i)); + parametrization.iParamsOut[i] = paramO.getInteger(Integer.toString(i)); + } + } + }else{ + NBTTagCompound paramI = aNBT.getCompoundTag("eParamsInD"); + for (int i = 0; i < parametrization.iParamsIn.length; i++) { + parametrization.iParamsIn[i] = paramI.getDouble(Integer.toString(i)); + } + NBTTagCompound paramO = aNBT.getCompoundTag("eParamsOutD"); + for (int i = 0; i < parametrization.iParamsOut.length; i++) { + parametrization.iParamsOut[i] = paramO.getDouble(Integer.toString(i)); + } } NBTTagCompound paramIs = aNBT.getCompoundTag("eParamsInS"); - for (int i = 0; i < eParamsInStatus.length; i++) { - eParamsInStatus[i] = paramIs.getByte(Integer.toString(i)); + for (int i = 0; i < parametrization.eParamsInStatus.length; i++) { + parametrization.eParamsInStatus[i] = LedStatus.getStatus(paramIs.getByte(Integer.toString(i))); } NBTTagCompound paramOs = aNBT.getCompoundTag("eParamsOutS"); - for (int i = 0; i < eParamsOutStatus.length; i++) { - eParamsOutStatus[i] = paramOs.getByte(Integer.toString(i)); + for (int i = 0; i < parametrization.eParamsOutStatus.length; i++) { + parametrization.eParamsOutStatus[i] = LedStatus.getStatus(paramOs.getByte(Integer.toString(i))); } } @@ -1239,46 +1171,43 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt } /** - * callback for updating parameters, change this if u really need dynamic (inside recipe time) parameter updates + * callback for updating parameters and new hatches */ protected void hatchesStatusUpdate_EM() { + if(getBaseMetaTileEntity().isClientSide()){ + return; + } boolean busy=mMaxProgresstime>0; if (busy) {//write from buffer to hatches only for (GT_MetaTileEntity_Hatch_Param hatch : eParamHatches) { if (!GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(hatch) || hatch.param < 0) { continue; } - int paramID = hatch.param; - if(bParamsAreFloats[hatch.param] == hatch.isUsingFloats()){ - hatch.input0i = iParamsOut[paramID]; - hatch.input1i = iParamsOut[paramID + 10]; - }else if(hatch.isUsingFloats()){ - hatch.input0i = Float.floatToIntBits((float)iParamsOut[paramID]); - hatch.input1i = Float.floatToIntBits((float)iParamsOut[paramID + 10]); - }else { - hatch.input0i = (int)Float.intBitsToFloat(iParamsOut[paramID]); - hatch.input1i = (int)Float.intBitsToFloat(iParamsOut[paramID + 10]); + int hatchId = hatch.param; + if(parametrization.groups[hatchId]!=null && parametrization.groups[hatchId].updateWhileRunning){ + parametrization.iParamsIn[hatchId] = hatch.value0D; + parametrization.iParamsIn[hatchId + 10] = hatch.value1D; } + hatch.input0D = parametrization.iParamsOut[hatchId]; + hatch.input1D = parametrization.iParamsOut[hatchId + 10]; } - parametersInRead_EM(); } else {//if has nothing to do update all for (GT_MetaTileEntity_Hatch_Param hatch : eParamHatches) { if (!GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(hatch) || hatch.param < 0) { continue; } - int paramID = hatch.param; - bParamsAreFloats[hatch.param] = hatch.isUsingFloats(); - iParamsIn[paramID] = hatch.value0i; - iParamsIn[paramID + 10] = hatch.value1i; - hatch.input0i = iParamsOut[paramID]; - hatch.input1i = iParamsOut[paramID + 10]; + int hatchId = hatch.param; + parametrization.iParamsIn[hatchId] = hatch.value0D; + parametrization.iParamsIn[hatchId + 10] = hatch.value1D; + hatch.input0D = parametrization.iParamsOut[hatchId]; + hatch.input1D = parametrization.iParamsOut[hatchId + 10]; } } for (GT_MetaTileEntity_Hatch_Uncertainty uncertainty : eUncertainHatches) { eCertainStatus = uncertainty.update(eCertainMode); } eAvailableData = getAvailableData_EM(); - parametersOutAndStatusesWrite_EM(busy); + parametersStatusesWrite_EM(busy); } @Deprecated @@ -1482,9 +1411,6 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt for (GT_MetaTileEntity_Hatch_Param hatch : eParamHatches){ if (GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(hatch)) { hatch.getBaseMetaTileEntity().setActive(true); - if(hatch.param>=0) { - bParamsAreFloats[hatch.param] = hatch.isUsingFloats(); - } } } } else { @@ -2668,48 +2594,4 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt } return false; } - - public static void run() { - try { - adderMethodMap.put("addToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addClassicToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addClassicToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addElementalToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addElementalToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addMufflerToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addMufflerToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addClassicMufflerToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addClassicMufflerToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addElementalMufflerToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addElementalMufflerToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addInputToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addInputToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addOutputToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addOutputToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addEnergyInputToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addEnergyInputToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addDynamoToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addDynamoToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addEnergyIOToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addEnergyIOToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addElementalInputToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addElementalInputToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addElementalOutputToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addElementalOutputToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addClassicInputToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addClassicInputToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addClassicOutputToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addClassicOutputToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addParametrizerToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addParametrizerToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addUncertainToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addUncertainToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addMaintenanceToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addMaintenanceToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addClassicMaintenanceToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addClassicMaintenanceToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addDataConnectorToMachineList", GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addDataConnectorToMachineList", IGregTechTileEntity.class, int.class)); - adderMethod = GT_MetaTileEntity_MultiblockBase_EM.class.getMethod("addThing", String.class, IGregTechTileEntity.class, int.class); - } catch (NoSuchMethodException e) { - if (DEBUG_MODE) { - e.printStackTrace(); - } - } - } - - //CALLBACK from hatches adders - public boolean addThing(String methodName, IGregTechTileEntity igt, int casing) { - try { - return (boolean) adderMethodMap.get(methodName).invoke(this, igt, casing); - } catch (InvocationTargetException | IllegalAccessException e) { - if (DEBUG_MODE) { - e.printStackTrace(); - } - } - return false; - } - - //endregion } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/HatchAdder.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/HatchAdder.java new file mode 100644 index 0000000000..177f8b2cfb --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/HatchAdder.java @@ -0,0 +1,8 @@ +package com.github.technus.tectech.thing.metaTileEntity.multi.base; + + +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; + +public interface HatchAdder{ + Boolean apply(IGregTechTileEntity iGregTechTileEntity, Short aShort); +} diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/LedStatus.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/LedStatus.java new file mode 100644 index 0000000000..e32df43ae4 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/LedStatus.java @@ -0,0 +1,89 @@ +package com.github.technus.tectech.thing.metaTileEntity.multi.base; + +public enum LedStatus { + STATUS_UNUSED("Unused",true), + STATUS_TOO_LOW("Too Low",false), + STATUS_LOW("Low",true), + STATUS_WRONG("Wrong",false), + STATUS_OK("Valid",true), + STATUS_TOO_HIGH("Too High",false), + STATUS_HIGH("High",true), + STATUS_UNDEFINED("Unknown",false), + STATUS_NEUTRAL("Neutral",true); + + public final String name; + public final boolean isOk; + + LedStatus(String name,boolean ok){ + this.name=name; + this.isOk=ok; + } + + public byte getOrdinalByte(){ + return (byte)ordinal(); + } + + public static LedStatus getStatus(byte value){ + try{ + return LedStatus.values()[value]; + }catch (Exception e){ + return STATUS_UNDEFINED; + } + } + + public static LedStatus[] makeArray(int count,LedStatus defaultValue){ + LedStatus[] statuses=new LedStatus[count]; + for (int i = 0; i < count; i++) { + statuses[i]=defaultValue; + } + return statuses; + } + + public static LedStatus fromLimitsInclusiveOuterBoundary(double value, double min,double low, double high, double max, double... excludedNumbers){ + if(value<min) return STATUS_TOO_LOW; + if(value>max) return STATUS_TOO_HIGH; + + if(value<low) return STATUS_LOW; + if(value>high) return STATUS_HIGH; + for (double val : excludedNumbers) { + if(val==value) return STATUS_WRONG; + } + if(Double.isNaN(value)) return STATUS_WRONG; + return STATUS_UNDEFINED; + } + + public static LedStatus fromLimitsExclusiveOuterBoundary(double value, double min,double low, double high,double max, double... excludedNumbers){ + if(value<=min) return STATUS_TOO_LOW; + if(value>=max) return STATUS_TOO_HIGH; + + if(value<low) return STATUS_LOW; + if(value>high) return STATUS_HIGH; + for (double val : excludedNumbers) { + if(val==value) return STATUS_WRONG; + } + if(Double.isNaN(value)) return STATUS_WRONG; + return STATUS_OK; + } + + public static LedStatus fromLimitsInclusiveBoundary(double value, double min, double max, double... excludedNumbers){ + if(value<min) return STATUS_TOO_LOW; + if(value>max) return STATUS_TOO_HIGH; + + for (double val : excludedNumbers) { + if(val==value) return STATUS_WRONG; + } + if(Double.isNaN(value)) return STATUS_WRONG; + return STATUS_OK; + } + + public static LedStatus fromLimitsExclusiveBoundary(double value, double min, double max, double... excludedNumbers){ + if(value<=min) return STATUS_TOO_LOW; + if(value>=max) return STATUS_TOO_HIGH; + + for (double val : excludedNumbers) { + if(val==value) return STATUS_WRONG; + } + if(Double.isNaN(value)) return STATUS_WRONG; + return STATUS_OK; + } +} diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/NameFunction.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/NameFunction.java new file mode 100644 index 0000000000..a296600abf --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/NameFunction.java @@ -0,0 +1,5 @@ +package com.github.technus.tectech.thing.metaTileEntity.multi.base; + +public interface NameFunction<T extends GT_MetaTileEntity_MultiblockBase_EM>{ + String apply(T t, Parameters.IParameter iParameter); +} diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/Parameters.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/Parameters.java new file mode 100644 index 0000000000..4aba953df6 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/Parameters.java @@ -0,0 +1,326 @@ +package com.github.technus.tectech.thing.metaTileEntity.multi.base; + +import java.util.ArrayList; + +/** + * Instantiate parameters as field in parametersInstantiation_EM(); + */ +public class Parameters { + private static final StatusFunction LED_STATUS_FUNCTION_DEFAULT = (b,p)->LedStatus.STATUS_UNDEFINED; + private static final NameFunction NAME_FUNCTION_DEFAULT= (b,p)->"Undefined"; + + final Group[] groups = new Group[10]; + + double[] iParamsIn = new double[20];//number I from parametrizers + double[] iParamsOut = new double[20];//number O to parametrizers + final ArrayList<Group.ParameterIn> parameterInArrayList =new ArrayList<>(); + final ArrayList<Group.ParameterOut> parameterOutArrayList =new ArrayList<>(); + + //package private for use in gui + LedStatus[] eParamsInStatus = LedStatus.makeArray(20,LedStatus.STATUS_UNUSED);//LED status for I + LedStatus[] eParamsOutStatus = LedStatus.makeArray(20,LedStatus.STATUS_UNUSED);//LED status for O + + double getIn(int hatchNo,int parameterId){ + return iParamsIn[hatchNo+10*parameterId]; + } + + double getOut(int hatchNo,int parameterId){ + return iParamsOut[hatchNo+10*parameterId]; + } + + private final GT_MetaTileEntity_MultiblockBase_EM parent; + + Parameters(GT_MetaTileEntity_MultiblockBase_EM parent){ + this.parent=parent; + } + + public boolean trySetParameters(int hatch,double parameter0,double parameter1){ + Group p=groups[hatch]; + if(parent.mMaxProgresstime<=0 || (p!=null && p.updateWhileRunning)){ + iParamsIn[hatch]=parameter0; + iParamsIn[hatch+10]=parameter1; + return true; + } + return false; + } + + public void setToDefaults(int hatch,boolean defaultIn, boolean defaultOut) { + Group p= groups[hatch]; + if (p == null) { + if (defaultIn) { + iParamsIn[hatch] = 0; + iParamsIn[hatch + 10] = 0; + } + if (defaultOut) { + iParamsOut[hatch] = 0; + iParamsOut[hatch + 10] = 0; + } + } else { + p.setToDefaults(defaultIn,defaultOut); + } + } + + public void setToDefaults(boolean defaultIn, boolean defaultOut){ + for (int hatch=0;hatch<10;hatch++) { + setToDefaults(hatch,defaultIn,defaultOut); + } + } + + public void ClearDefinitions(){ + parameterInArrayList.clear(); + parameterOutArrayList.clear(); + for(int i = 0; i< groups.length; i++){ + groups[i]=null; + } + } + + public void removeGroup(Group group){ + if(group==groups[group.hatchNo]){ + removeGroup(group.hatchNo); + }else{ + throw new IllegalArgumentException("Group does not exists in this parametrization!"); + } + } + + public void removeGroup(int hatchNo){ + Group hatch=groups[hatchNo]; + if(hatch!=null){ + for (Group.ParameterOut p:hatch.parameterOut) { + parameterOutArrayList.remove(p); + } + for (Group.ParameterIn p:hatch.parameterIn) { + parameterInArrayList.remove(p); + } + groups[hatchNo]=null; + } + } + + public Group getGroup(int hatchNo, boolean updateWhileRunning){ + return groups[hatchNo]!=null?groups[hatchNo]:new Group( hatchNo, updateWhileRunning); + } + + public Group getGroup(int hatchNo){ + return groups[hatchNo]!=null?groups[hatchNo]:new Group( hatchNo, false); + } + + public interface IParameter{ + double get(); + double getDefault(); + void updateStatus(); + LedStatus getStatus(boolean update); + int id(); + int hatchId(); + int parameterId(); + String getBrief(); + } + + /** + * most likely used locally in parametersInstantiation_EM() + */ + public class Group { + private final int hatchNo; + final ParameterIn[] parameterIn =new ParameterIn[2]; + final ParameterOut[] parameterOut =new ParameterOut[2]; + public boolean updateWhileRunning; + + private Group(int hatchNo, boolean updateWhileRunning){ + if(hatchNo<0 || hatchNo>=10){ + throw new IllegalArgumentException("Hatch id must be in 0 to 9 range"); + } + this.hatchNo=hatchNo; + this.updateWhileRunning=updateWhileRunning; + groups[hatchNo]=this; + } + + public ParameterIn makeInParameter(int paramID, double defaultValue, NameFunction name, StatusFunction status){ + return new ParameterIn(paramID, defaultValue,name, status); + } + + public ParameterOut makeOutParameter(int paramID, double defaultValue, NameFunction name, StatusFunction status){ + return new ParameterOut(paramID, defaultValue, name, status); + } + + public void setToDefaults(boolean defaultIn, boolean defaultOut) { + if(defaultIn){ + if (this.parameterIn[0] != null) { + this.parameterIn[0].setDefault(); + } else { + iParamsIn[hatchNo] = 0; + } + if (this.parameterIn[1] != null) { + this.parameterIn[1].setDefault(); + } else { + iParamsIn[hatchNo + 10] = 0; + } + } + if(defaultOut){ + if (this.parameterOut[0] != null) { + this.parameterOut[0].setDefault(); + } else { + iParamsIn[hatchNo] = 0; + } + if (this.parameterOut[1] != null) { + this.parameterOut[1].setDefault(); + } else { + iParamsIn[hatchNo + 10] = 0; + } + } + } + + /** + * Make a field out of this... + */ + public class ParameterOut implements IParameter { + public final int id; + public final double defaultValue; + StatusFunction status; + NameFunction name; + + private ParameterOut(int paramID, double defaultValue, NameFunction name, StatusFunction status){ + this.name= name==null?NAME_FUNCTION_DEFAULT:name; + if(paramID<0 || paramID>2){ + throw new IllegalArgumentException("Parameter id must be in 0 to 1 range"); + } + if(parameterOut[paramID]!=null){ + throw new IllegalArgumentException("Parameter id already occupied"); + } + this.id=hatchNo+10*paramID; + this.defaultValue=defaultValue; + this.status = status==null?LED_STATUS_FUNCTION_DEFAULT:status; + parameterOutArrayList.add(this); + parameterOut[paramID]=this; + } + + void setDefault() { + set(defaultValue); + } + + @Override + public double get(){ + return iParamsOut[id]; + } + + @Override + public double getDefault() { + return defaultValue; + } + + public void set(double value){ + iParamsOut[id]=value; + } + + @SuppressWarnings("unchecked") + @Override + public void updateStatus(){ + eParamsOutStatus[id]=status.apply(parent,this); + } + + @Override + public LedStatus getStatus(boolean update){ + if(update){ + updateStatus(); + } + return eParamsOutStatus[id]; + } + + @Override + public String getBrief(){ + return name.apply(parent,this); + } + + @Override + public int id() { + return id; + } + + @Override + public int hatchId() { + return id%10; + } + + @Override + public int parameterId() { + return id/10; + } + } + + /** + * Make a field out of this... + */ + public class ParameterIn implements IParameter { + public final int id; + public final double defaultValue; + StatusFunction status; + NameFunction name; + + private ParameterIn(int paramID, double defaultValue, NameFunction name, StatusFunction status){ + this.name= name==null?NAME_FUNCTION_DEFAULT:name; + this.id=hatchNo+10*paramID; + if(paramID<0 || paramID>2){ + throw new IllegalArgumentException("Parameter id must be in 0 to 1 range"); + } + if(parameterOut[paramID]!=null){ + throw new IllegalArgumentException("Parameter id already occupied"); + } + this.defaultValue=defaultValue; + this.status = status==null?LED_STATUS_FUNCTION_DEFAULT:status; + parameterInArrayList.add(this); + parameterIn[paramID]=this; + } + + void setDefault() { + set(defaultValue); + } + + @Override + public double get(){ + return iParamsIn[id]; + } + + void set(double value){ + iParamsIn[id]=value; + } + + @Override + public double getDefault() { + return defaultValue; + } + + @SuppressWarnings("unchecked") + @Override + public void updateStatus(){ + eParamsInStatus[id]=status.apply(parent,this); + } + + @Override + public LedStatus getStatus(boolean update){ + if(update){ + updateStatus(); + } + return eParamsInStatus[id]; + } + + @Override + public String getBrief(){ + return name.apply(parent,this); + } + + + @Override + public int id() { + return id; + } + + @Override + public int hatchId() { + return id%10; + } + + @Override + public int parameterId() { + return id/10; + } + } + } +} + diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/StatusFunction.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/StatusFunction.java new file mode 100644 index 0000000000..e285c75344 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/StatusFunction.java @@ -0,0 +1,5 @@ +package com.github.technus.tectech.thing.metaTileEntity.multi.base; + +public interface StatusFunction<T extends GT_MetaTileEntity_MultiblockBase_EM>{ + LedStatus apply(T t, Parameters.IParameter iParameter); +} diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_Centrifuge.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_Centrifuge.java index 4b7d41494b..5f072b3196 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_Centrifuge.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_Centrifuge.java @@ -4,24 +4,52 @@ import com.github.technus.tectech.TecTech; import com.github.technus.tectech.mechanics.elementalMatter.core.cElementalInstanceStackMap; import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.cElementalInstanceStack; import com.github.technus.tectech.mechanics.elementalMatter.definitions.complex.atom.dAtomDefinition; -import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; import com.github.technus.tectech.thing.metaTileEntity.multi.base.MultiblockControl; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.NameFunction; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.Parameters; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.StatusFunction; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Comparator; import static com.github.technus.tectech.CommonValues.V; import static com.github.technus.tectech.loader.TecTechConfig.DEBUG_MODE; +import static com.github.technus.tectech.thing.metaTileEntity.multi.base.LedStatus.*; /** * Created by danie_000 on 24.12.2017. */ -public class Behaviour_Centrifuge extends GT_MetaTileEntity_EM_machine.Behaviour { - private final float radius, maxRPM, maxRCF, maxForce, maxCapacity; +public class Behaviour_Centrifuge implements GT_MetaTileEntity_EM_machine.Behaviour { private final byte tier; - private final static String[] DESCRIPTION_I =new String[]{"RPM Input","Fraction Count Input"}; - private final static String[] DESCRIPTION_O =new String[]{"RPM Setting","RCF Setting","Radius [mm]","Max RPM","Max Force [eV/c^2 * m/s]","Max Capacity [eV/c^2]","Max Power Usage[EU/t]","Max Recipe Rime [tick]"}; + private float radius, maxRPM, maxRCF, maxForce, maxCapacity; + private Parameters.Group.ParameterIn settingRPM, settingFraction; + private final static NameFunction<GT_MetaTileEntity_EM_machine> rpmName= (gt_metaTileEntity_em_machine, iParameter) -> "RPM Setting"; + private final StatusFunction<GT_MetaTileEntity_EM_machine> rpmStatus= (gt_metaTileEntity_em_machine, iParameter) -> { + double v=iParameter.get(); + if(Double.isNaN(v)){ + return STATUS_WRONG; + } + if (v <=0) { + return STATUS_TOO_LOW; + }else if (v>maxRPM){ + return STATUS_TOO_HIGH; + } + return STATUS_OK; + }; + private final static NameFunction<GT_MetaTileEntity_EM_machine> fractionName= (gt_metaTileEntity_em_machine, iParameter) -> "Fraction Count"; + private static final StatusFunction<GT_MetaTileEntity_EM_machine> fractionStatus= (gt_metaTileEntity_em_machine, iParameter) -> { + double v=iParameter.get(); + if(Double.isNaN(v)){ + return STATUS_WRONG; + } + v=(int)v; + if (v <= 1) { + return STATUS_TOO_LOW; + }else if (v>6){ + return STATUS_TOO_HIGH; + } + return STATUS_OK; + }; + //private final static String[] DESCRIPTION_O =new String[]{"RPM Setting","RCF Setting","Radius [mm]","Max RPM","Max Force [eV/c^2 * m/s]","Max Capacity [eV/c^2]","Max Power Usage[EU/t]","Max Recipe Rime [tick]"}; private static final double[/*tier+5*/][/*outputHatches+2*/] MIXING_FACTORS =new double[][]{ {.45,.85,.95,1,1,}, @@ -45,91 +73,40 @@ public class Behaviour_Centrifuge extends GT_MetaTileEntity_EM_machine.Behaviour maxCapacity = maxSafeMass * 4f * radius;// eV/c^2 } - @Override - protected void getFullLedDescriptionIn(ArrayList<String> baseDescr, int hatchNo, int paramID) { - if(hatchNo==0) { - baseDescr.add(DESCRIPTION_I[(hatchNo << 1) + paramID]); - } + private double getRCF(double RPM) { + return RPM * RPM * radius * 0.001118; } - @Override - protected void getFullLedDescriptionOut(ArrayList<String> baseDescr, int hatchNo, int paramID) { - if(hatchNo<=2) { - baseDescr.add(DESCRIPTION_O[(hatchNo<<1)+paramID]); + private void addRandomly(cElementalInstanceStack me, cElementalInstanceStackMap[] toThis, int fractionCount) { + long amountPerFraction = me.amount / fractionCount; + cElementalInstanceStack[] stacks = new cElementalInstanceStack[fractionCount]; + for (int i = 0; i < fractionCount; i++) { + stacks[i] = me.clone(); + stacks[i].amount = amountPerFraction; + toThis[i].putReplace(stacks[i]); + } + int remainingAmount = (int) (me.amount % fractionCount); + while (remainingAmount > 0) { + int amountToAdd = TecTech.RANDOM.nextInt(remainingAmount) + 1; + stacks[TecTech.RANDOM.nextInt(fractionCount)].amount += amountToAdd; + remainingAmount -= amountToAdd; } } @Override - public boolean setAndCheckParametersOutAndStatuses(GT_MetaTileEntity_EM_machine te, double[] parametersToCheckAndFix) { - boolean check=true; - - te.setParameterOut(1, 0, radius * 1000);//in mm - te.setParameterOut(1, 1, maxRPM); - te.setParameterOut(2, 0, maxForce * 9.80665);// (eV/c^2 * m/s) - te.setParameterOut(2, 1, maxCapacity);// eV/c^2 - - for(int i=4;i<=9;i++) { - te.setStatusOfParameterOut(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_UNUSED); - te.setStatusOfParameterOut(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_UNUSED); - } - for(int i=1;i<=3;i++) { - te.setStatusOfParameterIn(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_UNUSED); - te.setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_UNUSED); - } - - double RPM = parametersToCheckAndFix[0]; - if (RPM > maxRPM) { - te.setStatusOfParameterIn(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - te.setParameterOut(0, 0, maxRPM);//rpm - te.setParameterOut(0, 1, maxRCF);//rcf - check=false; - } else if (RPM > maxRPM / 3f * 2f) { - te.setStatusOfParameterIn(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_HIGH); - } else if (RPM > maxRPM / 3f) { - te.setStatusOfParameterIn(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - } else if (RPM > 0) { - te.setStatusOfParameterIn(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_LOW); - } else if (RPM <= 0) { - te.setStatusOfParameterIn(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - te.setParameterOut(0, 0, 0);//rpm - te.setParameterOut(0, 1, 0);//rcf - check=false; - } else { - te.setStatusOfParameterIn(0, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - te.setParameterOut(0, 0, 0);//rpm - te.setParameterOut(0, 1, 0);//rcf - check=false; - } - - if(check) { - te.setParameterOut(0, 0, RPM); - te.setParameterOut(0, 1, getRCF(RPM)); - } - - double fractionCount = parametersToCheckAndFix[1]; - if (fractionCount > 6) { - parametersToCheckAndFix[1] = 6; - te.setStatusOfParameterIn(0, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - check=false; - } else if (fractionCount >= 2) { - te.setStatusOfParameterIn(0, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - } else if (fractionCount < 2) { - parametersToCheckAndFix[1] = 2; - te.setStatusOfParameterIn(0, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - check=false; - } else { - te.setStatusOfParameterIn(0, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - check=false; - } - - te.setParameterOut(3,0,(int) (Math.pow(parametersToCheckAndFix[0] / maxRPM, 3f) * V[tier]));//max eut - te.setParameterOut(3,1,(int) (20 * (fractionCount - 1)));//max time + public void parametersInstantiation(GT_MetaTileEntity_EM_machine te, Parameters parameters) { + Parameters.Group hatch1=parameters.getGroup(7); + settingRPM=hatch1.makeInParameter(0,0,rpmName,rpmStatus); + settingFraction=hatch1.makeInParameter(1,2,fractionName,fractionStatus); + } - return check; + @Override + public boolean checkParametersInAndSetStatuses(GT_MetaTileEntity_EM_machine te, Parameters parameters) { + return settingRPM.getStatus(true).isOk && settingFraction.getStatus(true).isOk; } @Override - public MultiblockControl<cElementalInstanceStackMap[]> process(cElementalInstanceStackMap[] inputs, double[] checkedAndFixedParameters) { + public MultiblockControl<cElementalInstanceStackMap[]> process(cElementalInstanceStackMap[] inputs, GT_MetaTileEntity_EM_machine te, Parameters parameters) { cElementalInstanceStackMap input = inputs[0]; if (input == null || input.isEmpty()) return null;//nothing in only valid input @@ -154,11 +131,11 @@ public class Behaviour_Centrifuge extends GT_MetaTileEntity_EM_machine.Behaviour inputMass = Math.abs(input.getMass()); - double RCF = getRCF(checkedAndFixedParameters[0]); + double RCF = getRCF(settingRPM.get()); if (inputMass * RCF > maxForce) return new MultiblockControl<>(excessMass);//AND THEN IT EXPLODES // how many output hatches to use - int fractionCount = (int) checkedAndFixedParameters[1]; + int fractionCount = (int) settingFraction.get(); cElementalInstanceStackMap[] outputs = new cElementalInstanceStackMap[fractionCount]; for (int i = 0; i < fractionCount; i++) { outputs[i] = new cElementalInstanceStackMap(); @@ -170,7 +147,7 @@ public class Behaviour_Centrifuge extends GT_MetaTileEntity_EM_machine.Behaviour TecTech.LOGGER.info("mixingFactor "+mixingFactor); } - int mEut = (int) (Math.pow(checkedAndFixedParameters[0] / maxRPM, 3f) * V[tier]); + int mEut = (int) (Math.pow(settingRPM.get() / maxRPM, 3f) * V[tier]); mEut = Math.max(mEut, 512); mEut = -mEut; int mTicks = (int) (20 * (inputMass / maxCapacity) * (fractionCount - 1)); @@ -180,15 +157,12 @@ public class Behaviour_Centrifuge extends GT_MetaTileEntity_EM_machine.Behaviour //take all from hatch handler and put into new map - this takes from hatch to inner data storage stacks = input.takeAllToNewMap().values();//cleanup stacks if (stacks.length > 1) { - Arrays.sort(stacks, new Comparator<cElementalInstanceStack>() { - @Override - public int compare(cElementalInstanceStack o1, cElementalInstanceStack o2) { - float m1 = o1.definition.getMass(); - float m2 = o2.definition.getMass(); - if (m1 < m2) return -1; - if (m1 > m2) return 1; - return o1.compareTo(o2); - } + Arrays.sort(stacks, (o1, o2) -> { + float m1 = o1.definition.getMass(); + float m2 = o2.definition.getMass(); + if (m1 < m2) return -1; + if (m1 > m2) return 1; + return o1.compareTo(o2); }); double absMassPerOutput = 0;//"volume" @@ -257,24 +231,4 @@ public class Behaviour_Centrifuge extends GT_MetaTileEntity_EM_machine.Behaviour } return new MultiblockControl<>(outputs, mEut, 1, 0, 10000, mTicks, 0, excessMass); } - - private double getRCF(double RPM) { - return RPM * RPM * radius * 0.001118; - } - - private void addRandomly(cElementalInstanceStack me, cElementalInstanceStackMap[] toThis, int fractionCount) { - long amountPerFraction = me.amount / fractionCount; - cElementalInstanceStack[] stacks = new cElementalInstanceStack[fractionCount]; - for (int i = 0; i < fractionCount; i++) { - stacks[i] = me.clone(); - stacks[i].amount = amountPerFraction; - toThis[i].putReplace(stacks[i]); - } - int remainingAmount = (int) (me.amount % fractionCount); - while (remainingAmount > 0) { - int amountToAdd = TecTech.RANDOM.nextInt(remainingAmount) + 1; - stacks[TecTech.RANDOM.nextInt(fractionCount)].amount += amountToAdd; - remainingAmount -= amountToAdd; - } - } } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_Electrolyzer.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_Electrolyzer.java index 9fe54588bc..42b41a5ae3 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_Electrolyzer.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_Electrolyzer.java @@ -2,23 +2,29 @@ package com.github.technus.tectech.thing.metaTileEntity.multi.em_machine; import com.github.technus.tectech.mechanics.elementalMatter.core.cElementalInstanceStackMap; import com.github.technus.tectech.thing.metaTileEntity.multi.base.MultiblockControl; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.Parameters; /** * Created by danie_000 on 24.12.2017. */ -public class Behaviour_Electrolyzer extends GT_MetaTileEntity_EM_machine.Behaviour { +public class Behaviour_Electrolyzer implements GT_MetaTileEntity_EM_machine.Behaviour { final int tier; public Behaviour_Electrolyzer(int tier){ this.tier=tier; } @Override - public boolean setAndCheckParametersOutAndStatuses(GT_MetaTileEntity_EM_machine te, double[] parametersToCheckAndFix) { + public void parametersInstantiation(GT_MetaTileEntity_EM_machine te, Parameters parameters) { + + } + + @Override + public boolean checkParametersInAndSetStatuses(GT_MetaTileEntity_EM_machine te, Parameters parameters) { return false; } @Override - public MultiblockControl<cElementalInstanceStackMap[]> process(cElementalInstanceStackMap[] inputs, double[] checkedAndFixedParameters) { + public MultiblockControl<cElementalInstanceStackMap[]> process(cElementalInstanceStackMap[] inputs, GT_MetaTileEntity_EM_machine te, Parameters parameters) { return null; } } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_ElectromagneticSeparator.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_ElectromagneticSeparator.java index 8c912dd38d..d2b08f0960 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_ElectromagneticSeparator.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_ElectromagneticSeparator.java @@ -4,26 +4,83 @@ import com.github.technus.tectech.TecTech; import com.github.technus.tectech.mechanics.elementalMatter.core.cElementalInstanceStackMap; import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.cElementalInstanceStack; import com.github.technus.tectech.mechanics.elementalMatter.definitions.complex.atom.dAtomDefinition; -import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; import com.github.technus.tectech.thing.metaTileEntity.multi.base.MultiblockControl; - -import java.util.ArrayList; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.NameFunction; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.Parameters; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.StatusFunction; import static com.github.technus.tectech.CommonValues.V; +import static com.github.technus.tectech.thing.metaTileEntity.multi.base.LedStatus.*; /** * Created by danie_000 on 24.12.2017. */ -public class Behaviour_ElectromagneticSeparator extends GT_MetaTileEntity_EM_machine.Behaviour { +public class Behaviour_ElectromagneticSeparator implements GT_MetaTileEntity_EM_machine.Behaviour { private final byte tier; - private final int ticks; - private final byte precisionFull; - private final byte precisionMinimal; - private final float maxCapacity; - private final long maxCharge; - private final int offsetMax; - private final static String[] DESCRIPTION_I =new String[]{"Full Precision Input [e/3]","Minimal Precision Input [e/3]","Offset Input [e/3]",null}; - private final static String[] DESCRIPTION_O =new String[]{"Full Precision Limit [e/3]","Minimal Precision Limit [e/3]","Offset Limit [e/3]",null,"Max Charge [e/3]","Max Capacity [eV/c^2]","Max Power Usage[EU/t]","Max Recipe Rime [tick]"}; + private int ticks; + private byte precisionFull,precisionMinimal; + private float maxCapacity; + private long maxCharge; + private int offsetMax; + private Parameters.Group.ParameterIn fullSetting,minimalSetting,offsetSetting; + private final static NameFunction<GT_MetaTileEntity_EM_machine> fullName= (gt_metaTileEntity_em_machine, iParameter) -> "Full Precision Input [e/3]"; + private final StatusFunction<GT_MetaTileEntity_EM_machine> fullStatus= (gt_metaTileEntity_em_machine, iParameter) -> { + double v=iParameter.get(); + if(Double.isNaN(v)){ + return STATUS_WRONG; + } + v=(int)v; + if(Double.isInfinite(v) && v>0) { + return STATUS_TOO_HIGH; + }else if(v>precisionFull){ + return STATUS_HIGH; + }else if(v<precisionFull){ + return STATUS_TOO_LOW; + } + return STATUS_OK; + }; + private final static NameFunction<GT_MetaTileEntity_EM_machine> minimalName= (gt_metaTileEntity_em_machine, iParameter) -> "Minimal Precision Input [e/3]"; + private final StatusFunction<GT_MetaTileEntity_EM_machine> minimalStatus= (gt_metaTileEntity_em_machine, iParameter) -> { + double minimal=iParameter.get(); + double full=fullSetting.get(); + if(Double.isInfinite(minimal) && minimal>0) { + return STATUS_TOO_HIGH; + }else if(minimal>precisionMinimal){ + if(minimal>full){ + return STATUS_TOO_HIGH; + }else { + return STATUS_HIGH; + } + }else if(minimal==precisionMinimal){ + if(minimal>full){ + return STATUS_TOO_HIGH; + }else { + return STATUS_OK; + } + }else if(minimal<precisionMinimal){ + return STATUS_TOO_LOW; + }else { + return STATUS_WRONG; + } + }; + private final static NameFunction<GT_MetaTileEntity_EM_machine> offsetName= (gt_metaTileEntity_em_machine, iParameter) -> "Offset Input [e/3]"; + private final StatusFunction<GT_MetaTileEntity_EM_machine> offsetStatus= (gt_metaTileEntity_em_machine, iParameter) -> { + double offset=iParameter.get(); + if(offset>offsetMax){ + return STATUS_TOO_HIGH; + }else if(offset>0){ + return STATUS_HIGH; + }else if(offset==0){ + return STATUS_OK; + }else if(offset>=-offsetMax){ + return STATUS_LOW; + }else if(offset<-offsetMax){ + return STATUS_TOO_LOW; + }else { + return STATUS_WRONG; + } + }; + //private final static String[] DESCRIPTION_O =new String[]{"Full Precision Limit [e/3]","Minimal Precision Limit [e/3]","Offset Limit [e/3]",null,"Max Charge [e/3]","Max Capacity [eV/c^2]","Max Power Usage[EU/t]","Max Recipe Rime [tick]"}; public Behaviour_ElectromagneticSeparator(int desiredTier){ tier=(byte) desiredTier; @@ -69,113 +126,21 @@ public class Behaviour_ElectromagneticSeparator extends GT_MetaTileEntity_EM_mac } @Override - protected void getFullLedDescriptionIn(ArrayList<String> baseDescr, int hatchNo, int paramID) { - if(hatchNo<=1) { - String desc=DESCRIPTION_I[(hatchNo << 1) + paramID]; - if(desc!=null){ - baseDescr.add(desc); - } - } - } - - @Override - protected void getFullLedDescriptionOut(ArrayList<String> baseDescr, int hatchNo, int paramID) { - if(hatchNo<=3){ - String desc=DESCRIPTION_O[(hatchNo<<1)+paramID]; - if(desc!=null){ - baseDescr.add(desc); - } - } + public void parametersInstantiation(GT_MetaTileEntity_EM_machine te, Parameters parameters) { + Parameters.Group hatch1=parameters.getGroup(7); + fullSetting=hatch1.makeInParameter(0,0,fullName,fullStatus); + minimalSetting=hatch1.makeInParameter(1,2,minimalName,minimalStatus); + Parameters.Group hatch2=parameters.getGroup(8); + offsetSetting=hatch2.makeInParameter(0,0,offsetName,offsetStatus); } @Override - public boolean setAndCheckParametersOutAndStatuses(GT_MetaTileEntity_EM_machine te, double[] parametersToCheckAndFix) { - boolean check=true; - - te.setParameterOut(0,0,precisionFull); - te.setParameterOut(0,1,precisionMinimal); - te.setParameterOut(1,0,offsetMax); - te.setStatusOfParameterOut(1,1,GT_MetaTileEntity_MultiblockBase_EM.STATUS_UNUSED); - te.setParameterOut(2,0,maxCharge); - te.setParameterOut(2,1,maxCapacity); - te.setParameterOut(3,0,V[tier]); - te.setParameterOut(3,1,ticks); - - for(int i=4;i<=9;i++) { - te.setStatusOfParameterOut(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_UNUSED); - te.setStatusOfParameterOut(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_UNUSED); - } - te.setStatusOfParameterIn(1, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_UNUSED); - for(int i=2;i<=3;i++) { - te.setStatusOfParameterIn(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_UNUSED); - te.setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_UNUSED); - } - - double full=parametersToCheckAndFix[0]; - if(Double.isInfinite(full) && full>0) { - te.setStatusOfParameterIn(0,0,GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - check=false; - }else if(full>precisionFull){ - te.setStatusOfParameterIn(0,0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_HIGH); - }else if(full==precisionFull){ - te.setStatusOfParameterIn(0,0,GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - }else if(full<precisionFull){ - te.setStatusOfParameterIn(0,0,GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - check=false; - }else { - te.setStatusOfParameterIn(0,0,GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - check=false; - } - - double minimal=parametersToCheckAndFix[1]; - if(Double.isInfinite(minimal) && minimal>0) { - te.setStatusOfParameterIn(0,1,GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - check=false; - }else if(minimal>precisionMinimal){ - if(minimal>full){ - te.setStatusOfParameterIn(0,1,GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - check=false; - }else { - te.setStatusOfParameterIn(0,1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_HIGH); - } - }else if(minimal==precisionMinimal){ - if(minimal>full){ - te.setStatusOfParameterIn(0,1,GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - check=false; - }else { - te.setStatusOfParameterIn(0,1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - } - }else if(minimal<precisionMinimal){ - te.setStatusOfParameterIn(0,1,GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - check=false; - }else { - te.setStatusOfParameterIn(0,1,GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - check=false; - } - - double offset=parametersToCheckAndFix[2]; - if(offset>offsetMax){ - te.setStatusOfParameterIn(1,0,GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - check=false; - }else if(offset>0){ - te.setStatusOfParameterIn(1,0,GT_MetaTileEntity_MultiblockBase_EM.STATUS_HIGH); - }else if(offset==0){ - te.setStatusOfParameterIn(1,0,GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - }else if(offset>=-offsetMax){ - te.setStatusOfParameterIn(1,0,GT_MetaTileEntity_MultiblockBase_EM.STATUS_LOW); - }else if(offset<-offsetMax){ - te.setStatusOfParameterIn(1,0,GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - check=false; - }else { - te.setStatusOfParameterIn(1,0,GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - check=false; - } - - return check; + public boolean checkParametersInAndSetStatuses(GT_MetaTileEntity_EM_machine te, Parameters parameters) { + return fullSetting.getStatus(true).isOk && minimalSetting.getStatus(true).isOk && offsetSetting.getStatus(true).isOk; } @Override - public MultiblockControl<cElementalInstanceStackMap[]> process(cElementalInstanceStackMap[] inputs, double[] checkedAndFixedParameters) { + public MultiblockControl<cElementalInstanceStackMap[]> process(cElementalInstanceStackMap[] inputs, GT_MetaTileEntity_EM_machine te, Parameters parameters) { cElementalInstanceStackMap input = inputs[0]; if (input == null || input.isEmpty()) return null;//nothing in only valid input @@ -211,9 +176,9 @@ public class Behaviour_ElectromagneticSeparator extends GT_MetaTileEntity_EM_mac outputs[i] = new cElementalInstanceStackMap(); } - double offsetIn=checkedAndFixedParameters[2]; - double precisionFullIn=checkedAndFixedParameters[0]; - double precisionMinimalIn=checkedAndFixedParameters[1]; + double offsetIn=offsetSetting.get(); + double precisionFullIn=fullSetting.get(); + double precisionMinimalIn=minimalSetting.get(); double levelsCountPlus1=precisionFullIn-precisionMinimalIn+1; //take all from hatch handler and put into new map - this takes from hatch to inner data storage diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_PrecisionLaser.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_PrecisionLaser.java index bae032cd9e..02ddecbdc6 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_PrecisionLaser.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_PrecisionLaser.java @@ -2,23 +2,29 @@ package com.github.technus.tectech.thing.metaTileEntity.multi.em_machine; import com.github.technus.tectech.mechanics.elementalMatter.core.cElementalInstanceStackMap; import com.github.technus.tectech.thing.metaTileEntity.multi.base.MultiblockControl; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.Parameters; /** * Created by danie_000 on 24.12.2017. */ -public class Behaviour_PrecisionLaser extends GT_MetaTileEntity_EM_machine.Behaviour { +public class Behaviour_PrecisionLaser implements GT_MetaTileEntity_EM_machine.Behaviour { final int tier; public Behaviour_PrecisionLaser(int tier){ this.tier=tier; } @Override - public boolean setAndCheckParametersOutAndStatuses(GT_MetaTileEntity_EM_machine te, double[] parametersToCheckAndFix) { + public void parametersInstantiation(GT_MetaTileEntity_EM_machine te, Parameters parameters) { + + } + + @Override + public boolean checkParametersInAndSetStatuses(GT_MetaTileEntity_EM_machine te, Parameters parameters) { return false; } @Override - public MultiblockControl<cElementalInstanceStackMap[]> process(cElementalInstanceStackMap[] inputs, double[] checkedAndFixedParameters) { + public MultiblockControl<cElementalInstanceStackMap[]> process(cElementalInstanceStackMap[] inputs, GT_MetaTileEntity_EM_machine te, Parameters parameters) { return null; } } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_Recycler.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_Recycler.java index 4f6d555fdc..e30fdf111b 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_Recycler.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_Recycler.java @@ -2,23 +2,29 @@ package com.github.technus.tectech.thing.metaTileEntity.multi.em_machine; import com.github.technus.tectech.mechanics.elementalMatter.core.cElementalInstanceStackMap; import com.github.technus.tectech.thing.metaTileEntity.multi.base.MultiblockControl; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.Parameters; /** * Created by danie_000 on 24.12.2017. */ -public class Behaviour_Recycler extends GT_MetaTileEntity_EM_machine.Behaviour { +public class Behaviour_Recycler implements GT_MetaTileEntity_EM_machine.Behaviour { final int tier; public Behaviour_Recycler(int tier){ this.tier=tier; } @Override - public boolean setAndCheckParametersOutAndStatuses(GT_MetaTileEntity_EM_machine te, double[] parametersToCheckAndFix) { + public void parametersInstantiation(GT_MetaTileEntity_EM_machine te, Parameters parameters) { + + } + + @Override + public boolean checkParametersInAndSetStatuses(GT_MetaTileEntity_EM_machine te, Parameters parameters) { return false; } @Override - public MultiblockControl<cElementalInstanceStackMap[]> process(cElementalInstanceStackMap[] inputs, double[] checkedAndFixedParameters) { + public MultiblockControl<cElementalInstanceStackMap[]> process(cElementalInstanceStackMap[] inputs, GT_MetaTileEntity_EM_machine te, Parameters parameters) { return null; } } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_Scanner.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_Scanner.java index 32d8b81fdd..627f713a22 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_Scanner.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/Behaviour_Scanner.java @@ -2,23 +2,29 @@ package com.github.technus.tectech.thing.metaTileEntity.multi.em_machine; import com.github.technus.tectech.mechanics.elementalMatter.core.cElementalInstanceStackMap; import com.github.technus.tectech.thing.metaTileEntity.multi.base.MultiblockControl; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.Parameters; /** * Created by danie_000 on 24.12.2017. */ -public class Behaviour_Scanner extends GT_MetaTileEntity_EM_machine.Behaviour { +public class Behaviour_Scanner implements GT_MetaTileEntity_EM_machine.Behaviour { final int tier; public Behaviour_Scanner(int tier){ this.tier=tier; } @Override - public boolean setAndCheckParametersOutAndStatuses(GT_MetaTileEntity_EM_machine te, double[] parametersToCheckAndFix) { + public void parametersInstantiation(GT_MetaTileEntity_EM_machine te, Parameters parameters) { + + } + + @Override + public boolean checkParametersInAndSetStatuses(GT_MetaTileEntity_EM_machine te, Parameters parameters) { return false; } @Override - public MultiblockControl<cElementalInstanceStackMap[]> process(cElementalInstanceStackMap[] inputs, double[] checkedAndFixedParameters) { + public MultiblockControl<cElementalInstanceStackMap[]> process(cElementalInstanceStackMap[] inputs, GT_MetaTileEntity_EM_machine te, Parameters parameters) { return null; } } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/GT_MetaTileEntity_EM_machine.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/GT_MetaTileEntity_EM_machine.java index 46e4ede660..c29da7208a 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/GT_MetaTileEntity_EM_machine.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/em_machine/GT_MetaTileEntity_EM_machine.java @@ -7,32 +7,38 @@ import com.github.technus.tectech.mechanics.elementalMatter.core.cElementalInsta import com.github.technus.tectech.thing.block.QuantumGlassBlock; import com.github.technus.tectech.thing.block.QuantumStuffBlock; import com.github.technus.tectech.thing.metaTileEntity.IConstructable; +import com.github.technus.tectech.thing.metaTileEntity.multi.GT_MetaTileEntity_EM_junction; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; import com.github.technus.tectech.thing.metaTileEntity.multi.base.MultiblockControl; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.Parameters; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.NameFunction; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.StatusFunction; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.common.util.ForgeDirection; -import java.util.ArrayList; -import java.util.BitSet; import java.util.HashMap; +import java.util.function.Supplier; import static com.github.technus.tectech.Util.StructureBuilderExtreme; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.textureOffset; import static com.github.technus.tectech.thing.casing.TT_Container_Casings.sBlockCasingsTT; +import static com.github.technus.tectech.thing.metaTileEntity.multi.base.LedStatus.*; /** * Created by danie_000 on 17.12.2016. */ public class GT_MetaTileEntity_EM_machine extends GT_MetaTileEntity_MultiblockBase_EM implements IConstructable { - public static final String machine = "EM Machinery"; + private ItemStack loadedMachine; private Behaviour currentBehaviour; //region structure @@ -46,7 +52,7 @@ public class GT_MetaTileEntity_EM_machine extends GT_MetaTileEntity_MultiblockBa {"B0", "A!!!", "0!!!0", "A!!!", "B0",},}; private static final Block[] blockType = new Block[]{sBlockCasingsTT, QuantumGlassBlock.INSTANCE, sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMeta = new byte[]{4, 0, 5, 6}; - private static final String[] addingMethods = new String[]{"addClassicToMachineList", "addElementalToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{this::addClassicToMachineList,this::addElementalToMachineList}; private static final short[] casingTextures = new short[]{textureOffset, textureOffset + 4}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasingsTT, sBlockCasingsTT}; private static final byte[] blockMetaFallback = new byte[]{0, 4}; @@ -56,6 +62,36 @@ public class GT_MetaTileEntity_EM_machine extends GT_MetaTileEntity_MultiblockBa "2 - Elemental Hatches or Molecular Casing",}; //endregion + //region parameters + protected Parameters.Group.ParameterIn[] inputMux; + protected Parameters.Group.ParameterIn[] outputMux; + private static final StatusFunction<GT_MetaTileEntity_EM_machine> SRC_STATUS = + (base,p)-> { + double v = p.get(); + if (Double.isNaN(v)) return STATUS_WRONG; + v=(int)v; + if (v < 0) return STATUS_TOO_LOW; + if (v == 0) return STATUS_NEUTRAL; + if (v >= base.eInputHatches.size()) return STATUS_TOO_HIGH; + return STATUS_OK; + }; + private static final StatusFunction<GT_MetaTileEntity_EM_machine> DST_STATUS = + (base,p)->{ + if(base.inputMux[p.hatchId()].getStatus(false)== STATUS_OK){ + double v = p.get(); + if (Double.isNaN(v)) return STATUS_WRONG; + v=(int)v; + if (v < 0) return STATUS_TOO_LOW; + if (v == 0) return STATUS_LOW; + if (v >= base.eInputHatches.size()) return STATUS_TOO_HIGH; + return STATUS_OK; + } + return STATUS_NEUTRAL; + }; + private static final NameFunction<GT_MetaTileEntity_EM_junction> ROUTE_NAME= + (base,p)->(p.parameterId()==0?"Source ":"Destination ")+p.hatchId(); + //endregion + public GT_MetaTileEntity_EM_machine(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); } @@ -65,6 +101,33 @@ public class GT_MetaTileEntity_EM_machine extends GT_MetaTileEntity_MultiblockBa } @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + if(aNBT.hasKey("eLoadedMachine")){ + loadedMachine = ItemStack.loadItemStackFromNBT(aNBT.getCompoundTag("eLoadedMachine")); + } + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + if(loadedMachine !=null) { + aNBT.setTag("eLoadedMachine", loadedMachine.writeToNBT(new NBTTagCompound())); + } + } + + @Override + protected void parametersInstantiation_EM() { + inputMux=new Parameters.Group.ParameterIn[6]; + outputMux=new Parameters.Group.ParameterIn[6]; + for (int i=0;i<6;i++){ + Parameters.Group hatch=parametrization.getGroup(i); + inputMux[i]=hatch.makeInParameter(0,i,ROUTE_NAME,SRC_STATUS); + outputMux[i]=hatch.makeInParameter(1,i,ROUTE_NAME,DST_STATUS); + } + } + + @Override public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_EM_machine(mName); } @@ -91,6 +154,7 @@ public class GT_MetaTileEntity_EM_machine extends GT_MetaTileEntity_MultiblockBa @Override public void onFirstTick_EM(IGregTechTileEntity aBaseMetaTileEntity) { + setCurrentBehaviour(); if(aBaseMetaTileEntity.isServerSide()) { quantumStuff(aBaseMetaTileEntity.isActive()); } @@ -99,7 +163,9 @@ public class GT_MetaTileEntity_EM_machine extends GT_MetaTileEntity_MultiblockBa @Override public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { if(aBaseMetaTileEntity.isClientSide() && (aTick & 0x2)==0){ - currentBehaviour=GT_MetaTileEntity_EM_machine.map.get(new Util.TT_ItemStack(mInventory[1])); + if((aTick&0x10)==0) { + setCurrentBehaviour(); + } if(aBaseMetaTileEntity.isActive()){ int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX*2+aBaseMetaTileEntity.getXCoord(); int yDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetY*2+aBaseMetaTileEntity.getYCoord(); @@ -109,28 +175,6 @@ public class GT_MetaTileEntity_EM_machine extends GT_MetaTileEntity_MultiblockBa } } - private boolean setCurrentBehaviour(Behaviour newBehaviour){ - boolean changed=currentBehaviour!=newBehaviour; - if(changed){ - setDefaultParametersAndStatuses(); - } - currentBehaviour=newBehaviour; - return changed; - } - - private void setDefaultParametersAndStatuses() { - for (int i = 0; i <= 3; i++) { - setStatusOfParameterIn(i, 0, STATUS_NEUTRAL); - setStatusOfParameterIn(i, 1, STATUS_NEUTRAL); - } - for (int i = 0; i <= 9; i++) { - setStatusOfParameterOut(i, 0, STATUS_NEUTRAL); - setStatusOfParameterOut(i, 1, STATUS_NEUTRAL); - setParameterOut(i, 0, 0); - setParameterOut(i, 1, 0); - } - } - @Override public void onRemoval() { quantumStuff(false); @@ -139,48 +183,21 @@ public class GT_MetaTileEntity_EM_machine extends GT_MetaTileEntity_MultiblockBa @Override public boolean checkRecipe_EM(ItemStack itemStack) { - setCurrentBehaviour(GT_MetaTileEntity_EM_machine.map.get(new Util.TT_ItemStack(itemStack))); + setCurrentBehaviour(); if(currentBehaviour==null){ return false; } - //mux input - double[] parameters = new double[]{ - getParameterIn(0, 0), - getParameterIn(0, 1), - getParameterIn(1, 0), - getParameterIn(1, 1), - getParameterIn(2, 0), - getParameterIn(2, 1), - getParameterIn(3, 0), - getParameterIn(3, 1)}; - if (!currentBehaviour.setAndCheckParametersOutAndStatuses(this, parameters)) { + + if (!currentBehaviour.checkParametersInAndSetStatuses(this, parametrization)) { return false; } cElementalInstanceStackMap[] handles = new cElementalInstanceStackMap[6]; - int pointer = getParameterInInt(4, 0) - 1; - if (pointer >= 0 && pointer < eInputHatches.size()) { - handles[0] = eInputHatches.get(pointer).getContainerHandler(); - } - pointer = getParameterInInt(4, 1) - 1; - if (pointer >= 0 && pointer < eInputHatches.size()) { - handles[1] = eInputHatches.get(pointer).getContainerHandler(); - } - pointer = getParameterInInt(5, 0) - 1; - if (pointer >= 0 && pointer < eInputHatches.size()) { - handles[2] = eInputHatches.get(pointer).getContainerHandler(); - } - pointer = getParameterInInt(5, 1) - 1; - if (pointer >= 0 && pointer < eInputHatches.size()) { - handles[3] = eInputHatches.get(pointer).getContainerHandler(); - } - pointer = getParameterInInt(6, 0) - 1; - if (pointer >= 0 && pointer < eInputHatches.size()) { - handles[4] = eInputHatches.get(pointer).getContainerHandler(); - } - pointer = getParameterInInt(6, 1) - 1; - if (pointer >= 0 && pointer < eInputHatches.size()) { - handles[5] = eInputHatches.get(pointer).getContainerHandler(); + for (int i = 0; i < 6; i++) { + int pointer = (int)inputMux[i].get(); + if (pointer >= 0 && pointer < eInputHatches.size()) { + handles[i] = eInputHatches.get(pointer).getContainerHandler(); + } } for (int i = 1; i < 6; i++) { @@ -193,7 +210,7 @@ public class GT_MetaTileEntity_EM_machine extends GT_MetaTileEntity_MultiblockBa } } - MultiblockControl<cElementalInstanceStackMap[]> control = currentBehaviour.process(handles, parameters); + MultiblockControl<cElementalInstanceStackMap[]> control = currentBehaviour.process(handles,this, parametrization); if (control == null) { return false; } @@ -222,33 +239,16 @@ public class GT_MetaTileEntity_EM_machine extends GT_MetaTileEntity_MultiblockBa @Override public void outputAfterRecipe_EM() { - if (setCurrentBehaviour(GT_MetaTileEntity_EM_machine.map.get(new Util.TT_ItemStack(mInventory[1])))) { + if (setCurrentBehaviour()) { return; } + cElementalInstanceStackMap[] handles = new cElementalInstanceStackMap[6]; - int pointer = getParameterInInt(7, 0) - 1; - if (pointer >= 0 && pointer < eOutputHatches.size()) { - handles[0] = eOutputHatches.get(pointer).getContainerHandler(); - } - pointer = getParameterInInt(7, 1) - 1; - if (pointer >= 0 && pointer < eOutputHatches.size()) { - handles[1] = eOutputHatches.get(pointer).getContainerHandler(); - } - pointer = getParameterInInt(8, 0) - 1; - if (pointer >= 0 && pointer < eOutputHatches.size()) { - handles[2] = eOutputHatches.get(pointer).getContainerHandler(); - } - pointer = getParameterInInt(8, 1) - 1; - if (pointer >= 0 && pointer < eOutputHatches.size()) { - handles[3] = eOutputHatches.get(pointer).getContainerHandler(); - } - pointer = getParameterInInt(9, 0) - 1; - if (pointer >= 0 && pointer < eOutputHatches.size()) { - handles[4] = eOutputHatches.get(pointer).getContainerHandler(); - } - pointer = getParameterInInt(9, 1) - 1; - if (pointer >= 0 && pointer < eOutputHatches.size()) { - handles[5] = eOutputHatches.get(pointer).getContainerHandler(); + for (int i = 0; i < 6; i++) { + int pointer = (int)outputMux[i].get(); + if (pointer >= 0 && pointer < eOutputHatches.size()) { + handles[i] = eOutputHatches.get(pointer).getContainerHandler(); + } } //output for (int i = 0; i < 6 && i < outputEM.length; i++) { @@ -268,168 +268,70 @@ public class GT_MetaTileEntity_EM_machine extends GT_MetaTileEntity_MultiblockBa } @Override - protected void parametersLoadDefault_EM() {//default routing table - setParameterPairIn_ClearOut(4, false, 1, 2);//I - setParameterPairIn_ClearOut(5, false, 3, 4);//I - setParameterPairIn_ClearOut(6, false, 5, 6);//I - - setParameterPairIn_ClearOut(7, false, 1, 2);//O - setParameterPairIn_ClearOut(8, false, 3, 4);//O - setParameterPairIn_ClearOut(9, false, 5, 6);//O + public void parametersStatusesWrite_EM(boolean machineBusy) { + if (!machineBusy) { + setCurrentBehaviour(); + } + super.parametersStatusesWrite_EM(machineBusy); } - @Override - public void parametersOutAndStatusesWrite_EM(boolean machineBusy) { - int pointer; - { - BitSet checkArray = new BitSet(); - for (int i = 4; i <= 6; i++) { - pointer = getParameterInInt(i, 0); - if (Double.isNaN(pointer)) { - setStatusOfParameterIn(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - } else if (pointer <= 0) { - setStatusOfParameterIn(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - }//else if(pointer==0) - // setStatusOfParameterIn(i,0,STATUS_LOW); - else if (pointer <= eInputHatches.size()) { - if (checkArray.get(pointer)) { - setStatusOfParameterIn(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - } else { - setStatusOfParameterIn(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - checkArray.set(pointer); - } - } else { - setStatusOfParameterIn(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - } - pointer = getParameterInInt(i, 1); - if (Double.isNaN(pointer)) { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - } else if (pointer < 0) { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - } else if (pointer == 0) { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_LOW); - } else if (pointer <= eInputHatches.size()) { - if (checkArray.get(pointer)) { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - } else { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - checkArray.set(pointer); - } - } else { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - } - } + private boolean setCurrentBehaviour(){ + ItemStack newMachine=mInventory[1]; + if(ItemStack.areItemStacksEqual(newMachine, loadedMachine)){ + return false; } - { - for (int i = 7; i <= 9; i++) { - pointer = getParameterInInt(i, 0); - if (Double.isNaN(pointer)) { - setStatusOfParameterIn(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - } else if (pointer < 0) { - setStatusOfParameterIn(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - } else if (pointer == 0) { - setStatusOfParameterIn(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_LOW); - } else if (pointer <= eOutputHatches.size()) { - setStatusOfParameterIn(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - } else { - setStatusOfParameterIn(i, 0, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - } - pointer = getParameterInInt(i, 1); - if (Double.isNaN(pointer)) { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_WRONG); - } else if (pointer < 0) { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_LOW); - } else if (pointer == 0) { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_LOW); - } else if (pointer <= eOutputHatches.size()) { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_OK); - } else { - setStatusOfParameterIn(i, 1, GT_MetaTileEntity_MultiblockBase_EM.STATUS_TOO_HIGH); - } + loadedMachine=newMachine; + Supplier<Behaviour> behaviourSupplier=GT_MetaTileEntity_EM_machine.BEHAVIOUR_MAP.get(new Util.ItemStack_NoNBT(newMachine)); + if(currentBehaviour==null && behaviourSupplier==null) { + return false; + } + if(currentBehaviour!=null){ + for(int i=6;i<10;i++){ + parametrization.removeGroup(i); } } - setCurrentBehaviour(GT_MetaTileEntity_EM_machine.map.get(new Util.TT_ItemStack(mInventory[1]))); - if (currentBehaviour == null) { - setDefaultParametersAndStatuses(); + if(behaviourSupplier!=null){ + currentBehaviour=behaviourSupplier.get(); + currentBehaviour.parametersInstantiation(this, parametrization); + for(int i=6;i<10;i++){ + parametrization.setToDefaults(i,true,true); + } } else { - double[] parameters = new double[]{ - getParameterIn(0, 0), - getParameterIn(0, 1), - getParameterIn(1, 0), - getParameterIn(1, 1), - getParameterIn(2, 0), - getParameterIn(2, 1), - getParameterIn(3, 0), - getParameterIn(3, 1)}; - currentBehaviour.setAndCheckParametersOutAndStatuses(this,parameters); + currentBehaviour=null; } + return true; } - private static final HashMap<Util.TT_ItemStack, Behaviour> map = new HashMap<>(); + private static final HashMap<Util.ItemStack_NoNBT, Supplier<Behaviour>> BEHAVIOUR_MAP = new HashMap<>(); - public static void registerBehaviour(Behaviour behaviour, ItemStack is) { - map.put(new Util.TT_ItemStack(is), behaviour); - TecTech.LOGGER.info("Registered EM machine behaviour "+behaviour.getClass().getSimpleName()+' '+new Util.TT_ItemStack(is).toString()); + public static void registerBehaviour(Supplier<Behaviour> behaviour, ItemStack is) { + BEHAVIOUR_MAP.put(new Util.ItemStack_NoNBT(is), behaviour); + TecTech.LOGGER.info("Registered EM machine behaviour "+behaviour.get().getClass().getSimpleName()+' '+new Util.ItemStack_NoNBT(is).toString()); } - public static abstract class Behaviour { - public Behaviour(){} + public interface Behaviour { + /** + * instantiate parameters, u can also check machine tier here + * @param te + * @param parameters + */ + void parametersInstantiation(GT_MetaTileEntity_EM_machine te, Parameters parameters); /** - * handle parameters pre recipe, and cyclically - * this shouldn't write to input parameters! only to the provided array and/or output parameters - * @param te this - * @param parametersToCheckAndFix array of 6 parameters to pass to the process method (can be modified) - * this allows to pass different numbers if u want to employ automatic parameter correction here + * handle parameters per recipe + * @param te this te instance + * @param parameters of this te * @return return true if machine can start with current parameters, false if not */ - public abstract boolean setAndCheckParametersOutAndStatuses(GT_MetaTileEntity_EM_machine te, double[] parametersToCheckAndFix); + boolean checkParametersInAndSetStatuses(GT_MetaTileEntity_EM_machine te, Parameters parameters); /** * do recipe handling * @param inputs from muxed inputs - * @param checkedAndFixedParameters array passed from previous method! + * @param parameters array passed from previous method! * @return null if recipe should not start, control object to set machine state and start recipe */ - public abstract MultiblockControl<cElementalInstanceStackMap[]> process(cElementalInstanceStackMap[] inputs, double[] checkedAndFixedParameters); - - /** - * get input param description, only for 4 first hatches - * @param baseDescr - * @param hatchNo - * @param paramID - */ - protected void getFullLedDescriptionIn(ArrayList<String> baseDescr, int hatchNo, int paramID){} - - /** - * get output param description - * @param baseDescr - * @param hatchNo - * @param paramID - */ - protected void getFullLedDescriptionOut(ArrayList<String> baseDescr, int hatchNo, int paramID){} - } - - @Override - public ArrayList<String> getFullLedDescriptionIn(int hatchNo, int paramID) { - ArrayList<String> base=super.getFullLedDescriptionIn(hatchNo, paramID); - if(hatchNo>=7){ - base.add("Output mux "+((hatchNo-7)*2+paramID+1)); - }else if(hatchNo>=4){ - base.add("Input mux "+((hatchNo-4)*2+paramID+1)); - }else if(currentBehaviour!=null){ - currentBehaviour.getFullLedDescriptionIn(base,hatchNo,paramID); - } - return base; - } - - @Override - public ArrayList<String> getFullLedDescriptionOut(int hatchNo, int paramID) { - ArrayList<String> base=super.getFullLedDescriptionOut(hatchNo, paramID); - if(currentBehaviour!=null){ - currentBehaviour.getFullLedDescriptionOut(base,hatchNo,paramID); - } - return base; + MultiblockControl<cElementalInstanceStackMap[]> process(cElementalInstanceStackMap[] inputs, GT_MetaTileEntity_EM_machine te, Parameters parameters); } private void quantumStuff(boolean shouldExist){ diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DataReader.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DataReader.java index 6612167e5f..758afa69b9 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DataReader.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DataReader.java @@ -37,7 +37,7 @@ import static com.github.technus.tectech.Reference.MODID; * Created by Tec on 23.03.2017. */ public class GT_MetaTileEntity_DataReader extends GT_MetaTileEntity_BasicMachine { - private static final HashMap<Util.TT_ItemStack,ArrayList<DataRender>> RENDER_REGISTRY =new HashMap<>(); + private static final HashMap<Util.ItemStack_NoNBT,ArrayList<DataRender>> RENDER_REGISTRY =new HashMap<>(); private static GT_RenderedTexture READER_ONLINE, READER_OFFLINE; public GT_MetaTileEntity_DataReader(int aID, String aName, String aNameRegional, int aTier) { @@ -89,7 +89,7 @@ public class GT_MetaTileEntity_DataReader extends GT_MetaTileEntity_BasicMachine return DID_NOT_FIND_RECIPE; } ItemStack input=getInputAt(0); - ArrayList<DataRender> renders=getRenders(new Util.TT_ItemStack(input)); + ArrayList<DataRender> renders=getRenders(new Util.ItemStack_NoNBT(input)); for(DataRender render:renders){ if(render.canRender(input,mTier)){ mOutputItems[0]=input.copy(); @@ -173,7 +173,7 @@ public class GT_MetaTileEntity_DataReader extends GT_MetaTileEntity_BasicMachine return maxEUInput()*4L; } - public static void addDataRender(Util.TT_ItemStack stack,DataRender render){ + public static void addDataRender(Util.ItemStack_NoNBT stack, DataRender render){ ArrayList<DataRender> renders=RENDER_REGISTRY.get(stack); if(renders==null){ RENDER_REGISTRY.put(stack,renders=new ArrayList<>()); @@ -184,7 +184,7 @@ public class GT_MetaTileEntity_DataReader extends GT_MetaTileEntity_BasicMachine renders.add(render); } - public static ArrayList<DataRender> getRenders(Util.TT_ItemStack stack){ + public static ArrayList<DataRender> getRenders(Util.ItemStack_NoNBT stack){ return RENDER_REGISTRY.get(stack); } @@ -205,7 +205,7 @@ public class GT_MetaTileEntity_DataReader extends GT_MetaTileEntity_BasicMachine } public static void run(){ - addDataRender(new Util.TT_ItemStack(ItemList.Tool_DataStick.get(1)),new DataRender() { + addDataRender(new Util.ItemStack_NoNBT(ItemList.Tool_DataStick.get(1)),new DataRender() { @SideOnly(Side.CLIENT) private ResourceLocation bg; @SideOnly(Side.CLIENT) diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/gui/GT_GUIContainer_DataReader.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/gui/GT_GUIContainer_DataReader.java index 97e7601b67..022247b541 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/gui/GT_GUIContainer_DataReader.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/gui/GT_GUIContainer_DataReader.java @@ -115,7 +115,7 @@ public class GT_GUIContainer_DataReader extends GT_GUIContainerMetaTile_Machine private void renderDataBG(ItemStack thing, int mouseX, int mouseY, int x, int y, byte mTier) { if (thing != null) { - ArrayList<GT_MetaTileEntity_DataReader.DataRender> renders = GT_MetaTileEntity_DataReader.getRenders(new Util.TT_ItemStack(thing)); + ArrayList<GT_MetaTileEntity_DataReader.DataRender> renders = GT_MetaTileEntity_DataReader.getRenders(new Util.ItemStack_NoNBT(thing)); for (GT_MetaTileEntity_DataReader.DataRender render : renders) { if (render.canRender(thing, mTier)) { if (!GT_Utility.areStacksEqual(stack, thing, false)) { @@ -133,7 +133,7 @@ public class GT_GUIContainer_DataReader extends GT_GUIContainerMetaTile_Machine if(stack==null){ return false; } - ArrayList<GT_MetaTileEntity_DataReader.DataRender> renders = GT_MetaTileEntity_DataReader.getRenders(new Util.TT_ItemStack(stack)); + ArrayList<GT_MetaTileEntity_DataReader.DataRender> renders = GT_MetaTileEntity_DataReader.getRenders(new Util.ItemStack_NoNBT(stack)); for (GT_MetaTileEntity_DataReader.DataRender render : renders) { if (render.canRender(stack, mTier)) { render.renderForeground(stack, mouseX, mouseY, this, fontRendererObj); @@ -147,7 +147,7 @@ public class GT_GUIContainer_DataReader extends GT_GUIContainerMetaTile_Machine if(stack==null){ return false; } - ArrayList<GT_MetaTileEntity_DataReader.DataRender> renders = GT_MetaTileEntity_DataReader.getRenders(new Util.TT_ItemStack(stack)); + ArrayList<GT_MetaTileEntity_DataReader.DataRender> renders = GT_MetaTileEntity_DataReader.getRenders(new Util.ItemStack_NoNBT(stack)); for (GT_MetaTileEntity_DataReader.DataRender render : renders) { if (render.canRender(stack, mTier)) { render.renderTooltips(stack, mouseX, mouseY, this); |