aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java')
-rw-r--r--src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java198
1 files changed, 29 insertions, 169 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java
index f10066edf8..fc67ec1b55 100644
--- a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java
@@ -11,6 +11,7 @@ import java.util.UUID;
import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
+import gregtech.api.enums.GT_Values;
import gregtech.api.enums.Textures;
import gregtech.api.enums.Textures.BlockIcons;
import gregtech.api.graphs.Lock;
@@ -19,6 +20,7 @@ import gregtech.api.graphs.paths.NodePath;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IConnectable;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
+import gregtech.api.interfaces.tileentity.IDebugableTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.interfaces.tileentity.IPipeRenderedTileEntity;
import gregtech.api.net.GT_Packet_TileEntity;
@@ -54,14 +56,13 @@ import static gregtech.api.metatileentity.BaseMetaTileEntity.COVER_DATA_NBT_KEYS
* <p/>
* This is the main TileEntity for EVERYTHING.
*/
-public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements IGregTechTileEntity, IPipeRenderedTileEntity {
+public class BaseMetaPipeEntity extends CommonMetaTileEntity implements IGregTechTileEntity, IPipeRenderedTileEntity, IDebugableTileEntity {
public byte mConnections = IConnectable.NO_CONNECTION;
protected MetaPipeEntity mMetaTileEntity;
- private byte[] mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0};
private int[] mTimeStatistics = new int[GregTech_API.TICKS_FOR_LAG_AVERAGING];
- private boolean mInventoryChanged = false, mWorkUpdate = false, mWorks = true, mNeedsUpdate = true, mNeedsBlockUpdate = true, mSendClientData = false;
+ private boolean mWorkUpdate = false, mWorks = true;
private final boolean mCheckConnections = false;
- private byte mColor = 0, oColor = 0, mStrongRedstone = 0, oStrongRedstone = 0, oRedstoneData = 63, oTextureData = 0, oUpdateData = 0, mLagWarningCount = 0;
+ private byte mColor = 0, oColor = 0, oStrongRedstone = 0, oRedstoneData = 63, oTextureData = 0, oUpdateData = 0, mLagWarningCount = 0;
private int oX = 0, oY = 0, oZ = 0, mTimeStatisticsIndex = 0;
protected Node node;
protected NodePath nodePath;
@@ -119,20 +120,16 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
try {
super.writeToNBT(aNBT);
} catch (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 immediately to GregTech Intergalactical!!!");
- e.printStackTrace(GT_Log.err);
+ GT_FML_LOGGER.error("Encountered CRITICAL ERROR while saving MetaTileEntity", e);
}
try {
aNBT.setInteger("mID", mID);
- saveCoverNBT(aNBT);
- aNBT.setByteArray("mRedstoneSided", mSidedRedstone);
+ writeCoverNBT(aNBT, false);
aNBT.setByte("mConnections", mConnections);
aNBT.setByte("mColor", mColor);
- aNBT.setByte("mStrongRedstone", mStrongRedstone);
aNBT.setBoolean("mWorks", !mWorks);
} catch (Throwable e) {
- GT_Log.err.println("Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk would've been corrupted by now, but I prevented that. Please report immediately to GregTech Intergalactical!!!");
- e.printStackTrace(GT_Log.err);
+ GT_FML_LOGGER.error("Encountered CRITICAL ERROR while saving MetaTileEntity", e);
}
saveMetaTileNBT(aNBT);
}
@@ -152,15 +149,13 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
} else {
if (aID <= 0) mID = (short) aNBT.getInteger("mID");
else mID = aID;
- mSidedRedstone = aNBT.getByteArray("mRedstoneSided");
mConnections = aNBT.getByte("mConnections");
mColor = aNBT.getByte("mColor");
- mStrongRedstone = aNBT.getByte("mStrongRedstone");
mWorks = !aNBT.getBoolean("mWorks");
if (mSidedRedstone.length != 6) mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0};
- loadCoverNBT(aNBT);
+ readCoverNBT(aNBT);
loadMetaTileNBT(aNBT);
}
}
@@ -206,7 +201,7 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
if (!doCoverThings())
return;
- byte oldConnections = mConnections;
+ final byte oldConnections = mConnections;
// Mask-out connection direction bits to keep only Foam related connections
mConnections = (byte) (mMetaTileEntity.mConnections | (mConnections & ~IConnectable.CONNECTED_ALL));
// If foam not hardened, tries roll chance to harden
@@ -266,7 +261,7 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
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*1000000) && mTickTimer > 1000 && getMetaTileEntity().doTickProfilingMessageDuringThisTick() && mLagWarningCount++ < 10)
+ 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());
}
@@ -289,12 +284,6 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
sendCoverDataIfNeeded();
}
- @Override
- public Packet getDescriptionPacket() {
- issueClientUpdate();
- return null;
- }
-
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) {
issueTextureUpdate();
if (aID > 0 && mID != aID) {
@@ -309,10 +298,10 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
setCoverIDAtSide((byte) 4, aCover4);
setCoverIDAtSide((byte) 5, aCover5);
- receiveClientEvent(MetaTileClientEvents.CHANGE_COMMON_DATA, aTextureData);
- receiveClientEvent(MetaTileClientEvents.CHANGE_CUSTOM_DATA, aUpdateData);
- receiveClientEvent(MetaTileClientEvents.CHANGE_COLOR, aColorData);
- receiveClientEvent(MetaTileClientEvents.CHANGE_REDSTONE_OUTPUT, aRedstoneData);
+ receiveClientEvent(GregTechTileClientEvents.CHANGE_COMMON_DATA, aTextureData);
+ receiveClientEvent(GregTechTileClientEvents.CHANGE_CUSTOM_DATA, aUpdateData);
+ receiveClientEvent(GregTechTileClientEvents.CHANGE_COLOR, aColorData);
+ receiveClientEvent(GregTechTileClientEvents.CHANGE_REDSTONE_OUTPUT, aRedstoneData);
}
@Override
@@ -323,25 +312,24 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
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!!!");
- e.printStackTrace(GT_Log.err);
+ GT_FML_LOGGER.error("Encountered Exception while receiving Data from the Server", e);
}
}
if (isClientSide()) {
issueTextureUpdate();
switch (aEventID) {
- case MetaTileClientEvents.CHANGE_COMMON_DATA:
+ case GregTechTileClientEvents.CHANGE_COMMON_DATA:
mConnections = (byte) aValue;
break;
- case MetaTileClientEvents.CHANGE_CUSTOM_DATA:
+ case GregTechTileClientEvents.CHANGE_CUSTOM_DATA:
if (hasValidMetaTileEntity()) mMetaTileEntity.onValueUpdate((byte) aValue);
break;
- case MetaTileClientEvents.CHANGE_COLOR:
+ case GregTechTileClientEvents.CHANGE_COLOR:
if (aValue > 16 || aValue < 0) aValue = 0;
mColor = (byte) aValue;
break;
- case MetaTileClientEvents.CHANGE_REDSTONE_OUTPUT:
+ case GregTechTileClientEvents.CHANGE_REDSTONE_OUTPUT:
mSidedRedstone[0] = (byte) ((aValue & 1) == 1 ? 15 : 0);
mSidedRedstone[1] = (byte) ((aValue & 2) == 2 ? 15 : 0);
mSidedRedstone[2] = (byte) ((aValue & 4) == 4 ? 15 : 0);
@@ -349,15 +337,15 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
mSidedRedstone[4] = (byte) ((aValue & 16) == 16 ? 15 : 0);
mSidedRedstone[5] = (byte) ((aValue & 32) == 32 ? 15 : 0);
break;
- case MetaTileClientEvents.DO_SOUND:
+ case GregTechTileClientEvents.DO_SOUND:
if (hasValidMetaTileEntity() && mTickTimer > 20)
mMetaTileEntity.doSound((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5);
break;
- case MetaTileClientEvents.START_SOUND_LOOP:
+ case GregTechTileClientEvents.START_SOUND_LOOP:
if (hasValidMetaTileEntity() && mTickTimer > 20)
mMetaTileEntity.startSoundLoop((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5);
break;
- case MetaTileClientEvents.STOP_SOUND_LOOP:
+ case GregTechTileClientEvents.STOP_SOUND_LOOP:
if (hasValidMetaTileEntity() && mTickTimer > 20)
mMetaTileEntity.stopSoundLoop((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5);
break;
@@ -366,8 +354,9 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
return true;
}
+ @Override
public ArrayList<String> getDebugInfo(EntityPlayer aPlayer, int aLogLevel) {
- ArrayList<String> tList = new ArrayList<String>();
+ final ArrayList<String> tList = new ArrayList<>();
if (aLogLevel > 2) {
tList.add("Meta-ID: " + EnumChatFormatting.BLUE+ mID +EnumChatFormatting.RESET + (hasValidMetaTileEntity() ? EnumChatFormatting.GREEN+" valid"+EnumChatFormatting.RESET : EnumChatFormatting.RED+" invalid"+EnumChatFormatting.RESET) + (mMetaTileEntity == null ? EnumChatFormatting.RED+" MetaTileEntity == null!"+EnumChatFormatting.RESET : " "));
}
@@ -395,52 +384,11 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
}
@Override
- public void issueTextureUpdate() {
- mNeedsUpdate = true;
- }
-
- @Override
- public void issueBlockUpdate() {
- mNeedsBlockUpdate = true;
- }
-
- @Override
- public void issueClientUpdate() {
- mSendClientData = true;
- }
-
- @Override
- public void issueCoverUpdate(byte aSide) {
- super.issueCoverUpdate(aSide);
- issueClientUpdate();
- }
-
- @Override
- public byte getStrongestRedstone() {
- return (byte) Math.max(getInternalInputRedstoneSignal((byte) 0), Math.max(getInternalInputRedstoneSignal((byte) 1), Math.max(getInternalInputRedstoneSignal((byte) 2), Math.max(getInternalInputRedstoneSignal((byte) 3), Math.max(getInternalInputRedstoneSignal((byte) 4), getInternalInputRedstoneSignal((byte) 5))))));
- }
-
- @Override
- public boolean getRedstone() {
- return getRedstone((byte) 0) || getRedstone((byte) 1) || getRedstone((byte) 2) || getRedstone((byte) 3) || getRedstone((byte) 4) || getRedstone((byte) 5);
- }
-
- @Override
- public boolean getRedstone(byte aSide) {
- return getInternalInputRedstoneSignal(aSide) > 0;
- }
-
- @Override
public boolean isGivingInformation() {
if (canAccessData()) return mMetaTileEntity.isGivingInformation();
return false;
}
- @Override
- public boolean isValidFacing(byte aSide) {
- if (canAccessData()) return mMetaTileEntity.isFacingValid(aSide);
- return false;
- }
@Override
public byte getBackFacing() {
@@ -676,23 +624,6 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
}
@Override
- public boolean increaseStoredSteam(long aEnergy, boolean aIgnoreTooMuchEnergy) {
- return false;
- }
-
- @Override
- public String[] getDescription() {
- if (canAccessData()) return mMetaTileEntity.getDescription();
- return new String[0];
- }
-
- @Override
- public boolean isValidSlot(int aIndex) {
- if (canAccessData()) return mMetaTileEntity.isValidSlot(aIndex);
- return false;
- }
-
- @Override
public long getUniversalEnergyStored() {
return Math.max(getStoredEU(), getStoredSteam());
}
@@ -712,15 +643,6 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
return 0;
}
- @Override
- public long getStoredSteam() {
- return 0;
- }
-
- @Override
- public long getSteamCapacity() {
- return 0;
- }
@Override
public ITexture[] getTexture(Block aBlock, byte aSide) {
@@ -764,9 +686,6 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
return mMetaTileEntity != null && mMetaTileEntity.getBaseMetaTileEntity() == this;
}
- protected boolean canAccessData() {
- return hasValidMetaTileEntity() && !isDead;
- }
@Override
public void doExplosion(long aAmount) {
@@ -935,8 +854,7 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
return handled;
}
} catch (Throwable e) {
- GT_Log.err.println("Encountered Exception while rightclicking TileEntity, the Game should've crashed now, but I prevented that. Please report immediately to GregTech Intergalactical!!!");
- e.printStackTrace(GT_Log.err);
+ GT_FML_LOGGER.error("Encountered Exception while right clicking TileEntity", e);
}
return false;
@@ -947,8 +865,7 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
try {
if (aPlayer != null && hasValidMetaTileEntity()) mMetaTileEntity.onLeftclick(this, aPlayer);
} catch (Throwable e) {
- GT_Log.err.println("Encountered Exception while leftclicking TileEntity, the Game should've crashed now, but I prevented that. Please report immediately to GregTech Intergalactical!!!");
- e.printStackTrace(GT_Log.err);
+ GT_FML_LOGGER.error("Encountered Exception while left clicking TileEntity", e);
}
}
@@ -988,7 +905,7 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
public int[] getAccessibleSlotsFromSide(int aSide) {
if (canAccessData() && (getCoverBehaviorAtSideNew((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getComplexCoverDataAtSide((byte) aSide), -1, this) || getCoverBehaviorAtSideNew((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getComplexCoverDataAtSide((byte) aSide), -1, this)))
return mMetaTileEntity.getAccessibleSlotsFromSide(aSide);
- return new int[0];
+ return GT_Values.emptyIntArray;
}
/**
@@ -1013,36 +930,6 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
}
@Override
- public byte getInternalInputRedstoneSignal(byte aSide) {
- return (byte) (getCoverBehaviorAtSideNew(aSide).getRedstoneInput(aSide, getInputRedstoneSignal(aSide), getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this) & 15);
- }
-
- @Override
- public byte getInputRedstoneSignal(byte aSide) {
- return (byte) (worldObj.getIndirectPowerLevelTo(getOffsetX(aSide, 1), getOffsetY(aSide, 1), getOffsetZ(aSide, 1), aSide) & 15);
- }
-
- @Override
- public byte getOutputRedstoneSignal(byte aSide) {
- return (byte) (getCoverBehaviorAtSideNew(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this) || (getCoverBehaviorAtSideNew(aSide).letsRedstoneGoOut(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this)) ? mSidedRedstone[aSide] & 15 : 0);
- }
-
- @Override
- public void setInternalOutputRedstoneSignal(byte aSide, byte aStrength) {
- if (!getCoverBehaviorAtSideNew(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this))
- setOutputRedstoneSignal(aSide, aStrength);
- }
-
- @Override
- public void setOutputRedstoneSignal(byte aSide, byte aStrength) {
- aStrength = (byte) Math.min(Math.max(0, aStrength), 15);
- if (aSide >= 0 && aSide < 6 && mSidedRedstone[aSide] != aStrength) {
- mSidedRedstone[aSide] = aStrength;
- issueBlockUpdate();
- }
- }
-
- @Override
public boolean isSteamEngineUpgradable() {
return isUpgradable() && !hasSteamEngineUpgrade() && getSteamCapacity() > 0;
}
@@ -1062,13 +949,8 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
}
@Override
- public boolean hasInventoryBeenModified() {
- return mInventoryChanged;
- }
-
- @Override
public void setGenericRedstoneOutput(boolean aOnOff) {
- //
+ // Do nothing
}
@Override
@@ -1132,17 +1014,6 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
}
@Override
- public byte getStrongOutputRedstoneSignal(byte aSide) {
- return aSide >= 0 && aSide < 6 && (mStrongRedstone & (1 << aSide)) != 0 ? (byte) (mSidedRedstone[aSide] & 15) : 0;
- }
-
- @Override
- public void setStrongOutputRedstoneSignal(byte aSide, byte aStrength) {
- mStrongRedstone |= (1 << aSide);
- setOutputRedstoneSignal(aSide, aStrength);
- }
-
- @Override
public ItemStack decrStackSize(int aIndex, int aAmount) {
if (canAccessData()) {
mInventoryChanged = true;
@@ -1244,11 +1115,6 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
}
@Override
- public boolean isInvalidTileEntity() {
- return isInvalid();
- }
-
- @Override
public boolean addStackToSlot(int aIndex, ItemStack aStack) {
if (GT_Utility.isStackInvalid(aStack)) return true;
if (aIndex < 0 || aIndex >= getSizeInventory()) return false;
@@ -1333,12 +1199,6 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I
return mConnections;
}
- @Override
- public void markDirty() {
- super.markDirty();
- mInventoryChanged = true;
- }
-
public void onNeighborBlockChange(int aX, int aY, int aZ) {
if (canAccessData()) {
final IMetaTileEntity meta = getMetaTileEntity();