diff options
| author | Raven Szewczyk <git@eigenraven.me> | 2022-08-27 10:19:57 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-27 11:19:57 +0200 |
| commit | 6f31720697bcc351421a4d86ba3bf749375dd12c (patch) | |
| tree | 3adf8f318f22c892d74cd7c9d30b6dd3f11f11bd /src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java | |
| parent | c3eac50decd33ee2be8703dfb2ecf9cdc31c2b67 (diff) | |
| download | GT5-Unofficial-6f31720697bcc351421a4d86ba3bf749375dd12c.tar.gz GT5-Unofficial-6f31720697bcc351421a4d86ba3bf749375dd12c.tar.bz2 GT5-Unofficial-6f31720697bcc351421a4d86ba3bf749375dd12c.zip | |
Update buildscript & apply spotless (#1306)
* Update dependencies
* Update buildscript, apply spotless
Diffstat (limited to 'src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java')
| -rw-r--r-- | src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java | 879 |
1 files changed, 608 insertions, 271 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index b68715770c..911c1cabcb 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -1,5 +1,10 @@ package gregtech.api.metatileentity; +import static gregtech.GT_Mod.GT_FML_LOGGER; +import static gregtech.api.enums.GT_Values.NW; +import static gregtech.api.enums.GT_Values.V; +import static gregtech.api.objects.XSTR.XSTR_INSTANCE; + import appeng.api.networking.IGridNode; import appeng.api.networking.security.IActionHost; import appeng.api.util.AECableType; @@ -9,11 +14,9 @@ import appeng.me.helpers.IGridProxyable; import appeng.tile.TileEvent; import appeng.tile.events.TileEventType; import com.gtnewhorizon.structurelib.alignment.IAlignment; -import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider; import com.gtnewhorizon.structurelib.alignment.constructable.IConstructable; import com.gtnewhorizon.structurelib.alignment.constructable.IConstructableProvider; -import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing; import cpw.mods.fml.common.Optional; import cpw.mods.fml.relauncher.ReflectionHelper; import gregtech.GT_Mod; @@ -38,6 +41,9 @@ import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.*; import gregtech.common.GT_Pollution; import ic2.api.Direction; +import java.lang.reflect.Field; +import java.util.*; +import javax.annotation.Nullable; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; import net.minecraft.block.Block; @@ -61,27 +67,34 @@ import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; -import javax.annotation.Nullable; -import java.lang.reflect.Field; -import java.util.*; - -import static gregtech.GT_Mod.GT_FML_LOGGER; -import static gregtech.api.enums.GT_Values.NW; -import static gregtech.api.enums.GT_Values.V; -import static gregtech.api.objects.XSTR.XSTR_INSTANCE; - /** * NEVER INCLUDE THIS FILE IN YOUR MOD!!! * <p/> * This is the main TileEntity for EVERYTHING. */ -@Optional.InterfaceList(value = { - @Optional.Interface(iface = "appeng.api.networking.security.IActionHost", modid = "appliedenergistics2", striprefs = true), - @Optional.Interface(iface = "appeng.me.helpers.IGridProxyable", modid = "appliedenergistics2", striprefs = true)}) -public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTechTileEntity, IActionHost, IGridProxyable, IAlignmentProvider, IConstructableProvider, IDebugableTileEntity, IGregtechWailaProvider { - private static final Field ENTITY_ITEM_HEALTH_FIELD = ReflectionHelper.findField(EntityItem.class, "health", "field_70291_e"); - private final boolean[] mActiveEUInputs = new boolean[]{false, false, false, false, false, false}; - private final boolean[] mActiveEUOutputs = new boolean[]{false, false, false, false, false, false}; +@Optional.InterfaceList( + value = { + @Optional.Interface( + iface = "appeng.api.networking.security.IActionHost", + modid = "appliedenergistics2", + striprefs = true), + @Optional.Interface( + iface = "appeng.me.helpers.IGridProxyable", + modid = "appliedenergistics2", + striprefs = true) + }) +public class BaseMetaTileEntity extends CommonMetaTileEntity + implements IGregTechTileEntity, + IActionHost, + IGridProxyable, + IAlignmentProvider, + IConstructableProvider, + IDebugableTileEntity, + IGregtechWailaProvider { + private static final Field ENTITY_ITEM_HEALTH_FIELD = + ReflectionHelper.findField(EntityItem.class, "health", "field_70291_e"); + private final boolean[] mActiveEUInputs = new boolean[] {false, false, false, false, false, false}; + private final boolean[] mActiveEUOutputs = new boolean[] {false, false, false, false, false, false}; private final int[] mTimeStatistics = new int[GregTech_API.TICKS_FOR_LAG_AVERAGING]; public long mLastSoundTick = 0; public boolean mWasShutdown = false; @@ -89,12 +102,29 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec protected long mStoredEnergy = 0, mStoredSteam = 0; protected int mAverageEUInputIndex = 0, mAverageEUOutputIndex = 0; protected boolean mReleaseEnergy = false; - protected long[] mAverageEUInput = new long[]{0, 0, 0, 0, 0}, mAverageEUOutput = new long[]{0, 0, 0, 0, 0}; - private boolean mHasEnoughEnergy = true, mRunningThroughTick = false, mInputDisabled = false, mOutputDisabled = false, mMuffler = false, mLockUpgrade = false; + protected long[] mAverageEUInput = new long[] {0, 0, 0, 0, 0}, mAverageEUOutput = new long[] {0, 0, 0, 0, 0}; + private boolean mHasEnoughEnergy = true, + mRunningThroughTick = false, + mInputDisabled = false, + mOutputDisabled = false, + mMuffler = false, + mLockUpgrade = false; private boolean mActive = false, mWorkUpdate = false, mSteamConverter = false, mWorks = true; private boolean oRedstone = false; - private byte mColor = 0, oColor = 0, oStrongRedstone = 0, oRedstoneData = 63, oTextureData = 0, oUpdateData = 0, oTexturePage = 0; - private byte oLightValueClient = -1, oLightValue = -1, mLightValue = 0, mOtherUpgrades = 0, mFacing = 0, oFacing = 0, mWorkData = 0; + private byte mColor = 0, + oColor = 0, + oStrongRedstone = 0, + oRedstoneData = 63, + oTextureData = 0, + oUpdateData = 0, + oTexturePage = 0; + private byte 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 long oOutput = 0, mAcceptedAmperes = Long.MAX_VALUE; private long mLastCheckTick = 0; @@ -103,8 +133,7 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec private NBTTagCompound mRecipeStuff = new NBTTagCompound(); private int cableUpdateDelay = 30; - public BaseMetaTileEntity() { - } + public BaseMetaTileEntity() {} @Override public void writeToNBT(NBTTagCompound aNBT) { @@ -152,7 +181,9 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec if (aID > 0) mID = aID; else mID = mID > 0 ? mID : 0; if (mID != 0) createNewMetatileEntity(mID); - mSidedRedstone = (hasValidMetaTileEntity() && mMetaTileEntity.hasSidedRedstoneOutputBehavior() ? new byte[]{0, 0, 0, 0, 0, 0} : new byte[]{15, 15, 15, 15, 15, 15}); + mSidedRedstone = (hasValidMetaTileEntity() && mMetaTileEntity.hasSidedRedstoneOutputBehavior() + ? new byte[] {0, 0, 0, 0, 0, 0} + : new byte[] {15, 15, 15, 15, 15, 15}); } else { if (aID <= 0) mID = (short) aNBT.getInteger("mID"); else mID = aID; @@ -175,7 +206,8 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec mWorks = !aNBT.getBoolean("mWorks"); mInputDisabled = aNBT.getBoolean("mInputDisabled"); mOutputDisabled = aNBT.getBoolean("mOutputDisabled"); - mOtherUpgrades = (byte) (aNBT.getByte("mOtherUpgrades") + aNBT.getByte("mBatteries") + aNBT.getByte("mLiBatteries")); + mOtherUpgrades = + (byte) (aNBT.getByte("mOtherUpgrades") + aNBT.getByte("mBatteries") + aNBT.getByte("mLiBatteries")); mRecipeStuff = aNBT.getCompoundTag("GT.CraftingComponents"); final int nbtVersion = aNBT.getInteger("nbtVersion"); @@ -184,11 +216,11 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec } if (mCoverData == null || mCoverData.length != 6) mCoverData = new ISerializableObject[6]; - if (mCoverSides.length != 6) mCoverSides = new int[]{0, 0, 0, 0, 0, 0}; + if (mCoverSides.length != 6) mCoverSides = new int[] {0, 0, 0, 0, 0, 0}; if (mSidedRedstone.length != 6) if (hasValidMetaTileEntity() && mMetaTileEntity.hasSidedRedstoneOutputBehavior()) - mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; - else mSidedRedstone = new byte[]{15, 15, 15, 15, 15, 15}; + mSidedRedstone = new byte[] {0, 0, 0, 0, 0, 0}; + else mSidedRedstone = new byte[] {15, 15, 15, 15, 15, 15}; updateCoverBehavior(); } @@ -205,14 +237,29 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec * Called when trying to charge Items */ public void chargeItem(ItemStack aStack) { - decreaseStoredEU(GT_ModHandler.chargeElectricItem(aStack, (int) Math.min(Integer.MAX_VALUE, getStoredEU()), (int) Math.min(Integer.MAX_VALUE, mMetaTileEntity.getOutputTier()), false, false), true); + decreaseStoredEU( + GT_ModHandler.chargeElectricItem( + aStack, + (int) Math.min(Integer.MAX_VALUE, getStoredEU()), + (int) Math.min(Integer.MAX_VALUE, mMetaTileEntity.getOutputTier()), + false, + false), + true); } /** * Called when trying to discharge Items */ public void dischargeItem(ItemStack aStack) { - increaseStoredEnergyUnits(GT_ModHandler.dischargeElectricItem(aStack, (int) Math.min(Integer.MAX_VALUE, getEUCapacity() - getStoredEU()), (int) Math.min(Integer.MAX_VALUE, mMetaTileEntity.getInputTier()), false, false, false), true); + increaseStoredEnergyUnits( + GT_ModHandler.dischargeElectricItem( + aStack, + (int) Math.min(Integer.MAX_VALUE, getEUCapacity() - getStoredEU()), + (int) Math.min(Integer.MAX_VALUE, mMetaTileEntity.getInputTier()), + false, + false, + false), + true); } protected boolean isRainPossible() { @@ -274,7 +321,7 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec if (mNeedsUpdate) { worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - //worldObj.func_147479_m(xCoord, yCoord, zCoord); + // worldObj.func_147479_m(xCoord, yCoord, zCoord); mNeedsUpdate = false; } } @@ -340,12 +387,15 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec } } - if (mMetaTileEntity.isEnetOutput() && oOutput > 0) { - final long tOutputVoltage = Math.max(oOutput, oOutput + (1L << Math.max(0, GT_Utility.getTier(oOutput) - 1))); - final long tUsableAmperage = Math.min(getOutputAmperage(), (getStoredEU() - mMetaTileEntity.getMinimumStoredEU()) / tOutputVoltage); + final long tOutputVoltage = + Math.max(oOutput, oOutput + (1L << Math.max(0, GT_Utility.getTier(oOutput) - 1))); + final long tUsableAmperage = Math.min( + getOutputAmperage(), + (getStoredEU() - mMetaTileEntity.getMinimumStoredEU()) / tOutputVoltage); if (tUsableAmperage > 0) { - final long tEU = tOutputVoltage * Util.emitEnergyToNetwork(oOutput, tUsableAmperage, this); + final long tEU = + tOutputVoltage * Util.emitEnergyToNetwork(oOutput, tUsableAmperage, this); mAverageEUOutput[mAverageEUOutputIndex] += tEU; decreaseStoredEU(tEU, true); } @@ -362,26 +412,46 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec } if (getRandomNumber(1000) == 0 && isRainPossible()) { - final int precipitationHeightAtSide2 = worldObj.getPrecipitationHeight(xCoord, zCoord - 1); - final int precipitationHeightAtSide3 = worldObj.getPrecipitationHeight(xCoord, zCoord + 1); - final int precipitationHeightAtSide4 = worldObj.getPrecipitationHeight(xCoord - 1, zCoord); - final int precipitationHeightAtSide5 = worldObj.getPrecipitationHeight(xCoord + 1, zCoord); - - if ((getCoverIDAtSide((byte) 1) == 0 && worldObj.getPrecipitationHeight(xCoord, zCoord) - 2 < yCoord) - || (getCoverIDAtSide((byte) 2) == 0 && precipitationHeightAtSide2 - 1 < yCoord && precipitationHeightAtSide2 > -1) - || (getCoverIDAtSide((byte) 3) == 0 && precipitationHeightAtSide3 - 1 < yCoord && precipitationHeightAtSide3 > -1) - || (getCoverIDAtSide((byte) 4) == 0 && precipitationHeightAtSide4 - 1 < yCoord && precipitationHeightAtSide4 > -1) - || (getCoverIDAtSide((byte) 5) == 0 && precipitationHeightAtSide5 - 1 < yCoord && precipitationHeightAtSide5 > -1)) { + final int precipitationHeightAtSide2 = + worldObj.getPrecipitationHeight(xCoord, zCoord - 1); + final int precipitationHeightAtSide3 = + worldObj.getPrecipitationHeight(xCoord, zCoord + 1); + final int precipitationHeightAtSide4 = + worldObj.getPrecipitationHeight(xCoord - 1, zCoord); + final int precipitationHeightAtSide5 = + worldObj.getPrecipitationHeight(xCoord + 1, zCoord); + + if ((getCoverIDAtSide((byte) 1) == 0 + && worldObj.getPrecipitationHeight(xCoord, zCoord) - 2 < yCoord) + || (getCoverIDAtSide((byte) 2) == 0 + && precipitationHeightAtSide2 - 1 < yCoord + && precipitationHeightAtSide2 > -1) + || (getCoverIDAtSide((byte) 3) == 0 + && precipitationHeightAtSide3 - 1 < yCoord + && precipitationHeightAtSide3 > -1) + || (getCoverIDAtSide((byte) 4) == 0 + && precipitationHeightAtSide4 - 1 < yCoord + && precipitationHeightAtSide4 > -1) + || (getCoverIDAtSide((byte) 5) == 0 + && precipitationHeightAtSide5 - 1 < yCoord + && precipitationHeightAtSide5 > -1)) { if (GregTech_API.sMachineRainExplosions && worldObj.isRaining()) { if (getRandomNumber(10) == 0) { try { - GT_Mod.achievements.issueAchievement(this.getWorldObj().getPlayerEntityByName(mOwnerName), "badweather"); + GT_Mod.achievements.issueAchievement( + this.getWorldObj().getPlayerEntityByName(mOwnerName), + "badweather"); } catch (Exception ignored) { } - GT_Log.exp.println("Machine at: " + this.getXCoord() + " | " + this.getYCoord() + " | " + this.getZCoord() + " DIMID: " + this.worldObj.provider.dimensionId + " explosion due to rain!"); + GT_Log.exp.println("Machine at: " + this.getXCoord() + " | " + + this.getYCoord() + " | " + this.getZCoord() + " DIMID: " + + this.worldObj.provider.dimensionId + " explosion due to rain!"); doEnergyExplosion(); } else { - GT_Log.exp.println("Machine at: " + this.getXCoord() + " | " + this.getYCoord() + " | " + this.getZCoord() + " DIMID: " + this.worldObj.provider.dimensionId + " set to Fire due to rain!"); + GT_Log.exp.println("Machine at: " + this.getXCoord() + " | " + + this.getYCoord() + " | " + this.getZCoord() + " DIMID: " + + this.worldObj.provider.dimensionId + + " set to Fire due to rain!"); setOnFire(); } } @@ -389,12 +459,18 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec mRunningThroughTick = false; return; } - if (GregTech_API.sMachineThunderExplosions && worldObj.isThundering() && getRandomNumber(3) == 0) { + if (GregTech_API.sMachineThunderExplosions + && worldObj.isThundering() + && getRandomNumber(3) == 0) { try { - GT_Mod.achievements.issueAchievement(this.getWorldObj().getPlayerEntityByName(mOwnerName), "badweather"); + GT_Mod.achievements.issueAchievement( + this.getWorldObj().getPlayerEntityByName(mOwnerName), "badweather"); } catch (Exception ignored) { } - GT_Log.exp.println("Machine at: " + this.getXCoord() + " | " + this.getYCoord() + " | " + this.getZCoord() + " DIMID: " + this.worldObj.provider.dimensionId + " explosion due to Thunderstorm!"); + GT_Log.exp.println("Machine at: " + this.getXCoord() + " | " + this.getYCoord() + + " | " + this.getZCoord() + " DIMID: " + + this.worldObj.provider.dimensionId + + " explosion due to Thunderstorm!"); doEnergyExplosion(); } } @@ -409,12 +485,21 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec } if (aSideServer) { if (mMetaTileEntity.dechargerSlotCount() > 0 && getStoredEU() < getEUCapacity()) { - for (int i = mMetaTileEntity.dechargerSlotStartIndex(), k = mMetaTileEntity.dechargerSlotCount() + i; i < k; i++) { + for (int i = mMetaTileEntity.dechargerSlotStartIndex(), + k = mMetaTileEntity.dechargerSlotCount() + i; + i < k; + i++) { if (mMetaTileEntity.mInventory[i] != null && getStoredEU() < getEUCapacity()) { dischargeItem(mMetaTileEntity.mInventory[i]); if (ic2.api.info.Info.itemEnergy.getEnergyValue(mMetaTileEntity.mInventory[i]) > 0) { - if ((getStoredEU() + ic2.api.info.Info.itemEnergy.getEnergyValue(mMetaTileEntity.mInventory[i])) < getEUCapacity()) { - increaseStoredEnergyUnits((long) ic2.api.info.Info.itemEnergy.getEnergyValue(mMetaTileEntity.mInventory[i]), false); + if ((getStoredEU() + + ic2.api.info.Info.itemEnergy.getEnergyValue( + mMetaTileEntity.mInventory[i])) + < getEUCapacity()) { + increaseStoredEnergyUnits( + (long) ic2.api.info.Info.itemEnergy.getEnergyValue( + mMetaTileEntity.mInventory[i]), + false); mMetaTileEntity.mInventory[i].stackSize--; mInventoryChanged = true; } @@ -429,7 +514,10 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec } if (aSideServer) { if (mMetaTileEntity.rechargerSlotCount() > 0 && getStoredEU() > 0) { - for (int i = mMetaTileEntity.rechargerSlotStartIndex(), k = mMetaTileEntity.rechargerSlotCount() + i; i < k; i++) { + for (int i = mMetaTileEntity.rechargerSlotStartIndex(), + k = mMetaTileEntity.rechargerSlotCount() + i; + i < k; + i++) { if (getStoredEU() > 0 && mMetaTileEntity.mInventory[i] != null) { chargeItem(mMetaTileEntity.mInventory[i]); if (mMetaTileEntity.mInventory[i].stackSize <= 0) { @@ -460,7 +548,11 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec } if (mTickTimer > 10) { - byte tData = (byte) ((mFacing & 7) | (mActive ? 8 : 0) | (mRedstone ? 16 : 0) | (mLockUpgrade ? 32 : 0) | (mWorks ? 64 : 0)); + byte tData = (byte) ((mFacing & 7) + | (mActive ? 8 : 0) + | (mRedstone ? 16 : 0) + | (mLockUpgrade ? 32 : 0) + | (mWorks ? 64 : 0)); if (tData != oTextureData) sendBlockEvent(GregTechTileClientEvents.CHANGE_COMMON_DATA, oTextureData = tData); @@ -470,10 +562,16 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec if (mMetaTileEntity instanceof GT_MetaTileEntity_Hatch) { tData = ((GT_MetaTileEntity_Hatch) mMetaTileEntity).getTexturePage(); if (tData != oTexturePage) - sendBlockEvent(GregTechTileClientEvents.CHANGE_CUSTOM_DATA, (byte) ((oTexturePage = tData) | 0x80));//set last bit as a flag for page + sendBlockEvent(GregTechTileClientEvents.CHANGE_CUSTOM_DATA, (byte) + ((oTexturePage = tData) | 0x80)); // set last bit as a flag for page } if (mColor != oColor) sendBlockEvent(GregTechTileClientEvents.CHANGE_COLOR, oColor = mColor); - tData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) | ((mSidedRedstone[2] > 0) ? 4 : 0) | ((mSidedRedstone[3] > 0) ? 8 : 0) | ((mSidedRedstone[4] > 0) ? 16 : 0) | ((mSidedRedstone[5] > 0) ? 32 : 0)); + tData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) + | ((mSidedRedstone[1] > 0) ? 2 : 0) + | ((mSidedRedstone[2] > 0) ? 4 : 0) + | ((mSidedRedstone[3] > 0) ? 8 : 0) + | ((mSidedRedstone[4] > 0) ? 16 : 0) + | ((mSidedRedstone[5] > 0) ? 32 : 0)); if (tData != oRedstoneData) sendBlockEvent(GregTechTileClientEvents.CHANGE_REDSTONE_OUTPUT, oRedstoneData = tData); if (mLightValue != oLightValue) { @@ -505,16 +603,24 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec if (aSideServer && hasValidMetaTileEntity()) { tTime = System.nanoTime() - tTime; if (mTimeStatistics.length > 0) - mTimeStatistics[mTimeStatisticsIndex = (mTimeStatisticsIndex + 1) % mTimeStatistics.length] = (int) tTime; - if (tTime > 0 && tTime > (GregTech_API.MILLISECOND_THRESHOLD_UNTIL_LAG_WARNING * 1000000L) && mTickTimer > 1000 && getMetaTileEntity().doTickProfilingMessageDuringThisTick() && mLagWarningCount++ < 10) - GT_FML_LOGGER.warn("WARNING: Possible Lag Source at [" + xCoord + ", " + yCoord + ", " + zCoord + "] in Dimension " + worldObj.provider.dimensionId + " with " + tTime + "ns caused by an instance of " + getMetaTileEntity().getClass()); + mTimeStatistics[mTimeStatisticsIndex = (mTimeStatisticsIndex + 1) % mTimeStatistics.length] = + (int) tTime; + if (tTime > 0 + && tTime > (GregTech_API.MILLISECOND_THRESHOLD_UNTIL_LAG_WARNING * 1000000L) + && mTickTimer > 1000 + && getMetaTileEntity().doTickProfilingMessageDuringThisTick() + && mLagWarningCount++ < 10) + GT_FML_LOGGER.warn("WARNING: Possible Lag Source at [" + xCoord + ", " + yCoord + ", " + zCoord + + "] in Dimension " + worldObj.provider.dimensionId + " with " + tTime + + "ns caused by an instance of " + getMetaTileEntity().getClass()); } mWorkUpdate = mInventoryChanged = mRunningThroughTick = false; } @Override - public void getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { + public void getWailaBody( + ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { if (hasValidMetaTileEntity() && getMetaTileEntity() != null) { getMetaTileEntity().getWailaBody(itemStack, currenttip, accessor, config); } @@ -522,7 +628,8 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec } @Override - public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y, int z) { + public void getWailaNBTData( + EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y, int z) { super.getWailaNBTData(player, tile, tag, world, x, y, z); if (hasValidMetaTileEntity() && getMetaTileEntity() != null) { getMetaTileEntity().getWailaNBTData(player, tile, tag, world, x, y, z); @@ -532,22 +639,55 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec private void sendClientData() { if (mSendClientData) { NW.sendPacketToAllPlayersInRange( - worldObj, - new GT_Packet_TileEntity( - xCoord, (short) yCoord, zCoord, mID, mCoverSides[0], mCoverSides[1], mCoverSides[2], mCoverSides[3], mCoverSides[4], mCoverSides[5], - oTextureData = (byte) ((mFacing & 7) | (mActive ? 8 : 0) | (mRedstone ? 16 : 0) | (mLockUpgrade ? 32 : 0) | (mWorks ? 64 : 0)), - oTexturePage = (hasValidMetaTileEntity() && mMetaTileEntity instanceof GT_MetaTileEntity_Hatch) ? ((GT_MetaTileEntity_Hatch) mMetaTileEntity).getTexturePage() : 0, - oUpdateData = hasValidMetaTileEntity() ? mMetaTileEntity.getUpdateData() : 0, - oRedstoneData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) | ((mSidedRedstone[2] > 0) ? 4 : 0) | ((mSidedRedstone[3] > 0) ? 8 : 0) | ((mSidedRedstone[4] > 0) ? 16 : 0) | ((mSidedRedstone[5] > 0) ? 32 : 0)), - oColor = mColor), - xCoord, zCoord - ); + worldObj, + new GT_Packet_TileEntity( + xCoord, + (short) yCoord, + zCoord, + mID, + mCoverSides[0], + mCoverSides[1], + mCoverSides[2], + mCoverSides[3], + mCoverSides[4], + mCoverSides[5], + oTextureData = (byte) ((mFacing & 7) + | (mActive ? 8 : 0) + | (mRedstone ? 16 : 0) + | (mLockUpgrade ? 32 : 0) + | (mWorks ? 64 : 0)), + oTexturePage = + (hasValidMetaTileEntity() && mMetaTileEntity instanceof GT_MetaTileEntity_Hatch) + ? ((GT_MetaTileEntity_Hatch) mMetaTileEntity).getTexturePage() + : 0, + oUpdateData = hasValidMetaTileEntity() ? mMetaTileEntity.getUpdateData() : 0, + oRedstoneData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) + | ((mSidedRedstone[1] > 0) ? 2 : 0) + | ((mSidedRedstone[2] > 0) ? 4 : 0) + | ((mSidedRedstone[3] > 0) ? 8 : 0) + | ((mSidedRedstone[4] > 0) ? 16 : 0) + | ((mSidedRedstone[5] > 0) ? 32 : 0)), + oColor = mColor), + xCoord, + zCoord); mSendClientData = false; } sendCoverDataIfNeeded(); } - public final void receiveMetaTileEntityData(short aID, int aCover0, int aCover1, int aCover2, int aCover3, int aCover4, int aCover5, byte aTextureData, byte aTexturePage, byte aUpdateData, byte aRedstoneData, byte aColorData) { + public final void receiveMetaTileEntityData( + short aID, + int aCover0, + int aCover1, + int aCover2, + int aCover3, + int aCover4, + int aCover5, + byte aTextureData, + byte aTexturePage, + byte aUpdateData, + byte aRedstoneData, + byte aColorData) { issueTextureUpdate(); if (mID != aID && aID > 0) { mID = aID; @@ -569,11 +709,33 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec } @Deprecated - public final void receiveMetaTileEntityData(short aID, int aCover0, int aCover1, int aCover2, int aCover3, int aCover4, int aCover5, byte aTextureData, byte aUpdateData, byte aRedstoneData, byte aColorData) { - receiveMetaTileEntityData(aID, aCover0, aCover1, aCover2, aCover3, aCover4, aCover5, aTextureData, (byte) 0, aUpdateData, aRedstoneData, aColorData); + public final void receiveMetaTileEntityData( + short aID, + int aCover0, + int aCover1, + int aCover2, + int aCover3, + int aCover4, + int aCover5, + byte aTextureData, + byte aUpdateData, + byte aRedstoneData, + byte aColorData) { + receiveMetaTileEntityData( + aID, + aCover0, + aCover1, + aCover2, + aCover3, + aCover4, + aCover5, + aTextureData, + (byte) 0, + aUpdateData, + aRedstoneData, + aColorData); } - @Override public boolean receiveClientEvent(int aEventID, int aValue) { super.receiveClientEvent(aEventID, aValue); @@ -582,7 +744,8 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec try { mMetaTileEntity.receiveClientEvent((byte) aEventID, (byte) aValue); } catch (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 immediately to GregTech Intergalactical!!!"); + 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 immediately to GregTech Intergalactical!!!"); e.printStackTrace(GT_Log.err); } } @@ -594,15 +757,15 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec mFacing = (byte) (aValue & 7); mActive = ((aValue & 8) != 0); mRedstone = ((aValue & 16) != 0); - //mLockUpgrade = ((aValue&32) != 0); + // mLockUpgrade = ((aValue&32) != 0); mWorks = ((aValue & 64) != 0); break; case GregTechTileClientEvents.CHANGE_CUSTOM_DATA: if (hasValidMetaTileEntity()) { - if ((aValue & 0x80) == 0) //Is texture index - mMetaTileEntity.onValueUpdate((byte) (aValue & 0x7F)); - else if (mMetaTileEntity instanceof GT_MetaTileEntity_Hatch)//is texture page and hatch - ((GT_MetaTileEntity_Hatch) mMetaTileEntity).onTexturePageUpdate((byte) (aValue & 0x7F)); + if ((aValue & 0x80) == 0) // Is texture index + mMetaTileEntity.onValueUpdate((byte) (aValue & 0x7F)); + else if (mMetaTileEntity instanceof GT_MetaTileEntity_Hatch) // is texture page and hatch + ((GT_MetaTileEntity_Hatch) mMetaTileEntity).onTexturePageUpdate((byte) (aValue & 0x7F)); } break; case GregTechTileClientEvents.CHANGE_COLOR: @@ -641,7 +804,13 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec public ArrayList<String> getDebugInfo(EntityPlayer aPlayer, int aLogLevel) { final ArrayList<String> tList = new ArrayList<>(); if (aLogLevel > 2) { - tList.add("Meta-ID: " + EnumChatFormatting.BLUE + mID + EnumChatFormatting.RESET + (canAccessData() ? EnumChatFormatting.GREEN + " valid" + EnumChatFormatting.RESET : EnumChatFormatting.RED + " invalid" + EnumChatFormatting.RESET) + (mMetaTileEntity == null ? EnumChatFormatting.RED + " MetaTileEntity == null!" + EnumChatFormatting.RESET : " ")); + tList.add("Meta-ID: " + EnumChatFormatting.BLUE + mID + EnumChatFormatting.RESET + + (canAccessData() + ? EnumChatFormatting.GREEN + " valid" + EnumChatFormatting.RESET + : EnumChatFormatting.RED + " invalid" + EnumChatFormatting.RESET) + + (mMetaTileEntity == null + ? EnumChatFormatting.RED + " MetaTileEntity == null!" + EnumChatFormatting.RESET + : " ")); } if (aLogLevel > 1) { if (mTimeStatistics.length > 0) { @@ -653,27 +822,40 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec tWorstTime = tTime; } // Uncomment this line to print out tick-by-tick times. - //tList.add("tTime " + tTime); + // tList.add("tTime " + tTime); } - tList.add("Average CPU load of ~" + GT_Utility.formatNumbers(tAverageTime / mTimeStatistics.length) + "ns over " + GT_Utility.formatNumbers(mTimeStatistics.length) + " ticks with worst time of " + GT_Utility.formatNumbers(tWorstTime) + "ns."); - tList.add("Recorded " + GT_Utility.formatNumbers(mMetaTileEntity.mSoundRequests) + " sound requests in " + GT_Utility.formatNumbers(mTickTimer - mLastCheckTick) + " ticks."); + tList.add("Average CPU load of ~" + GT_Utility.formatNumbers(tAverageTime / mTimeStatistics.length) + + "ns over " + GT_Utility.formatNumbers(mTimeStatistics.length) + " ticks with worst time of " + + GT_Utility.formatNumbers(tWorstTime) + "ns."); + tList.add("Recorded " + GT_Utility.formatNumbers(mMetaTileEntity.mSoundRequests) + " sound requests in " + + GT_Utility.formatNumbers(mTickTimer - mLastCheckTick) + " ticks."); mLastCheckTick = mTickTimer; mMetaTileEntity.mSoundRequests = 0; } if (mLagWarningCount > 0) { - tList.add("Caused " + (mLagWarningCount >= 10 ? "more than 10" : mLagWarningCount) + " Lag Spike Warnings (anything taking longer than " + GregTech_API.MILLISECOND_THRESHOLD_UNTIL_LAG_WARNING + "ms) on the Server."); + tList.add("Caused " + (mLagWarningCount >= 10 ? "more than 10" : mLagWarningCount) + + " Lag Spike Warnings (anything taking longer than " + + GregTech_API.MILLISECOND_THRESHOLD_UNTIL_LAG_WARNING + "ms) on the Server."); } - tList.add("Is" + (mMetaTileEntity.isAccessAllowed(aPlayer) ? " " : EnumChatFormatting.RED + " not " + EnumChatFormatting.RESET) + "accessible for you"); + tList.add("Is" + + (mMetaTileEntity.isAccessAllowed(aPlayer) + ? " " + : EnumChatFormatting.RED + " not " + EnumChatFormatting.RESET) + + "accessible for you"); } if (aLogLevel > 0) { if (getSteamCapacity() > 0 && hasSteamEngineUpgrade()) - tList.add(GT_Utility.formatNumbers(getStoredSteam()) + " of " + GT_Utility.formatNumbers(getSteamCapacity()) + " Steam"); - tList.add("Machine is " + (mActive ? EnumChatFormatting.GREEN + "active" + EnumChatFormatting.RESET : EnumChatFormatting.RED + "inactive" + EnumChatFormatting.RESET)); + tList.add(GT_Utility.formatNumbers(getStoredSteam()) + " of " + + GT_Utility.formatNumbers(getSteamCapacity()) + " Steam"); + tList.add("Machine is " + + (mActive + ? EnumChatFormatting.GREEN + "active" + EnumChatFormatting.RESET + : EnumChatFormatting.RED + "inactive" + EnumChatFormatting.RESET)); if (!mHasEnoughEnergy) - tList.add(EnumChatFormatting.RED + "ATTENTION: This Device needs more power." + EnumChatFormatting.RESET); + tList.add( + EnumChatFormatting.RED + "ATTENTION: This Device needs more power." + EnumChatFormatting.RESET); } - if (joinedIc2Enet) - tList.add("Joined IC2 ENet"); + if (joinedIc2Enet) tList.add("Joined IC2 ENet"); return mMetaTileEntity.getSpecialDebugInfo(this, aPlayer, aLogLevel, tList); } @@ -729,7 +911,8 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec mInventoryChanged = true; if (canAccessData()) { markDirty(); - mMetaTileEntity.setInventorySlotContents(aIndex, worldObj.isRemote ? aStack : GT_OreDictUnificator.setStack(true, aStack)); + mMetaTileEntity.setInventorySlotContents( + aIndex, worldObj.isRemote ? aStack : GT_OreDictUnificator.setStack(true, aStack)); } } @@ -758,9 +941,12 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec @Override public boolean isUseableByPlayer(EntityPlayer aPlayer) { - return canAccessData() && playerOwnsThis(aPlayer, false) && mTickTimer > 40 && - getTileEntityOffset(0, 0, 0) == this && - aPlayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + |
