From 3b15de7e6090b0b60dd77311d8e599c7dccd9326 Mon Sep 17 00:00:00 2001 From: Alkalus Date: Sat, 9 Sep 2017 21:10:23 +1000 Subject: - Removed Superconductors and Conduction Nodes. --- .../GregtechMetaPipeEntity_SuperConductor.java | 263 --- .../GregtechMetaSuperConductorNodeBase.java | 316 --- .../GregtechBaseMetaTileEntityLossless.java | 2113 -------------------- .../GregtechMetaPipeEntity_BaseSuperConductor.java | 663 ------ .../lossless/GregtechMetaTileEntityLossless.java | 71 - .../GregtechMetaTileEntityLosslessBasicTank.java | 265 --- ...chMetaTileEntityLosslessTieredMachineBlock.java | 71 - .../base/lossless/MetaTileEntityLossless.java | 889 -------- 8 files changed, 4651 deletions(-) delete mode 100644 src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_SuperConductor.java delete mode 100644 src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaSuperConductorNodeBase.java delete mode 100644 src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/lossless/GregtechBaseMetaTileEntityLossless.java delete mode 100644 src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/lossless/GregtechMetaPipeEntity_BaseSuperConductor.java delete mode 100644 src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/lossless/GregtechMetaTileEntityLossless.java delete mode 100644 src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/lossless/GregtechMetaTileEntityLosslessBasicTank.java delete mode 100644 src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/lossless/GregtechMetaTileEntityLosslessTieredMachineBlock.java delete mode 100644 src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/lossless/MetaTileEntityLossless.java (limited to 'src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity') diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_SuperConductor.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_SuperConductor.java deleted file mode 100644 index b6f798c57a..0000000000 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_SuperConductor.java +++ /dev/null @@ -1,263 +0,0 @@ -package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; - -import static gregtech.api.enums.GT_Values.VN; - -import java.util.ArrayList; -import java.util.Arrays; - -import cofh.energy.IEnergyReceiver; -import gregtech.api.GregTech_API; -import gregtech.api.enums.*; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.metatileentity.IMetaTileEntityCable; -import gregtech.api.interfaces.tileentity.*; -import gregtech.api.metatileentity.BaseMetaPipeEntity; -import gregtech.api.objects.GT_RenderedTexture; -import gregtech.api.util.GT_Utility; -import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials; -import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMetaPipeEntityBase_Cable; -import ic2.api.energy.tile.IEnergySink; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -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 GregtechMetaPipeEntity_SuperConductor extends GregtechMetaPipeEntityBase_Cable implements IMetaTileEntityCable { - - public final float mThickNess; - public final GT_Materials mMaterial; - public final long mCableLossPerMeter, mAmperage, mVoltage; - public final boolean mInsulated, mCanShock; - - public GregtechMetaPipeEntity_SuperConductor(final int aID, final String aName, final String aNameRegional, final float aThickNess, final GT_Materials aMaterial, final long aCableLossPerMeter, final long aAmperage, final long aVoltage, final boolean aInsulated, final boolean aCanShock) { - super(aID, aName, aNameRegional, 0, aMaterial, 0, aAmperage, aVoltage, aInsulated, aCanShock); - this.mThickNess = aThickNess; - this.mMaterial = aMaterial; - this.mAmperage = aAmperage; - this.mVoltage = aVoltage; - this.mInsulated = aInsulated; - this.mCanShock = aCanShock; - this.mCableLossPerMeter = 0; - } - - public GregtechMetaPipeEntity_SuperConductor(final String aName, final float aThickNess, final GT_Materials aMaterial, final long aCableLossPerMeter, final long aAmperage, final long aVoltage, final boolean aInsulated, final boolean aCanShock) { - super(aName, 0, aMaterial, 0, aAmperage, aVoltage, aInsulated, aCanShock); - this.mThickNess = aThickNess; - this.mMaterial = aMaterial; - this.mAmperage = aAmperage; - this.mVoltage = aVoltage; - this.mInsulated = aInsulated; - this.mCanShock = aCanShock; - this.mCableLossPerMeter = 0; - } - - @Override - public byte getTileEntityBaseType() { - return (byte)(this.mInsulated?9:8); - } - - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaPipeEntity_SuperConductor(this.mName, this.mThickNess, this.mMaterial, this.mCableLossPerMeter, this.mAmperage, this.mVoltage, this.mInsulated, this.mCanShock); - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aConnections, final byte aColorIndex, final boolean aConnected, final boolean aRedstone) { - if (!this.mInsulated) { - return new ITexture[] {new GT_RenderedTexture(this.mMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], this.mMaterial.mRGBa)}; - } - if (aConnected) { - final float tThickNess = this.getThickNess(); - if (tThickNess < 0.37F) { - return new ITexture[] {new GT_RenderedTexture(this.mMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], this.mMaterial.mRGBa), new GT_RenderedTexture(Textures.BlockIcons.INSULATION_TINY , Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa))}; - } - if (tThickNess < 0.49F) { - return new ITexture[] {new GT_RenderedTexture(this.mMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], this.mMaterial.mRGBa), new GT_RenderedTexture(Textures.BlockIcons.INSULATION_SMALL , Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa))}; - } - if (tThickNess < 0.74F) { - return new ITexture[] {new GT_RenderedTexture(this.mMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], this.mMaterial.mRGBa), new GT_RenderedTexture(Textures.BlockIcons.INSULATION_MEDIUM , Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa))}; - } - if (tThickNess < 0.99F) { - return new ITexture[] {new GT_RenderedTexture(this.mMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], this.mMaterial.mRGBa), new GT_RenderedTexture(Textures.BlockIcons.INSULATION_LARGE , Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa))}; - } - return new ITexture[] {new GT_RenderedTexture(this.mMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], this.mMaterial.mRGBa), new GT_RenderedTexture(Textures.BlockIcons.INSULATION_HUGE , Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa))}; - } - return new ITexture[] {new GT_RenderedTexture(Textures.BlockIcons.INSULATION_FULL, Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa))}; - } - - @Override - public void onEntityCollidedWithBlock(final World aWorld, final int aX, final int aY, final int aZ, final Entity aEntity) { - if (this.mCanShock && ((((BaseMetaPipeEntity)this.getBaseMetaTileEntity()).mConnections & -128) == 0) && (aEntity instanceof EntityLivingBase)) { - GT_Utility.applyElectricityDamage((EntityLivingBase)aEntity, this.mTransferredVoltageLast20, this.mTransferredAmperageLast20); - } - } - - @Override - public AxisAlignedBB getCollisionBoundingBoxFromPool(final World aWorld, final int aX, final int aY, final int aZ) { - if (!this.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(final byte aFacing) {return false;} - @Override public boolean isValidSlot(final int aIndex) {return true;} - // @Override public final boolean renderInside(byte aSide) {return false;} - @Override public int getProgresstime() {return (int)this.mTransferredAmperage*64;} - @Override public int maxProgresstime() {return (int)this.mAmperage*64;} - - @Override - public long injectEnergyUnits(final byte aSide, final long aVoltage, final long aAmperage) { - if (!this.getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide).letsEnergyIn(aSide, this.getBaseMetaTileEntity().getCoverIDAtSide(aSide), this.getBaseMetaTileEntity().getCoverDataAtSide(aSide), this.getBaseMetaTileEntity())) { - return 0; - } - return this.transferElectricity(aSide, aVoltage, aAmperage, new ArrayList<>(Arrays.asList((TileEntity)this.getBaseMetaTileEntity()))); - } - - @Override - public long transferElectricity(final byte aSide, long aVoltage, final long aAmperage, final ArrayList aAlreadyPassedTileEntityList) { - long rUsedAmperes = 0; - aVoltage -= this.mCableLossPerMeter; - if (aVoltage > 0) { - for (byte i = 0; (i < 6) && (aAmperage > rUsedAmperes); i++) { - if ((i != aSide) && ((this.mConnections & (1<= 0) { - final byte tColor = ((IEnergyConnected)tTileEntity).getColorization(); - if ((tColor >= 0) && (tColor != this.getBaseMetaTileEntity().getColorization())) { - continue; - } - } - if ((tTileEntity instanceof IGregTechTileEntity) && (((IGregTechTileEntity)tTileEntity).getMetaTileEntity() instanceof IMetaTileEntityCable) && ((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() > 50) { - rUsedAmperes += ((IMetaTileEntityCable)((IGregTechTileEntity)tTileEntity).getMetaTileEntity()).transferElectricity(GT_Utility.getOppositeSide(i), aVoltage, aAmperage-rUsedAmperes, aAlreadyPassedTileEntityList); - } - } else { - rUsedAmperes += ((IEnergyConnected)tTileEntity).injectEnergyUnits(GT_Utility.getOppositeSide(i), aVoltage, aAmperage-rUsedAmperes); - } - // } else if (tTileEntity instanceof IEnergySink) { - // ForgeDirection tDirection = ForgeDirection.getOrientation(i).getOpposite(); - // if (((IEnergySink)tTileEntity).acceptsEnergyFrom((TileEntity)getBaseMetaTileEntity(), tDirection)) { - // if (((IEnergySink)tTileEntity).demandedEnergyUnits() > 0 && ((IEnergySink)tTileEntity).injectEnergyUnits(tDirection, aVoltage) < aVoltage) rUsedAmperes++; - // } - } else if (tTileEntity instanceof IEnergySink) { - final ForgeDirection tDirection = ForgeDirection.getOrientation(i).getOpposite(); - if (((IEnergySink)tTileEntity).acceptsEnergyFrom((TileEntity)this.getBaseMetaTileEntity(), tDirection)) { - if ((((IEnergySink)tTileEntity).getDemandedEnergy() > 0) && (((IEnergySink)tTileEntity).injectEnergy(tDirection, aVoltage, aVoltage) < aVoltage)) { - rUsedAmperes++; - } - } - } else if(GregTech_API.mOutputRF && (tTileEntity instanceof IEnergyReceiver)){ - final ForgeDirection tDirection = ForgeDirection.getOrientation(i).getOpposite(); - final int rfOut = (int) ((aVoltage * GregTech_API.mEUtoRF) / 100); - if(((IEnergyReceiver)tTileEntity).receiveEnergy(tDirection, rfOut, true)==rfOut){ - ((IEnergyReceiver)tTileEntity).receiveEnergy(tDirection, rfOut, false); rUsedAmperes++; - }else if(((IEnergyReceiver)tTileEntity).receiveEnergy(tDirection, rfOut, true)>0){ - if(this.mRestRF==0){ - final int RFtrans = ((IEnergyReceiver)tTileEntity).receiveEnergy(tDirection, rfOut, false);rUsedAmperes++; - this.mRestRF = rfOut - RFtrans; - }else{ - final int RFtrans = ((IEnergyReceiver)tTileEntity).receiveEnergy(tDirection, (int) this.mRestRF, false); - this.mRestRF = this.mRestRF - RFtrans; - } - } - if(GregTech_API.mRFExplosions && (((IEnergyReceiver)tTileEntity).getMaxEnergyStored(tDirection) < (rfOut * 600))){ - if(rfOut > ((32 * GregTech_API.mEUtoRF) / 100)) { - this.doExplosion(rfOut); - } - } - } - } - } - } - } - this.mTransferredAmperage += rUsedAmperes; - this.mTransferredVoltageLast20 = Math.max(this.mTransferredVoltageLast20, aVoltage); - this.mTransferredAmperageLast20 = Math.max(this.mTransferredAmperageLast20, this.mTransferredAmperage); - if ((aVoltage > this.mVoltage) || (this.mTransferredAmperage > this.mAmperage)) { - this.getBaseMetaTileEntity().setToFire(); - return aAmperage; - } - return rUsedAmperes; - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - if (aBaseMetaTileEntity.isServerSide()) { - this.mTransferredAmperage = 0; - - if ((aTick % 20) == 0) { - this.mTransferredVoltageLast20 = 0; - this.mTransferredAmperageLast20 = 0; - this.mConnections = 0; - for (byte i = 0, j = 0; i < 6; i++) { - j = GT_Utility.getOppositeSide(i); - if (aBaseMetaTileEntity.getCoverBehaviorAtSide(i).alwaysLookConnected(i, aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getCoverDataAtSide(i), aBaseMetaTileEntity) || aBaseMetaTileEntity.getCoverBehaviorAtSide(i).letsEnergyIn(i, aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getCoverDataAtSide(i), aBaseMetaTileEntity) || aBaseMetaTileEntity.getCoverBehaviorAtSide(i).letsEnergyOut(i, aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getCoverDataAtSide(i), aBaseMetaTileEntity)) { - final TileEntity tTileEntity = aBaseMetaTileEntity.getTileEntityAtSide(i); - if (tTileEntity instanceof IColoredTileEntity) { - if (aBaseMetaTileEntity.getColorization() >= 0) { - final byte tColor = ((IColoredTileEntity)tTileEntity).getColorization(); - if ((tColor >= 0) && (tColor != aBaseMetaTileEntity.getColorization())) { - continue; - } - } - } - if ((tTileEntity instanceof IEnergyConnected) && (((IEnergyConnected)tTileEntity).inputEnergyFrom(j) || ((IEnergyConnected)tTileEntity).outputsEnergyTo(j))) { - this.mConnections |= (1< 1; - } - - @Override - public boolean isSimpleMachine() { - return false; - } - - @Override - public boolean isValidSlot(final int aIndex) { - return aIndex < 2; - } - - @Override - public boolean isEnetInput() { - return true; - } - - @Override - public boolean isEnetOutput() { - return true; - } - - @Override - public boolean isOutputFacing(final byte aSide) { - return true; - } - - @Override - public boolean isAccessAllowed(final EntityPlayer aPlayer) { - return true; - } - - @Override - public long getMinimumStoredEU() { - return V[this.mTier] * 16 * this.mInventory.length; - } - - @Override - public long maxEUStore() { - return V[this.mTier] * 64; - } - - @Override - public long maxEUInput() { - return V[this.mTier]; - } - - @Override - public long maxEUOutput() { - return V[this.mTier]; - } - - @Override - public long maxAmperesIn() { - return 16; - } - - @Override - public long maxAmperesOut() { - return 16; - } - - @Override - public boolean doesFillContainers() { - return this.getBaseMetaTileEntity().isAllowedToWork(); - } - - @Override - public boolean doesEmptyContainers() { - return this.getBaseMetaTileEntity().isAllowedToWork(); - } - - @Override - public boolean canTankBeFilled() { - return this.getBaseMetaTileEntity().isAllowedToWork(); - } - - @Override - public boolean canTankBeEmptied() { - return this.getBaseMetaTileEntity().isAllowedToWork(); - } - - @Override - public boolean displaysItemStack() { - return true; - } - - @Override - public boolean displaysStackSize() { - return false; - } - - @Override - public boolean isFluidInputAllowed(final FluidStack aFluid) { - return this.getFuelValue(aFluid) > 0; - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - if ((this.getEUVar() == this.maxEUStore()) || (this.mFluid == null)){ - aBaseMetaTileEntity.disableWorking(); - } - else { - aBaseMetaTileEntity.enableWorking(); - } - if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() && ((aTick % 10) == 0)) { - if (this.mFluid == null) { - if (aBaseMetaTileEntity.getUniversalEnergyStored() < (this.maxEUOutput() + this.getMinimumStoredEU())) { - this.mInventory[this.getStackDisplaySlot()] = null; - } else { - if (this.mInventory[this.getStackDisplaySlot()] == null) { - this.mInventory[this.getStackDisplaySlot()] = new ItemStack(Blocks.fire, 1); - } - this.mInventory[this.getStackDisplaySlot()].setStackDisplayName("Generating: " + (aBaseMetaTileEntity.getUniversalEnergyStored() - this.getMinimumStoredEU()) + " EU"); - } - } else { - final int tFuelValue = this.getFuelValue(this.mFluid), tConsumed = this.consumedFluidPerOperation(this.mFluid); - if ((tConsumed > 0) && (this.mFluid.amount > tConsumed)) { - final long tFluidAmountToUse = Math.min(this.mFluid.amount / tConsumed, (((this.maxEUOutput() * 20) + this.getMinimumStoredEU()) - aBaseMetaTileEntity.getUniversalEnergyStored())); - if (tFluidAmountToUse > 0 /*&& aBaseMetaTileEntity.increaseStoredEnergyUnits(tFluidAmountToUse * tFuelValue, true)*/) { - this.mFluid.amount -= tFluidAmountToUse * tConsumed; - } - } - } - if ((this.mInventory[this.getInputSlot()] != null) && (aBaseMetaTileEntity.getUniversalEnergyStored() < ((this.maxEUOutput() * 20) + this.getMinimumStoredEU())) && (GT_Utility.getFluidForFilledItem(this.mInventory[this.getInputSlot()], true) == null)) { - final int tFuelValue = this.getFuelValue(this.mInventory[this.getInputSlot()]); - if (tFuelValue >= 0) { - final ItemStack tEmptyContainer = this.getEmptyContainer(this.mInventory[this.getInputSlot()]); - if (aBaseMetaTileEntity.addStackToSlot(this.getOutputSlot(), tEmptyContainer)) { - //aBaseMetaTileEntity.increaseStoredEnergyUnits(tFuelValue, true); - aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); - } - } - } - } - - if (aBaseMetaTileEntity.isServerSide()) { - aBaseMetaTileEntity.setActive(aBaseMetaTileEntity.isAllowedToWork() && (aBaseMetaTileEntity.getUniversalEnergyStored() >= (this.maxEUOutput() + this.getMinimumStoredEU()))); - } - } - - public abstract GT_Recipe_Map getRecipes(); - - public abstract int getEfficiency(); - - public int consumedFluidPerOperation(final FluidStack aLiquid) { - return 1; - } - - public int getFuelValue(final FluidStack aLiquid) { - if ((aLiquid == null) || (this.getRecipes() == null)) { - return 0; - } - FluidStack tLiquid; - final Collection tRecipeList = this.getRecipes().mRecipeList; - if (tRecipeList != null) { - for (final GT_Recipe tFuel : tRecipeList) { - if ((tLiquid = GT_Utility.getFluidForFilledItem(tFuel.getRepresentativeInput(0), true)) != null) { - if (aLiquid.isFluidEqual(tLiquid)) { - return 0; - } - } - } - } - //return (int) (((long) tFuel.mSpecialValue * getEfficiency() * consumedFluidPerOperation(tLiquid)) / 100); - return 0; - } - - public int getFuelValue(final ItemStack aStack) { - if (GT_Utility.isStackInvalid(aStack) || (this.getRecipes() == null)) { - return 0; - } - final GT_Recipe tFuel = this.getRecipes().findRecipe(this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack); - if (tFuel != null) { - return 0; - } - //return (int) ((tFuel.mSpecialValue * 1000L * getEfficiency()) / 100); - return 0; - } - - public ItemStack getEmptyContainer(final ItemStack aStack) { - if (GT_Utility.isStackInvalid(aStack) || (this.getRecipes() == null)) { - return null; - } - final GT_Recipe tFuel = this.getRecipes().findRecipe(this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack); - if (tFuel != null) { - return GT_Utility.copy(tFuel.getOutput(0)); - } - return GT_Utility.getContainerItem(aStack, true); - } - - @Override - public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { - return super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack) && ((this.getFuelValue(aStack) > 0) || (this.getFuelValue(GT_Utility.getFluidForFilledItem(aStack, true)) > 0)); - } - - @Override - public int getCapacity() { - return 16000; - } - - @Override - public int getTankPressure() { - return -100; - } - - -} diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/lossless/GregtechBaseMetaTileEntityLossless.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/lossless/GregtechBaseMetaTileEntityLossless.java deleted file mode 100644 index 3343750c09..0000000000 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/lossless/GregtechBaseMetaTileEntityLossless.java +++ /dev/null @@ -1,2113 +0,0 @@ -package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.lossless; - -import static gregtech.api.enums.GT_Values.NW; -import static gregtech.api.enums.GT_Values.V; - -import java.util.*; - -import gregtech.GT_Mod; -import gregtech.api.GregTech_API; -import gregtech.api.enums.ItemList; -import gregtech.api.enums.Textures; -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.BaseTileEntity; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.net.GT_Packet_TileEntity; -import gregtech.api.objects.GT_ItemStack; -import gregtech.api.util.*; -import ic2.api.Direction; -import net.minecraft.block.Block; -import net.minecraft.block.BlockFire; -import net.minecraft.entity.Entity; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.network.Packet; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.world.EnumSkyBlock; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.*; - -/** - * NEVER INCLUDE THIS FILE IN YOUR MOD!!! - *

- * This is the main TileEntity for EVERYTHING. - */ -public class GregtechBaseMetaTileEntityLossless extends BaseTileEntity implements IGregTechTileEntity { - private final GT_CoverBehavior[] mCoverBehaviors = new GT_CoverBehavior[]{GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior}; - protected MetaTileEntity mMetaTileEntity; - protected long mStoredEnergy = 0, mStoredSteam = 0; - protected int mAverageEUInputIndex = 0, mAverageEUOutputIndex = 0; - protected boolean mReleaseEnergy = false; - protected int[] mAverageEUInput = new int[]{0, 0, 0, 0, 0}, mAverageEUOutput = new int[]{0, 0, 0, 0, 0}; - private final boolean[] mActiveEUInputs = new boolean[]{false, false, false, false, false, false}, mActiveEUOutputs = new boolean[]{false, false, false, false, false, false}; - private byte[] mSidedRedstone = new byte[]{15, 15, 15, 15, 15, 15}; - private int[] mCoverSides = new int[]{0, 0, 0, 0, 0, 0}, mCoverData = new int[]{0, 0, 0, 0, 0, 0}; - private final int[] mTimeStatistics = new int[GregTech_API.TICKS_FOR_LAG_AVERAGING]; - private boolean mHasEnoughEnergy = true, mRunningThroughTick = false, mInputDisabled = false, mOutputDisabled = false, mMuffler = false, mLockUpgrade = false, mActive = false, mRedstone = false, mWorkUpdate = false, mSteamConverter = false, mInventoryChanged = false, mWorks = true, mNeedsUpdate = true, mNeedsBlockUpdate = true, mSendClientData = false, oRedstone = false; - private byte mColor = 0, oColor = 0, mStrongRedstone = 0, oRedstoneData = 63, oTextureData = 0, oUpdateData = 0, oLightValueClient = -1, oLightValue = -1, mLightValue = 0, mOtherUpgrades = 0, mFacing = 0, oFacing = 0, mWorkData = 0; - private int mDisplayErrorCode = 0, oX = 0, oY = 0, oZ = 0, mTimeStatisticsIndex = 0, mLagWarningCount = 0; - private short mID = 0; - private long mTickTimer = 0, oOutput = 0, mAcceptedAmperes = Long.MAX_VALUE; - private String mOwnerName = ""; - private NBTTagCompound mRecipeStuff = new NBTTagCompound(); - - public GregtechBaseMetaTileEntityLossless() { - } - - @Override - public void writeToNBT(final NBTTagCompound aNBT) { - try { - super.writeToNBT(aNBT); - } catch (final Throwable e) { - GT_Log.err.println("Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk whould've been corrupted by now, but I prevented that. Please report immidietly to GregTech Intergalactical!!!"); - e.printStackTrace(GT_Log.err); - } - try { - aNBT.setInteger("mID", this.mID); - aNBT.setLong("mStoredSteam", this.mStoredSteam); - aNBT.setLong("mStoredEnergy", this.mStoredEnergy); - aNBT.setIntArray("mCoverData", this.mCoverData); - aNBT.setIntArray("mCoverSides", this.mCoverSides); - aNBT.setByteArray("mRedstoneSided", this.mSidedRedstone); - aNBT.setByte("mColor", this.mColor); - aNBT.setByte("mLightValue", this.mLightValue); - aNBT.setByte("mOtherUpgrades", this.mOtherUpgrades); - aNBT.setByte("mWorkData", this.mWorkData); - aNBT.setByte("mStrongRedstone", this.mStrongRedstone); - aNBT.setShort("mFacing", this.mFacing); - aNBT.setString("mOwnerName", this.mOwnerName); - aNBT.setBoolean("mLockUpgrade", this.mLockUpgrade); - aNBT.setBoolean("mMuffler", this.mMuffler); - aNBT.setBoolean("mSteamConverter", this.mSteamConverter); - aNBT.setBoolean("mActive", this.mActive); - aNBT.setBoolean("mRedstone", this.mRedstone); - aNBT.setBoolean("mWorks", !this.mWorks); - aNBT.setBoolean("mInputDisabled", this.mInputDisabled); - aNBT.setBoolean("mOutputDisabled", this.mOutputDisabled); - aNBT.setTag("GT.CraftingComponents", this.mRecipeStuff); - } catch (final Throwable e) { - GT_Log.err.println("Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk whould've been corrupted by now, but I prevented that. Please report immidietly to GregTech Intergalactical!!!"); - e.printStackTrace(GT_Log.err); - } - try { - if (this.hasValidMetaTileEntity()) { - final NBTTagList tItemList = new NBTTagList(); - for (int i = 0; i < this.mMetaTileEntity.getRealInventory().length; i++) { - final ItemStack tStack = this.mMetaTileEntity.getRealInventory()[i]; - if (tStack != null) { - final NBTTagCompound tTag = new NBTTagCompound(); - tTag.setInteger("IntSlot", i); - tStack.writeToNBT(tTag); - tItemList.appendTag(tTag); - } - } - aNBT.setTag("Inventory", tItemList); - - try { - this.mMetaTileEntity.saveNBTData(aNBT); - } catch (final Throwable e) { - GT_Log.err.println("Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk whould've been corrupted by now, but I prevented that. Please report immidietly to GregTech Intergalactical!!!"); - e.printStackTrace(GT_Log.err); - } - } - } catch (final Throwable e) { - GT_Log.err.println("Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk whould've been corrupted by now, but I prevented that. Please report immidietly to GregTech Intergalactical!!!"); - e.printStackTrace(GT_Log.err); - } - } - - @Override - public void readFromNBT(final NBTTagCompound aNBT) { - super.readFromNBT(aNBT); - this.setInitialValuesAsNBT(aNBT, (short) 0); - } - - @Override - public void setInitialValuesAsNBT(final NBTTagCompound aNBT, final short aID) { - if (aNBT == null) { - if (aID > 0) { - this.mID = aID; - } else { - this.mID = this.mID > 0 ? this.mID : 0; - } - if (this.mID != 0) { - this.createNewMetatileEntity(this.mID); - } - this.mSidedRedstone = (this.hasValidMetaTileEntity() && this.mMetaTileEntity.hasSidedRedstoneOutputBehavior() ? new byte[]{0, 0, 0, 0, 0, 0} : new byte[]{15, 15, 15, 15, 15, 15}); - } else { - if (aID <= 0) { - this.mID = (short) aNBT.getInteger("mID"); - } else { - this.mID = aID; - } - this.mStoredSteam = aNBT.getInteger("mStoredSteam"); - this.mStoredEnergy = aNBT.getInteger("mStoredEnergy"); - this.mColor = aNBT.getByte("mColor"); - this.mLightValue = aNBT.getByte("mLightValue"); - this.mWorkData = aNBT.getByte("mWorkData"); - this.mStrongRedstone = aNBT.getByte("mStrongRedstone"); - this.mFacing = this.oFacing = (byte) aNBT.getShort("mFacing"); - this.mOwnerName = aNBT.getString("mOwnerName"); - this.mLockUpgrade = aNBT.getBoolean("mLockUpgrade"); - this.mMuffler = aNBT.getBoolean("mMuffler"); - this.mSteamConverter = aNBT.getBoolean("mSteamConverter"); - this.mActive = aNBT.getBoolean("mActive"); - this.mRedstone = aNBT.getBoolean("mRedstone"); - this.mWorks = !aNBT.getBoolean("mWorks"); - this.mInputDisabled = aNBT.getBoolean("mInputDisabled"); - this.mOutputDisabled = aNBT.getBoolean("mOutputDisabled"); - this.mOtherUpgrades = (byte) (aNBT.getByte("mOtherUpgrades") + aNBT.getByte("mBatteries") + aNBT.getByte("mLiBatteries")); - this.mCoverSides = aNBT.getIntArray("mCoverSides"); - this.mCoverData = aNBT.getIntArray("mCoverData"); - this.mSidedRedstone = aNBT.getByteArray("mRedstoneSided"); - this.mRecipeStuff = aNBT.getCompoundTag("GT.CraftingComponents"); - - if (this.mCoverData.length != 6) { - this.mCoverData = new int[]{0, 0, 0, 0, 0, 0}; - } - if (this.mCoverSides.length != 6) { - this.mCoverSides = new int[]{0, 0, 0, 0, 0, 0}; - } - if (this.mSidedRedstone.length != 6) { - if (this.hasValidMetaTileEntity() && this.mMetaTileEntity.hasSidedRedstoneOutputBehavior()) { - this.mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; - } else { - this.mSidedRedstone = new byte[]{15, 15, 15, 15, 15, 15}; - } - } - - for (byte i = 0; i < 6; i++) { - this.mCoverBehaviors[i] = GregTech_API.getCoverBehavior(this.mCoverSides[i]); - } - - if ((this.mID != 0) && this.createNewMetatileEntity(this.mID)) { - final NBTTagList tItemList = aNBT.getTagList("Inventory", 10); - for (int i = 0; i < tItemList.tagCount(); i++) { - final NBTTagCompound tTag = tItemList.getCompoundTagAt(i); - final int tSlot = tTag.getInteger("IntSlot"); - if ((tSlot >= 0) && (tSlot < this.mMetaTileEntity.getRealInventory().length)) { - this.mMetaTileEntity.getRealInventory()[tSlot] = GT_Utility.loadItem(tTag); - } - } - - try { - this.mMetaTileEntity.loadNBTData(aNBT); - } catch (final Throwable e) { - GT_Log.err.println("Encountered Exception while loading MetaTileEntity, the Server should've crashed now, but I prevented that. Please report immidietly to GregTech Intergalactical!!!"); - e.printStackTrace(GT_Log.err); - } - } - } - - if (this.mCoverData.length != 6) { - this.mCoverData = new int[]{0, 0, 0, 0, 0, 0}; - } - if (this.mCoverSides.length != 6) { - this.mCoverSides = new int[]{0, 0, 0, 0, 0, 0}; - } - if (this.mSidedRedstone.length != 6) { - if (this.hasValidMetaTileEntity() && this.mMetaTileEntity.hasSidedRedstoneOutputBehavior()) { - this.mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; - } else { - this.mSidedRedstone = new byte[]{15, 15, 15, 15, 15, 15}; - } - } - - for (byte i = 0; i < 6; i++) { - this.mCoverBehaviors[i] = GregTech_API.getCoverBehavior(this.mCoverSides[i]); - } - } - - private boolean createNewMetatileEntity(final short aID) { - if ((aID <= 0) || (aID >= GregTech_API.METATILEENTITIES.length) || (GregTech_API.METATILEENTITIES[aID] == null)) { - GT_Log.err.println("MetaID " + aID + " not loadable => locking TileEntity!"); - } else { - if (aID != 0) { - if (this.hasValidMetaTileEntity()) { - this.mMetaTileEntity.setBaseMetaTileEntity(null); - } - GregTech_API.METATILEENTITIES[aID].newMetaEntity(this).setBaseMetaTileEntity(this); - this.mTickTimer = 0; - this.mID = aID; - return true; - } - } - return false; - } - - /** - * Used for ticking special BaseMetaTileEntities, which need that for Energy Conversion - * It's called right before onPostTick() - */ - public void updateStatus() { - // - } - - /** - * Called when trying to charge Items - */ - public void chargeItem(final ItemStack aStack) { - this.decreaseStoredEU(GT_ModHandler.chargeElectricItem(aStack, (int) Math.min(Integer.MAX_VALUE, this.getStoredEU()), (int) Math.min(Integer.MAX_VALUE, this.mMetaTileEntity.getOutputTier()), false, false), true); - } - - /** - * Called when trying to discharge Items - */ - public void dischargeItem(final ItemStack aStack) { - this.increaseStoredEnergyUnits(GT_ModHandler.dischargeElectricItem(aStack, (int) Math.min(Integer.MAX_VALUE, this.getEUCapacity() - this.getStoredEU()), (int) Math.min(Integer.MAX_VALUE, this.mMetaTileEntity.getInputTier()), false, false, false), true); - } - - @Override - public void updateEntity() { - super.updateEntity(); - - if (!this.hasValidMetaTileEntity()) { - if (this.mMetaTileEntity == null) { - return; - } - this.mMetaTileEntity.setBaseMetaTileEntity(this); - } - - this.mRunningThroughTick = true; - long tTime = System.currentTimeMillis(); - - for (int tCode = 0; this.hasValidMetaTileEntity() && (tCode >= 0); ) { - try { - switch (tCode) { - case 0: - tCode++; - if (this.mTickTimer++ == 0) { - this.oX = this.xCoord; - this.oY = this.yCoord; - this.oZ = this.zCoord; - if (this.isServerSide()) { - for (byte i = 0; i < 6; i++) { - if (this.getCoverIDAtSide(i) != 0) { - if (!this.mMetaTileEntity.allowCoverOnSide(i, new GT_ItemStack(this.getCoverIDAtSide(i)))) { - this.dropCover(i, i, true); - } - } - } - } - - this.worldObj.markTileEntityChunkModified(this.xCoord, this.yCoord, this.zCoord, this); - - this.mMetaTileEntity.onFirstTick(this); - if (!this.hasValidMetaTileEntity()) { - this.mRunningThroughTick = false; - return; - } - } - case 1: - tCode++; - if (this.isClientSide()) { - if (this.mColor != this.oColor) { - this.mMetaTileEntity.onColorChangeClient(this.oColor = this.mColor); - this.issueTextureUpdate(); - } - - if (this.mLightValue != this.oLightValueClient) { - this.worldObj.setLightValue(EnumSkyBlock.Block, this.xCoord, this.yCoord, this.zCoord, this.mLightValue); - this.worldObj.updateLightByType(EnumSkyBlock.Block, this.xCoord, this.yCoord, this.zCoord); - this.worldObj.updateLightByType(EnumSkyBlock.Block, this.xCoord + 1, this.yCoord, this.zCoord); - this.worldObj.updateLightByType(EnumSkyBlock.Block, this.xCoord - 1, this.yCoord, this.zCoord); - this.worldObj.updateLightByType(EnumSkyBlock.Block, this.xCoord, this.yCoord + 1, this.zCoord); - this.worldObj.updateLightByType(EnumSkyBlock.Block, this.xCoord, this.yCoord - 1, this.zCoord); - this.worldObj.updateLightByType(EnumSkyBlock.Block, this.xCoord, this.yCoord, this.zCoord + 1); - this.worldObj.updateLightByType(EnumSkyBlock.Block, this.xCoord, this.yCoord, this.zCoord - 1); - this.oLightValueClient = this.mLightValue; - this.issueTextureUpdate(); - } - - if (this.mNeedsUpdate) { - this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); - //worldObj.func_147479_m(xCoord, yCoord, zCoord); - this.mNeedsUpdate = false; - } - } - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - if (this.isServerSide() && (this.mTickTimer > 10)) { - for (byte i = (byte) (tCode - 2); i < 6; i++) { - if (this.getCoverIDAtSide(i) != 0) { - tCode++; - final GT_CoverBehavior tCover = this.getCoverBehaviorAtSide(i); - final int tCoverTickRate = tCover.getTickRate(i, this.getCoverIDAtSide(i), this.mCoverData[i], this); - if ((tCoverTickRate > 0) && ((this.mTickTimer % tCoverTickRate) == 0)) { - this.mCoverData[i] = tCover.doCoverThings(i, this.getInputRedstoneSignal(i), this.getCoverIDAtSide(i), this.mCoverData[i], this, this.mTickTimer); - if (!this.hasValidMetaTileEntity()) { - this.mRunningThroughTick = false; - return; - } - } - } - } - - } - case 8: - tCode = 9; - if (this.isServerSide()) { - if (++this.mAverageEUInputIndex >= this.mAverageEUInput.length) { - this.mAverageEUInputIndex = 0; - } - if (++this.mAverageEUOutputIndex >= this.mAverageEUOutput.length) { - this.mAverageEUOutputIndex = 0; - } - - this.mAverageEUInput[this.mAverageEUInputIndex] = 0; - this.mAverageEUOutput[this.mAverageEUOutputIndex] = 0; - } - case 9: - tCode++; - this.mMetaTileEntity.onPreTick(this, this.mTickTimer); - if (!this.hasValidMetaTileEntity()) { - this.mRunningThroughTick = false; - return; - } - case 10: - tCode++; - if (this.isServerSide()) { - if ((this.mRedstone != this.oRedstone) || (this.mTickTimer == 10)) { - for (byte i = 0; i < 6; i++) { - this.mCoverBehaviors[i] = GregTech_API.getCoverBehavior(this.mCoverSides[i]); - } - this.oRedstone = this.mRedstone; - this.issueBlockUpdate(); - } - - if ((this.xCoord != this.oX) || (this.yCoord != this.oY) || (this.zCoord != this.oZ)) { - this.oX = this.xCoord; - this.oY = this.yCoord; - this.oZ = this.zCoord; - this.issueClientUpdate(); - this.clearTileEntityBuffer(); - } - - if (this.mFacing != this.oFacing) { - this.oFacing = this.mFacing; - for (byte i = 0; i < 6; i++) { - if (this.getCoverIDAtSide(i) != 0) { - if (!this.mMetaTileEntity.allowCoverOnSide(i, new GT_ItemStack(this.getCoverIDAtSide(i)))) { - this.dropCover(i, i, true); - } - } - } - this.issueBlockUpdate(); - } - - if ((this.mTickTimer > 20) && this.mMetaTileEntity.isElectric()) { - this.mAcceptedAmperes = 0; - - if (this.getOutputVoltage() != this.oOutput) { - this.oOutput = this.getOutputVoltage(); - } - - if (this.mMetaTileEntity.isEnetOutput() || this.mMetaTileEntity.isEnetInput()) { - for (byte i = 0; i < 6; i++) { - boolean - temp = this.isEnergyInputSide(i); - if (temp != this.mActiveEUInputs[i]) { - this.mActiveEUInputs[i] = temp; - } - temp = this.isEnergyOutputSide(i); - if (temp != this.mActiveEUOutputs[i]) { - this.mActiveEUOutputs[i] = temp; - } - } - } - - - - if (this.mMetaTileEntity.isEnetOutput() && (this.oOutput > 0)) { - final long tOutputVoltage = this.oOutput, tUsableAmperage = Math.min(this.getOutputAmperage(), (this.getStoredEU() - this.mMetaTileEntity.getMinimumStoredEU()) / tOutputVoltage); - if (tUsableAmperage > 0) { - final long tEU = tOutputVoltage * IEnergyConnected.Util.emitEnergyToNetwork(this.oOutput, tUsableAmperage, this); - this.mAverageEUOutput[this.mAverageEUOutputIndex] += tEU; - this.decreaseStoredEU(tEU, true); - } - } - - - if (this.getEUCapacity() > 0) { - if (GregTech_API.sMachineFireExplosions && (this.getRandomNumber(1000) == 0)) { - final Block tBlock = this.getBlockAtSide((byte) this.getRandomNumber(6)); - if ((tBlock != null) && (tBlock instanceof BlockFire)) { - this.doEnergyExplosion(); - } - } - - if (!this.hasValidMetaTileEntity()) { - this.mRunningThroughTick = false; - return; - } - - if (this.getRandomNumber(1000) == 0) { - if (((this.getCoverIDAtSide((byte) 1) == 0) && ((this.worldObj.getPrecipitationHeight(this.xCoord, this.zCoord) - 2) < this.yCoord)) - || ((this.getCoverIDAtSide((byte) 2) == 0) && ((this.worldObj.getPrecipitationHeight(this.xCoord, this.zCoord - 1) - 1) < this.yCoord)) - || ((this.getCoverIDAtSide((byte) 3) == 0) && ((this.worldObj.getPrecipitationHeight(this.xCoord, this.zCoord + 1) - 1) < this.yCoord)) - || ((this.getCoverIDAtSide((byte) 4) == 0) && ((this.worldObj.getPrecipitationHeight(this.xCoord - 1, this.zCoord) - 1) < this.yCoord)) - || ((this.getCoverIDAtSide((byte) 5) == 0) && ((this.worldObj.getPrecipitationHeight(this.xCoord + 1, this.zCoord) - 1) < this.yCoord))) { - if (GregTech_API.sMachineRainExplosions && this.worldObj.isRaining() && (this.getBiome().rainfall > 0)) { - if (this.getRandomNumber(10) == 0) { - try { - GT_Mod.achievements.issueAchievement(this.getWorldObj().getPlayerEntityByName(this.mOwnerName), "badweather"); - } catch (final Exception e) { - } - this.doEnergyExplosion(); - } else { - this.setOnFire(); - } - } - if (!this.hasValidMetaTileEntity()) { - this.mRunningThroughTick = false; - return; - } - if (GregTech_API.sMachineThunderExplosions && this.worldObj.isThundering() && (this.getBiome().rainfall > 0) && (this.getRandomNumber(3) == 0)) { - try { - GT_Mod.achievements.issueAchievement(this.getWorldObj().getPlayerEntityByName(this.mOwnerName), "badweather"); - } catch (final Exception e) { - } - this.doEnergyExplosion(); - } - } - } - } - } - - if (!this.hasValidMetaTileEntity()) { - this.mRunningThroughTick = false; - return; - } - } - case 11: - tCode++; - if (this.isServerSide()) { - if ((this.mMetaTileEntity.dechargerSlotCount() > 0) && (this.getStoredEU() < this.getEUCapacity())) { - for (int i = this.mMetaTileEntity.dechargerSlotStartIndex(), k = this.mMetaTileEntity.dechargerSlotCount() + i; i < k; i++) { - if ((this.mMetaTileEntity.mInventory[i] != null) && (this.getStoredEU() < this.getEUCapacity())) { - this.dischargeItem(this.mMetaTileEntity.mInventory[i]); - if (this.mMetaTileEntity.mInventory[i].stackSize <= 0) { - this.mMetaTileEntity.mInventory[i] = null; - } - this.mInventoryChanged = true; - } - } - } - } - case 12: - tCode++; - if (this.isServerSide()) { - if ((this.mMetaTileEntity.rechargerSlotCount() > 0) && (this.getStoredEU() > 0)) { - for (int i = this.mMetaTileEntity.rechargerSlotStartIndex(), k = this.mMetaTileEntity.rechargerSlotCount() + i; i < k; i++) { - if ((this.getStoredEU() > 0) && (this.mMetaTileEntity.mInventory[i] != null)) { - this.chargeItem(this.mMetaTileEntity.mInventory[i]); - if (this.mMetaTileEntity.mInventory[i].stackSize <= 0) { - this.mMetaTileEntity.mInventory[i] = null; - } - this.mInventoryChanged = true; - } - } - } - } - case 13: - tCode++; - this.updateStatus(); - if (!this.hasValidMetaTileEntity()) { - this.mRunningThroughTick = false; - return; - } - case 14: - tCode++; - this.mMetaTileEntity.onPostTick(this, this.mTickTimer); - if (!this.hasValidMetaTileEntity()) { - this.mRunningThroughTick = false; - return; - } - case 15: - tCode++; - if (this.isServerSide()) { - if ((this.mTickTimer % 10) == 0) { - if (this.mSendClientData) { - NW.sendPacketToAllPlayersInRange(this.worldObj, new GT_Packet_TileEntity(this.xCoord, (short) this.yCoord, this.zCoord, this.mID, this.mCoverSides[0], this.mCoverSides[1], this.mCoverSides[2], this.mCoverSides[3], this.mCoverSides[4], this.mCoverSides[5], this.oTextureData = (byte) ((this.mFacing & 7) | (this.mActive ? 8 : 0) | (this.mRedstone ? 16 : 0) | (this.mLockUpgrade ? 32 : 0)), this.oUpdateData = this.hasValidMetaTileEntity() ? this.mMetaTileEntity.getUpdateData() : 0, this.oRedstoneData = (byte) (((this.mSidedRedstone[0] > 0) ? 1 : 0) | ((this.mSidedRedstone[1] > 0) ? 2 : 0) | ((this.mSidedRedstone[2] > 0) ? 4 : 0) | ((this.mSidedRedstone[3] > 0) ? 8 : 0) | ((this.mSidedRedstone[4] > 0) ? 16 : 0) | ((this.mSidedRedstone[5] > 0) ? 32 : 0)), this.oColor = this.mColor), this.xCoord, this.zCoord); - this.mSendClientData = false; - } - } - - if (this.mTickTimer > 10) { - byte tData = (byte) ((this.mFacing & 7) | (this.mActive ? 8 : 0) | (this.mRedstone ? 16 : 0) | (this.mLockUpgrade ? 32 : 0)); - if (tData != this.oTextureData) { - this.sendBlockEvent((byte) 0, this.oTextureData = tData); - } - tData = this.mMetaTileEntity.getUpdateData(); - if (tData != this.oUpdateData) { - this.sendBlockEvent((byte) 1, this.oUpdateData = tData); - } - if (this.mColor != this.oColor) { - this.sendBlockEvent((byte) 2, this.oColor = this.mColor); - } - tData = (byte) (((this.mSidedRedstone[0] > 0) ? 1 : 0) | ((this.mSidedRedstone[1] > 0) ? 2 : 0) | ((this.mSidedRedstone[2] > 0) ? 4 : 0) | ((this.mSidedRedstone[3] > 0) ? 8 : 0) | ((this.mSidedRedstone[4] > 0) ? 16 : 0) | ((this.mSidedRedstone[5] > 0) ? 32 : 0)); - if (tData != this.oRedstoneData) { - this.sendBlockEvent((byte) 3, this.oRedstoneData = tData); - } - if (this.mLightValue != this.oLightValue) { - this.worldObj.setLightValue(EnumSkyBlock.Block, this.xCoord, this.yCoord, this.zCoord, this.mLightValue); - this.worldObj.updateLightByType(EnumSkyBlock.Block, this.xCoord, this.yCoord, this.zCoord); - this.worldObj.updateLightByType(EnumSkyBlock.Block, this.xCoord + 1, this.yCoord, this.zCoord); - this.worldObj.updateLightByType(EnumSkyBlock.Block, this.xCoord - 1, this.yCoord, this.zCoord); - this.worldObj.updateLightByType(EnumSkyBlock.Block, this.xCoord, this.yCoord + 1, this.zCoord); - this.worldObj.updateLightByType(EnumSkyBlock.Block, this.xCoord, this.yCoord - 1, this.zCoord); - this.worldObj.updateLightByType(EnumSkyBlock.Block, this.xCoord, this.yCoord, this.zCoord + 1); - this.worldObj.updateLightByType(EnumSkyBlock.Block, this.xCoord, this.yCoord, this.zCoord - 1); - this.issueTextureUpdate(); - this.sendBlockEvent((byte) 7, this.oLightValue = this.mLightValue); - } - } - - if (this.mNeedsBlockUpdate) { - this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, this.getBlockOffset(0, 0, 0)); - this.mNeedsBlockUpdate = false; - } - } - default: - tCode = -1; - break; - } - } catch (final Throwable e) { - GT_Log.err.println("Encountered Exception while ticking MetaTileEntity in Step " + (tCode - 1) + ". The Game should've crashed now, but I prevented that. Please report immidietly to GregTech Intergalactical!!!"); - e.printStackTrace(GT_Log.err); - } - } - - if (this.isServerSide() && this.hasValidMetaTileEntity()) { - tTime = System.currentTimeMillis() - tTime; - if (this.mTimeStatistics.length > 0) { - this.mTimeStatistics[this.mTimeStatisticsIndex = (this.mTimeStatisticsIndex + 1) % this.mTimeStatistics.length] = (int) tTime; - } - if ((tTime > 0) && (tTime > GregTech_API.MILLISECOND_THRESHOLD_UNTIL_LAG_WARNING) && (this.mTickTimer > 1000) && this.getMetaTileEntity().doTickProfilingMessageDuringThisTick() && (this.mLagWarningCount++ < 10)) { - System.out.println("WARNING: Possible Lag Source at [" + this.xCoord + ", " + this.yCoord + ", " + this.zCoord + "] in Dimension " + this.worldObj.provider.dimensionId + " with " + tTime + "ms caused by an instance of " + this.getMetaTileEntity().getClass()); - } - } - - this.mWorkUpdate = this.mInventoryChanged = this.mRunningThroughTick = false; - } - - @Override - public Packet getDescriptionPacket() { - this.issueClientUpdate(); - return null; - } - - public final void receiveMetaTileEntityData(final short aID, final int aCover0, final int aCover1, final int aCover2, final int aCover3, final int aCover4, final int aCover5, final byte aTextureData, final byte aUpdateData, final byte aRedstoneData, final byte aColorData) { - this.issueTextureUpdate(); - if ((this.mID != aID) && (aID > 0)) { - this.mID = aID; - this.createNewMetatileEntity(this.mID); - } - - this.mCoverSides[0] = aCover0; - this.mCoverSides[1] = aCover1; - this.mCoverSides[2] = aCover2; - this.mCoverSides[3] = aCover3; - this.mCoverSides[4] = aCover4; - this.mCoverSides[5] = aCover5; - - for (byte i = 0; i < 6; i++) { - this.mCoverBehaviors[i] = GregTech_API.getCoverBehavior(this.mCoverSides[i]); - } - - this.receiveClientEvent(0, aTextureData); - this.receiveClientEvent(1, aUpdateData); - this.receiveClientEvent(2, aColorData); - this.receiveClientEvent(3, aRedstoneData); - } - - @Override - public boolean receiveClientEvent(final int aEventID, int aValue) { - super.receiveClientEvent(aEventID, aValue); - - if (this.hasValidMetaTileEntity()) { - try { - this.mMetaTileEntity.receiveClientEvent((byte) aEventID, (byte) aValue); - } catch (final Throwable e) { - GT_Log.err.println("Encountered Exception while receiving Data from the Server, the Client should've been crashed by now, but I prevented that. Please report immidietly to GregTech Intergalactical!!!"); - e.printStackTrace(GT_Log.err); - } - } - - if (this.isClientSide()) { - this.issueTextureUpdate(); - switch (aEventID) { - case 0: - this.mFacing = (byte) (aValue & 7); - this.mActive = ((aValue & 8) != 0); - this.mRedstone = ((aValue & 16) != 0); - //mLockUpgrade = ((aValue&32) != 0); - break; - case 1: - if (this.hasValidMetaTileEntity()) { - this.mMetaTileEntity.onValueUpdate((byte) aValue); - } - break; - case 2: - if ((aValue > 16) || (aValue < 0)) { - aValue = 0; - } - this.mColor = (byte) aValue; - break; - case 3: - this.mSidedRedstone[0] = (byte) ((aValue & 1) > 0 ? 15 : 0); - this.mSidedRedstone[1] = (byte) ((aValue & 2) > 0 ? 15 : 0); - this.mSidedRedstone[2] = (byte) ((aValue & 4) > 0 ? 15 : 0); - this.mSidedRedstone[3] = (byte) ((aValue & 8) > 0 ? 15 : 0); - this.mSidedRedstone[4] = (byte) ((aValue & 16) > 0 ? 15 : 0); - this.mSidedRedstone[5] = (byte) ((aValue & 32) > 0 ? 15 : 0); - break; - case 4: - if (this.hasValidMetaTileEntity() && (this.mTickTimer > 20)) { - this.mMetaTileEntity.doSound((byte) aValue, this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5); - } - break; - case 5: - if (this.hasValidMetaTileEntity() && (this.mTickTimer > 20)) { - this.mMetaTileEntity.startSoundLoop((byte) aValue, this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5); - } - break; - case 6: - if (this.hasValidMetaTileEntity() && (this.mTickTimer > 20)) { - this.mMetaTileEntity.stopSoundLoop((byte) aValue, this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5); - } - break; - case 7: - this.mLightValue = (byte) aValue; - break; - } - } - return true; - } - - public ArrayList getDebugInfo(final EntityPlayer aPlayer, final int aLogLevel) { - final ArrayList tList = new ArrayList<>(); - if (aLogLevel > 2) { - tList.add("Meta-ID: " + this.mID + (this.canAccessData() ? " valid" : " invalid") + (this.mMetaTileEntity == null ? " MetaTileEntity == null!" : " ")); - } - if (aLogLevel > 1) { - if (this.mTimeStatistics.length > 0) { - double tAverageTime = 0; - for (final int tTime : this.mTimeStatistics) { - tAverageTime += tTime; - } - tList.add("This particular TileEntity has caused an average CPU-load of ~" + (tAverageTime / this.mTimeStatistics.length) + "ms over the last " + this.mTimeStatistics.length + " ticks."); - } - if (this.mLagWarningCount > 0) { - tList.add("This TileEntity has also caused " + (this.mLagWarningCount >= 10 ? "more than 10" : this.mLagWarningCount) + " Lag Spike Warnings (anything taking longer than " + GregTech_API.MILLISECOND_THRESHOLD_UNTIL_LAG_WARNING + "ms) on the Server."); - } - tList.add("Is" + (this.mMetaTileEntity.isAccessAllowed(aPlayer) ? " " : " not ") + "accessible for you"); - } - if (aLogLevel > 0) { - if ((this.getSteamCapacity() > 0) && this.hasSteamEngineUpgrade()) { - tList.add(this.getStoredSteam() + " of " + this.getSteamCapacity() + " Steam"); - } - tList.add("Machine is " + (this.mActive ? "active" : "inactive")); - if (!this.mHasEnoughEnergy) { - tList.add("ATTENTION: This Device consumes Energy at a higher Rate than you input. You could insert more to speed up the process."); - } - } - return this.mMetaTileEntity.getSpecialDebugInfo(this, aPlayer, aLogLevel, tList); - } - - @Override - public void issueTextureUpdate() { - this.mNeedsUpdate = true; - } - - @Override - public void issueBlockUpdate() { - this.mNeedsBlockUpdate = true; - } - - @Override - public void issueClientUpdate() { - this.mSendClientData = true; - } - - @Override - public void issueCoverUpdate(final byte aSide) { - this.issueClientUpdate(); - } - - @Override - public byte getStrongestRedstone() { - return (byte) Math.max(this.getInternalInputRedstoneSignal((byte) 0), Math.max(this.getInternalInputRedstoneSignal((byte) 1), Math.max(this.getInternalInputRedstoneSignal((byte) 2), Math.max(this.getInternalInputRedstoneSignal((byte) 3), Math.max(this.getInternalInputRedstoneSignal((byte) 4), this.getInternalInputRedstoneSignal((byte) 5)))))); - } - - @Override - public boolean getRedstone() { - return this.getRedstone((byte) 0) || this.getRedstone((byte) 1) || this.getRedstone((byte) 2) || this.getRedstone((byte) 3) || this.getRedstone((byte) 4) || this.getRedstone((byte) 5); - } - - @Override - public boolean getRedstone(final byte aSide) { - return this.getInternalInputRedstoneSignal(aSide) > 0; - } - - public ITexture getCoverTexture(final byte aSide) { - return GregTech_API.sCovers.get(new GT_ItemStack(this.getCoverIDAtSide(aSide))); - } - - @Override - public boolean isGivingInformation() { - if (this.canAccessData()) { - return this.mMetaTileEntity.isGivingInformation(); - } - return false; - } - - @Override - public boolean isValidFacing(final byte aSide) { - if (this.canAccessData()) { - return this.mMetaTileEntity.isFacingValid(aSide); - } - return false; - } - - @Override - public byte getBackFacing() { - return GT_Utility.getOppositeSide(this.mFacing); - } - - @Override - public byte getFrontFacing() { - return this.mFacing; - } - - @Override - public void setFrontFacing(final byte aFacing) { - if (this.isValidFacing(aFacing)) { - this.mFacing = aFacing; - this.mMetaTileEntity.onFacingChange(); - this.onMachineBlockUpdate(); - } - } - - @Override - public int getSizeInventory() { - if (this.canAccessData()) { - return this.mMetaTileEntity.getSizeInventory(); - } - return 0; - } - - @Override - public ItemStack getStackInSlot(final int aIndex) { - if (this.canAccessData()) { - return this.mMetaTileEntity.getStackInSlot(aIndex); - } - return null; - } - - @Override - public void setInventorySlotContents(final int aIndex, final ItemStack aStack) { - this.mInventoryChanged = true; - if (this.canAccessData()) { - this.mMetaTileEntity.setInventorySlotContents(aIndex, this.worldObj.isRemote ? aStack : GT_OreDictUnificator.setStack(true, aStack)); - } - } - - @Override - public String getInventoryName() { - if (this.canAccessData()) { - return this.mMetaTileEntity.getInventoryName(); - } - if (GregTech_API.METATILEENTITIES[this.mID] != null) { - return GregTech_API.METATILEENTITIES[this.mID].getInventoryName(); - } - return ""; - } - - @Override - public int getInventoryStackLimit() { - if (this.canAccessData()) { - return this.mMetaTileEntity.getInventoryStackLimit(); - } - return 64; - } - - @Override - public void openInventory() { - if (this.canAccessData()) { - this.mMetaTileEntity.onOpenGUI(); - } - } - - @Override - public void closeInventory() { - if (this.canAccessData()) { - this.mMetaTileEntity.onCloseGUI(); - } - } - - @Override - public boolean isUseableByPlayer(final EntityPlayer aPlayer) { - return this.canAccessData() && this.playerOwnsThis(aPlayer, false) && (this.mTickTimer > 40) && (this.getTileEntityOffset(0, 0, 0) == this) && (aPlayer.getDistanceSq(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5) < 64) && this.mMetaTileEntity.isAccessAllowed(aPlayer); - } - - @Override - public void validate() { - super.validate(); - this.mTickTimer = 0; - } - - @Override - public void invalidate() { - this.tileEntityInvalid = false; - if (this.canAccessData()) { - this.mMetaTileEntity.onRemoval(); - this.mMetaTileEntity.setBaseMetaTileEntity(null); - } -