From 9a97b84b32c7be83b90fab7d5c08c20279991fec Mon Sep 17 00:00:00 2001 From: Bass Date: Sun, 10 Mar 2019 20:11:38 +0000 Subject: Nevermind merging bROKE SHIT --- .../hatch/GT_MetaTileEntity_Hatch_Capacitor.java | 86 ++++++++++++++++----- .../hatch/gui/GT_Container_Capacitor.java | 53 +++++++++---- .../hatch/gui/GT_GUIContainer_Capacitor.java | 21 +++--- .../multi/GT_MetaTileEntity_TM_teslaCoil.java | 88 ++++++++++++++++++---- 4 files changed, 190 insertions(+), 58 deletions(-) diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Capacitor.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Capacitor.java index 7277819b9b..29b284d8a6 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Capacitor.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_Capacitor.java @@ -20,6 +20,7 @@ import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; import java.util.HashMap; @@ -36,15 +37,32 @@ public class GT_MetaTileEntity_Hatch_Capacitor extends GT_MetaTileEntity_Hatch { private static Textures.BlockIcons.CustomIcon EM_H; private static Textures.BlockIcons.CustomIcon EM_H_ACTIVE; private static Map componentBinds = new HashMap<>(); - private float energyStoredFrac = 0; + public float energyStoredFrac = 0; public GT_MetaTileEntity_Hatch_Capacitor(int aID, String aName, String aNameRegional, int aTier, String descr) { - super(aID, aName, aNameRegional, aTier, 1, descr); + super(aID, aName, aNameRegional, aTier, 16, descr); Util.setTier(aTier,this); } public GT_MetaTileEntity_Hatch_Capacitor(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 1, aDescription, aTextures); + super(aName, aTier, 16, aDescription, aTextures); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setFloat("energyStoredFrac", energyStoredFrac); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + energyStoredFrac = aNBT.getFloat("energyStoredFrac"); + } + + @Override + public int getInventoryStackLimit() { + return 1; } @Override @@ -121,7 +139,7 @@ public class GT_MetaTileEntity_Hatch_Capacitor extends GT_MetaTileEntity_Hatch { @Override public int getSizeInventory() { - return energyStoredFrac >= 0.25 || getBaseMetaTileEntity().isActive() ? 0 : mInventory.length; + return energyStoredFrac > 0.2 || getBaseMetaTileEntity().isActive() ? 0 : mInventory.length; } @Override @@ -133,32 +151,66 @@ public class GT_MetaTileEntity_Hatch_Capacitor extends GT_MetaTileEntity_Hatch { }; } + public long[] getCapacitors() { + long tier = -1; + long tCurrent = 0; + long tEnergyMax = 0; + for (int i = 0; i < mInventory.length; i++) { + if (mInventory[i] == null || mInventory[i].stackSize != 1) { + continue; + } + CapacitorComponent cap = componentBinds.get(getUniqueIdentifier(mInventory[i])); + if (cap != null && cap.tier > tier) { + tier = cap.tier; + } + } + if (tier >= 0) { + for (int i = 0; i < mInventory.length; i++) { + if (mInventory[i] == null || mInventory[i].stackSize != 1) { + continue; + } + CapacitorComponent cap = componentBinds.get(getUniqueIdentifier(mInventory[i])); + if (cap == null) { + continue; + } + if (cap.tier < tier) { + if (getBaseMetaTileEntity().isActive()) { + mInventory[i] = null; + getBaseMetaTileEntity().setOnFire(); + } + } else { + tCurrent = +cap.current; + tEnergyMax = +cap.energyMax; + } + } + } + return new long[]{tier, tCurrent, tEnergyMax}; + } + public static void run() { - new GT_MetaTileEntity_Hatch_Capacitor.CapacitorComponent(Reference.MODID+":tm.teslaCoilCapacitor.0", 0, 1, 1024, 1);//LV Capacitor - new GT_MetaTileEntity_Hatch_Capacitor.CapacitorComponent(Reference.MODID+":tm.teslaCoilCapacitor.1", 1, 1, 1024, 1);//MV Capacitor - new GT_MetaTileEntity_Hatch_Capacitor.CapacitorComponent(Reference.MODID+":tm.teslaCoilCapacitor.2", 2, 1, 1024, 1);//HV Capacitor - new GT_MetaTileEntity_Hatch_Capacitor.CapacitorComponent(Reference.MODID+":tm.teslaCoilCapacitor.3", 3, 1, 1024, 1);//EV Capacitor - new GT_MetaTileEntity_Hatch_Capacitor.CapacitorComponent(Reference.MODID+":tm.teslaCoilCapacitor.4", 4, 1, 1024, 1);//IV Capacitor - new GT_MetaTileEntity_Hatch_Capacitor.CapacitorComponent(Reference.MODID+":tm.teslaCoilCapacitor.5", 5, 1, 1024, 1);//LuV Capacitor - new GT_MetaTileEntity_Hatch_Capacitor.CapacitorComponent(Reference.MODID+":tm.teslaCoilCapacitor.6", 6, 1, 1024, 1);//ZPM Capacitor - new GT_MetaTileEntity_Hatch_Capacitor.CapacitorComponent(Reference.MODID+":tm.teslaCoilCapacitor.7", 7, 1, 1024, 1);//UV Capacitor + new GT_MetaTileEntity_Hatch_Capacitor.CapacitorComponent(Reference.MODID+":item.tm.teslaCoilCapacitor.0", 0, 1, V[0]*512);//LV Capacitor + new GT_MetaTileEntity_Hatch_Capacitor.CapacitorComponent(Reference.MODID+":item.tm.teslaCoilCapacitor.1", 1, 1, V[1]*512);//MV Capacitor + new GT_MetaTileEntity_Hatch_Capacitor.CapacitorComponent(Reference.MODID+":item.tm.teslaCoilCapacitor.2", 2, 1, V[2]*512);//HV Capacitor + new GT_MetaTileEntity_Hatch_Capacitor.CapacitorComponent(Reference.MODID+":item.tm.teslaCoilCapacitor.3", 3, 1, V[3]*512);//EV Capacitor + new GT_MetaTileEntity_Hatch_Capacitor.CapacitorComponent(Reference.MODID+":item.tm.teslaCoilCapacitor.4", 4, 1, V[4]*512);//IV Capacitor + new GT_MetaTileEntity_Hatch_Capacitor.CapacitorComponent(Reference.MODID+":item.tm.teslaCoilCapacitor.5", 5, 1, V[5]*512);//LuV Capacitor + new GT_MetaTileEntity_Hatch_Capacitor.CapacitorComponent(Reference.MODID+":item.tm.teslaCoilCapacitor.6", 6, 1, V[6]*512);//ZPM Capacitor + new GT_MetaTileEntity_Hatch_Capacitor.CapacitorComponent(Reference.MODID+":item.tm.teslaCoilCapacitor.7", 7, 1, V[7]*512);//UV Capacitor } public static class CapacitorComponent implements Comparable { private final String unlocalizedName; private final long tier, current, energyMax; - private final float efficiency; - CapacitorComponent(ItemStack is, long tier, long current, long energyMax, float efficiency) { - this(getUniqueIdentifier(is), tier, current, energyMax, efficiency); + CapacitorComponent(ItemStack is, long tier, long current, long energyMax) { + this(getUniqueIdentifier(is), tier, current, energyMax); } - CapacitorComponent(String is, long tier, long current, long energyMax, float efficiency) { + CapacitorComponent(String is, long tier, long current, long energyMax) { unlocalizedName = is; this.tier = tier; this.current = current; this.energyMax = energyMax; - this.efficiency = efficiency; componentBinds.put(unlocalizedName, this); if (DEBUG_MODE) { TecTech.LOGGER.info("Tesla Capacitor registered: " + unlocalizedName); diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_Container_Capacitor.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_Container_Capacitor.java index f368867736..0b27dc4f04 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_Container_Capacitor.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_Container_Capacitor.java @@ -1,38 +1,61 @@ package com.github.technus.tectech.thing.metaTileEntity.hatch.gui; +import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_Capacitor; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.gui.GT_ContainerMetaTile_Machine; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -/** - * Created by Tec on 09.04.2017. - */ public class GT_Container_Capacitor extends GT_ContainerMetaTile_Machine { + public boolean charged = false; + public GT_Container_Capacitor(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { super(aInventoryPlayer, aTileEntity); } @Override public void addSlots(InventoryPlayer aInventoryPlayer) { - addSlotToContainer(new Slot(mTileEntity, 0, 80, 39)); + this.addSlotToContainer(new Slot(this.mTileEntity, 0, 53, 8)); + this.addSlotToContainer(new Slot(this.mTileEntity, 1, 71, 8)); + this.addSlotToContainer(new Slot(this.mTileEntity, 2, 89, 8)); + this.addSlotToContainer(new Slot(this.mTileEntity, 3, 107, 8)); + this.addSlotToContainer(new Slot(this.mTileEntity, 4, 53, 26)); + this.addSlotToContainer(new Slot(this.mTileEntity, 5, 71, 26)); + this.addSlotToContainer(new Slot(this.mTileEntity, 6, 89, 26)); + this.addSlotToContainer(new Slot(this.mTileEntity, 7, 107, 26)); + this.addSlotToContainer(new Slot(this.mTileEntity, 8, 53, 44)); + this.addSlotToContainer(new Slot(this.mTileEntity, 9, 71, 44)); + this.addSlotToContainer(new Slot(this.mTileEntity, 10, 89, 44)); + this.addSlotToContainer(new Slot(this.mTileEntity, 11, 107, 44)); + this.addSlotToContainer(new Slot(this.mTileEntity, 12, 53, 62)); + this.addSlotToContainer(new Slot(this.mTileEntity, 13, 71, 62)); + this.addSlotToContainer(new Slot(this.mTileEntity, 14, 89, 62)); + this.addSlotToContainer(new Slot(this.mTileEntity, 15, 107, 62)); } @Override - public int getSlotCount() { - return 1; - } + public int getSlotCount() { return 16; } + + @Override + public int getShiftClickSlotCount() { return getSlotCount(); } @Override - public int getShiftClickSlotCount() { - return 1; + public void detectAndSendChanges() { + super.detectAndSendChanges(); + if (mTileEntity.isClientSide() || mTileEntity.getMetaTileEntity() == null) { + return; + } + charged = ((GT_MetaTileEntity_Hatch_Capacitor) mTileEntity.getMetaTileEntity()).energyStoredFrac > 0; } @Override public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { - if (mActive != 0) { + if (charged || mActive != 0) { return null; } return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); @@ -40,7 +63,7 @@ public class GT_Container_Capacitor extends GT_ContainerMetaTile_Machine { @Override public ItemStack transferStackInSlot(EntityPlayer aPlayer, int aSlotIndex) { - if (mActive != 0) { + if (charged || mActive != 0) { return null; } return super.transferStackInSlot(aPlayer, aSlotIndex); @@ -48,7 +71,7 @@ public class GT_Container_Capacitor extends GT_ContainerMetaTile_Machine { @Override public boolean canDragIntoSlot(Slot par1Slot) { - if (mActive != 0) { + if (charged || mActive != 0) { return false; } return super.canDragIntoSlot(par1Slot); @@ -56,7 +79,7 @@ public class GT_Container_Capacitor extends GT_ContainerMetaTile_Machine { @Override public void putStacksInSlots(ItemStack[] par1ArrayOfItemStack) { - if (mActive != 0) { + if (charged || mActive != 0) { return; } super.putStacksInSlots(par1ArrayOfItemStack); @@ -64,7 +87,7 @@ public class GT_Container_Capacitor extends GT_ContainerMetaTile_Machine { @Override protected boolean mergeItemStack(ItemStack aStack, int aStartIndex, int aSlotCount, boolean par4) { - if (mActive != 0) { + if (charged || mActive != 0) { return false; } return super.mergeItemStack(aStack, aStartIndex, aSlotCount, par4); @@ -72,7 +95,7 @@ public class GT_Container_Capacitor extends GT_ContainerMetaTile_Machine { @Override public void putStackInSlot(int par1, ItemStack par2ItemStack) { - if (mActive != 0) { + if (charged || mActive != 0) { return; } super.putStackInSlot(par1, par2ItemStack); diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_GUIContainer_Capacitor.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_GUIContainer_Capacitor.java index fbc34f1e29..3850e7dc30 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_GUIContainer_Capacitor.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/gui/GT_GUIContainer_Capacitor.java @@ -4,17 +4,19 @@ import gregtech.api.gui.GT_GUIContainerMetaTile_Machine; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.InventoryPlayer; -/** - * Created by Tec on 09.04.2017. - */ public class GT_GUIContainer_Capacitor extends GT_GUIContainerMetaTile_Machine { private final String mName; public GT_GUIContainer_Capacitor(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName) { - super(new GT_Container_Capacitor(aInventoryPlayer, aTileEntity), "gregtech:textures/gui/holder.png"); + super(new GT_Container_Capacitor(aInventoryPlayer, aTileEntity), "gregtech:textures/gui/4by4.png"); mName = aName; } + public GT_GUIContainer_Capacitor(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName, String aBackground) { + super(new GT_Container_Capacitor(aInventoryPlayer, aTileEntity), "gregtech:textures/gui/" + aBackground + "4by4.png"); + this.mName = aName; + } + @Override protected void drawGuiContainerForegroundLayer(int par1, int par2) { fontRendererObj.drawString(mName, 8, 4, 4210752); @@ -23,13 +25,8 @@ public class GT_GUIContainer_Capacitor extends GT_GUIContainerMetaTile_Machine { @Override protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { super.drawGuiContainerBackgroundLayer(par1, par2, par3); - int x = (width - xSize) / 2; - int y = (height - ySize) / 2; - drawTexturedModalRect(x, y, 0, 0, xSize, ySize); - if (mContainer != null) { - if (((GT_Container_Capacitor) mContainer).mActive == 1) { - drawTexturedModalRect(x + 151, y + 23, 183, 23, 18, 18); - } - } + int x = (this.width - this.xSize) / 2; + int y = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); } } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java index 4c10b6505c..deecb27feb 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java @@ -57,6 +57,7 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock private long outputVoltage = 0; //Tesla Voltage Output private long outputCurrent = 0; //Tesla Current Output + private long energyCapacity = 0; //Total energy the tower can store public boolean powerPassToggle = false; //Power Pass for public viewing @@ -72,6 +73,10 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock private long outputCurrentParam = 0; private int scanTimeMinParam = 0; + public int vTier = -1; + public int pTier = 0; + public int sTier = 0; + //region structure private static final String[][] shape0 = new String[][]{//3 16 0 {"\u000F", "A . ",}, @@ -140,9 +145,6 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock return new GT_MetaTileEntity_TM_teslaCoil(mName); } - @Override - public void onRemoval(){}//Literally stops this machine from exploding if you break it with some power left, it doesn't deal with any EM ffs - @Override @SideOnly(Side.CLIENT) public void registerIcons(IIconRegister aBlockIconRegister) { @@ -153,7 +155,7 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock @Override public long maxEUStore() { - return V[9] * 2; + return energyCapacity * 2; } @Override @@ -164,9 +166,31 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock return new ITexture[]{Textures.BlockIcons.casingTexturePages[texturePage][4]}; } + @Override + public void onRemoval() { + super.onRemoval(); + for (GT_MetaTileEntity_Hatch_Capacitor cap : eCaps) { + cap.getBaseMetaTileEntity().setActive(false); + } + } + + @Override + public void stopMachine() { + super.stopMachine(); + for (GT_MetaTileEntity_Hatch_Capacitor cap : eCaps) { + cap.getBaseMetaTileEntity().setActive(false); + } + } + @Override public boolean checkMachine_EM(IGregTechTileEntity iGregTechTileEntity, ItemStack itemStack) { + for (GT_MetaTileEntity_Hatch_Capacitor cap : eCaps) { + if (GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(cap)) { + cap.getBaseMetaTileEntity().setActive(false); + } + } eCaps.clear(); + int coilX0 = 0; int coilX1 = 0; int coilX2 = 0; @@ -249,7 +273,15 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock return false; } - return structureCheck_EM(shapes[orientation], blockType, blockMetas[tier], addingMethods, casingTextures, blockTypeFallback, blockMetaFallback, xOffset, yOffset, zOffset); + if (structureCheck_EM(shapes[orientation], blockType, blockMetas[tier], addingMethods, casingTextures, blockTypeFallback, blockMetaFallback, xOffset, yOffset, zOffset) && eCaps.size() > 0) { + for (GT_MetaTileEntity_Hatch_Capacitor cap : eCaps) { + if (GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(cap)) { + cap.getBaseMetaTileEntity().setActive(iGregTechTileEntity.isActive()); + } + } + return true; + } + return false; } @Override @@ -276,17 +308,42 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock public boolean checkRecipe_EM(ItemStack itemStack) { mEfficiencyIncrease = 10000; mMaxProgresstime = 20; + vTier = -1; + long[] capacitorData; + for (GT_MetaTileEntity_Hatch_Capacitor cap : eCaps) { + if (!GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(cap)) { + continue; + } + if (cap.getCapacitors()[0] > vTier) { + vTier = (int) cap.getCapacitors()[0]; + } + } + if(vTier < 0){ return false; } + outputVoltage = V[vTier]; + for (GT_MetaTileEntity_Hatch_Capacitor cap : eCaps) { + if (!GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(cap)) { + continue; + } + capacitorData = cap.getCapacitors(); + if (capacitorData[0] < vTier) { + if(getEUVar() > 0){ + cap.getBaseMetaTileEntity().setToFire(); + } + eCaps.remove(cap); + } else { + cap.getBaseMetaTileEntity().setActive(true); + outputCurrent =+ capacitorData[1]; + energyCapacity =+ capacitorData[2]; + } + } return true; } @Override public boolean onRunningTick(ItemStack aStack) { - IGregTechTileEntity mte = getBaseMetaTileEntity(); - - if (mte.isClientSide()) { + if (getBaseMetaTileEntity().isClientSide()) { return true; } - //Parametrizer hatch loader TODO Add parametrizer detection if (false) { parametrized = true; @@ -309,6 +366,13 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock float energyFrac = (float)energyStored/energyMax; + for (GT_MetaTileEntity_Hatch_Capacitor cap : eCaps) { + if (!GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(cap)) { + continue; + } + cap.energyStoredFrac = energyFrac; + } + //Hysteresis Parameters sanity check if (parametrized && histScaleParam > 0 && histLowParam > 0 && histScaleParam <= histHighParam && histLowParam < histHighParam) { float histLowt = (float)histLowParam/histScaleParam; @@ -351,7 +415,7 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock if (xPosOffset == 0 && yPosOffset == 0 && zPosOffset == 0) { continue; } - IGregTechTileEntity node = mte.getIGregTechTileEntityOffset(xPosOffset, yPosOffset, zPosOffset); + IGregTechTileEntity node = getBaseMetaTileEntity().getIGregTechTileEntityOffset(xPosOffset, yPosOffset, zPosOffset); if (node == null) { continue; } @@ -366,9 +430,6 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock //Stuff to do if ePowerPass if (powerPassToggle) { - outputVoltage = 512;//TODO Generate depending on kind of capacitors - outputCurrent = 1;//TODO Generate depending on count of capacitors - if (parametrized && outputVoltageParam > 0 && outputVoltage > outputVoltageParam){ outputVoltage = outputVoltageParam; } @@ -415,7 +476,6 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock } catch (Exception e) { } } - System.out.println("Something just got purged!"); eTeslaMap.remove(Rx.getKey()); } -- cgit