diff options
| author | Technus <daniel112092@gmail.com> | 2017-04-09 12:52:34 +0200 |
|---|---|---|
| committer | Technus <daniel112092@gmail.com> | 2017-04-09 12:52:34 +0200 |
| commit | b410c1cba1311addfcd52c7bc80b020f1a529699 (patch) | |
| tree | 56198c670a93ba43006e2cc1c6c8818016c30791 | |
| parent | 0f6ef8576dfd03b17b569be495f7944fd021356b (diff) | |
| download | GT5-Unofficial-b410c1cba1311addfcd52c7bc80b020f1a529699.tar.gz GT5-Unofficial-b410c1cba1311addfcd52c7bc80b020f1a529699.tar.bz2 GT5-Unofficial-b410c1cba1311addfcd52c7bc80b020f1a529699.zip | |
Computers coded, some reworks.
21 files changed, 355 insertions, 247 deletions
diff --git a/src/main/java/com/github/technus/tectech/CommonValues.java b/src/main/java/com/github/technus/tectech/CommonValues.java index 66ce2cde3d..7293c351d2 100644 --- a/src/main/java/com/github/technus/tectech/CommonValues.java +++ b/src/main/java/com/github/technus/tectech/CommonValues.java @@ -10,7 +10,7 @@ public final class CommonValues { EnumChatFormatting.BLUE + "Tec" + EnumChatFormatting.DARK_BLUE + "Tech" + EnumChatFormatting.BLUE + ": Elemental Matter"; - public final static byte decayAt = 0;// hatches compute dacays + public final static byte decayAt = 0;// hatches compute decays public final static byte multiPurge1At = 2;// multiblocks clean their hatches 1 public final static byte moveAt = 4;// move stuff around public final static byte recipeAt = 6;// move stuff around diff --git a/src/main/java/com/github/technus/tectech/TecTech.java b/src/main/java/com/github/technus/tectech/TecTech.java index a903ca21dd..0e6088832c 100644 --- a/src/main/java/com/github/technus/tectech/TecTech.java +++ b/src/main/java/com/github/technus/tectech/TecTech.java @@ -2,7 +2,7 @@ package com.github.technus.tectech; import com.github.technus.tectech.auxiliary.Reference; import com.github.technus.tectech.auxiliary.TecTechConfig; -import com.github.technus.tectech.loader.Main; +import com.github.technus.tectech.loader.MainLoader; import com.github.technus.tectech.proxy.CommonProxy; import com.github.technus.tectech.thing.block.QuantumGlass; import com.github.technus.tectech.thing.casing.GT_Container_CasingsTT; @@ -46,7 +46,7 @@ public class TecTech { public static LogHelper Logger = new LogHelper(Reference.MODID); private static IngameErrorLog Module_AdminErrorLogs = null; - public static Main GTCustomLoader = null; + public static MainLoader GTCustomLoader = null; public static TecTechConfig ModConfig; public static XSTR Rnd = null; public static CreativeTabs mainTab = null; @@ -84,13 +84,9 @@ public class TecTech { public void PostLoad(FMLPostInitializationEvent PostEvent) { hasCOFH=Loader.isModLoaded(Reference.COFHCORE); - QuantumGlass.run(); - DebugContainer_EM.run(); - DebugBuilder.run(); - - GTCustomLoader = new Main(); - GTCustomLoader.run(); - GTCustomLoader.run2(); + GTCustomLoader = new MainLoader(); + GTCustomLoader.things(); + GTCustomLoader.recipes(); mainTab = new CreativeTabs("TecTech") { @SideOnly(Side.CLIENT) @@ -110,7 +106,7 @@ public class TecTech { } }; - RegisterThingsInTabs(); + GTCustomLoader.registerThingsInTabs(); if (Loader.isModLoaded("dreamcraft")) ;//TODO init recipes for GTNH version else ;//TODO init recipes for NON-GTNH version @@ -119,18 +115,11 @@ public class TecTech { @EventHandler public void serverLoad(FMLServerStartingEvent pEvent) { if(!oneTimeFix) { - if (ModConfig.NERF_FUSION) FixBrokenFusionRecipes(); oneTimeFix=true; + if (ModConfig.NERF_FUSION) FixBrokenFusionRecipes(); } } - private void RegisterThingsInTabs() { - QuantumGlass.INSTANCE.setCreativeTab(mainTab); - GT_Container_CasingsTT.sBlockCasingsTT.setCreativeTab(mainTab); - DebugContainer_EM.INSTANCE.setCreativeTab(mainTab); - DebugBuilder.INSTANCE.setCreativeTab(mainTab); - } - private void FixBrokenFusionRecipes(){ HashMap<Fluid,Fluid> binds=new HashMap<>(); for(Materials m:Materials.values()){ diff --git a/src/main/java/com/github/technus/tectech/dataFramework/quantumDataPacket.java b/src/main/java/com/github/technus/tectech/dataFramework/quantumDataPacket.java index aeb3314d06..7b14a8535e 100644 --- a/src/main/java/com/github/technus/tectech/dataFramework/quantumDataPacket.java +++ b/src/main/java/com/github/technus/tectech/dataFramework/quantumDataPacket.java @@ -1,6 +1,7 @@ package com.github.technus.tectech.dataFramework; import com.github.technus.tectech.vec3pos; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.nbt.NBTTagCompound; import java.util.TreeSet; @@ -14,10 +15,6 @@ public class quantumDataPacket { public long computation=0; public TreeSet<vec3pos> trace=new TreeSet<>(); - public quantumDataPacket(long comp){ - computation=comp; - } - public quantumDataPacket(vec3pos pos,long computation){ this.computation=computation; trace.add(pos); @@ -28,11 +25,6 @@ public class quantumDataPacket { trace.addAll(q.trace); } - public quantumDataPacket(quantumDataPacket q){ - this.computation=q.computation; - trace.addAll(q.trace); - } - public quantumDataPacket(NBTTagCompound nbt){ computation=nbt.getLong("qComputation"); for(int i=0;i<nbt.getByte("qHistory");i++){ @@ -77,7 +69,7 @@ public class quantumDataPacket { return check()?this:null; } - public long computationIfNotConatined(vec3pos pos){ + public long computationIfNotContained(vec3pos pos){ if(trace.contains(pos))return 0; return computation; } diff --git a/src/main/java/com/github/technus/tectech/loader/CasingLoader.java b/src/main/java/com/github/technus/tectech/loader/CasingLoader.java new file mode 100644 index 0000000000..26ed2e554b --- /dev/null +++ b/src/main/java/com/github/technus/tectech/loader/CasingLoader.java @@ -0,0 +1,13 @@ +package com.github.technus.tectech.loader; + +import com.github.technus.tectech.thing.casing.GT_Block_CasingsTT; +import com.github.technus.tectech.thing.casing.GT_Container_CasingsTT; + +/** + * Created by danie_000 on 03.10.2016. + */ +public class CasingLoader implements Runnable { + public void run() { + GT_Container_CasingsTT.sBlockCasingsTT = new GT_Block_CasingsTT(); + } +} diff --git a/src/main/java/com/github/technus/tectech/loader/Machines.java b/src/main/java/com/github/technus/tectech/loader/MachineLoader.java index ff262ba4b7..800f5cd332 100644 --- a/src/main/java/com/github/technus/tectech/loader/Machines.java +++ b/src/main/java/com/github/technus/tectech/loader/MachineLoader.java @@ -11,7 +11,7 @@ import static com.github.technus.tectech.thing.CustomItemList.*; /** * Created by danie_000 on 16.11.2016. */ -public class Machines implements Runnable { +public class MachineLoader implements Runnable { public void run() {//TODO add config for starting position // =================================================================================================== // eM IN diff --git a/src/main/java/com/github/technus/tectech/loader/Main.java b/src/main/java/com/github/technus/tectech/loader/Main.java deleted file mode 100644 index 6a88c06176..0000000000 --- a/src/main/java/com/github/technus/tectech/loader/Main.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.technus.tectech.loader; - -import com.github.technus.tectech.TecTech; -import com.github.technus.tectech.thing.casing.GT_Loader_CasingsTT; - -public class Main { - private Machines ElementalLoader; - private GT_Loader_CasingsTT ElementalCasing; - private Recipes ElementalRecipes; - - public Main() { - } - - public void run() { - ElementalCasing = new GT_Loader_CasingsTT(); - ElementalCasing.run(); - TecTech.Logger.info("Casing Init Done"); - ElementalLoader = new Machines(); - ElementalLoader.run(); - TecTech.Logger.info("Machine Init Done"); - } - - public void run2() { - ElementalRecipes = new Recipes(); - ElementalRecipes.run(); - TecTech.Logger.info("Recipe Init Done"); - } -} diff --git a/src/main/java/com/github/technus/tectech/loader/MainLoader.java b/src/main/java/com/github/technus/tectech/loader/MainLoader.java new file mode 100644 index 0000000000..e3000759b3 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/loader/MainLoader.java @@ -0,0 +1,43 @@ +package com.github.technus.tectech.loader; + +import com.github.technus.tectech.TecTech; +import com.github.technus.tectech.thing.block.QuantumGlass; +import com.github.technus.tectech.thing.casing.GT_Container_CasingsTT; +import com.github.technus.tectech.thing.item.DebugBuilder; +import com.github.technus.tectech.thing.item.DebugContainer_EM; + +import static com.github.technus.tectech.TecTech.mainTab; + +public class MainLoader { + private MachineLoader machineLoader; + private CasingLoader casingLoader; + private RecipeLoader recipeLoader; + private ThingsLoader thingsLoader; + + public MainLoader() {} + + public void things() { + casingLoader = new CasingLoader(); + casingLoader.run(); + TecTech.Logger.info("Casing Init Done"); + machineLoader = new MachineLoader(); + machineLoader.run(); + TecTech.Logger.info("Machine Init Done"); + thingsLoader = new ThingsLoader(); + thingsLoader.run(); + TecTech.Logger.info("Other things Init Done"); + } + + public void recipes() { + recipeLoader = new RecipeLoader(); + recipeLoader.run(); + TecTech.Logger.info("Recipe Init Done"); + } + + public void registerThingsInTabs(){ + QuantumGlass.INSTANCE.setCreativeTab(mainTab); + GT_Container_CasingsTT.sBlockCasingsTT.setCreativeTab(mainTab); + DebugContainer_EM.INSTANCE.setCreativeTab(mainTab); + DebugBuilder.INSTANCE.setCreativeTab(mainTab); + } +} diff --git a/src/main/java/com/github/technus/tectech/loader/Recipes.java b/src/main/java/com/github/technus/tectech/loader/RecipeLoader.java index 30424076cd..8e97115c01 100644 --- a/src/main/java/com/github/technus/tectech/loader/Recipes.java +++ b/src/main/java/com/github/technus/tectech/loader/RecipeLoader.java @@ -10,7 +10,7 @@ import com.github.technus.tectech.thing.metaTileEntity.multi.GT_MetaTileEntity_M /** * Created by danie_000 on 16.11.2016. */ -public class Recipes implements Runnable { +public class RecipeLoader implements Runnable { public void run() { // =================================================================================================== // def init diff --git a/src/main/java/com/github/technus/tectech/loader/ThingsLoader.java b/src/main/java/com/github/technus/tectech/loader/ThingsLoader.java new file mode 100644 index 0000000000..d08fbba709 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/loader/ThingsLoader.java @@ -0,0 +1,23 @@ +package com.github.technus.tectech.loader; + +import com.github.technus.tectech.TecTech; +import com.github.technus.tectech.elementalMatter.classes.cElementalPrimitive; +import com.github.technus.tectech.elementalMatter.definitions.*; +import com.github.technus.tectech.thing.block.QuantumGlass; +import com.github.technus.tectech.thing.item.DebugBuilder; +import com.github.technus.tectech.thing.item.DebugContainer_EM; +import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_Rack; +import com.github.technus.tectech.thing.metaTileEntity.multi.GT_MetaTileEntity_EM_computer; +import com.github.technus.tectech.thing.metaTileEntity.multi.GT_MetaTileEntity_EM_quantizer; +import com.github.technus.tectech.thing.metaTileEntity.multi.GT_MetaTileEntity_MultiblockBase_EM; + +/** + * Created by danie_000 on 16.11.2016. + */ +public class ThingsLoader implements Runnable { + public void run() { + QuantumGlass.run(); + DebugContainer_EM.run(); + DebugBuilder.run(); + } +} diff --git a/src/main/java/com/github/technus/tectech/thing/casing/GT_Loader_CasingsTT.java b/src/main/java/com/github/technus/tectech/thing/casing/GT_Loader_CasingsTT.java deleted file mode 100644 index 2e7ef20b27..0000000000 --- a/src/main/java/com/github/technus/tectech/thing/casing/GT_Loader_CasingsTT.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.technus.tectech.thing.casing; - -/** - * Created by danie_000 on 03.10.2016. - */ -public class GT_Loader_CasingsTT implements Runnable { - public void run() { - GT_Container_CasingsTT.sBlockCasingsTT = new GT_Block_CasingsTT(); - } -} diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_DataConnector.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_DataConnector.java index f0f2c30088..8f34e15e1e 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_DataConnector.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_DataConnector.java @@ -62,14 +62,16 @@ public abstract class GT_MetaTileEntity_Hatch_DataConnector extends GT_MetaTileE public void saveNBTData(NBTTagCompound aNBT) { super.saveNBTData(aNBT); aNBT.setShort("eID", id); - aNBT.setTag("eDATA",q.toNbt()); + if(q!=null) + aNBT.setTag("eDATA",q.toNbt()); } @Override public void loadNBTData(NBTTagCompound aNBT) { super.loadNBTData(aNBT); id = aNBT.getShort("eID"); - q=new quantumDataPacket(aNBT.getCompoundTag("eDATA")); + if(aNBT.hasKey("eDATA")) + q=new quantumDataPacket(aNBT.getCompoundTag("eDATA")); } @Override diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_OutputData.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_OutputData.java index 5249c78678..7288d182c4 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_OutputData.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_OutputData.java @@ -52,9 +52,8 @@ public class GT_MetaTileEntity_Hatch_OutputData extends GT_MetaTileEntity_Hatch_ while((next=current.getNext(source))!=null && range++<1000){ if(next instanceof GT_MetaTileEntity_Hatch_InputData){ ((GT_MetaTileEntity_Hatch_InputData) next).q=q; - ((GT_MetaTileEntity_Hatch_InputData) next).delDelay =true; - q=null; - return; + ((GT_MetaTileEntity_Hatch_InputData) next).delDelay=true; + break; } source=current; current=next; } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Rack.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Rack.java index e606374792..ddd68639e4 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Rack.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Rack.java @@ -1,7 +1,10 @@ package com.github.technus.tectech.thing.metaTileEntity.hatch; import com.github.technus.tectech.CommonValues; +import com.github.technus.tectech.TecTech; import com.github.technus.tectech.thing.machineTT; +import com.github.technus.tectech.thing.metaTileEntity.hatch.gui.GT_Container_Rack; +import com.github.technus.tectech.thing.metaTileEntity.hatch.gui.GT_GUIContainer_Rack; import gregtech.api.enums.ItemList; import gregtech.api.enums.Textures; import gregtech.api.gui.GT_Container_2by2; @@ -30,7 +33,7 @@ public class GT_MetaTileEntity_Hatch_Rack extends GT_MetaTileEntity_Hatch implem private static Textures.BlockIcons.CustomIcon EM_R; private static Textures.BlockIcons.CustomIcon EM_R_ACTIVE; public int heat=0; - private float overclock=1; + private float overClock =1, overVolt =1; private static TreeMap<String,component> componentBinds=new TreeMap<>(); public GT_MetaTileEntity_Hatch_Rack(int aID, String aName, String aNameRegional, int aTier, String descr) { @@ -45,14 +48,16 @@ public class GT_MetaTileEntity_Hatch_Rack extends GT_MetaTileEntity_Hatch implem public void saveNBTData(NBTTagCompound aNBT) { super.saveNBTData(aNBT); aNBT.setInteger("eHeat",heat); - aNBT.setFloat("eOverclock",overclock); + aNBT.setFloat("eOverClock", overClock); + aNBT.setFloat("eOverVolt", overVolt); } @Override public void loadNBTData(NBTTagCompound aNBT) { super.loadNBTData(aNBT); heat=aNBT.getInteger("eHeat"); - overclock=aNBT.getFloat("eOverclock"); + overClock =aNBT.getFloat("eOverClock"); + overVolt =aNBT.getFloat("eOverVolt"); } @Override @@ -111,12 +116,12 @@ public class GT_MetaTileEntity_Hatch_Rack extends GT_MetaTileEntity_Hatch implem @Override public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_2by2(aPlayerInventory, aBaseMetaTileEntity); + return new GT_Container_Rack(aPlayerInventory, aBaseMetaTileEntity); } @Override public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_2by2(aPlayerInventory, aBaseMetaTileEntity, "Computer Rack"); + return new GT_GUIContainer_Rack(aPlayerInventory, aBaseMetaTileEntity, "Computer Rack"); } @Override @@ -132,26 +137,29 @@ public class GT_MetaTileEntity_Hatch_Rack extends GT_MetaTileEntity_Hatch implem } //TODO implement: glitches with OC, random component burning with OC - private int getComputationPower(float overclock,boolean heatProcess){ + private int getComputationPower(float overclock, float overvolt, boolean tickingComponents){ float computation=0,heat=0; - for(ItemStack is:mInventory){ - if(is==null || is.stackSize!=1) continue; - component comp=componentBinds.get(is.getUnlocalizedName()); + for(int i=0;i<mInventory.length;i++){ + if(mInventory[i]==null || mInventory[i].stackSize!=1) continue; + component comp=componentBinds.get(mInventory[i].getUnlocalizedName()); if(comp==null) continue; - if(heatProcess){ - if(this.heat>comp.maxHeat){ - is.stackSize=0; + if(tickingComponents) { + if (this.heat > comp.maxHeat) { + mInventory[i] = null; continue; - } - if(comp.subZero || this.heat>=0) - heat+=comp.heat>0?comp.heat*overclock*overclock:comp.heat; + } else if (comp.subZero || this.heat > 0) + heat += comp.heat > 0 ? comp.heat * overclock * overclock * overvolt: comp.heat; + //=MAX(0;MIN(MIN($B4;1*C$3+C$3-0,25);1+RAND()+(C$3-1)-($B4-1)/2)) + if(overvolt*10f>7f+TecTech.Rnd.nextFloat()) + computation+=comp.computation*Math.max(0,Math.min(Math.min(overclock,overvolt+overvolt-0.25),1+TecTech.Rnd.nextFloat()+(overvolt-1)-(overclock-1)/2)); + }else{ + computation+=comp.computation*overclock; } - computation+=comp.computation; } - if(heatProcess){ + if(tickingComponents) { this.heat+=Math.ceil(heat); } - return (int)Math.ceil(computation*overclock); + return (int)Math.floor(computation); } @Override @@ -159,10 +167,10 @@ public class GT_MetaTileEntity_Hatch_Rack extends GT_MetaTileEntity_Hatch implem return 1; } - public int tickComponents(float oc) { - overclock=oc; - if(overclock>10) getBaseMetaTileEntity().setToFire(); - return getComputationPower(overclock,true); + public int tickComponents(float oc,float ov) { + if(oc>3+TecTech.Rnd.nextFloat() || ov>2+TecTech.Rnd.nextFloat()) getBaseMetaTileEntity().setToFire(); + overClock =oc; overVolt =ov; + return getComputationPower(overClock, overVolt,true); } @Override @@ -203,8 +211,8 @@ public class GT_MetaTileEntity_Hatch_Rack extends GT_MetaTileEntity_Hatch implem @Override public String[] getInfoData() { return new String[]{ - "Base computation: "+ EnumChatFormatting.AQUA +getComputationPower(1,false), - "After overclocking: "+ EnumChatFormatting.AQUA +getComputationPower(overclock,false), + "Base computation: "+ EnumChatFormatting.AQUA +getComputationPower(1,0,false), + "After overclocking: "+ EnumChatFormatting.AQUA +getComputationPower(overClock,0,false), "Heat Accumulated: "+ EnumChatFormatting.RED + ((heat+99)/100) +EnumChatFormatting.RESET+" %"}; //heat==0? --> ((heat+9)/10) = 0 //Heat==1-10? --> 1 @@ -228,6 +236,7 @@ public class GT_MetaTileEntity_Hatch_Rack extends GT_MetaTileEntity_Hatch implem this.maxHeat=maxHeat; this.subZero=subZero; componentBinds.put(unlocalizedName,this); + if(TecTech.ModConfig.DEBUG_MODE) TecTech.Logger.info("Component registered: "+unlocalizedName); } @Override diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Uncertainty.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Uncertainty.java index 9db22ab1a4..042b2cf49d 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Uncertainty.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Uncertainty.java @@ -26,9 +26,8 @@ import net.minecraftforge.fluids.FluidStack; public class GT_MetaTileEntity_Hatch_Uncertainty extends GT_MetaTileEntity_Hatch implements machineTT { private static Textures.BlockIcons.CustomIcon ScreenON; private static Textures.BlockIcons.CustomIcon ScreenOFF; - private static float errorMargin = 0.05f; public short[] matrix = new short[]{500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500}; - public byte selection = -1, mode = 0, status = -128; + public byte selection = -1, mode = 0, status = -128;//all 8 bits set public GT_MetaTileEntity_Hatch_Uncertainty(int aID, String aName, String aNameRegional, int aTier) { super(aID, aName, aNameRegional, aTier, 0, "Feeling certain, or not?"); @@ -71,10 +70,15 @@ public class GT_MetaTileEntity_Hatch_Uncertainty extends GT_MetaTileEntity_Hatch @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { if (aBaseMetaTileEntity.isServerSide() && (aTick & 15) == 0) { - shift(); - compute(); - if (mode == 0) aBaseMetaTileEntity.setActive(false); - else aBaseMetaTileEntity.setActive(true); + if (mode == 0) { + aBaseMetaTileEntity.setActive(false); + status=-128; + } + else { + aBaseMetaTileEntity.setActive(true); + shift(); + compute(); + } } } @@ -172,17 +176,12 @@ public class GT_MetaTileEntity_Hatch_Uncertainty extends GT_MetaTileEntity_Hatch }; } - private float massOffset(int sideLenY, int sideLenX, short... masses) { - int mass = 0; - int massI = 0, massJ = 0; - for (int i = 0; i < sideLenY; i++) { - for (int j = 0; j < sideLenY * sideLenX; j += sideLenY) { - mass += masses[i + j]; - massI += ((float) i - ((float) sideLenY / 2f) + .5f) * masses[i + j]; - massJ += ((float) (j / sideLenY) - ((float) sideLenX / 2f) + .5f) * masses[i + j]; - } + private boolean balanceCheck(int sideLenY, short... masses) { + float inequality = 0; + for (int i = 0; i < masses.length>>1; i++) { + inequality += Math.abs(masses[i]-masses[masses.length-i-1]); } - return ((Math.abs(massI / (float) mass) / (float) sideLenY) + (Math.abs(massJ / (float) mass)) / (float) sideLenX); + return inequality < (masses.length<<7); } public void regenerate() { @@ -194,92 +193,80 @@ public class GT_MetaTileEntity_Hatch_Uncertainty extends GT_MetaTileEntity_Hatch int result = 0; switch (mode) { case 1://ooo oxo ooo - result = (massOffset(4, 4, matrix) < errorMargin) ? 0 : 1; + result = balanceCheck(4, matrix) ? 0 : 1; break; case 2://ooo xox ooo - result += (massOffset(4, 2, + result += balanceCheck(4, matrix[0], matrix[4], matrix[1], matrix[5], matrix[2], matrix[6], - matrix[3], matrix[7]) < errorMargin) ? 0 : 1; - result += (massOffset(4, 2, + matrix[3], matrix[7]) ? 0 : 1; + result += balanceCheck(4, matrix[8], matrix[12], matrix[9], matrix[13], matrix[10], matrix[14], - matrix[11], matrix[15]) < errorMargin) ? 0 : 2; + matrix[11], matrix[15]) ? 0 : 2; break; case 3://oxo xox oxo - result += (massOffset(2, 4, + result += balanceCheck(2, matrix[0], matrix[4], matrix[8], matrix[12], - matrix[1], matrix[5], matrix[9], matrix[13]) < errorMargin) ? 0 : 1; - result += (massOffset(4, 2, + matrix[1], matrix[5], matrix[9], matrix[13]) ? 0 : 1; + result += balanceCheck(4, matrix[0], matrix[4], matrix[1], matrix[5], matrix[2], matrix[6], - matrix[3], matrix[7]) < errorMargin) ? 0 : 2; - result += (massOffset(4, 2, + matrix[3], matrix[7]) ? 0 : 2; + result += balanceCheck(4, matrix[8], matrix[12], matrix[9], matrix[13], matrix[10], matrix[14], - matrix[11], matrix[15]) < errorMargin) ? 0 : 4; - result += (massOffset(2, 4, + matrix[11], matrix[15]) ? 0 : 4; + result += balanceCheck(2, matrix[2], matrix[6], matrix[10], matrix[14], - matrix[3], matrix[7], matrix[11], matrix[15]) < errorMargin) ? 0 : 8; + matrix[3], matrix[7], matrix[11], matrix[15]) ? 0 : 8; break; case 4://xox ooo xox - result += (massOffset(2, 2, + result += balanceCheck(2, matrix[0], matrix[4], - matrix[1], matrix[5]) < errorMargin) ? 0 : 1; - result += (massOffset(2, 2, + matrix[1], matrix[5]) ? 0 : 1; + result += balanceCheck(2, matrix[8], matrix[12], - matrix[9], matrix[13]) < errorMargin) ? 0 : 2; - result += (massOffset(2, 2, + matrix[9], matrix[13]) ? 0 : 2; + result += balanceCheck(2, matrix[2], matrix[6], - matrix[3], matrix[7]) < errorMargin) ? 0 : 4; - result += (massOffset(2, 2, + matrix[3], matrix[7]) ? 0 : 4; + result += balanceCheck(2, matrix[10], matrix[14], - matrix[11], matrix[15]) < errorMargin) ? 0 : 8; + matrix[11], matrix[15]) ? 0 : 8; break; case 5://xox oxo xox - result += (massOffset(2, 2, + result += balanceCheck(2, matrix[0], matrix[4], - matrix[1], matrix[5]) < errorMargin) ? 0 : 1; - result += (massOffset(2, 2, + matrix[1], matrix[5]) ? 0 : 1; + result += balanceCheck(2, matrix[8], matrix[12], - matrix[9], matrix[13]) < errorMargin) ? 0 : 2; - result += (massOffset(4, 4, matrix) < errorMargin) ? 0 : 4; - result += (massOffset(2, 2, + matrix[9], matrix[13]) ? 0 : 2; + result += balanceCheck(4, matrix) ? 0 : 4; + result += balanceCheck(2, matrix[2], matrix[6], - matrix[3], matrix[7]) < errorMargin) ? 0 : 8; - result += (massOffset(2, 2, + matrix[3], matrix[7]) ? 0 : 8; + result += balanceCheck(2, matrix[10], matrix[14], - matrix[11], matrix[15]) < errorMargin) ? 0 : 16; + matrix[11], matrix[15]) ? 0 : 16; break; } return status = (byte) result; } private void shift() {//TODO MAKE IT MORE EVIL - final int i = TecTech.Rnd.nextInt(16), j = TecTech.Rnd.nextInt(2); - matrix[i] += (((matrix[i] & 1) == 0) ? 2 : -2) * j; - switch (matrix[i]) { - case 1002: - matrix[i] -= 3; - break; - case 1001: - matrix[i] -= 1; - break; - case -1: - matrix[i] += 1; - break; - case -2: - matrix[i] += 3; - break; - } + final int i = TecTech.Rnd.nextInt(16); + matrix[i] += (((matrix[i] & 1) == 0) ? 2 : -2) * TecTech.Rnd.nextInt(5); + if(matrix[i]<0) matrix[i]=0; + else if (matrix[i]>1000) matrix[i]=999; } public byte update(int newMode) { - if (newMode == mode) return mode; + if (newMode == mode) return status; if |
