From 615fc4e2495ca8bae3fcd45c54e5fe8cfc2e3681 Mon Sep 17 00:00:00 2001 From: Tec Date: Sun, 10 Mar 2019 14:25:39 +0100 Subject: storing work --- src/main/java/com/github/technus/tectech/Util.java | 139 +++++++-- .../GT_MetaTileEntity_EM_essentiaDequantizer.java | 6 +- .../GT_MetaTileEntity_EM_essentiaQuantizer.java | 6 +- .../tectech/loader/recipe/BloodyRecipeLoader.java | 52 ++-- .../hatch/GT_MetaTileEntity_Hatch_Param.java | 62 ++-- .../hatch/gui/GT_Container_Param.java | 74 ++--- .../hatch/gui/GT_Container_ParamAdv.java | 108 +++---- .../hatch/gui/GT_GUIContainer_Param.java | 15 +- .../hatch/gui/GT_GUIContainer_ParamAdv.java | 26 +- .../multi/GT_MetaTileEntity_EM_annihilation.java | 3 +- .../multi/GT_MetaTileEntity_EM_bhg.java | 3 +- .../multi/GT_MetaTileEntity_EM_collider.java | 36 ++- .../multi/GT_MetaTileEntity_EM_computer.java | 45 ++- .../multi/GT_MetaTileEntity_EM_crafting.java | 3 +- .../multi/GT_MetaTileEntity_EM_dataBank.java | 15 +- .../multi/GT_MetaTileEntity_EM_decay.java | 27 +- .../multi/GT_MetaTileEntity_EM_dequantizer.java | 6 +- .../multi/GT_MetaTileEntity_EM_infuser.java | 3 +- .../multi/GT_MetaTileEntity_EM_junction.java | 108 ++++--- .../multi/GT_MetaTileEntity_EM_quantizer.java | 6 +- .../multi/GT_MetaTileEntity_EM_research.java | 14 +- .../multi/GT_MetaTileEntity_EM_scanner.java | 57 +++- .../multi/GT_MetaTileEntity_EM_stabilizer.java | 3 +- .../multi/GT_MetaTileEntity_EM_switch.java | 83 ++--- .../multi/GT_MetaTileEntity_EM_transformer.java | 3 +- .../multi/GT_MetaTileEntity_EM_wormhole.java | 3 +- .../multi/GT_MetaTileEntity_TM_microwave.java | 125 +++----- .../multi/GT_MetaTileEntity_TM_teslaCoil.java | 15 +- .../base/GT_MetaTileEntity_MultiblockBase_EM.java | 183 ++++------- .../metaTileEntity/multi/base/HatchAdder.java | 8 + .../thing/metaTileEntity/multi/base/LedStatus.java | 19 +- .../metaTileEntity/multi/base/NameFunction.java | 8 + .../metaTileEntity/multi/base/Parameters.java | 303 ++++++++++-------- .../metaTileEntity/multi/base/StatusFunction.java | 8 + .../multi/em_machine/Behaviour_Centrifuge.java | 112 ++++--- .../multi/em_machine/Behaviour_Electrolyzer.java | 12 +- .../Behaviour_ElectromagneticSeparator.java | 12 +- .../multi/em_machine/Behaviour_PrecisionLaser.java | 12 +- .../multi/em_machine/Behaviour_Recycler.java | 12 +- .../multi/em_machine/Behaviour_Scanner.java | 12 +- .../em_machine/GT_MetaTileEntity_EM_machine.java | 342 ++++++++------------- .../single/GT_MetaTileEntity_DataReader.java | 10 +- .../single/gui/GT_GUIContainer_DataReader.java | 6 +- 43 files changed, 1052 insertions(+), 1053 deletions(-) create mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/HatchAdder.java create mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/NameFunction.java create mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/StatusFunction.java (limited to 'src/main') diff --git a/src/main/java/com/github/technus/tectech/Util.java b/src/main/java/com/github/technus/tectech/Util.java index 1fd479939c..05e7fd6336 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; @@ -22,8 +25,6 @@ import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.StringUtils; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; @@ -71,6 +72,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 @@ -360,14 +377,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 @@ -578,28 +595,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; } } } @@ -1291,18 +1302,18 @@ public final class Util { return (testedValue & setBits) == setBits; } - public static class TT_ItemStack implements Comparable { + public static class ItemStack_NoNBT implements Comparable { 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; @@ -1314,7 +1325,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; @@ -1329,10 +1340,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 @@ -1346,7 +1357,7 @@ public final class Util { } } - public static void setTier(int tier,Object me){ + public static void setTier(int tier,GT_MetaTileEntity_TieredMachineBlock me){ try{ Field field=GT_MetaTileEntity_TieredMachineBlock.class.getField("mTier"); field.setAccessible(true); @@ -1355,4 +1366,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/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 6a9ef392cd..96230201ba 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 0fbf3aaa13..ba97367cd7 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/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..aa92eb777e 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 value0i = 0; + public double value1i = 0; + public double input0i = 0; + public double input1i = 0; private static Textures.BlockIcons.CustomIcon ScreenON; private static Textures.BlockIcons.CustomIcon ScreenOFF; @@ -105,9 +104,6 @@ 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, @@ -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("eDValue0i", value0i); + aNBT.setDouble("eDValue1i", value1i); + aNBT.setDouble("eDInput0i", input0i); + aNBT.setDouble("eDInput1i", input1i); 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){ + value0i=Float.intBitsToFloat(aNBT.getInteger("eValue0i")); + value1i=Float.intBitsToFloat(aNBT.getInteger("eValue1i")); + input0i=Float.intBitsToFloat(aNBT.getInteger("eInput0i")); + input1i=Float.intBitsToFloat(aNBT.getInteger("eInput1i")); + }else { + value0i=aNBT.getInteger("eValue0i"); + value1i=aNBT.getInteger("eValue1i"); + input0i=aNBT.getInteger("eInput0i"); + input1i=aNBT.getInteger("eInput1i"); + } + }else{ + value0i=aNBT.getDouble("eDValue0i"); + value1i=aNBT.getDouble("eDValue1i"); + input0i=aNBT.getDouble("eDInput0i"); + input1i=aNBT.getDouble("eDInput1i"); + } 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..db0c2d501f 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); @@ -67,8 +68,8 @@ public class GT_Container_Param extends GT_ContainerMetaTile_Machine { paramH.value1i -= aShifthold == 1 ? 4096 : 256; break; case 3: - paramH.value0i >>= aShifthold == 1 ? 16 : 4; - paramH.value1i >>= aShifthold == 1 ? 16 : 4; + paramH.value0i /= aShifthold == 1 ? 4096 : 256; + paramH.value1i /= aShifthold == 1 ? 4096 : 256; break; case 4: paramH.param -= aShifthold == 1 ? 2 : 1; @@ -80,8 +81,8 @@ public class GT_Container_Param extends GT_ContainerMetaTile_Machine { paramH.value1i -= aShifthold == 1 ? 16 : 1; break; case 7: - paramH.value0i >>= aShifthold == 1 ? 2 : 1; - paramH.value1i >>= aShifthold == 1 ? 2 : 1; + paramH.value0i /= aShifthold == 1 ? 16 : 2; + paramH.value1i /= aShifthold == 1 ? 16 : 2; break; case 8: paramH.param += aShifthold == 1 ? 16 : 4; @@ -93,8 +94,8 @@ public class GT_Container_Param extends GT_ContainerMetaTile_Machine { paramH.value1i += aShifthold == 1 ? 4096 : 256; break; case 11: - paramH.value0i <<= aShifthold == 1 ? 16 : 4; - paramH.value1i <<= aShifthold == 1 ? 16 : 4; + paramH.value0i *= aShifthold == 1 ? 4096 : 256; + paramH.value1i *= aShifthold == 1 ? 4096 : 256; break; case 12: paramH.param += aShifthold == 1 ? 2 : 1; @@ -106,8 +107,8 @@ public class GT_Container_Param extends GT_ContainerMetaTile_Machine { paramH.value1i += aShifthold == 1 ? 16 : 1; break; case 15: - paramH.value0i <<= aShifthold == 1 ? 2 : 1; - paramH.value1i <<= aShifthold == 1 ? 2 : 1; + paramH.value0i *= aShifthold == 1 ? 16 : 2; + paramH.value1i *= aShifthold == 1 ? 16 : 2; break; default: doStuff = false; @@ -139,16 +140,11 @@ public class GT_Container_Param extends GT_ContainerMetaTile_Machine { 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..6b1e4f68cd 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.value1i = Double.longBitsToDouble(0xFFFF_FFFF_FFFF_FFFFL); } else { - paramH.value0i = 0xFFFFFFFF; + paramH.value0i = Double.longBitsToDouble(0xFFFF_FFFF_FFFF_FFFFL); } } else { if (secondRow) { - paramH.value1i |= 1 << columnPointer; + long temp=Double.doubleToLongBits(paramH.value1i); + temp |= 1 << columnPointer; + paramH.value1i=Double.longBitsToDouble(temp); } else { - paramH.value0i |= 1 << columnPointer; + long temp=Double.doubleToLongBits(paramH.value0i); + temp |= 1 << columnPointer; + paramH.value0i=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.value1i = Double.longBitsToDouble(0); } else { - paramH.value0i = 0; + paramH.value0i = Double.longBitsToDouble(0); } } else { if (secondRow) { - paramH.value1i &= ~(1 << columnPointer); + long temp=Double.doubleToLongBits(paramH.value1i); + temp &= ~(1 << columnPointer); + paramH.value1i=Double.longBitsToDouble(temp); } else { - paramH.value0i &= ~(1 << columnPointer); + long temp=Double.doubleToLongBits(paramH.value0i); + temp &= ~(1 << columnPointer); + paramH.value0i=Double.longBitsToDouble(temp); } } break; @@ -144,7 +151,8 @@ public class GT_Container_ParamAdv extends GT_ContainerMetaTile_Machine { } break; case 11: - showInts ^= true; + paramH.value0i=paramH.input0i; + paramH.value1i=paramH.input1i; 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.value1i = Double.longBitsToDouble(~Double.doubleToLongBits(paramH.value1i)); } else { - paramH.value0i ^= 0xFFFFFFFF; + paramH.value0i = Double.longBitsToDouble(~Double.doubleToLongBits(paramH.value1i)); } } else { if (secondRow) { - paramH.value1i ^= 1 << columnPointer; + long temp=Double.doubleToLongBits(paramH.value1i); + temp ^= 1 << columnPointer; + paramH.value1i=Double.longBitsToDouble(temp); } else { - paramH.value0i ^= 1 << columnPointer; + long temp=Double.doubleToLongBits(paramH.value0i); + temp ^= 1 << columnPointer; + paramH.value0i=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) { @@ -213,22 +224,15 @@ public class GT_Container_ParamAdv extends GT_ContainerMetaTile_Machine { input0f = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).input0i; input1f = ((GT_MetaTileEntity_Hatch_Param) mTileEntity.getMetaTileEntity()).input1i; 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..9b8f818da8 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,14 @@ 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.glScalef(.5f,.5f,.5f); + proxy.renderUnicodeString("\u24EA\u2b06" + Util.longBitsToShortString(Double.doubleToLongBits(((GT_Container_Param) mContainer).value0f)), 46*2, 50*2, 167*2, 0x00bbff); + proxy.renderUnicodeString("\u2460\u2b06" + Util.longBitsToShortString(Double.doubleToLongBits(((GT_Container_Param) mContainer).value1f)), 46*2, 58*2, 167*2, 0x0077ff); + GL11.glScalef(1,1,1); } 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..541c8323b1 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,22 @@ 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.glScalef(.5f,.5f,.5f); + proxy.renderUnicodeString("\u24EA\u2b06" + Util.longBitsToShortString(Double.doubleToLongBits(((GT_Container_ParamAdv) mContainer).value0f)), 46*2, 50*2, 167*2, 0x00bbff); + proxy.renderUnicodeString("\u2460\u2b06" + Util.longBitsToShortString(Double.doubleToLongBits(((GT_Container_ParamAdv) mContainer).value1f)), 46*2, 58*2, 167*2, 0x0077ff); + GL11.glScalef(1,1,1); 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 03404cf652..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,8 +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.LedStatus; +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; @@ -34,7 +36,6 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.common.util.ForgeDirection; import java.util.HashMap; -import java.util.function.Function; import static com.github.technus.tectech.Util.StructureBuilderExtreme; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.textureOffset; @@ -273,25 +274,26 @@ public class GT_MetaTileEntity_EM_collider extends GT_MetaTileEntity_MultiblockB //region parameters protected Parameters.Group.ParameterIn mode; - private static final Function MODE_STATUS = base_EM->{ + private static final StatusFunction MODE_STATUS = (base_EM, p)->{ if(base_EM.isMaster()){ - if (base_EM.mode.get() == FUSE_MODE || base_EM.mode.get() == COLLIDE_MODE) { + double mode=p.get(); + if (mode == FUSE_MODE || mode == COLLIDE_MODE) { return STATUS_OK; - } else if (base_EM.mode.get() > 1) { + } else if (mode > 1) { return STATUS_TOO_HIGH; - } else if (base_EM.mode.get() < 0) { + } else if (mode < 0) { return STATUS_TOO_LOW; - }else{ - return STATUS_WRONG; } + return STATUS_WRONG; } return STATUS_UNUSED; }; - private static final Function MODE_NAME = base_EM->{ + private static final NameFunction MODE_NAME = (base_EM, p)->{ if(base_EM.isMaster()){ - if(base_EM.mode.get()==FUSE_MODE){ + double mode=p.get(); + if(mode==FUSE_MODE){ return "Mode: Fuse"; - }else if(base_EM.mode.get()==COLLIDE_MODE){ + }else if(mode==COLLIDE_MODE){ return "Mode: Collide"; } return "Mode: Undefined"; @@ -337,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}; @@ -361,7 +367,7 @@ public class GT_MetaTileEntity_EM_collider extends GT_MetaTileEntity_MultiblockB @Override protected void parametersInstantiation_EM() { - Parameters.Group hatch_0=parametrization.makeGroup(0,false); + Parameters.Group hatch_0=parametrization.getGroup(0); mode=hatch_0.makeInParameter(0,FUSE_MODE, MODE_NAME, MODE_STATUS); } @@ -476,9 +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()) { - super.parametersOutAndStatusesWrite_EM(machineBusy); + super.parametersStatusesWrite_EM(machineBusy); } } 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 d12ec0ca64..c2b6589901 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,8 +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; @@ -29,11 +32,9 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import java.util.ArrayList; -import java.util.function.Function; 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; @@ -49,17 +50,17 @@ public class GT_MetaTileEntity_EM_computer extends GT_MetaTileEntity_MultiblockB //region parameters protected Parameters.Group.ParameterIn overclock,overvolt; protected Parameters.Group.ParameterOut maxCurrentTemp,availableData; - private static final Function OC_NAME = base-> "Overclock ratio"; - private static final Function OV_NAME = base-> "Overvoltage ratio"; - private static final Function MAX_TEMP_NAME = base-> "Current max. heat"; - private static final Function COMPUTE_NAME = base-> "Produced computation"; - private static final Function OC_STATUS= - base->LedStatus.fromLimitsInclusiveOuterBoundary(base.overclock.get(),0,1,1,3); - private static final Function OV_STATUS= - base->LedStatus.fromLimitsInclusiveOuterBoundary(base.overvolt.get(),.7,.8,1.2,2); - private static final Function MAX_TEMP_STATUS= - base->LedStatus.fromLimitsInclusiveOuterBoundary(base.maxCurrentTemp.get(),-10000,0,0,5000); - private static final Function COMPUTE_STATUS=base->{ + private static final NameFunction OC_NAME = (base, p)-> "Overclock ratio"; + private static final NameFunction OV_NAME = (base,p)-> "Overvoltage ratio"; + private static final NameFunction MAX_TEMP_NAME = (base,p)-> "Current max. heat"; + private static final NameFunction COMPUTE_NAME = (base,p)-> "Produced computation"; + private static final StatusFunction OC_STATUS= + (base,p)->LedStatus.fromLimitsInclusiveOuterBoundary(p.get(),0,1,1,3); + private static final StatusFunction OV_STATUS= + (base,p)->LedStatus.fromLimitsInclusiveOuterBoundary(p.get(),.7,.8,1.2,2); + private static final StatusFunction MAX_TEMP_STATUS= + (base,p)->LedStatus.fromLimitsInclusiveOuterBoundary(p.get(),-10000,0,0,5000); + private static final StatusFunction COMPUTE_STATUS=(base,p)->{ if(base.eAvailableData<0){ return STATUS_TOO_LOW; } @@ -79,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}; @@ -104,7 +105,7 @@ public class GT_MetaTileEntity_EM_computer extends GT_MetaTileEntity_MultiblockB @Override protected void parametersInstantiation_EM() { - Parameters.Group hatch_0=parametrization.makeGroup(0,true); + 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); @@ -140,7 +141,7 @@ public class GT_MetaTileEntity_EM_computer extends GT_MetaTileEntity_MultiblockB @Override public boolean checkRecipe_EM(ItemStack itemStack) { - parametrization.setToDefaults(false,true,false); + parametrization.setToDefaults(false,true); eAvailableData = 0; double maxTemp=0; double overClockRatio= overclock.get(); @@ -148,7 +149,7 @@ public class GT_MetaTileEntity_EM_computer extends GT_MetaTileEntity_MultiblockB if(Double.isNaN(overClockRatio) || Double.isNaN(overVoltageRatio)) { return false; } - if(overclock.getStatus(true).isOk() && overvolt.getStatus(true).isOk()){ + if(overclock.getStatus(true).isOk && overvolt.getStatus(true).isOk){ float eut=V[8] * (float)overVoltageRatio * (float)overClockRatio; if(eut eStacksDataOutputs = new ArrayList<>(); @@ -46,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}; @@ -176,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 36b7505a65..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,8 +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.LedStatus; +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,14 +27,13 @@ import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; -import java.util.function.Function; - import static com.github.technus.tectech.CommonValues.VN; 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.*; +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. @@ -47,9 +48,9 @@ public class GT_MetaTileEntity_EM_decay extends GT_MetaTileEntity_MultiblockBase //region parameters protected Parameters.Group.ParameterIn ampereFlow; - private final Function FLOW_NAME=base->"Ampere divider"; - private final Function FLOW_STATUS=base->{ - if(eAmpereFlow<=0){ + private static final NameFunction FLOW_NAME= (base, p)->"Ampere divider"; + private static final StatusFunction FLOW_STATUS= (base, p)->{ + if(base.eAmpereFlow<=0){ return STATUS_TOO_LOW; } return STATUS_OK; @@ -70,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}; @@ -91,7 +92,7 @@ public class GT_MetaTileEntity_EM_decay extends GT_MetaTileEntity_MultiblockBase @Override protected void parametersInstantiation_EM() { - Parameters.Group hatch_0=parametrization.makeGroup(0,false); + Parameters.Group hatch_0=parametrization.getGroup(0, true); ampereFlow=hatch_0.makeInParameter(0,1,FLOW_NAME,FLOW_STATUS); } @@ -179,8 +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/(eAmpereFlow=(long) ampereFlow.get())); - + eAmpereFlow=(long) ampereFlow.get(); + if (eAmpereFlow <= 0) { + mEUt=0; + return false; + } + mEUt=(int)(energyDose/eAmpereFlow); return outputEM[0].hasStacks(); } 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 8c0a0f0708..5f5febb383 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 a295a5c7f1..d78ed3cbc4 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; @@ -16,6 +21,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.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. @@ -29,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}; @@ -42,6 +55,36 @@ public class GT_MetaTileEntity_EM_junction extends GT_MetaTileEntity_MultiblockB }; //endregion + //region parameters + private static final NameFunction ROUTE_NAME= + (base,p)->(p.parameterId()==0?"Source ":"Destination ")+p.hatchId(); + private static final StatusFunction 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 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=new Parameters.Group.ParameterIn[10]; + protected Parameters.Group.ParameterIn[] dst=new Parameters.Group.ParameterIn[10]; + //endregion + public GT_MetaTileEntity_EM_junction(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); } @@ -50,6 +93,15 @@ public class GT_MetaTileEntity_EM_junction extends GT_MetaTileEntity_MultiblockB super(aName); } + @Override + protected void parametersInstantiation_EM() { + 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); @@ -57,7 +109,13 @@ public class GT_MetaTileEntity_EM_junction extends GT_MetaTileEntity_MultiblockB @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 +137,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, STATUS_TOO_LOW); - setStatusOfParameterIn(i, 1, STATUS_NEUTRAL); - } else if (src > eInputHatches.size()) { - setStatusOfParameterIn(i, 0, STATUS_TOO_HIGH); - setStatusOfParameterIn(i, 1, STATUS_NEUTRAL); - } else if (Double.isNaN(src)) { - setStatusOfParameterIn(i, 0, STATUS_WRONG); - setStatusOfParameterIn(i, 1, STATUS_NEUTRAL); - } else { - setStatusOfParameterIn(i, 0, STATUS_OK); - dest = getParameterIn(i, 1); - if (dest < 0) { - setStatusOfParameterIn(i, 1, STATUS_TOO_LOW); - } else if (dest == 0) { - setStatusOfParameterIn(i, 1, STATUS_LOW); - } else if (dest > eOutputHatches.size()) { - setStatusOfParameterIn(i, 1, STATUS_TOO_HIGH); - } else if (Double.isNaN(dest)) { - setStatusOfParameterIn(i, 1, STATUS_WRONG); - } else { - setStatusOfParameterIn(i, 1, STATUS_OK); - } - } - } - } - @Override public boolean checkRecipe_EM(ItemStack itemStack) { for (GT_MetaTileEntity_Hatch_InputElemental in : eInputHatches) { @@ -127,18 +153,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 1494d97e34..e7a42fa941 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 b4b786dcdb..6b3cab021e 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..d7cf3303f3 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 CONFIG_NAME= + (base,p)->"Config at Depth: "+(p.hatchId()*2+p.parameterId()); + private static final StatusFunction 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=new Parameters.Group.ParameterIn[20]; + //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}; @@ -97,6 +120,15 @@ public class GT_MetaTileEntity_EM_scanner extends GT_MetaTileEntity_MultiblockBa eDismantleBoom=true; } + @Override + protected void parametersInstantiation_EM() { + 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 +280,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 +304,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 +449,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 767bd676d6..e5bcb3f75d 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; @@ -39,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}; @@ -49,6 +53,34 @@ public class GT_MetaTileEntity_EM_switch extends GT_MetaTileEntity_MultiblockBas }; //endregion + //region parameters + private static final NameFunction ROUTE_NAME= + (base,p)->(p.parameterId()==0?"Destination ":"Weight ")+p.hatchId(); + private static final StatusFunction 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 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=new Parameters.Group.ParameterIn[10]; + protected Parameters.Group.ParameterIn[] weight =new Parameters.Group.ParameterIn[10]; + //endregion + public GT_MetaTileEntity_EM_switch(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); } @@ -57,6 +89,15 @@ public class GT_MetaTileEntity_EM_switch extends GT_MetaTileEntity_MultiblockBas super(aName); } + @Override + protected void parametersInstantiation_EM() { + 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 @@ -117,12 +158,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 } } @@ -144,9 +183,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 +217,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, STATUS_TOO_LOW); - setStatusOfParameterIn(i, 1, STATUS_NEUTRAL); - } else if (Double.isNaN(weight)) { - setStatusOfParameterIn(i, 0, STATUS_WRONG); - setStatusOfParameterIn(i, 1, STATUS_NEUTRAL); - } else { - setStatusOfParameterIn(i, 0, weight==0?STATUS_LOW:STATUS_OK); - dest = getParameterIn(i, 1); - if (dest < 0) { - setStatusOfParameterIn(i, 1, STATUS_TOO_LOW); - } else if (dest == 0) { - setStatusOfParameterIn(i, 1, STATUS_LOW); - } else if (dest > eOutputData.size()) { - setStatusOfParameterIn(i, 1, STATUS_TOO_HIGH); - } else if (Double.isNaN(dest)) { - setStatusOfParameterIn(i, 1, STATUS_WRONG); - } else { - setStatusOfParameterIn(i, 1, STATUS_OK); - } - } - } - } - @Override public String[] getDescription() { return new String[]{ 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 541adfd953..4456f97130 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; @@ -35,8 +34,6 @@ 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 @@ -51,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}; @@ -62,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 POWER_NAME = (base, p)-> "Power setting"; + private static final NameFunction TIMER_SETTING_NAME = (base, p)-> "Timer setting"; + private static final NameFunction TIMER_REMAINING_NAME = (base, p)-> "Timer remaining"; + private static final NameFunction TIMER_VALUE_NAME = (base,p)-> "Timer value"; + private static final StatusFunction POWER_STATUS= + (base,p)-> LedStatus.fromLimitsInclusiveOuterBoundary(p.get(),300,1000,1000,Double.POSITIVE_INFINITY); + private static final StatusFunction 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,6 +86,15 @@ public class GT_MetaTileEntity_TM_microwave extends GT_MetaTileEntity_Multiblock super(aName); } + @Override + 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(0,360,TIMER_REMAINING_NAME,TIMER_STATUS); + } + @Override public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_TM_microwave(mName); @@ -123,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; @@ -141,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]; @@ -153,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 itemsToOutput=new ArrayList<>(); HashSet tickedStuff=new HashSet<>(); @@ -194,59 +221,14 @@ 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 parametersInReadWhileActive_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, STATUS_TOO_LOW); - } else if (powerParameter < 1000) { - setStatusOfParameterIn(0, 0, STATUS_LOW); - } else if (powerParameter == 1000) { - setStatusOfParameterIn(0, 0, STATUS_OK); - } else if (powerParameter == Double.POSITIVE_INFINITY) { - setStatusOfParameterIn(0, 0, STATUS_TOO_HIGH); - } else if (Double.isNaN(powerParameter)) { - setStatusOfParameterIn(0, 0, STATUS_WRONG); - } else { - setStatusOfParameterOut(0, 0, STATUS_HIGH); - } - - double timerParameter = getParameterIn(0, 1); - if (timerParameter <= 1) { - setStatusOfParameterIn(0, 1, STATUS_TOO_LOW); - } else if (timerParameter <= 3000) { - setStatusOfParameterIn(0, 1, STATUS_OK); - } else if (Double.isNaN(timerParameter)) { - setStatusOfParameterIn(0, 1, STATUS_WRONG); - } else { - setStatusOfParameterIn(0, 1, STATUS_TOO_HIGH); - } - - setParameterOut(0, 0, timerValue); - setParameterOut(0, 1, timerSetting - timerValue); - } - @Override public boolean onRunningTick(ItemStack aStack) { if(eSafeVoid) { @@ -258,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/GT_MetaTileEntity_TM_teslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java index 82722e76f9..2c58006360 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java @@ -6,6 +6,7 @@ import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_H import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoMulti; 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 cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.enums.Textures; @@ -23,7 +24,6 @@ import java.util.ArrayList; import static com.github.technus.tectech.CommonValues.V; import static com.github.technus.tectech.Util.StructureBuilder; -import static com.github.technus.tectech.loader.TecTechConfig.DEBUG_MODE; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.texturePage; import static gregtech.api.GregTech_API.*; import static gregtech.api.enums.GT_Values.E; @@ -88,7 +88,7 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock private static final byte[] blockMetaT1 = new byte[]{15, 1, 13, 0}; private static final byte[] blockMetaT2 = new byte[]{15, 2, 13, 0}; private static final byte[][] blockMetas = new byte[][]{blockMetaT0,blockMetaT1,blockMetaT2}; - private static final String[] addingMethods = new String[]{"addCapacitorToMachineList", "addFrameToMachineList"}; + private final HatchAdder[] addingMethods = new HatchAdder[]{this::addCapacitorToMachineList, this::addFrameToMachineList}; private static final short[] casingTextures = new short[]{29, 0}; private static final Block[] blockTypeFallback = new Block[]{sBlockCasings2, null}; private static final byte[] blockMetaFallback = new byte[]{13, 0}; @@ -348,15 +348,4 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock } return false; } - - public static void run() { - try { - adderMethodMap.put("addFrameToMachineList", GT_MetaTileEntity_TM_teslaCoil.class.getMethod("addFrameToMachineList", IGregTechTileEntity.class, int.class)); - adderMethodMap.put("addCapacitorToMachineList", GT_MetaTileEntity_TM_teslaCoil.class.getMethod("addCapacitorToMachineList", 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/base/GT_MetaTileEntity_MultiblockBase_EM.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java index f3147d890c..3c9102d072 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 @@ -14,7 +14,6 @@ import com.github.technus.tectech.thing.metaTileEntity.multi.base.network.Rotati import com.github.technus.tectech.thing.metaTileEntity.multi.base.render.TT_RenderedTexture; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import gregtech.api.enums.GT_Values; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -36,18 +35,13 @@ 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; import static com.github.technus.tectech.Util.getTier; import static com.github.technus.tectech.loader.TecTechConfig.DEBUG_MODE; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.texturePage; -import static gregtech.api.enums.GT_Values.B; /** * Created by danie_000 on 27.10.2016. @@ -59,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 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 @@ -155,14 +143,14 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt super(aID, aName, aNameRegional); parametrization=new Parameters(this); parametersInstantiation_EM(); - parametrization.setToDefaults(true,true,true); + parametrization.setToDefaults(true,true); } protected GT_MetaTileEntity_MultiblockBase_EM(String aName) { super(aName); parametrization=new Parameters(this); parametersInstantiation_EM(); - parametrization.setToDefaults(true,true,true); + parametrization.setToDefaults(true,true); } //region SUPER STRUCT @@ -375,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); } @@ -435,7 +423,6 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt } } } - //endregion //region tooltip and scanner result @@ -455,11 +442,10 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt EnumChatFormatting.YELLOW+ ":"+ EnumChatFormatting.AQUA+"I"); list.add(EnumChatFormatting.WHITE+"Value: "+ - EnumChatFormatting.AQUA+parametrization.getIn(hatchNo,paramID)+ - EnumChatFormatting.GOLD+(((parametrization.bParamsAreFloats& B[hatchNo])!=0)?" float":" int")); + EnumChatFormatting.AQUA+parametrization.getIn(hatchNo,paramID)); try{ list.add(parametrization.groups[hatchNo].parameterIn[paramID].getBrief()); - }catch (NullPointerException e){ + }catch (NullPointerException|IndexOutOfBoundsException e){ list.add("Unused"); } return list; @@ -480,11 +466,10 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt EnumChatFormatting.YELLOW+ ":"+ EnumChatFormatting.AQUA+"O"); list.add(EnumChatFormatting.WHITE+"Value: "+ - EnumChatFormatting.AQUA+parametrization.getOut(hatchNo,paramID)+ - EnumChatFormatting.GOLD+(((parametrization.bParamsAreFloats& B[hatchNo])!=0)?" float":" int")); + EnumChatFormatting.AQUA+parametrization.getOut(hatchNo,paramID)); try{ list.add(parametrization.groups[hatchNo].parameterOut[paramID].getBrief()); - }catch (NullPointerException e){ + }catch (NullPointerException|IndexOutOfBoundsException e){ list.add("Unused"); } return list; @@ -726,16 +711,6 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt */ protected void parametersInstantiation_EM(){} - /** - * This is called automatically when there was IN parameters data update and machine IS RUNNING - * although the base code only downloads the IN values from parametrizers when machine is NOT OPERATING - * - * this can be used to update the IN values on the fly when machine is running to affect the current process - * - */ - protected void parametersInReadWhileActive_EM() { - } - /** * It is automatically called OFTEN * update status of parameters in guis (and "machine state" if u wish) @@ -745,13 +720,23 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt * * @param machineBusy is machine doing SHIT */ - protected void parametersOutAndStatusesWrite_EM(boolean machineBusy) {//todo unimplement + 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) { @@ -891,17 +876,15 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt NBTTagCompound paramI = new NBTTagCompound(); for (int i = 0; i < parametrization.iParamsIn.length; i++) { - paramI.setInteger(Integer.toString(i), parametrization.iParamsIn[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 < parametrization.iParamsOut.length; i++) { - paramO.setInteger(Integer.toString(i), parametrization.iParamsOut[i]); + paramO.setDouble(Integer.toString(i), parametrization.iParamsOut[i]); } - aNBT.setTag("eParamsOut", paramO); - - aNBT.setShort("eParamsS",parametrization.bParamsAreFloats); + aNBT.setTag("eParamsOutD", paramO); NBTTagCompound paramIs = new NBTTagCompound(); for (int i = 0; i < parametrization.eParamsInStatus.length; i++) { @@ -978,24 +961,28 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt outputEM = null; } - NBTTagCompound paramI = aNBT.getCompoundTag("eParamsIn"); - for (int i = 0; i < parametrization.iParamsIn.length; i++) { - parametrization.iParamsIn[i] = paramI.getInteger(Integer.toString(i)); - } - - NBTTagCompound paramO = aNBT.getCompoundTag("eParamsOut"); - for (int i = 0; i < parametrization.iParamsOut.length; i++) { - parametrization.iParamsOut[i] = paramO.getInteger(Integer.toString(i)); - } - - if(aNBT.hasKey("eParamsB")) { + 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"); - parametrization.bParamsAreFloats=0; for (int i = 0; i < 10; i++) { - parametrization.bParamsAreFloats|=paramB.getBoolean(Integer.toString(i))? B[i]:0; + 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{ - parametrization.bParamsAreFloats=aNBT.getShort("eParamsS"); + 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"); @@ -1187,47 +1174,40 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt * 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((parametrization.bParamsAreFloats&B[hatch.param])!=0){ - hatch.input0i = parametrization.iParamsOut[paramID]; - hatch.input1i = parametrization.iParamsOut[paramID + 10]; - }else if(hatch.isUsingFloats()){ - hatch.input0i = Float.floatToIntBits((float)parametrization.iParamsOut[paramID]); - hatch.input1i = Float.floatToIntBits((float)parametrization.iParamsOut[paramID + 10]); - }else { - hatch.input0i = (int)Float.intBitsToFloat(parametrization.iParamsOut[paramID]); - hatch.input1i = (int)Float.intBitsToFloat(parametrization.iParamsOut[paramID + 10]); + int hatchId = hatch.param; + if(parametrization.groups[hatchId]!=null && parametrization.groups[hatchId].updateWhileRunning){ + parametrization.iParamsIn[hatchId] = hatch.value0i; + parametrization.iParamsIn[hatchId + 10] = hatch.value1i; } + hatch.input0i = parametrization.iParamsOut[hatchId]; + hatch.input1i = parametrization.iParamsOut[hatchId + 10]; } - parametersInReadWhileActive_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; - if(hatch.isUsingFloats()){ - parametrization.bParamsAreFloats |= B[hatch.param]; - }else { - parametrization.bParamsAreFloats &=~B[hatch.param]; - } - parametrization.iParamsIn[paramID] = hatch.value0i; - parametrization.iParamsIn[paramID + 10] = hatch.value1i; - hatch.input0i = parametrization.iParamsOut[paramID]; - hatch.input1i = parametrization.iParamsOut[paramID + 10]; + int hatchId = hatch.param; + parametrization.iParamsIn[hatchId] = hatch.value0i; + parametrization.iParamsIn[hatchId + 10] = hatch.value1i; + hatch.input0i = parametrization.iParamsOut[hatchId]; + hatch.input1i = 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 @@ -1431,13 +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) { - if(hatch.isUsingFloats()){ - parametrization.bParamsAreFloats |= B[hatch.param]; - }else { - parametrization.bParamsAreFloats &=~B[hatch.param]; - } - } } } } else { @@ -2621,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..a8633c4837 --- /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; + +import java.util.function.BiFunction; + +public interface HatchAdder extends BiFunction {} 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 index 52d4f30c12..e32df43ae4 100644 --- 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 @@ -19,14 +19,6 @@ public enum LedStatus { this.isOk=ok; } - public boolean isOk(){ - return isOk; - } - - public boolean isBad(){ - return !isOk; - } - public byte getOrdinalByte(){ return (byte)ordinal(); } @@ -61,7 +53,6 @@ public enum LedStatus { } public static LedStatus fromLimitsExclusiveOuterBoundary(double value, double min,double low, double high,double max, double... excludedNumbers){ - if(Double.isNaN(value)) return STATUS_WRONG; if(value<=min) return STATUS_TOO_LOW; if(value>=max) return STATUS_TOO_HIGH; @@ -75,10 +66,8 @@ public enum LedStatus { } public static LedStatus fromLimitsInclusiveBoundary(double value, double min, double max, double... excludedNumbers){ - if(Double.isNaN(value)) return STATUS_WRONG; - if(value<=min) return STATUS_TOO_LOW; - else if(value==min) - if(value>=max) return STATUS_TOO_HIGH; + if(valuemax) return STATUS_TOO_HIGH; for (double val : excludedNumbers) { if(val==value) return STATUS_WRONG; @@ -88,10 +77,8 @@ public enum LedStatus { } public static LedStatus fromLimitsExclusiveBoundary(double value, double min, double max, double... excludedNumbers){ - if(Double.isNaN(value)) return STATUS_WRONG; if(value<=min) return STATUS_TOO_LOW; - else if(value==min) - if(value>=max) return STATUS_TOO_HIGH; + if(value>=max) return STATUS_TOO_HIGH; for (double val : excludedNumbers) { if(val==value) return STATUS_WRONG; 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..8ced431576 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/NameFunction.java @@ -0,0 +1,8 @@ +package com.github.technus.tectech.thing.metaTileEntity.multi.base; + +import java.util.function.BiFunction; + +public interface NameFunction extends BiFunction { + @Override + 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 index 3ab2947085..2e8959c00f 100644 --- 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 @@ -1,40 +1,31 @@ package com.github.technus.tectech.thing.metaTileEntity.multi.base; -import gregtech.api.enums.GT_Values; - import java.util.ArrayList; -import java.util.BitSet; -import java.util.function.Function; - -import static gregtech.api.enums.GT_Values.B; /** * Instantiate parameters as field in parametersInstantiation_EM(); */ public class Parameters { - public static final Function LED_STATUS_FUNCTION_DEFAULT = o->LedStatus.STATUS_UNDEFINED; - public static final Function NAME_FUNCTION_DEFAULT=o->"Undefined"; - public static final int ZERO_FLOAT=Float.floatToIntBits(0); + 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]; - int[] iParamsIn = new int[20];//number I from parametrizers - int[] iParamsOut = new int[20];//number O to parametrizers + double[] iParamsIn = new double[20];//number I from parametrizers + double[] iParamsOut = new double[20];//number O to parametrizers final ArrayList parameterInArrayList =new ArrayList<>(); final ArrayList parameterOutArrayList =new ArrayList<>(); - short bParamsAreFloats=0; - //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 - public double getIn(int hatchNo,int parameterId){ - return (bParamsAreFloats& B[hatchNo])!=0?Float.intBitsToFloat(iParamsIn[hatchNo+10*parameterId]):iParamsIn[hatchNo+10*parameterId]; + double getIn(int hatchNo,int parameterId){ + return iParamsIn[hatchNo+10*parameterId]; } - public double getOut(int hatchNo,int parameterId){ - return (bParamsAreFloats& B[hatchNo])!=0?Float.intBitsToFloat(iParamsOut[hatchNo+10*parameterId]):iParamsOut[hatchNo+10*parameterId]; + double getOut(int hatchNo,int parameterId){ + return iParamsOut[hatchNo+10*parameterId]; } private final GT_MetaTileEntity_MultiblockBase_EM parent; @@ -43,49 +34,29 @@ public class Parameters { this.parent=parent; } - public void setToDefaults(boolean defaultIn, boolean defaultOut,boolean defaultAreFloats){ - for (int hatch=0;hatch<10;hatch++) { - Group p= groups[hatch]; - if (p!=null){ - p.setToDefaults(defaultIn,defaultOut,defaultAreFloats); - }else{ - if(defaultAreFloats){ - bParamsAreFloats&=~B[hatch]; - if(defaultIn){ - iParamsIn[hatch] = 0; - iParamsIn[hatch + 10] = 0; - } - if(defaultOut){ - iParamsOut[hatch] = 0; - iParamsOut[hatch + 10] = 0; - } - }else{ - if((bParamsAreFloats& B[hatch])!=0){ - if(defaultIn){ - iParamsIn[hatch] = ZERO_FLOAT; - iParamsIn[hatch + 10] = ZERO_FLOAT; - } - if(defaultOut){ - iParamsOut[hatch] = ZERO_FLOAT; - iParamsOut[hatch + 10] = ZERO_FLOAT; - } - }else{ - if(defaultIn){ - iParamsIn[hatch] = 0; - iParamsIn[hatch + 10] = 0; - } - if(defaultOut){ - iParamsOut[hatch] = 0; - iParamsOut[hatch + 10] = 0; - } - } - } + 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(){ - setToDefaults(true,true,false); parameterInArrayList.clear(); parameterOutArrayList.clear(); for(int i = 0; i< groups.length; i++){ @@ -93,72 +64,95 @@ public class Parameters { } } - public Group makeGroup(int hatchNo, boolean aParamsDefaultsAreFloats){ - return new Group( hatchNo, aParamsDefaultsAreFloats); + 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 boolean bParamsDefaultsAreStoredAsFloats; private final int hatchNo; final ParameterIn[] parameterIn =new ParameterIn[2]; final ParameterOut[] parameterOut =new ParameterOut[2]; + public boolean updateWhileRunning; - private Group(int hatchNo, boolean aParamsDefaultsAreFloats){ + private Group(int hatchNo, boolean updateWhileRunning){ if(hatchNo<0 || hatchNo>=10){ throw new IllegalArgumentException("ParameterGroup id must be in 0 to 9 range"); } this.hatchNo=hatchNo; - bParamsDefaultsAreStoredAsFloats =aParamsDefaultsAreFloats; + this.updateWhileRunning=updateWhileRunning; groups[hatchNo]=this; } - public ParameterIn makeInParameter(int paramID, double defaultValue, Function name, Function status){ + 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, Function name, Function 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,boolean defaultConfigureAreFloats) { - if(defaultConfigureAreFloats){ - if(bParamsDefaultsAreStoredAsFloats){ - bParamsAreFloats|= B[hatchNo]; - }else { - bParamsAreFloats&=~B[hatchNo]; - } - } + public void setToDefaults(boolean defaultIn, boolean defaultOut) { if(defaultIn){ - for(int in=0;in<2;in++){ - if(this.parameterIn[in]!=null){ - this.parameterIn[in].setDefault(); - }else { - if ((bParamsAreFloats& B[hatchNo])!=0) { - iParamsIn[hatchNo] = ZERO_FLOAT; - iParamsIn[hatchNo + 10] = ZERO_FLOAT; - } else { - iParamsIn[hatchNo] = 0; - iParamsIn[hatchNo + 10] = 0; - } - } + 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){ - for(int out=0;out<2;out++){ - if(this.parameterOut[out]!=null){ - this.parameterOut[out].setDefault(); - }else { - if ((bParamsAreFloats& B[hatchNo])!=0) { - iParamsIn[hatchNo] = ZERO_FLOAT; - iParamsIn[hatchNo + 10] = ZERO_FLOAT; - } else { - iParamsIn[hatchNo] = 0; - iParamsIn[hatchNo + 10] = 0; - } - } + 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; } } } @@ -166,48 +160,52 @@ public class Parameters { /** * Make a field out of this... */ - public class ParameterOut { + public class ParameterOut implements IParameter { public final int id; public final double defaultValue; - Function status; - Function name; + StatusFunction status; + NameFunction name; - @SuppressWarnings("unchecked") - private ParameterOut(int paramID, double defaultValue, Function name, Function status){ - this.name= name; - this.id=hatchNo+10*paramID; + 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"); } - this.defaultValue=defaultValue; if(parameterOut[paramID]!=null){ - throw new InstantiationError("This parameter already exists!"); + throw new IllegalArgumentException("Parameter id already occupied"); } - this.status = status; + this.id=hatchNo+10*paramID; + this.defaultValue=defaultValue; + this.status = status==null?LED_STATUS_FUNCTION_DEFAULT:status; parameterOutArrayList.add(this); parameterOut[paramID]=this; } - private void setDefault() { + void setDefault() { set(defaultValue); } + @Override public double get(){ - return (bParamsAreFloats& B[hatchNo])!=0?Float.intBitsToFloat(iParamsOut[id]):iParamsOut[id]; + return iParamsOut[id]; + } + + @Override + public double getDefault() { + return defaultValue; } public void set(double value){ - if((bParamsAreFloats& B[hatchNo])!=0) { - iParamsOut[id]=Float.floatToIntBits((float) value); - }else{ - iParamsOut[id]=(int)value; - } + iParamsOut[id]=value; } + @SuppressWarnings("unchecked") + @Override public void updateStatus(){ - eParamsOutStatus[id]=status.apply(parent); + eParamsOutStatus[id]=status.apply(parent,this); } + @Override public LedStatus getStatus(boolean update){ if(update){ updateStatus(); @@ -215,52 +213,76 @@ public class Parameters { return eParamsOutStatus[id]; } + @Override public String getBrief(){ - return name.apply(parent); + 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 { + public class ParameterIn implements IParameter { public final int id; public final double defaultValue; - Function status; - Function name; + StatusFunction status; + NameFunction name; - @SuppressWarnings("unchecked") - private ParameterIn(int paramID, double defaultValue, Function name, Function status){ - this.name= 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"); } - this.defaultValue=defaultValue; - if(parameterIn[paramID]!=null){ - throw new InstantiationError("This parameter already exists!"); + if(parameterOut[paramID]!=null){ + throw new IllegalArgumentException("Parameter id already occupied"); } - this.status = status; + this.defaultValue=defaultValue; + this.status = status==null?LED_STATUS_FUNCTION_DEFAULT:status; parameterInArrayList.add(this); parameterIn[paramID]=this; } - private void setDefault() { - if((bParamsAreFloats& B[hatchNo])!=0) { - iParamsIn[id]=Float.floatToIntBits((float) defaultValue); - }else{ - iParamsIn[id]=(int)defaultValue; - } + void setDefault() { + set(defaultValue); } + @Override public double get(){ - return (bParamsAreFloats& B[hatchNo])!=0?Float.intBitsToFloat(iParamsIn[id]):iParamsIn[id]; + 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); + eParamsInStatus[id]=status.apply(parent,this); } + @Override public LedStatus getStatus(boolean update){ if(update){ updateStatus(); @@ -268,8 +290,25 @@ public class Parameters { return eParamsInStatus[id]; } + @Override public String getBrief(){ - return name.apply(parent); + 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..224f0fc47c --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/StatusFunction.java @@ -0,0 +1,8 @@ +package com.github.technus.tectech.thing.metaTileEntity.multi.base; + +import java.util.function.BiFunction; + +public interface StatusFunction extends BiFunction { + @Override + 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 efbca82c8f..4551ef3b17 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,12 +4,11 @@ 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.*; import java.util.ArrayList; import java.util.Arrays; -import java.util.Comparator; +import java.util.function.BiFunction; import static com.github.technus.tectech.CommonValues.V; import static com.github.technus.tectech.loader.TecTechConfig.DEBUG_MODE; @@ -18,10 +17,22 @@ import static com.github.technus.tectech.thing.metaTileEntity.multi.base.LedStat /** * 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 float radius, maxRPM, maxRCF, maxForce, maxCapacity; + private Parameters.Group.ParameterIn settingRPM, settingFraction; + private final static NameFunction rpmName= (gt_metaTileEntity_em_machine, iParameter) -> "RPM Setting"; + private static final StatusFunction rpmStatus= (gt_metaTileEntity_em_machine, iParameter) -> { + double v=iParameter.get(); + if(Double.isNaN(v)){ + return STATUS_WRONG; + } + + }; + private final static NameFunction fractionName= (gt_metaTileEntity_em_machine, iParameter) -> "Fraction Count"; + private static final StatusFunction fractionStatus= (gt_metaTileEntity_em_machine, iParameter) -> { + + }; 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[][]{ @@ -46,13 +57,6 @@ public class Behaviour_Centrifuge extends GT_MetaTileEntity_EM_machine.Behaviour maxCapacity = maxSafeMass * 4f * radius;// eV/c^2 } - @Override - protected void getFullLedDescriptionIn(ArrayList baseDescr, int hatchNo, int paramID) { - if(hatchNo==0) { - baseDescr.add(DESCRIPTION_I[(hatchNo << 1) + paramID]); - } - } - @Override protected void getFullLedDescriptionOut(ArrayList baseDescr, int hatchNo, int paramID) { if(hatchNo<=2) { @@ -60,25 +64,38 @@ public class Behaviour_Centrifuge extends GT_MetaTileEntity_EM_machine.Behaviour } } - @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 + private double getRCF(double RPM) { + return RPM * RPM * radius * 0.001118; + } - for(int i=4;i<=9;i++) { - te.setStatusOfParameterOut(i, 0, STATUS_UNUSED); - te.setStatusOfParameterOut(i, 1, STATUS_UNUSED); + 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]); } - for(int i=1;i<=3;i++) { - te.setStatusOfParameterIn(i, 0, STATUS_UNUSED); - te.setStatusOfParameterIn(i, 1, STATUS_UNUSED); + 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; } + } - double RPM = parametersToCheckAndFix[0]; + @Override + public void parametersInstantiation(GT_MetaTileEntity_EM_machine te, Parameters parameters) { + Parameters.Group hatch1=parameters.getGroup(7); + settingRPM=hatch1.makeInParameter(0,0,,); + settingFraction=hatch1.makeInParameter(1,2,,); + } + + @Override + public boolean checkParametersInAndSetStatuses(GT_MetaTileEntity_EM_machine te, Parameters parameters) { + boolean check=true; + + double RPM = settingRPM.get(); if (RPM > maxRPM) { te.setStatusOfParameterIn(0, 0, STATUS_TOO_HIGH); te.setParameterOut(0, 0, maxRPM);//rpm @@ -107,7 +124,7 @@ public class Behaviour_Centrifuge extends GT_MetaTileEntity_EM_machine.Behaviour te.setParameterOut(0, 1, getRCF(RPM)); } - double fractionCount = parametersToCheckAndFix[1]; + double fractionCount = settingFraction.get(); if (fractionCount > 6) { parametersToCheckAndFix[1] = 6; te.setStatusOfParameterIn(0, 1, STATUS_TOO_HIGH); @@ -130,7 +147,7 @@ public class Behaviour_Centrifuge extends GT_MetaTileEntity_EM_machine.Behaviour } @Override - public MultiblockControl process(cElementalInstanceStackMap[] inputs, double[] checkedAndFixedParameters) { + public MultiblockControl 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 @@ -181,15 +198,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() { - @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" @@ -258,24 +272,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 process(cElementalInstanceStackMap[] inputs, double[] checkedAndFixedParameters) { + public MultiblockControl 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 94f00ece1b..e8b0ac7401 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 @@ -15,7 +15,7 @@ import static com.github.technus.tectech.thing.metaTileEntity.multi.base.LedStat /** * 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; @@ -102,16 +102,6 @@ public class Behaviour_ElectromagneticSeparator extends GT_MetaTileEntity_EM_mac te.setParameterOut(3,0,V[tier]); te.setParameterOut(3,1,ticks); - for(int i=4;i<=9;i++) { - te.setStatusOfParameterOut(i, 0, STATUS_UNUSED); - te.setStatusOfParameterOut(i, 1, STATUS_UNUSED); - } - te.setStatusOfParameterIn(1, 1, STATUS_UNUSED); - for(int i=2;i<=3;i++) { - te.setStatusOfParameterIn(i, 0, STATUS_UNUSED); - te.setStatusOfParameterIn(i, 1, STATUS_UNUSED); - } - double full=parametersToCheckAndFix[0]; if(Double.isInfinite(full) && full>0) { te.setStatusOfParameterIn(0,0,STATUS_TOO_HIGH); 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 process(cElementalInstanceStackMap[] inputs, double[] checkedAndFixedParameters) { + public MultiblockControl 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 process(cElementalInstanceStackMap[] inputs, double[] checkedAndFixedParameters) { + public MultiblockControl 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 process(cElementalInstanceStackMap[] inputs, double[] checkedAndFixedParameters) { + public MultiblockControl 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 9c45b5df67..1ef3705b50 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,21 +7,25 @@ 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; @@ -34,6 +38,7 @@ import static com.github.technus.tectech.thing.metaTileEntity.multi.base.LedStat 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 @@ -47,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}; @@ -57,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=new Parameters.Group.ParameterIn[6]; + protected Parameters.Group.ParameterIn[] outputMux=new Parameters.Group.ParameterIn[6]; + private static final StatusFunction 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 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 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 +100,31 @@ public class GT_MetaTileEntity_EM_machine extends GT_MetaTileEntity_MultiblockBa super(aName); } + @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() { + 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); @@ -92,6 +152,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()); } @@ -100,7 +161,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(); @@ -110,28 +173,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); @@ -140,48 +181,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++) { @@ -194,7 +208,7 @@ public class GT_MetaTileEntity_EM_machine extends GT_MetaTileEntity_MultiblockBa } } - MultiblockControl control = currentBehaviour.process(handles, parameters); + MultiblockControl control = currentBehaviour.process(handles,this, parametrization); if (control == null) { return false; } @@ -223,33 +237,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++) { @@ -269,159 +266,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, STATUS_WRONG); - } else if (pointer <= 0) { - setStatusOfParameterIn(i, 0, STATUS_TOO_LOW); - }//else if(pointer==0) - // setStatusOfParameterIn(i,0,STATUS_LOW); - else if (pointer <= eInputHatches.size()) { - if (checkArray.get(pointer)) { - setStatusOfParameterIn(i, 0, STATUS_WRONG); - } else { - setStatusOfParameterIn(i, 0, STATUS_OK); - checkArray.set(pointer); - } - } else { - setStatusOfParameterIn(i, 0, STATUS_TOO_HIGH); - } - pointer = getParameterInInt(i, 1); - if (Double.isNaN(pointer)) { - setStatusOfParameterIn(i, 1, STATUS_WRONG); - } else if (pointer < 0) { - setStatusOfParameterIn(i, 1, STATUS_TOO_LOW); - } else if (pointer == 0) { - setStatusOfParameterIn(i, 1, STATUS_LOW); - } else if (pointer <= eInputHatches.size()) { - if (checkArray.get(pointer)) { - setStatusOfParameterIn(i, 1, STATUS_WRONG); - } else { - setStatusOfParameterIn(i, 1, STATUS_OK); - checkArray.set(pointer); - } - } else { - setStatusOfParameterIn(i, 1, 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, STATUS_WRONG); - } else if (pointer < 0) { - setStatusOfParameterIn(i, 0, STATUS_TOO_LOW); - } else if (pointer == 0) { - setStatusOfParameterIn(i, 0, STATUS_LOW); - } else if (pointer <= eOutputHatches.size()) { - setStatusOfParameterIn(i, 0, STATUS_OK); - } else { - setStatusOfParameterIn(i, 0, STATUS_TOO_HIGH); - } - pointer = getParameterInInt(i, 1); - if (Double.isNaN(pointer)) { - setStatusOfParameterIn(i, 1, STATUS_WRONG); - } else if (pointer < 0) { - setStatusOfParameterIn(i, 1, STATUS_TOO_LOW); - } else if (pointer == 0) { - setStatusOfParameterIn(i, 1, STATUS_LOW); - } else if (pointer <= eOutputHatches.size()) { - setStatusOfParameterIn(i, 1, STATUS_OK); - } else { - setStatusOfParameterIn(i, 1, STATUS_TOO_HIGH); - } + loadedMachine=newMachine; + Supplier 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 map = new HashMap<>(); + private static final HashMap> 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, 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 final void setOnMachine(GT_MetaTileEntity_EM_machine te){ - te.parametrization.clearGroups(); - parametersInstantiation(te.parametrization); - } - - public abstract void parametersInstantiation(Parameters parameters); + 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 process(cElementalInstanceStackMap[] inputs, double[] checkedAndFixedParameters); - } - - @Override - public ArrayList getFullLedDescriptionIn(int hatchNo, int paramID) { - ArrayList 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 getFullLedDescriptionOut(int hatchNo, int paramID) { - ArrayList base=super.getFullLedDescriptionOut(hatchNo, paramID); - if(currentBehaviour!=null){ - currentBehaviour.getFullLedDescriptionOut(base,hatchNo,paramID); - } - return base; + MultiblockControl 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> RENDER_REGISTRY =new HashMap<>(); + private static final HashMap> 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 renders=getRenders(new Util.TT_ItemStack(input)); + ArrayList 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 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 getRenders(Util.TT_ItemStack stack){ + public static ArrayList 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 renders = GT_MetaTileEntity_DataReader.getRenders(new Util.TT_ItemStack(thing)); + ArrayList 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 renders = GT_MetaTileEntity_DataReader.getRenders(new Util.TT_ItemStack(stack)); + ArrayList 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 renders = GT_MetaTileEntity_DataReader.getRenders(new Util.TT_ItemStack(stack)); + ArrayList 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); -- cgit