From 9dc7592301281137ef1cfb4332065c754b691eab Mon Sep 17 00:00:00 2001 From: Technus Date: Sat, 23 Dec 2017 14:51:20 +0100 Subject: draft on em Machine --- .../GT_MetaTileEntity_EM_essentiaDequantizer.java | 4 +- .../GT_MetaTileEntity_EM_essentiaQuantizer.java | 4 +- .../tectech/thing/item/gui/ScanDisplayScreen.java | 21 ++-- .../multi/GT_MetaTileEntity_EM_computer.java | 14 +-- .../multi/GT_MetaTileEntity_EM_decay.java | 4 +- .../multi/GT_MetaTileEntity_EM_dequantizer.java | 4 +- .../multi/GT_MetaTileEntity_EM_infuser.java | 6 +- .../multi/GT_MetaTileEntity_EM_junction.java | 4 +- .../multi/GT_MetaTileEntity_EM_machine.java | 53 +++++++++ .../multi/GT_MetaTileEntity_EM_quantizer.java | 4 +- .../multi/GT_MetaTileEntity_EM_research.java | 4 +- .../multi/GT_MetaTileEntity_EM_scanner.java | 4 +- .../multi/GT_MetaTileEntity_EM_switch.java | 4 +- .../multi/GT_MetaTileEntity_EM_transformer.java | 2 +- .../multi/GT_MetaTileEntity_TM_microwave.java | 4 +- .../base/GT_MetaTileEntity_MultiblockBase_EM.java | 118 ++++++++++++++------- .../multi/base/MultiblockControl.java | 44 ++++++++ 17 files changed, 203 insertions(+), 95 deletions(-) create mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/MultiblockControl.java (limited to 'src/main/java') 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 903729149a..8f4d48b798 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 @@ -101,7 +101,7 @@ public class GT_MetaTileEntity_EM_essentiaDequantizer extends GT_MetaTileEntity_ } @Override - public boolean checkRecipe_EM(ItemStack itemStack, boolean noParametrizationHatches) { + public boolean checkRecipe_EM(ItemStack itemStack, boolean hadNoParametrizationHatches) { container=essentiaContainerCompat.getContainer(this); if (eInputHatches.size() < 1 || container==null) { stopMachine(); @@ -123,8 +123,6 @@ public class GT_MetaTileEntity_EM_essentiaDequantizer extends GT_MetaTileEntity_ } return true; } - mEfficiencyIncrease = 0; - mMaxProgresstime = 0; return false; } 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 c1007ac36a..bb04d81089 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 @@ -110,7 +110,7 @@ public class GT_MetaTileEntity_EM_essentiaQuantizer extends GT_MetaTileEntity_Mu } @Override - public boolean checkRecipe_EM(ItemStack itemStack, boolean noParametrizationHatches) { + public boolean checkRecipe_EM(ItemStack itemStack, boolean hadNoParametrizationHatches) { container=essentiaContainerCompat.getContainer(this); cElementalInstanceStack newStack=essentiaContainerCompat.getFromContainer(container); if(newStack!=null){ @@ -127,8 +127,6 @@ public class GT_MetaTileEntity_EM_essentiaQuantizer extends GT_MetaTileEntity_Mu } return true; } - mEfficiencyIncrease = 0; - mMaxProgresstime = 0; return false; } diff --git a/src/main/java/com/github/technus/tectech/thing/item/gui/ScanDisplayScreen.java b/src/main/java/com/github/technus/tectech/thing/item/gui/ScanDisplayScreen.java index 9b6c336cf6..c35a37a5cf 100644 --- a/src/main/java/com/github/technus/tectech/thing/item/gui/ScanDisplayScreen.java +++ b/src/main/java/com/github/technus/tectech/thing/item/gui/ScanDisplayScreen.java @@ -21,15 +21,14 @@ public class ScanDisplayScreen extends GuiScreen { private final String[] lines; private int firstLine =0; - private static final ResourceLocation[] BACKGROUND1 =new ResourceLocation[]{new ResourceLocation("tectech:textures/gui/scanDisplayScreen1.png"), - new ResourceLocation("tectech:textures/gui/scanDisplayScreen2.png"), - new ResourceLocation("tectech:textures/gui/scanDisplayScreen3.png"), - new ResourceLocation("tectech:textures/gui/scanDisplayScreen4.png"), - new ResourceLocation("tectech:textures/gui/scanDisplayScreen5.png"), - new ResourceLocation("tectech:textures/gui/scanDisplayScreen6.png"), - new ResourceLocation("tectech:textures/gui/scanDisplayScreen7.png"), - new ResourceLocation("tectech:textures/gui/scanDisplayScreen8.png")}; - private static final ResourceLocation BACKGROUND = BACKGROUND1[0]; + private static final ResourceLocation[] BACKGROUNDS =new ResourceLocation[]{new ResourceLocation("tectech:textures/gui/scanDisplayScreen1.png"), + new ResourceLocation("tectech:textures/gui/scanDisplayScreen2.png"), + new ResourceLocation("tectech:textures/gui/scanDisplayScreen3.png"), + new ResourceLocation("tectech:textures/gui/scanDisplayScreen4.png"), + new ResourceLocation("tectech:textures/gui/scanDisplayScreen5.png"), + new ResourceLocation("tectech:textures/gui/scanDisplayScreen6.png"), + new ResourceLocation("tectech:textures/gui/scanDisplayScreen7.png"), + new ResourceLocation("tectech:textures/gui/scanDisplayScreen8.png")}; private static final ResourceLocation ITEM =new ResourceLocation("tectech:textures/gui/scanDisplayItem.png"); public ScanDisplayScreen(EntityPlayer player){ @@ -45,7 +44,7 @@ public class ScanDisplayScreen extends GuiScreen { long tick=System.currentTimeMillis()/150; int itick=(int)(tick%12); drawTexturedModalRect(baseX+99,baseY+189,32*(itick/6),32*(itick%6), 32, 32); - this.mc.getTextureManager().bindTexture(BACKGROUND1[(int)(tick%8)]); + this.mc.getTextureManager().bindTexture(BACKGROUNDS[(int)(tick%8)]); drawTexturedModalRect(baseX,baseY,0,0, sizeX, sizeY); glDisable(GL_BLEND); super.drawScreen(x,y,partialTicks); @@ -132,7 +131,7 @@ public class ScanDisplayScreen extends GuiScreen { this.field_146123_n = xPos >= this.xPosition && yPos >= this.yPosition && xPos < this.xPosition + this.width && yPos < this.yPosition + this.height; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - mc.getTextureManager().bindTexture(BACKGROUND); + mc.getTextureManager().bindTexture(BACKGROUNDS[0]); drawTexturedModalRect(this.xPosition, this.yPosition, u + this.getHoverState(this.field_146123_n) * 80, v, this.width, this.height); glDisable(GL_BLEND); GL11.glEnable(GL11.GL_BLEND); 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 4db4c1096a..0c80e315ab 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 @@ -64,13 +64,13 @@ public class GT_MetaTileEntity_EM_computer extends GT_MetaTileEntity_MultiblockB public GT_MetaTileEntity_EM_computer(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); eCertainMode = 5; - eCertainStatus = -128;//no-brainer value + eCertainStatus = -128;//no-brain value } public GT_MetaTileEntity_EM_computer(String aName) { super(aName); eCertainMode = 5; - eCertainStatus = -128;//no-brainer value + eCertainStatus = -128;//no-brain value } public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { @@ -94,18 +94,16 @@ public class GT_MetaTileEntity_EM_computer extends GT_MetaTileEntity_MultiblockB } @Override - public boolean checkRecipe_EM(ItemStack itemStack, boolean noParametrizationHatches) { + public boolean checkRecipe_EM(ItemStack itemStack, boolean hadNoParametrizationHatches) { eAvailableData = 0; maxCurrentTemp = 0; double overClockRatio,overVoltageRatio; - if (noParametrizationHatches) { + if (hadNoParametrizationHatches) { overVoltageRatio=overClockRatio=1; } else { overClockRatio= getParameterIn(0,0); overVoltageRatio= getParameterIn(0,1); if(Double.isNaN(overClockRatio) || Double.isNaN(overVoltageRatio)) { - mMaxProgresstime = 0; - mEfficiencyIncrease = 0; for (GT_MetaTileEntity_Hatch_Rack r : eRacks) r.getBaseMetaTileEntity().setActive(false);//todo might be not needed return false; @@ -117,8 +115,6 @@ public class GT_MetaTileEntity_EM_computer extends GT_MetaTileEntity_MultiblockB mEUt = -(int)eut; else{ mEUt = -(int)V[8]; - mMaxProgresstime = 0; - mEfficiencyIncrease = 0; for (GT_MetaTileEntity_Hatch_Rack r : eRacks) r.getBaseMetaTileEntity().setActive(false);//todo might be not needed return false; @@ -156,8 +152,6 @@ public class GT_MetaTileEntity_EM_computer extends GT_MetaTileEntity_MultiblockB return true; } } - mMaxProgresstime = 0; - mEfficiencyIncrease = 0; for (GT_MetaTileEntity_Hatch_Rack r : eRacks) r.getBaseMetaTileEntity().setActive(false); return false; 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 b3f56a5bf5..9410842520 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 @@ -111,13 +111,11 @@ public class GT_MetaTileEntity_EM_decay extends GT_MetaTileEntity_MultiblockBase } @Override - public boolean checkRecipe_EM(ItemStack itemStack, boolean noParametrizationHatches) { + public boolean checkRecipe_EM(ItemStack itemStack, boolean hadNoParametrizationHatches) { cElementalInstanceStackMap map= getInputsClone_EM(); if(map!=null && map.hasStacks() && map.getFirst().getLifeTime()< STABLE_RAW_LIFE_TIME){ return startRecipe(map.getFirst()); } - mEfficiencyIncrease = 0; - mMaxProgresstime = 0; return false; } 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 a94f092cf0..48353603f8 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 @@ -83,7 +83,7 @@ public class GT_MetaTileEntity_EM_dequantizer extends GT_MetaTileEntity_Multiblo } @Override - public boolean checkRecipe_EM(ItemStack itemStack, boolean noParametrizationHatches) { + public boolean checkRecipe_EM(ItemStack itemStack, boolean hadNoParametrizationHatches) { for (GT_MetaTileEntity_Hatch_InputElemental in : eInputHatches) { cElementalInstanceStackMap map = in.getContainerHandler(); for (cElementalInstanceStack stack : map.values()) { @@ -118,8 +118,6 @@ public class GT_MetaTileEntity_EM_dequantizer extends GT_MetaTileEntity_Multiblo } } } - mEfficiencyIncrease = 0; - mMaxProgresstime = 0; return false; } 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 0f27bd746e..d86cce6170 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 @@ -92,7 +92,7 @@ public class GT_MetaTileEntity_EM_infuser extends GT_MetaTileEntity_MultiblockBa } @Override - public boolean checkRecipe_EM(ItemStack itemStack, boolean noParametrizationHatches) { + public boolean checkRecipe_EM(ItemStack itemStack, boolean hadNoParametrizationHatches) { if (itemStack != null && itemStack.stackSize == 1) { Item ofThis = itemStack.getItem(); if (ofThis instanceof IElectricItem) { @@ -105,10 +105,6 @@ public class GT_MetaTileEntity_EM_infuser extends GT_MetaTileEntity_MultiblockBa return true; } } - mEfficiencyIncrease = 0; - mMaxProgresstime = 0; - eAmpereFlow = 0; - mEUt = 0; return false; } 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 7a178a692f..91163d5c6d 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 @@ -104,7 +104,7 @@ public class GT_MetaTileEntity_EM_junction extends GT_MetaTileEntity_MultiblockB } @Override - public boolean checkRecipe_EM(ItemStack itemStack, boolean noParametrizationHatches) { + public boolean checkRecipe_EM(ItemStack itemStack, boolean hadNoParametrizationHatches) { for (GT_MetaTileEntity_Hatch_InputElemental in : eInputHatches) if (in.getContainerHandler().hasStacks()) { mEUt = -(int) V[8]; @@ -113,8 +113,6 @@ public class GT_MetaTileEntity_EM_junction extends GT_MetaTileEntity_MultiblockB mEfficiencyIncrease = 10000; return true; } - mMaxProgresstime = 0; - mEfficiencyIncrease = 0; return false; } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_machine.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_machine.java index 3c1986d635..6e5a16f5a5 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_machine.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_machine.java @@ -1,16 +1,24 @@ package com.github.technus.tectech.thing.metaTileEntity.multi; import com.github.technus.tectech.CommonValues; +import com.github.technus.tectech.elementalMatter.core.cElementalInstanceStackMap; 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.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.MultiblockControl; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.GT_ItemStack; import gregtech.common.blocks.GT_Block_Machines; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; +import java.util.ArrayList; +import java.util.HashMap; + import static com.github.technus.tectech.Util.StructureBuilder; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.textureOffset; import static com.github.technus.tectech.thing.casing.TT_Container_Casings.sBlockCasingsTT; @@ -81,4 +89,49 @@ public class GT_MetaTileEntity_EM_machine extends GT_MetaTileEntity_MultiblockBa EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + "the time u started using it." }; } + + @Override + public boolean checkRecipe_EM(ItemStack itemStack, boolean hadNoParametrizationHatches) { + Behaviour currentBehaviour=map.get(new GT_ItemStack(itemStack)); + if(currentBehaviour==null) return false; + //mux input + cElementalInstanceStackMap[] handles=new cElementalInstanceStackMap[3]; + if(hadNoParametrizationHatches){ + try { + handles[0] = eInputHatches.get(0).getContainerHandler(); + handles[1] = eInputHatches.get(1).getContainerHandler(); + handles[2] = eInputHatches.get(2).getContainerHandler(); + }catch (Exception ignored){} + }else{ + try { + + }catch (Exception ignored){} + } + MultiblockControl control=currentBehaviour.process(handles, hadNoParametrizationHatches); + if(control==null) return false; + outputEM=control.getValues(); + mEUt=control.getEUT(); + eAmpereFlow=control.getAmperage(); + mMaxProgresstime=control.getMaxProgressTime(); + eRequiredData=control.getRequiredData(); + mEfficiencyIncrease=control.getEffIncrease(); + return true; + } + + @Override + public void outputAfterRecipe_EM() { + //mux output + //output + } + + private static final HashMap map=new HashMap<>(); + public abstract class Behaviour { + public Behaviour(ItemStack... keyItems){ + for(ItemStack is:keyItems){ + map.put(new GT_ItemStack(is.getItem(),1,is.getItemDamage()),this); + } + } + + public abstract MultiblockControl process(cElementalInstanceStackMap[] inputs, boolean noParametrizationHatches, double... parameters); + } } 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 7357a141f1..f06ce1ba82 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 @@ -92,7 +92,7 @@ public class GT_MetaTileEntity_EM_quantizer extends GT_MetaTileEntity_Multiblock } @Override - public boolean checkRecipe_EM(ItemStack itemStack, boolean noParametrizationHatches) {//TODO implement by item quantization, implement instance quantization + public boolean checkRecipe_EM(ItemStack itemStack, boolean hadNoParametrizationHatches) {//TODO implement by item quantization, implement instance quantization if (GregTech_API.sPostloadFinished) { ItemStack[] inI = getStoredInputs().toArray(new ItemStack[0]); if (inI.length > 0) { @@ -144,8 +144,6 @@ public class GT_MetaTileEntity_EM_quantizer extends GT_MetaTileEntity_Multiblock } } } - mEfficiencyIncrease = 0; - mMaxProgresstime = 0; return false; } 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 4dfb4f7b6c..ccd5bc79e4 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 @@ -177,7 +177,7 @@ public class GT_MetaTileEntity_EM_research extends GT_MetaTileEntity_MultiblockB } @Override - public boolean checkRecipe_EM(ItemStack itemStack, boolean noParametrizationHatches) { + public boolean checkRecipe_EM(ItemStack itemStack, boolean hadNoParametrizationHatches) { tRecipe=null; aRecipe=null; if(eHolders.size()>0 && eHolders.get(0).mInventory[0]!=null) { @@ -244,8 +244,6 @@ public class GT_MetaTileEntity_EM_research extends GT_MetaTileEntity_MultiblockB } holdItem=null; computationRequired=computationRemaining=0; - mMaxProgresstime=0; - mEfficiencyIncrease = 0; for (GT_MetaTileEntity_Hatch_Holder r : eHolders) r.getBaseMetaTileEntity().setActive(false); return false; 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 d286869a0c..c2b9f3a13f 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 @@ -195,7 +195,7 @@ public class GT_MetaTileEntity_EM_scanner extends GT_MetaTileEntity_MultiblockBa } @Override - public boolean checkRecipe_EM(ItemStack itemStack, boolean noParametrizationHatches) { + public boolean checkRecipe_EM(ItemStack itemStack, boolean hadNoParametrizationHatches) { eRecipe=null; if(eInputHatches.size()>0 && eInputHatches.get(0).getContainerHandler().hasStacks() && !eOutputHatches.isEmpty()) { cElementalInstanceStackMap researchEM = eInputHatches.get(0).getContainerHandler(); @@ -276,8 +276,6 @@ public class GT_MetaTileEntity_EM_scanner extends GT_MetaTileEntity_MultiblockBa quantumStuff(false); objectResearched=null; totalComputationRemaining =0; - mMaxProgresstime=0; - mEfficiencyIncrease = 0; return false; } 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 9a16035d49..cef1965174 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 @@ -80,7 +80,7 @@ public class GT_MetaTileEntity_EM_switch extends GT_MetaTileEntity_MultiblockBas } @Override - public boolean checkRecipe_EM(ItemStack itemStack, boolean noParametrizationHatches) { + public boolean checkRecipe_EM(ItemStack itemStack, boolean hadNoParametrizationHatches) { short thingsActive = 0; for (GT_MetaTileEntity_Hatch_InputData di : eInputData) if (di.q != null) @@ -94,8 +94,6 @@ public class GT_MetaTileEntity_EM_switch extends GT_MetaTileEntity_MultiblockBas mEfficiencyIncrease = 10000; return true; } - mMaxProgresstime = 0; - mEfficiencyIncrease = 0; return false; } 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 7285340215..a5d6d6ad8c 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 @@ -112,7 +112,7 @@ public class GT_MetaTileEntity_EM_transformer extends GT_MetaTileEntity_Multiblo } @Override - public boolean checkRecipe_EM(ItemStack itemStack, boolean noParametrizationHatches) { + public boolean checkRecipe_EM(ItemStack itemStack, boolean hadNoParametrizationHatches) { if (ePowerPass) { mEfficiencyIncrease = 10000; mMaxProgresstime = 20; 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 03ac34a3d3..65ebabb7ac 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 @@ -155,9 +155,9 @@ public class GT_MetaTileEntity_TM_microwave extends GT_MetaTileEntity_Multiblock } @Override - public boolean checkRecipe_EM(ItemStack itemStack, boolean noParametrizationHatches) { + public boolean checkRecipe_EM(ItemStack itemStack, boolean hadNoParametrizationHatches) { hasBeenPausedThisCycle =false; - if(noParametrizationHatches){ + if(hadNoParametrizationHatches){ powerSetting=POWER_SETTING_DEFAULT; timerSetting=TIMER_SETTING_DEFAULT; } 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 c955466138..972d2df54e 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 @@ -94,7 +94,7 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt protected long eRequiredData = 0; // data required to operate protected long eAvailableData = 0; // data being available - private boolean explodedThisTick=false; + private boolean explodedThisTick=false, eHadNoParametrizationHatches = true; //init param states in constructor, or implement it in checkrecipe/outputfunction @@ -103,7 +103,7 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt //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 checkRecipe_EM(ItemStack itemStack, boolean noParametrizationHatches) { + public boolean checkRecipe_EM(ItemStack itemStack, boolean hadNoParametrizationHatches) { return false; } // My code handles AMPS, if you want overclocking just modify mEUt and mMaxProgressTime, leave amps as usual! @@ -122,7 +122,7 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt // (Well it can be overflowed if machine didn't finished, soft-hammered/disabled/not enough EU) // Setting available data processing - protected void hatchInit_EM() { + protected void hatchInit_EM(boolean mMachine) { }//For extra types of hatches initiation, LOOK HOW IT IS CALLED! onPostTick protected void extraExplosions_EM() { @@ -158,13 +158,44 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt return 0; } - //triggered if machine is not allowed to work after completing a recipe + //helper method so i don't have to set that params to nothing at all times + protected void afterRecipeCheckFailed(){ + if (outputEM != null) { + float mass = 0; + for (cElementalInstanceStackMap tree : outputEM) + mass += tree.getMass(); + if (mass > 0) { + if (eMufflerHatches.size() < 1) explodeMultiblock(); + else { + mass /= eMufflerHatches.size(); + for (GT_MetaTileEntity_Hatch_MufflerElemental dump : eMufflerHatches) + if (dump.addOverflowMatter(mass)) explodeMultiblock(); + } + } + outputEM = null; + } + + for (GT_MetaTileEntity_Hatch_OutputData data : eOutputData) + data.q = null; + + mOutputItems = null; + mOutputFluids = null; + mEfficiency = 0; + mEfficiencyIncrease = 0; + mProgresstime = 0; + //mMaxProgresstime = 0; //Done after this - cos it is VITAL! + eAvailableData = 0; + //getBaseMetaTileEntity().disableWorking(); + //hatchesStatusUpdate_EM(); //called always after recipe checks + } + + //triggered if machine is not allowed to work after completing a recipe, override to make it not shutdown for instance (like turbines). protected void notAllowedToWork_stopMachine_EM(){ stopMachine(); } //Override if needed but usually call super method at start! - //On machine stop - NOT called when softhammered to offline state! - it SHOULD cause a full stop like power failure does + //On machine stop - NOT called directly when softhammered to offline state! - it SHOULD cause a full stop like power failure does @Override public void stopMachine() { if (outputEM != null) { @@ -188,11 +219,12 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt mOutputItems = null; mOutputFluids = null; mEfficiency = 0; + mEfficiencyIncrease = 0; mProgresstime = 0; mMaxProgresstime = 0; - mEfficiencyIncrease = 0; - getBaseMetaTileEntity().disableWorking(); + eAvailableData = 0; hatchesStatusUpdate_EM(); + getBaseMetaTileEntity().disableWorking(); } @Override @@ -267,6 +299,7 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt aNBT.setBoolean("eVoid", eSafeVoid); aNBT.setBoolean("eBoom", eDismantleBoom); aNBT.setBoolean("eOK", mMachine); + aNBT.setBoolean("eHadNoParam", eHadNoParametrizationHatches); //Ensures compatibility if (mOutputItems != null) { @@ -345,6 +378,7 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt eSafeVoid = aNBT.getBoolean("eVoid"); eDismantleBoom = aNBT.getBoolean("eBoom"); mMachine = aNBT.getBoolean("eOK"); + eHadNoParametrizationHatches = aNBT.getBoolean("eHadNoParam"); //Ensures compatibility int aOutputItemsLength = aNBT.getInteger("mOutputItemsLength"); @@ -597,13 +631,14 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt if(hatch.param>=0) bParamsAreFloats[hatch.param]=hatch.isUsingFloats(); } } + eHadNoParametrizationHatches &=eParamHatches.size()==0; } else { maxEUinputMin = 0; maxEUinputMax = 0; eMaxAmpereFlow = 0; this.setEUVar(0); } - hatchInit_EM(); + hatchInit_EM(mMachine); } if (mStartUpCheck < 0) {//E @@ -744,7 +779,8 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt if (checkRecipe(mInventory[1])) { mEfficiency = Math.max(0, Math.min(mEfficiency + mEfficiencyIncrease, getMaxEfficiency(mInventory[1]) - ((getIdealStatus() - getRepairStatus()) * 1000))); }else { - mMaxProgresstime=0; + afterRecipeCheckFailed(); + mMaxProgresstime=0;//Just to be sure... } updateSlots(); } else notAllowedToWork_stopMachine_EM(); @@ -757,7 +793,8 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt if (checkRecipe(mInventory[1])) { mEfficiency = Math.max(0, Math.min(mEfficiency + mEfficiencyIncrease, getMaxEfficiency(mInventory[1]) - ((getIdealStatus() - getRepairStatus()) * 1000))); }else { - mMaxProgresstime=0; + afterRecipeCheckFailed(); + mMaxProgresstime=0;//Just to be sure... } updateSlots(); } //else notAllowedToWork_stopMachine_EM(); //it is already stopped here @@ -815,19 +852,19 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt @Override public boolean onRunningTick(ItemStack aStack) { if (eRequiredData > eAvailableData) { - if(energyFlow(aStack,false)) + if(energyFlowOnRunningTick(aStack,false)) stopMachine(); return false; } - return energyFlow(aStack,true); + return energyFlowOnRunningTick(aStack,true); } //new method - private boolean energyFlow(ItemStack aStack,boolean allowProduction) { - long temp = mEUt * eAmpereFlow;//quick scope sign - if (allowProduction && temp > 0) { + private boolean energyFlowOnRunningTick(ItemStack aStack, boolean allowProduction) { + long euFlow = mEUt * eAmpereFlow;//quick scope sign + if (allowProduction && euFlow > 0) { this.addEnergyOutput_EM((long) mEUt * (long) mEfficiency / getMaxEfficiency(aStack), eAmpereFlow); - } else if (temp < 0) { + } else if (euFlow < 0) { if (!this.drainEnergyInput_EM(mEUt,(long) mEUt * getMaxEfficiency(aStack) / Math.max(1000L, this.mEfficiency), eAmpereFlow)) { stopMachine(); return false; @@ -837,18 +874,18 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt } //region energy - public final boolean energyFlowWithoutEffieciencyComputation(int eu,long ampere) { - long temp = eu * ampere;//quick scope sign - if (temp > 0) { - this.addEnergyOutput_EM(eu, ampere); - } else if (temp < 0) { - if (!this.drainEnergyInput_EM(eu,eu, ampere)) { - stopMachine(); - return false; - } - } - return true; - } + //public final boolean energyFlowWithoutEffieciencyComputation(int eu,long ampere) { + // long temp = eu * ampere;//quick scope sign + // if (temp > 0) { + // this.addEnergyOutput_EM(eu, ampere); + // } else if (temp < 0) { + // if (!this.drainEnergyInput_EM(eu,eu, ampere)) { + // stopMachine(); + // return false; + // } + // } + // return true; + //} @Override public final long maxEUStore() { @@ -940,17 +977,17 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt return false; } - private boolean drainEnergyInput_EM(long EUt, long EUtEff, long Amperes) { - if(EUt<0) EUt=-EUt; - if(EUtEff<0) EUtEff=-EUtEff; + private boolean drainEnergyInput_EM(long EUtTierVoltage, long EUtEffective, long Amperes) { + if(EUtTierVoltage<0) EUtTierVoltage=-EUtTierVoltage; + if(EUtEffective<0) EUtEffective=-EUtEffective; if(Amperes<0) Amperes=-Amperes; - long EUuse = EUtEff * Amperes; + long EUuse = EUtEffective * Amperes; if (EUuse > getEUVar() || //not enough power - EUt > maxEUinputMax || //TIER IS BASED ON BEST HATCH! not total EUtEff input - ((EUt*Amperes) - 1) / maxEUinputMin + 1 > eMaxAmpereFlow) {// EUuse==0? --> (EUuse - 1) / maxEUinputMin + 1 = 1! //if not too much A + EUtTierVoltage > maxEUinputMax || //TIER IS BASED ON BEST HATCH! not total EUtEffective input + ((EUtTierVoltage*Amperes) - 1) / maxEUinputMin + 1 > eMaxAmpereFlow) {// EUuse==0? --> (EUuse - 1) / maxEUinputMin + 1 = 1! //if not too much A if (DEBUG_MODE) { TecTech.Logger.debug("L1 " + EUuse + " " + getEUVar() + " " + (EUuse > getEUVar())); - TecTech.Logger.debug("L2 " + EUtEff + " " + maxEUinputMax + " " + (EUtEff > maxEUinputMax)); + TecTech.Logger.debug("L2 " + EUtEffective + " " + maxEUinputMax + " " + (EUtEffective > maxEUinputMax)); TecTech.Logger.debug("L3 " + EUuse + " " + eMaxAmpereFlow); TecTech.Logger.debug("L4 " + ((EUuse - 1) / maxEUinputMin + 1) + " " + eMaxAmpereFlow + " " + ((EUuse - 1) / maxEUinputMin + 1 > eMaxAmpereFlow)); } @@ -1100,7 +1137,7 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt if (outputEM == null) return; float mass = 0; for (cElementalInstanceStackMap map : outputEM) - mass = map.removeOverflow(0, 0); + mass += map.getMass(); if (mass > 0) { if (eMufflerHatches.size() < 1) explodeMultiblock(); @@ -1115,7 +1152,9 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt @Override public final boolean checkRecipe(ItemStack itemStack) {//do recipe checks, based on "machine content and state" hatchesStatusUpdate_EM(); - return checkRecipe_EM(itemStack, eParamHatches.size()==0); + boolean result= checkRecipe_EM(itemStack, eHadNoParametrizationHatches);//if had no - set default params + hatchesStatusUpdate_EM(); + return result; } private void hatchesStatusUpdate_EM() { @@ -1129,7 +1168,7 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt hatch.input0i = iParamsOut[paramID]; hatch.input1i = iParamsOut[paramID + 10]; } - }else {//write only + }else {//write to hatches only for (GT_MetaTileEntity_Hatch_Param hatch : eParamHatches) { if (!isValidMetaTileEntity(hatch) || hatch.param < 0) continue; final int paramID = hatch.param; @@ -1225,7 +1264,8 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt for (GT_MetaTileEntity_Hatch_Param hatch : eParamHatches) hatch.getBaseMetaTileEntity().setActive(false); } - if ((ePowerPass && getEUVar()>V[3]) || (eDismantleBoom && mMaxProgresstime > 0 && areChunksAroundLoaded_EM())) explodeMultiblock(); + if ((ePowerPass && getEUVar()>V[3]) || (eDismantleBoom && mMaxProgresstime > 0 && areChunksAroundLoaded_EM())) + explodeMultiblock(); if (outputEM != null) for (cElementalInstanceStackMap output : outputEM) if (output.hasStacks()) explodeMultiblock(); diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/MultiblockControl.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/MultiblockControl.java new file mode 100644 index 0000000000..bc5e1b387b --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/MultiblockControl.java @@ -0,0 +1,44 @@ +package com.github.technus.tectech.thing.metaTileEntity.multi.base; + +/** + * Created by danie_000 on 23.12.2017. + */ + +public class MultiblockControl{ + private final int[] controls; + private final T[] values; + + public MultiblockControl(T[] values, int EUt, int amperes, int requiredData, int effIncrease, int maxProgressTime){ + this.values = values; + controls=new int[5]; + controls[0]=EUt; + controls[1]=amperes; + controls[2]=requiredData; + controls[3]=effIncrease; + controls[4]=maxProgressTime; + } + + public T[] getValues() { + return values; + } + + public int getEUT(){ + return controls[0]; + } + + public int getAmperage(){ + return controls[1]; + } + + public int getRequiredData(){ + return controls[2]; + } + + public int getEffIncrease(){ + return controls[3]; + } + + public int getMaxProgressTime(){ + return controls[4]; + } +} -- cgit