From 73bd4c1cc06267ff3574230e5076c654ea300429 Mon Sep 17 00:00:00 2001 From: Technus Date: Tue, 21 Mar 2017 11:00:59 +0100 Subject: Initial work on computation multiblocks, implementing cables and I/O's --- .../java/com/github/technus/tectech/TecTech.java | 2 +- .../technus/tectech/loader/GT_Loader_Machines.java | 18 +- .../technus/tectech/thing/CustomItemList.java | 4 +- ...GT_MetaTileEntity_Hatch_ElementalContainer.java | 249 ---- .../GT_MetaTileEntity_MultiblockBase_EM.java | 1410 ------------------- .../GT_MetaTileEntity_Hatch_DataConnector.java | 152 +++ ...GT_MetaTileEntity_Hatch_ElementalContainer.java | 246 ++++ .../hatch/GT_MetaTileEntity_Hatch_InputData.java | 43 + .../GT_MetaTileEntity_Hatch_InputElemental.java | 1 - .../hatch/GT_MetaTileEntity_Hatch_OutputData.java | 71 + .../GT_MetaTileEntity_Hatch_OutputElemental.java | 1 - .../multi/GT_MetaTileEntity_EM_bhg.java | 1 - .../multi/GT_MetaTileEntity_EM_collider.java | 1 - .../multi/GT_MetaTileEntity_EM_computer.java | 1 - .../multi/GT_MetaTileEntity_EM_crafter.java | 1 - .../multi/GT_MetaTileEntity_EM_dequantizer.java | 1 - .../multi/GT_MetaTileEntity_EM_infuser.java | 30 +- .../multi/GT_MetaTileEntity_EM_junction.java | 1 - .../multi/GT_MetaTileEntity_EM_machine.java | 1 - .../multi/GT_MetaTileEntity_EM_quantizer.java | 1 - .../multi/GT_MetaTileEntity_EM_scanner.java | 1 - .../multi/GT_MetaTileEntity_EM_stabilizer.java | 1 - .../multi/GT_MetaTileEntity_EM_transformer.java | 1 - .../multi/GT_MetaTileEntity_EM_wormhole.java | 1 - .../multi/GT_MetaTileEntity_MultiblockBase_EM.java | 1417 ++++++++++++++++++++ .../multi/gui/GT_Container_MultiMachineEM.java | 2 +- .../pipe/GT_MetaTileEntity_Pipe_Data.java | 161 +++ .../pipe/GT_MetaTileEntity_Pipe_EM.java | 42 +- .../metaTileEntity/pipe/iConnectsToDataPipe.java | 8 + 29 files changed, 2136 insertions(+), 1733 deletions(-) delete mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/GT_MetaTileEntity_Hatch_ElementalContainer.java delete mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/GT_MetaTileEntity_MultiblockBase_EM.java create mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_DataConnector.java create mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_ElementalContainer.java create mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_InputData.java create mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_OutputData.java create mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_MultiblockBase_EM.java create mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/pipe/GT_MetaTileEntity_Pipe_Data.java create mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/pipe/iConnectsToDataPipe.java (limited to 'src/main/java') diff --git a/src/main/java/com/github/technus/tectech/TecTech.java b/src/main/java/com/github/technus/tectech/TecTech.java index a2879c16d8..b373ef3ec9 100644 --- a/src/main/java/com/github/technus/tectech/TecTech.java +++ b/src/main/java/com/github/technus/tectech/TecTech.java @@ -29,7 +29,7 @@ import net.minecraft.item.ItemStack; import java.util.List; @Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, dependencies = "required-after:Forge@[10.13.4.1614,);" - + "required-after:YAMCore@[0.5.70,);" + "required-after:gregtech;" + "after:CoFHCore") + + "required-after:YAMCore@[0.5.73,);" + "required-after:gregtech;" + "after:CoFHCore") public class TecTech { @SidedProxy(clientSide = Reference.CLIENTSIDE, serverSide = Reference.SERVERSIDE) diff --git a/src/main/java/com/github/technus/tectech/loader/GT_Loader_Machines.java b/src/main/java/com/github/technus/tectech/loader/GT_Loader_Machines.java index 21824b4579..d149e37da5 100644 --- a/src/main/java/com/github/technus/tectech/loader/GT_Loader_Machines.java +++ b/src/main/java/com/github/technus/tectech/loader/GT_Loader_Machines.java @@ -2,6 +2,7 @@ package com.github.technus.tectech.loader; import com.github.technus.tectech.thing.metaTileEntity.hatch.*; import com.github.technus.tectech.thing.metaTileEntity.multi.*; +import com.github.technus.tectech.thing.metaTileEntity.pipe.GT_MetaTileEntity_Pipe_Data; import com.github.technus.tectech.thing.metaTileEntity.pipe.GT_MetaTileEntity_Pipe_EM; import static com.github.technus.tectech.thing.CustomItemList.*; @@ -175,10 +176,10 @@ public class GT_Loader_Machines implements Runnable { // =================================================================================================== Machine_Multi_Transformer.set(new GT_MetaTileEntity_EM_transformer(12160, "multimachine.em.transformer", "Active Transformer").getStackForm(1L)); - Machine_Multi_Infuser.set(new GT_MetaTileEntity_EM_infuser(12161,"multimachine.em.infuser","Energy infuser").getStackForm(1)); + Machine_Multi_Infuser.set(new GT_MetaTileEntity_EM_infuser(12161,"multimachine.em.infuser","Energy Infuser").getStackForm(1)); Machine_Multi_MatterToEM.set(new GT_MetaTileEntity_EM_quantizer(12162, "multimachine.em.mattertoem", "Matter Quantizer").getStackForm(1L)); Machine_Multi_EMToMatter.set(new GT_MetaTileEntity_EM_dequantizer(12163, "multimachine.em.emtomatter", "Matter Dequantizer").getStackForm(1L)); - Machine_Multi_EMjunction.set(new GT_MetaTileEntity_EM_junction(12164, "multimachine.em.junction", "Matter junction").getStackForm(1L)); + Machine_Multi_EMjunction.set(new GT_MetaTileEntity_EM_junction(12164, "multimachine.em.junction", "Matter Junction").getStackForm(1L)); Machine_Multi_EMmachine.set(new GT_MetaTileEntity_EM_machine(12165, "multimachine.em.processing", "Quantum Processing Machine").getStackForm(1L)); Machine_Multi_EMCrafter.set(new GT_MetaTileEntity_EM_crafter(12166, "multimachine.em.crafter", "Matter Assembler").getStackForm(1L)); Machine_Multi_Collider.set(new GT_MetaTileEntity_EM_collider(12167, "multimachine.em.collider", "Matter Collider").getStackForm(1L)); @@ -186,18 +187,21 @@ public class GT_Loader_Machines implements Runnable { Machine_Multi_Wormhole.set(new GT_MetaTileEntity_EM_wormhole(12169, "multimachine.em.wormhole", "Wormhole").getStackForm(1L)); Machine_Multi_Stabilizer.set(new GT_MetaTileEntity_EM_stabilizer(12170, "multimachine.em.stabilizer", "Elemental Stabilizer").getStackForm(1L)); Machine_Multi_Scanner.set(new GT_MetaTileEntity_EM_scanner(12171, "multimachine.em.scanner", "Elemental Scanner").getStackForm(1L)); - Machine_Multi_Computer.set(new GT_MetaTileEntity_EM_computer(12172, "multimachine.em.computer", "Quantum computer").getStackForm(1L)); + Machine_Multi_Computer.set(new GT_MetaTileEntity_EM_computer(12172, "multimachine.em.computer", "Quantum Computer").getStackForm(1L)); // =================================================================================================== // Hatches EM // =================================================================================================== - Parametrizer_Hatch.set(new GT_MetaTileEntity_Hatch_Param(12180, "hatch.param.tier.06", "Parametrizer for machines", 6).getStackForm(1L)); - Uncertainty_Hatch.set(new GT_MetaTileEntity_Hatch_Uncertainty(12181, "hatch.certain.tier.06", "Uncertainty resolver", 6).getStackForm(1L)); - UncertaintyX_Hatch.set(new GT_MetaTileEntity_Hatch_Uncertainty(12182, "hatch.certain.tier.10", "Uncertainty resolver X", 10).getStackForm(1L)); + Parametrizer_Hatch.set(new GT_MetaTileEntity_Hatch_Param(12180, "hatch.param.tier.08", "Parametrizer", 8).getStackForm(1L)); + Uncertainty_Hatch.set(new GT_MetaTileEntity_Hatch_Uncertainty(12181, "hatch.certain.tier.08", "Uncertainty Resolver", 10).getStackForm(1L)); + UncertaintyX_Hatch.set(new GT_MetaTileEntity_Hatch_Uncertainty(12182, "hatch.certain.tier.10", "Uncertainty Resolver X", 10).getStackForm(1L)); + dataIn_Hatch.set(new GT_MetaTileEntity_Hatch_InputData(12183, "hatch.datain.tier.08", "Optical Host Connector", 8).getStackForm(1L)); + dataOut_Hatch.set(new GT_MetaTileEntity_Hatch_OutputData(12184, "hatch.dataout.tier.08", "Optical Server Connector", 8).getStackForm(1L)); // =================================================================================================== // EM pipe // =================================================================================================== - EMpipe.set(new GT_MetaTileEntity_Pipe_EM(12199, "pipe.elementalmatter", "Quantum tunnel").getStackForm(1L)); + EMpipe.set(new GT_MetaTileEntity_Pipe_EM(12200, "pipe.elementalmatter", "Quantum Tunnel").getStackForm(1L)); + DATApipe.set(new GT_MetaTileEntity_Pipe_Data(12201, "pipe.datastream", "Optical Fiber Cable").getStackForm(1L)); } } diff --git a/src/main/java/com/github/technus/tectech/thing/CustomItemList.java b/src/main/java/com/github/technus/tectech/thing/CustomItemList.java index e40b478325..0de21e30a0 100644 --- a/src/main/java/com/github/technus/tectech/thing/CustomItemList.java +++ b/src/main/java/com/github/technus/tectech/thing/CustomItemList.java @@ -11,7 +11,7 @@ import net.minecraft.item.ItemStack; import static gregtech.api.enums.GT_Values.W; public enum CustomItemList implements IItemContainer { - EMpipe, + EMpipe,DATApipe, eM_dynamomulti4_UV, eM_dynamomulti16_UV, eM_dynamomulti64_UV, eM_dynamomulti4_UHV, eM_dynamomulti16_UHV, eM_dynamomulti64_UHV, eM_dynamomulti4_UEV, eM_dynamomulti16_UEV, eM_dynamomulti64_UEV, @@ -27,7 +27,7 @@ public enum CustomItemList implements IItemContainer { eM_in_UV, eM_in_UHV, eM_in_UEV, eM_in_UIV, eM_in_UMV, eM_in_UXV, eM_out_UV, eM_out_UHV, eM_out_UEV, eM_out_UIV, eM_out_UMV, eM_out_UXV, eM_muffler_UV, eM_muffler_UHV, eM_muffler_UEV, eM_muffler_UIV, eM_muffler_UMV, eM_muffler_UXV, - Parametrizer_Hatch, Uncertainty_Hatch, UncertaintyX_Hatch, + Parametrizer_Hatch, Uncertainty_Hatch, UncertaintyX_Hatch, dataIn_Hatch, dataOut_Hatch, eM_Casing, eM_Field, eM_Field_Casing, eM_Coil, eM_Tele, eM_TimeSpaceWarp, debugBlock, Machine_Multi_MatterToEM, Machine_Multi_EMToMatter, Machine_Multi_EMjunction, diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/GT_MetaTileEntity_Hatch_ElementalContainer.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/GT_MetaTileEntity_Hatch_ElementalContainer.java deleted file mode 100644 index 6fd6eaa403..0000000000 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/GT_MetaTileEntity_Hatch_ElementalContainer.java +++ /dev/null @@ -1,249 +0,0 @@ -package com.github.technus.tectech.thing.metaTileEntity; - -import com.github.technus.tectech.TecTech; -import com.github.technus.tectech.elementalMatter.classes.cElementalInstanceStackTree; -import com.github.technus.tectech.elementalMatter.classes.tElementalException; -import com.github.technus.tectech.elementalMatter.commonValues; -import com.github.technus.tectech.elementalMatter.interfaces.iElementalInstanceContainer; -import com.github.technus.tectech.thing.machineTT; -import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_MufflerElemental; -import com.github.technus.tectech.thing.metaTileEntity.pipe.iConnectsToEMpipe; -import gregtech.api.enums.Dyes; -import gregtech.api.enums.Textures; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; -import gregtech.api.objects.GT_RenderedTexture; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumChatFormatting; -import net.minecraftforge.fluids.FluidStack; - -import static com.github.technus.tectech.elementalMatter.commonValues.*; -import static gregtech.api.enums.Dyes.MACHINE_METAL; -import static gregtech.api.enums.GT_Values.V; -import static gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity; - -/** - * Created by danie_000 on 11.12.2016. - */ -public abstract class GT_MetaTileEntity_Hatch_ElementalContainer extends GT_MetaTileEntity_Hatch implements iElementalInstanceContainer, iConnectsToEMpipe, machineTT { - private static Textures.BlockIcons.CustomIcon EM_T_SIDES; - private static Textures.BlockIcons.CustomIcon EM_T_ACTIVE; - - protected cElementalInstanceStackTree content = new cElementalInstanceStackTree(); - //float lifeTimeMult=1f; - public int postEnergize = 0; - public float overflowMatter = 0f; - public short id = -1; - private byte deathDelay = 2; - - public GT_MetaTileEntity_Hatch_ElementalContainer(int aID, String aName, String aNameRegional, int aTier, String descr) { - super(aID, aName, aNameRegional, aTier, 0, descr); - } - - public GT_MetaTileEntity_Hatch_ElementalContainer(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 0, aDescription, aTextures); - } - - @Override - public void registerIcons(IIconRegister aBlockIconRegister) { - super.registerIcons(aBlockIconRegister); - EM_T_ACTIVE = new Textures.BlockIcons.CustomIcon("iconsets/OVERLAY_EM_T_ACTIVE"); - EM_T_SIDES = new Textures.BlockIcons.CustomIcon("iconsets/OVERLAY_EM_T_SIDES"); - } - - @Override - public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(EM_T_ACTIVE, Dyes.getModulation(getBaseMetaTileEntity().getColorization(), MACHINE_METAL.getRGBA())), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; - } - - @Override - public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(EM_T_SIDES, Dyes.getModulation(getBaseMetaTileEntity().getColorization(), MACHINE_METAL.getRGBA())), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setInteger("postEnergize", postEnergize); - //aNBT.setFloat("lifeTimeMult",lifeTimeMult); - aNBT.setFloat("overflowMatter", overflowMatter); - aNBT.setTag("eM_Stacks", content.toNBT()); - aNBT.setShort("eID", id); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - postEnergize = aNBT.getInteger("postEnergize"); - //lifeTimeMult=aNBT.getFloat("lifeTimeMult"); - overflowMatter = aNBT.getFloat("overflowMatter"); - id = aNBT.getShort("eID"); - try { - content = cElementalInstanceStackTree.fromNBT(aNBT.getCompoundTag("eM_Stacks")); - } catch (tElementalException e) { - if (TecTech.ModConfig.DEBUG_MODE) e.printStackTrace(); - if (content == null) content = new cElementalInstanceStackTree(); - } - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (aBaseMetaTileEntity.isServerSide()) { - byte Tick = (byte) (aTick % 20); - if (decayAt == Tick) { - purgeOverflow(); - content.tickContent(postEnergize);//Hatches don't life time mult things - purgeOverflow(); - } else if (overflowAt == Tick) { - if (overflowMatter <= 0) { - deathDelay = 3; - } else { - if (deathDelay == 2) { - if (TecTech.ModConfig.BOOM_ENABLE && TecTech.Rnd.nextInt(10) == 0) - aBaseMetaTileEntity.setOnFire(); - else - TecTech.proxy.broadcast("Container0 FIRE! " + getBaseMetaTileEntity().getXCoord() + " " + getBaseMetaTileEntity().getYCoord() + " " + getBaseMetaTileEntity().getZCoord()); - } else if (deathDelay == 1) { - IGregTechTileEntity tGTTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(aBaseMetaTileEntity.getBackFacing()); - if (tGTTileEntity == null || !(tGTTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_Hatch_MufflerElemental)) - tGTTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityAtSide((byte) 0); - if (tGTTileEntity == null || !(tGTTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_Hatch_MufflerElemental)) - tGTTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityAtSide((byte) 1); - if (tGTTileEntity != null && (tGTTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_Hatch_MufflerElemental)) { - GT_MetaTileEntity_Hatch_MufflerElemental aMetaTileEntity = (GT_MetaTileEntity_Hatch_MufflerElemental) tGTTileEntity.getMetaTileEntity(); - aMetaTileEntity.overflowMatter += overflowMatter; - if (aMetaTileEntity.overflowMatter > aMetaTileEntity.overflowMax) { - if (TecTech.ModConfig.BOOM_ENABLE) tGTTileEntity.doExplosion(V[14]); - else - TecTech.proxy.broadcast("Container1 BOOM! " + getBaseMetaTileEntity().getXCoord() + " " + getBaseMetaTileEntity().getYCoord() + " " + getBaseMetaTileEntity().getZCoord()); - } else overflowMatter = 0F; - } - } else if (deathDelay < 1) { - if (TecTech.ModConfig.BOOM_ENABLE) getBaseMetaTileEntity().doExplosion(V[14]); - else - TecTech.proxy.broadcast("Container2 BOOM! " + getBaseMetaTileEntity().getXCoord() + " " + getBaseMetaTileEntity().getYCoord() + " " + getBaseMetaTileEntity().getZCoord()); - } - deathDelay--; - } - } else if (moveAt == Tick) { - moveAround(aBaseMetaTileEntity); - getBaseMetaTileEntity().setActive(content.hasStacks()); - } - } - } - - public void moveAround(IGregTechTileEntity aBaseMetaTileEntity) { - } - - @Override - public cElementalInstanceStackTree getContainerHandler() { - return content; - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - return true; - } - - @Override - public boolean isFacingValid(byte aFacing) { - return true; - } - - @Override - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - @Override - public boolean isLiquidInput(byte aSide) { - return false; - } - - @Override - public boolean isFluidInputAllowed(FluidStack aFluid) { - return false; - } - - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return false; - } - - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return false; - } - - @Override - public boolean isValidSlot(int aIndex) { - return false; - } - - public int getMaxStacksCount() { - return mTier * 2; - } - - public int getMaxStackSize() { - return mTier * (mTier - 7) * 1000; - } - - @Override - public float purgeOverflow() { - return overflowMatter += content.removeOverflow(getMaxStacksCount(), getMaxStackSize()); - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public String[] getInfoData() { - if (id > 0) { - if (content == null || content.size() == 0) - return new String[]{"ID: " + EnumChatFormatting.AQUA + id, "No Stacks"}; - else { - final String[] lines = content.getElementalInfo(); - final String[] output = new String[lines.length + 1]; - output[0] = "ID: " + EnumChatFormatting.AQUA + id; - System.arraycopy(lines, 0, output, 1, lines.length); - return output; - } - } - if (content == null || content.size() == 0) return new String[]{"No Stacks"}; - return content.getElementalInfo(); - } - - public float updateSlots() { - return purgeOverflow(); - } - - @Override - public String[] getDescription() { - return new String[]{ - commonValues.tecMark, - mDescription, - "Max stacks amount: " + EnumChatFormatting.AQUA + getMaxStacksCount(), - "Stack capacity: " + EnumChatFormatting.AQUA + getMaxStackSize(), - "Place Overflow Hatch behind,on top or below", - "to provide overflow protection while this block", - "is not attached to multi block.", - "Transport range can be extended in straight", - "line up to 15 blocks with quantum tunnels.", - EnumChatFormatting.AQUA + "Must be painted to work" - }; - } - - @Override - public void onRemoval() { - if (isValidMetaTileEntity(this) && getBaseMetaTileEntity().isActive()) - if (TecTech.ModConfig.BOOM_ENABLE) getBaseMetaTileEntity().doExplosion(V[15]); - else - TecTech.proxy.broadcast("BOOM! " + getBaseMetaTileEntity().getXCoord() + " " + getBaseMetaTileEntity().getYCoord() + " " + getBaseMetaTileEntity().getZCoord()); - } -} diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/GT_MetaTileEntity_MultiblockBase_EM.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/GT_MetaTileEntity_MultiblockBase_EM.java deleted file mode 100644 index dcb4a7a6fc..0000000000 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/GT_MetaTileEntity_MultiblockBase_EM.java +++ /dev/null @@ -1,1410 +0,0 @@ -package com.github.technus.tectech.thing.metaTileEntity; - -import com.github.technus.tectech.TecTech; -import com.github.technus.tectech.elementalMatter.classes.cElementalDefinitionStack; -import com.github.technus.tectech.elementalMatter.classes.cElementalInstanceStack; -import com.github.technus.tectech.elementalMatter.classes.cElementalInstanceStackTree; -import com.github.technus.tectech.elementalMatter.classes.tElementalException; -import com.github.technus.tectech.elementalMatter.commonValues; -import com.github.technus.tectech.thing.machineTT; -import com.github.technus.tectech.thing.metaTileEntity.hatch.*; -import com.github.technus.tectech.thing.metaTileEntity.multi.gui.GT_Container_MultiMachineEM; -import com.github.technus.tectech.thing.metaTileEntity.multi.gui.GT_GUIContainer_MultiMachineEM; -import gregtech.api.GregTech_API; -import gregtech.api.enums.Textures; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.metatileentity.implementations.*; -import gregtech.api.objects.GT_RenderedTexture; -import gregtech.api.util.GT_OreDictUnificator; -import gregtech.api.util.GT_Recipe; -import gregtech.api.util.GT_Utility; -import gregtech.common.GT_Pollution; -import net.minecraft.block.Block; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.world.ChunkPosition; -import net.minecraftforge.fluids.FluidStack; - -import java.util.ArrayList; - -import static com.github.technus.tectech.elementalMatter.commonValues.*; -import static gregtech.api.enums.GT_Values.V; -import static gregtech.api.enums.GT_Values.VN; - -/** - * Created by danie_000 on 27.10.2016. - */ -public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEntity_MultiBlockBase implements machineTT { - protected cElementalInstanceStackTree[] outputEM = new cElementalInstanceStackTree[0]; - - public final static ItemStack[] nothingI = new ItemStack[0]; - public final static FluidStack[] nothingF = new FluidStack[0]; - - private static Textures.BlockIcons.CustomIcon ScreenOFF; - private static Textures.BlockIcons.CustomIcon ScreenON; - - public ArrayList eInputHatches = new ArrayList<>(); - public ArrayList eOutputHatches = new ArrayList<>(); - public ArrayList eMufflerHatches = new ArrayList<>(); - public ArrayList eParamHatches = new ArrayList<>(); - public ArrayList eUncertainHatches = new ArrayList<>(); - public ArrayList eEnergyMulti = new ArrayList<>(); - public ArrayList eDynamoMulti = new ArrayList<>(); - - public final float[] eParamsIn = new float[20]; - public final float[] eParamsOut = new float[20]; - public final byte[] eParamsInStatus = new byte[20]; - public final byte[] eParamsOutStatus = new byte[20]; - protected final static byte PARAM_UNUSED = 0, PARAM_OK = 1, PARAM_TOO_LOW = 2, PARAM_LOW = 3, PARAM_TOO_HIGH = 4, PARAM_HIGH = 5, PARAM_WRONG = 6; - - //TO ENABLE this change value in to false and/or other than 0, can also be added in recipe check or whatever - public boolean eParameters = true, ePowerPass = false, eSafeVoid = false, eDismatleBoom = false; - public byte eCertainMode = 0, eCertainStatus = 0, minRepairStatus = 3; - - private long eMaxAmpereFlow = 0; - private long maxEUinputMin = 0, maxEUinputMax = 0; - public long eAmpereFlow = 1; - - //init param states in constructor, or implement it in checkrecipe/outputfunction - - //METHODS TO OVERRIDE - this 3 below + checkMachine - - //if you want to add checks that run periodically when machine works then make onRunningTick better - //if you want to add checks that run periodically when machine is built then use check params - - public boolean EM_checkRecipe(ItemStack itemStack) { - return false; - } - //My code handles AMPS, if you want overclocking just modify mEUt and mMaxProgressTime, leave amps as usual! - - public void EM_checkParams() { - } - //update status of parameters in guis and "machine state" - - public void EM_outputFunction() { - } - // based on "machine state" do output, - // this must move to output EM things and can also modify output items/fluids/EM, remaining EM is NOT overflowed. - //(Well it can be overflowed if machine didn't finished, soft-hammered/disabled/not enough EU) - - //RATHER LEAVE ALONE Section - - public GT_MetaTileEntity_MultiblockBase_EM(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GT_MetaTileEntity_MultiblockBase_EM(String aName) { - super(aName); - } - - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_MultiMachineEM(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachineEM(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "EMDisplay.png"); - } - - @Override - public void registerIcons(IIconRegister aBlockIconRegister) { - ScreenOFF = new Textures.BlockIcons.CustomIcon("iconsets/EM_CONTROLLER"); - ScreenON = new Textures.BlockIcons.CustomIcon("iconsets/EM_CONTROLLER_ACTIVE"); - super.registerIcons(aBlockIconRegister); - } - - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { - if (aSide == aFacing) { - return new ITexture[]{Textures.BlockIcons.CASING_BLOCKS[99], new GT_RenderedTexture(aActive ? ScreenON : ScreenOFF)}; - } - return new ITexture[]{Textures.BlockIcons.CASING_BLOCKS[99]}; - } - - @Override - public final byte getTileEntityBaseType() { - return 3; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - - //Fix supermethod shit. - if (mOutputItems != null) - aNBT.setInteger("eItemsOut", mOutputItems.length); - if (mOutputFluids != null) - aNBT.setInteger("eFluidsOut", mOutputFluids.length); - - aNBT.setLong("eMaxEUmin", maxEUinputMin); - aNBT.setLong("eMaxEUmax", maxEUinputMax); - aNBT.setLong("eRating", eAmpereFlow); - aNBT.setLong("eMaxA", eMaxAmpereFlow); - aNBT.setByte("eCertainM", eCertainMode); - aNBT.setByte("eCertainS", eCertainStatus); - aNBT.setByte("eMinRepair", minRepairStatus); - aNBT.setBoolean("eParam", eParameters); - aNBT.setBoolean("ePass", ePowerPass); - aNBT.setBoolean("eVoid", eSafeVoid); - aNBT.setBoolean("eBoom", eDismatleBoom); - - if (outputEM != null) { - aNBT.setInteger("outputStackCount", outputEM.length); - NBTTagCompound output = new NBTTagCompound(); - for (int i = 0; i < outputEM.length; i++) - output.setTag(Integer.toString(i), outputEM[i].toNBT()); - aNBT.setTag("outputEM", output); - } else { - aNBT.setInteger("outputStackCount", 0); - aNBT.removeTag("outputEM"); - } - - NBTTagCompound paramI = new NBTTagCompound(); - for (int i = 0; i < 20; i++) - paramI.setFloat(Integer.toString(i), eParamsIn[i]); - aNBT.setTag("eParamsIn", paramI); - - NBTTagCompound paramO = new NBTTagCompound(); - for (int i = 0; i < 20; i++) - paramO.setFloat(Integer.toString(i), eParamsOut[i]); - aNBT.setTag("eParamsOut", paramO); - - NBTTagCompound paramIs = new NBTTagCompound(); - for (int i = 0; i < 20; i++) - paramIs.setByte(Integer.toString(i), eParamsInStatus[i]); - aNBT.setTag("eParamsInS", paramIs); - - NBTTagCompound paramOs = new NBTTagCompound(); - for (int i = 0; i < 20; i++) - paramOs.setByte(Integer.toString(i), eParamsOutStatus[i]); - aNBT.setTag("eParamsOutS", paramOs); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - - maxEUinputMin = aNBT.getLong("eMaxEUmin"); - maxEUinputMax = aNBT.getLong("eMaxEUmax"); - eAmpereFlow = aNBT.getLong("eRating"); - eMaxAmpereFlow = aNBT.getLong("eMaxA"); - eCertainMode = aNBT.getByte("eCertainM"); - eCertainStatus = aNBT.getByte("eCertainS"); - minRepairStatus = aNBT.getByte("eMinRepair"); - eParameters = aNBT.getBoolean("eParam"); - ePowerPass = aNBT.getBoolean("ePass"); - eSafeVoid = aNBT.getBoolean("eVoid"); - eDismatleBoom = aNBT.getBoolean("eBoom"); - - //Fix supermethod shit. - mOutputItems = new ItemStack[aNBT.getInteger("eItemsOut")]; - for (int i = 0; i < mOutputItems.length; i++) - mOutputItems[i] = GT_Utility.loadItem(aNBT, "mOutputItem" + i); - mOutputFluids = new FluidStack[aNBT.getInteger("eFluidsOut")]; - for (int i = 0; i < mOutputFluids.length; i++) - mOutputFluids[i] = GT_Utility.loadFluid(aNBT, "mOutputFluids" + i); - - final int outputLen = aNBT.getInteger("outputStackCount"); - if (outputLen > 0) { - outputEM = new cElementalInstanceStackTree[outputLen]; - for (int i = 0; i < outputEM.length; i++) - try { - outputEM[i] = cElementalInstanceStackTree.fromNBT( - aNBT.getCompoundTag("outputEM").getCompoundTag(Integer.toString(i))); - } catch (tElementalException e) { - if (TecTech.ModConfig.DEBUG_MODE) e.printStackTrace(); - outputEM[i] = new cElementalInstanceStackTree(); - } - } else outputEM = new cElementalInstanceStackTree[0]; - - NBTTagCompound paramI = aNBT.getCompoundTag("eParamsIn"); - for (int i = 0; i < eParamsIn.length; i++) - eParamsIn[i] = paramI.getFloat(Integer.toString(i)); - - NBTTagCompound paramO = aNBT.getCompoundTag("eParamsOut"); - for (int i = 0; i < eParamsOut.length; i++) - eParamsOut[i] = paramO.getFloat(Integer.toString(i)); - - NBTTagCompound paramIs = aNBT.getCompoundTag("eParamsInS"); - for (int i = 0; i < eParamsInStatus.length; i++) - eParamsInStatus[i] = paramIs.getByte(Integer.toString(i)); - - NBTTagCompound paramOs = aNBT.getCompoundTag("eParamsOutS"); - for (int i = 0; i < eParamsOutStatus.length; i++) - eParamsOutStatus[i] = paramOs.getByte(Integer.toString(i)); - } - - @Override - public final long maxEUStore() { - return (maxEUinputMin * eMaxAmpereFlow) << 3; - } - - @Override - public final long getMinimumStoredEU() { - return maxEUStore() >> 1; - } - - @Override - public final long maxAmperesIn() { - return 0L; - } - - @Override - public final long maxAmperesOut() { - return 0L; - } - - @Override - public int getPollutionPerTick(ItemStack itemStack) { - return 0; - } - - @Override - public final void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (aBaseMetaTileEntity.isServerSide()) { - if (mEfficiency < 0) mEfficiency = 0; - if (--mUpdate == 0 || --mStartUpCheck == 0) { - - mInputHatches.clear(); - mInputBusses.clear(); - mOutputHatches.clear(); - mOutputBusses.clear(); - mDynamoHatches.clear(); - mEnergyHatches.clear(); - mMufflerHatches.clear(); - mMaintenanceHatches.clear(); - - for (GT_MetaTileEntity_Hatch_ElementalContainer hatch_elemental : eOutputHatches) - if (isValidMetaTileEntity(hatch_elemental)) hatch_elemental.id = -1; - for (GT_MetaTileEntity_Hatch_ElementalContainer hatch_elemental : eInputHatches) - if (isValidMetaTileEntity(hatch_elemental)) hatch_elemental.id = -1; - for (GT_MetaTileEntity_Hatch_Uncertainty hatch : eUncertainHatches) - if (isValidMetaTileEntity(hatch)) hatch.getBaseMetaTileEntity().setActive(false); - for (GT_MetaTileEntity_Hatch_Param hatch : eParamHatches) - if (isValidMetaTileEntity(hatch)) hatch.getBaseMetaTileEntity().setActive(false); - - eUncertainHatches.clear(); - eEnergyMulti.clear(); - eInputHatches.clear(); - eOutputHatches.clear(); - eParamHatches.clear(); - eMufflerHatches.clear(); - eDynamoMulti.clear(); - - mMachine = checkMachine(aBaseMetaTileEntity, mInventory[1]); - - if (!mMachine) - if (eDismatleBoom && mMaxProgresstime > 0) explodeMultiblock(); - else if (outputEM != null) - for (cElementalInstanceStackTree tree : outputEM) - if (tree.hasStacks()) { - explodeMultiblock(); - break; - } - - if (eUncertainHatches.size() > 1) mMachine = false; - - if (mMachine) { - short id = 1; - for (GT_MetaTileEntity_Hatch_ElementalContainer hatch_elemental : eOutputHatches) - if (isValidMetaTileEntity(hatch_elemental)) hatch_elemental.id = id++; - id = 1; - for (GT_MetaTileEntity_Hatch_ElementalContainer hatch_elemental : eInputHatches) - if (isValidMetaTileEntity(hatch_elemental)) hatch_elemental.id = id++; - - if (mEnergyHatches.size() > 0 || eEnergyMulti.size() > 0) { - maxEUinputMin = V[15]; - maxEUinputMax = V[0]; - for (GT_MetaTileEntity_Hatch_Energy hatch : mEnergyHatches) - if (isValidMetaTileEntity(hatch)) { - if (hatch.maxEUInput() < maxEUinputMin) maxEUinputMin = hatch.maxEUInput(); - if (hatch.maxEUInput() > maxEUinputMax) maxEUinputMax = hatch.maxEUInput(); - } - for (GT_MetaTileEntity_Hatch_EnergyMulti hatch : eEnergyMulti) - if (isValidMetaTileEntity(hatch)) { - if (hatch.maxEUInput() < maxEUinputMin) maxEUinputMin = hatch.maxEUInput(); - if (hatch.maxEUInput() > maxEUinputMax) maxEUinputMax = hatch.maxEUInput(); - } - eMaxAmpereFlow = 0; - //counts only full amps - for (GT_MetaTileEntity_Hatch_Energy hatch : mEnergyHatches) - if (isValidMetaTileEntity(hatch)) eMaxAmpereFlow += hatch.maxEUInput() / maxEUinputMin; - for (GT_MetaTileEntity_Hatch_EnergyMulti hatch : eEnergyMulti) - if (isValidMetaTileEntity(hatch)) - eMaxAmpereFlow += (hatch.maxEUInput() / maxEUinputMin) * hatch.Amperes; - if (this.getEUVar() > maxEUStore()) this.setEUVar(this.maxEUStore()); - } else { - maxEUinputMin = 0; - maxEUinputMax = 0; - eMaxAmpereFlow = 0; - this.setEUVar(0); - } - - for (GT_MetaTileEntity_Hatch_Uncertainty hatch : eUncertainHatches) - if (isValidMetaTileEntity(hatch)) hatch.getBaseMetaTileEntity().setActive(true); - for (GT_MetaTileEntity_Hatch_Param hatch : eParamHatches) - if (isValidMetaTileEntity(hatch)) hatch.getBaseMetaTileEntity().setActive(true); - } else { - maxEUinputMin = 0; - maxEUinputMax = 0; - eMaxAmpereFlow = 0; - this.setEUVar(0); - } - } - - if (mStartUpCheck < 0) {//E - if (mMachine) {//S - final byte Tick = (byte) (aTick % 20); - if (multiPurge1At == Tick || multiPurge2At == Tick) - purgeAll(); - else if (multiCheckAt == Tick) - for (GT_MetaTileEntity_Hatch_Maintenance tHatch : mMaintenanceHatches) { - if (isValidMetaTileEntity(tHatch)) { - if (disableMaintenance) { - mWrench = true; - mScrewdriver = true; - mSoftHammer = true; - mHardHammer = true; - mSolderingTool = true; - mCrowbar = true; - } else { - if (tHatch.mAuto && !(mWrench && mScrewdriver && mSoftHammer && mHardHammer && mSolderingTool && mCrowbar)) - tHatch.isRecipeInputEqual(true); - if (tHatch.mWrench) mWrench = true; - if (tHatch.mScrewdriver) mScrewdriver = true; - if (tHatch.mSoftHammer) mSoftHammer = true; - if (tHatch.mHardHammer) mHardHammer = true; - if (tHatch.mSolderingTool) mSolderingTool = true; - if (tHatch.mCrowbar) mCrowbar = true; - - tHatch.mWrench = false; - tHatch.mScrewdriver = false; - tHatch.mSoftHammer = false; - tHatch.mHardHammer = false; - tHatch.mSolderingTool = false; - tHatch.mCrowbar = false; - } - } - } - else if (moveAt == Tick && eSafeVoid) { - for (GT_MetaTileEntity_Hatch_MufflerElemental voider : eMufflerHatches) { - if (voider.overflowMax < voider.overflowMatter) continue; - float remaining = voider.overflowMax - voider.overflowMatter; - for (GT_MetaTileEntity_Hatch_InputElemental in : eInputHatches) { - for (cElementalInstanceStack instance : in.getContainerHandler().values()) { - int qty = (int) Math.floor(remaining / instance.definition.getMass()); - if (qty > 0) { - qty = Math.min(qty, instance.amount); - voider.overflowMatter += instance.definition.getMass() * qty; - in.getContainerHandler().removeAmount(false, new cElementalDefinitionStack(instance.definition, qty)); - } - } - } - for (GT_MetaTileEntity_Hatch_OutputElemental out : eOutputHatches) { - for (cElementalInstanceStack instance : out.getContainerHandler().values()) { - int qty = (int) Math.floor(remaining / instance.definition.getMass()); - if (qty > 0) { - qty = Math.min(qty, instance.amount); - voider.overflowMatter += instance.definition.getMass() * qty; - out.getContainerHandler().removeAmount(false, new cElementalDefinitionStack(instance.definition, qty)); - } - } - } - //in case some weird shit happened here, it will still be safe - if (voider.overflowMatter > voider.overflowMax) voider.overflowMatter = voider.overflowMax; - } - } - - if (getRepairStatus() >= minRepairStatus) {//S - if (multiCheckAt == Tick) - paramsUpdate(); - - if (mMaxProgresstime > 0 && doRandomMaintenanceDamage()) {//Start - if (onRunningTick(mInventory[1])) {//Compute EU - if (!polluteEnvironment(getPollutionPerTick(mInventory[1]))) - stopMachine(); - - if (mMaxProgresstime > 0 && ++mProgresstime >= mMaxProgresstime && recipeAt == Tick) {//progress increase and done - paramsUpdate(); - EM_outputFunction(); - if (mOutputItems != null) for (ItemStack tStack : mOutputItems) - if (tStack != null) - addOutput(tStack); - - if (mOutputFluids != null && mOutputFluids.length == 1) - for (FluidStack tStack : mOutputFluids) - if (tStack != null) - addOutput(tStack); - else if (mOutputFluids != null && mOutputFluids.length > 1) - addFluidOutputs(mOutputFluids); - updateSlots(); - mOutputItems = null; - mOutputFluids = null; - outputEM = new cElementalInstanceStackTree[0]; - mProgresstime = 0; - mMaxProgresstime = 0; - mEfficiencyIncrease = 0; - if (aBaseMetaTileEntity.isAllowedToWork()) { - if (checkRecipe(mInventory[1])) { - mEfficiency = Math.max(0, Math.min(mEfficiency + mEfficiencyIncrease, getMaxEfficiency(mInventory[1]) - ((getIdealStatus() - getRepairStatus()) * 1000))); - } - updateSlots(); - } - } - } - } else { - if (recipeAt == Tick || aBaseMetaTileEntity.hasWorkJustBeenEnabled()) { - if (aBaseMetaTileEntity.isAllowedToWork()) { - if (checkRecipe(mInventory[1])) { - mEfficiency = Math.max(0, Math.min(mEfficiency + mEfficiencyIncrease, getMaxEfficiency(mInventory[1]) - ((getIdealStatus() - getRepairStatus()) * 1000))); - } - updateSlots(); - } - } - } - - {//DO ONCE - long euVar; - for (GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) { - if (this.getEUVar() > this.getMinimumStoredEU()) break; - if (isValidMetaTileEntity(tHatch)) { - euVar = tHatch.maxEUInput(); - if (tHatch.getBaseMetaTileEntity().decreaseStoredEnergyUnits(euVar, false)) - this.setEUVar(this.getEUVar() + euVar); - } - } - for (GT_MetaTileEntity_Hatch_EnergyMulti tHatch : eEnergyMulti) { - if (this.getEUVar() > this.getMinimumStoredEU()) break; - if (isValidMetaTileEntity(tHatch)) { - euVar = tHatch.maxEUInput() * tHatch.Amperes; - if (tHatch.getBaseMetaTileEntity().decreaseStoredEnergyUnits(euVar, false)) - this.setEUVar(this.getEUVar() + euVar); - } - } - if (ePowerPass) { - for (GT_MetaTileEntity_Hatch_Dynamo tHatch : mDynamoHatches) { - if (isValidMetaTileEntity(tHatch)) { - euVar = tHatch.maxEUOutput(); - if (tHatch.getBaseMetaTileEntity().getStoredEU() <= (tHatch.maxEUStore() - euVar) && - aBaseMetaTileEntity.decreaseStoredEnergyUnits(euVar + (euVar >> 7), false)) - tHatch.setEUVar(tHatch.getBaseMetaTileEntity().getStoredEU() + euVar); - } - } - for (GT_MetaTileEntity_Hatch_DynamoMulti tHatch : eDynamoMulti) { - if (isValidMetaTileEntity(tHatch)) { - euVar = tHatch.maxEUOutput() * tHatch.Amperes; - if (tHatch.getBaseMetaTileEntity().getStoredEU() <= tHatch.maxEUStore() - euVar && - aBaseMetaTileEntity.decreaseStoredEnergyUnits(euVar + (euVar >> 7), false)) - tHatch.setEUVar(tHatch.getBaseMetaTileEntity().getStoredEU() + euVar); - } - } - } - } - } else {//not repaired - stopMachine(); - } - } else {//not machine - stopMachine(); - } - } - aBaseMetaTileEntity.setErrorDisplayID((aBaseMetaTileEntity.getErrorDisplayID() & -512) | (mWrench ? 0 : 1) | (mScrewdriver ? 0 : 2) | (mSoftHammer ? 0 : 4) | (mHardHammer ? 0 : 8) | (mSolderingTool ? 0 : 16) | (mCrowbar ? 0 : 32) | (mMachine ? 0 : 64) | ((eCertainStatus == 0) ? 0 : 128) | (eParameters ? 0 : 256)); - aBaseMetaTileEntity.setActive(mMaxProgresstime > 0); - boolean active = aBaseMetaTileEntity.isActive() && mPollution > 0; - for (GT_MetaTileEntity_Hatch_Muffler aMuffler : mMufflerHatches) - aMuffler.getBaseMetaTileEntity().setActive(active); - } - } - - @Deprecated - @Override - public final int getAmountOfOutputs() { - return 0; - } - - private void addFluidOutputs(FluidStack[] mOutputFluids2) { - for (int i = 0; i < mOutputFluids2.length; ++i) { - if (this.mOutputHatches.size() > i && this.mOutputHatches.get(i) != null && mOutputFluids2[i] != null && isValidMetaTileEntity((MetaTileEntity) this.mOutputHatches.get(i))) { - this.mOutputHatches.get(i).fill(mOutputFluids2[i], true); - } - } - } - - @Override - public int getMaxEfficiency(ItemStack itemStack) { - return 10000; - } - - @Override - public int getIdealStatus() { - return super.getIdealStatus() + 2; - } - - @Override - public int getRepairStatus() { - return super.getRepairStatus() + ((eCertainStatus == 0) ? 1 : 0) + (this.eParameters ? 1 : 0); - } - - @Override - public boolean onRunningTick(ItemStack aStack) { - if (this.mEUt > 0) { - this.EMaddEnergyOutput((long) mEUt * (long) mEfficiency / getMaxEfficiency(aStack), eAmpereFlow); - return true; - } else if (this.mEUt < 0 && !this.EMdrainEnergyInput((long) (-this.mEUt) * getMaxEfficiency(aStack) / (long) Math.max(1000, this.mEfficiency), eAmpereFlow)) { - this.stopMachine(); - return false; - } else return true; - } - - @Deprecated - @Override - public final boolean addEnergyOutput(long EU) { - if (EU <= 0L) return true; - for (GT_MetaTileEntity_Hatch tHatch : eDynamoMulti) - if (isValidMetaTileEntity(tHatch) && tHatch.getBaseMetaTileEntity().increaseStoredEnergyUnits(EU, false)) - return true; - for (GT_MetaTileEntity_Hatch tHatch : mDynamoHatches) - if (isValidMetaTileEntity(tHatch) && tHatch.getBaseMetaTileEntity().increaseStoredEnergyUnits(EU, false)) - return true; - return false; - } - - //new method - public final boolean EMaddEnergyOutput(long EU, long Amperes) { - if (EU <= 0L || Amperes <= 0) return true; - long euVar = EU * Amperes; - long diff; - for (GT_MetaTileEntity_Hatch_Dynamo tHatch : mDynamoHatches) { - if (isValidMetaTileEntity(tHatch)) { - if (tHatch.maxEUOutput() < EU) explodeMultiblock(); - diff = tHatch.maxEUStore() - tHatch.getBaseMetaTileEntity().getStoredEU(); - if (diff > 0) { - if (euVar > diff) { - tHatch.setEUVar(tHatch.maxEUStore()); - euVar -= diff; - } else if (euVar <= diff) { - tHatch.setEUVar(tHatch.getBaseMetaTileEntity().getStoredEU() + euVar); - return true; - } - } - } - } - for (GT_MetaTileEntity_Hatch_DynamoMulti tHatch : eDynamoMulti) { - if (isValidMetaTileEntity(tHatch)) { - if (tHatch.maxEUOutput() < EU) explodeMultiblock(); - diff = tHatch.maxEUStore() - tHatch.getBaseMetaTileEntity().getStoredEU(); - if (diff > 0) { - if (euVar > diff) { - tHatch.setEUVar(tHatch.maxEUStore()); - euVar -= diff; - } else if (euVar <= diff) { - tHatch.setEUVar(tHatch.getBaseMetaTileEntity().getStoredEU() + euVar); - return true; - } - } - } - } - return false; - } - - @Deprecated - @Override - public final boolean drainEnergyInput(long EU) { - if (EU <= 0L) return true; - for (GT_MetaTileEntity_Hatch tHatch : eEnergyMulti) - if (isValidMetaTileEntity(tHatch) && tHatch.getBaseMetaTileEntity().decreaseStoredEnergyUnits(EU, false)) - return true; - for (GT_MetaTileEntity_Hatch tHatch : mEnergyHatches) - if (isValidMetaTileEntity(tHatch) && tHatch.getBaseMetaTileEntity().decreaseStoredEnergyUnits(EU, false)) - return true; - return false; - } - - //new method - public final boolean EMdrainEnergyInput(long EU, long Amperes) { - if (EU <= 0L || Amperes <= 0) return true; - long euVar = EU * Amperes; - if (euVar > getEUVar() || - EU > maxEUinputMax || - (euVar - 1) / maxEUinputMin + 1 > eMaxAmpereFlow) { - if (TecTech.ModConfig.DEBUG_MODE) { - TecTech.Logger.debug("OMG1 " + euVar + " " + getEUVar() + " " + (euVar > getEUVar())); - TecTech.Logger.debug("OMG2 " + EU + " " + maxEUinputMax + " " + (EU > maxEUinputMax)); - TecTech.Logger.debug("OMG3 " + euVar + " " + eMaxAmpereFlow); - TecTech.Logger.debug("OMG4 " + ((euVar - 1) / maxEUinputMin + 1) + " " + eMaxAmpereFlow + " " + ((euVar - 1) / maxEUinputMin + 1 > eMaxAmpereFlow)); - } - return false; - } - //sub eu - setEUVar(getEUVar() - euVar); - return true; - } - - //new method - public final boolean EMoverclockAndPutValuesIn(long EU, int time) { - if (EU == 0) { - mEUt = 0; - mMaxProgresstime = time; - return true; - } - long tempEUt = EU < V[1] ? V[1] : EU; - long tempTier = maxEUinputMax >> 2; - while (tempEUt < tempTier) { - tempEUt <<= 2; - time >>= 1; - EU = time == 0 ? EU >> 1 : EU << 2;//U know, if the time is less than 1 tick make the machine use less power - } - if (EU > Integer.MAX_VALUE || EU < Integer.MIN_VALUE) { - mEUt = Integer.MAX_VALUE - 1; - mMaxProgresstime = Integer.MAX_VALUE - 1; - return false; - } - mEUt = (int) EU; - mMaxProgresstime = time == 0 ? 1 : time; - return true; - }//Use in EM check recipe return statement if you want overclocking - - @Override - public final long getMaxInputVoltage() { - long rVoltage = 0; - for (GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) - if (isValidMetaTileEntity(tHatch)) rVoltage += tHatch.maxEUInput(); - for (GT_MetaTileEntity_Hatch_EnergyMulti tHatch : eEnergyMulti) - if (isValidMetaTileEntity(tHatch)) rVoltage += tHatch.maxEUInput(); - return rVoltage; - } - - //new Method - public final int getMaxEnergyInputTier() { - return GT_Utility.getTier(maxEUinputMax); - } - - //new Method - public final int getMinEnergyInputTier() { - return GT_Utility.getTier(maxEUinputMin); - } - - @Override - public final void stopMachine() { - mOutputItems = null; - mOutputFluids = null; - //mEUt = 0; - mEfficiency = 0; - mProgresstime = 0; - mMaxProgresstime = 0; - mEfficiencyIncrease = 0; - getBaseMetaTileEntity().disableWorking(); - - float mass = 0; - if (outputEM == null) return; - for (cElementalInstanceStackTree tree : outputEM) - mass += tree.getMass(); - if (mass > 0) { - if (eMufflerHatches.size() < 1) explodeMultiblock(); - mass /= eMufflerHatches.size(); - for (GT_MetaTileEntity_Hatch_MufflerElemental dump : eMufflerHatches) { - dump.overflowMatter += mass; - if (dump.overflowMatter > dump.overflowMax) explodeMultiblock(); - } - } - outputEM = null; - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - return null; - } - - @Override - public void updateSlots() { - super.updateSlots(); - purgeAll(); - } - - private void purgeAll() { - float mass = 0; - for (GT_MetaTileEntity_Hatch_InputElemental tHatch : eInputHatches) { - if (isValidMetaTileEntity(tHatch)) tHatch.updateSlots(); - mass += tHatch.overflowMatter; - tHatch.overflowMatter = 0; - } - for (GT_MetaTileEntity_Hatch_OutputElemental tHatch : eOutputHatches) { - if (isValidMetaTileEntity(tHatch)) tHatch.updateSlots(); - mass += tHatch.overflowMatter; - tHatch.overflowMatter = 0; - } - if (mass > 0) { - if (eMufflerHatches.size() < 1) { - explodeMultiblock(); - return; - } - mass /= eMufflerHatches.size(); - for (GT_MetaTileEntity_Hatch_MufflerElemental dump : eMufflerHatches) { - dump.overflowMatter += mass; - if (dump.overflowMatter > dump.overflowMax) explodeMultiblock(); - } - } - } - - public void cleanHatchContent(GT_MetaTileEntity_Hatch_ElementalContainer target) { - float mass = target.getContainerHandler().getMass(); - if (mass > 0) { - if (eMufflerHatches.size() < 1) explodeMultiblock(); - mass /= eMufflerHatches.size(); - for (GT_MetaTileEntity_Hatch_MufflerElemental dump : eMufflerHatches) { - dump.overflowMatter += mass; - if (dump.overflowMatter > dump.overflowMax) explodeMultiblock(); - } - } - } - - @Override - public final boolean checkRecipe(ItemStack itemStack) {//do recipe checks, based on "machine content and state" - paramsUpdate(); - return EM_checkRecipe(itemStack); - } - - private void paramsUpdate() { - for (GT_MetaTileEntity_Hatch_Param param : eParamHatches) { - int paramID = param.param; - if (paramID < 0) continue; - eParamsIn[paramID] = param.value1f; - eParamsIn[paramID + 10] = param.value2f; - param.input1f = eParamsOut[paramID]; - param.input2f = eParamsOut[paramID + 10]; - } - EM_checkParams(); - for (GT_MetaTileEntity_Hatch_Uncertainty uncertainty : eUncertainHatches) { - eCertainStatus = uncertainty.update(eCertainMode); - } - } - - @Override - public boolean isCorrectMachinePart(ItemStack itemStack) { - return true; - } - - @Override - public int getDamageToComponent(ItemStack itemStack) { - return 0; - } - - @Override - public boolean explodesOnComponentBreak(ItemStack itemStack) { - return false; - } - - @Override - public void explodeMultiblock() {//BEST METHOD EVER!!! - if (!TecTech.ModConfig.BOOM_ENABLE) { - TecTech.proxy.broadcast("Multi Explode BOOM! " + getBaseMetaTileEntity().getXCoord() + " " + getBaseMetaTileEntity().getYCoord() + " " + getBaseMetaTileEntity().getZCoord()); - StackTraceElement[] ste = Thread.currentThread().getStackTrace(); - TecTech.proxy.broadcast("Multi Explode BOOM! " + ste[2].toString()); - return; - } - GT_Pollution.addPollution(new ChunkPosition(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getYCoord(), this.getBaseMetaTileEntity().getZCoord()), 600000); - mInventory[1] = null; - for (MetaTileEntity tTileEntity : mInputBusses) tTileEntity.getBaseMetaTileEntity().doExplosion(V[9]); - for (MetaTileEntity tTileEntity : mOutputBusses) tTileEntity.getBaseMetaTileEntity().doExplosion(V[9]); - for (MetaTileEntity tTileEntity : mInputHatches) tTileEntity.getBaseMetaTileEntity().doExplosion(V[9]); - for (MetaTileEntity tTileEntity : mOutputHatches) tTileEntity.getBaseMetaTileEntity().doExplosion(V[9]); - for (MetaTileEntity tTileEntity : mDynamoHatches) tTileEntity.getBaseMetaTileEntity().doExplosion(V[14]); - for (MetaTileEntity tTileEntity : mMufflerHatches) tTileEntity.getBaseMetaTileEntity().doExplosion(V[9]); - for (MetaTileEntity tTileEntity : mEnergyHatches) tTileEntity.getBaseMetaTileEntity().doExplosion(V[14]); - for (MetaTileEntity tTileEntity : mMaintenanceHatches) tTileEntity.getBaseMetaTileEntity().doExplosion(V[9]); - for (MetaTileEntity tTileEntity : eParamHatches) tTileEntity.getBaseMetaTileEntity().doExplosion(V[9]); - for (MetaTileEntity tTileEntity : eInputHatches) tTileEntity.getBaseMetaTileEntity().doExplosion(V[14]); - for (MetaTileEntity tTileEntity : eOutputHatches) tTileEntity.getBaseMetaTileEntity().doExplosion(V[14]); - for (MetaTileEntity tTileEntity : eMufflerHatches) tTileEntity.getBaseMetaTileEntity().doExplosion(V[14]); - for (MetaTileEntity tTileEntity : eEnergyMulti) tTileEntity.getBaseMetaTileEntity().doExplosion(V[14]); - for (MetaTileEntity tTileEntity : eUncertainHatches) tTileEntity.getBaseMetaTileEntity().doExplosion(V[9]); - for (MetaTileEntity tTileEntity : eDynamoMulti) tTileEntity.getBaseMetaTileEntity().doExplosion(V[14]); - getBaseMetaTileEntity().doExplosion(V[15]); - } - - @Override - public final boolean addToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null) return false; - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) return false; - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch) - ((GT_MetaTileEntity_Hatch) aMetaTileEntity).mMachineBlock = (byte) aBaseCasingIndex; - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) - return mInputHatches.add((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) - return mInputBusses.add((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) - return mOutputHatches.add((GT_MetaTileEntity_Hatch_Output) aMetaTileEntity); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) - return mOutputBusses.add((GT_MetaTileEntity_Hatch_OutputBus) aMetaTileEntity); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy) - return mEnergyHatches.add((GT_MetaTileEntity_Hatch_Energy) aMetaTileEntity); - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo) - return mDynamoHatches.add