aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java')
-rw-r--r--src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java111
1 files changed, 71 insertions, 40 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
index de81b09cec..0823d913d1 100644
--- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
@@ -32,9 +32,11 @@ import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Random;
import static gregtech.api.enums.GT_Values.NW;
import static gregtech.api.enums.GT_Values.V;
@@ -207,13 +209,11 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
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 (hasValidMetaTileEntity()) mMetaTileEntity.setBaseMetaTileEntity(null);
- GregTech_API.METATILEENTITIES[aID].newMetaEntity(this).setBaseMetaTileEntity(this);
- mTickTimer = 0;
- mID = aID;
- return true;
- }
+ if (hasValidMetaTileEntity()) mMetaTileEntity.setBaseMetaTileEntity(null);
+ GregTech_API.METATILEENTITIES[aID].newMetaEntity(this).setBaseMetaTileEntity(this);
+ mTickTimer = 0;
+ mID = aID;
+ return true;
}
return false;
}
@@ -251,8 +251,11 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
mRunningThroughTick = true;
long tTime = System.currentTimeMillis();
+ int tCode = 0;
+ boolean aSideServer = isServerSide();
+ boolean aSideClient = isClientSide();
- try { for (int tCode = 0; hasValidMetaTileEntity() && tCode >= 0; ) {
+ try { for (tCode = 0; hasValidMetaTileEntity() && tCode >= 0; ) {
switch (tCode) {
case 0:
tCode++;
@@ -260,13 +263,11 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
oX = xCoord;
oY = yCoord;
oZ = zCoord;
- if (isServerSide()) for (byte i = 0; i < 6; i++)
+ if (aSideServer) for (byte i = 0; i < 6; i++)
if (getCoverIDAtSide(i) != 0)
if (!mMetaTileEntity.allowCoverOnSide(i, new GT_ItemStack(getCoverIDAtSide(i))))
dropCover(i, i, true);
-
worldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this);
-
mMetaTileEntity.onFirstTick(this);
if (!hasValidMetaTileEntity()) {
mRunningThroughTick = false;
@@ -275,7 +276,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
}
case 1:
tCode++;
- if (isClientSide()) {
+ if (aSideClient) {
if (mColor != oColor) {
mMetaTileEntity.onColorChangeClient(oColor = mColor);
issueTextureUpdate();
@@ -306,7 +307,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
case 5:
case 6:
case 7:
- if (isServerSide() && mTickTimer > 10) {
+ if (aSideServer && mTickTimer > 10) {
for (byte i = (byte) (tCode - 2); i < 6; i++)
if (getCoverIDAtSide(i) != 0) {
tCode++;
@@ -324,7 +325,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
}
case 8:
tCode = 9;
- if (isServerSide()) {
+ if (aSideServer) {
if (++mAverageEUInputIndex >= mAverageEUInput.length) mAverageEUInputIndex = 0;
if (++mAverageEUOutputIndex >= mAverageEUOutput.length) mAverageEUOutputIndex = 0;
@@ -340,7 +341,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
}
case 10:
tCode++;
- if (isServerSide()) {
+ if (aSideServer) {
if (mRedstone != oRedstone || mTickTimer == 10) {
for (byte i = 0; i < 6; i++)
mCoverBehaviors[i] = GregTech_API.getCoverBehavior(mCoverSides[i]);
@@ -413,10 +414,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
|| (getCoverIDAtSide((byte) 5) == 0 && worldObj.getPrecipitationHeight(xCoord + 1, zCoord) - 1 < yCoord)) {
if (GregTech_API.sMachineRainExplosions && worldObj.isRaining() && getBiome().rainfall > 0) {
if (getRandomNumber(10) == 0) {
- try {
- GT_Mod.instance.achievements.issueAchievement(this.getWorldObj().getPlayerEntityByName(mOwnerName), "badweather");
- } catch (Exception e) {
- }
+ try{GT_Mod.instance.achievements.issueAchievement(this.getWorldObj().getPlayerEntityByName(mOwnerName), "badweather");}catch(Exception e){}
doEnergyExplosion();
} else setOnFire();
}
@@ -425,10 +423,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
return;
}
if (GregTech_API.sMachineThunderExplosions && worldObj.isThundering() && getBiome().rainfall > 0 && getRandomNumber(3) == 0) {
- try {
- GT_Mod.instance.achievements.issueAchievement(this.getWorldObj().getPlayerEntityByName(mOwnerName), "badweather");
- } catch (Exception e) {
- }
+ try{GT_Mod.instance.achievements.issueAchievement(this.getWorldObj().getPlayerEntityByName(mOwnerName), "badweather");}catch(Exception e){}
doEnergyExplosion();
}
}
@@ -443,7 +438,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
}
case 11:
tCode++;
- if (isServerSide()) {
+ if (aSideServer) {
if (mMetaTileEntity.dechargerSlotCount() > 0 && getStoredEU() < getEUCapacity()) {
for (int i = mMetaTileEntity.dechargerSlotStartIndex(), k = mMetaTileEntity.dechargerSlotCount() + i; i < k; i++) {
if (mMetaTileEntity.mInventory[i] != null && getStoredEU() < getEUCapacity()) {
@@ -457,7 +452,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
}
case 12:
tCode++;
- if (isServerSide()) {
+ if (aSideServer) {
if (mMetaTileEntity.rechargerSlotCount() > 0 && getStoredEU() > 0) {
for (int i = mMetaTileEntity.rechargerSlotStartIndex(), k = mMetaTileEntity.rechargerSlotCount() + i; i < k; i++) {
if (getStoredEU() > 0 && mMetaTileEntity.mInventory[i] != null) {
@@ -485,7 +480,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
}
case 15:
tCode++;
- if (isServerSide()) {
+ if (aSideServer) {
if (mTickTimer % 10 == 0) {
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)), 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);
@@ -522,14 +517,14 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
}
default:
tCode = -1;
- break;
- }}
+ }
+ }
} catch (Throwable e) {
- //gregtech.api.util.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 immediately to GregTech Intergalactical!!!");
+ //gregtech.api.util.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 (isServerSide() && hasValidMetaTileEntity()) {
+ if (aSideServer && hasValidMetaTileEntity()) {
tTime = System.currentTimeMillis() - tTime;
if (mTimeStatistics.length > 0)
mTimeStatistics[mTimeStatisticsIndex = (mTimeStatisticsIndex + 1) % mTimeStatistics.length] = (int) tTime;
@@ -588,7 +583,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
mFacing = (byte) (aValue & 7);
mActive = ((aValue & 8) != 0);
mRedstone = ((aValue & 16) != 0);
-// mLockUpgrade = ((aValue&32) != 0);
+ //mLockUpgrade = ((aValue&32) != 0);
break;
case 1:
if (hasValidMetaTileEntity()) mMetaTileEntity.onValueUpdate((byte) aValue);
@@ -598,12 +593,12 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
mColor = (byte) aValue;
break;
case 3:
- mSidedRedstone[0] = (byte) ((aValue & 1) > 0 ? 15 : 0);
- mSidedRedstone[1] = (byte) ((aValue & 2) > 0 ? 15 : 0);
- mSidedRedstone[2] = (byte) ((aValue & 4) > 0 ? 15 : 0);
- mSidedRedstone[3] = (byte) ((aValue & 8) > 0 ? 15 : 0);
- mSidedRedstone[4] = (byte) ((aValue & 16) > 0 ? 15 : 0);
- mSidedRedstone[5] = (byte) ((aValue & 32) > 0 ? 15 : 0);
+ mSidedRedstone[0] = (byte) ((aValue & 1) == 1 ? 15 : 0);
+ mSidedRedstone[1] = (byte) ((aValue & 2) == 2 ? 15 : 0);
+ mSidedRedstone[2] = (byte) ((aValue & 4) == 4 ? 15 : 0);
+ mSidedRedstone[3] = (byte) ((aValue & 8) == 8 ? 15 : 0);
+ mSidedRedstone[4] = (byte) ((aValue & 16) == 16 ? 15 : 0);
+ mSidedRedstone[5] = (byte) ((aValue & 32) == 32 ? 15 : 0);
break;
case 4:
if (hasValidMetaTileEntity() && mTickTimer > 20)
@@ -639,7 +634,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
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("Is" + (mMetaTileEntity.isAccessAllowed(aPlayer) ? " " : " not ") + "accessible for you");
+ tList.add("Is" + (mMetaTileEntity.isAccessAllowed(aPlayer) ? " " : EnumChatFormatting.RED+" not "+EnumChatFormatting.RESET) + "accessible for you");
}
if (aLogLevel > 0) {
if (getSteamCapacity() > 0 && hasSteamEngineUpgrade())
@@ -1076,8 +1071,8 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
public boolean playerOwnsThis(EntityPlayer aPlayer, boolean aCheckPrecicely) {
if (!canAccessData()) return false;
- if (aCheckPrecicely || privateAccess() || mOwnerName.equals(""))
- if (mOwnerName.equals("") && isServerSide()) setOwnerName(aPlayer.getDisplayName());
+ if (aCheckPrecicely || privateAccess() || (mOwnerName.length() == 0))
+ if ((mOwnerName.length() == 0) && isServerSide()) setOwnerName(aPlayer.getDisplayName());
else if (privateAccess() && !aPlayer.getDisplayName().equals("Player") && !mOwnerName.equals("Player") && !mOwnerName.equals(aPlayer.getDisplayName()))
return false;
return true;
@@ -1108,9 +1103,45 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
mReleaseEnergy = false;
// Normal Explosion Code
mMetaTileEntity.onExplosion();
+ if(GT_Mod.gregtechproxy.mExplosionItemDrop){
+ for (int i = 0; i < this.getSizeInventory(); i++) {
+ ItemStack tItem = this.getStackInSlot(i);
+ if ((tItem != null) && (tItem.stackSize > 0) && (this.isValidSlot(i))) {
+ dropItems(tItem);
+ this.setInventorySlotContents(i, null); }
+ }
+ }
+ if (mRecipeStuff != null) {
+ for (int i = 0; i < 9; i++) {
+ if (this.getRandomNumber(100) < 50) {
+ dropItems(GT_Utility.loadItem(mRecipeStuff, "Ingredient." + i));
+ }
+ }
+ }
mMetaTileEntity.doExplosion(aAmount);
}
}
+
+ public void dropItems(ItemStack tItem){
+ if(tItem==null)return;
+ Random tRandom = new Random();
+ EntityItem tItemEntity = new EntityItem(this.worldObj, this.xCoord + tRandom.nextFloat() * 0.8F + 0.1F, this.yCoord + tRandom.nextFloat() * 0.8F + 0.1F, this.zCoord + tRandom.nextFloat() * 0.8F + 0.1F, new ItemStack(tItem.getItem(), tItem.stackSize, tItem.getItemDamage()));
+ if (tItem.hasTagCompound()) {
+ tItemEntity.getEntityItem().setTagCompound((NBTTagCompound) tItem.getTagCompound().copy());
+ }
+ tItemEntity.motionX = (tRandom.nextGaussian() * 0.0500000007450581D);
+ tItemEntity.motionY = (tRandom.nextGaussian() * 0.0500000007450581D + 0.2000000029802322D);
+ tItemEntity.motionZ = (tRandom.nextGaussian() * 0.0500000007450581D);
+ tItemEntity.hurtResistantTime = 999999;
+ tItemEntity.lifespan = 60000;
+ try {
+ Field tField = tItemEntity.getClass().getDeclaredField("health");
+ tField.setAccessible(true);
+ tField.setInt(tItemEntity, 99999999);
+ } catch (Exception e) {e.printStackTrace();}
+ this.worldObj.spawnEntityInWorld(tItemEntity);
+ tItem.stackSize = 0;
+ }
@Override
public ArrayList<ItemStack> getDrops() {