diff options
author | Alkalus <draknyte1@hotmail.com> | 2017-11-15 05:28:56 +1000 |
---|---|---|
committer | Alkalus <draknyte1@hotmail.com> | 2017-11-15 05:28:56 +1000 |
commit | 04118a76458b4e6c886454081dd3695b62660f80 (patch) | |
tree | e1811dac86275d3b20f1744c3af7f6285fb4f4a2 /src | |
parent | f5f5d246723fce0aaa01bf72d47bb2120d9eb5d1 (diff) | |
download | GT5-Unofficial-04118a76458b4e6c886454081dd3695b62660f80.tar.gz GT5-Unofficial-04118a76458b4e6c886454081dd3695b62660f80.tar.bz2 GT5-Unofficial-04118a76458b4e6c886454081dd3695b62660f80.zip |
$ Fixed Charge Hatches not having the correct amount of inputs.
$ Fixed Charge Hatches correctly handling electric items.
Diffstat (limited to 'src')
4 files changed, 222 insertions, 25 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBattery.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBattery.java index d0201c64d1..24a92fd628 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBattery.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBattery.java @@ -1,5 +1,8 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; +import static gregtech.api.enums.GT_Values.V; + +import gregtech.api.enums.GT_Values; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -7,7 +10,9 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.util.Utils; import gtPlusPlus.xmod.gregtech.api.gui.hatches.charge.CONTAINER_Electric_2by2; import gtPlusPlus.xmod.gregtech.api.gui.hatches.charge.CONTAINER_Electric_4by4; import gtPlusPlus.xmod.gregtech.api.gui.hatches.charge.GUI_Electric_2by2; @@ -18,8 +23,8 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; public class GT_MetaTileEntity_Hatch_InputBattery - extends - GT_MetaTileEntity_Hatch { +extends +GT_MetaTileEntity_Hatch { public GT_Recipe_Map mRecipeMap = null; public GT_MetaTileEntity_Hatch_InputBattery(int aID, String aName, @@ -34,17 +39,48 @@ public class GT_MetaTileEntity_Hatch_InputBattery String aDescription, ITexture[][][] aTextures) { super(aName, aTier, aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 4 : 16, - aDescription, aTextures); + aDescription, aTextures); } public GT_MetaTileEntity_Hatch_InputBattery(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { super(aName, aTier, aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 4 : 16, - aDescription, aTextures); + aDescription, aTextures); } @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isInputFacing(byte aSide) { + return aSide == getBaseMetaTileEntity().getFrontFacing(); + } + + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUInput() { + return V[mTier]; + } + + @Override + public long maxEUStore() { + return 512 + V[mTier + 1] * 16; + } + + @Override + public long maxAmperesIn() { + return 4; + } + + @Override public ITexture[] getTexturesActive(ITexture aBaseTexture) { return new ITexture[]{aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Charger)}; @@ -110,7 +146,7 @@ public class GT_MetaTileEntity_Hatch_InputBattery @Override public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - switch (mInventory.length) { + switch (mTier) { case 2 : return new GUI_Electric_2by2(aPlayerInventory, aBaseMetaTileEntity, "Charging Bus"); @@ -124,12 +160,34 @@ public class GT_MetaTileEntity_Hatch_InputBattery } @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, - long aTimer) { + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { fillStacksIntoFirstSlots(); } + if (aBaseMetaTileEntity.isServerSide()){ + if (aBaseMetaTileEntity.getMetaTileEntity() instanceof MetaTileEntity) { + MetaTileEntity mMetaTileEntity = (MetaTileEntity) aBaseMetaTileEntity.getMetaTileEntity(); + if (mMetaTileEntity.rechargerSlotCount() > 0 && aBaseMetaTileEntity.getStoredEU() > 0) { + for (int i = mMetaTileEntity.rechargerSlotStartIndex(), k = mMetaTileEntity.rechargerSlotCount() + i; i < k; i++) { + if (aBaseMetaTileEntity.getStoredEU() > 0 && mMetaTileEntity.mInventory[i] != null) { + for (int u=0;u<10;u++){ + aBaseMetaTileEntity.decreaseStoredEnergyUnits(GT_ModHandler.chargeElectricItem(mMetaTileEntity.mInventory[i], (int) Math.min(V[this.mTier] * 15, aBaseMetaTileEntity.getStoredEU()), (int) Math.min(Integer.MAX_VALUE, GT_Values.V[u]), false, false), true); + if (mMetaTileEntity.mInventory[i].stackSize <= 0){ + mMetaTileEntity.mInventory[i] = null; + } + } + } + } + } + else { + //Utils.LOG_INFO("reCharger Slot Count = "+mMetaTileEntity.rechargerSlotCount()); + //Utils.LOG_INFO("getStoredEU = "+aBaseMetaTileEntity.getStoredEU()); + //Utils.LOG_INFO("getEUVar = "+mMetaTileEntity.getEUVar()); + } + } + } + super.onPostTick(aBaseMetaTileEntity, aTimer); } public void updateSlots() { @@ -143,8 +201,8 @@ public class GT_MetaTileEntity_Hatch_InputBattery for (int i = 0; i < mInventory.length; i++) for (int j = i + 1; j < mInventory.length; j++) if (mInventory[j] != null - && (mInventory[i] == null || GT_Utility.areStacksEqual( - mInventory[i], mInventory[j]))) { + && (mInventory[i] == null || GT_Utility.areStacksEqual( + mInventory[i], mInventory[j]))) { GT_Utility.moveStackFromSlotAToSlotB( getBaseMetaTileEntity(), getBaseMetaTileEntity(), j, i, (byte) 64, (byte) 1, (byte) 64, (byte) 1); @@ -164,4 +222,27 @@ public class GT_MetaTileEntity_Hatch_InputBattery return aSide == getBaseMetaTileEntity().getFrontFacing() && (mRecipeMap == null || mRecipeMap.containsInput(aStack)); } + + public int rechargerSlotStartIndex() { + return 0; + } + + public int rechargerSlotCount() { + switch (mTier) { + case 2 : + return 4; + case 4 : + return 16; + default : + return 16; + } + } + + public int dechargerSlotStartIndex() { + return 0; + } + + public int dechargerSlotCount() { + return 0; + } } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBattery.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBattery.java index 62fef4dac3..5dd333e2fa 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBattery.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBattery.java @@ -1,12 +1,16 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; +import static gregtech.api.enums.GT_Values.V; + import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.util.Utils; import gtPlusPlus.xmod.gregtech.api.gui.hatches.charge.CONTAINER_Electric_2by2; import gtPlusPlus.xmod.gregtech.api.gui.hatches.charge.CONTAINER_Electric_4by4; import gtPlusPlus.xmod.gregtech.api.gui.hatches.charge.GUI_Electric_2by2; @@ -17,8 +21,8 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; public class GT_MetaTileEntity_Hatch_OutputBattery - extends - GT_MetaTileEntity_Hatch { +extends +GT_MetaTileEntity_Hatch { public GT_MetaTileEntity_Hatch_OutputBattery(int aID, String aName, String aNameRegional, int aTier) { super(aID, aName, aNameRegional, aTier, getSlots(aTier), @@ -31,14 +35,39 @@ public class GT_MetaTileEntity_Hatch_OutputBattery String aDescription, ITexture[][][] aTextures) { super(aName, aTier, aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 9 : 16, - aDescription, aTextures); + aDescription, aTextures); } public GT_MetaTileEntity_Hatch_OutputBattery(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { super(aName, aTier, aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 9 : 16, - aDescription, aTextures); + aDescription, aTextures); + } + + @Override + public boolean isEnetOutput() { + return true; + } + + @Override + public boolean isOutputFacing(byte aSide) { + return aSide == getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUOutput() { + return V[mTier]; + } + + @Override + public long maxEUStore() { + return 512 + V[mTier + 1] * 8; } @Override @@ -143,11 +172,55 @@ public class GT_MetaTileEntity_Hatch_OutputBattery for (int i = 0; i < mInventory.length; i++) for (int j = i + 1; j < mInventory.length; j++) if (mInventory[j] != null - && (mInventory[i] == null || GT_Utility.areStacksEqual( - mInventory[i], mInventory[j]))) { + && (mInventory[i] == null || GT_Utility.areStacksEqual( + mInventory[i], mInventory[j]))) { GT_Utility.moveStackFromSlotAToSlotB( getBaseMetaTileEntity(), getBaseMetaTileEntity(), j, i, (byte) 64, (byte) 1, (byte) 64, (byte) 1); } } + + public int rechargerSlotStartIndex() { + return 0; + } + + public int rechargerSlotCount() { + return 0; + } + + public int dechargerSlotStartIndex() { + return 0; + } + + public int dechargerSlotCount() { + return mTier == 2 ? 4 : 16; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (aBaseMetaTileEntity.isServerSide() + && aBaseMetaTileEntity.hasInventoryBeenModified()) { + fillStacksIntoFirstSlots(); + } + + if (aBaseMetaTileEntity.isServerSide()){ + if (aBaseMetaTileEntity.getMetaTileEntity() instanceof MetaTileEntity) { + MetaTileEntity mMetaTileEntity = (MetaTileEntity) aBaseMetaTileEntity.getMetaTileEntity(); + if (mMetaTileEntity.dechargerSlotCount() > 0 && mMetaTileEntity.getEUVar() < aBaseMetaTileEntity.getEUCapacity()) { + Utils.LOG_INFO("3"); + for (int i = mMetaTileEntity.dechargerSlotStartIndex(), k = mMetaTileEntity.dechargerSlotCount() + i; i < k; i++) { + if (mMetaTileEntity.mInventory[i] != null && mMetaTileEntity.getEUVar() < aBaseMetaTileEntity.getEUCapacity()) { + aBaseMetaTileEntity.increaseStoredEnergyUnits(GT_ModHandler.dischargeElectricItem(mMetaTileEntity.mInventory[i], (int) Math.min(V[mTier] * 15, aBaseMetaTileEntity.getEUCapacity() - aBaseMetaTileEntity.getStoredEU()), (int) Math.min(Integer.MAX_VALUE, mMetaTileEntity.getInputTier()), true, false, false), true); + if (mMetaTileEntity.mInventory[i].stackSize <= 0) + mMetaTileEntity.mInventory[i] = null; + } + } + } + } + } + super.onPostTick(aBaseMetaTileEntity, aTimer); + } + + + } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java index df86584a69..e9831d96e0 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java @@ -164,9 +164,9 @@ public abstract class GregtechMeta_MultiBlockBase @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - this.mChargeHatches.clear(); - this.mDischargeHatches.clear(); super.onPostTick(aBaseMetaTileEntity, aTick); + //this.mChargeHatches.clear(); + //this.mDischargeHatches.clear(); } @Override @@ -203,10 +203,7 @@ public abstract class GregtechMeta_MultiBlockBase IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); if (aMetaTileEntity == null) return false; - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch) { - ((GT_MetaTileEntity_Hatch) aMetaTileEntity) - .updateTexture(aBaseCasingIndex); - } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBattery) return this.mChargeHatches.add( (GT_MetaTileEntity_Hatch_InputBattery) aMetaTileEntity); diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntity_PowerSubStationController.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntity_PowerSubStationController.java index c6a4cc03c1..a163215459 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntity_PowerSubStationController.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntity_PowerSubStationController.java @@ -17,6 +17,8 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.xmod.gregtech.api.gui.GUI_MultiMachine; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBattery; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_OutputBattery; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import net.minecraft.block.Block; import net.minecraft.entity.player.InventoryPlayer; @@ -244,12 +246,12 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe } } } - if ((this.mInputBusses.size() != 1) || (this.mOutputBusses.size() != 1) + if ((this.mChargeHatches.size() < 1) || (this.mDischargeHatches.size() < 1) || (this.mMaintenanceHatches.size() != 1) || (this.mEnergyHatches.size() < 1) || (this.mDynamoHatches.size() < 1)) { Utils.LOG_MACHINE_INFO("Returned False 3"); - Utils.LOG_MACHINE_INFO("Input Buses: "+this.mInputBusses.size()+" | expected: 1 | "+(this.mInputBusses.size() != 1)); - Utils.LOG_MACHINE_INFO("Output Buses: "+this.mOutputBusses.size()+" | expected: 1 | "+(this.mOutputBusses.size() != 1)); + Utils.LOG_MACHINE_INFO("Charge Buses: "+this.mChargeHatches.size()+" | expected: 1 | "+(this.mChargeHatches.size() != 1)); + Utils.LOG_MACHINE_INFO("Discharge Buses: "+this.mDischargeHatches.size()+" | expected: 1 | "+(this.mDischargeHatches.size() != 1)); Utils.LOG_MACHINE_INFO("Energy Hatches: "+this.mEnergyHatches.size()+" | expected: >= 1 | "+(this.mEnergyHatches.size() < 1)); Utils.LOG_MACHINE_INFO("Dynamo Hatches: "+this.mDynamoHatches.size()+" | expected: >= 1 | "+(this.mDynamoHatches.size() < 1)); Utils.LOG_MACHINE_INFO("Maint. Hatches: "+this.mMaintenanceHatches.size()+" | expected: 1 | "+(this.mMaintenanceHatches.size() != 1)); @@ -363,6 +365,13 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { this.mActualStoredEU = this.getEUVar(); + + if (this.mActualStoredEU < 0){ + this.mActualStoredEU = 0; + } + if (this.getEUVar() < 0){ + this.setEUVar(0); + } if (aBaseMetaTileEntity.isServerSide()){ this.mTotalRunTime++; @@ -391,6 +400,17 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe if (this.getBaseMetaTileEntity().isAllowedToWork()){ this.getBaseMetaTileEntity().enableWorking(); } + for (GT_MetaTileEntity_Hatch_OutputBattery energy : this.mDischargeHatches){ + long stored = energy.getEUVar(); + long voltage = energy.maxEUInput(); + if (stored > 0){ + energy.setEUVar((stored-voltage)); + this.mTotalEnergyAdded+=voltage; + if (this.getBaseMetaTileEntity().increaseStoredEnergyUnits(voltage, false)){ + //Utils.LOG_INFO("Draining Discharge Hatch #1"); + } + } + } for (GT_MetaTileEntity_Hatch_Energy energy : this.mEnergyHatches){ long stored = energy.getEUVar(); long voltage = energy.maxEUInput(); @@ -431,14 +451,28 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe public boolean drainEnergyInput(long aEU) { if (aEU <= 0L) return true; + long nStoredPower = this.getEUVar(); + for (GT_MetaTileEntity_Hatch_OutputBattery tHatch : this.mDischargeHatches) { + if ((isValidMetaTileEntity(tHatch)) && (tHatch.getBaseMetaTileEntity().decreaseStoredEnergyUnits(aEU, false))){ + if (this.mActualStoredEU<this.maxEUStore()){ + + } + Utils.LOG_INFO("Draining Discharge Hatch #2"); + } + } for (GT_MetaTileEntity_Hatch_Energy tHatch : this.mEnergyHatches) { if ((isValidMetaTileEntity(tHatch)) && (tHatch.getBaseMetaTileEntity().decreaseStoredEnergyUnits(aEU, false))){ if (this.mActualStoredEU<this.maxEUStore()){ //this.getBaseMetaTileEntity().increaseStoredEnergyUnits(aEU, false); } - return true; } + } + long nNewStoredPower = this.getEUVar(); + if (nNewStoredPower < nStoredPower){ + Utils.LOG_ERROR("Used "+(nStoredPower-nNewStoredPower)+"eu."); + return true; } + return false; } @@ -448,7 +482,19 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe return true; long nStoredPower = this.getEUVar(); int hatchCount = 0; + //Utils.LOG_INFO("Charge Hatches: "+this.mChargeHatches.size()); + for (GT_MetaTileEntity_Hatch_InputBattery tHatch : this.mChargeHatches) { + //Utils.LOG_INFO("Storing Power in a Charge Hatch"); + if ((isValidMetaTileEntity(tHatch)) && (tHatch.getBaseMetaTileEntity().increaseStoredEnergyUnits(tHatch.maxEUInput(), false))) { + this.setEUVar(this.getEUVar()-(tHatch.maxEUInput())); + this.mTotalEnergyConsumed+=(tHatch.maxEUInput()); + //this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(tHatch.getOutputTier()*2, false); + //Utils.LOG_INFO("Hatch "+hatchCount+" has "+tHatch.getEUVar()+"eu stored. Avg used is "+(this.mAverageEuUsage)); + } + hatchCount++; + } for (GT_MetaTileEntity_Hatch_Dynamo tHatch : this.mDynamoHatches) { + //Utils.LOG_INFO("Storing Power in a Dynamo Hatch"); if ((isValidMetaTileEntity(tHatch)) && (tHatch.getBaseMetaTileEntity().increaseStoredEnergyUnits(tHatch.getOutputTier()*2, false))) { this.setEUVar(this.getEUVar()-(tHatch.getOutputTier()*2)); this.mTotalEnergyConsumed+=(tHatch.getOutputTier()*2); |