diff options
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations')
9 files changed, 861 insertions, 713 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Heat.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Heat.java deleted file mode 100644 index 68ec0ba0c9..0000000000 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Heat.java +++ /dev/null @@ -1,532 +0,0 @@ -package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; - -import java.util.ArrayList; -import java.util.Arrays; - -import gregtech.GT_Mod; -import gregtech.api.enums.Dyes; -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.enums.Textures.BlockIcons; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.tileentity.IEnergyConnected; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.BaseMetaPipeEntity; -import gregtech.api.metatileentity.MetaPipeEntity; -import gregtech.api.objects.GT_RenderedTexture; -import gregtech.api.util.GT_Utility; -import gregtech.common.GT_Client; -import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.xmod.gregtech.api.interfaces.IHeatEntity; -import gtPlusPlus.xmod.gregtech.api.interfaces.IMetaTileEntityHeatPipe; -import gtPlusPlus.xmod.gregtech.common.StaticFields59; -import ic2.api.energy.tile.IEnergySink; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; - -public class GT_MetaPipeEntity_Heat extends MetaPipeEntity implements IMetaTileEntityHeatPipe, IHeatEntity { - - public final Materials mMaterial; - public final long mHeatLossPerMeter, mAmperage, mMaxTemp; - public final boolean mInsulated, mCanShock; - public long mTransferredAmperage = 0, mTransferredAmperageLast20 = 0, mTransferredVoltageLast20 = 0; - public short mOverheat; - - private boolean mCheckConnections; - public byte mDisableInput; - - public GT_MetaPipeEntity_Heat(int aID, String aName, String aNameRegional, Materials aMaterial, long aMaxTemp) { - super(aID, aName, aNameRegional, 0); - mMaterial = aMaterial; - mAmperage = 1; - mMaxTemp = aMaxTemp; - mInsulated = false; - mCanShock = true; - mHeatLossPerMeter = aMaxTemp/1000; - } - - public GT_MetaPipeEntity_Heat(String aName, Materials aMaterial, long aMaxTemp) { - super(aName, 0); - mMaterial = aMaterial; - mAmperage = 1; - mMaxTemp = aMaxTemp; - mInsulated = false; - mCanShock = true; - mHeatLossPerMeter = aMaxTemp/1000; - } - - - @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaPipeEntity_Heat(mName, mMaterial, mMaxTemp); - } - - @Override - public void onEntityCollidedWithBlock(World aWorld, int aX, int aY, int aZ, Entity aEntity) { - if (mCanShock && (((BaseMetaPipeEntity) getBaseMetaTileEntity()).mConnections & -128) == 0 && aEntity instanceof EntityLivingBase) - GT_Utility.applyHeatDamage((EntityLivingBase) aEntity, mTransferredVoltageLast20); - } - - @Override - public AxisAlignedBB getCollisionBoundingBoxFromPool(World aWorld, int aX, int aY, int aZ) { - if (!mCanShock) return super.getCollisionBoundingBoxFromPool(aWorld, aX, aY, aZ); - return AxisAlignedBB.getBoundingBox(aX + 0.125D, aY + 0.125D, aZ + 0.125D, aX + 0.875D, aY + 0.875D, aZ + 0.875D); - } - - @Override - public boolean isSimpleMachine() { - return true; - } - - @Override - public boolean isFacingValid(byte aFacing) { - return false; - } - - @Override - public boolean isValidSlot(int aIndex) { - return true; - } - - @Override - public final boolean renderInside(byte aSide) { - return false; - } - - @Override - public int getProgresstime() { - return (int) mTransferredAmperage * 64; - } - - @Override - public int maxProgresstime() { - return (int) mAmperage * 64; - } - - @Override - public long injectEnergyUnits(byte aSide, long aVoltage, long aAmperage) { - if (!getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide).letsEnergyIn(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSide(aSide), getBaseMetaTileEntity())) - return 0; - return transferHeat(aSide, aVoltage, aAmperage, new ArrayList<TileEntity>(Arrays.asList((TileEntity) getBaseMetaTileEntity()))); - } - - @Override - public long transferHeat(byte aSide, long aVoltage, long aAmperage, ArrayList<TileEntity> aAlreadyPassedTileEntityList) { - if (!this.isConnectedAtSide(aSide) && aSide != 6) { - return 0L; - } else { - long rUsedAmperes = 0L; - aVoltage -= this.mHeatLossPerMeter; - if (aVoltage > 0L) { - for (byte i = 0; i < 6 && aAmperage > rUsedAmperes; ++i) { - if (i != aSide && this.isConnectedAtSide(i) - && this.getBaseMetaTileEntity().getCoverBehaviorAtSide(i).letsEnergyOut(i, - this.getBaseMetaTileEntity().getCoverIDAtSide(i), - this.getBaseMetaTileEntity().getCoverDataAtSide(i), this.getBaseMetaTileEntity())) { - TileEntity tTileEntity = this.getBaseMetaTileEntity().getTileEntityAtSide(i); - if (!aAlreadyPassedTileEntityList.contains(tTileEntity)) { - aAlreadyPassedTileEntityList.add(tTileEntity); - if (tTileEntity instanceof IEnergyConnected) { - if (this.getBaseMetaTileEntity().getColorization() >= 0) { - byte tColor = ((IEnergyConnected) tTileEntity).getColorization(); - if (tColor >= 0 && tColor != this.getBaseMetaTileEntity().getColorization()) { - continue; - } - } - - if (tTileEntity instanceof IGregTechTileEntity - && ((IGregTechTileEntity) tTileEntity) - .getMetaTileEntity() instanceof IMetaTileEntityHeatPipe - && ((IGregTechTileEntity) tTileEntity) - .getCoverBehaviorAtSide(GT_Utility.getOppositeSide(i)) - .letsEnergyIn(GT_Utility.getOppositeSide(i), - ((IGregTechTileEntity) tTileEntity) - .getCoverIDAtSide(GT_Utility.getOppositeSide(i)), - ((IGregTechTileEntity) tTileEntity) - .getCoverDataAtSide(GT_Utility.getOppositeSide(i)), - (IGregTechTileEntity) tTileEntity)) { - if (((IGregTechTileEntity) tTileEntity).getTimer() > 50L) { - rUsedAmperes += ((IMetaTileEntityHeatPipe) ((IGregTechTileEntity) tTileEntity) - .getMetaTileEntity()).transferHeat(GT_Utility.getOppositeSide(i), - aVoltage, aAmperage - rUsedAmperes, - aAlreadyPassedTileEntityList); - } - } else { - rUsedAmperes += ((IEnergyConnected) tTileEntity).injectEnergyUnits( - GT_Utility.getOppositeSide(i), aVoltage, aAmperage - rUsedAmperes); - } - } else { - ForgeDirection tDirection; - - if (tTileEntity instanceof IEnergySink) { - tDirection = ForgeDirection.getOrientation(i).getOpposite(); - if (((IEnergySink) tTileEntity) - .acceptsEnergyFrom((TileEntity) this.getBaseMetaTileEntity(), tDirection) - && ((IEnergySink) tTileEntity).getDemandedEnergy() > 0.0D - && ((IEnergySink) tTileEntity).injectEnergy(tDirection, (double) aVoltage, - (double) aVoltage) < (double) aVoltage) { - ++rUsedAmperes; - } - } - } - } - } - } - } - - this.mTransferredAmperage += rUsedAmperes; - this.mTransferredVoltageLast20 = Math.max(this.mTransferredVoltageLast20, aVoltage); - this.mTransferredAmperageLast20 = Math.max(this.mTransferredAmperageLast20, this.mTransferredAmperage); - if (aVoltage <= this.mMaxTemp && this.mTransferredAmperage <= this.mAmperage) { - return rUsedAmperes; - } else { - if (this.mOverheat > GT_Mod.gregtechproxy.mWireHeatingTicks * 100) { - //this.getBaseMetaTileEntity().setToFire(); - } else { - this.mOverheat = (short) (this.mOverheat + 100); - } - - return aAmperage; - } - } - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (aBaseMetaTileEntity.isServerSide()) { - this.mTransferredAmperage = 0L; - if (this.mOverheat > 0) { - --this.mOverheat; - } - - if (aTick % 20L == 0L) { - this.mTransferredVoltageLast20 = 0L; - this.mTransferredAmperageLast20 = 0L; - - for (byte tSide = 0; tSide < 6; ++tSide) { - IGregTechTileEntity tBaseMetaTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(tSide); - byte uSide = GT_Utility.getOppositeSide(tSide); - if ((this.mCheckConnections || this.isConnectedAtSide(tSide) - || aBaseMetaTileEntity.getCoverBehaviorAtSide(tSide).alwaysLookConnected(tSide, - aBaseMetaTileEntity.getCoverIDAtSide(tSide), - aBaseMetaTileEntity.getCoverDataAtSide(tSide), aBaseMetaTileEntity) - || tBaseMetaTileEntity != null && tBaseMetaTileEntity.getCoverBehaviorAtSide(uSide) - .alwaysLookConnected(uSide, tBaseMetaTileEntity.getCoverIDAtSide(uSide), - tBaseMetaTileEntity.getCoverDataAtSide(uSide), tBaseMetaTileEntity)) - && this.connect(tSide) == 0) { - this.disconnect(tSide); - } - } - - if (isGT6Pipes()) { - this.mCheckConnections = false; - } - } - } else if (aBaseMetaTileEntity.isClientSide() && GT_Client.changeDetected == 4) { - aBaseMetaTileEntity.issueTextureUpdate(); - } - - } - - @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 String[] getDescription() { - return new String[]{ - "Max Voltage: " + EnumChatFormatting.GOLD + mMaxTemp + "C" + EnumChatFormatting.GRAY, - "Loss: " + EnumChatFormatting.RED + mHeatLossPerMeter + EnumChatFormatting.GRAY + " HU per meter", - CORE.GT_Tooltip - }; - } - - @Override - public float getThickNess() { - return 1; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setInteger("HeatBuffer", this.HeatBuffer); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - this.HeatBuffer = aNBT.getInteger("HeatBuffer"); - } - - - - - - - - - - - - - - protected int transmitHeat; - protected int maxHeatEmitpeerTick; - protected int HeatBuffer; - - - - - public byte getTileEntityBaseType() { - return 4; - } - - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aConnections, - byte aColorIndex, boolean aConnected, boolean aRedstone) { - float tThickNess = this.getThickNess(); - if (this.mDisableInput == 0) { - return new ITexture[]{(ITexture) (aConnected - ? getBaseTexture(tThickNess, 1, this.mMaterial, aColorIndex) - : new GT_RenderedTexture(this.mMaterial.mIconSet.mTextures[OrePrefixes.pipe.mTextureIndex], - Dyes.getModulation(aColorIndex, this.mMaterial.mRGBa)))}; - } else { - byte tMask = 0; - byte[][] sRestrictionArray = new byte[][]{{2, 3, 5, 4}, {2, 3, 4, 5}, {1, 0, 4, 5}, {1, 0, 4, 5}, - {1, 0, 2, 3}, {1, 0, 2, 3}}; - if (aSide >= 0 && aSide < 6) { - for (byte i = 0; i < 4; ++i) { - if (this.isInputDisabledAtSide(sRestrictionArray[aSide][i])) { - tMask = (byte) (tMask | 1 << i); - } - } - } - - return new ITexture[]{ - (ITexture) (aConnected - ? getBaseTexture(tThickNess, 1, this.mMaterial, aColorIndex) - : new GT_RenderedTexture(this.mMaterial.mIconSet.mTextures[OrePrefixes.pipe.mTextureIndex], - Dyes.getModulation(aColorIndex, this.mMaterial.mRGBa))), - getRestrictorTexture(tMask)}; - } - } - - protected static final ITexture getBaseTexture(float aThickNess, int aPipeAmount, Materials aMaterial, - byte aColorIndex) { - if (aPipeAmount >= 9) { - return new GT_RenderedTexture(aMaterial.mIconSet.mTextures[OrePrefixes.pipeNonuple.mTextureIndex], - Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); - } else if (aPipeAmount >= 4) { - return new GT_RenderedTexture(aMaterial.mIconSet.mTextures[OrePrefixes.pipeQuadruple.mTextureIndex], - Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); - } else if (aThickNess < 0.124F) { - return new GT_RenderedTexture(aMaterial.mIconSet.mTextures[OrePrefixes.pipe.mTextureIndex], - Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); - } else if (aThickNess < 0.374F) { - return new GT_RenderedTexture(aMaterial.mIconSet.mTextures[OrePrefixes.pipeTiny.mTextureIndex], - Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); - } else if (aThickNess < 0.499F) { - return new GT_RenderedTexture(aMaterial.mIconSet.mTextures[OrePrefixes.pipeSmall.mTextureIndex], - Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); - } else if (aThickNess < 0.749F) { - return new GT_RenderedTexture(aMaterial.mIconSet.mTextures[OrePrefixes.pipeMedium.mTextureIndex], - Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); - } else { - return aThickNess < 0.874F - ? new GT_RenderedTexture(aMaterial.mIconSet.mTextures[OrePrefixes.pipeLarge.mTextureIndex], - Dyes.getModulation(aColorIndex, aMaterial.mRGBa)) - : new GT_RenderedTexture(aMaterial.mIconSet.mTextures[OrePrefixes.pipeHuge.mTextureIndex], - Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); - } - } - - protected static final ITexture getRestrictorTexture(byte aMask) { - switch (aMask) { - case 1 : - return new GT_RenderedTexture(BlockIcons.PIPE_RESTRICTOR_UP); - case 2 : - return new GT_RenderedTexture(BlockIcons.PIPE_RESTRICTOR_DOWN); - case 3 : - return new GT_RenderedTexture(BlockIcons.PIPE_RESTRICTOR_UD); - case 4 : - return new GT_RenderedTexture(BlockIcons.PIPE_RESTRICTOR_LEFT); - case 5 : - return new GT_RenderedTexture(BlockIcons.PIPE_RESTRICTOR_UL); - case 6 : - return new GT_RenderedTexture(BlockIcons.PIPE_RESTRICTOR_DL); - case 7 : - return new GT_RenderedTexture(BlockIcons.PIPE_RESTRICTOR_NR); - case 8 : - return new GT_RenderedTexture(BlockIcons.PIPE_RESTRICTOR_RIGHT); - case 9 : - return new GT_RenderedTexture(BlockIcons.PIPE_RESTRICTOR_UR); - case 10 : - return new GT_RenderedTexture(BlockIcons.PIPE_RESTRICTOR_DR); - case 11 : - return new GT_RenderedTexture(BlockIcons.PIPE_RESTRICTOR_NL); - case 12 : - return new GT_RenderedTexture(BlockIcons.PIPE_RESTRICTOR_LR); - case 13 : - return new GT_RenderedTexture(BlockIcons.PIPE_RESTRICTOR_ND); - case 14 : - return new GT_RenderedTexture(BlockIcons.PIPE_RESTRICTOR_NU); - case 15 : - return new GT_RenderedTexture(BlockIcons.PIPE_RESTRICTOR); - default : - return null; - } - } - - - public final boolean isGT6Pipes() { - return StaticFields59.mGT6StylePipes; - } - - public void updateHeatEntity() { - int amount = this.getMaxHeatEmittedPerTick() - this.HeatBuffer; - if (amount > 0) { - this.addtoHeatBuffer(this.fillHeatBuffer(amount)); - } - } - - public boolean facingMatchesDirection(ForgeDirection direction) { - return true; - } - - public int maxrequestHeatTick(ForgeDirection directionFrom) { - return this.getMaxHeatEmittedPerTick(); - } - - public int requestHeat(ForgeDirection directionFrom, int requestheat) { - if (this.facingMatchesDirection(directionFrom)) { - int heatbuffertemp = this.getHeatBuffer(); - if (this.getHeatBuffer() >= requestheat) { - this.setHeatBuffer(this.getHeatBuffer() - requestheat); - this.transmitHeat = requestheat; - return requestheat; - } else { - this.transmitHeat = heatbuffertemp; - this.setHeatBuffer(0); - return heatbuffertemp; - } - } else { - return 0; - } - } - - - public int getHeatBuffer() { - return this.HeatBuffer; - } - - public void setHeatBuffer(int HeatBuffer) { - this.HeatBuffer = HeatBuffer; - } - - public void addtoHeatBuffer(int heat) { - this.setHeatBuffer(this.getHeatBuffer() + heat); - } - - - public int fillHeatBuffer(int maxAmount) { - return maxAmount >= this.getMaxHeatEmittedPerTick() ? this.getMaxHeatEmittedPerTick() : maxAmount; - } - - public int getMaxHeatEmittedPerTick() { - return (int) (this.mMaxTemp/1000); - } - - - public boolean onWrenchRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, - float aZ) { - if (isGT6Pipes()) { - byte tSide = GT_Utility.determineWrenchingSide(aSide, aX, aY, aZ); - byte tMask = (byte) (1 << tSide); - if (aPlayer.isSneaking()) { - if (this.isInputDisabledAtSide(tSide)) { - this.mDisableInput = (byte) (this.mDisableInput & ~tMask); - GT_Utility.sendChatToPlayer(aPlayer, this.trans("212", "Input enabled")); - if (!this.isConnectedAtSide(tSide)) { - this.connect(tSide); - } - } else { - this.mDisableInput |= tMask; - GT_Utility.sendChatToPlayer(aPlayer, this.trans("213", "Input disabled")); - } - } else if (!this.isConnectedAtSide(tSide)) { - if (this.connect(tSide) > 0) { - GT_Utility.sendChatToPlayer(aPlayer, this.trans("214", "Connected")); - } - } else { - this.disconnect(tSide); - GT_Utility.sendChatToPlayer(aPlayer, this.trans("215", "Disconnected")); - } - - return true; - } else { - return false; - } - } - - public boolean isInputDisabledAtSide(int aSide) { - return (this.mDisableInput & 1 << aSide) != 0; - } - - - - - @Override - public int maxHeatInPerTick(ForgeDirection var1) { - return (int) (this.mMaxTemp/500); - } - - @Override - public int addHeat(ForgeDirection var1, int var2) { - - - - /*ForgeDirection dir = ForgeDirection.getOrientation(this.getFacing()); - TileEntity te = this.getBaseMetaTileEntity().getWorld().getTileEntity(this.xCoord + dir.offsetX, this.yCoord + dir.offsetY, - this.zCoord + dir.offsetZ); - if (te instanceof IHeatSource) { - int heatbandwith = ((IHeatSource) te).maxrequestHeatTick(dir.getOpposite()); - double freeEUstorage = (double) this.maxEUStorage - this.EUstorage; - if (freeEUstorage >= this.productionpeerheat * (double) heatbandwith) { - this.receivedheat = ((IHeatSource) te).requestHeat(dir.getOpposite(), heatbandwith); - if (this.receivedheat != 0) { - this.production = (double) this.receivedheat * this.productionpeerheat; - this.EUstorage += this.production; - return true; - } - } - } - - this.production = 0.0D; - this.receivedheat = 0;*/ - - - return 0; - } - - @Override - public int getTransmitHeat() { - return this.transmitHeat; - } - - - - - -}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_DynamoBuffer.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_DynamoBuffer.java index 9b730c84a3..5fef0f1088 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_DynamoBuffer.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_DynamoBuffer.java @@ -34,14 +34,17 @@ public class GT_MetaTileEntity_Hatch_DynamoBuffer extends GT_MetaTileEntity_Hatc return new ITexture[]{aBaseTexture, TexturesGtBlock.OVERLAYS_ENERGY_OUT_MULTI_BUFFER[this.mTier]}; } + @Override public long getMinimumStoredEU() { return 0L; } + @Override public long maxEUStore() { return 512L + GT_Values.V[this.mTier + 1] * 2048L; } + @Override public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { return (MetaTileEntity) new GT_MetaTileEntity_Hatch_DynamoBuffer(this.mName, this.mTier, this.mDescription, this.mTextures); } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_TurbineProvider.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_TurbineProvider.java new file mode 100644 index 0000000000..752321506d --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_TurbineProvider.java @@ -0,0 +1,212 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.items.GT_MetaGenerated_Tool; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; +import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_LargeTurbine; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.sys.KeyboardUtils; +import gtPlusPlus.xmod.gregtech.api.gui.hatches.CONTAINER_1by1_Turbine; +import gtPlusPlus.xmod.gregtech.api.gui.hatches.GUI_1by1_Turbine; +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.world.World; +import net.minecraft.world.chunk.Chunk; + +public class GT_MetaTileEntity_Hatch_TurbineProvider extends GT_MetaTileEntity_Hatch_InputBus { + + public GT_MetaTileEntity_Hatch_TurbineProvider(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier); + } + + public GT_MetaTileEntity_Hatch_TurbineProvider(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + public GT_MetaTileEntity_Hatch_TurbineProvider(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription[0], aTextures); + } + + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_TurbineProvider(this.mName, this.mTier, this.mDescription, this.mTextures); + } + + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_1by1_Turbine(aPlayerInventory, aBaseMetaTileEntity); + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_1by1_Turbine(aPlayerInventory, aBaseMetaTileEntity, "Turbine Housing"); + } + + @Override + public String[] getDescription() { + return new String[]{ + "An automation port for Large Turbines", "Will attempt once per 1200 ticks to fill the turbine slot of it's parent turbine", "You may adjust this with a screwdriver", "Hold shift to adjust in finer amounts", "Hold control to adjust direction", "Left Click with Screwdriver to reset", "This module assumes the entire turbine is in the same Chunk"}; + } + + + private GT_MetaTileEntity_LargeTurbine mParent = null; + + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + super.onPostTick(aBaseMetaTileEntity, aTimer); + if (aTimer % mRefreshTime == 0 && this.getBaseMetaTileEntity().isServerSide()) { + tryRefillTurbine(); + } + } + + private final void tryFindParentTurbine() { + Logger.INFO("This turbine housing has no parent, searching world."); + IGregTechTileEntity T = this.getBaseMetaTileEntity(); + World W = T.getWorld(); + Chunk C = W.getChunkFromBlockCoords(T.getXCoord(), T.getZCoord()); + for (Object o : C.chunkTileEntityMap.values()) { + if (o instanceof IGregTechTileEntity) { + IGregTechTileEntity G = (IGregTechTileEntity) o; + final IMetaTileEntity aMetaTileEntity = G.getMetaTileEntity(); + if (aMetaTileEntity == null) { + continue; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_LargeTurbine) { + GT_MetaTileEntity_LargeTurbine aTurb = (GT_MetaTileEntity_LargeTurbine) aMetaTileEntity; + for (GT_MetaTileEntity_Hatch_InputBus ee : aTurb.mInputBusses) { + if (ee.equals(this)) { + mParent = aTurb; + Logger.INFO("Found a Parent to attach to this housing."); + return; + } + } + } + } + } + } + + private final void tryRefillTurbine() { + if (mParent == null) { + tryFindParentTurbine(); + } + if (mParent != null && mParent.mInventory[1] == null) { + for (ItemStack aStack : this.mInventory) { + if (isItemStackTurbine(aStack)) { + setGUIItemStack(aStack); + } + } + } + } + + protected boolean setGUIItemStack(ItemStack aNewGuiSlotContents) { + boolean result = false; + if (mParent.mInventory[1] == null) { + mParent.mInventory[1] = aNewGuiSlotContents != null ? aNewGuiSlotContents.copy() : null; + mParent.depleteInput(aNewGuiSlotContents); + mParent.updateSlots(); + this.updateSlots(); + result = true; + } + return result; + } + + public boolean isItemStackTurbine(ItemStack aStack) { + if (aStack.getItem() instanceof GT_MetaGenerated_Tool) { + if (aStack.getItemDamage() >= 170 && aStack.getItemDamage() <= 176) { + return true; + } + } + return false; + } + + public boolean isItemStackScrewdriver(ItemStack aStack) { + if (aStack.getItem() instanceof GT_MetaGenerated_Tool) { + if (aStack.getItemDamage() == 22 || aStack.getItemDamage() == 150) { + return true; + } + } + 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 isItemStackTurbine(aStack); + } + + private int mRefreshTime = 1200; + private boolean mDescending = true; + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mRefreshTime", mRefreshTime); + aNBT.setBoolean("mDescending", mDescending); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mRefreshTime = aNBT.getInteger("mRefreshTime"); + mDescending = aNBT.getBoolean("mDescending"); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aPlayer != null) { + if (KeyboardUtils.isCtrlKeyDown()) { + mDescending = Utils.invertBoolean(mDescending); + PlayerUtils.messagePlayer(aPlayer, "Direction: "+(mDescending ? "DOWN" : "UP")); + } + else { + int aAmount = 0; + if (KeyboardUtils.isShiftKeyDown()) { + aAmount = 10; + } + else { + aAmount = 100; + } + if (mDescending) { + mRefreshTime -= aAmount; + if (mRefreshTime < 0) { + mRefreshTime = 1200; + } + } + else { + mRefreshTime += aAmount; + if (mRefreshTime > 1200) { + mRefreshTime = 0; + } + } + PlayerUtils.messagePlayer(aPlayer, "Set check time to be every "+mRefreshTime+" ticks."); + } + } + } + + @Override + public void onLeftclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + boolean aDidScrewdriver = false; + if (aPlayer != null) { + if (aPlayer.getHeldItem() != null) { + if (isItemStackScrewdriver(aPlayer.getHeldItem())) { + aDidScrewdriver = true; + mRefreshTime = 1200; + PlayerUtils.messagePlayer(aPlayer, "Reset check time to "+mRefreshTime+" ticks."); + } + } + } + if (!aDidScrewdriver) { + super.onLeftclick(aBaseMetaTileEntity, aPlayer); + } + } + + +} diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Input.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Input.java index e0844bb071..4c60d9a932 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Input.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Input.java @@ -9,7 +9,6 @@ import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Utility; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; -import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; @@ -17,7 +16,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; public class GT_MetaTileEntity_SuperBus_Input extends GT_MetaTileEntity_Hatch_InputBus { - public GT_Recipe_Map mRecipeMap = null; public GT_MetaTileEntity_SuperBus_Input(int aID, String aName, String aNameRegional, int aTier) { super(aID, aName, aNameRegional, aTier); diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Output.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Output.java index 3afa3312b1..cca5a39de3 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Output.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Output.java @@ -58,7 +58,7 @@ public class GT_MetaTileEntity_SuperBus_Output extends GT_MetaTileEntity_Hatch_O if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { this.fillStacksIntoFirstSlots(); } - + super.onPostTick(aBaseMetaTileEntity, aTimer); } public void updateSlots() { diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java index 8a29dc5db2..be23123193 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java @@ -18,13 +18,7 @@ public class GregtechMetaPipeEntityFluid extends GT_MetaPipeEntity_Fluid { public static final boolean mGt6Pipe; static { - Boolean aGt6 = (Boolean) StaticFields59.getFieldFromGregtechProxy("gt6Pipe"); - if (aGt6 != null) { - mGt6Pipe = aGt6; - } - else { - mGt6Pipe = false; - } + mGt6Pipe = StaticFields59.mGT6StylePipes; } public final GT_Materials mMaterial; diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GT_MetaTileEntity_Hatch_CustomFluidBase.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GT_MetaTileEntity_Hatch_CustomFluidBase.java index 839fb3a14a..c9b98a6a64 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GT_MetaTileEntity_Hatch_CustomFluidBase.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GT_MetaTileEntity_Hatch_CustomFluidBase.java @@ -102,7 +102,7 @@ public class GT_MetaTileEntity_Hatch_CustomFluidBase extends GT_MetaTileEntity_H String[] s2 = new String[]{ "Fluid Input for Multiblocks", "Capacity: " + getCapacity()+"L", - "Accepted Fluid: " + mTempMod + mLockedStack.getLocalizedName() + "Accepted Fluid: " + mTempMod + mLockedStack != null ? mLockedStack.getLocalizedName() : "Empty" }; return s2; } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaPipeEntityBase_Cable.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaPipeEntityBase_Cable.java index d17c820699..4dd5bf25d6 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaPipeEntityBase_Cable.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaPipeEntityBase_Cable.java @@ -5,6 +5,7 @@ import static gregtech.api.enums.GT_Values.VN; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import cofh.api.energy.IEnergyReceiver; import net.minecraft.entity.Entity; @@ -219,6 +220,18 @@ public class GregtechMetaPipeEntityBase_Cable extends MetaPipeEntity implements return this.transferElectricity(aSide, aVoltage, aAmperage, new ArrayList<>(Arrays.asList((TileEntity) this.getBaseMetaTileEntity()))); } + + + /** + * Adds support for the newer function added by https://github.com/Blood-Asp/GT5-Unofficial/commit/73ee102b63efd92c0f164a7ed7a79ebcd2619617#diff-3051838621d8ae87aa5ccd1345e1f07d + */ + public long transferElectricity(byte arg0, long arg1, long arg2, HashSet<TileEntity> arg3) { + ArrayList<TileEntity> aTiles = new ArrayList<TileEntity>(); + for (TileEntity y : arg3) { + aTiles.add(y); + } + return transferElectricity(arg0, arg1, arg2, aTiles); + } @Override public long transferElectricity(final byte aSide, long aVoltage, final long aAmperage, 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 0e1ef0e47e..4a6cad20c3 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 @@ -4,9 +4,9 @@ import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.lang.reflect.ParameterizedType; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.concurrent.TimeUnit; @@ -41,18 +41,28 @@ import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; import gtPlusPlus.GTplusplus; import gtPlusPlus.GTplusplus.INIT_PHASE; +import gtPlusPlus.api.helpers.GregtechPlusPlus_API.Multiblock_API; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.data.ConcurrentHashSet; +import gtPlusPlus.api.objects.data.ConcurrentSet; +import gtPlusPlus.api.objects.data.FlexiblePair; +import gtPlusPlus.api.objects.data.Triplet; import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.api.objects.minecraft.multi.SpecialMultiBehaviour; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.recipe.common.CI; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.preloader.asm.AsmConfig; import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_MultiMachine; +import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_MultiMachine_NoPlayerInventory; import gtPlusPlus.xmod.gregtech.api.gui.GUI_MultiMachine; +import gtPlusPlus.xmod.gregtech.api.gui.GUI_MultiMachine_Default; import gtPlusPlus.xmod.gregtech.api.gui.GUI_Multi_Basic_Slotted; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_AirIntake; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_ControlCore; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBattery; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_OutputBattery; @@ -66,16 +76,13 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; +import net.minecraft.world.World; import net.minecraftforge.fluids.FluidStack; -public abstract class GregtechMeta_MultiBlockBase -extends -GT_MetaTileEntity_MultiBlockBase { - +public abstract class GregtechMeta_MultiBlockBase extends GT_MetaTileEntity_MultiBlockBase { public static final boolean DEBUG_DISABLE_CORES_TEMPORARILY = true; - static { Method a08 = findRecipe08 = ReflectionUtils.getMethod(GT_Recipe_Map.class, "findRecipe", IHasWorldObjectAndCoords.class, GT_Recipe.class, boolean.class, long.class, FluidStack[].class, ItemStack.class, ItemStack[].class); @@ -83,8 +90,19 @@ GT_MetaTileEntity_MultiBlockBase { Logger.MACHINE_INFO("Found .08 findRecipe method? "+(a08 != null)); Logger.MACHINE_INFO("Found .09 findRecipe method? "+(a09 != null)); - //gregtech.api.util.GT_Recipe.GT_Recipe_Map.findRecipe(IHasWorldObjectAndCoords, GT_Recipe, boolean, long, FluidStack[], ItemStack, ItemStack...) + if (CORE.DEBUG) { + aLogger = ReflectionUtils.getMethod(Logger.class, "INFO", String.class); + } + else { + aLogger = ReflectionUtils.getMethod(Logger.class, "MACHINE_INFO", String.class); + } + try { + calculatePollutionReduction = GT_MetaTileEntity_Hatch_Muffler.class.getDeclaredMethod("calculatePollutionReduction", int.class); + } catch (NoSuchMethodException | SecurityException e) {} + + mCustomBehviours = new HashMap<String, SpecialMultiBehaviour>(); + } //Find Recipe Methods @@ -98,9 +116,14 @@ GT_MetaTileEntity_MultiBlockBase { //Control Core Hatch public ArrayList<GT_MetaTileEntity_Hatch_ControlCore> mControlCoreBus = new ArrayList<GT_MetaTileEntity_Hatch_ControlCore>(); + public ArrayList<GT_MetaTileEntity_Hatch_AirIntake> mAirIntakes = new ArrayList<GT_MetaTileEntity_Hatch_AirIntake>(); public ArrayList<GT_MetaTileEntity_Hatch_InputBattery> mChargeHatches = new ArrayList<GT_MetaTileEntity_Hatch_InputBattery>(); public ArrayList<GT_MetaTileEntity_Hatch_OutputBattery> mDischargeHatches = new ArrayList<GT_MetaTileEntity_Hatch_OutputBattery>(); + // Custom Behaviour Map + private static final HashMap<String, SpecialMultiBehaviour> mCustomBehviours; + + public GregtechMeta_MultiBlockBase(final int aID, final String aName, final String aNameRegional) { super(aID, aName, aNameRegional); @@ -120,13 +143,23 @@ GT_MetaTileEntity_MultiBlockBase { public abstract boolean hasSlotInGUI(); + public long getTotalRuntimeInTicks() { + return this.mTotalRunTime; + } + @Override public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { if (hasSlotInGUI()) { return new GT_Container_MultiMachine(aPlayerInventory, aBaseMetaTileEntity); } - else { - return new CONTAINER_MultiMachine(aPlayerInventory, aBaseMetaTileEntity); + else { + String aCustomGUI = getCustomGUIResourceName(); + if (aCustomGUI == null) { + return new CONTAINER_MultiMachine_NoPlayerInventory(aPlayerInventory, aBaseMetaTileEntity); + } + else { + return new CONTAINER_MultiMachine(aPlayerInventory, aBaseMetaTileEntity); + } } } @@ -139,7 +172,7 @@ GT_MetaTileEntity_MultiBlockBase { @Override public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { String aCustomGUI = getCustomGUIResourceName(); - aCustomGUI = aCustomGUI != null ? aCustomGUI : "MultiblockDisplay"; + aCustomGUI = aCustomGUI != null ? aCustomGUI : hasSlotInGUI() ? "MultiblockDisplay" : "MultiblockDisplay_Generic"; aCustomGUI = aCustomGUI + ".png"; if (hasSlotInGUI()) { if (!requiresVanillaGtGUI()) { @@ -150,7 +183,12 @@ GT_MetaTileEntity_MultiBlockBase { } } else { - return new GUI_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), aCustomGUI); + if (getCustomGUIResourceName() == null && !hasSlotInGUI()) { + return new GUI_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), aCustomGUI); + } + else { + return new GUI_MultiMachine_Default(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), aCustomGUI); + } } } @@ -189,31 +227,17 @@ GT_MetaTileEntity_MultiBlockBase { long minutes = TimeUnit.SECONDS.toMinutes(seconds) - (TimeUnit.SECONDS.toHours(seconds) * 60); long second = TimeUnit.SECONDS.toSeconds(seconds) - (TimeUnit.SECONDS.toMinutes(seconds) *60); - int mPollutionReduction=0; - for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { - if (isValidMetaTileEntity(tHatch)) { - mPollutionReduction=Math.max(calculatePollutionReductionForHatch(tHatch, 100),mPollutionReduction); - } - } - - long storedEnergy=0; - long maxEnergy=0; - for(GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) { - if (isValidMetaTileEntity(tHatch)) { - storedEnergy+=tHatch.getBaseMetaTileEntity().getStoredEU(); - maxEnergy+=tHatch.getBaseMetaTileEntity().getEUCapacity(); - } - } - + int mPollutionReduction = getPollutionReductionForAllMufflers(); + long storedEnergy = getStoredEnergyInAllEnergyHatches(); + long maxEnergy = getMaxEnergyStorageOfAllEnergyHatches(); int tTier = this.getControlCoreTier(); - mInfo.add(getMachineTooltip()); //Lets borrow the GTNH handling - mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.Progress")+": "+ + mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.progress")+": "+ EnumChatFormatting.GREEN + Integer.toString(mProgresstime/20) + EnumChatFormatting.RESET +" s / "+ EnumChatFormatting.YELLOW + Integer.toString(mMaxProgresstime/20) + EnumChatFormatting.RESET +" s"); @@ -260,6 +284,36 @@ GT_MetaTileEntity_MultiBlockBase { } + public int getPollutionReductionForAllMufflers() { + int mPollutionReduction=0; + for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { + if (isValidMetaTileEntity(tHatch)) { + mPollutionReduction=Math.max(calculatePollutionReductionForHatch(tHatch, 100),mPollutionReduction); + } + } + return mPollutionReduction; + } + + public long getStoredEnergyInAllEnergyHatches() { + long storedEnergy=0; + for(GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) { + if (isValidMetaTileEntity(tHatch)) { + storedEnergy+=tHatch.getBaseMetaTileEntity().getStoredEU(); + } + } + return storedEnergy; + } + + public long getMaxEnergyStorageOfAllEnergyHatches() { + long maxEnergy=0; + for(GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) { + if (isValidMetaTileEntity(tHatch)) { + maxEnergy+=tHatch.getBaseMetaTileEntity().getEUCapacity(); + } + } + return maxEnergy; + } + @Override public boolean isGivingInformation() { return true; @@ -294,7 +348,7 @@ GT_MetaTileEntity_MultiBlockBase { }*/ String aRequiresMuffler = "1x Muffler Hatch"; - String aRequiresCoreModule = "1x Core Module"; + //String aRequiresCoreModule = "1x Core Module"; String aRequiresMaint = "1x Maintanence Hatch"; String[] x = getTooltip(); @@ -330,7 +384,7 @@ GT_MetaTileEntity_MultiBlockBase { AutoMap<String> aOrderedMap = new AutoMap<String>(); if (showHatches) { aOrderedMap.put(aRequiresMaint); - aOrderedMap.put(aRequiresCoreModule); + //aOrderedMap.put(aRequiresCoreModule); if (showPollution) { aOrderedMap.put(aRequiresMuffler); } @@ -361,8 +415,11 @@ GT_MetaTileEntity_MultiBlockBase { String[] aToolTip = new String[(a2 + a3)]; aToolTip = ArrayUtils.addAll(aToolTip, x); aToolTip = ArrayUtils.addAll(aToolTip, z); - aCachedToolTip = aToolTip; - return aToolTip; + + if (aCachedToolTip == null || aCachedToolTip.length <= 0) { + aCachedToolTip = aToolTip; + } + return aCachedToolTip; } public abstract String[] getTooltip(); @@ -414,67 +471,316 @@ GT_MetaTileEntity_MultiBlockBase { public String getSound() { return ""; } + public boolean canBufferOutputs(final GT_Recipe aRecipe, int aParallelRecipes) { - if (aRecipe.mOutputs.length > 16) { - // Gendustry custom comb with a billion centrifuge outputs? Do it anyway. - return true; - } + return canBufferOutputs(aRecipe, aParallelRecipes, true); + } + + public boolean canBufferOutputs(final GT_Recipe aRecipe, int aParallelRecipes, boolean aAllow16SlotWithoutCheck) { - // Count slots available in output buses - ArrayList<ItemStack> tBusStacks = new ArrayList<>(); + Logger.INFO("Determining if we have space to buffer outputs. Parallel: "+aParallelRecipes); - int tEmptySlots = 0; - for (final GT_MetaTileEntity_Hatch_OutputBus tBus : this.mOutputBusses) { - if (!isValidMetaTileEntity(tBus)) { - continue; + // Null recipe or a recipe with lots of outputs? + // E.G. Gendustry custom comb with a billion centrifuge outputs? + // Do it anyway, provided the multi allows it. Default behaviour is aAllow16SlotWithoutCheck = true. + if (aRecipe == null || aRecipe.mOutputs.length > 16) { + if (aRecipe == null) { + return false; } - final IInventory tBusInv = tBus.getBaseMetaTileEntity(); - for (int i = 0; i < tBusInv.getSizeInventory(); i++) { - if (tBus.getStackInSlot(i) == null) { - tEmptySlots++; + else if (aRecipe.mOutputs.length > 16) { + if (aAllow16SlotWithoutCheck) { + return true; } else { - tBusStacks.add(tBus.getStackInSlot(i)); + // Do nothing, we want to check this recipe properly. } - } - } + } + } - int slotsNeeded = aRecipe.mOutputs.length; - for (final ItemStack tRecipeOutput: aRecipe.mOutputs) { - if (tRecipeOutput == null) continue; - int amount = tRecipeOutput.stackSize * aParallelRecipes; - for (final ItemStack tBusStack : tBusStacks) { - if (GT_Utility.areStacksEqual(tBusStack, tRecipeOutput)) { - if (tBusStack.stackSize + amount <= tBusStack.getMaxStackSize()) { - slotsNeeded--; - break; + // Do we even need to check for item outputs? + boolean aDoesOutputItems = aRecipe.mOutputs.length > 0; + // Do we even need to check for fluid outputs? + boolean aDoesOutputFluids = aRecipe.mFluidOutputs.length > 0; + + + + /* ======================================== + * Item Management + * ======================================== + */ + + if (aDoesOutputItems) { + Logger.INFO("We have items to output."); + + // How many slots are free across all the output buses? + int aInputBusSlotsFree = 0; + + /* + * Create Variables for Item Output + */ + + AutoMap<FlexiblePair<ItemStack, Integer>> aItemMap = new AutoMap<FlexiblePair<ItemStack, Integer>>(); + AutoMap<ItemStack> aOutputs = new AutoMap<ItemStack>(aRecipe.mOutputs); + + for (final GT_MetaTileEntity_Hatch_OutputBus tBus : this.mOutputBusses) { + if (!isValidMetaTileEntity(tBus)) { + continue; + } + final IInventory tBusInv = tBus.getBaseMetaTileEntity(); + for (int i = 0; i < tBusInv.getSizeInventory(); i++) { + if (tBus.getStackInSlot(i) == null) { + aInputBusSlotsFree++; + } + else { + ItemStack aT = tBus.getStackInSlot(i); + int aSize = aT.stackSize; + aT = aT.copy(); + aT.stackSize = 0; + aItemMap.put(new FlexiblePair<ItemStack, Integer>(aT, aSize)); } + } + } + + // Count the slots we need, later we can check if any are able to merge with existing stacks + int aRecipeSlotsRequired = 0; + + // A map to hold the items we will be 'inputting' into the output buses. These itemstacks are actually the recipe outputs. + ConcurrentSet<FlexiblePair<ItemStack, Integer>> aInputMap = new ConcurrentHashSet<FlexiblePair<ItemStack, Integer>>(); + + // Iterate over the outputs, calculating require stack spacing they will require. + for (int i=0;i<aOutputs.size();i++) { + ItemStack aY = aOutputs.get(i); + if (aY == null) { + continue; } + else { + int aStackSize = aY.stackSize * aParallelRecipes; + if (aStackSize > 64) { + int aSlotsNeedsForThisStack = (int) Math.ceil((double) ((float) aStackSize / 64f)); + // Should round up and add as many stacks as required nicely. + aRecipeSlotsRequired += aSlotsNeedsForThisStack; + for (int o=0;o<aRecipeSlotsRequired;o++) { + int aStackToRemove = (aStackSize -= 64) > 64 ? 64 : aStackSize; + aY = aY.copy(); + aY.stackSize = 0; + aInputMap.add(new FlexiblePair<ItemStack, Integer>(aY, aStackToRemove)); + } + } + else { + // Only requires one slot + aRecipeSlotsRequired++; + aY = aY.copy(); + aY.stackSize = 0; + aInputMap.add(new FlexiblePair<ItemStack, Integer>(aY, aStackSize)); + } + } + } + + // We have items to add to the output buses. See if any are not full stacks and see if we can make them full. + if (aInputMap.size() > 0) { + // Iterate over the current stored items in the Output busses, if any match and are not full, we can try account for merging. + busItems: for (FlexiblePair<ItemStack, Integer> y : aItemMap) { + // Iterate over the 'inputs', we can safely remove these as we go. + outputItems: for (FlexiblePair<ItemStack, Integer> u : aInputMap) { + // Create local vars for readability. + ItemStack aOutputBusStack = y.getKey(); + ItemStack aOutputStack = u.getKey(); + // Stacks match, including NBT. + if (GT_Utility.areStacksEqual(aOutputBusStack, aOutputStack, false)) { + // Stack Matches, but it's full, continue. + if (aOutputBusStack.stackSize >= 64) { + // This stack is full, no point checking it. + continue busItems; + } + else { + // We can merge these two stacks without any hassle. + if ((aOutputBusStack.stackSize + aOutputStack.stackSize) <= 64) { + // Update the stack size in the bus storage map. + y.setValue(aOutputBusStack.stackSize + aOutputStack.stackSize); + // Remove the 'input' stack from the recipe outputs, so we don't try count it again. + aInputMap.remove(u); + continue outputItems; + } + // Stack merging is too much, so we fill this stack, leave the remainder. + else { + int aRemainder = (aOutputBusStack.stackSize + aOutputStack.stackSize) - 64; + // Update the stack size in the bus storage map. + y.setValue(64); + // Create a new object to iterate over later, with the remainder data; + FlexiblePair<ItemStack, Integer> t = new FlexiblePair<ItemStack, Integer>(u.getKey(), aRemainder); + // Remove the 'input' stack from the recipe outputs, so we don't try count it again. + aInputMap.remove(u); + // Add the remainder stack. + aInputMap.add(t); + continue outputItems; + } + } + } + else { + continue outputItems; + } + } + } } + + // We have stacks that did not merge, do we have space for them? + if (aInputMap.size() > 0) { + if (aInputMap.size() > aInputBusSlotsFree) { + // We do not have enough free slots in total to accommodate the remaining managed stacks. + Logger.INFO("Failed to find enough space for all item outputs. Free: "+aInputBusSlotsFree+", Required: "+aInputMap.size()); + return false; + } + } + + /* + * End Item Management + */ + } - // Enough open slots? - if (tEmptySlots < slotsNeeded) return false; - // For each output fluid, make sure an output hatch can accept it. - for (FluidStack tRecipeFluid: aRecipe.mFluidOutputs) { - if (tRecipeFluid == null) continue; - boolean tCanBufferFluid = false; - int tRecipeAmount = tRecipeFluid.amount; - for (final GT_MetaTileEntity_Hatch_Output tHatch : this.mOutputHatches) { - FluidStack tHatchFluid = tHatch.getFluid(); - if (tHatchFluid == null) { - if(tHatch.getCapacity() > tRecipeAmount) { - tCanBufferFluid = true; - break; - } + + + + + /* ======================================== + * Fluid Management + * ======================================== + */ + + + + if (aDoesOutputFluids) { + Logger.INFO("We have Fluids to output."); + // How many slots are free across all the output buses? + int aFluidHatches = 0; + int aEmptyFluidHatches = 0; + int aFullFluidHatches = 0; + // Create Map for Fluid Output + ConcurrentHashSet<Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>> aOutputHatches = new ConcurrentHashSet<Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>>(); + for (final GT_MetaTileEntity_Hatch_Output tBus : this.mOutputHatches) { + if (!isValidMetaTileEntity(tBus)) { + continue; } - else if (tHatchFluid.isFluidEqual(tRecipeFluid) && tHatch.getCapacity() - tHatchFluid.amount > tRecipeAmount) { - tCanBufferFluid = true; - break; + aFluidHatches++; + // Map the Hatch with the space left for easy checking later. + if (tBus.getFluid() == null) { + aOutputHatches.add(new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(tBus, null, tBus.getCapacity())); + } + else { + int aSpaceLeft = tBus.getCapacity() - tBus.getFluidAmount(); + aOutputHatches.add(new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(tBus, tBus.getFluid(), aSpaceLeft)); + } + } + // Create a map of all the fluids we would like to output, we can iterate over this and see how many we can merge into existing hatch stacks. + ConcurrentHashSet<FluidStack> aOutputFluids = new ConcurrentHashSet<FluidStack>(); + // Ugly ass boxing + aOutputFluids.addAll(new AutoMap<FluidStack>(aRecipe.mFluidOutputs)); + // Iterate the Hatches, updating their 'stored' data. + aHatchIterator: for (Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aHatchData : aOutputHatches) { + // The Hatch Itself + GT_MetaTileEntity_Hatch_Output aHatch = aHatchData.getValue_1(); + // Fluid in the Hatch + FluidStack aHatchStack = aHatchData.getValue_2(); + // Space left in Hatch + int aSpaceLeftInHatch = aHatch.getCapacity() - aHatch.getFluidAmount(); + // Hatch is full, + if (aSpaceLeftInHatch <= 0) { + aFullFluidHatches++; + aOutputHatches.remove(aHatchData); + continue aHatchIterator; + } + // Hatch has space + else { + // Check if any fluids match + aFluidMatch: for (FluidStack aOutputStack : aOutputFluids) { + if (GT_Utility.areFluidsEqual(aHatchStack, aOutputStack)) { + int aFluidToPutIntoHatch = aOutputStack.amount; + // Not Enough space to insert all of the fluid. + // We fill this hatch and add a smaller Fluidstack back to the iterator. + if (aSpaceLeftInHatch < aFluidToPutIntoHatch) { + // Copy existing Hatch Stack + FluidStack aNewHatchStack = aHatchStack.copy(); + aNewHatchStack.amount = 0; + // Copy existing Hatch Stack again + FluidStack aNewOutputStack = aHatchStack.copy(); + aNewOutputStack.amount = 0; + // How much fluid do we have left after we fill the hatch? + int aFluidLeftAfterInsert = aFluidToPutIntoHatch - aSpaceLeftInHatch; + // Set new stacks to appropriate values + aNewHatchStack.amount = aHatch.getCapacity(); + aNewOutputStack.amount = aFluidLeftAfterInsert; + // Remove fluid from output list, merge success + aOutputFluids.remove(aOutputStack); + // Remove hatch from hatch list, data is now invalid. + aOutputHatches.remove(aHatchData); + // Add remaining Fluid to Output list + aOutputFluids.add(aNewOutputStack); + // Re-add hatch to hatch list, with new data. + Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(aHatch, aNewHatchStack, aNewHatchStack.amount); + aOutputHatches.add(aNewHatchData); + continue aHatchIterator; + } + // We can fill this hatch perfectly (rare case), may as well add it directly to the full list. + else if (aSpaceLeftInHatch == aFluidToPutIntoHatch) { + // Copy Old Stack + FluidStack aNewHatchStack = aHatchStack.copy(); + // Add in amount from output stack + aNewHatchStack.amount += aOutputStack.amount; + // Remove fluid from output list, merge success + aOutputFluids.remove(aOutputStack); + // Remove hatch from hatch list, data is now invalid. + aOutputHatches.remove(aHatchData); + // Re-add hatch to hatch list, with new data. + Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(aHatch, aNewHatchStack, aNewHatchStack.amount); + aOutputHatches.add(aNewHatchData); + continue aHatchIterator; + } + // We have more space than we need to merge, so we remove the stack from the output list and update the hatch list. + else { + // Copy Old Stack + FluidStack aNewHatchStack = aHatchStack.copy(); + // Add in amount from output stack + aNewHatchStack.amount += aOutputStack.amount; + // Remove fluid from output list, merge success + aOutputFluids.remove(aOutputStack); + // Remove hatch from hatch list, data is now invalid. + aOutputHatches.remove(aHatchData); + // Re-add hatch to hatch list, with new data. + Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(aHatch, aNewHatchStack, aNewHatchStack.amount); + aOutputHatches.add(aNewHatchData); + // Check next fluid + continue aFluidMatch; + } + + } + else { + continue aFluidMatch; + } + } } } - if (!tCanBufferFluid) return false; + + for (Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aFreeHatchCheck : aOutputHatches) { + // Free Hatch + if (aFreeHatchCheck.getValue_2() == null || aFreeHatchCheck.getValue_3() == 0 || aFreeHatchCheck.getValue_1().getFluid() == null) { + aEmptyFluidHatches++; + } + } + + // We have Fluid Stacks we did not merge. Do we have space? + if (aOutputFluids.size() > 0) { + // Not enough space to add fluids. + if (aOutputFluids.size() < aEmptyFluidHatches) { + Logger.INFO("Failed to find enough space for all fluid outputs."); + return false; + } + } + + /* + * End Fluid Management + */ } + return true; } @@ -484,21 +790,26 @@ GT_MetaTileEntity_MultiBlockBase { public static Method aLogger = null; public void log(String s) { - - boolean isDebugLogging = CORE.DEBUG; boolean reset = true; - - if (aLogger == null || reset) { - if (isDebugLogging) { - aLogger = ReflectionUtils.getMethod(Logger.class, "INFO", String.class); + if (reset || aLogger == null) { + if (!AsmConfig.disableAllLogging) { + aLogger = ReflectionUtils.getMethod( + Logger.class, "INFO", String.class + ); } else { - aLogger = ReflectionUtils.getMethod(Logger.class, "MACHINE_INFO", String.class); + aLogger = ReflectionUtils.getMethod( + Logger.class, "MACHINE_INFO", String.class + ); } } try { aLogger.invoke(null, s); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {} + } + catch (IllegalAccessException | IllegalArgumentException + | InvocationTargetException e) { + e.printStackTrace(); + } } @@ -678,12 +989,20 @@ GT_MetaTileEntity_MultiBlockBase { * log("GOOD RETURN - 1"); return true; } */ + public long getMaxInputEnergy() { + long rEnergy = 0; + if (mEnergyHatches.size() < 2) // so it only takes 1 amp is only 1 hatch is present so it works like most gt multies + return mEnergyHatches.get(0).getBaseMetaTileEntity().getInputVoltage(); + for (GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) + if (isValidMetaTileEntity(tHatch)) rEnergy += tHatch.getBaseMetaTileEntity().getInputVoltage() * tHatch.getBaseMetaTileEntity().getInputAmperage(); + return rEnergy; + } + public boolean checkRecipeGeneric( ItemStack[] aItemInputs, FluidStack[] aFluidInputs, int aMaxParallelRecipes, int aEUPercent, int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe) { - // Based on the Processing Array. A bit overkill, but very flexible. - + // Based on the Processing Array. A bit overkill, but very flexible. // Reset outputs and progress stats this.mEUt = 0; @@ -693,13 +1012,13 @@ GT_MetaTileEntity_MultiBlockBase { long tVoltage = getMaxInputVoltage(); byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); log("Running checkRecipeGeneric(0)"); - - + GT_Recipe tRecipe = findRecipe( getBaseMetaTileEntity(), mLastRecipe, false, - gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); - + gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); + log("Running checkRecipeGeneric(1)"); // Remember last recipe - an optimization for findRecipe() this.mLastRecipe = tRecipe; @@ -708,6 +1027,50 @@ GT_MetaTileEntity_MultiBlockBase { log("BAD RETURN - 1"); return false; } + + + /* + * Check for Special Behaviours + */ + + // First populate the map if we need to. + if (mCustomBehviours == null || mCustomBehviours.isEmpty()) { + mCustomBehviours.putAll(Multiblock_API.getSpecialBehaviourItemMap()); + } + + // We have a special slot object in the recipe + if (tRecipe.mSpecialItems != null) { + // The special slot is an item + if (tRecipe.mSpecialItems instanceof ItemStack) { + // Make an Itemstack instance of this. + ItemStack aSpecialStack = (ItemStack) tRecipe.mSpecialItems; + // Check if this item is in an input bus. + boolean aDidFindMatch = false; + for (ItemStack aInputItemsToCheck : aItemInputs) { + // If we find a matching stack, continue. + if (GT_Utility.areStacksEqual(aSpecialStack, aInputItemsToCheck, false)) { + // Iterate all special behaviour items, to see if we need to utilise one. + aDidFindMatch = true; + break; + } + } + // Try prevent needless iteration loops if we don't have the required inputs at all. + if (aDidFindMatch) { + // Iterate all special behaviour items, to see if we need to utilise one. + for (SpecialMultiBehaviour aBehaviours : mCustomBehviours.values()) { + // Found a match, let's adjust this recipe now. + if (aBehaviours.isTriggerItem(aSpecialStack)) { + // Adjust this recipe to suit special item + aMaxParallelRecipes = aBehaviours.getMaxParallelRecipes(); + aEUPercent = aBehaviours.getEUPercent(); + aSpeedBonusPercent = aBehaviours.getSpeedBonusPercent(); + aOutputChanceRoll = aBehaviours.getOutputChanceRoll(); + break; + } + } + } + } + } if (!this.canBufferOutputs(tRecipe, aMaxParallelRecipes)) { log("BAD RETURN - 2"); @@ -726,7 +1089,7 @@ GT_MetaTileEntity_MultiBlockBase { log("tVoltage: "+tVoltage); log("tRecipeEUt: "+tRecipeEUt); // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits - for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tVoltage - tRecipeEUt); parallelRecipes++) { + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { log("Broke at "+parallelRecipes+"."); break; @@ -743,6 +1106,7 @@ GT_MetaTileEntity_MultiBlockBase { // -- Try not to fail after this point - inputs have already been consumed! -- + // Convert speed bonus to duration multiplier // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); @@ -835,7 +1199,7 @@ GT_MetaTileEntity_MultiBlockBase { log("GOOD RETURN - 1"); return true; -} + } @@ -932,10 +1296,10 @@ GT_MetaTileEntity_MultiBlockBase { ItemStack[] aItemInputs, FluidStack[] aFluidInputs, int aMaxParallelRecipes, int aEUPercent, int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe) { - + long tVoltage = getMaxInputVoltage(); byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - + long tEnergy = getMaxInputEnergy(); log("Running checkRecipeGeneric(0)"); GT_Recipe tRecipe = aRecipe != null ? aRecipe : findRecipe( @@ -943,12 +1307,12 @@ GT_MetaTileEntity_MultiBlockBase { gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); log("Running checkRecipeGeneric(1)"); - + //First we check whether or not we have an input cached for boosting. //If not, we set it to the current recipe. //If we do, we compare it against the current recipe, if thy are the same, we try return a boosted recipe, if not, we boost a new recipe. boolean isRecipeInputTheSame = false; - + //No cached recipe inputs, assume first run. if (mInputVerificationForBoosting == null) { mInputVerificationForBoosting = tRecipe.mInputs; @@ -963,7 +1327,7 @@ GT_MetaTileEntity_MultiBlockBase { isRecipeInputTheSame = false; } } - + //Inputs are the same, let's see if there's a boosted version. if (isRecipeInputTheSame) { //Yes, let's just set that as the recipe @@ -999,14 +1363,14 @@ GT_MetaTileEntity_MultiBlockBase { mHasBoostedCurrentRecipe = false; } } - + //Bad modify, let's just use the original recipe. if (!mHasBoostedCurrentRecipe || mBoostedRecipe == null) { tRecipe = aRecipe != null ? aRecipe : findRecipe( getBaseMetaTileEntity(), mLastRecipe, false, gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); } - + // Remember last recipe - an optimization for findRecipe() this.mLastRecipe = tRecipe; @@ -1032,7 +1396,7 @@ GT_MetaTileEntity_MultiBlockBase { log("tVoltage: "+tVoltage); log("tRecipeEUt: "+tRecipeEUt); // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits - for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tVoltage - tRecipeEUt); parallelRecipes++) { + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { log("Broke at "+parallelRecipes+"."); break; @@ -1188,6 +1552,7 @@ GT_MetaTileEntity_MultiBlockBase { this.mChargeHatches.clear(); this.mDischargeHatches.clear(); this.mControlCoreBus.clear(); + this.mAirIntakes.clear(); this.mMultiDynamoHatches.clear(); } } @@ -1252,22 +1617,22 @@ GT_MetaTileEntity_MultiBlockBase { ItemStack guiSlot = this.mInventory[1]; return guiSlot; } - + protected boolean setGUIItemStack(ItemStack aNewGuiSlotContents) { boolean result = false; if (this.mInventory[1] == null) { this.mInventory[1] = aNewGuiSlotContents != null ? aNewGuiSlotContents.copy() : null; - aNewGuiSlotContents = null; + this.depleteInput(aNewGuiSlotContents); this.updateSlots(); result = true; } return result; } - + protected boolean clearGUIItemSlot() { return setGUIItemStack(null); } - + public ItemStack findItemInInventory(Item aSearchStack) { return findItemInInventory(aSearchStack, 0); @@ -1276,7 +1641,7 @@ GT_MetaTileEntity_MultiBlockBase { public ItemStack findItemInInventory(Item aSearchStack, int aMeta) { return findItemInInventory(ItemUtils.simpleMetaStack(aSearchStack, aMeta, 1)); } - + public ItemStack findItemInInventory(ItemStack aSearchStack) { if (aSearchStack != null && this.mInputBusses.size() > 0) { for (GT_MetaTileEntity_Hatch_InputBus bus : this.mInputBusses) { @@ -1325,54 +1690,63 @@ GT_MetaTileEntity_MultiBlockBase { public boolean causeMaintenanceIssue() { boolean b = false; switch (this.getBaseMetaTileEntity().getRandomNumber(6)) { - case 0 : { - this.mWrench = false; - b = true; - break; - } - case 1 : { - this.mScrewdriver = false; - b = true; - break; - } - case 2 : { - this.mSoftHammer = false; - b = true; - break; - } - case 3 : { - this.mHardHammer = false; - b = true; - break; - } - case 4 : { - this.mSolderingTool = false; - b = true; - break; - } - case 5 : { - this.mCrowbar = false; - b = true; - break; - } + case 0 : { + this.mWrench = false; + b = true; + break; + } + case 1 : { + this.mScrewdriver = false; + b = true; + break; + } + case 2 : { + this.mSoftHammer = false; + b = true; + break; + } + case 3 : { + this.mHardHammer = false; + b = true; + break; + } + case 4 : { + this.mSolderingTool = false; + b = true; + break; + } + case 5 : { + this.mCrowbar = false; + b = true; + break; + } } return b; } + public void fixAllMaintenanceIssue() { + this.mCrowbar = true; + this.mWrench = true; + this.mHardHammer = true; + this.mSoftHammer = true; + this.mSolderingTool = true; + this.mScrewdriver = true; + } + public <E> boolean addToMachineListInternal(ArrayList<E> aList, final IMetaTileEntity aTileEntity, final int aBaseCasingIndex) { if (aTileEntity == null) { return false; } - + //Check type /* * Class <?> aHatchType = ReflectionUtils.getTypeOfGenericObject(aList); if * (!aHatchType.isInstance(aTileEntity)) { return false; } */ - - + + if (aList.isEmpty()) { if (aTileEntity instanceof GT_MetaTileEntity_Hatch) { if (GTplusplus.CURRENT_LOAD_PHASE == INIT_PHASE.STARTED) { @@ -1387,13 +1761,15 @@ GT_MetaTileEntity_MultiBlockBase { boolean aExists = false; for (E m : aList) { IGregTechTileEntity b = ((IMetaTileEntity) m).getBaseMetaTileEntity(); - BlockPos aPos = new BlockPos(b); - if (b != null && aPos != null) { - if (aCurPos.equals(aPos)) { - if (GTplusplus.CURRENT_LOAD_PHASE == INIT_PHASE.STARTED) { - log("Found Duplicate "+b.getInventoryName()+" at " + aPos.getLocationString()); + if (b != null) { + BlockPos aPos = new BlockPos(b); + if (aPos != null) { + if (aCurPos.equals(aPos)) { + if (GTplusplus.CURRENT_LOAD_PHASE == INIT_PHASE.STARTED) { + log("Found Duplicate "+b.getInventoryName()+" at " + aPos.getLocationString()); + } + return false; } - return false; } } } @@ -1546,6 +1922,20 @@ GT_MetaTileEntity_MultiBlockBase { return addToMachineList(aTileEntity, aBaseCasingIndex); } + public boolean addAirIntakeToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_AirIntake) { + this.mAirIntakes.add((GT_MetaTileEntity_Hatch_AirIntake)aMetaTileEntity); + } + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + public boolean addFluidInputToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { if (aTileEntity == null) { return false; @@ -1569,6 +1959,10 @@ GT_MetaTileEntity_MultiBlockBase { return false; } + public boolean clearRecipeMapForAllInputHatches() { + return resetRecipeMapForAllInputHatches(null); + } + public boolean resetRecipeMapForAllInputHatches() { return resetRecipeMapForAllInputHatches(this.getRecipeMap()); } @@ -1588,17 +1982,22 @@ GT_MetaTileEntity_MultiBlockBase { return cleared > 0; } public boolean resetRecipeMapForHatch(IGregTechTileEntity aTileEntity, GT_Recipe_Map aMap) { - if (aTileEntity == null) { - return false; - } - final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity();; - if (aMetaTileEntity == null) { - return false; - } - if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { - return resetRecipeMapForHatch((GT_MetaTileEntity_Hatch)aMetaTileEntity, aMap); + try { + if (aTileEntity == null) { + return false; + } + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { + return resetRecipeMapForHatch((GT_MetaTileEntity_Hatch)aMetaTileEntity, aMap); + } + else { + return false; + } } - else { + catch (Throwable t) { return false; } } @@ -1611,12 +2010,23 @@ GT_MetaTileEntity_MultiBlockBase { if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input){ ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = null; - ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = aMap; - log("Remapped Input Hatch to "+aMap.mNEIName); + ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = aMap; + if (aMap != null && aMap.mNEIName != null) { + log("Remapped Input Hatch to "+aMap.mNEIName+"."); + } + else { + log("Cleared Input Hatch."); + } } else { ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mRecipeMap = null; - ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mRecipeMap = aMap; + ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mRecipeMap = aMap; + if (aMap != null && aMap.mNEIName != null) { + log("Remapped Input Bus to "+aMap.mNEIName+"."); + } + else { + log("Cleared Input Bus."); + } } return true; } @@ -1628,8 +2038,9 @@ GT_MetaTileEntity_MultiBlockBase { @Override public final void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); - resetRecipeMapForAllInputHatches(); + clearRecipeMapForAllInputHatches(); onModeChangeByScrewdriver(aSide, aPlayer, aX, aY, aZ); + resetRecipeMapForAllInputHatches(); } public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { @@ -1745,7 +2156,7 @@ GT_MetaTileEntity_MultiBlockBase { @SuppressWarnings("rawtypes") public boolean isThisHatchMultiDynamo(Object aMetaTileEntity){ - Class mDynamoClass; + Class<?> mDynamoClass; mDynamoClass = ReflectionUtils.getClass("com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoMulti"); if (mDynamoClass != null){ if (mDynamoClass.isInstance(aMetaTileEntity)){ @@ -1784,20 +2195,16 @@ GT_MetaTileEntity_MultiBlockBase { } } - private static Method calculatePollutionReduction; + private static Method calculatePollutionReduction = null; public int calculatePollutionReductionForHatch(GT_MetaTileEntity_Hatch_Muffler i , int g) { - if (calculatePollutionReduction == null) { + if (calculatePollutionReduction != null) { try { - calculatePollutionReduction = i.getClass().getDeclaredMethod("calculatePollutionReduction", int.class); - } catch (NoSuchMethodException | SecurityException e) { - calculatePollutionReduction = null; + return (int) calculatePollutionReduction.invoke(i, g); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } - } - try { - return (int) calculatePollutionReduction.invoke(i, g); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - return 0; } + return 0; } @Override @@ -2104,6 +2511,59 @@ GT_MetaTileEntity_MultiBlockBase { return false; } + @Override + public boolean depleteInput(final FluidStack aLiquid) { + if (aLiquid == null) { + return false; + } + for (final GT_MetaTileEntity_Hatch_Input tHatch : this.mInputHatches) { + tHatch.mRecipeMap = this.getRecipeMap(); + if (isValidMetaTileEntity(tHatch)) { + FluidStack tLiquid = tHatch.getFluid(); + if (tLiquid == null || !tLiquid.isFluidEqual(aLiquid) || tLiquid.amount < aLiquid.amount) { + continue; + } + tLiquid = tHatch.drain(aLiquid.amount, false); + if (tLiquid != null && tLiquid.amount >= aLiquid.amount) { + tLiquid = tHatch.drain(aLiquid.amount, true); + return tLiquid != null && tLiquid.amount >= aLiquid.amount; + } + continue; + } + } + return false; + } + + @Override + public void onServerStart() { + super.onServerStart(); + tryTickWaitTimerDown(); + } + + @Override + public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + tryTickWaitTimerDown(); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + tryTickWaitTimerDown(); + } + + @Override + public void onCreated(ItemStack aStack, World aWorld, EntityPlayer aPlayer) { + super.onCreated(aStack, aWorld, aPlayer); + tryTickWaitTimerDown(); + } + + private final void tryTickWaitTimerDown() { + /*if (mStartUpCheck > 10) { + mStartUpCheck = 10; + }*/ + } + |