From d4934c1611e209e75e2cb5d3409adffd69c1dc20 Mon Sep 17 00:00:00 2001 From: Johnson Date: Mon, 24 Feb 2020 11:20:56 +0500 Subject: Provide owner's UUID to forge event bus for fake players. --- .../interfaces/tileentity/IGregTechTileEntity.java | 11 + .../api/metatileentity/BaseMetaPipeEntity.java | 2853 ++++++------ .../api/metatileentity/BaseMetaTileEntity.java | 35 +- src/main/java/gregtech/api/util/GT_Utility.java | 4729 ++++++++++---------- .../gregtech/common/blocks/GT_Item_Machines.java | 365 +- 5 files changed, 4020 insertions(+), 3973 deletions(-) (limited to 'src') diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IGregTechTileEntity.java b/src/main/java/gregtech/api/interfaces/tileentity/IGregTechTileEntity.java index 953e3e5dc4..8bd8c5b678 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IGregTechTileEntity.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IGregTechTileEntity.java @@ -12,6 +12,7 @@ import net.minecraftforge.fluids.IFluidHandler; import java.util.ArrayList; import java.util.List; +import java.util.UUID; /** * A simple compound Interface for all my TileEntities. @@ -92,6 +93,16 @@ public interface IGregTechTileEntity extends ITexturedTileEntity, IGearEnergyTil */ public String getOwnerName(); + /** + * Gets the UniqueID of the Machines Owner. + */ + public UUID getOwnerUuid(); + + /** + * Sets the UniqueID of the Machines Owner. + */ + public void setOwnerUuid(UUID uuid); + /** * Sets initial Values from NBT * diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java index 6d9ce47ef2..881d4a814e 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java @@ -1,1421 +1,1432 @@ -package gregtech.api.metatileentity; - -import static gregtech.GT_Mod.GT_FML_LOGGER; -import static gregtech.api.enums.GT_Values.NW; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import gregtech.api.GregTech_API; -import gregtech.api.enums.Textures; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.interfaces.tileentity.IPipeRenderedTileEntity; -import gregtech.api.net.GT_Packet_TileEntity; -import gregtech.api.objects.GT_ItemStack; -import gregtech.api.util.GT_CoverBehavior; -import gregtech.api.util.GT_Log; -import gregtech.api.util.GT_ModHandler; -import gregtech.api.util.GT_OreDictUnificator; -import gregtech.api.util.GT_Utility; -import gregtech.common.covers.GT_Cover_Fluidfilter; -import net.minecraft.block.Block; -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.util.AxisAlignedBB; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidTankInfo; -import net.minecraftforge.fluids.IFluidHandler; - -/** - * NEVER INCLUDE THIS FILE IN YOUR MOD!!! - *

- * This is the main TileEntity for EVERYTHING. - */ -public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileEntity, IPipeRenderedTileEntity { - 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}; - public byte mConnections = 0; - protected MetaPipeEntity mMetaTileEntity; - private byte[] mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; - private int[] mCoverSides = new int[]{0, 0, 0, 0, 0, 0}, mCoverData = new int[]{0, 0, 0, 0, 0, 0}, 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 mCheckConnections = false; - private byte mColor = 0, oColor = 0, mStrongRedstone = 0, oRedstoneData = 63, oTextureData = 0, oUpdateData = 0, mLagWarningCount = 0; - private int oX = 0, oY = 0, oZ = 0, mTimeStatisticsIndex = 0; - private short mID = 0; - private long mTickTimer = 0; - - public BaseMetaPipeEntity() { - } - - @Override - public void writeToNBT(NBTTagCompound aNBT) { - 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); - } - try { - aNBT.setInteger("mID", mID); - aNBT.setIntArray("mCoverData", mCoverData); - aNBT.setIntArray("mCoverSides", mCoverSides); - aNBT.setByteArray("mRedstoneSided", mSidedRedstone); - aNBT.setByte("mConnections", mConnections); - aNBT.setByte("mColor", mColor); - aNBT.setByte("mStrongRedstone", mStrongRedstone); - aNBT.setBoolean("mWorks", !mWorks); - - for(int i=0;i < mCoverData.length; i++) { - if (GregTech_API.getCoverBehavior(mCoverSides[i]) instanceof GT_Cover_Fluidfilter) { - final int fluidId = mCoverData[i] >>> 3; - final Fluid fluid = FluidRegistry.getFluid(fluidId); - if(fluid != null) { - final String fluidName = FluidRegistry.getFluidName(fluid); - aNBT.setString(String.format("fluidFilter%d", i), fluidName); - } - } - } - - } 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); - } - try { - if (hasValidMetaTileEntity()) { - NBTTagList tItemList = new NBTTagList(); - for (int i = 0; i < mMetaTileEntity.getRealInventory().length; i++) { - ItemStack tStack = mMetaTileEntity.getRealInventory()[i]; - if (tStack != null) { - NBTTagCompound tTag = new NBTTagCompound(); - tTag.setInteger("IntSlot", i); - tStack.writeToNBT(tTag); - tItemList.appendTag(tTag); - } - } - aNBT.setTag("Inventory", tItemList); - - try { - mMetaTileEntity.saveNBTData(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); - } - } - } 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); - } - } - - @Override - public void readFromNBT(NBTTagCompound aNBT) { - super.readFromNBT(aNBT); - setInitialValuesAsNBT(aNBT, (short) 0); - } - - @Override - public void setInitialValuesAsNBT(NBTTagCompound aNBT, short aID) { - if (aNBT == null) { - if (aID > 0) mID = aID; - else mID = mID > 0 ? mID : 0; - if (mID != 0) createNewMetatileEntity(mID); - } else { - if (aID <= 0) mID = (short) aNBT.getInteger("mID"); - else mID = aID; - mCoverSides = aNBT.getIntArray("mCoverSides"); - mCoverData = aNBT.getIntArray("mCoverData"); - mSidedRedstone = aNBT.getByteArray("mRedstoneSided"); - mConnections = aNBT.getByte("mConnections"); - mColor = aNBT.getByte("mColor"); - mStrongRedstone = aNBT.getByte("mStrongRedstone"); - mWorks = !aNBT.getBoolean("mWorks"); - - if (mCoverData.length != 6) mCoverData = 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) mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; - - for (byte i = 0; i < 6; i++) { - mCoverBehaviors[i] = GregTech_API.getCoverBehavior(mCoverSides[i]); - if(mCoverBehaviors[i] instanceof GT_Cover_Fluidfilter) { - final String filterKey = String.format("fluidFilter%d", i); - if (aNBT.hasKey(filterKey)) { - mCoverData[i] = (mCoverData[i] & 7) | (FluidRegistry.getFluidID(aNBT.getString(filterKey)) << 3); - } - } - } - - - if (mID != 0 && createNewMetatileEntity(mID)) { - NBTTagList tItemList = aNBT.getTagList("Inventory", 10); - for (int i = 0; i < tItemList.tagCount(); i++) { - NBTTagCompound tTag = tItemList.getCompoundTagAt(i); - int tSlot = tTag.getInteger("IntSlot"); - if (tSlot >= 0 && tSlot < mMetaTileEntity.getRealInventory().length) { - mMetaTileEntity.getRealInventory()[tSlot] = GT_Utility.loadItem(tTag); - } - } - - try { - mMetaTileEntity.loadNBTData(aNBT); - } catch (Throwable e) { - GT_Log.err.println("Encountered Exception while loading MetaTileEntity, the Server should've crashed now, but I prevented that. Please report immediately to GregTech Intergalactical!!!"); - e.printStackTrace(GT_Log.err); - } - } - } - - if (mCoverData.length != 6) mCoverData = 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) mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; - - for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehavior(mCoverSides[i]); - } - - private boolean createNewMetatileEntity(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 (hasValidMetaTileEntity()) mMetaTileEntity.setBaseMetaTileEntity(null); - GregTech_API.METATILEENTITIES[aID].newMetaEntity(this).setBaseMetaTileEntity(this); - mTickTimer = 0; - mID = aID; - return true; - } - return false; - } - - @Override - public void updateEntity() { - super.updateEntity(); - - if (!hasValidMetaTileEntity()) { - if (mMetaTileEntity == null) return; - mMetaTileEntity.setBaseMetaTileEntity(this); - } - - long tTime = System.nanoTime(); - int tCode = 0; - - try { for (tCode = 0; hasValidMetaTileEntity() && tCode >= 0; ) { - switch (tCode) { - case 0: - tCode++; - if (mTickTimer++ == 0) { - oX = xCoord; - oY = yCoord; - oZ = zCoord; - if (isServerSide()) 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()) return; - } - case 1: - tCode++; - if (isClientSide()) { - if (mColor != oColor) { - mMetaTileEntity.onColorChangeClient(oColor = mColor); - issueTextureUpdate(); - } - - if (mNeedsUpdate) { - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - //worldObj.func_147479_m(xCoord, yCoord, zCoord); - mNeedsUpdate = false; - } - } - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - if (isServerSide() && mTickTimer > 10) { - for (byte i = (byte) (tCode - 2); i < 6; i++) - if (getCoverIDAtSide(i) != 0) { - tCode++; - GT_CoverBehavior tCover = getCoverBehaviorAtSide(i); - int tCoverTickRate = tCover.getTickRate(i, getCoverIDAtSide(i), mCoverData[i], this); - if (tCoverTickRate > 0 && mTickTimer % tCoverTickRate == 0) { - mCoverData[i] = tCover.doCoverThings(i, getInputRedstoneSignal(i), getCoverIDAtSide(i), mCoverData[i], this, mTickTimer); - if (!hasValidMetaTileEntity()) return; - } - } - mConnections = (byte) (mMetaTileEntity.mConnections | (mConnections & ~63)); - if ((mConnections & -64) == 64 && getRandomNumber(1000) == 0) { - mConnections = (byte) ((mConnections & ~64) | -128); - } - } - case 8: - tCode = 9; - mMetaTileEntity.onPreTick(this, mTickTimer); - if (!hasValidMetaTileEntity()) return; - case 9: - tCode++; - if (isServerSide()) { - if (mTickTimer == 10) { - for (byte i = 0; i < 6; i++) - mCoverBehaviors[i] = GregTech_API.getCoverBehavior(mCoverSides[i]); - issueBlockUpdate(); - joinEnet(); - } - - if (xCoord != oX || yCoord != oY || zCoord != oZ) { - oX = xCoord; - oY = yCoord; - oZ = zCoord; - issueClientUpdate(); - clearTileEntityBuffer(); - } - } - case 10: - tCode++; - mMetaTileEntity.onPostTick(this, mTickTimer); - if (!hasValidMetaTileEntity()) return; - case 11: - tCode++; - if (isServerSide()) { - 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 = mConnections, 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; - } - } - - if (mTickTimer > 10) { - if (mConnections != oTextureData) sendBlockEvent((byte) 0, oTextureData = mConnections); - byte tData = mMetaTileEntity.getUpdateData(); - if (tData != oUpdateData) sendBlockEvent((byte) 1, oUpdateData = tData); - if (mColor != oColor) sendBlockEvent((byte) 2, 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)); - if (tData != oRedstoneData) sendBlockEvent((byte) 3, oRedstoneData = tData); - } - - if (mNeedsBlockUpdate) { - worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockOffset(0, 0, 0)); - mNeedsBlockUpdate = false; - } - } - default: - tCode = -1; - break; - } - } - } catch (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 (isServerSide() && 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*1000000) && 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 = false; - } - - @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) { - mID = aID; - createNewMetatileEntity(mID); - } - - mCoverSides[0] = aCover0; - mCoverSides[1] = aCover1; - mCoverSides[2] = aCover2; - mCoverSides[3] = aCover3; - mCoverSides[4] = aCover4; - mCoverSides[5] = aCover5; - - for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehavior(mCoverSides[i]); - - receiveClientEvent(0, aTextureData); - receiveClientEvent(1, aUpdateData); - receiveClientEvent(2, aColorData); - receiveClientEvent(3, aRedstoneData); - } - - @Override - public boolean receiveClientEvent(int aEventID, int aValue) { - super.receiveClientEvent(aEventID, aValue); - - if (hasValidMetaTileEntity()) { - 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); - } - } - - if (isClientSide()) { - issueTextureUpdate(); - switch (aEventID) { - case 0: - mConnections = (byte) aValue; - break; - case 1: - if (hasValidMetaTileEntity()) mMetaTileEntity.onValueUpdate((byte) aValue); - break; - case 2: - if (aValue > 16 || aValue < 0) aValue = 0; - mColor = (byte) aValue; - break; - case 3: - 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) - mMetaTileEntity.doSound((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); - break; - case 5: - if (hasValidMetaTileEntity() && mTickTimer > 20) - mMetaTileEntity.startSoundLoop((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); - break; - case 6: - if (hasValidMetaTileEntity() && mTickTimer > 20) - mMetaTileEntity.stopSoundLoop((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); - break; - } - } - return true; - } - - public ArrayList getDebugInfo(EntityPlayer aPlayer, int aLogLevel) { - ArrayList 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 : " ")); - } - if (aLogLevel > 1) { - if (mTimeStatistics.length > 0) { - double tAverageTime = 0; - double tWorstTime = 0; - for (int tTime : mTimeStatistics) { - tAverageTime += tTime; - if (tTime > tWorstTime) { - tWorstTime = tTime; - } - } - tList.add("Average CPU-load of ~" + (tAverageTime / mTimeStatistics.length) + "ns since " + mTimeStatistics.length + " ticks with worst time of " + tWorstTime + "ns."); - } - 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) ? " " : EnumChatFormatting.RED+" not "+EnumChatFormatting.RESET) + "accessible for you"); - } - if(joinedIc2Enet) - tList.add("Joined IC2 ENet"); - - return mMetaTileEntity.getSpecialDebugInfo(this, aPlayer, aLogLevel, tList); - } - - @Override - public void issueTextureUpdate() { - mNeedsUpdate = true; - } - - @Override - public void issueBlockUpdate() { - mNeedsBlockUpdate = true; - } - - @Override - public void issueClientUpdate() { - mSendClientData = true; - } - - @Override - public void issueCoverUpdate(byte 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; - } - - public ITexture getCoverTexture(byte aSide) { - return GregTech_API.sCovers.get(new GT_ItemStack(getCoverIDAtSide(aSide))); - } - - @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() { - return GT_Utility.getOppositeSide(getFrontFacing()); - } - - @Override - public byte getFrontFacing() { - return 6; - } - - @Override - public void setFrontFacing(byte aFacing) { - doEnetUpdate(); - } - - @Override - public int getSizeInventory() { - if (canAccessData()) return mMetaTileEntity.getSizeInventory(); - return 0; - } - - @Override - public ItemStack getStackInSlot(int aIndex) { - if (canAccessData()) return mMetaTileEntity.getStackInSlot(aIndex); - return null; - } - - @Override - public void setInventorySlotContents(int aIndex, ItemStack aStack) { - mInventoryChanged = true; - if (canAccessData()) - mMetaTileEntity.setInventorySlotContents(aIndex, worldObj.isRemote ? aStack : GT_OreDictUnificator.setStack(true, aStack)); - } - - @Override - public String getInventoryName() { - if (canAccessData()) return mMetaTileEntity.getInventoryName(); - if (GregTech_API.METATILEENTITIES[mID] != null) return GregTech_API.METATILEENTITIES[mID].getInventoryName(); - return ""; - } - - @Override - public int getInventoryStackLimit() { - if (canAccessData()) return mMetaTileEntity.getInventoryStackLimit(); - return 64; - } - - @Override - public void openInventory() {/*Do nothing*/} - - @Override - public void closeInventory() {/*Do nothing*/} - - @Override - public boolean isUseableByPlayer(EntityPlayer aPlayer) { - return hasValidMetaTileEntity() && mTickTimer > 40 && getTileEntityOffset(0, 0, 0) == this && aPlayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64 && mMetaTileEntity.isAccessAllowed(aPlayer); - } - - @Override - public void validate() { - super.validate(); - mTickTimer = 0; - } - - @Override - public void invalidate() { - tileEntityInvalid = false; - if (hasValidMetaTileEntity()) { - mMetaTileEntity.onRemoval(); - mMetaTileEntity.setBaseMetaTileEntity(null); - } - leaveEnet(); - super.invalidate(); - } - - @Override - public void onChunkUnload() { - super.onChunkUnload(); - } - - @Override - public boolean hasCustomInventoryName() { - return false; - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - ItemStack stack = getStackInSlot(slot); - if (stack != null) setInventorySlotContents(slot, null); - return stack; - } - - @Override - public void onMachineBlockUpdate() { - if (canAccessData()) mMetaTileEntity.onMachineBlockUpdate(); - } - - @Override - public int getProgress() { - return canAccessData() ? mMetaTileEntity.getProgresstime() : 0; - } - - @Override - public int getMaxProgress() { - return canAccessData() ? mMetaTileEntity.maxProgresstime() : 0; - } - - @Override - public boolean increaseProgress(int aProgressAmountInTicks) { - return canAccessData() ? mMetaTileEntity.increaseProgress(aProgressAmountInTicks) != aProgressAmountInTicks : false; - } - - @Override - public boolean hasThingsToDo() { - return getMaxProgress() > 0; - } - - @Override - public void enableWorking() { - if (!mWorks) mWorkUpdate = true; - mWorks = true; - } - - @Override - public void disableWorking() { - mWorks = false; - } - - @Override - public boolean isAllowedToWork() { - return mWorks; - } - - @Override - public boolean hasWorkJustBeenEnabled() { - return mWorkUpdate; - } - - @Override - public byte getWorkDataValue() { - return 0; - } - - @Override - public void setWorkDataValue(byte aValue) {/*Do nothing*/} - - @Override - public int getMetaTileID() { - return mID; - } - - @Override - public int setMetaTileID(short aID) { - return mID = aID; - } - - @Override - public boolean isActive() { - return false; - } - - @Override - public void setActive(boolean aActive) {/*Do nothing*/} - - @Override - public long getTimer() { - return mTickTimer; - } - - @Override - public boolean decreaseStoredEnergyUnits(long aEnergy, boolean aIgnoreTooLessEnergy) { - return false; - } - - @Override - public boolean increaseStoredEnergyUnits(long aEnergy, boolean aIgnoreTooMuchEnergy) { - return false; - } - - @Override - public boolean inputEnergyFrom(byte aSide) { - return false; - } - - @Override - public boolean inputEnergyFrom(byte aSide, boolean waitForActive) { - return false; - } - - @Override - public boolean outputsEnergyTo(byte aSide) { - return false; - } - - @Override - public boolean outputsEnergyTo(byte aSide, boolean waitForActive) { - return false; - } - - @Override - public long getOutputAmperage() { - return 0; - } - - @Override - public long getOutputVoltage() { - return 0; - } - - @Override - public long getInputAmperage() { - return 0; - } - - @Override - public long getInputVoltage() { - return 0; - } - - @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()); - } - - @Override - public long getUniversalEnergyCapacity() { - return Math.max(getEUCapacity(), getSteamCapacity()); - } - - @Override - public long getStoredEU() { - return 0; - } - - @Override - public long getEUCapacity() { - return 0; - } - - @Override - public long getStoredSteam() { - return 0; - } - - @Override - public long getSteamCapacity() { - return 0; - } - - @Override - public ITexture[] getTexture(Block aBlock, byte aSide) { - ITexture rIcon = getCoverTexture(aSide); - if (rIcon != null) return new ITexture[]{rIcon}; - return getTextureUncovered(aSide); - } - - @Override - public ITexture[] getTextureUncovered(byte aSide) { - if ((mConnections & 64) != 0) return Textures.BlockIcons.FRESHFOAM; - if ((mConnections & -128) != 0) return Textures.BlockIcons.HARDENEDFOAMS[mColor]; - if ((mConnections & -64) != 0) return Textures.BlockIcons.ERROR_RENDERING; - byte tConnections = mConnections; - if (tConnections == 1 || tConnections == 2) tConnections = 3; - else if (tConnections == 4 || tConnections == 8) tConnections = 12; - else if (tConnections == 16 || tConnections == 32) tConnections = 48; - if (hasValidMetaTileEntity()) - return mMetaTileEntity.getTexture(this, aSide, tConnections, (byte) (mColor - 1), tConnections == 0 || (tConnections & (1 << aSide)) != 0, getOutputRedstoneSignal(aSide) > 0); - return Textures.BlockIcons.ERROR_RENDERING; - } - - protected boolean hasValidMetaTileEntity() { - return mMetaTileEntity != null && mMetaTileEntity.getBaseMetaTileEntity() == this; - } - - protected boolean canAccessData() { - return hasValidMetaTileEntity() && !isDead; - } - - @Override - public void doExplosion(long aAmount) { - if (canAccessData()) { - mMetaTileEntity.onExplosion(); - mMetaTileEntity.doExplosion(aAmount); - } - } - - @Override - public ArrayList getDrops() { - ItemStack rStack = new ItemStack(GregTech_API.sBlockMachines, 1, mID); - NBTTagCompound tNBT = new NBTTagCompound(); - if (mStrongRedstone > 0) tNBT.setByte("mStrongRedstone", mStrongRedstone); - for (byte i = 0; i < mCoverSides.length; i++) { - if (mCoverSides[i] != 0) { - tNBT.setIntArray("mCoverData", mCoverData); - tNBT.setIntArray("mCoverSides", mCoverSides); - break; - } - } - if (hasValidMetaTileEntity()) mMetaTileEntity.setItemNBT(tNBT); - if (!tNBT.hasNoTags()) rStack.setTagCompound(tNBT); - return new ArrayList(Arrays.asList(rStack)); - } - - @Override - public boolean onRightclick(EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { - if (isClientSide()) { - if (getCoverBehaviorAtSide(aSide).onCoverRightclickClient(aSide, this, aPlayer, aX, aY, aZ)) return true; - } - if (isServerSide()) { - ItemStack tCurrentItem = aPlayer.inventory.getCurrentItem(); - if (tCurrentItem != null) { - if (getColorization() >= 0 && GT_Utility.areStacksEqual(new ItemStack(Items.water_bucket, 1), tCurrentItem)) { - tCurrentItem.func_150996_a(Items.bucket); - setColorization((byte) -1); - return true; - } - byte tSide = GT_Utility.determineWrenchingSide(aSide, aX, aY, aZ); - if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sWrenchList)) { - if (mMetaTileEntity.onWrenchRightClick(aSide, tSide, aPlayer, aX, aY, aZ)) { - GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer); - GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(100), 1.0F, -1, xCoord, yCoord, zCoord); - } - return true; - } - if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sScrewdriverList)) { - if (getCoverIDAtSide(aSide) == 0 && getCoverIDAtSide(tSide) != 0) { - if (GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 200, aPlayer)) { - setCoverDataAtSide(tSide, getCoverBehaviorAtSide(tSide).onCoverScrewdriverclick(tSide, getCoverIDAtSide(tSide), getCoverDataAtSide(tSide), this, aPlayer, 0.5F, 0.5F, 0.5F)); - mMetaTileEntity.onScrewdriverRightClick(tSide, aPlayer, aX, aY, aZ); - GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(100), 1.0F, -1, xCoord, yCoord, zCoord); - } - } else { - if (GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer)) { - setCoverDataAtSide(aSide, getCoverBehaviorAtSide(aSide).onCoverScrewdriverclick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this, aPlayer, aX, aY, aZ)); - mMetaTileEntity.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); - GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(100), 1.0F, -1, xCoord, yCoord, zCoord); - } - } - return true; - } - - if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sHardHammerList)) { - //if (GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer)) { - // GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(1), 1.0F, -1, xCoord, yCoord, zCoord); - //} - return true; - } - - if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sSoftHammerList)) { - if (GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer)) { - if (mWorks) disableWorking(); - else enableWorking(); - GT_Utility.sendChatToPlayer(aPlayer, trans("090","Machine Processing: ") + (isAllowedToWork() ? trans("088","Enabled") : trans("087","Disabled"))); - GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(101), 1.0F, -1, xCoord, yCoord, zCoord); - } - return true; - } - - if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sWireCutterList)) { - if (mMetaTileEntity.onWireCutterRightClick(aSide, tSide, aPlayer, aX, aY, aZ)) { - //logic handled internally - GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(100), 1.0F, -1, xCoord, yCoord, zCoord); - } - doEnetUpdate(); - return true; - } - - if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sSolderingToolList)) { - if (mMetaTileEntity.onSolderingToolRightClick(aSide, tSide, aPlayer, aX, aY, aZ)) { - //logic handled internally - GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(103), 1.0F, -1, xCoord, yCoord, zCoord); - } else if (GT_ModHandler.useSolderingIron(tCurrentItem, aPlayer)) { - mStrongRedstone ^= (1 << tSide); - GT_Utility.sendChatToPlayer(aPlayer, trans("091","Redstone Output at Side ") + tSide + trans("092"," set to: ") + ((mStrongRedstone & (1 << tSide)) != 0 ? trans("093","Strong") : trans("094","Weak"))); - GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(103), 3.0F, -1, xCoord, yCoord, zCoord); - } - doEnetUpdate(); - return true; - } - - byte cSide = tSide; - if (getCoverIDAtSide(aSide) != 0) cSide = aSide; - - if (getCoverIDAtSide(cSide) == 0) { - if (GregTech_API.sCovers.containsKey(new GT_ItemStack(tCurrentItem))) { - if (GregTech_API.getCoverBehavior(tCurrentItem).isCoverPlaceable(cSide, new GT_ItemStack(tCurrentItem), this) && mMetaTileEntity.allowCoverOnSide(cSide, new GT_ItemStack(tCurrentItem))) { - setCoverItemAtSide(cSide, tCurrentItem); - if (!aPlayer.capabilities.isCreativeMode) tCurrentItem.stackSize--; - GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(100), 1.0F, -1, xCoord, yCoord, zCoord); - } - return true; - } - } else { - if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sCrowbarList)) { - if (GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer)) { - GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(0), 1.0F, -1, xCoord, yCoord, zCoord); - dropCover(cSide, aSide, false); - } - return true; - } - } - } - - if (getCoverBehaviorAtSide(aSide).onCoverRightclick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this, aPlayer, aX, aY, aZ)) - return true; - } - - if (!getCoverBehaviorAtSide(aSide).isGUIClickable(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this)) - return false; - - try { - if (hasValidMetaTileEntity()) return mMetaTileEntity.onRightclick(this, aPlayer, aSide, aX, aY, aZ); - } 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); - } - - return false; - } - - @Override - public void onLeftclick(EntityPlayer aPlayer) { - 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); - } - } - - @Override - public boolean isDigitalChest() { - return false; - } - - @Override - public ItemStack[] getStoredItemData() { - return null; - } - - @Override - public void setItemCount(int aCount) { - // - } - - @Override - public int getMaxItemCount() { - return 0; - } - - /** - * Can put aStack into Slot - */ - @Override - public boolean isItemValidForSlot(int aIndex, ItemStack aStack) { - return canAccessData() && mMetaTileEntity.isItemValidForSlot(aIndex, aStack); - } - - /** - * returns all valid Inventory Slots, no matter which Side (Unless it's covered). - * The Side Stuff is done in the following two Functions. - */ - @Override - public int[] getAccessibleSlotsFromSide(int aSide) { - if (canAccessData() && (getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSide((byte) aSide), -1, this) || getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSide((byte) aSide), -1, this))) - return mMetaTileEntity.getAccessibleSlotsFromSide(aSide); - return new int[0]; - } - - /** - * Can put aStack into Slot at Side - */ - @Override - public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { - return canAccessData() && getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSide((byte) aSide), aIndex, this) && mMetaTileEntity.canInsertItem(aIndex, aStack, aSide); - } - - /** - * Can pull aStack out of Slot from Side - */ - @Override - public boolean canExtractItem(int aIndex, ItemStack aStack, int aSide) { - return canAccessData() && getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSide((byte) aSide), aIndex, this) && mMetaTileEntity.canExtractItem(aIndex, aStack, aSide); - } - - @Override - public boolean isUpgradable() { - return false; - } - - @Override - public byte getInternalInputRedstoneSignal(byte aSide) { - return (byte) (getCoverBehaviorAtSide(aSide).getRedstoneInput(aSide, getInputRedstoneSignal(aSide), getCoverIDAtSide(aSide), getCoverDataAtSide(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) (getCoverBehaviorAtSide(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this) || (getCoverBehaviorAtSide(aSide).letsRedstoneGoOut(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this)) ? mSidedRedstone[aSide] & 15 : 0); - } - - @Override - public void setInternalOutputRedstoneSignal(byte aSide, byte aStrength) { - if (!getCoverBehaviorAtSide(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(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; - } - - @Override - public boolean addSteamEngineUpgrade() { - if (isSteamEngineUpgradable()) { - issueBlockUpdate(); - return true; - } - return false; - } - - @Override - public boolean hasSteamEngineUpgrade() { - return false; - } - - @Override - public boolean hasInventoryBeenModified() { - return mInventoryChanged; - } - - @Override - public void setGenericRedstoneOutput(boolean aOnOff) { - // - } - - @Override - public int getErrorDisplayID() { - return 0; - } - - @Override - public void setErrorDisplayID(int aErrorID) { - // - } - - @Override - public IMetaTileEntity getMetaTileEntity() { - return hasValidMetaTileEntity() ? mMetaTileEntity : null; - } - - @Override - public void setMetaTileEntity(IMetaTileEntity aMetaTileEntity) { - mMetaTileEntity = (MetaPipeEntity) aMetaTileEntity; - } - - @Override - public GT_CoverBehavior getCoverBehaviorAtSide(byte aSide) { - return aSide >= 0 && aSide < mCoverBehaviors.length ? mCoverBehaviors[aSide] : GregTech_API.sNoBehavior; - } - - @Override - public void setCoverIDAtSide(byte aSide, int aID) { - if (aSide >= 0 && aSide < 6) { - mCoverSides[aSide] = aID; - mCoverData[aSide] = 0; - mCoverBehaviors[aSide] = GregTech_API.getCoverBehavior(aID); - issueCoverUpdate(aSide); - issueBlockUpdate(); - } - } - - @Override - public void setCoverItemAtSide(byte aSide, ItemStack aCover) { - GregTech_API.getCoverBehavior(aCover).placeCover(aSide, aCover, this); - } - - @Override - public int getCoverIDAtSide(byte aSide) { - if (aSide >= 0 && aSide < 6) return mCoverSides[aSide]; - return 0; - } - - @Override - public ItemStack getCoverItemAtSide(byte aSide) { - return GT_Utility.intToStack(getCoverIDAtSide(aSide)); - } - - @Override - public boolean canPlaceCoverIDAtSide(byte aSide, int aID) { - return getCoverIDAtSide(aSide) == 0; - } - - @Override - public boolean canPlaceCoverItemAtSide(byte aSide, ItemStack aCover) { - return getCoverIDAtSide(aSide) == 0; - } - - @Override - public void setCoverDataAtSide(byte aSide, int aData) { - if (aSide >= 0 && aSide < 6) mCoverData[aSide] = aData; - } - - @Override - public int getCoverDataAtSide(byte aSide) { - if (aSide >= 0 && aSide < 6) return mCoverData[aSide]; - return 0; - } - - @Override - public void setLightValue(byte aLightValue) { - // - } - - @Override - public long getAverageElectricInput() { - return 0; - } - - @Override - public long getAverageElectricOutput() { - return 0; - } - - @Override - public boolean dropCover(byte aSide, byte aDroppedSide, boolean aForced) { - if (getCoverBehaviorAtSide(aSide).onCoverRemoval(aSide, getCoverIDAtSide(aSide), mCoverData[aSide], this, aForced) || aForced) { - ItemStack tStack = getCoverBehaviorAtSide(aSide).getDrop(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this); - if (tStack != null) { - tStack.setTagCompound(null); - EntityItem tEntity = new EntityItem(worldObj, getOffsetX(aDroppedSide, 1) + 0.5, getOffsetY(aDroppedSide, 1) + 0.5, getOffsetZ(aDroppedSide, 1) + 0.5, tStack); - tEntity.motionX = 0; - tEntity.motionY = 0; - tEntity.motionZ = 0; - worldObj.spawnEntityInWorld(tEntity); - } - - setCoverIDAtSide(aSide, 0); - setOutputRedstoneSignal(aSide, (byte) 0); - return true; - } - return false; - } - - @Override - public String getOwnerName() { - return "Player"; - } - - @Override - public String setOwnerName(String aName) { - return "Player"; - } - - @Override - public byte getComparatorValue(byte aSide) { - return canAccessData() ? mMetaTileEntity.getComparatorValue(aSide) : 0; - } - - @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; - return mMetaTileEntity.decrStackSize(aIndex, aAmount); - } - return null; - } - - @Override - public long injectEnergyUnits(byte aSide, long aVoltage, long aAmperage) { - if (canAccessData()) return mMetaTileEntity.injectEnergyUnits(aSide, aVoltage, aAmperage); - return 0; - } - - @Override - public boolean drainEnergyUnits(byte aSide, long aVoltage, long aAmperage) { - return false; - } - - @Override - public boolean acceptsRotationalEnergy(byte aSide) { - if (!canAccessData() || getCoverIDAtSide(aSide) != 0) return false; - return mMetaTileEntity.acceptsRotationalEnergy(aSide); - } - - @Override - public boolean injectRotationalEnergy(byte aSide, long aSpeed, long aEnergy) { - if (!canAccessData() || getCoverIDAtSide(aSide) != 0) return false; - return mMetaTileEntity.injectRotationalEnergy(aSide, aSpeed, aEnergy); - } - - private boolean canMoveFluidOnSide(ForgeDirection aSide, Fluid aFluid, boolean isFill) { - if (aSide == ForgeDirection.UNKNOWN) - return true; - - IFluidHandler tTileEntity = getITankContainerAtSide((byte) aSide.ordinal()); - // Only require a connection if there's something to connect to - Allows fluid cells & buckets to interact with the pipe - if (tTileEntity != null && !mMetaTileEntity.isConnectedAtSide((byte) aSide.ordinal())) - return false; - - if(isFill && mMetaTileEntity.isLiquidInput((byte) aSide.ordinal()) - && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), aFluid, this)) - return true; - - if (!isFill && mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) - && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()),aFluid, this)) - return true; - - return false; - } - - @Override - public int fill(ForgeDirection aSide, FluidStack aFluidStack, boolean doFill) { - if (mTickTimer > 5 && canAccessData() && canMoveFluidOnSide(aSide, aFluidStack == null ? null : aFluidStack.getFluid(), true)) - return mMetaTileEntity.fill(aSide, aFluidStack, doFill); - return 0; - } - - @Override - public FluidStack drain(ForgeDirection aSide, int maxDrain, boolean doDrain) { - if (mTickTimer > 5 && canAccessData() && canMoveFluidOnSide(aSide, mMetaTileEntity.getFluid() == null ? null : mMetaTileEntity.getFluid().getFluid(), false)) - return mMetaTileEntity.drain(aSide, maxDrain, doDrain); - return null; - } - - @Override - public FluidStack drain(ForgeDirection aSide, FluidStack aFluidStack, boolean doDrain) { - if (mTickTimer > 5 && canAccessData() && canMoveFluidOnSide(aSide, aFluidStack == null ? null : aFluidStack.getFluid(), false)) - return mMetaTileEntity.drain(aSide, aFluidStack, doDrain); - return null; - } - - @Override - public boolean canFill(ForgeDirection aSide, Fluid aFluid) { - if (mTickTimer > 5 && canAccessData() && canMoveFluidOnSide(aSide, aFluid, true)) - return mMetaTileEntity.canFill(aSide, aFluid); - return false; - } - - @Override - public boolean canDrain(ForgeDirection aSide, Fluid aFluid) { - if (mTickTimer > 5 && canAccessData() && canMoveFluidOnSide(aSide, aFluid, false)) - return mMetaTileEntity.canDrain(aSide, aFluid); - return false; - } - - @Override - public FluidTankInfo[] getTankInfo(ForgeDirection aSide) { - if (canAccessData() - && (aSide == ForgeDirection.UNKNOWN - || (mMetaTileEntity.isLiquidInput((byte) aSide.ordinal()) - && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), null, this)) - || (mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), null, this)) - // Doesn't need to be connected to get Tank Info -- otherwise things can't connect - ) - ) - return mMetaTileEntity.getTankInfo(aSide); - return new FluidTankInfo[]{}; - } - - @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; - ItemStack tStack = getStackInSlot(aIndex); - if (GT_Utility.isStackInvalid(tStack)) { - setInventorySlotContents(aIndex, aStack); - return true; - } - aStack = GT_OreDictUnificator.get(aStack); - if (GT_Utility.areStacksEqual(tStack, aStack) && tStack.stackSize + aStack.stackSize <= Math.min(aStack.getMaxStackSize(), getInventoryStackLimit())) { - tStack.stackSize += aStack.stackSize; - return true; - } - return false; - } - - @Override - public boolean addStackToSlot(int aIndex, ItemStack aStack, int aAmount) { - return addStackToSlot(aIndex, GT_Utility.copyAmount(aAmount, aStack)); - } - - @Override - public byte getColorization() { - return (byte) (mColor - 1); - } - - @Override - public byte setColorization(byte aColor) { - if (aColor > 15 || aColor < -1) aColor = -1; - mColor = (byte) (aColor + 1); - if (canAccessData()) mMetaTileEntity.onColorChangeServer(aColor); - return mColor; - } - - @Override - public float getThickNess() { - if (canAccessData()) return mMetaTileEntity.getThickNess(); - return 1.0F; - } - - public boolean renderInside(byte aSide) { - if (canAccessData()) return mMetaTileEntity.renderInside(aSide); - return false; - } - - @Override - public float getBlastResistance(byte aSide) { - return (mConnections & 192) != 0 ? 50.0F : 5.0F; - } - - @Override - public boolean isMufflerUpgradable() { - return false; - } - - @Override - public boolean addMufflerUpgrade() { - return false; - } - - @Override - public boolean hasMufflerUpgrade() { - return false; - } - - @Override - public boolean isUniversalEnergyStored(long aEnergyAmount) { - return getUniversalEnergyStored() >= aEnergyAmount; - } - - @Override - public String[] getInfoData() { - { - if (canAccessData()) return getMetaTileEntity().getInfoData(); - return new String[]{}; - } - } - - @Override - public byte getConnections() { - 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(); - if (meta instanceof MetaPipeEntity) { - // Trigger a checking of connections in case someone placed down a block that the pipe/wire shouldn't be connected to. - // However; don't do it immediately in case the world isn't finished loading - // (This caused issues with AE2 GTEU p2p connections. - ((MetaPipeEntity) meta).setCheckConnections(); - } - } - } - - @Override - public int getLightOpacity() { - return mMetaTileEntity == null ? 0 : mMetaTileEntity.getLightOpacity(); - } - - @Override - public void addCollisionBoxesToList(World aWorld, int aX, int aY, int aZ, AxisAlignedBB inputAABB, List outputAABB, Entity collider) { - mMetaTileEntity.addCollisionBoxesToList(aWorld, aX, aY, aZ, inputAABB, outputAABB, collider); - } - - @Override - public AxisAlignedBB getCollisionBoundingBoxFromPool(World aWorld, int aX, int aY, int aZ) { - return mMetaTileEntity.getCollisionBoundingBoxFromPool(aWorld, aX, aY, aZ); - } - - @Override - public void onEntityCollidedWithBlock(World aWorld, int aX, int aY, int aZ, Entity collider) { - mMetaTileEntity.onEntityCollidedWithBlock(aWorld, aX, aY, aZ, collider); - } -} +package gregtech.api.metatileentity; + +import static gregtech.GT_Mod.GT_FML_LOGGER; +import static gregtech.api.enums.GT_Values.NW; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.interfaces.tileentity.IPipeRenderedTileEntity; +import gregtech.api.net.GT_Packet_TileEntity; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.util.GT_CoverBehavior; +import gregtech.api.util.GT_Log; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; +import gregtech.common.covers.GT_Cover_Fluidfilter; +import net.minecraft.block.Block; +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.util.AxisAlignedBB; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; + +/** + * NEVER INCLUDE THIS FILE IN YOUR MOD!!! + *

+ * This is the main TileEntity for EVERYTHING. + */ +public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileEntity, IPipeRenderedTileEntity { + 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}; + public byte mConnections = 0; + protected MetaPipeEntity mMetaTileEntity; + private byte[] mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; + private int[] mCoverSides = new int[]{0, 0, 0, 0, 0, 0}, mCoverData = new int[]{0, 0, 0, 0, 0, 0}, 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 mCheckConnections = false; + private byte mColor = 0, oColor = 0, mStrongRedstone = 0, oRedstoneData = 63, oTextureData = 0, oUpdateData = 0, mLagWarningCount = 0; + private int oX = 0, oY = 0, oZ = 0, mTimeStatisticsIndex = 0; + private short mID = 0; + private long mTickTimer = 0; + + public BaseMetaPipeEntity() { + } + + @Override + public void writeToNBT(NBTTagCompound aNBT) { + 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); + } + try { + aNBT.setInteger("mID", mID); + aNBT.setIntArray("mCoverData", mCoverData); + aNBT.setIntArray("mCoverSides", mCoverSides); + aNBT.setByteArray("mRedstoneSided", mSidedRedstone); + aNBT.setByte("mConnections", mConnections); + aNBT.setByte("mColor", mColor); + aNBT.setByte("mStrongRedstone", mStrongRedstone); + aNBT.setBoolean("mWorks", !mWorks); + + for(int i=0;i < mCoverData.length; i++) { + if (GregTech_API.getCoverBehavior(mCoverSides[i]) instanceof GT_Cover_Fluidfilter) { + final int fluidId = mCoverData[i] >>> 3; + final Fluid fluid = FluidRegistry.getFluid(fluidId); + if(fluid != null) { + final String fluidName = FluidRegistry.getFluidName(fluid); + aNBT.setString(String.format("fluidFilter%d", i), fluidName); + } + } + } + + } 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); + } + try { + if (hasValidMetaTileEntity()) { + NBTTagList tItemList = new NBTTagList(); + for (int i = 0; i < mMetaTileEntity.getRealInventory().length; i++) { + ItemStack tStack = mMetaTileEntity.getRealInventory()[i]; + if (tStack != null) { + NBTTagCompound tTag = new NBTTagCompound(); + tTag.setInteger("IntSlot", i); + tStack.writeToNBT(tTag); + tItemList.appendTag(tTag); + } + } + aNBT.setTag("Inventory", tItemList); + + try { + mMetaTileEntity.saveNBTData(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); + } + } + } 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); + } + } + + @Override + public void readFromNBT(NBTTagCompound aNBT) { + super.readFromNBT(aNBT); + setInitialValuesAsNBT(aNBT, (short) 0); + } + + @Override + public void setInitialValuesAsNBT(NBTTagCompound aNBT, short aID) { + if (aNBT == null) { + if (aID > 0) mID = aID; + else mID = mID > 0 ? mID : 0; + if (mID != 0) createNewMetatileEntity(mID); + } else { + if (aID <= 0) mID = (short) aNBT.getInteger("mID"); + else mID = aID; + mCoverSides = aNBT.getIntArray("mCoverSides"); + mCoverData = aNBT.getIntArray("mCoverData"); + mSidedRedstone = aNBT.getByteArray("mRedstoneSided"); + mConnections = aNBT.getByte("mConnections"); + mColor = aNBT.getByte("mColor"); + mStrongRedstone = aNBT.getByte("mStrongRedstone"); + mWorks = !aNBT.getBoolean("mWorks"); + + if (mCoverData.length != 6) mCoverData = 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) mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; + + for (byte i = 0; i < 6; i++) { + mCoverBehaviors[i] = GregTech_API.getCoverBehavior(mCoverSides[i]); + if(mCoverBehaviors[i] instanceof GT_Cover_Fluidfilter) { + final String filterKey = String.format("fluidFilter%d", i); + if (aNBT.hasKey(filterKey)) { + mCoverData[i] = (mCoverData[i] & 7) | (FluidRegistry.getFluidID(aNBT.getString(filterKey)) << 3); + } + } + } + + + if (mID != 0 && createNewMetatileEntity(mID)) { + NBTTagList tItemList = aNBT.getTagList("Inventory", 10); + for (int i = 0; i < tItemList.tagCount(); i++) { + NBTTagCompound tTag = tItemList.getCompoundTagAt(i); + int tSlot = tTag.getInteger("IntSlot"); + if (tSlot >= 0 && tSlot < mMetaTileEntity.getRealInventory().length) { + mMetaTileEntity.getRealInventory()[tSlot] = GT_Utility.loadItem(tTag); + } + } + + try { + mMetaTileEntity.loadNBTData(aNBT); + } catch (Throwable e) { + GT_Log.err.println("Encountered Exception while loading MetaTileEntity, the Server should've crashed now, but I prevented that. Please report immediately to GregTech Intergalactical!!!"); + e.printStackTrace(GT_Log.err); + } + } + } + + if (mCoverData.length != 6) mCoverData = 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) mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; + + for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehavior(mCoverSides[i]); + } + + private boolean createNewMetatileEntity(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 (hasValidMetaTileEntity()) mMetaTileEntity.setBaseMetaTileEntity(null); + GregTech_API.METATILEENTITIES[aID].newMetaEntity(this).setBaseMetaTileEntity(this); + mTickTimer = 0; + mID = aID; + return true; + } + return false; + } + + @Override + public void updateEntity() { + super.updateEntity(); + + if (!hasValidMetaTileEntity()) { + if (mMetaTileEntity == null) return; + mMetaTileEntity.setBaseMetaTileEntity(this); + } + + long tTime = System.nanoTime(); + int tCode = 0; + + try { for (tCode = 0; hasValidMetaTileEntity() && tCode >= 0; ) { + switch (tCode) { + case 0: + tCode++; + if (mTickTimer++ == 0) { + oX = xCoord; + oY = yCoord; + oZ = zCoord; + if (isServerSide()) 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()) return; + } + case 1: + tCode++; + if (isClientSide()) { + if (mColor != oColor) { + mMetaTileEntity.onColorChangeClient(oColor = mColor); + issueTextureUpdate(); + } + + if (mNeedsUpdate) { + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + //worldObj.func_147479_m(xCoord, yCoord, zCoord); + mNeedsUpdate = false; + } + } + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + if (isServerSide() && mTickTimer > 10) { + for (byte i = (byte) (tCode - 2); i < 6; i++) + if (getCoverIDAtSide(i) != 0) { + tCode++; + GT_CoverBehavior tCover = getCoverBehaviorAtSide(i); + int tCoverTickRate = tCover.getTickRate(i, getCoverIDAtSide(i), mCoverData[i], this); + if (tCoverTickRate > 0 && mTickTimer % tCoverTickRate == 0) { + mCoverData[i] = tCover.doCoverThings(i, getInputRedstoneSignal(i), getCoverIDAtSide(i), mCoverData[i], this, mTickTimer); + if (!hasValidMetaTileEntity()) return; + } + } + mConnections = (byte) (mMetaTileEntity.mConnections | (mConnections & ~63)); + if ((mConnections & -64) == 64 && getRandomNumber(1000) == 0) { + mConnections = (byte) ((mConnections & ~64) | -128); + } + } + case 8: + tCode = 9; + mMetaTileEntity.onPreTick(this, mTickTimer); + if (!hasValidMetaTileEntity()) return; + case 9: + tCode++; + if (isServerSide()) { + if (mTickTimer == 10) { + for (byte i = 0; i < 6; i++) + mCoverBehaviors[i] = GregTech_API.getCoverBehavior(mCoverSides[i]); + issueBlockUpdate(); + joinEnet(); + } + + if (xCoord != oX || yCoord != oY || zCoord != oZ) { + oX = xCoord; + oY = yCoord; + oZ = zCoord; + issueClientUpdate(); + clearTileEntityBuffer(); + } + } + case 10: + tCode++; + mMetaTileEntity.onPostTick(this, mTickTimer); + if (!hasValidMetaTileEntity()) return; + case 11: + tCode++; + if (isServerSide()) { + 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 = mConnections, 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; + } + } + + if (mTickTimer > 10) { + if (mConnections != oTextureData) sendBlockEvent((byte) 0, oTextureData = mConnections); + byte tData = mMetaTileEntity.getUpdateData(); + if (tData != oUpdateData) sendBlockEvent((byte) 1, oUpdateData = tData); + if (mColor != oColor) sendBlockEvent((byte) 2, 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)); + if (tData != oRedstoneData) sendBlockEvent((byte) 3, oRedstoneData = tData); + } + + if (mNeedsBlockUpdate) { + worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockOffset(0, 0, 0)); + mNeedsBlockUpdate = false; + } + } + default: + tCode = -1; + break; + } + } + } catch (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 (isServerSide() && 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*1000000) && 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 = false; + } + + @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) { + mID = aID; + createNewMetatileEntity(mID); + } + + mCoverSides[0] = aCover0; + mCoverSides[1] = aCover1; + mCoverSides[2] = aCover2; + mCoverSides[3] = aCover3; + mCoverSides[4] = aCover4; + mCoverSides[5] = aCover5; + + for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehavior(mCoverSides[i]); + + receiveClientEvent(0, aTextureData); + receiveClientEvent(1, aUpdateData); + receiveClientEvent(2, aColorData); + receiveClientEvent(3, aRedstoneData); + } + + @Override + public boolean receiveClientEvent(int aEventID, int aValue) { + super.receiveClientEvent(aEventID, aValue); + + if (hasValidMetaTileEntity()) { + 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); + } + } + + if (isClientSide()) { + issueTextureUpdate(); + switch (aEventID) { + case 0: + mConnections = (byte) aValue; + break; + case 1: + if (hasValidMetaTileEntity()) mMetaTileEntity.onValueUpdate((byte) aValue); + break; + case 2: + if (aValue > 16 || aValue < 0) aValue = 0; + mColor = (byte) aValue; + break; + case 3: + 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) + mMetaTileEntity.doSound((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); + break; + case 5: + if (hasValidMetaTileEntity() && mTickTimer > 20) + mMetaTileEntity.startSoundLoop((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); + break; + case 6: + if (hasValidMetaTileEntity() && mTickTimer > 20) + mMetaTileEntity.stopSoundLoop((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); + break; + } + } + return true; + } + + public ArrayList getDebugInfo(EntityPlayer aPlayer, int aLogLevel) { + ArrayList 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 : " ")); + } + if (aLogLevel > 1) { + if (mTimeStatistics.length > 0) { + double tAverageTime = 0; + double tWorstTime = 0; + for (int tTime : mTimeStatistics) { + tAverageTime += tTime; + if (tTime > tWorstTime) { + tWorstTime = tTime; + } + } + tList.add("Average CPU-load of ~" + (tAverageTime / mTimeStatistics.length) + "ns since " + mTimeStatistics.length + " ticks with worst time of " + tWorstTime + "ns."); + } + 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) ? " " : EnumChatFormatting.RED+" not "+EnumChatFormatting.RESET) + "accessible for you"); + } + if(joinedIc2Enet) + tList.add("Joined IC2 ENet"); + + return mMetaTileEntity.getSpecialDebugInfo(this, aPlayer, aLogLevel, tList); + } + + @Override + public void issueTextureUpdate() { + mNeedsUpdate = true; + } + + @Override + public void issueBlockUpdate() { + mNeedsBlockUpdate = true; + } + + @Override + public void issueClientUpdate() { + mSendClientData = true; + } + + @Override + public void issueCoverUpdate(byte 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; + } + + public ITexture getCoverTexture(byte aSide) { + return GregTech_API.sCovers.get(new GT_ItemStack(getCoverIDAtSide(aSide))); + } + + @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() { + return GT_Utility.getOppositeSide(getFrontFacing()); + } + + @Override + public byte getFrontFacing() { + return 6; + } + + @Override + public void setFrontFacing(byte aFacing) { + doEnetUpdate(); + } + + @Override + public int getSizeInventory() { + if (canAccessData()) return mMetaTileEntity.getSizeInventory(); + return 0; + } + + @Override + public ItemStack getStackInSlot(int aIndex) { + if (canAccessData()) return mMetaTileEntity.getStackInSlot(aIndex); + return null; + } + + @Override + public void setInventorySlotContents(int aIndex, ItemStack aStack) { + mInventoryChanged = true; + if (canAccessData()) + mMetaTileEntity.setInventorySlotContents(aIndex, worldObj.isRemote ? aStack : GT_OreDictUnificator.setStack(true, aStack)); + } + + @Override + public String getInventoryName() { + if (canAccessData()) return mMetaTileEntity.getInventoryName(); + if (GregTech_API.METATILEENTITIES[mID] != null) return GregTech_API.METATILEENTITIES[mID].getInventoryName(); + return ""; + } + + @Override + public int getInventoryStackLimit() { + if (canAccessData()) return mMetaTileEntity.getInventoryStackLimit(); + return 64; + } + + @Override + public void openInventory() {/*Do nothing*/} + + @Override + public void closeInventory() {/*Do nothing*/} + + @Override + public boolean isUseableByPlayer(EntityPlayer aPlayer) { + return hasValidMetaTileEntity() && mTickTimer > 40 && getTileEntityOffset(0, 0, 0) == this && aPlayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64 && mMetaTileEntity.isAccessAllowed(aPlayer); + } + + @Override + public void validate() { + super.validate(); + mTickTimer = 0; + } + + @Override + public void invalidate() { + tileEntityInvalid = false; + if (hasValidMetaTileEntity()) { + mMetaTileEntity.onRemoval(); + mMetaTileEntity.setBaseMetaTileEntity(null); + } + leaveEnet(); + super.invalidate(); + } + + @Override + public void onChunkUnload() { + super.onChunkUnload(); + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public ItemStack getStackInSlotOnClosing(int slot) { + ItemStack stack = getStackInSlot(slot); + if (stack != null) setInventorySlotContents(slot, null); + return stack; + } + + @Override + public void onMachineBlockUpdate() { + if (canAccessData()) mMetaTileEntity.onMachineBlockUpdate(); + } + + @Override + public int getProgress() { + return canAccessData() ? mMetaTileEntity.getProgresstime() : 0; + } + + @Override + public int getMaxProgress() { + return canAccessData() ? mMetaTileEntity.maxProgresstime() : 0; + } + + @Override + public boolean increaseProgress(int aProgressAmountInTicks) { + return canAccessData() ? mMetaTileEntity.increaseProgress(aProgressAmountInTicks) != aProgressAmountInTicks : false; + } + + @Override + public boolean hasThingsToDo() { + return getMaxProgress() > 0; + } + + @Override + public void enableWorking() { + if (!mWorks) mWorkUpdate = true; + mWorks = true; + } + + @Override + public void disableWorking() { + mWorks = false; + } + + @Override + public boolean isAllowedToWork() { + return mWorks; + } + + @Override + public boolean hasWorkJustBeenEnabled() { + return mWorkUpdate; + } + + @Override + public byte getWorkDataValue() { + return 0; + } + + @Override + public void setWorkDataValue(byte aValue) {/*Do nothing*/} + + @Override + public int getMetaTileID() { + return mID; + } + + @Override + public int setMetaTileID(short aID) { + return mID = aID; + } + + @Override + public boolean isActive() { + return false; + } + + @Override + public void setActive(boolean aActive) {/*Do nothing*/} + + @Override + public long getTimer() { + return mTickTimer; + } + + @Override + public boolean decreaseStoredEnergyUnits(long aEnergy, boolean aIgnoreTooLessEnergy) { + return false; + } + + @Override + public boolean increaseStoredEnergyUnits(long aEnergy, boolean aIgnoreTooMuchEnergy) { + return false; + } + + @Override + public boolean inputEnergyFrom(byte aSide) { + return false; + } + + @Override + public boolean inputEnergyFrom(byte aSide, boolean waitForActive) { + return false; + } + + @Override + public boolean outputsEnergyTo(byte aSide) { + return false; + } + + @Override + public boolean outputsEnergyTo(byte aSide, boolean waitForActive) { + return false; + } + + @Override + public long getOutputAmperage() { + return 0; + } + + @Override + public long getOutputVoltage() { + return 0; + } + + @Override + public long getInputAmperage() { + return 0; + } + + @Override + public long getInputVoltage() { + return 0; + } + + @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()); + } + + @Override + public long getUniversalEnergyCapacity() { + return Math.max(getEUCapacity(), getSteamCapacity()); + } + + @Override + public long getStoredEU() { + return 0; + } + + @Override + public long getEUCapacity() { + return 0; + } + + @Override + public long getStoredSteam() { + return 0; + } + + @Override + public long getSteamCapacity() { + return 0; + } + + @Override + public ITexture[] getTexture(Block aBlock, byte aSide) { + ITexture rIcon = getCoverTexture(aSide); + if (rIcon != null) return new ITexture[]{rIcon}; + return getTextureUncovered(aSide); + } + + @Override + public ITexture[] getTextureUncovered(byte aSide) { + if ((mConnections & 64) != 0) return Textures.BlockIcons.FRESHFOAM; + if ((mConnections & -128) != 0) return Textures.BlockIcons.HARDENEDFOAMS[mColor]; + if ((mConnections & -64) != 0) return Textures.BlockIcons.ERROR_RENDERING; + byte tConnections = mConnections; + if (tConnections == 1 || tConnections == 2) tConnections = 3; + else if (tConnections == 4 || tConnections == 8) tConnections = 12; + else if (tConnections == 16 || tConnections == 32) tConnections = 48; + if (hasValidMetaTileEntity()) + return mMetaTileEntity.getTexture(this, aSide, tConnections, (byte) (mColor - 1), tConnections == 0 || (tConnections & (1 << aSide)) != 0, getOutputRedstoneSignal(aSide) > 0); + return Textures.BlockIcons.ERROR_RENDERING; + } + + protected boolean hasValidMetaTileEntity() { + return mMetaTileEntity != null && mMetaTileEntity.getBaseMetaTileEntity() == this; + } + + protected boolean canAccessData() { + return hasValidMetaTileEntity() && !isDead; + } + + @Override + public void doExplosion(long aAmount) { + if (canAccessData()) { + mMetaTileEntity.onExplosion(); + mMetaTileEntity.doExplosion(aAmount); + } + } + + @Override + public ArrayList getDrops() { + ItemStack rStack = new ItemStack(GregTech_API.sBlockMachines, 1, mID); + NBTTagCompound tNBT = new NBTTagCompound(); + if (mStrongRedstone > 0) tNBT.setByte("mStrongRedstone", mStrongRedstone); + for (byte i = 0; i < mCoverSides.length; i++) { + if (mCoverSides[i] != 0) { + tNBT.setIntArray("mCoverData", mCoverData); + tNBT.setIntArray("mCoverSides", mCoverSides); + break; + } + } + if (hasValidMetaTileEntity()) mMetaTileEntity.setItemNBT(tNBT); + if (!tNBT.hasNoTags()) rStack.setTagCompound(tNBT); + return new ArrayList(Arrays.asList(rStack)); + } + + @Override + public boolean onRightclick(EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { + if (isClientSide()) { + if (getCoverBehaviorAtSide(aSide).onCoverRightclickClient(aSide, this, aPlayer, aX, aY, aZ)) return true; + } + if (isServerSide()) { + ItemStack tCurrentItem = aPlayer.inventory.getCurrentItem(); + if (tCurrentItem != null) { + if (getColorization() >= 0 && GT_Utility.areStacksEqual(new ItemStack(Items.water_bucket, 1), tCurrentItem)) { + tCurrentItem.func_150996_a(Items.bucket); + setColorization((byte) -1); + return true; + } + byte tSide = GT_Utility.determineWrenchingSide(aSide, aX, aY, aZ); + if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sWrenchList)) { + if (mMetaTileEntity.onWrenchRightClick(aSide, tSide, aPlayer, aX, aY, aZ)) { + GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer); + GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(100), 1.0F, -1, xCoord, yCoord, zCoord); + } + return true; + } + if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sScrewdriverList)) { + if (getCoverIDAtSide(aSide) == 0 && getCoverIDAtSide(tSide) != 0) { + if (GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 200, aPlayer)) { + setCoverDataAtSide(tSide, getCoverBehaviorAtSide(tSide).onCoverScrewdriverclick(tSide, getCoverIDAtSide(tSide), getCoverDataAtSide(tSide), this, aPlayer, 0.5F, 0.5F, 0.5F)); + mMetaTileEntity.onScrewdriverRightClick(tSide, aPlayer, aX, aY, aZ); + GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(100), 1.0F, -1, xCoord, yCoord, zCoord); + } + } else { + if (GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer)) { + setCoverDataAtSide(aSide, getCoverBehaviorAtSide(aSide).onCoverScrewdriverclick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this, aPlayer, aX, aY, aZ)); + mMetaTileEntity.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); + GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(100), 1.0F, -1, xCoord, yCoord, zCoord); + } + } + return true; + } + + if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sHardHammerList)) { + //if (GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer)) { + // GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(1), 1.0F, -1, xCoord, yCoord, zCoord); + //} + return true; + } + + if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sSoftHammerList)) { + if (GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer)) { + if (mWorks) disableWorking(); + else enableWorking(); + GT_Utility.sendChatToPlayer(aPlayer, trans("090","Machine Processing: ") + (isAllowedToWork() ? trans("088","Enabled") : trans("087","Disabled"))); + GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(101), 1.0F, -1, xCoord, yCoord, zCoord); + } + return true; + } + + if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sWireCutterList)) { + if (mMetaTileEntity.onWireCutterRightClick(aSide, tSide, aPlayer, aX, aY, aZ)) { + //logic handled internally + GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(100), 1.0F, -1, xCoord, yCoord, zCoord); + } + doEnetUpdate(); + return true; + } + + if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sSolderingToolList)) { + if (mMetaTileEntity.onSolderingToolRightClick(aSide, tSide, aPlayer, aX, aY, aZ)) { + //logic handled internally + GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(103), 1.0F, -1, xCoord, yCoord, zCoord); + } else if (GT_ModHandler.useSolderingIron(tCurrentItem, aPlayer)) { + mStrongRedstone ^= (1 << tSide); + GT_Utility.sendChatToPlayer(aPlayer, trans("091","Redstone Output at Side ") + tSide + trans("092"," set to: ") + ((mStrongRedstone & (1 << tSide)) != 0 ? trans("093","Strong") : trans("094","Weak"))); + GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(103), 3.0F, -1, xCoord, yCoord, zCoord); + } + doEnetUpdate(); + return true; + } + + byte cSide = tSide; + if (getCoverIDAtSide(aSide) != 0) cSide = aSide; + + if (getCoverIDAtSide(cSide) == 0) { + if (GregTech_API.sCovers.containsKey(new GT_ItemStack(tCurrentItem))) { + if (GregTech_API.getCoverBehavior(tCurrentItem).isCoverPlaceable(cSide, new GT_ItemStack(tCurrentItem), this) && mMetaTileEntity.allowCoverOnSide(cSide, new GT_ItemStack(tCurrentItem))) { + setCoverItemAtSide(cSide, tCurrentItem); + if (!aPlayer.capabilities.isCreativeMode) tCurrentItem.stackSize--; + GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(100), 1.0F, -1, xCoord, yCoord, zCoord); + } + return true; + } + } else { + if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sCrowbarList)) { + if (GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer)) { + GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(0), 1.0F, -1, xCoord, yCoord, zCoord); + dropCover(cSide, aSide, false); + } + return true; + } + } + } + + if (getCoverBehaviorAtSide(aSide).onCoverRightclick(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this, aPlayer, aX, aY, aZ)) + return true; + } + + if (!getCoverBehaviorAtSide(aSide).isGUIClickable(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this)) + return false; + + try { + if (hasValidMetaTileEntity()) return mMetaTileEntity.onRightclick(this, aPlayer, aSide, aX, aY, aZ); + } 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); + } + + return false; + } + + @Override + public void onLeftclick(EntityPlayer aPlayer) { + 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); + } + } + + @Override + public boolean isDigitalChest() { + return false; + } + + @Override + public ItemStack[] getStoredItemData() { + return null; + } + + @Override + public void setItemCount(int aCount) { + // + } + + @Override + public int getMaxItemCount() { + return 0; + } + + /** + * Can put aStack into Slot + */ + @Override + public boolean isItemValidForSlot(int aIndex, ItemStack aStack) { + return canAccessData() && mMetaTileEntity.isItemValidForSlot(aIndex, aStack); + } + + /** + * returns all valid Inventory Slots, no matter which Side (Unless it's covered). + * The Side Stuff is done in the following two Functions. + */ + @Override + public int[] getAccessibleSlotsFromSide(int aSide) { + if (canAccessData() && (getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSide((byte) aSide), -1, this) || getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSide((byte) aSide), -1, this))) + return mMetaTileEntity.getAccessibleSlotsFromSide(aSide); + return new int[0]; + } + + /** + * Can put aStack into Slot at Side + */ + @Override + public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { + return canAccessData() && getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSide((byte) aSide), aIndex, this) && mMetaTileEntity.canInsertItem(aIndex, aStack, aSide); + } + + /** + * Can pull aStack out of Slot from Side + */ + @Override + public boolean canExtractItem(int aIndex, ItemStack aStack, int aSide) { + return canAccessData() && getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, getCoverIDAtSide((byte) aSide), getCoverDataAtSide((byte) aSide), aIndex, this) && mMetaTileEntity.canExtractItem(aIndex, aStack, aSide); + } + + @Override + public boolean isUpgradable() { + return false; + } + + @Override + public byte getInternalInputRedstoneSignal(byte aSide) { + return (byte) (getCoverBehaviorAtSide(aSide).getRedstoneInput(aSide, getInputRedstoneSignal(aSide), getCoverIDAtSide(aSide), getCoverDataAtSide(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) (getCoverBehaviorAtSide(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this) || (getCoverBehaviorAtSide(aSide).letsRedstoneGoOut(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this)) ? mSidedRedstone[aSide] & 15 : 0); + } + + @Override + public void setInternalOutputRedstoneSignal(byte aSide, byte aStrength) { + if (!getCoverBehaviorAtSide(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(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; + } + + @Override + public boolean addSteamEngineUpgrade() { + if (isSteamEngineUpgradable()) { + issueBlockUpdate(); + return true; + } + return false; + } + + @Override + public boolean hasSteamEngineUpgrade() { + return false; + } + + @Override + public boolean hasInventoryBeenModified() { + return mInventoryChanged; + } + + @Override + public void setGenericRedstoneOutput(boolean aOnOff) { + // + } + + @Override + public int getErrorDisplayID() { + return 0; + } + + @Override + public void setErrorDisplayID(int aErrorID) { + // + } + + @Override + public IMetaTileEntity getMetaTileEntity() { + return hasValidMetaTileEntity() ? mMetaTileEntity : null; + } + + @Override + public void setMetaTileEntity(IMetaTileEntity aMetaTileEntity) { + mMetaTileEntity = (MetaPipeEntity) aMetaTileEntity; + } + + @Override + public GT_CoverBehavior getCoverBehaviorAtSide(byte aSide) { + return aSide >= 0 && aSide < mCoverBehaviors.length ? mCoverBehaviors[aSide] : GregTech_API.sNoBehavior; + } + + @Override + public void setCoverIDAtSide(byte aSide, int aID) { + if (aSide >= 0 && aSide < 6) { + mCoverSides[aSide] = aID; + mCoverData[aSide] = 0; + mCoverBehaviors[aSide] = GregTech_API.getCoverBehavior(aID); + issueCoverUpdate(aSide); + issueBlockUpdate(); + } + } + + @Override + public void setCoverItemAtSide(byte aSide, ItemStack aCover) { + GregTech_API.getCoverBehavior(aCover).placeCover(aSide, aCover, this); + } + + @Override + public int getCoverIDAtSide(byte aSide) { + if (aSide >= 0 && aSide < 6) return mCoverSides[aSide]; + return 0; + } + + @Override + public ItemStack getCoverItemAtSide(byte aSide) { + return GT_Utility.intToStack(getCoverIDAtSide(aSide)); + } + + @Override + public boolean canPlaceCoverIDAtSide(byte aSide, int aID) { + return getCoverIDAtSide(aSide) == 0; + } + + @Override + public boolean canPlaceCoverItemAtSide(byte aSide, ItemStack aCover) { + return getCoverIDAtSide(aSide) == 0; + } + + @Override + public void setCoverDataAtSide(byte aSide, int aData) { + if (aSide >= 0 && aSide < 6) mCoverData[aSide] = aData; + } + + @Override + public int getCoverDataAtSide(byte aSide) { + if (aSide >= 0 && aSide < 6) return mCoverData[aSide]; + return 0; + } + + @Override + public void setLightValue(byte aLightValue) { + // + } + + @Override + public long getAverageElectricInput() { + return 0; + } + + @Override + public long getAverageElectricOutput() { + return 0; + } + + @Override + public boolean dropCover(byte aSide, byte aDroppedSide, boolean aForced) { + if (getCoverBehaviorAtSide(aSide).onCoverRemoval(aSide, getCoverIDAtSide(aSide), mCoverData[aSide], this, aForced) || aForced) { + ItemStack tStack = getCoverBehaviorAtSide(aSide).getDrop(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this); + if (tStack != null) { + tStack.setTagCompound(null); + EntityItem tEntity = new EntityItem(worldObj, getOffsetX(aDroppedSide, 1) + 0.5, getOffsetY(aDroppedSide, 1) + 0.5, getOffsetZ(aDroppedSide, 1) + 0.5, tStack); + tEntity.motionX = 0; + tEntity.motionY = 0; + tEntity.motionZ = 0; + worldObj.spawnEntityInWorld(tEntity); + } + + setCoverIDAtSide(aSide, 0); + setOutputRedstoneSignal(aSide, (byte) 0); + return true; + } + return false; + } + + @Override + public String getOwnerName() { + return "Player"; + } + + @Override + public String setOwnerName(String aName) { + return "Player"; + } + + @Override + public UUID getOwnerUuid() { + return GT_Utility.defaultUuid; + } + + @Override + public void setOwnerUuid(UUID uuid) { + + } + + @Override + public byte getComparatorValue(byte aSide) { + return canAccessData() ? mMetaTileEntity.getComparatorValue(aSide) : 0; + } + + @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; + return mMetaTileEntity.decrStackSize(aIndex, aAmount); + } + return null; + } + + @Override + public long injectEnergyUnits(byte aSide, long aVoltage, long aAmperage) { + if (canAccessData()) return mMetaTileEntity.injectEnergyUnits(aSide, aVoltage, aAmperage); + return 0; + } + + @Override + public boolean drainEnergyUnits(byte aSide, long aVoltage, long aAmperage) { + return false; + } + + @Override + public boolean acceptsRotationalEnergy(byte aSide) { + if (!canAccessData() || getCoverIDAtSide(aSide) != 0) return false; + return mMetaTileEntity.acceptsRotationalEnergy(aSide); + } + + @Override + public boolean injectRotationalEnergy(byte aSide, long aSpeed, long aEnergy) { + if (!canAccessData() || getCoverIDAtSide(aSide) != 0) return false; + return mMetaTileEntity.injectRotationalEnergy(aSide, aSpeed, aEnergy); + } + + private boolean canMoveFluidOnSide(ForgeDirection aSide, Fluid aFluid, boolean isFill) { + if (aSide == ForgeDirection.UNKNOWN) + return true; + + IFluidHandler tTileEntity = getITankContainerAtSide((byte) aSide.ordinal()); + // Only require a connection if there's something to connect to - Allows fluid cells & buckets to interact with the pipe + if (tTileEntity != null && !mMetaTileEntity.isConnectedAtSide((byte) aSide.ordinal())) + return false; + + if(isFill && mMetaTileEntity.isLiquidInput((byte) aSide.ordinal()) + && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), aFluid, this)) + return true; + + if (!isFill && mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) + && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()),aFluid, this)) + return true; + + return false; + } + + @Override + public int fill(ForgeDirection aSide, FluidStack aFluidStack, boolean doFill) { + if (mTickTimer > 5 && canAccessData() && canMoveFluidOnSide(aSide, aFluidStack == null ? null : aFluidStack.getFluid(), true)) + return mMetaTileEntity.fill(aSide, aFluidStack, doFill); + return 0; + } + + @Override + public FluidStack drain(ForgeDirection aSide, int maxDrain, boolean doDrain) { + if (mTickTimer > 5 && canAccessData() && canMoveFluidOnSide(aSide, mMetaTileEntity.getFluid() == null ? null : mMetaTileEntity.getFluid().getFluid(), false)) + return mMetaTileEntity.drain(aSide, maxDrain, doDrain); + return null; + } + + @Override + public FluidStack drain(ForgeDirection aSide, FluidStack aFluidStack, boolean doDrain) { + if (mTickTimer > 5 && canAccessData() && canMoveFluidOnSide(aSide, aFluidStack == null ? null : aFluidStack.getFluid(), false)) + return mMetaTileEntity.drain(aSide, aFluidStack, doDrain); + return null; + } + + @Override + public boolean canFill(ForgeDirection aSide, Fluid aFluid) { + if (mTickTimer > 5 && canAccessData() && canMoveFluidOnSide(aSide, aFluid, true)) + return mMetaTileEntity.canFill(aSide, aFluid); + return false; + } + + @Override + public boolean canDrain(ForgeDirection aSide, Fluid aFluid) { + if (mTickTimer > 5 && canAccessData() && canMoveFluidOnSide(aSide, aFluid, false)) + return mMetaTileEntity.canDrain(aSide, aFluid); + return false; + } + + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection aSide) { + if (canAccessData() + && (aSide == ForgeDirection.UNKNOWN + || (mMetaTileEntity.isLiquidInput((byte) aSide.ordinal()) + && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), null, this)) + || (mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), null, this)) + // Doesn't need to be connected to get Tank Info -- otherwise things can't connect + ) + ) + return mMetaTileEntity.getTankInfo(aSide); + return new FluidTankInfo[]{}; + } + + @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; + ItemStack tStack = getStackInSlot(aIndex); + if (GT_Utility.isStackInvalid(tStack)) { + setInventorySlotContents(aIndex, aStack); + return true; + } + aStack = GT_OreDictUnificator.get(aStack); + if (GT_Utility.areStacksEqual(tStack, aStack) && tStack.stackSize + aStack.stackSize <= Math.min(aStack.getMaxStackSize(), getInventoryStackLimit())) { + tStack.stackSize += aStack.stackSize; + return true; + } + return false; + } + + @Override + public boolean addStackToSlot(int aIndex, ItemStack aStack, int aAmount) { + return addStackToSlot(aIndex, GT_Utility.copyAmount(aAmount, aStack)); + } + + @Override + public byte getColorization() { + return (byte) (mColor - 1); + } + + @Override + public byte setColorization(byte aColor) { + if (aColor > 15 || aColor < -1) aColor = -1; + mColor = (byte) (aColor + 1); + if (canAccessData()) mMetaTileEntity.onColorChangeServer(aColor); + return mColor; + } + + @Override + public float getThickNess() { + if (canAccessData()) return mMetaTileEntity.getThickNess(); + return 1.0F; + } + + public boolean renderInside(byte aSide) { + if (canAccessData()) return mMetaTileEntity.renderInside(aSide); + return false; + } + + @Override + public float getBlastResistance(byte aSide) { + return (mConnections & 192) != 0 ? 50.0F : 5.0F; + } + + @Override + public boolean isMufflerUpgradable() { + return false; + } + + @Override + public boolean addMufflerUpgrade() { + return false; + } + + @Override + public boolean hasMufflerUpgrade() { + return false; + } + + @Override + public boolean isUniversalEnergyStored(long aEnergyAmount) { + return getUniversalEnergyStored() >= aEnergyAmount; + } + + @Override + public String[] getInfoData() { + { + if (canAccessData()) return getMetaTileEntity().getInfoData(); + return new String[]{}; + } + } + + @Override + public byte getConnections() { + 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(); + if (meta instanceof MetaPipeEntity) { + // Trigger a checking of connections in case someone placed down a block that the pipe/wire shouldn't be connected to. + // However; don't do it immediately in case the world isn't finished loading + // (This caused issues with AE2 GTEU p2p connections. + ((MetaPipeEntity) meta).setCheckConnections(); + } + } + } + + @Override + public int getLightOpacity() { + return mMetaTileEntity == null ? 0 : mMetaTileEntity.getLightOpacity(); + } + + @Override + public void addCollisionBoxesToList(World aWorld, int aX, int aY, int aZ, AxisAlignedBB inputAABB, List outputAABB, Entity collider) { + mMetaTileEntity.addCollisionBoxesToList(aWorld, aX, aY, aZ, inputAABB, outputAABB, collider); + } + + @Override + public AxisAlignedBB getCollisionBoundingBoxFromPool(World aWorld, int aX, int aY, int aZ) { + return mMetaTileEntity.getCollisionBoundingBoxFromPool(aWorld, aX, aY, aZ); + } + + @Override + public void onEntityCollidedWithBlock(World aWorld, int aX, int aY, int aZ, Entity collider) { + mMetaTileEntity.onEntityCollidedWithBlock(aWorld, aX, aY, aZ, collider); + } +} diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 1da2dffca9..58a97f644a 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -39,6 +39,7 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.UUID; import static gregtech.GT_Mod.GT_FML_LOGGER; import static gregtech.api.enums.GT_Values.NW; @@ -69,6 +70,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE public long mLastSoundTick = 0; private long mLastCheckTick = 0; private String mOwnerName = ""; + private UUID mOwnerUuid = GT_Utility.defaultUuid; private NBTTagCompound mRecipeStuff = new NBTTagCompound(); private static final Field ENTITY_ITEM_HEALTH_FIELD; @@ -116,6 +118,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE aNBT.setByte("mStrongRedstone", mStrongRedstone); aNBT.setShort("mFacing", mFacing); aNBT.setString("mOwnerName", mOwnerName); + aNBT.setString("mOwnerUuid", mOwnerUuid == null ? "" : mOwnerUuid.toString()); aNBT.setBoolean("mLockUpgrade", mLockUpgrade); aNBT.setBoolean("mMuffler", mMuffler); aNBT.setBoolean("mSteamConverter", mSteamConverter); @@ -181,6 +184,11 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE mStrongRedstone = aNBT.getByte("mStrongRedstone"); mFacing = oFacing = (byte) aNBT.getShort("mFacing"); mOwnerName = aNBT.getString("mOwnerName"); + try { + mOwnerUuid = UUID.fromString(aNBT.getString("mOwnerUuid")); + } catch (IllegalArgumentException e){ + mOwnerUuid = null; + } mLockUpgrade = aNBT.getBoolean("mLockUpgrade"); mMuffler = aNBT.getBoolean("mMuffler"); mSteamConverter = aNBT.getBoolean("mSteamConverter"); @@ -541,7 +549,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE 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), + oColor = mColor), xCoord, zCoord); mSendClientData = false; } @@ -1191,8 +1199,10 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE public boolean playerOwnsThis(EntityPlayer aPlayer, boolean aCheckPrecicely) { if (!canAccessData()) return false; 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())) + if ((mOwnerName.length() == 0) && isServerSide()) { + setOwnerName(aPlayer.getDisplayName()); + setOwnerUuid(aPlayer.getUniqueID()); + } else if (privateAccess() && !aPlayer.getDisplayName().equals("Player") && !mOwnerName.equals("Player") && !mOwnerName.equals(aPlayer.getDisplayName())) return false; return true; } @@ -1244,7 +1254,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE mMetaTileEntity.doExplosion(aAmount); } } - + public void dropItems(ItemStack tItem){ if(tItem==null)return; EntityItem tItemEntity = new EntityItem(this.worldObj, this.xCoord + XSTR_INSTANCE.nextFloat() * 0.8F + 0.1F, this.yCoord + XSTR_INSTANCE.nextFloat() * 0.8F + 0.1F, this.zCoord + XSTR_INSTANCE.nextFloat() * 0.8F + 0.1F, new ItemStack(tItem.getItem(), tItem.stackSize, tItem.getItemDamage())); @@ -1261,7 +1271,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE ENTITY_ITEM_HEALTH_FIELD.setInt(tItemEntity, 99999999); } catch (Exception ignored) {} this.worldObj.spawnEntityInWorld(tItemEntity); - tItem.stackSize = 0; + tItem.stackSize = 0; } @Override @@ -1365,7 +1375,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE doEnetUpdate(); return true; } - + if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sWireCutterList)) { byte tSide = GT_Utility.determineWrenchingSide(aSide, aX, aY, aZ); if (mMetaTileEntity.onWireCutterRightClick(aSide, tSide, aPlayer, aX, aY, aZ)) { @@ -1421,6 +1431,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE if (isUpgradable() && !mLockUpgrade) { mLockUpgrade = true; setOwnerName(aPlayer.getDisplayName()); + setOwnerUuid(aPlayer.getUniqueID()); GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(3), 1.0F, -1, xCoord, yCoord, zCoord); if (!aPlayer.capabilities.isCreativeMode) aPlayer.inventory.getCurrentItem().stackSize--; } @@ -1527,7 +1538,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE public byte getOutputRedstoneSignal(byte aSide) { return getCoverBehaviorAtSide(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this) ? mSidedRedstone[aSide] : getGeneralRS(aSide); } - + public byte getGeneralRS(byte aSide){ if(mMetaTileEntity==null)return 0; return mMetaTileEntity.allowGeneralRedstoneOutput() ? mSidedRedstone[aSide] : 0; @@ -1726,6 +1737,16 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE return mOwnerName = aName; } + @Override + public UUID getOwnerUuid() { + return mOwnerUuid; + } + + @Override + public void setOwnerUuid(UUID uuid) { + mOwnerUuid = uuid; + } + @Override public byte getComparatorValue(byte aSide) { return canAccessData() ? mMetaTileEntity.getComparatorValue(aSide) : 0; diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index fa7bd78c4d..f022124e95 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -1,2363 +1,2366 @@ -package gregtech.api.util; - -import cofh.api.transport.IItemDuct; -import com.mojang.authlib.GameProfile; -import cpw.mods.fml.common.FMLCommonHandler; -import gregtech.api.GregTech_API; -import gregtech.api.damagesources.GT_DamageSources; -import gregtech.api.enchants.Enchantment_Radioactivity; -import gregtech.api.enums.*; -import gregtech.api.events.BlockScanningEvent; -import gregtech.api.interfaces.IDebugableBlock; -import gregtech.api.interfaces.IProjectileItem; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.*; -import gregtech.api.items.GT_EnergyArmor_Item; -import gregtech.api.items.GT_Generic_Item; -import gregtech.api.net.GT_Packet_Sound; -import gregtech.api.objects.GT_ItemStack; -import gregtech.api.objects.ItemData; -import gregtech.api.threads.GT_Runnable_Sound; -import gregtech.common.GT_Proxy; -import ic2.api.recipe.IRecipeInput; -import ic2.api.recipe.RecipeInputItemStack; -import ic2.api.recipe.RecipeInputOreDict; -import ic2.api.recipe.RecipeOutput; -import net.minecraft.block.Block; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.*; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTBase.NBTPrimitive; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; -import net.minecraft.network.play.server.S07PacketRespawn; -import net.minecraft.network.play.server.S1DPacketEntityEffect; -import net.minecraft.network.play.server.S1FPacketSetExperience; -import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionEffect; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityChest; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.MathHelper; -import net.minecraft.world.World; -import net.minecraft.world.WorldServer; -import net.minecraftforge.common.DimensionManager; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.util.BlockSnapshot; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.common.util.FakePlayerFactory; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.event.ForgeEventFactory; -import net.minecraftforge.event.world.BlockEvent; -import net.minecraftforge.fluids.*; -import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.text.NumberFormat; -import java.util.*; -import java.util.Map.Entry; - -import static gregtech.GT_Mod.GT_FML_LOGGER; -import static gregtech.api.enums.GT_Values.*; -import static gregtech.common.GT_Proxy.GTPOLLUTION; -import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation; - -/** - * NEVER INCLUDE THIS FILE IN YOUR MOD!!! - *

- * Just a few Utility Functions I use. - */ -public class GT_Utility { - /** - * Forge screwed the Fluid Registry up again, so I make my own, which is also much more efficient than the stupid Stuff over there. - */ - private static final List sFluidContainerList = new ArrayList(); - private static final Map sFilledContainerToData = new /*Concurrent*/HashMap(); - private static final Map> sEmptyContainerToFluidToData = new /*Concurrent*/HashMap>(); - public static volatile int VERSION = 509; - public static boolean TE_CHECK = false, BC_CHECK = false, CHECK_ALL = true, RF_CHECK = false; - public static Map sPlayedSoundMap = new /*Concurrent*/HashMap(); - private static int sBookCount = 0; - - static { - GregTech_API.sItemStackMappings.add(sFilledContainerToData); - GregTech_API.sItemStackMappings.add(sEmptyContainerToFluidToData); - } - - public static int safeInt(long number, int margin){ - return number>Integer.MAX_VALUE-margin ? Integer.MAX_VALUE-margin :(int)number; - } - - public static int safeInt(long number){ - return number>GT_Values.V[GT_Values.V.length-1] ? safeInt(GT_Values.V[GT_Values.V.length-1],1) : number... aParameterTypes) { - Method rMethod = null; - try { - rMethod = aObject.getMethod(aMethod, aParameterTypes); - rMethod.setAccessible(true); - } catch (Throwable e) {/*Do nothing*/} - return rMethod; - } - - public static Method getMethod(Object aObject, String aMethod, Class... aParameterTypes) { - Method rMethod = null; - try { - rMethod = aObject.getClass().getMethod(aMethod, aParameterTypes); - rMethod.setAccessible(true); - } catch (Throwable e) {/*Do nothing*/} - return rMethod; - } - - public static Field getField(Object aObject, String aField, boolean aPrivate, boolean aLogErrors) { - try { - Field tField = (aObject instanceof Class) ? ((Class) aObject).getDeclaredField(aField) : (aObject instanceof String) ? Class.forName((String) aObject).getDeclaredField(aField) : aObject.getClass().getDeclaredField(aField); - if (aPrivate) tField.setAccessible(true); - return tField; - } catch (Throwable e) { - if (aLogErrors) e.printStackTrace(GT_Log.err); - } - return null; - } - - public static Object getFieldContent(Object aObject, String aField, boolean aPrivate, boolean aLogErrors) { - try { - Field tField = (aObject instanceof Class) ? ((Class) aObject).getDeclaredField(aField) : (aObject instanceof String) ? Class.forName((String) aObject).getDeclaredField(aField) : aObject.getClass().getDeclaredField(aField); - if (aPrivate) tField.setAccessible(true); - return tField.get(aObject instanceof Class || aObject instanceof String ? null : aObject); - } catch (Throwable e) { - if (aLogErrors) e.printStackTrace(GT_Log.err); - } - return null; - } - - public static Object callPublicMethod(Object aObject, String aMethod, Object... aParameters) { - return callMethod(aObject, aMethod, false, false, true, aParameters); - } - - public static Object callPrivateMethod(Object aObject, String aMethod, Object... aParameters) { - return callMethod(aObject, aMethod, true, false, true, aParameters); - } - - public static Object callMethod(Object aObject, String aMethod, boolean aPrivate, boolean aUseUpperCasedDataTypes, boolean aLogErrors, Object... aParameters) { - try { - Class[] tParameterTypes = new Class[aParameters.length]; - for (byte i = 0; i < aParameters.length; i++) { - if (aParameters[i] instanceof Class) { - tParameterTypes[i] = (Class) aParameters[i]; - aParameters[i] = null; - } else { - tParameterTypes[i] = aParameters[i].getClass(); - } - if (!aUseUpperCasedDataTypes) { - if (tParameterTypes[i] == Boolean.class) tParameterTypes[i] = boolean.class; - else if (tParameterTypes[i] == Byte.class) tParameterTypes[i] = byte.class; - else if (tParameterTypes[i] == Short.class) tParameterTypes[i] = short.class; - else if (tParameterTypes[i] == Integer.class) tParameterTypes[i] = int.class; - else if (tParameterTypes[i] == Long.class) tParameterTypes[i] = long.class; - else if (tParameterTypes[i] == Float.class) tParameterTypes[i] = float.class; - else if (tParameterTypes[i] == Double.class) tParameterTypes[i] = double.class; - } - } - - Method tMethod = (aObject instanceof Class) ? ((Class) aObject).getMethod(aMethod, tParameterTypes) : aObject.getClass().getMethod(aMethod, tParameterTypes); - if (aPrivate) tMethod.setAccessible(true); - return tMethod.invoke(aObject, aParameters); - } catch (Throwable e) { - if (aLogErrors) e.printStackTrace(GT_Log.err); - } - return null; - } - - public static Object callConstructor(String aClass, int aConstructorIndex, Object aReplacementObject, boolean aLogErrors, Object... aParameters) { - if (aConstructorIndex < 0) { - try { - for (Constructor tConstructor : Class.forName(aClass).getConstructors()) { - try { - return tConstructor.newInstance(aParameters); - } catch (Throwable e) {/*Do nothing*/} - } - } catch (Throwable e) { - if (aLogErrors) e.printStackTrace(GT_Log.err); - } - } else { - try { - return Class.forName(aClass).getConstructors()[aConstructorIndex].newInstance(aParameters); - } catch (Throwable e) { - if (aLogErrors) e.printStackTrace(GT_Log.err); - } - } - return aReplacementObject; - } - - public static String capitalizeString(String aString) { - if (aString != null && aString.length() > 0) - return aString.substring(0, 1).toUpperCase() + aString.substring(1); - return E; - } - - public static boolean getPotion(EntityLivingBase aPlayer, int aPotionIndex) { - try { - Field tPotionHashmap = null; - - Field[] var3 = EntityLiving.class.getDeclaredFields(); - int var4 = var3.length; - - for (int var5 = 0; var5 < var4; ++var5) { - Field var6 = var3[var5]; - if (var6.getType() == HashMap.class) { - tPotionHashmap = var6; - tPotionHashmap.setAccessible(true); - break; - } - } - - if (tPotionHashmap != null) - return ((HashMap) tPotionHashmap.get(aPlayer)).get(Integer.valueOf(aPotionIndex)) != null; - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - return false; - } - - public static String getClassName(Object aObject) { - if (aObject == null) return "null"; - return aObject.getClass().getName().substring(aObject.getClass().getName().lastIndexOf(".") + 1); - } - - public static void removePotion(EntityLivingBase aPlayer, int aPotionIndex) { - try { - Field tPotionHashmap = null; - - Field[] var3 = EntityLiving.class.getDeclaredFields(); - int var4 = var3.length; - - for (int var5 = 0; var5 < var4; ++var5) { - Field var6 = var3[var5]; - if (var6.getType() == HashMap.class) { - tPotionHashmap = var6; - tPotionHashmap.setAccessible(true); - break; - } - } - - if (tPotionHashmap != null) ((HashMap) tPotionHashmap.get(aPlayer)).remove(Integer.valueOf(aPotionIndex)); - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - } - - public static boolean getFullInvisibility(EntityPlayer aPlayer) { - try { - if (aPlayer.isInvisible()) { - for (int i = 0; i < 4; i++) { - if (aPlayer.inventory.armorInventory[i] != null) { - if (aPlayer.inventory.armorInventory[i].getItem() instanceof GT_EnergyArmor_Item) { - if ((((GT_EnergyArmor_Item) aPlayer.inventory.armorInventory[i].getItem()).mSpecials & 512) != 0) { - if (GT_ModHandler.canUseElectricItem(aPlayer.inventory.armorInventory[i], 10000)) { - return true; - } - } - } - } - } - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - return false; - } - - public static ItemStack suckOneItemStackAt(World aWorld, double aX, double aY, double aZ, double aL, double aH, double aW) { - for (EntityItem tItem : (ArrayList) aWorld.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(aX, aY, aZ, aX + aL, aY + aH, aZ + aW))) { - if (!tItem.isDead) { - aWorld.removeEntity(tItem); - tItem.setDead(); - return tItem.getEntityItem(); - } - } - return null; - } - - public static byte getOppositeSide(int aSide) { - return (byte) ForgeDirection.getOrientation(aSide).getOpposite().ordinal(); - } - - public static byte getTier(long l) { - byte i = -1; - while (++i < V.length) if (l <= V[i]) return i; - return i; - } - - public static void sendChatToPlayer(EntityPlayer aPlayer, String aChatMessage) { - if (aPlayer instanceof EntityPlayerMP && aChatMessage != null) { - aPlayer.addChatComponentMessage(new ChatComponentText(aChatMessage)); - } - } - - public static void checkAvailabilities() { - if (CHECK_ALL) { - try { - Class tClass = IItemDuct.class; - tClass.getCanonicalName(); - TE_CHECK = true; - } catch (Throwable e) {/**/} - try { - Class tClass = buildcraft.api.transport.IPipeTile.class; - tClass.getCanonicalName(); - BC_CHECK = true; - } catch (Throwable e) {/**/} - try { - Class tClass = cofh.api.energy.IEnergyReceiver.class; - tClass.getCanonicalName(); - RF_CHECK = true; - } catch (Throwable e) {/**/} - CHECK_ALL = false; - } - } - - public static boolean isConnectableNonInventoryPipe(Object aTileEntity, int aSide) { - if (aTileEntity == null) return false; - checkAvailabilities(); - if (TE_CHECK && aTileEntity instanceof IItemDuct) return true; - if (BC_CHECK && aTileEntity instanceof buildcraft.api.transport.IPipeTile) - return ((buildcraft.api.transport.IPipeTile) aTileEntity).isPipeConnected(ForgeDirection.getOrientation(aSide)); - if (GregTech_API.mTranslocator && aTileEntity instanceof codechicken.translocator.TileItemTranslocator) return true; - - return false; - } - /** - * Moves Stack from Inv-Slot to Inv-Slot, without checking if its even allowed. - * - * @return the Amount of moved Items - */ - public static byte moveStackIntoPipe(IInventory aTileEntity1, Object aTileEntity2, int[] aGrabSlots, int aGrabFrom, int aPutTo, List aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { - return moveStackIntoPipe(aTileEntity1, aTileEntity2, aGrabSlots, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, true); - } - - /** - * Moves Stack from Inv-Slot to Inv-Slot, without checking if its even allowed. - * - * @return the Amount of moved Items - */ - public static byte moveStackIntoPipe(IInventory aTileEntity1, Object aTileEntity2, int[] aGrabSlots, int aGrabFrom, int aPutTo, List aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce, boolean dropItem) { - if (aTileEntity1 == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMaxMoveAtOnce <= 0 || aMinMoveAtOnce > aMaxMoveAtOnce) - return 0; - if (aTileEntity2 != null) { - checkAvailabilities(); - if (TE_CHECK && aTileEntity2 instanceof IItemDuct) { - for (int i = 0; i < aGrabSlots.length; i++) { - if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlots[i]), true, aInvertFilter)) { - if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlots[i], (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlots[i]))) { - if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize) { - ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlots[i])); - ItemStack rStack = ((IItemDuct) aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), copy(tStack)); - byte tMovedItemCount = (byte) (tStack.stackSize - (rStack == null ? 0 : rStack.stackSize)); - if (tMovedItemCount >= 1/*Math.max(aMinMoveAtOnce, aMinTargetStackSize)*/) { - //((cofh.api.transport.IItemConduit)aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), copyAmount(tMovedItemCount, tStack), F); - aTileEntity1.decrStackSize(aGrabSlots[i], tMovedItemCount); - aTileEntity1.markDirty(); - return tMovedItemCount; - } - } - } - } - } - return 0; - } - if (BC_CHECK && aTileEntity2 instanceof buildcraft.api.transport.IPipeTile) { - for (int i = 0; i < aGrabSlots.length; i++) { - if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlots[i]), true, aInvertFilter)) { - if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlots[i], (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlots[i]))) { - if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize) { - ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlots[i])); - byte tMovedItemCount = (byte) ((buildcraft.api.transport.IPipeTile) aTileEntity2).injectItem(copy(tStack), false, ForgeDirection.getOrientation(aPutTo)); - if (tMovedItemCount >= Math.max(aMinMoveAtOnce, aMinTargetStackSize)) { - tMovedItemCount = (byte) (((buildcraft.api.transport.IPipeTile) aTileEntity2).injectItem(copyAmount(tMovedItemCount, tStack), true, ForgeDirection.getOrientation(aPutTo))); - aTileEntity1.decrStackSize(aGrabSlots[i], tMovedItemCount); - aTileEntity1.markDirty(); - return tMovedItemCount; - } - } - } - } - } - return 0; - } - } - - ForgeDirection tDirection = ForgeDirection.getOrientation(aGrabFrom); - if (aTileEntity1 instanceof TileEntity && tDirection != ForgeDirection.UNKNOWN && tDirection.getOpposite() == ForgeDirection.getOrientation(aPutTo)) { - int tX = ((TileEntity) aTileEntity1).xCoord + tDirection.offsetX, tY = ((TileEntity) aTileEntity1).yCoord + tDirection.offsetY, tZ = ((TileEntity) aTileEntity1).zCoord + tDirection.offsetZ; - if (!hasBlockHitBox(((TileEntity) aTileEntity1).getWorldObj(), tX, tY, tZ) && dropItem) { - for (int i = 0; i < aGrabSlots.length; i++) { - if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlots[i]), true, aInvertFilter)) { - if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlots[i], (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlots[i]))) { - if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize) { - ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlots[i])); - EntityItem tEntity = new EntityItem(((TileEntity) aTileEntity1).getWorldObj(), tX + 0.5, tY + 0.5, tZ + 0.5, tStack); - tEntity.motionX = tEntity.motionY = tEntity.motionZ = 0; - ((TileEntity) aTileEntity1).getWorldObj().spawnEntityInWorld(tEntity); - aTileEntity1.decrStackSize(aGrabSlots[i], tStack.stackSize); - aTileEntity1.markDirty(); - return (byte) tStack.stackSize; - } - } - } - } - } - } - return 0; - } - - /** - * Moves Stack from Inv-Slot to Inv-Slot, without checking if its even allowed. (useful for internal Inventory Operations) - * - * @return the Amount of moved Items - */ - public static byte moveStackFromSlotAToSlotB(IInventory aTileEntity1, IInventory aTileEntity2, int aGrabFrom, int aPutTo, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { - if (aTileEntity1 == null || aTileEntity2 == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMaxMoveAtOnce <= 0 || aMinMoveAtOnce > aMaxMoveAtOnce) - return 0; - - ItemStack tStack1 = aTileEntity1.getStackInSlot(aGrabFrom), tStack2 = aTileEntity2.getStackInSlot(aPutTo), tStack3 = null; - if (tStack1 != null) { - if (tStack2 != null && !areStacksEqual(tStack1, tStack2)) return 0; - tStack3 = copy(tStack1); - aMaxTargetStackSize = (byte) Math.min(aMaxTargetStackSize, Math.min(tStack3.getMaxStackSize(), Math.min(tStack2 == null ? Integer.MAX_VALUE : tStack2.getMaxStackSize(), aTileEntity2.getInventoryStackLimit()))); - tStack3.stackSize = Math.min(tStack3.stackSize, aMaxTargetStackSize - (tStack2 == null ? 0 : tStack2.stackSize)); - if (tStack3.stackSize > aMaxMoveAtOnce) tStack3.stackSize = aMaxMoveAtOnce; - if (tStack3.stackSize + (tStack2 == null ? 0 : tStack2.stackSize) >= Math.min(tStack3.getMaxStackSize(), aMinTargetStackSize) && tStack3.stackSize >= aMinMoveAtOnce) { - tStack3 = aTileEntity1.decrStackSize(aGrabFrom, tStack3.stackSize); - aTileEntity1.markDirty(); - if (tStack3 != null) { - if (tStack2 == null) { - aTileEntity2.setInventorySlotContents(aPutTo, copy(tStack3)); - aTileEntity2.markDirty(); - } else { - tStack2.stackSize += tStack3.stackSize; - aTileEntity2.markDirty(); - } - return (byte) tStack3.stackSize; - } - } - } - return 0; - } - - public static boolean isAllowedToTakeFromSlot(IInventory aTileEntity, int aSlot, byte aSide, ItemStack aStack) { - if (ForgeDirection.getOrientation(aSide) == ForgeDirection.UNKNOWN) { - return isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 0, aStack) - || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 1, aStack) - || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 2, aStack) - || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 3, aStack) - || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 4, aStack) - || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 5, aStack); - } - if (aTileEntity instanceof ISidedInventory) - return ((ISidedInventory) aTileEntity).canExtractItem(aSlot, aStack, aSide); - return true; - } - - public static boolean isAllowedToPutIntoSlot(IInventory aTileEntity, int aSlot, byte aSide, ItemStack aStack, byte aMaxStackSize) { - ItemStack tStack = aTileEntity.getStackInSlot(aSlot); - if (tStack != null && (!areStacksEqual(tStack, aStack) || tStack.stackSize >= tStack.getMaxStackSize())) - return false; - if (ForgeDirection.getOrientation(aSide) == ForgeDirection.UNKNOWN) { - return isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 0, aStack, aMaxStackSize) - || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 1, aStack, aMaxStackSize) - || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 2, aStack, aMaxStackSize) - || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 3, aStack, aMaxStackSize) - || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 4, aStack, aMaxStackSize) - || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 5, aStack, aMaxStackSize); - } - if (aTileEntity instanceof ISidedInventory && !((ISidedInventory) aTileEntity).canInsertItem(aSlot, aStack, aSide)) - return false; - return aSlot < aTileEntity.getSizeInventory() && aTileEntity.isItemValidForSlot(aSlot, aStack); - } - - /** - * Moves Stack from Inv-Side to Inv-Side. - * - * @return the Amount of moved Items - */ - public static byte moveOneItemStack(Object aTileEntity1, Object aTileEntity2, byte aGrabFrom, byte aPutTo, List aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { - if (aTileEntity1 instanceof IInventory) - return moveOneItemStack((IInventory) aTileEntity1, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, true); - return 0; - } - - /** - * This is only because I needed an additional Parameter for the Double Chest Check. - */ - private static byte moveOneItemStack(IInventory aTileEntity1, Object aTileEntity2, byte aGrabFrom, byte aPutTo, List aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce, boolean aDoCheckChests) { - if (aTileEntity1 == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce) - return 0; - - int[] tGrabSlots = null; - if (aTileEntity1 instanceof ISidedInventory) - tGrabSlots = ((ISidedInventory) aTileEntity1).getAccessibleSlotsFromSide(aGrabFrom); - if (tGrabSlots == null) { - tGrabSlots = new int[aTileEntity1.getSizeInventory()]; - for (int i = 0; i < tGrabSlots.length; i++) tGrabSlots[i] = i; - } - - if (aTileEntity2 != null && aTileEntity2 instanceof IInventory) { - int[] tPutSlots = null; - if (aTileEntity2 instanceof ISidedInventory) - tPutSlots = ((ISidedInventory) aTileEntity2).getAccessibleSlotsFromSide(aPutTo); - - if (tPutSlots == null) { - tPutSlots = new int[((IInventory) aTileEntity2).getSizeInventory()]; - for (int i = 0; i < tPutSlots.length; i++) tPutSlots[i] = i; - } - - for (int i = 0; i < tGrabSlots.length; i++) { - byte tMovedItemCount = 0; - for (int j = 0; j < tPutSlots.length; j++) { - if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(tGrabSlots[i]), true, aInvertFilter)) { - if (isAllowedToTakeFromSlot(aTileEntity1, tGrabSlots[i], aGrabFrom, aTileEntity1.getStackInSlot(tGrabSlots[i]))) { - if (isAllowedToPutIntoSlot((IInventory) aTileEntity2, tPutSlots[j], aPutTo, aTileEntity1.getStackInSlot(tGrabSlots[i]), aMaxTargetStackSize)) { - tMovedItemCount += moveStackFromSlotAToSlotB(aTileEntity1, (IInventory) aTileEntity2, tGrabSlots[i], tPutSlots[j], aMaxTargetStackSize, aMinTargetStackSize, (byte) (aMaxMoveAtOnce - tMovedItemCount), aMinMoveAtOnce); - if (tMovedItemCount >= aMaxMoveAtOnce) { - return tMovedItemCount; - - } - } - } - } - } - if (tMovedItemCount > 0) return tMovedItemCount; - } - - if (aDoCheckChests && aTileEntity1 instanceof TileEntityChest) { - TileEntityChest tTileEntity1 = (TileEntityChest) aTileEntity1; - if (tTileEntity1.adjacentChestChecked) { - byte tAmount = 0; - if (tTileEntity1.adjacentChestXNeg != null) { - tAmount = moveOneItemStack(tTileEntity1.adjacentChestXNeg, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); - } else if (tTileEntity1.adjacentChestZNeg != null) { - tAmount = moveOneItemStack(tTileEntity1.adjacentChestZNeg, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); - } else if (tTileEntity1.adjacentChestXPos != null) { - tAmount = moveOneItemStack(tTileEntity1.adjacentChestXPos, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); - } else if (tTileEntity1.adjacentChestZPos != null) { - tAmount = moveOneItemStack(tTileEntity1.adjacentChestZPos, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); - } - if (tAmount != 0) return tAmount; - } - } - if (aDoCheckChests && aTileEntity2 instanceof TileEntityChest) { - TileEntityChest tTileEntity2 = (TileEntityChest) aTileEntity2; - if (tTileEntity2.adjacentChestChecked) { - byte tAmount = 0; - if (tTileEntity2.adjacentChestXNeg != null) { - tAmount = moveOneItemStack(aTileEntity1, tTileEntity2.adjacentChestXNeg, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); - } else if (tTileEntity2.adjacentChestZNeg != null) { - tAmount = moveOneItemStack(aTileEntity1, tTileEntity2.adjacentChestZNeg, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); - } else if (tTileEntity2.adjacentChestXPos != null) { - tAmount = moveOneItemStack(aTileEntity1, tTileEntity2.adjacentChestXPos, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); - } else if (tTileEntity2.adjacentChestZPos != null) { - tAmount = moveOneItemStack(aTileEntity1, tTileEntity2.adjacentChestZPos, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); - } - if (tAmount != 0) return tAmount; - } - } - } - - return moveStackIntoPipe(aTileEntity1, aTileEntity2, tGrabSlots, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, aDoCheckChests); - } - - /** - * Moves Stack from Inv-Side to Inv-Slot. - * - * @return the Amount of moved Items - */ - public static byte moveOneItemStackIntoSlot(Object aTileEntity1, Object aTileEntity2, byte aGrabFrom, int aPutTo, List aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { - if (aTileEntity1 == null || !(aTileEntity1 instanceof IInventory) || aPutTo < 0 || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce) - return 0; - - int[] tGrabSlots = null; - if (aTileEntity1 instanceof ISidedInventory) - tGrabSlots = ((ISidedInventory) aTileEntity1).getAccessibleSlotsFromSide(aGrabFrom); - if (tGrabSlots == null) { - tGrabSlots = new int[((IInventory) aTileEntity1).getSizeInventory()]; - for (int i = 0; i < tGrabSlots.length; i++) tGrabSlots[i] = i; - } - - if (aTileEntity2 instanceof IInventory) { - for (int i = 0; i < tGrabSlots.length; i++) { - if (listContainsItem(aFilter, ((IInventory) aTileEntity1).getStackInSlot(tGrabSlots[i]), true, aInvertFilter)) { - if (isAllowedToTakeFromSlot((IInventory) aTileEntity1, tGrabSlots[i], aGrabFrom, ((IInventory) aTileEntity1).getStackInSlot(tGrabSlots[i]))) { - if (isAllowedToPutIntoSlot((IInventory) aTileEntity2, aPutTo, (byte) 6, ((IInventory) aTileEntity1).getStackInSlot(tGrabSlots[i]), aMaxTargetStackSize)) { - byte tMovedItemCount = moveStackFromSlotAToSlotB((IInventory) aTileEntity1, (IInventory) aTileEntity2, tGrabSlots[i], aPutTo, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce); - if (tMovedItemCount > 0) return tMovedItemCount; - } - } - } - } - } - - moveStackIntoPipe(((IInventory) aTileEntity1), aTileEntity2, tGrabSlots, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce); - return 0; - } - - /** - * Moves Stack from Inv-Slot to Inv-Slot. - * - * @return the Amount of moved Items - */ - public static byte moveFromSlotToSlot(IInventory aTileEntity1, IInventory aTileEntity2, int aGrabFrom, int aPutTo, List aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { - if (aTileEntity1 == null || aTileEntity2 == null || aGrabFrom < 0 || aPutTo < 0 || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce) - return 0; - if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabFrom), true, aInvertFilter)) { - if (isAllowedToTakeFromSlot(aTileEntity1, aGrabFrom, (byte) 6, aTileEntity1.getStackInSlot(aGrabFrom))) { - if (isAllowedToPutIntoSlot(aTileEntity2, aPutTo, (byte) 6, aTileEntity1.getStackInSlot(aGrabFrom), aMaxTargetStackSize)) { - byte tMovedItemCount = moveStackFromSlotAToSlotB(aTileEntity1, aTileEntity2, aGrabFrom, aPutTo, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce); - if (tMovedItemCount > 0) return tMovedItemCount; - } - } - } - return 0; - } - - public static boolean listContainsItem(Collection aList, ItemStack aStack, boolean aTIfListEmpty, boolean aInvertFilter) { - if (aStack == null || aStack.stackSize < 1) return false; - if (aList == null) return aTIfListEmpty; - while (aList.contains(null)) aList.remove(null); - if (aList.size() < 1) return aTIfListEmpty; - Iterator tIterator = aList.iterator(); - ItemStack tStack = null; - while (tIterator.hasNext()) - if ((tStack = tIterator.next()) != null && areStacksEqual(aStack, tStack)) return !aInvertFilter; - return aInvertFilter; - } - - public static boolean areStacksOrToolsEqual(ItemStack aStack1, ItemStack aStack2) { - if (aStack1 != null && aStack2 != null && aStack1.getItem() == aStack2.getItem()) { - if (aStack1.getItem().isDamageable()) return true; - return ((aStack1.getTagCompound() == null) == (aStack2.getTagCompound() == null)) && (aStack1.getTagCompound() == null || aStack1.getTagCompound().equals(aStack2.getTagCompound())) && (Items.feather.getDamage(aStack1) == Items.feather.getDamage(aStack2) || Items.feather.getDamage(aStack1) == W || Items.feather.getDamage(aStack2) == W); - } - return false; - } - - public static boolean areFluidsEqual(FluidStack aFluid1, FluidStack aFluid2) { - return areFluidsEqual(aFluid1, aFluid2, false); - } - - public static boolean areFluidsEqual(FluidStack aFluid1, FluidStack aFluid2, boolean aIgnoreNBT) { - return aFluid1 != null && aFluid2 != null && aFluid1.getFluid() == aFluid2.getFluid() && (aIgnoreNBT || ((aFluid1.tag == null) == (aFluid2.tag == null)) && (aFluid1.tag == null || aFluid1.tag.equals(aFluid2.tag))); - } - - public static boolean areStacksEqual(ItemStack aStack1, ItemStack aStack2) { - return areStacksEqual(aStack1, aStack2, false); - } - - public static boolean areStacksEqual(ItemStack aStack1, ItemStack aStack2, boolean aIgnoreNBT) { - return aStack1 != null && aStack2 != null && aStack1.getItem() == aStack2.getItem() && (aIgnoreNBT || ((aStack1.getTagCompound() == null) == (aStack2.getTagCompound() == null)) && (aStack1.getTagCompound() == null || aStack1.getTagCompound().equals(aStack2.getTagCompound()))) && (Items.feather.getDamage(aStack1) == Items.feather.getDamage(aStack2) || Items.feather.getDamage(aStack1) == W || Items.feather.getDamage(aStack2) == W); - } - - public static boolean areUnificationsEqual(ItemStack aStack1, ItemStack aStack2) { - return areUnificationsEqual(aStack1, aStack2, false); - } - - public static boolean areUnificationsEqual(ItemStack aStack1, ItemStack aStack2, boolean aIgnoreNBT) { - return areStacksEqual(GT_OreDictUnificator.get(aStack1), GT_OreDictUnificator.get(aStack2), aIgnoreNBT); - } - - public static String getFluidName(Fluid aFluid, boolean aLocalized) { - if (aFluid == null) return E; - String rName = aLocalized ? aFluid.getLocalizedName(new FluidStack(aFluid, 0)) : aFluid.getUnlocalizedName(); - if (rName.contains("fluid.") || rName.contains("tile.")) - return capitalizeString(rName.replaceAll("fluid.", E).replaceAll("tile.", E)); - return rName; - } - - public static String getFluidName(FluidStack aFluid, boolean aLocalized) { - if (aFluid == null) return E; - return getFluidName(aFluid.getFluid(), aLocalized); - } - - public static void reInit() { - sFilledContainerToData.clear(); - sEmptyContainerToFluidToData.clear(); - for (FluidContainerData tData : sFluidContainerList) { - sFilledContainerToData.put(new GT_ItemStack(tData.filledContainer), tData); - Map tFluidToContainer = sEmptyContainerToFluidToData.get(new GT_ItemStack(tData.emptyContainer)); - if (tFluidToContainer == null) { - sEmptyContainerToFluidToData.put(new GT_ItemStack(tData.emptyContainer), tFluidToContainer = new /*Concurrent*/HashMap()); - GregTech_API.sFluidMappings.add(tFluidToContainer); - } - tFluidToContainer.put(tData.fluid.getFluid(), tData); - } - } - - public static void addFluidContainerData(FluidContainerData aData) { - sFluidContainerList.add(aData); - sFilledContainerToData.put(new GT_ItemStack(aData.filledContainer), aData); - Map tFluidToContainer = sEmptyContainerToFluidToData.get(new GT_ItemStack(aData.emptyContainer)); - if (tFluidToContainer == null) { - sEmptyContainerToFluidToData.put(new GT_ItemStack(aData.emptyContainer), tFluidToContainer = new /*Concurrent*/HashMap()); - GregTech_API.sFluidMappings.add(tFluidToContainer); - } - tFluidToContainer.put(aData.fluid.getFluid(), aData); - } - - public static ItemStack fillFluidContainer(FluidStack aFluid, ItemStack aStack, boolean aRemoveFluidDirectly, boolean aCheckIFluidContainerItems) { - if (isStackInvalid(aStack) || aFluid == null) return null; - if (GT_ModHandler.isWater(aFluid) && ItemList.Bottle_Empty.isStackEqual(aStack)) { - if (aFluid.amount >= 250) { - if (aRemoveFluidDirectly) aFluid.amount -= 250; - return new ItemStack(Items.potionitem, 1, 0); - } - return null; - } - if (aCheckIFluidContainerItems && aStack.getItem() instanceof IFluidContainerItem && ((IFluidContainerItem) aStack.getItem()).getFluid(aStack) == null && ((IFluidContainerItem) aStack.getItem()).getCapacity(aStack) <= aFluid.amount) { - if (aRemoveFluidDirectly) - aFluid.amount -= ((IFluidContainerItem) aStack.getItem()).fill(aStack = copyAmount(1, aStack), aFluid, true); - else - ((IFluidContainerItem) aStack.getItem()).fill(aStack = copyAmount(1, aStack), aFluid, true); - return aStack; - } - Map tFluidToContainer = sEmptyContainerToFluidToData.get(new GT_ItemStack(aStack)); - if (tFluidToContainer == null) return null; - FluidContainerData tData = tFluidToContainer.get(aFluid.getFluid()); - if (tData == null || tData.fluid.amount > aFluid.amount) return null; - if (aRemoveFluidDirectly) aFluid.amount -= tData.fluid.amount; - return copyAmount(1, tData.filledContainer); - } - - public static ItemStack getFluidDisplayStack(Fluid aFluid) { - return aFluid == null ? null : getFluidDisplayStack(new FluidStack(aFluid, 0), false); - } - - public static ItemStack getFluidDisplayStack(FluidStack aFluid, boolean aUseStackSize) { - if (aFluid == null || aFluid.getFluid() == null) return null; - int tmp = 0; - try { - tmp = aFluid.getFluid().getID(); - } catch (Exception e) { - System.err.println(e); - } - ItemStack rStack = ItemList.Display_Fluid.getWithDamage(aUseStackSize ? aFluid.amount / 1000 : 1, tmp); - NBTTagCompound tNBT = new NBTTagCompound(); - tNBT.setLong("mFluidDisplayAmount", aFluid.amount); - tNBT.setLong("mFluidDisplayHeat", aFluid.getFluid().getTemperature(aFluid)); - tNBT.setBoolean("mFluidState", aFluid.getFluid().isGaseous(aFluid)); - rStack.setTagCompound(tNBT); - return rStack; - } - - public static boolean containsFluid(ItemStack aStack, FluidStack aFluid, boolean aCheckIFluidContainerItems) { - if (isStackInvalid(aStack) || aFluid == null) return false; - if (aCheckIFluidContainerItems && aStack.getItem() instanceof IFluidContainerItem && ((IFluidContainerItem) aStack.getItem()).getCapacity(aStack) > 0) - return aFluid.isFluidEqual(((IFluidContainerItem) aStack.getItem()).getFluid(aStack = copyAmount(1, aStack))); - FluidContainerData tData = sFilledContainerToData.get(new GT_ItemStack(aStack)); - return tData == null ? false : tData.fluid.isFluidEqual(aFluid); - } - - public static FluidStack getFluidForFilledItem(ItemStack aStack, boolean aCheckIFluidContainerItems) { - if (isStackInvalid(aStack)) return null; - if (aCheckIFluidContainerItems && aStack.getItem() instanceof IFluidContainerItem && ((IFluidContainerItem) aStack.getItem()).getCapacity(aStack) > 0) - return ((IFluidContainerItem) aStack.getItem()).drain(copyAmount(1, aStack), Integer.MAX_VALUE, true); - FluidContainerData tData = sFilledContainerToData.get(new GT_ItemStack(aStack)); - return tData == null ? null : tData.fluid.copy(); - } - - public static ItemStack getContainerForFilledItem(ItemStack aStack, boolean aCheckIFluidContainerItems) { - if (isStackInvalid(aStack)) return null; - FluidContainerData tData = sFilledContainerToData.get(new GT_ItemStack(aStack)); - if (tData != null) return copyAmount(1, tData.emptyContainer); - if (aCheckIFluidContainerItems && aStack.getItem() instanceof IFluidContainerItem && ((IFluidContainerItem) aStack.getItem()).getCapacity(aStack) > 0) { - ((IFluidContainerItem) aStack.getItem()).drain(aStack = copyAmount(1, aStack), Integer.MAX_VALUE, true); - return aStack; - } - return null; - } - - public static ItemStack getContainerItem(ItemStack aStack, boolean aCheckIFluidContainerItems) { - if (isStackInvalid(aStack)) return null; - if (aStack.getItem().hasContainerItem(aStack)) return aStack.getItem().getContainerItem(aStack); - /** These are all special Cases, in which it is intended to have only GT Blocks outputting those Container Items */ - if (ItemList.Cell_Empty.isStackEqual(aStack, false, true)) return null; - if (ItemList.IC2_Fuel_Can_Filled.isStackEqual(aStack, false, true)) return ItemList.IC2_Fuel_Can_Empty.get(1); - if (aStack.getItem() == Items.potionitem || aStack.getItem() == Items.experience_bottle || ItemList.TF_Vial_FieryBlood.isStackEqual(aStack) || ItemList.TF_Vial_FieryTears.isStackEqual(aStack)) - return ItemList.Bottle_Empty.get(1); - - if (aCheckIFluidContainerItems && aStack.getItem() instanceof IFluidContainerItem && ((IFluidContainerItem) aStack.getItem()).getCapacity(aStack) > 0) { - ItemStack tStack = copyAmount(1, aStack); - ((IFluidContainerItem) aStack.getItem()).drain(tStack, Integer.MAX_VALUE, true); - if (!areStacksEqual(aStack, tStack)) return tStack; - return null; - } - - int tCapsuleCount = GT_ModHandler.getCapsuleCellContainerCount(aStack); - if (tCapsuleCount > 0) return ItemList.Cell_Empty.get(tCapsuleCount); - - if (ItemList.IC2_ForgeHammer.isStackEqual(aStack) || ItemList.IC2_WireCutter.isStackEqual(aStack)) - return copyMetaData(Items.feather.getDamage(aStack) + 1, aStack); - return null; - } - - public static synchronized boolean removeIC2BottleRecipe(ItemStack aContainer, ItemStack aInput, Map aRecipeList, ItemStack aOutput){ - if ((isStackInvalid(aInput) && isStackInvalid(aOutput) && isStackInvalid(aContainer)) || aRecipeList == null) return false; - boolean rReturn = false; - Iterator> tIterator = aRecipeList.entrySet().iterator(); - aOutput = GT_OreDictUnificator.get(aOutput); - while (tIterator.hasNext()) { - Map.Entry tEntry = tIterator.next(); - if (aInput == null || tEntry.getKey().matches(aContainer, aInput)) { - List tList = tEntry.getValue().items; - if (tList != null) for (ItemStack tOutput : tList) - if (aOutput == null || areStacksEqual(GT_OreDictUnificator.get(tOutput), aOutput)) { - tIterator.remove(); - rReturn = true; - break; - } - } - } - return rReturn; - } - - public static synchronized boolean removeSimpleIC2MachineRecipe(ItemStack aInput, Map aRecipeList, ItemStack aOutput) { - if ((isStackInvalid(aInput) && isStackInvalid(aOutput)) || aRecipeList == null) return false; - boolean rReturn = false; - Iterator> tIterator = aRecipeList.entrySet().iterator(); - aOutput = GT_OreDictUnificator.get(aOutput); - while (tIterator.hasNext()) { - Map.Entry tEntry = tIterator.next(); - if (aInput == null || tEntry.getKey().matches(aInput)) { - List tList = tEntry.getValue().items; - if (tList != null) for (ItemStack tOutput : tList) - if (aOutput == null || areStacksEqual(GT_OreDictUnificator.get(tOutput), aOutput)) { - tIterator.remove(); - rReturn = true; - break; - } - } - } - return rReturn; - } - - public static boolean addSimpleIC2MachineRecipe(ItemStack aInput, Map aRecipeList, NBTTagCompound aNBT, Object... aOutput) { - if (isStackInvalid(aInput) || aOutput.length == 0 || aRecipeList == null) return false; - ItemData tOreName = GT_OreDictUnificator.getAssociation(aInput); - for (int i = 0; i < aOutput.length; i++) { - if (aOutput[i] == null) { - GT_FML_LOGGER.info("EmptyIC2Output!" + aInput.getUnlocalizedName()); - return false; - } - } - ItemStack[] tStack = GT_OreDictUnificator.getStackArray(true, aOutput); - if(tStack==null||(tStack.length>0&>_Utility.areStacksEqual(aInput, tStack[0])))return false; - if (tOreName != null) { - if(tOreName.toString().equals("dustAsh")&&tStack[0].getUnlocalizedName().equals("tile.volcanicAsh"))return false; - aRecipeList.put(new RecipeInputOreDict(tOreName.toString(), aInput.stackSize), new RecipeOutput(aNBT, tStack)); - } else { - aRecipeList.put(new RecipeInputItemStack(copy(aInput), aInput.stackSize), new RecipeOutput(aNBT, tStack)); - } - return true; - } - - public static ItemStack getWrittenBook(String aMapping, ItemStack aStackToPutNBT) { - if (isStringInvalid(aMapping)) return null; - ItemStack rStack = GregTech_API.sBookList.get(aMapping); - if (rStack == null) return aStackToPutNBT; - if (aStackToPutNBT != null) { - aStackToPutNBT.setTagCompound(rStack.getTagCompound()); - return aStackToPutNBT; - } - return copyAmount(1, rStack); - } - - public static ItemStack getWrittenBook(String aMapping, String aTitle, String aAuthor, String... aPages) { - if (isStringInvalid(aMapping)) return null; - ItemStack rStack = GregTech_API.sBookList.get(aMapping); - if (rStack != null) return copyAmount(1, rStack); - if (isStringInvalid(aTitle) || isStringInvalid(aAuthor) || aPages.length <= 0) return null; - sBookCount++; - rStack = new ItemStack(Items.written_book, 1); - NBTTagCompound tNBT = new NBTTagCompound(); - tNBT.setString("title", GT_LanguageManager.addStringLocalization("Book." + aTitle + ".Name", aTitle)); - tNBT.setString("author", aAuthor); - NBTTagList tNBTList = new NBTTagList(); - for (byte i = 0; i < aPages.length; i++) { - aPages[i] = GT_LanguageManager.addStringLocalization("Book." + aTitle + ".Page" + ((i < 10) ? "0" + i : i), aPages[i]); - if (i < 48) { - if (aPages[i].length() < 256) - tNBTList.appendTag(new NBTTagString(aPages[i])); - else - GT_Log.err.println("WARNING: String for written Book too long! -> " + aPages[i]); - } else { - GT_Log.err.println("WARNING: Too much Pages for written Book! -> " + aTitle); - break; - } - } - tNBTList.appendTag(new NBTTagString("Credits to " + aAuthor + " for writing this Book. This was Book Nr. " + sBookCount + " at its creation. Gotta get 'em all!")); - tNBT.setTag("pages", tNBTList); - rStack.setTagCompound(tNBT); - GT_Log.out.println("GT_Mod: Added Book to Book List - Mapping: '" + aMapping + "' - Name: '" + aTitle + "' - Author: '" + aAuthor + "'"); - GregTech_API.sBookList.put(aMapping, rStack); - return copy(rStack); - } - - public static boolean doSoundAtClient(String aSoundName, int aTimeUntilNextSound, float aSoundStrength) { - return doSoundAtClient(aSoundName, aTimeUntilNextSound, aSoundStrength, GT.getThePlayer()); - } - - public static boolean doSoundAtClient(String aSoundName, int aTimeUntilNextSound, float aSoundStrength, Entity aEntity) { - if (aEntity == null) return false; - return doSoundAtClient(aSoundName, aTimeUntilNextSound, aSoundStrength, aEntity.posX, aEntity.posY, aEntity.posZ); - } - - public static boolean doSoundAtClient(String aSoundName, int aTimeUntilNextSound, float aSoundStrength, double aX, double aY, double aZ) { - return doSoundAtClient(aSoundName, aTimeUntilNextSound, aSoundStrength, 1.01818028F, aX, aY, aZ); - } - - public static boolean doSoundAtClient(String aSoundName, int aTimeUntilNextSound, float aSoundStrength, float aSoundModulation, double aX, double aY, double aZ) { - if (isStringInvalid(aSoundName) || !FMLCommonHandler.instance().getEffectiveSide().isClient() || GT.getThePlayer() == null || !GT.getThePlayer().worldObj.isRemote) - return false; - if (GregTech_API.sMultiThreadedSounds) - new Thread(new GT_Runnable_Sound(GT.getThePlayer().worldObj, MathHelper.floor_double(aX), MathHelper.floor_double(aY), MathHelper.floor_double(aZ), aTimeUntilNextSound, aSoundName, aSoundStrength, aSoundModulation), "Sound Effect").start(); - else - new GT_Runnable_Sound(GT.getThePlayer().worldObj, MathHelper.floor_double(aX), MathHelper.floor_double(aY), MathHelper.floor_double(aZ), aTimeUntilNextSound, aSoundName, aSoundStrength, aSoundModulation).run(); - return true; - } - - public static boolean sendSoundToPlayers(World aWorld, String aSoundName, float aSoundStrength, float aSoundModulation, int aX, int aY, int aZ) { - if (isStringInvalid(aSoundName) || aWorld == null || aWorld.isRemote) return false; - NW.sendPacketToAllPlayersInRange(aWorld, new GT_Packet_Sound(aSoundName, aSoundStrength, aSoundModulation, aX, (short) aY, aZ), aX, aZ); - return true; - } - - public static int stackToInt(ItemStack aStack) { - if (isStackInvalid(aStack)) return 0; - return Item.getIdFromItem(aStack.getItem()) | (Items.feather.getDamage(aStack) << 16); - } - - public static int stackToWildcard(ItemStack aStack) { - if (isStackInvalid(aStack)) return 0; - return Item.getIdFromItem(aStack.getItem()) | (W << 16); - } - - public static ItemStack intToStack(int aStack) { - int tID = aStack & (~0 >>> 16), tMeta = aStack >>> 16; - Item tItem = Item.getItemById(tID); - if (tItem != null) return new ItemStack(tItem, 1, tMeta); - return null; - } - - public static Integer[] stacksToIntegerArray(ItemStack... aStacks) { - Integer[] rArray = new Integer[aStacks.length]; - for (int i = 0; i < rArray.length; i++) { - rArray[i] = stackToInt(aStacks[i]); - } - return rArray; - } - - public static int[] stacksToIntArray(ItemStack... aStacks) { - int[] rArray = new int[aStacks.length]; - for (int i = 0; i < rArray.length; i++) { - rArray[i] = stackToInt(aStacks[i]); - } - return rArray; - } - - public static boolean arrayContains(Object aObject, Object... aObjects) { - return listContains(aObject, Arrays.asList(aObjects)); - } - - public static boolean listContains(Object aObject, Collection aObjects) { - if (aObjects == null) return false; - return aObjects.contains(aObject); - } - - public static boolean arrayContainsNonNull(T... aArray) { - if (aArray != null) for (Object tObject : aArray) if (tObject != null) return true; - return false; - } - - public static ArrayList getArrayListWithoutNulls(T... aArray) { - if (aArray == null) return new ArrayList(); - ArrayList rList = new ArrayList(Arrays.asList(aArray)); - for (int i = 0; i < rList.size(); i++) if (rList.get(i) == null) rList.remove(i--); - return rList; - } - - public static ArrayList getArrayListWithoutTrailingNulls(T... aArray) { - if (aArray == null) return new ArrayList(); - ArrayList rList = new ArrayList(Arrays.asList(aArray)); - for (int i = rList.size() - 1; i >= 0 && rList.get(i) == null; ) rList.remove(i--); - return rList; - } - - public static Block getBlock(Object aBlock) { - return (Block) aBlock; - } - - public static Block getBlockFromStack(ItemStack itemStack) { - if (isStackInvalid(itemStack)) return Blocks.air; - return getBlockFromItem(itemStack.getItem()); - } - - public static Block getBlockFromItem(Item item) { - return Block.getBlockFromItem(item); - } - - public static boolean isBlockValid(Object aBlock) { - return (aBlock instanceof Block); - } - - public static boolean isBlockInvalid(Object aBlock) { - return aBlock == null || !(aBlock instanceof Block); - } - - public static boolean isStringValid(Object aString) { - return aString != null && !aString.toString().isEmpty(); - } - - public static boolean isStringInvalid(Object aString) { - return aString == null || aString.toString().isEmpty(); - } - - public static boolean isStackValid(Object aStack) { - return (aStack instanceof ItemStack) && ((ItemStack) aStack).getItem() != null && ((ItemStack) aStack).stackSize >= 0; - } - - public static boolean isStackInvalid(Object aStack) { - return aStack == null || !(aStack instanceof ItemStack) || ((ItemStack) aStack).getItem() == null || ((ItemStack) aStack).stackSize < 0; - } - - public static boolean isDebugItem(ItemStack aStack) { - return /*ItemList.Armor_Cheat.isStackEqual(aStack, T, T) || */areStacksEqual(GT_ModHandler.getIC2Item("debug", 1), aStack, true); - } - - public static ItemStack updateItemStack(ItemStack aStack) { - if (isStackValid(aStack) && aStack.getItem() instanceof GT_Generic_Item) - ((GT_Generic_Item) aStack.getItem()).isItemStackUsable(aStack); - return aStack; - } - - public static boolean isOpaqueBlock(World aWorld, int aX, int aY, int aZ) { - return aWorld.getBlock(aX, aY, aZ).isOpaqueCube(); - } - - public static boolean isBlockAir(World aWorld, int aX, int aY, int aZ) { - return aWorld.getBlock(aX, aY, aZ).isAir(aWorld, aX, aY, aZ); - } - - public static boolean hasBlockHitBox(World aWorld, int aX, int aY, int aZ) { - return aWorld.getBlock(aX, aY, aZ).getCollisionBoundingBoxFromPool(aWorld, aX, aY, aZ) != null; - } - - public static void setCoordsOnFire(World aWorld, int aX, int aY, int aZ, boolean aReplaceCenter) { - if (aReplaceCenter) - if (aWorld.getBlock(aX, aY, aZ).getCollisionBoundingBoxFromPool(aWorld, aX, aY, aZ) == null) - aWorld.setBlock(aX, aY, aZ, Blocks.fire); - if (aWorld.getBlock(aX + 1, aY, aZ).getCollisionBoundingBoxFromPool(aWorld, aX + 1, aY, aZ) == null) - aWorld.setBlock(aX + 1, aY, aZ, Blocks.fire); - if (aWorld.getBlock(aX - 1, aY, aZ).getCollisionBoundingBoxFromPool(aWorld, aX - 1, aY, aZ) == null) - aWorld.setBlock(aX - 1, aY, aZ, Blocks.fire); - if (aWorld.getBlock(aX, aY + 1, aZ).getCollisionBoundingBoxFromPool(aWorld, aX, aY + 1, aZ) == null) - aWorld.setBlock(aX, aY + 1, aZ, Blocks.fire); - if (aWorld.getBlock(aX, aY - 1, aZ).getCollisionBoundingBoxFromPool(aWorld, aX, aY - 1, aZ) == null) - aWorld.setBlock(aX, aY - 1, aZ, Blocks.fire); - if (aWorld.getBlock(aX, aY, aZ + 1).getCollisionBoundingBoxFromPool(aWorld, aX, aY, aZ + 1) == null) - aWorld.setBlock(aX, aY, aZ + 1, Blocks.fire); - if (aWorld.getBlock(aX, aY, aZ - 1).getCollisionBoundingBoxFromPool(aWorld, aX, aY, aZ - 1) == null) - aWorld.setBlock(aX, aY, aZ - 1, Blocks.fire); - } - - public static ItemStack getProjectile(SubTag aProjectileType, IInventory aInventory) { - if (aInventory != null) for (int i = 0, j = aInventory.getSizeInventory(); i < j; i++) { - ItemStack rStack = aInventory.getStackInSlot(i); - if (isStackValid(rStack) && rStack.getItem() instanceof IProjectileItem && ((IProjectileItem) rStack.getItem()).hasProjectile(aProjectileType, rStack)) - return updateItemStack(rStack); - } - return null; - } - - public static void removeNullStacksFromInventory(IInventory aInventory) { - if (aInventory != null) for (int i = 0, j = aInventory.getSizeInventory(); i < j; i++) { - ItemStack tStack = aInventory.getStackInSlot(i); - if (tStack != null && (tStack.stackSize == 0 || tStack.getItem() == null)) - aInventory.setInventorySlotContents(i, null); - } - } - - /** - * Initializes a new texture page. - */ - public static boolean addTexturePage(byte page){ - if(Textures.BlockIcons.casingTexturePages[page]==null){ - Textures.BlockIcons.casingTexturePages[page]=new ITexture[128]; - return true; - } - return false; - } - - /** - * Converts a Number to a String - */ - public static String parseNumberToString(int aNumber) { - boolean temp = true, negative = false; - - if (aNumber < 0) { - aNumber *= -1; - negative = true; - } - - StringBuilder tStringB = new StringBuilder(); - for (int i = 1000000000; i > 0; i /= 10) { - int tDigit = (aNumber / i) % 10; - if (temp && tDigit != 0) temp = false; - if (!temp) { - tStringB.append(tDigit); - if (i != 1) for (int j = i; j > 0; j /= 1000) if (j == 1) tStringB.append(","); - } - } - - String tString = tStringB.toString(); - - if (tString.equals(E)) tString = "0"; - - return negative ? "-" + tString : tString; - } - - public static NBTTagCompound getNBTContainingBoolean(NBTTagCompound aNBT, Object aTag, boolean aValue) { - if (aNBT == null) aNBT = new NBTTagCompound(); - aNBT.setBoolean(aTag.toString(), aValue); - return aNBT; - } - - public static NBTTagCompound getNBTContainingByte(NBTTagCompound aNBT, Object aTag, byte aValue) { - if (aNBT == null) aNBT = new NBTTagCompound(); - aNBT.setByte(aTag.toString(), aValue); - return aNBT; - } - - public static NBTTagCompound getNBTContainingShort(NBTTagCompound aNBT, Object aTag, short aValue) { - if (aNBT == null) aNBT = new NBTTagCompound(); - aNBT.setShort(aTag.toString(), aValue); - return aNBT; - } - - public static NBTTagCompound getNBTContainingInteger(NBTTagCompound aNBT, Object aTag, int aValue) { - if (aNBT == null) aNBT = new NBTTagCompound(); - aNBT.setInteger(aTag.toString(), aValue); - return aNBT; - } - - public static NBTTagCompound getNBTContainingFloat(NBTTagCompound aNBT, Object aTag, float aValue) { - if (aNBT == null) aNBT = new NBTTagCompound(); - aNBT.setFloat(aTag.toString(), aValue); - return aNBT; - } - - public static NBTTagCompound getNBTContainingDouble(NBTTagCompound aNBT, Object aTag, double aValue) { - if (aNBT == null) aNBT = new NBTTagCompound(); - aNBT.setDouble(aTag.toString(), aValue); - return aNBT; - } - - public static NBTTagCompound getNBTContainingString(NBTTagCompound aNBT, Object aTag, Object aValue) { - if (aNBT == null) aNBT = new NBTTagCompound(); - if (aValue == null) return aNBT; - aNBT.setString(aTag.toString(), aValue.toString()); - return aNBT; - } - - public static boolean isWearingFullFrostHazmat(EntityLivingBase aEntity) { - for (byte i = 1; i < 5; i++) - if (!isStackInList(aEntity.getEquipmentInSlot(i), GregTech_API.sFrostHazmatList)) return false; - return true; - } - - public static boolean isWearingFullHeatHazmat(EntityLivingBase aEntity) { - for (byte i = 1; i < 5; i++) - if (!isStackInList(aEntity.getEquipmentInSlot(i), GregTech_API.sHeatHazmatList)) return false; - return true; - } - - public static boolean isWearingFullBioHazmat(EntityLivingBase aEntity) { - for (byte i = 1; i < 5; i++) - if (!isStackInList(aEntity.getEquipmentInSlot(i), GregTech_API.sBioHazmatList)) return false; - return true; - } - - public static boolean isWearingFullRadioHazmat(EntityLivingBase aEntity) { - for (byte i = 1; i < 5; i++) - if (!isStackInList(aEntity.getEquipmentInSlot(i), GregTech_API.sRadioHazmatList)) return false; - return true; - } - - public static boolean isWearingFullElectroHazmat(EntityLivingBase aEntity) { - for (byte i = 1; i < 5; i++) - if (!isStackInList(aEntity.getEquipmentInSlot(i), GregTech_API.sElectroHazmatList)) return false; - return true; - } - - public static boolean isWearingFullGasHazmat(EntityLivingBase aEntity) { - for (byte i = 1; i < 5; i++) - if (!isStackInList(aEntity.getEquipmentInSlot(i), GregTech_API.sGasHazmatList)) return false; - return true; - } - - public static float getHeatDamageFromItem(ItemStack aStack) { - ItemData tData = GT_OreDictUnificator.getItemData(aStack); - return tData == null ? 0 : (tData.mPrefix == null ? 0 : tData.mPrefix.mHeatDamage) + (tData.hasValidMaterialData() ? tData.mMaterial.mMaterial.mHeatDamage : 0); - } - - public static int getRadioactivityLevel(ItemStack aStack) { - ItemData tData = GT_OreDictUnificator.getItemData(aStack); - if (tData != null && tData.hasValidMaterialData()) { - if (tData.mMaterial.mMaterial.mEnchantmentArmors instanceof Enchantment_Radioactivity) - return tData.mMaterial.mMaterial.mEnchantmentArmorsLevel; - if (tData.mMaterial.mMaterial.mEnchantmentTools instanceof Enchantment_Radioactivity) - return tData.mMaterial.mMaterial.mEnchantmentToolsLevel; - } - return EnchantmentHelper.getEnchantmentLevel(Enchantment_Radioactivity.INSTANCE.effectId, aStack); - } - - public static boolean isImmuneToBreathingGasses(EntityLivingBase aEntity) { - return isWearingFullGasHazmat(aEntity); - } - - public static boolean applyHeatDamage(EntityLivingBase aEntity, float aDamage) { - if (aDamage > 0 && aEntity != null && aEntity.getActivePotionEffect(Potion.fireResistance) == null && !isWearingFullHeatHazmat(aEntity)) { - aEntity.attackEntityFrom(GT_DamageSources.getHeatDamage(), aDamage); - return true; - } - return false; - } - - public static boolean applyFrostDamage(EntityLivingBase aEntity, float aDamage) { - if (aDamage > 0 && aEntity != null && !isWearingFullFrostHazmat(aEntity)) { - aEntity.attackEntityFrom(GT_DamageSources.getFrostDamage(), aDamage); - return true; - } - return false; - } - - public static boolean applyElectricityDamage(EntityLivingBase aEntity, long aVoltage, long aAmperage) { - long aDamage = getTier(aVoltage) * aAmperage * 4; - if (aDamage > 0 && aEntity != null && !isWearingFullElectroHazmat(aEntity)) { - aEntity.attackEntityFrom(GT_DamageSources.getElectricDamage(), aDamage); - return true; - } - return false; - } - - public static boolean applyRadioactivity(EntityLivingBase aEntity, int aLevel, int aAmountOfItems) { - if (aLevel > 0 && aEntity != null && aEntity.getCreatureAttribute() != EnumCreatureAttribute.UNDEAD && aEntity.getCreatureAttribute() != EnumCreatureAttribute.ARTHROPOD && !isWearingFullRadioHazmat(aEntity)) { - PotionEffect tEffect = null; - aEntity.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, aLevel * 140 * aAmountOfItems + Math.max(0, ((tEffect = aEntity.getActivePotionEffect(Potion.moveSlowdown)) == null ? 0 : tEffect.getDuration())), Math.max(0, (5 * aLevel) / 7))); - aEntity.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, aLevel * 150 * aAmountOfItems + Math.max(0, ((tEffect = aEntity.getActivePotionEffect(Potion.digSlowdown)) == null ? 0 : tEffect.getDuration())), Math.max(0, (5 * aLevel) / 7))); - aEntity.addPotionEffect(new PotionEffect(Potion.confusion.id, aLevel * 130 * aAmountOfItems + Math.max(0, ((tEffect = aEntity.getActivePotionEffect(Potion.confusion)) == null ? 0 : tEffect.getDuration())), Math.max(0, (5 * aLevel) / 7))); - aEntity.addPotionEffect(new PotionEffect(Potion.weakness.id, aLevel * 150 * aAmountOfItems + Math.max(0, ((tEffect = aEntity.getActivePotionEffect(Potion.weakness)) == null ? 0 : tEffect.getDuration())), Math.max(0, (5 * aLevel) / 7))); - aEntity.addPotionEffect(new PotionEffect(Potion.hunger.id, aLevel * 130 * aAmountOfItems + Math.max(0, ((tEffect = aEntity.getActivePotionEffect(Potion.hunger)) == null ? 0 : tEffect.getDuration())), Math.max(0, (5 * aLevel) / 7))); - aEntity.addPotionEffect(new PotionEffect(24 /* IC2 Radiation */, aLevel * 180 * aAmountOfItems + Math.max(0, ((tEffect = aEntity.getActivePotionEffect(Potion.potionTypes[24])) == null ? 0 : tEffect.getDuration())), Math.max(0, (5 * aLevel) / 7))); - return true; - } - return false; - } - - public static ItemStack setStack(Object aSetStack, Object aToStack) { - if (isStackInvalid(aSetStack) || isStackInvalid(aToStack)) return null; - ((ItemStack) aSetStack).func_150996_a(((ItemStack) aToStack).getItem()); - ((ItemStack) aSetStack).stackSize = ((ItemStack) aToStack).stackSize; - Items.feather.setDamage((ItemStack) aSetStack, Items.feather.getDamage((ItemStack) aToStack)); - ((ItemStack) aSetStack).setTagCompound(((ItemStack) aToStack).getTagCompound()); - return (ItemStack) aSetStack; - } - - public static FluidStack[] copyFluidArray(FluidStack... aStacks) { - FluidStack[] rStacks = new FluidStack[aStacks.length]; - for (int i = 0; i < aStacks.length; i++) if (aStacks[i] != null) rStacks[i] = aStacks[i].copy(); - return rStacks; - } - - public static ItemStack[] copyStackArray(Object... aStacks) { - ItemStack[] rStacks = new ItemStack[aStacks.length]; - for (int i = 0; i < aStacks.length; i++) rStacks[i] = copy(aStacks[i]); - return rStacks; - } - - public static ItemStack copy(Object... aStacks) { - for (Object tStack : aStacks) if (isStackValid(tStack)) return ((ItemStack) tStack).copy(); - return null; - } - - public static ItemStack copyAmount(long aAmount, Object... aStacks) { - ItemStack rStack = copy(aStacks); - if (isStackInvalid(rStack)) return null; - if (aAmount > 64) aAmount = 64; - else if (aAmount == -1) aAmount = 111; - else if (aAmount < 0) aAmount = 0; - rStack.stackSize = (byte) aAmount; - return rStack; - } - - public static ItemStack copyMetaData(long aMetaData, Object... aStacks) { - ItemStack rStack = copy(aStacks); - if (isStackInvalid(rStack)) return null; - Items.feather.setDamage(rStack, (short) aMetaData); - return rStack; - } - - public static ItemStack copyAmountAndMetaData(long aAmount, long aMetaData, Object... aStacks) { - ItemStack rStack = copyAmount(aAmount, aStacks); - if (isStackInvalid(rStack)) return null; - Items.feather.setDamage(rStack, (short) aMetaData); - return rStack; - } - - /** - * returns a copy of an ItemStack with its Stacksize being multiplied by aMultiplier - */ - public static ItemStack mul(long aMultiplier, Object... aStacks) { - ItemStack rStack = copy(aStacks); - if (rStack == null) return null; - rStack.stackSize *= aMultiplier; - return rStack; - } - - /** - * Loads an ItemStack properly. - */ - public static ItemStack loadItem(NBTTagCompound aNBT, String aTagName) { - return loadItem(aNBT.getCompoundTag(aTagName)); - } - - public static FluidStack loadFluid(NBTTagCompound aNBT, String aTagName) { - return loadFluid(aNBT.getCompoundTag(aTagName)); - } - - /** - * Loads an ItemStack properly. - */ - public static ItemStack loadItem(NBTTagCompound aNBT) { - if (aNBT == null) return null; - ItemStack rStack = ItemStack.loadItemStackFromNBT(aNBT); - try { - if (rStack != null && (rStack.getItem().getClass().getName().startsWith("ic2.core.migration"))) { - rStack.getItem().onUpdate(rStack, DW, null, 0, false); - } - } catch (Throwable e) { - e.printStackTrace(GT_Log.err); - } - return GT_OreDictUnificator.get(true, rStack); - } - - /** - * Loads an FluidStack properly. - */ - public static FluidStack loadFluid(NBTTagCompound aNBT) { - if (aNBT == null) return null; - return FluidStack.loadFluidStackFromNBT(aNBT); - } - - public static E selectItemInList(int aIndex, E aReplacement, List aList) { - if (aList == null || aList.isEmpty()) return aReplacement; - if (aList.size() <= aIndex) return aList.get(aList.size() - 1); - if (aIndex < 0) return aList.get(0); - return aList.get(aIndex); - } - - public static E selectItemInList(int aIndex, E aReplacement, E... aList) { - if (aList == null || aList.length == 0) return aReplacement; - if (aList.length <= aIndex) return aList[aList.length - 1]; - if (aIndex < 0) return aList[0]; - return aList[aIndex]; - } - - public static boolean isStackInList(ItemStack aStack, Collection aList) { - if (aStack == null) { - return false; - } - return isStackInList(new GT_ItemStack(aStack), aList); - } - - public static boolean isStackInList(GT_ItemStack aStack, Collection aList) { - return aStack != null && (aList.contains(aStack) || aList.contains(new GT_ItemStack(aStack.mItem, aStack.mStackSize, W))); - } - - /** - * re-maps all Keys of a Map after the Keys were weakened. - */ - public static Map reMap(Map aMap) { - Map tMap = new /*Concurrent*/HashMap(); - tMap.putAll(aMap); - aMap.clear(); - aMap.putAll(tMap); - return aMap; - } - - /** - * Why the fuck do neither Java nor Guava have a Function to do this? - */ - public static LinkedHashMap sortMapByValuesAcending(Map aMap) { - List> tEntrySet = new LinkedList>(aMap.entrySet()); - Collections.sort(tEntrySet, new Comparator>() { - @Override - public int compare(Entry aValue1, Entry aValue2) { - return aValue1.getValue().compareTo(aValue2.getValue()); - } - }); - LinkedHashMap rMap = new LinkedHashMap(); - for (Map.Entry tEntry : tEntrySet) rMap.put(tEntry.getKey(), tEntry.getValue()); - return rMap; - } - - /** - * Why the fuck do neither Java nor Guava have a Function to do this? - */ - public static LinkedHashMap sortMapByValuesDescending(Map aMap) { - List> tEntrySet = new LinkedList>(aMap.entrySet()); - Collections.sort(tEntrySet, new Comparator>() { - @Override - public int compare(Entry aValue1, Entry aValue2) { - return aValue2.getValue().compareTo(aValue1.getValue());//FB: RV - RV_NEGATING_RESULT_OF_COMPARETO - } - }); - LinkedHashMap rMap = new LinkedHashMap(); - for (Map.Entry tEntry : tEntrySet) rMap.put(tEntry.getKey(), tEntry.getValue()); - return rMap; - } - - /** - * Translates a Material Amount into an Amount of Fluid in Fluid Material Units. - */ - public static long translateMaterialToFluidAmount(long aMaterialAmount, boolean aRoundUp) { - return translateMaterialToAmount(aMaterialAmount, L, aRoundUp); - } - - /** - * Translates a Material Amount into an Amount of Fluid. Second Parameter for things like Bucket Amounts (1000) and similar - */ - public static long translateMaterialToAmount(long aMaterialAmount, long aAmountPerUnit, boolean aRoundUp) { - return Math.max(0, ((aMaterialAmount * aAmountPerUnit) / M) + (aRoundUp && (aMaterialAmount * aAmountPerUnit) % M > 0 ? 1 : 0)); - } - - /** - * This checks if the Dimension is really a Dimension and not another Planet or something. - * Used for my Teleporter. - */ - public static boolean isRealDimension(int aDimensionID) { - if(aDimensionID<=1 && aDimensionID>=-1 && !GregTech_API.sDimensionalList.contains(aDimensionID)) return true; - return !GregTech_API.sDimensionalList.contains(aDimensionID) && DimensionManager.isDimensionRegistered(aDimensionID); - } - - //public static boolean isRealDimension(int aDimensionID) { - // try { - // if (DimensionManager.getProvider(aDimensionID).getClass().getName().contains("com.xcompwiz.mystcraft")) - // return true; - // } catch (Throwable e) {/*Do nothing*/} - // try { - // if (DimensionManager.getProvider(aDimensionID).getClass().getName().contains("TwilightForest")) return true; - // } catch (Throwable e) {/*Do nothing*/} - // try { - // if (DimensionManager.getProvider(aDimensionID).getClass().getName().contains("galacticraft")) return true; - // } catch (Throwable e) {/*Do nothing*/} - // return GregTech_API.sDimensionalList.contains(aDimensionID); - //} - - public static boolean moveEntityToDimensionAtCoords(Entity entity, int aDimension, double aX, double aY, double aZ) { - //Credit goes to BrandonCore Author :!: - - if (entity == null || entity.worldObj.isRemote) return false; - if (entity.ridingEntity != null) entity.mountEntity(null); - if (entity.riddenByEntity != null) entity.riddenByEntity.mountEntity(null); - - World startWorld = entity.worldObj; - World destinationWorld = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(aDimension); - - if (destinationWorld == null) {return false;} - - boolean interDimensional = startWorld.provider.dimensionId != destinationWorld.provider.dimensionId; - if(!interDimensional)return false; - startWorld.updateEntityWithOptionalForce(entity, false);//added - - if ((entity instanceof EntityPlayerMP) && interDimensional) { - EntityPlayerMP player = (EntityPlayerMP) entity; - player.closeScreen();//added - player.dimension = aDimension; - player.playerNetServerHandler.sendPacket(new S07PacketRespawn(player.dimension, player.worldObj.difficultySetting, destinationWorld.getWorldInfo().getTerrainType(), player.theItemInWorldManager.getGameType())); - ((WorldServer) startWorld).getPlayerManager().removePlayer(player); - - startWorld.playerEntities.remove(player); - startWorld.updateAllPlayersSleepingFlag(); - int i = entity.chunkCoordX; - int j = entity.chunkCoordZ; - if ((entity.addedToChunk) && (startWorld.getChunkProvider().chunkExists(i, j))) { - startWorld.getChunkFromChunkCoords(i, j).removeEntity(entity); - startWorld.getChunkFromChunkCoords(i, j).isModified = true; - } - startWorld.loadedEntityList.remove(entity); - startWorld.onEntityRemoved(entity); - } - - entity.setLocationAndAngles(aX, aY, aZ, entity.rotationYaw, entity.rotationPitch); - - ((WorldServer) destinationWorld).theChunkProviderServer.loadChunk((int) aX >> 4, (int) aZ >> 4); - - destinationWorld.theProfiler.startSection("placing"); - if (interDimensional) { - if (!(entity instanceof EntityPlayer)) { - NBTTagCompound entityNBT = new NBTTagCompound(); - entity.isDead = false; - entityNBT.setString("id", EntityList.getEntityString(entity)); - entity.writeToNBT(entityNBT); - entity.isDead = true; - entity = EntityList.createEntityFromNBT(entityNBT, destinationWorld); - if (entity == null) { - return false; - } - entity.dimension = destinationWorld.provider.dimensionId; - } - destinationWorld.spawnEntityInWorld(entity); - entity.setWorld(destinationWorld); - } - entity.setLocationAndAngles(aX, aY, aZ, entity.rotationYaw, entity.rotationPitch); - - destinationWorld.updateEntityWithOptionalForce(entity, false); - entity.setLocationAndAngles(aX, aY, aZ, entity.rotationYaw, entity.rotationPitch); - - if ((entity instanceof EntityPlayerMP)) { - EntityPlayerMP player = (EntityPlayerMP) entity; - if (interDimensional) { - player.mcServer.getConfigurationManager().func_72375_a(player, (WorldServer) destinationWorld); - } - player.playerNetServerHandler.setPlayerLocation(aX, aY, aZ, player.rotationYaw, player.rotationPitch); - } - - destinationWorld.updateEntityWithOptionalForce(entity, false); - - if (((entity instanceof EntityPlayerMP)) && interDimensional) { - EntityPlayerMP player = (EntityPlayerMP) entity; - player.theItemInWorldManager.setWorld((WorldServer) destinationWorld); - player.mcServer.getConfigurationManager().updateTimeAndWeatherForPlayer(player, (WorldServer) destinationWorld); - player.mcServer.getConfigurationManager().syncPlayerInventory(player); - - for (PotionEffect potionEffect : (Iterable) player.getActivePotionEffects()) { - player.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(player.getEntityId(), potionEffect)); - } - - player.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel)); - FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, startWorld.provider.dimensionId, destinationWorld.provider.dimensionId); - } - entity.setLocationAndAngles(aX, aY, aZ, entity.rotationYaw, entity.rotationPitch); - - destinationWorld.theProfiler.endSection(); - entity.fallDistance = 0; - return true; - } - - public static int getScaleCoordinates(double aValue, int aScale) { - return (int)Math.floor(aValue / aScale); - } - - public static int getCoordinateScan(ArrayList aList, EntityPlayer aPlayer, World aWorld, int aScanLevel, int aX, int aY, int aZ, int aSide, float aClickX, float aClickY, float aClickZ) { - if (aList == null) return 0; - - ArrayList tList = new ArrayList(); - int rEUAmount = 0; - - TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); - - Block tBlock = aWorld.getBlock(aX, aY, aZ); - - tList.add("----- X: " +EnumChatFormatting.AQUA+ aX +EnumChatFormatting.RESET+ " Y: " +EnumChatFormatting.AQUA+ aY +EnumChatFormatting.RESET+ " Z: " +EnumChatFormatting.AQUA+ aZ +EnumChatFormatting.RESET+ " D: " +EnumChatFormatting.AQUA+ aWorld.provider.dimensionId +EnumChatFormatting.RESET+ " -----"); - try { - if (tTileEntity != null && tTileEntity instanceof IInventory) - tList.add(trans("162","Name: ") +EnumChatFormatting.BLUE+ ((IInventory) tTileEntity).getInventoryName() +EnumChatFormatting.RESET+ trans("163"," MetaData: ") +EnumChatFormatting.AQUA+ aWorld.getBlockMetadata(aX, aY, aZ) +EnumChatFormatting.RESET); - else - tList.add(trans("162","Name: ") +EnumChatFormatting.BLUE+ tBlock.getUnlocalizedName() +EnumChatFormatting.RESET+ trans("163"," MetaData: ") +EnumChatFormatting.AQUA+ aWorld.getBlockMetadata(aX, aY, aZ) +EnumChatFormatting.RESET); - - tList.add(trans("164","Hardness: ") +EnumChatFormatting.YELLOW+ tBlock.getBlockHardness(aWorld, aX, aY, aZ) +EnumChatFormatting.RESET+ trans("165"," Blast Resistance: ") +EnumChatFormatting.YELLOW+ tBlock.getExplosionResistance(aPlayer, aWorld, aX, aY, aZ, aPlayer.posX, aPlayer.posY, aPlayer.posZ) +EnumChatFormatting.RESET); - if (tBlock.isBeaconBase(aWorld, aX, aY, aZ, aX, aY + 1, aZ)) tList.add(EnumChatFormatting.GOLD+ trans("166","Is valid Beacon Pyramid Material") +EnumChatFormatting.RESET); - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - if (tTileEntity != null) { - try { - if (tTileEntity instanceof IFluidHandler) { - rEUAmount += 500; - FluidTankInfo[] tTanks = ((IFluidHandler) tTileEntity).getTankInfo(ForgeDirection.getOrientation(aSide)); - if (tTanks != null) for (byte i = 0; i < tTanks.length; i++) { - tList.add(trans("167","Tank ") + i + ": " +EnumChatFormatting.GREEN+ GT_Utility.formatNumbers((tTanks[i].fluid == null ? 0 : tTanks[i].fluid.amount)) +EnumChatFormatting.RESET+ " L / " +EnumChatFormatting.YELLOW+ GT_Utility.formatNumbers(tTanks[i].capacity) +EnumChatFormatting.RESET+ " L " +EnumChatFormatting.GOLD+ getFluidName(tTanks[i].fluid, true)+EnumChatFormatting.RESET); - } - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.reactor.IReactorChamber) { - rEUAmount += 500; - tTileEntity = (TileEntity) (((ic2.api.reactor.IReactorChamber) tTileEntity).getReactor()); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.reactor.IReactor) { - rEUAmount += 500; - tList.add(trans("168","Heat: ") +EnumChatFormatting.GREEN+ ((ic2.api.reactor.IReactor) tTileEntity).getHeat() +EnumChatFormatting.RESET+ " / " +EnumChatFormatting.YELLOW+ ((ic2.api.reactor.IReactor) tTileEntity).getMaxHeat()+EnumChatFormatting.RESET); - tList.add(trans("169","HEM: ") +EnumChatFormatting.YELLOW+((ic2.api.reactor.IReactor) tTileEntity).getHeatEffectModifier() +EnumChatFormatting.RESET/*+ trans("170"," Base EU Output: ")/* + ((ic2.api.reactor.IReactor)tTileEntity).getOutput()*/); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.tile.IWrenchable) { - rEUAmount += 100; - tList.add(trans("171","Facing: ") +EnumChatFormatting.GREEN+ ((ic2.api.tile.IWrenchable) tTileEntity).getFacing() +EnumChatFormatting.RESET+ trans("172"," / Chance: ") +EnumChatFormatting.YELLOW+ (((ic2.api.tile.IWrenchable) tTileEntity).getWrenchDropRate() * 100) +EnumChatFormatting.RESET+ "%"); - tList.add(((ic2.api.tile.IWrenchable) tTileEntity).wrenchCanRemove(aPlayer) ? EnumChatFormatting.GREEN+ trans("173","You can remove this with a Wrench") +EnumChatFormatting.RESET : EnumChatFormatting.RED+ trans("174","You can NOT remove this with a Wrench") +EnumChatFormatting.RESET); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.energy.tile.IEnergyTile) { - rEUAmount += 200; - //aList.add(((ic2.api.energy.tile.IEnergyTile)tTileEntity).isAddedToEnergyNet()?"Added to E-net":"Not added to E-net! Bug?"); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.energy.tile.IEnergySink) { - rEUAmount += 400; - //aList.add("Demanded Energy: " + ((ic2.api.energy.tile.IEnergySink)tTileEntity).demandsEnergy()); - //tList.add("Max Safe Input: " + getTier(((ic2.api.energy.tile.IEnergySink)tTileEntity).getSinkTier())); - //tList.add("Max Safe Input: " + ((ic2.api.energy.tile.IEnergySink)tTileEntity).getMaxSafeInput()); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.energy.tile.IEnergySource) { - rEUAmount += 400; - //aList.add("Max Energy Output: " + ((ic2.api.energy.tile.IEnergySource)tTileEntity).getMaxEnergyOutput()); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.energy.tile.IEnergyConductor) { - rEUAmount += 200; - tList.add(trans("175","Conduction Loss: ") +EnumChatFormatting.YELLOW+ ((ic2.api.energy.tile.IEnergyConductor) tTileEntity).getConductionLoss()+EnumChatFormatting.RESET); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.tile.IEnergyStorage) { - rEUAmount += 200; - tList.add(trans("176","Contained Energy: ") +EnumChatFormatting.YELLOW+ ((ic2.api.tile.IEnergyStorage) tTileEntity).getStored() +EnumChatFormatting.RESET+ " EU / " +EnumChatFormatting.YELLOW+ ((ic2.api.tile.IEnergyStorage) tTileEntity).getCapacity()+EnumChatFormatting.RESET+" EU"); - //aList.add(((ic2.api.tile.IEnergyStorage)tTileEntity).isTeleporterCompatible(ic2.api.Direction.YP)?"Teleporter Compatible":"Not Teleporter Compatible"); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof IUpgradableMachine) { - rEUAmount += 500; - if (((IUpgradableMachine) tTileEntity).hasMufflerUpgrade()) tList.add(EnumChatFormatting.GREEN+ trans("177","Has Muffler Upgrade") +EnumChatFormatting.RESET); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof IMachineProgress) { - rEUAmount += 400; - int tValue = 0; - if (0 < (tValue = ((IMachineProgress) tTileEntity).getMaxProgress())) - tList.add(trans("178","Progress/Load: ") +EnumChatFormatting.GREEN+GT_Utility.formatNumbers(((IMachineProgress) tTileEntity).getProgress()) +EnumChatFormatting.RESET+ " / " +EnumChatFormatting.YELLOW+GT_Utility.formatNumbers(tValue) +EnumChatFormatting.RESET); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ICoverable) { - rEUAmount += 300; - String tString = ((ICoverable) tTileEntity).getCoverBehaviorAtSide((byte) aSide).getDescription((byte) aSide, ((ICoverable) tTileEntity).getCoverIDAtSide((byte) aSide), ((ICoverable) tTileEntity).getCoverDataAtSide((byte) aSide), (ICoverable) tTileEntity); - if (tString != null && !tString.equals(E)) tList.add(tString); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof IBasicEnergyContainer && ((IBasicEnergyContainer) tTileEntity).getEUCapacity() > 0) { - tList.add(trans("179","Max IN: ") +EnumChatFormatting.RED+ ((IBasicEnergyContainer) tTileEntity).getInputVoltage() + " (" + GT_Values.VN[GT_Utility.getTier(((IBasicEnergyContainer) tTileEntity).getInputVoltage())] + ") " +EnumChatFormatting.RESET+ trans("182"," EU at ") +EnumChatFormatting.RED+((IBasicEnergyContainer)tTileEntity).getInputAmperage()+EnumChatFormatting.RESET+trans("183"," A")); - tList.add(trans("181","Max OUT: ") +EnumChatFormatting.RED+ ((IBasicEnergyContainer) tTileEntity).getOutputVoltage() + " (" + GT_Values.VN[GT_Utility.getTier(((IBasicEnergyContainer) tTileEntity).getOutputVoltage())] + ") " +EnumChatFormatting.RESET+ trans("182"," EU at ") +EnumChatFormatting.RED+ ((IBasicEnergyContainer) tTileEntity).getOutputAmperage() +EnumChatFormatting.RESET+ trans("183"," A")); - tList.add(trans("184","Energy: ") +EnumChatFormatting.GREEN+ GT_Utility.formatNumbers(((IBasicEnergyContainer) tTileEntity).getStoredEU()) +EnumChatFormatting.RESET+ " EU / " +EnumChatFormatting.YELLOW+ GT_Utility.formatNumbers(((IBasicEnergyContainer) tTileEntity).getEUCapacity()) +EnumChatFormatting.RESET+ " EU"); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof IGregTechTileEntity) { - tList.add(trans("186","Owned by: ") +EnumChatFormatting.BLUE+ ((IGregTechTileEntity) tTileEntity).getOwnerName()+EnumChatFormatting.RESET); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof IGregTechDeviceInformation && ((IGregTechDeviceInformation) tTileEntity).isGivingInformation()) { - tList.addAll(Arrays.asList(((IGregTechDeviceInformation) tTileEntity).getInfoData())); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.crops.ICropTile) { - if (((ic2.api.crops.ICropTile) tTileEntity).getScanLevel() < 4) { - rEUAmount += 10000; - ((ic2.api.crops.ICropTile) tTileEntity).setScanLevel((byte) 4); - } - if (((ic2.api.crops.ICropTile) tTileEntity).getID() >= 0 && ((ic2.api.crops.ICropTile) tTileEntity).getID() < ic2.api.crops.Crops.instance.getCropList().length && ic2.api.crops.Crops.instance.getCropList()[((ic2.api.crops.ICropTile) tTileEntity).getID()] != null) { - rEUAmount += 1000; - tList.add(trans("187","Type -- Crop-Name: ") + ic2.api.crops.Crops.instance.getCropList()[((ic2.api.crops.ICropTile) tTileEntity).getID()].name() - + trans("188"," Growth: ") + ((ic2.api.crops.ICropTile) tTileEntity).getGrowth() - + trans("189"," Gain: ") + ((ic2.api.crops.ICropTile) tTileEntity).getGain() - + trans("190"," Resistance: ") + ((ic2.api.crops.ICropTile) tTileEntity).getResistance() - ); - tList.add(trans("191","Plant -- Fertilizer: ") + ((ic2.api.crops.ICropTile) tTileEntity).getNutrientStorage() - + trans("192"," Water: ") + ((ic2.api.crops.ICropTile) tTileEntity).getHydrationStorage() - + trans("193"," Weed-Ex: ") + ((ic2.api.crops.ICropTile) tTileEntity).getWeedExStorage() - + trans("194"," Scan-Level: ") + ((ic2.api.crops.ICropTile) tTileEntity).getScanLevel() - ); - tList.add(trans("195","Environment -- Nutrients: ") + ((ic2.api.crops.ICropTile) tTileEntity).getNutrients() - + trans("196"," Humidity: ") + ((ic2.api.crops.ICropTile) tTileEntity).getHumidity() - + trans("197"," Air-Quality: ") + ((ic2.api.crops.ICropTile) tTileEntity).getAirQuality() - ); - StringBuilder tStringB = new StringBuilder(); - for (String tAttribute : ic2.api.crops.Crops.instance.getCropList()[((ic2.api.crops.ICropTile) tTileEntity).getID()].attributes()) { - tStringB.append(", ").append(tAttribute); - } - String tString = tStringB.toString(); - tList.add(trans("198","Attributes:") + tString.replaceFirst(",", E)); - tList.add(trans("199","Discovered by: ") + ic2.api.crops.Crops.instance.getCropList()[((ic2.api.crops.ICropTile) tTileEntity).getID()].discoveredBy()); - } - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - } - - if (aPlayer.capabilities.isCreativeMode) { - FluidStack tFluid = undergroundOilReadInformation(aWorld.getChunkFromBlockCoords(aX,aZ));//-# to only read - if (tFluid!=null) - tList.add(EnumChatFormatting.GOLD+tFluid.getLocalizedName()+EnumChatFormatting.RESET+": " +EnumChatFormatting.YELLOW+ tFluid.amount +EnumChatFormatting.RESET+" L"); - else - tList.add(EnumChatFormatting.GOLD+trans("201","Nothing")+EnumChatFormatting.RESET+": " +EnumChatFormatting.YELLOW+ '0' +EnumChatFormatting.RESET+" L"); - } -// if(aPlayer.capabilities.isCreativeMode){ - int[] chunkData = GT_Proxy.dimensionWiseChunkData.get(aWorld.provider.dimensionId).get(aWorld.getChunkFromBlockCoords(aX,aZ).getChunkCoordIntPair()); - if(chunkData !=null){ - if(chunkData[GTPOLLUTION]>0){ - tList.add(trans("202","Pollution in Chunk: ")+EnumChatFormatting.RED+chunkData[GTPOLLUTION]+EnumChatFormatting.RESET+trans("203"," gibbl")); - }else{ - tList.add(EnumChatFormatting.GREEN+trans("204","No Pollution in Chunk! HAYO!")+EnumChatFormatting.RESET); - } - }else{ - tList.add(EnumChatFormatting.GREEN+trans("204","No Pollution in Chunk! HAYO!")+EnumChatFormatting.RESET); - } - - try { - if (tBlock instanceof IDebugableBlock) { - rEUAmount += 500; - ArrayList temp = ((IDebugableBlock) tBlock).getDebugInfo(aPlayer, aX, aY, aZ, 3); - if (temp != null) tList.addAll(temp); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - - BlockScanningEvent tEvent = new BlockScanningEvent(aWorld, aPlayer, aX, aY, aZ, (byte) aSide, aScanLevel, tBlock, tTileEntity, tList, aClickX, aClickY, aClickZ); - tEvent.mEUCost = rEUAmount; - MinecraftForge.EVENT_BUS.post(tEvent); - if (!tEvent.isCanceled()) aList.addAll(tList); - return tEvent.mEUCost; - } - - public static String trans(String aKey, String aEnglish){ - return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_"+aKey, aEnglish, false); - } - - /** - * @return an Array containing the X and the Y Coordinate of the clicked Point, with the top left Corner as Origin, like on the Texture Sheet. return values should always be between [0.0F and 0.99F]. - */ - public static float[] getClickedFacingCoords(byte aSide, float aX, float aY, float aZ) { - switch (aSide) { - case 0: - return new float[]{Math.min(0.99F, Math.max(0, 1 - aX)), Math.min(0.99F, Math.max(0, aZ))}; - case 1: - return new float[]{Math.min(0.99F, Math.max(0, aX)), Math.min(0.99F, Math.max(0, aZ))}; - case 2: - return new float[]{Math.min(0.99F, Math.max(0, 1 - aX)), Math.min(0.99F, Math.max(0, 1 - aY))}; - case 3: - return new float[]{Math.min(0.99F, Math.max(0, aX)), Math.min(0.99F, Math.max(0, 1 - aY))}; - case 4: - return new float[]{Math.min(0.99F, Math.max(0, aZ)), Math.min(0.99F, Math.max(0, 1 - aY))}; - case 5: - return new float[]{Math.min(0.99F, Math.max(0, 1 - aZ)), Math.min(0.99F, Math.max(0, 1 - aY))}; - default: - return new float[]{0.5F, 0.5F}; - } - } - - /** - * This Function determines the direction a Block gets when being Wrenched. - * returns -1 if invalid. Even though that could never happen. - */ - public static byte determineWrenchingSide(byte aSide, float aX, float aY, float aZ) { - byte tBack = getOppositeSide(aSide); - switch (aSide) { - case 0: - case 1: - if (aX < 0.25) { - if (aZ < 0.25) return tBack; - if (aZ > 0.75) return tBack; - return 4; - } - if (aX > 0.75) { - if (aZ < 0.25) return tBack; - if (aZ > 0.75) return tBack; - return 5; - } - if (aZ < 0.25) return 2; - if (aZ > 0.75) return 3; - return aSide; - case 2: - case 3: - if (aX < 0.25) { - if (aY < 0.25) return tBack; - if (aY > 0.75) return tBack; - return 4; - } - if (aX > 0.75) { - if (aY < 0.25) return tBack; - if (aY > 0.75) return tBack; - return 5; - } - if (aY < 0.25) return 0; - if (aY > 0.75) return 1; - return aSide; - case 4: - case 5: - if (aZ < 0.25) { - if (aY < 0.25) return tBack; - if (aY > 0.75) return tBack; - return 2; - } - if (aZ > 0.75) { - if (aY < 0.25) return tBack; - if (aY > 0.75) return tBack; - return 3; - } - if (aY < 0.25) return 0; - if (aY > 0.75) return 1; - return aSide; - } - return -1; - } - - public static String formatNumbers(long aNumber) { - DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.US); - DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols(); - symbols.setGroupingSeparator(' '); - return formatter.format(aNumber); - } - - /* - * Check if stack has enough items of given type and subtract from stack, if there's no creative or 111 stack. - */ - public static boolean consumeItems(EntityPlayer player, ItemStack stack, Item item, int count) { - if (stack != null && stack.getItem() == item && stack.stackSize >= count) { - if ((!player.capabilities.isCreativeMode) && (stack.stackSize != 111)) - stack.stackSize -= count; - return true; - } - return false; - } - - /* - * Check if stack has enough items of given gregtech material (will be oredicted) - * and subtract from stack, if there's no creative or 111 stack. - */ - public static boolean consumeItems(EntityPlayer player, ItemStack stack, gregtech.api.enums.Materials mat, int count) { - if (stack != null - && GT_OreDictUnificator.getItemData(stack).mMaterial.mMaterial == mat - && stack.stackSize >= count) { - if ((!player.capabilities.isCreativeMode) && (stack.stackSize != 111)) - stack.stackSize -= count; - return true; - } - return false; - } - - public static ArrayList sortByValueToList( Map map ) { - List> list = - new LinkedList>( map.entrySet() ); - Collections.sort( list, new Comparator>() - { - public int compare( Map.Entry o1, Map.Entry o2 ) - { - return o2.getValue() - o1.getValue(); - } - } ); - - ArrayList result = new ArrayList(); - for (Map.Entry e : list) - result.add(e.getKey()); - return result; - } - - public static String joinListToString(List list) { - StringBuilder result = new StringBuilder(32); - for (String s : list) - result.append(result.length()==0?s:'|'+s); - return result.toString(); - } - - public static ItemStack getIntegratedCircuit(int config){ - return ItemList.Circuit_Integrated.getWithDamage(0, config, new Object[0]); - } - - public static float getBlockHardnessAt(World aWorld, int aX, int aY, int aZ) { - return aWorld.getBlock(aX, aY, aZ).getBlockHardness(aWorld, aX, aY, aZ); - } - - public static FakePlayer getFakePlayer(IGregTechTileEntity aBaseMetaTileEntity) { - if (aBaseMetaTileEntity.getWorld() instanceof WorldServer) { - return FakePlayerFactory.get((WorldServer) aBaseMetaTileEntity.getWorld(), new GameProfile(null, aBaseMetaTileEntity.getOwnerName())); - } - return null; - } - - public static boolean eraseBlockByFakePlayer(FakePlayer aPlayer, int aX, int aY, int aZ, boolean isSimulate) { - if (aPlayer == null) return false; - World aWorld = aPlayer.worldObj; - BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(aX, aY, aZ, aWorld, aWorld.getBlock(aX, aY, aZ), aWorld.getBlockMetadata(aX, aY, aZ), aPlayer); - MinecraftForge.EVENT_BUS.post(event); - if (!event.isCanceled()) { - if (!isSimulate) return aWorld.setBlockToAir(aX, aY, aZ); - return true; - } - return false; - } - - public static boolean setBlockByFakePlayer(FakePlayer aPlayer, int aX, int aY, int aZ, Block aBlock, int aMeta, boolean isSimulate) { - if (aPlayer == null) return false; - World aWorld = aPlayer.worldObj; - BlockEvent.PlaceEvent event = ForgeEventFactory.onPlayerBlockPlace(aPlayer, new BlockSnapshot(aWorld, aX, aY, aZ, aBlock, aMeta), ForgeDirection.UNKNOWN); - if (!event.isCanceled()) { - if (!isSimulate) return aWorld.setBlock(aX, aY, aZ, aBlock, aMeta, 3); - return true; - } - return false; - } - - public static class ItemNBT { - public static void setNBT(ItemStack aStack, NBTTagCompound aNBT) { - if (aNBT == null) { - aStack.setTagCompound(null); - return; - } - ArrayList tTagsToRemove = new ArrayList(); - for (Object tKey : aNBT.func_150296_c()) { - NBTBase tValue = aNBT.getTag((String) tKey); - if (tValue == null || (tValue instanceof NBTPrimitive && ((NBTPrimitive) tValue).func_150291_c() == 0) || (tValue instanceof NBTTagString && isStringInvalid(((NBTTagString) tValue).func_150285_a_()))) - tTagsToRemove.add((String) tKey); - } - for (Object tKey : tTagsToRemove) aNBT.removeTag((String) tKey); - aStack.setTagCompound(aNBT.hasNoTags() ? null : aNBT); - } - - public static NBTTagCompound getNBT(ItemStack aStack) { - NBTTagCompound rNBT = aStack.getTagCompound(); - return rNBT == null ? new NBTTagCompound() : rNBT; - } - - public static void setPunchCardData(ItemStack aStack, String aPunchCardData) { - NBTTagCompound tNBT = getNBT(aStack); - tNBT.setString("GT.PunchCardData", aPunchCardData); - setNBT(aStack, tNBT); - } - - public static String getPunchCardData(ItemStack aStack) { - NBTTagCompound tNBT = getNBT(aStack); - return tNBT.getString("GT.PunchCardData"); - } - - public static void setLighterFuel(ItemStack aStack, long aFuel) { - NBTTagCompound tNBT = getNBT(aStack); - tNBT.setLong("GT.LighterFuel", aFuel); - setNBT(aStack, tNBT); - } - - public static long getLighterFuel(ItemStack aStack) { - NBTTagCompound tNBT = getNBT(aStack); - return tNBT.getLong("GT.LighterFuel"); - } - - public static void setMapID(ItemStack aStack, short aMapID) { - NBTTagCompound tNBT = getNBT(aStack); - tNBT.setShort("map_id", aMapID); - setNBT(aStack, tNBT); - } - - public static short getMapID(ItemStack aStack) { - NBTTagCompound tNBT = getNBT(aStack); - if (!tNBT.hasKey("map_id")) return -1; - return tNBT.getShort("map_id"); - } - - public static void setBookTitle(ItemStack aStack, String aTitle) { - NBTTagCompound tNBT = getNBT(aStack); - tNBT.setString("title", aTitle); - setNBT(aStack, tNBT); - } - - public static String getBookTitle(ItemStack aStack) { - NBTTagCompound tNBT = getNBT(aStack); - return tNBT.getString("title"); - } - - public static void setBookAuthor(ItemStack aStack, String aAuthor) { - NBTTagCompound tNBT = getNBT(aStack); - tNBT.setString("author", aAuthor); - setNBT(aStack, tNBT); - } - - public static String getBookAuthor(ItemStack aStack) { - NBTTagCompound tNBT = getNBT(aStack); - return tNBT.getString("author"); - } - - public static void setProspectionData(ItemStack aStack, int aX, int aY, int aZ, int aDim, FluidStack aFluid, String... aOres) { - NBTTagCompound tNBT = getNBT(aStack); - String tData = aX + "," + aY + "," + aZ + "," + aDim + ","; - if (aFluid!=null) - tData += (aFluid.amount) + "," + aFluid.getLocalizedName() + ",";//TODO CHECK IF THAT /5000 is needed (Not needed) - for (String tString : aOres) { - tData += tString + ","; - } - tNBT.setString("prospection", tData); - setNBT(aStack, tNBT); - } - - public static void setAdvancedProspectionData( - byte aTier, - ItemStack aStack, - int aX, short aY, int aZ, int aDim, - ArrayList aOils, - ArrayList aOres, - int aRadius) { - - setBookTitle(aStack, "Raw Prospection Data"); - - NBTTagCompound tNBT = GT_Utility.ItemNBT.getNBT(aStack); - - tNBT.setByte("prospection_tier", aTier); - tNBT.setString("prospection_pos", "Dim: " + aDim + "\nX: " + aX + " Y: " + aY + " Z: " + aZ); - - // ores - Collections.sort(aOres); - tNBT.setString("prospection_ores", joinListToString(aOres)); - - // oils - ArrayList tOilsTransformed = new ArrayList(aOils.size()); - for (String aStr : aOils) { - String[] aStats = aStr.split(","); - tOilsTransformed.add(aStats[0] + ": " + aStats[1] + "L " + aStats[2]); - } - - tNBT.setString("prospection_oils", joinListToString(tOilsTransformed)); - - String tOilsPosStr = "X: " + Math.floorDiv(aX, 16*8)*16*8 + " Z: " + Math.floorDiv(aZ, 16*8)*16*8 + "\n"; - int xOff = aX - Math.floorDiv(aX, 16*8)*16*8; - xOff = xOff/16; - int xOffRemain = 7 - xOff; - - int zOff = aZ - Math.floorDiv(aZ, 16*8)*16*8; - zOff = zOff/16; - int zOffRemain = 7 - zOff; - - for( ; zOff > 0; zOff-- ) { - tOilsPosStr = tOilsPosStr.concat("--------\n"); - } - for( ; xOff > 0; xOff-- ) { - tOilsPosStr = tOilsPosStr.concat("-"); - } - - tOilsPosStr = tOilsPosStr.concat("P"); - - for( ; xOffRemain > 0; xOffRemain-- ) { - tOilsPosStr = tOilsPosStr.concat("-"); - } - tOilsPosStr = tOilsPosStr.concat("\n"); - for( ; zOffRemain > 0; zOffRemain-- ) { - tOilsPosStr = tOilsPosStr.concat("--------\n"); - } - tOilsPosStr = tOilsPosStr.concat( " X: " + (Math.floorDiv(aX, 16*8) + 1)*16*8 + " Z: " + (Math.floorDiv(aZ, 16*8) + 1)*16*8 ); // +1 oilfied to find bottomright of [5] - - tNBT.setString("prospection_oils_pos", tOilsPosStr); - - tNBT.setString("prospection_radius", String.valueOf(aRadius)); - - setNBT(aStack, tNBT); - } - - public static void convertProspectionData(ItemStack aStack) { - NBTTagCompound tNBT = getNBT(aStack); - byte tTier = tNBT.getByte("prospection_tier"); - - if (tTier == 0) { // basic prospection data - String tData = tNBT.getString("prospection"); - String[] tDataArray = tData.split(","); - if (tDataArray.length > 6) { - tNBT.setString("author", " Dim: " + tDataArray[3] + "X: " + tDataArray[0] + " Y: " + tDataArray[1] + " Z: " + tDataArray[2]); - NBTTagList tNBTList = new NBTTagList(); - String tOres = " Prospected Ores: "; - for (int i = 6; tDataArray.length > i; i++) { - tOres += (tDataArray[i] + " "); - } - tNBTList.appendTag(new NBTTagString("Tier " + tTier + " Prospecting Data From: X" + tDataArray[0] + " Z:" + tDataArray[2] + " Dim:" + tDataArray[3] + " Produces " + tDataArray[4] + "L " + tDataArray[5] + " " + tOres)); - tNBT.setTag("pages", tNBTList); - } - setNBT(aStack, tNBT); - } else { // advanced prospection data - String tPos = tNBT.getString("prospection_pos"); - String tRadius = tNBT.getString("prospection_radius"); - - String tOresStr = tNBT.getString("prospection_ores"); - String tOilsStr = tNBT.getString("prospection_oils"); - String tOilsPosStr = tNBT.getString("prospection_oils_pos"); - - String[] tOres = tOresStr.isEmpty() ? null : tOresStr.split("\\|"); - String[] tOils = tOilsStr.isEmpty() ? null : tOilsStr.split("\\|"); - - NBTTagList tNBTList = new NBTTagList(); - - String tPageText = "Prospector report\n" - + tPos + "\n\n" - + "Oils: " + (tOils != null ? tOils.length : 0) + "\n\n" - + "Ores within " + tRadius + " blocks\n\n" - + "Location is center of orevein\n\n" - + "Check NEI to confirm orevein type"; - tNBTList.appendTag(new NBTTagString(tPageText)); - - if (tOres != null) - fillBookWithList(tNBTList, "Ores Found %s\n\n", "\n", 7, tOres); - - - if (tOils != null) - fillBookWithList(tNBTList, "Oils%s\n\n", "\n", 9, tOils); - - tPageText = "Oil notes\n\n" - + "Prospects from NW to SE 576 chunks" - + "(9 8x8 oilfields)\n around and gives min-max amount" + "\n\n" - + "[1][2][3]" + "\n" - + "[4][5][6]" + "\n" - + "[7][8][9]" + "\n" - + "\n" - + "[5] - Prospector in this 8x8 area"; - tNBTList.appendTag(new NBTTagString(tPageText)); - - tPageText = "Corners of [5] are \n" + - tOilsPosStr + "\n" + - "P - Prospector in 8x8 field"; - tNBTList.appendTag(new NBTTagString(tPageText)); - - tNBT.setString("author", tPos.replace("\n"," ")); - tNBT.setTag("pages", tNBTList); - setNBT(aStack, tNBT); - } - } - - public static void fillBookWithList(NBTTagList aBook, String aPageHeader, String aListDelimiter, int aItemsPerPage, String[] list) { - String aPageFormatter = " %d/%d"; - int tTotalPages = list.length / aItemsPerPage + (list.length % aItemsPerPage > 0 ? 1 : 0); - int tPage = 0; - String tPageText; - do { - tPageText = ""; - for (int i = tPage*aItemsPerPage; i < (tPage+1)*aItemsPerPage && i < list.length; i += 1) - tPageText += (tPageText.isEmpty() ? "" : aListDelimiter) + list[i]; - - if (!tPageText.isEmpty()) { - String tPageCounter = tTotalPages > 1 ? String.format(aPageFormatter, tPage + 1, tTotalPages) : ""; - NBTTagString tPageTag = new NBTTagString(String.format(aPageHeader, tPageCounter) + tPageText); - aBook.appendTag(tPageTag); - } - - ++tPage; - } while (!tPageText.isEmpty()); - } - - public static void addEnchantment(ItemStack aStack, Enchantment aEnchantment, int aLevel) { - NBTTagCompound tNBT = getNBT(aStack), tEnchantmentTag; - if (!tNBT.hasKey("ench", 9)) tNBT.setTag("ench", new NBTTagList()); - NBTTagList tList = tNBT.getTagList("ench", 10); - - boolean temp = true; - - for (int i = 0; i < tList.tagCount(); i++) { - tEnchantmentTag = tList.getCompoundTagAt(i); - if (tEnchantmentTag.getShort("id") == aEnchantment.effectId) { - tEnchantmentTag.setShort("id", (short) aEnchantment.effectId); - tEnchantmentTag.setShort("lvl", (byte) aLevel); - temp = false; - break; - } - } - - if (temp) { - tEnchantmentTag = new NBTTagCompound(); - tEnchantmentTag.setShort("id", (short) aEnchantment.effectId); - tEnchantmentTag.setShort("lvl", (byte) aLevel); - tList.appendTag(tEnchantmentTag); - } - aStack.setTagCompound(tNBT); - } - } - - /** - * THIS IS BULLSHIT!!! WHY DO I HAVE TO DO THIS SHIT JUST TO HAVE ENCHANTS PROPERLY!?! - */ - public static class GT_EnchantmentHelper { - private static final BullshitIteratorA mBullshitIteratorA = new BullshitIteratorA(); - private static final BullshitIteratorB mBullshitIteratorB = new BullshitIteratorB(); - - private static void applyBullshit(IBullshit aBullshitModifier, ItemStack aStack) { - if (aStack != null) { - NBTTagList nbttaglist = aStack.getEnchantmentTagList(); - if (nbttaglist != null) { - try { - for (int i = 0; i < nbttaglist.tagCount(); ++i) { - short short1 = nbttaglist.getCompoundTagAt(i).getShort("id"); - short short2 = nbttaglist.getCompoundTagAt(i).getShort("lvl"); - if (Enchantment.enchantmentsList[short1] != null) - aBullshitModifier.calculateModifier(Enchantment.enchantmentsList[short1], short2); - } - } catch (Throwable e) {/**/} - } - } - } - - private static void applyArrayOfBullshit(IBullshit aBullshitModifier, ItemStack[] aStacks) { - ItemStack[] aitemstack1 = aStacks; - int i = aStacks.length; - for (int j = 0; j < i; ++j) { - ItemStack itemstack = aitemstack1[j]; - applyBullshit(aBullshitModifier, itemstack); - } - } - - public static void applyBullshitA(EntityLivingBase aPlayer, Entity aEntity, ItemStack aStack) { - mBullshitIteratorA.mPlayer = aPlayer; - mBullshitIteratorA.mEntity = aEntity; - if (aPlayer != null) applyArrayOfBullshit(mBullshitIteratorA, aPlayer.getLastActiveItems()); - if (aStack != null) applyBullshit(mBullshitIteratorA, aStack); - } - - public static void applyBullshitB(EntityLivingBase aPlayer, Entity aEntity, ItemStack aStack) { - mBullshitIteratorB.mPlayer = aPlayer; - mBullshitIteratorB.mEntity = aEntity; - if (aPlayer != null) applyArrayOfBullshit(mBullshitIteratorB, aPlayer.getLastActiveItems()); - if (aStack != null) applyBullshit(mBullshitIteratorB, aStack); - } - - interface IBullshit { - void calculateModifier(Enchantment aEnchantment, int aLevel); - } - - static final class BullshitIteratorA implements IBullshit { - public EntityLivingBase mPlayer; - public Entity mEntity; - - BullshitIteratorA() { - } - - @Override - public void calculateModifier(Enchantment aEnchantment, int aLevel) { - aEnchantment.func_151367_b(mPlayer, mEntity, aLevel); - } - } - - static final class BullshitIteratorB implements IBullshit { - public EntityLivingBase mPlayer; - public Entity mEntity; - - BullshitIteratorB() { - } - - @Override - public void calculateModifier(Enchantment aEnchantment, int aLevel) { - aEnchantment.func_151368_a(mPlayer, mEntity, aLevel); - } - } - } - - public static String toSubscript(long no){ - char[] chars=Long.toString(no).toCharArray(); - for(int i=0;i + * Just a few Utility Functions I use. + */ +public class GT_Utility { + /** + * Forge screwed the Fluid Registry up again, so I make my own, which is also much more efficient than the stupid Stuff over there. + */ + private static final List sFluidContainerList = new ArrayList(); + private static final Map sFilledContainerToData = new /*Concurrent*/HashMap(); + private static final Map> sEmptyContainerToFluidToData = new /*Concurrent*/HashMap>(); + public static volatile int VERSION = 509; + public static boolean TE_CHECK = false, BC_CHECK = false, CHECK_ALL = true, RF_CHECK = false; + public static Map sPlayedSoundMap = new /*Concurrent*/HashMap(); + private static int sBookCount = 0; + public static UUID defaultUuid = null; // maybe default non-null? UUID.fromString("00000000-0000-0000-0000-000000000000"); + + + static { + GregTech_API.sItemStackMappings.add(sFilledContainerToData); + GregTech_API.sItemStackMappings.add(sEmptyContainerToFluidToData); + } + + public static int safeInt(long number, int margin){ + return number>Integer.MAX_VALUE-margin ? Integer.MAX_VALUE-margin :(int)number; + } + + public static int safeInt(long number){ + return number>GT_Values.V[GT_Values.V.length-1] ? safeInt(GT_Values.V[GT_Values.V.length-1],1) : number... aParameterTypes) { + Method rMethod = null; + try { + rMethod = aObject.getMethod(aMethod, aParameterTypes); + rMethod.setAccessible(true); + } catch (Throwable e) {/*Do nothing*/} + return rMethod; + } + + public static Method getMethod(Object aObject, String aMethod, Class... aParameterTypes) { + Method rMethod = null; + try { + rMethod = aObject.getClass().getMethod(aMethod, aParameterTypes); + rMethod.setAccessible(true); + } catch (Throwable e) {/*Do nothing*/} + return rMethod; + } + + public static Field getField(Object aObject, String aField, boolean aPrivate, boolean aLogErrors) { + try { + Field tField = (aObject instanceof Class) ? ((Class) aObject).getDeclaredField(aField) : (aObject instanceof String) ? Class.forName((String) aObject).getDeclaredField(aField) : aObject.getClass().getDeclaredField(aField); + if (aPrivate) tField.setAccessible(true); + return tField; + } catch (Throwable e) { + if (aLogErrors) e.printStackTrace(GT_Log.err); + } + return null; + } + + public static Object getFieldContent(Object aObject, String aField, boolean aPrivate, boolean aLogErrors) { + try { + Field tField = (aObject instanceof Class) ? ((Class) aObject).getDeclaredField(aField) : (aObject instanceof String) ? Class.forName((String) aObject).getDeclaredField(aField) : aObject.getClass().getDeclaredField(aField); + if (aPrivate) tField.setAccessible(true); + return tField.get(aObject instanceof Class || aObject instanceof String ? null : aObject); + } catch (Throwable e) { + if (aLogErrors) e.printStackTrace(GT_Log.err); + } + return null; + } + + public static Object callPublicMethod(Object aObject, String aMethod, Object... aParameters) { + return callMethod(aObject, aMethod, false, false, true, aParameters); + } + + public static Object callPrivateMethod(Object aObject, String aMethod, Object... aParameters) { + return callMethod(aObject, aMethod, true, false, true, aParameters); + } + + public static Object callMethod(Object aObject, String aMethod, boolean aPrivate, boolean aUseUpperCasedDataTypes, boolean aLogErrors, Object... aParameters) { + try { + Class[] tParameterTypes = new Class[aParameters.length]; + for (byte i = 0; i < aParameters.length; i++) { + if (aParameters[i] instanceof Class) { + tParameterTypes[i] = (Class) aParameters[i]; + aParameters[i] = null; + } else { + tParameterTypes[i] = aParameters[i].getClass(); + } + if (!aUseUpperCasedDataTypes) { + if (tParameterTypes[i] == Boolean.class) tParameterTypes[i] = boolean.class; + else if (tParameterTypes[i] == Byte.class) tParameterTypes[i] = byte.class; + else if (tParameterTypes[i] == Short.class) tParameterTypes[i] = short.class; + else if (tParameterTypes[i] == Integer.class) tParameterTypes[i] = int.class; + else if (tParameterTypes[i] == Long.class) tParameterTypes[i] = long.class; + else if (tParameterTypes[i] == Float.class) tParameterTypes[i] = float.class; + else if (tParameterTypes[i] == Double.class) tParameterTypes[i] = double.class; + } + } + + Method tMethod = (aObject instanceof Class) ? ((Class) aObject).getMethod(aMethod, tParameterTypes) : aObject.getClass().getMethod(aMethod, tParameterTypes); + if (aPrivate) tMethod.setAccessible(true); + return tMethod.invoke(aObject, aParameters); + } catch (Throwable e) { + if (aLogErrors) e.printStackTrace(GT_Log.err); + } + return null; + } + + public static Object callConstructor(String aClass, int aConstructorIndex, Object aReplacementObject, boolean aLogErrors, Object... aParameters) { + if (aConstructorIndex < 0) { + try { + for (Constructor tConstructor : Class.forName(aClass).getConstructors()) { + try { + return tConstructor.newInstance(aParameters); + } catch (Throwable e) {/*Do nothing*/} + } + } catch (Throwable e) { + if (aLogErrors) e.printStackTrace(GT_Log.err); + } + } else { + try { + return Class.forName(aClass).getConstructors()[aConstructorIndex].newInstance(aParameters); + } catch (Throwable e) { + if (aLogErrors) e.printStackTrace(GT_Log.err); + } + } + return aReplacementObject; + } + + public static String capitalizeString(String aString) { + if (aString != null && aString.length() > 0) + return aString.substring(0, 1).toUpperCase() + aString.substring(1); + return E; + } + + public static boolean getPotion(EntityLivingBase aPlayer, int aPotionIndex) { + try { + Field tPotionHashmap = null; + + Field[] var3 = EntityLiving.class.getDeclaredFields(); + int var4 = var3.length; + + for (int var5 = 0; var5 < var4; ++var5) { + Field var6 = var3[var5]; + if (var6.getType() == HashMap.class) { + tPotionHashmap = var6; + tPotionHashmap.setAccessible(true); + break; + } + } + + if (tPotionHashmap != null) + return ((HashMap) tPotionHashmap.get(aPlayer)).get(Integer.valueOf(aPotionIndex)) != null; + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + return false; + } + + public static String getClassName(Object aObject) { + if (aObject == null) return "null"; + return aObject.getClass().getName().substring(aObject.getClass().getName().lastIndexOf(".") + 1); + } + + public static void removePotion(EntityLivingBase aPlayer, int aPotionIndex) { + try { + Field tPotionHashmap = null; + + Field[] var3 = EntityLiving.class.getDeclaredFields(); + int var4 = var3.length; + + for (int var5 = 0; var5 < var4; ++var5) { + Field var6 = var3[var5]; + if (var6.getType() == HashMap.class) { + tPotionHashmap = var6; + tPotionHashmap.setAccessible(true); + break; + } + } + + if (tPotionHashmap != null) ((HashMap) tPotionHashmap.get(aPlayer)).remove(Integer.valueOf(aPotionIndex)); + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + } + + public static boolean getFullInvisibility(EntityPlayer aPlayer) { + try { + if (aPlayer.isInvisible()) { + for (int i = 0; i < 4; i++) { + if (aPlayer.inventory.armorInventory[i] != null) { + if (aPlayer.inventory.armorInventory[i].getItem() instanceof GT_EnergyArmor_Item) { + if ((((GT_EnergyArmor_Item) aPlayer.inventory.armorInventory[i].getItem()).mSpecials & 512) != 0) { + if (GT_ModHandler.canUseElectricItem(aPlayer.inventory.armorInventory[i], 10000)) { + return true; + } + } + } + } + } + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + return false; + } + + public static ItemStack suckOneItemStackAt(World aWorld, double aX, double aY, double aZ, double aL, double aH, double aW) { + for (EntityItem tItem : (ArrayList) aWorld.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(aX, aY, aZ, aX + aL, aY + aH, aZ + aW))) { + if (!tItem.isDead) { + aWorld.removeEntity(tItem); + tItem.setDead(); + return tItem.getEntityItem(); + } + } + return null; + } + + public static byte getOppositeSide(int aSide) { + return (byte) ForgeDirection.getOrientation(aSide).getOpposite().ordinal(); + } + + public static byte getTier(long l) { + byte i = -1; + while (++i < V.length) if (l <= V[i]) return i; + return i; + } + + public static void sendChatToPlayer(EntityPlayer aPlayer, String aChatMessage) { + if (aPlayer instanceof EntityPlayerMP && aChatMessage != null) { + aPlayer.addChatComponentMessage(new ChatComponentText(aChatMessage)); + } + } + + public static void checkAvailabilities() { + if (CHECK_ALL) { + try { + Class tClass = IItemDuct.class; + tClass.getCanonicalName(); + TE_CHECK = true; + } catch (Throwable e) {/**/} + try { + Class tClass = buildcraft.api.transport.IPipeTile.class; + tClass.getCanonicalName(); + BC_CHECK = true; + } catch (Throwable e) {/**/} + try { + Class tClass = cofh.api.energy.IEnergyReceiver.class; + tClass.getCanonicalName(); + RF_CHECK = true; + } catch (Throwable e) {/**/} + CHECK_ALL = false; + } + } + + public static boolean isConnectableNonInventoryPipe(Object aTileEntity, int aSide) { + if (aTileEntity == null) return false; + checkAvailabilities(); + if (TE_CHECK && aTileEntity instanceof IItemDuct) return true; + if (BC_CHECK && aTileEntity instanceof buildcraft.api.transport.IPipeTile) + return ((buildcraft.api.transport.IPipeTile) aTileEntity).isPipeConnected(ForgeDirection.getOrientation(aSide)); + if (GregTech_API.mTranslocator && aTileEntity instanceof codechicken.translocator.TileItemTranslocator) return true; + + return false; + } + /** + * Moves Stack from Inv-Slot to Inv-Slot, without checking if its even allowed. + * + * @return the Amount of moved Items + */ + public static byte moveStackIntoPipe(IInventory aTileEntity1, Object aTileEntity2, int[] aGrabSlots, int aGrabFrom, int aPutTo, List aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { + return moveStackIntoPipe(aTileEntity1, aTileEntity2, aGrabSlots, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, true); + } + + /** + * Moves Stack from Inv-Slot to Inv-Slot, without checking if its even allowed. + * + * @return the Amount of moved Items + */ + public static byte moveStackIntoPipe(IInventory aTileEntity1, Object aTileEntity2, int[] aGrabSlots, int aGrabFrom, int aPutTo, List aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce, boolean dropItem) { + if (aTileEntity1 == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMaxMoveAtOnce <= 0 || aMinMoveAtOnce > aMaxMoveAtOnce) + return 0; + if (aTileEntity2 != null) { + checkAvailabilities(); + if (TE_CHECK && aTileEntity2 instanceof IItemDuct) { + for (int i = 0; i < aGrabSlots.length; i++) { + if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlots[i]), true, aInvertFilter)) { + if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlots[i], (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlots[i]))) { + if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize) { + ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlots[i])); + ItemStack rStack = ((IItemDuct) aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), copy(tStack)); + byte tMovedItemCount = (byte) (tStack.stackSize - (rStack == null ? 0 : rStack.stackSize)); + if (tMovedItemCount >= 1/*Math.max(aMinMoveAtOnce, aMinTargetStackSize)*/) { + //((cofh.api.transport.IItemConduit)aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), copyAmount(tMovedItemCount, tStack), F); + aTileEntity1.decrStackSize(aGrabSlots[i], tMovedItemCount); + aTileEntity1.markDirty(); + return tMovedItemCount; + } + } + } + } + } + return 0; + } + if (BC_CHECK && aTileEntity2 instanceof buildcraft.api.transport.IPipeTile) { + for (int i = 0; i < aGrabSlots.length; i++) { + if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlots[i]), true, aInvertFilter)) { + if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlots[i], (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlots[i]))) { + if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize) { + ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlots[i])); + byte tMovedItemCount = (byte) ((buildcraft.api.transport.IPipeTile) aTileEntity2).injectItem(copy(tStack), false, ForgeDirection.getOrientation(aPutTo)); + if (tMovedItemCount >= Math.max(aMinMoveAtOnce, aMinTargetStackSize)) { + tMovedItemCount = (byte) (((buildcraft.api.transport.IPipeTile) aTileEntity2).injectItem(copyAmount(tMovedItemCount, tStack), true, ForgeDirection.getOrientation(aPutTo))); + aTileEntity1.decrStackSize(aGrabSlots[i], tMovedItemCount); + aTileEntity1.markDirty(); + return tMovedItemCount; + } + } + } + } + } + return 0; + } + } + + ForgeDirection tDirection = ForgeDirection.getOrientation(aGrabFrom); + if (aTileEntity1 instanceof TileEntity && tDirection != ForgeDirection.UNKNOWN && tDirection.getOpposite() == ForgeDirection.getOrientation(aPutTo)) { + int tX = ((TileEntity) aTileEntity1).xCoord + tDirection.offsetX, tY = ((TileEntity) aTileEntity1).yCoord + tDirection.offsetY, tZ = ((TileEntity) aTileEntity1).zCoord + tDirection.offsetZ; + if (!hasBlockHitBox(((TileEntity) aTileEntity1).getWorldObj(), tX, tY, tZ) && dropItem) { + for (int i = 0; i < aGrabSlots.length; i++) { + if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlots[i]), true, aInvertFilter)) { + if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlots[i], (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlots[i]))) { + if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize) { + ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlots[i])); + EntityItem tEntity = new EntityItem(((TileEntity) aTileEntity1).getWorldObj(), tX + 0.5, tY + 0.5, tZ + 0.5, tStack); + tEntity.motionX = tEntity.motionY = tEntity.motionZ = 0; + ((TileEntity) aTileEntity1).getWorldObj().spawnEntityInWorld(tEntity); + aTileEntity1.decrStackSize(aGrabSlots[i], tStack.stackSize); + aTileEntity1.markDirty(); + return (byte) tStack.stackSize; + } + } + } + } + } + } + return 0; + } + + /** + * Moves Stack from Inv-Slot to Inv-Slot, without checking if its even allowed. (useful for internal Inventory Operations) + * + * @return the Amount of moved Items + */ + public static byte moveStackFromSlotAToSlotB(IInventory aTileEntity1, IInventory aTileEntity2, int aGrabFrom, int aPutTo, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { + if (aTileEntity1 == null || aTileEntity2 == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMaxMoveAtOnce <= 0 || aMinMoveAtOnce > aMaxMoveAtOnce) + return 0; + + ItemStack tStack1 = aTileEntity1.getStackInSlot(aGrabFrom), tStack2 = aTileEntity2.getStackInSlot(aPutTo), tStack3 = null; + if (tStack1 != null) { + if (tStack2 != null && !areStacksEqual(tStack1, tStack2)) return 0; + tStack3 = copy(tStack1); + aMaxTargetStackSize = (byte) Math.min(aMaxTargetStackSize, Math.min(tStack3.getMaxStackSize(), Math.min(tStack2 == null ? Integer.MAX_VALUE : tStack2.getMaxStackSize(), aTileEntity2.getInventoryStackLimit()))); + tStack3.stackSize = Math.min(tStack3.stackSize, aMaxTargetStackSize - (tStack2 == null ? 0 : tStack2.stackSize)); + if (tStack3.stackSize > aMaxMoveAtOnce) tStack3.stackSize = aMaxMoveAtOnce; + if (tStack3.stackSize + (tStack2 == null ? 0 : tStack2.stackSize) >= Math.min(tStack3.getMaxStackSize(), aMinTargetStackSize) && tStack3.stackSize >= aMinMoveAtOnce) { + tStack3 = aTileEntity1.decrStackSize(aGrabFrom, tStack3.stackSize); + aTileEntity1.markDirty(); + if (tStack3 != null) { + if (tStack2 == null) { + aTileEntity2.setInventorySlotContents(aPutTo, copy(tStack3)); + aTileEntity2.markDirty(); + } else { + tStack2.stackSize += tStack3.stackSize; + aTileEntity2.markDirty(); + } + return (byte) tStack3.stackSize; + } + } + } + return 0; + } + + public static boolean isAllowedToTakeFromSlot(IInventory aTileEntity, int aSlot, byte aSide, ItemStack aStack) { + if (ForgeDirection.getOrientation(aSide) == ForgeDirection.UNKNOWN) { + return isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 0, aStack) + || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 1, aStack) + || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 2, aStack) + || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 3, aStack) + || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 4, aStack) + || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 5, aStack); + } + if (aTileEntity instanceof ISidedInventory) + return ((ISidedInventory) aTileEntity).canExtractItem(aSlot, aStack, aSide); + return true; + } + + public static boolean isAllowedToPutIntoSlot(IInventory aTileEntity, int aSlot, byte aSide, ItemStack aStack, byte aMaxStackSize) { + ItemStack tStack = aTileEntity.getStackInSlot(aSlot); + if (tStack != null && (!areStacksEqual(tStack, aStack) || tStack.stackSize >= tStack.getMaxStackSize())) + return false; + if (ForgeDirection.getOrientation(aSide) == ForgeDirection.UNKNOWN) { + return isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 0, aStack, aMaxStackSize) + || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 1, aStack, aMaxStackSize) + || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 2, aStack, aMaxStackSize) + || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 3, aStack, aMaxStackSize) + || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 4, aStack, aMaxStackSize) + || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 5, aStack, aMaxStackSize); + } + if (aTileEntity instanceof ISidedInventory && !((ISidedInventory) aTileEntity).canInsertItem(aSlot, aStack, aSide)) + return false; + return aSlot < aTileEntity.getSizeInventory() && aTileEntity.isItemValidForSlot(aSlot, aStack); + } + + /** + * Moves Stack from Inv-Side to Inv-Side. + * + * @return the Amount of moved Items + */ + public static byte moveOneItemStack(Object aTileEntity1, Object aTileEntity2, byte aGrabFrom, byte aPutTo, List aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { + if (aTileEntity1 instanceof IInventory) + return moveOneItemStack((IInventory) aTileEntity1, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, true); + return 0; + } + + /** + * This is only because I needed an additional Parameter for the Double Chest Check. + */ + private static byte moveOneItemStack(IInventory aTileEntity1, Object aTileEntity2, byte aGrabFrom, byte aPutTo, List aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce, boolean aDoCheckChests) { + if (aTileEntity1 == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce) + return 0; + + int[] tGrabSlots = null; + if (aTileEntity1 instanceof ISidedInventory) + tGrabSlots = ((ISidedInventory) aTileEntity1).getAccessibleSlotsFromSide(aGrabFrom); + if (tGrabSlots == null) { + tGrabSlots = new int[aTileEntity1.getSizeInventory()]; + for (int i = 0; i < tGrabSlots.length; i++) tGrabSlots[i] = i; + } + + if (aTileEntity2 != null && aTileEntity2 instanceof IInventory) { + int[] tPutSlots = null; + if (aTileEntity2 instanceof ISidedInventory) + tPutSlots = ((ISidedInventory) aTileEntity2).getAccessibleSlotsFromSide(aPutTo); + + if (tPutSlots == null) { + tPutSlots = new int[((IInventory) aTileEntity2).getSizeInventory()]; + for (int i = 0; i < tPutSlots.length; i++) tPutSlots[i] = i; + } + + for (int i = 0; i < tGrabSlots.length; i++) { + byte tMovedItemCount = 0; + for (int j = 0; j < tPutSlots.length; j++) { + if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(tGrabSlots[i]), true, aInvertFilter)) { + if (isAllowedToTakeFromSlot(aTileEntity1, tGrabSlots[i], aGrabFrom, aTileEntity1.getStackInSlot(tGrabSlots[i]))) { + if (isAllowedToPutIntoSlot((IInventory) aTileEntity2, tPutSlots[j], aPutTo, aTileEntity1.getStackInSlot(tGrabSlots[i]), aMaxTargetStackSize)) { + tMovedItemCount += moveStackFromSlotAToSlotB(aTileEntity1, (IInventory) aTileEntity2, tGrabSlots[i], tPutSlots[j], aMaxTargetStackSize, aMinTargetStackSize, (byte) (aMaxMoveAtOnce - tMovedItemCount), aMinMoveAtOnce); + if (tMovedItemCount >= aMaxMoveAtOnce) { + return tMovedItemCount; + + } + } + } + } + } + if (tMovedItemCount > 0) return tMovedItemCount; + } + + if (aDoCheckChests && aTileEntity1 instanceof TileEntityChest) { + TileEntityChest tTileEntity1 = (TileEntityChest) aTileEntity1; + if (tTileEntity1.adjacentChestChecked) { + byte tAmount = 0; + if (tTileEntity1.adjacentChestXNeg != null) { + tAmount = moveOneItemStack(tTileEntity1.adjacentChestXNeg, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); + } else if (tTileEntity1.adjacentChestZNeg != null) { + tAmount = moveOneItemStack(tTileEntity1.adjacentChestZNeg, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); + } else if (tTileEntity1.adjacentChestXPos != null) { + tAmount = moveOneItemStack(tTileEntity1.adjacentChestXPos, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); + } else if (tTileEntity1.adjacentChestZPos != null) { + tAmount = moveOneItemStack(tTileEntity1.adjacentChestZPos, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); + } + if (tAmount != 0) return tAmount; + } + } + if (aDoCheckChests && aTileEntity2 instanceof TileEntityChest) { + TileEntityChest tTileEntity2 = (TileEntityChest) aTileEntity2; + if (tTileEntity2.adjacentChestChecked) { + byte tAmount = 0; + if (tTileEntity2.adjacentChestXNeg != null) { + tAmount = moveOneItemStack(aTileEntity1, tTileEntity2.adjacentChestXNeg, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); + } else if (tTileEntity2.adjacentChestZNeg != null) { + tAmount = moveOneItemStack(aTileEntity1, tTileEntity2.adjacentChestZNeg, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); + } else if (tTileEntity2.adjacentChestXPos != null) { + tAmount = moveOneItemStack(aTileEntity1, tTileEntity2.adjacentChestXPos, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); + } else if (tTileEntity2.adjacentChestZPos != null) { + tAmount = moveOneItemStack(aTileEntity1, tTileEntity2.adjacentChestZPos, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); + } + if (tAmount != 0) return tAmount; + } + } + } + + return moveStackIntoPipe(aTileEntity1, aTileEntity2, tGrabSlots, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, aDoCheckChests); + } + + /** + * Moves Stack from Inv-Side to Inv-Slot. + * + * @return the Amount of moved Items + */ + public static byte moveOneItemStackIntoSlot(Object aTileEntity1, Object aTileEntity2, byte aGrabFrom, int aPutTo, List aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { + if (aTileEntity1 == null || !(aTileEntity1 instanceof IInventory) || aPutTo < 0 || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce) + return 0; + + int[] tGrabSlots = null; + if (aTileEntity1 instanceof ISidedInventory) + tGrabSlots = ((ISidedInventory) aTileEntity1).getAccessibleSlotsFromSide(aGrabFrom); + if (tGrabSlots == null) { + tGrabSlots = new int[((IInventory) aTileEntity1).getSizeInventory()]; + for (int i = 0; i < tGrabSlots.length; i++) tGrabSlots[i] = i; + } + + if (aTileEntity2 instanceof IInventory) { + for (int i = 0; i < tGrabSlots.length; i++) { + if (listContainsItem(aFilter, ((IInventory) aTileEntity1).getStackInSlot(tGrabSlots[i]), true, aInvertFilter)) { + if (isAllowedToTakeFromSlot((IInventory) aTileEntity1, tGrabSlots[i], aGrabFrom, ((IInventory) aTileEntity1).getStackInSlot(tGrabSlots[i]))) { + if (isAllowedToPutIntoSlot((IInventory) aTileEntity2, aPutTo, (byte) 6, ((IInventory) aTileEntity1).getStackInSlot(tGrabSlots[i]), aMaxTargetStackSize)) { + byte tMovedItemCount = moveStackFromSlotAToSlotB((IInventory) aTileEntity1, (IInventory) aTileEntity2, tGrabSlots[i], aPutTo, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce); + if (tMovedItemCount > 0) return tMovedItemCount; + } + } + } + } + } + + moveStackIntoPipe(((IInventory) aTileEntity1), aTileEntity2, tGrabSlots, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce); + return 0; + } + + /** + * Moves Stack from Inv-Slot to Inv-Slot. + * + * @return the Amount of moved Items + */ + public static byte moveFromSlotToSlot(IInventory aTileEntity1, IInventory aTileEntity2, int aGrabFrom, int aPutTo, List aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { + if (aTileEntity1 == null || aTileEntity2 == null || aGrabFrom < 0 || aPutTo < 0 || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce) + return 0; + if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabFrom), true, aInvertFilter)) { + if (isAllowedToTakeFromSlot(aTileEntity1, aGrabFrom, (byte) 6, aTileEntity1.getStackInSlot(aGrabFrom))) { + if (isAllowedToPutIntoSlot(aTileEntity2, aPutTo, (byte) 6, aTileEntity1.getStackInSlot(aGrabFrom), aMaxTargetStackSize)) { + byte tMovedItemCount = moveStackFromSlotAToSlotB(aTileEntity1, aTileEntity2, aGrabFrom, aPutTo, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce); + if (tMovedItemCount > 0) return tMovedItemCount; + } + } + } + return 0; + } + + public static boolean listContainsItem(Collection aList, ItemStack aStack, boolean aTIfListEmpty, boolean aInvertFilter) { + if (aStack == null || aStack.stackSize < 1) return false; + if (aList == null) return aTIfListEmpty; + while (aList.contains(null)) aList.remove(null); + if (aList.size() < 1) return aTIfListEmpty; + Iterator tIterator = aList.iterator(); + ItemStack tStack = null; + while (tIterator.hasNext()) + if ((tStack = tIterator.next()) != null && areStacksEqual(aStack, tStack)) return !aInvertFilter; + return aInvertFilter; + } + + public static boolean areStacksOrToolsEqual(ItemStack aStack1, ItemStack aStack2) { + if (aStack1 != null && aStack2 != null && aStack1.getItem() == aStack2.getItem()) { + if (aStack1.getItem().isDamageable()) return true; + return ((aStack1.getTagCompound() == null) == (aStack2.getTagCompound() == null)) && (aStack1.getTagCompound() == null || aStack1.getTagCompound().equals(aStack2.getTagCompound())) && (Items.feather.getDamage(aStack1) == Items.feather.getDamage(aStack2) || Items.feather.getDamage(aStack1) == W || Items.feather.getDamage(aStack2) == W); + } + return false; + } + + public static boolean areFluidsEqual(FluidStack aFluid1, FluidStack aFluid2) { + return areFluidsEqual(aFluid1, aFluid2, false); + } + + public static boolean areFluidsEqual(FluidStack aFluid1, FluidStack aFluid2, boolean aIgnoreNBT) { + return aFluid1 != null && aFluid2 != null && aFluid1.getFluid() == aFluid2.getFluid() && (aIgnoreNBT || ((aFluid1.tag == null) == (aFluid2.tag == null)) && (aFluid1.tag == null || aFluid1.tag.equals(aFluid2.tag))); + } + + public static boolean areStacksEqual(ItemStack aStack1, ItemStack aStack2) { + return areStacksEqual(aStack1, aStack2, false); + } + + public static boolean areStacksEqual(ItemStack aStack1, ItemStack aStack2, boolean aIgnoreNBT) { + return aStack1 != null && aStack2 != null && aStack1.getItem() == aStack2.getItem() && (aIgnoreNBT || ((aStack1.getTagCompound() == null) == (aStack2.getTagCompound() == null)) && (aStack1.getTagCompound() == null || aStack1.getTagCompound().equals(aStack2.getTagCompound()))) && (Items.feather.getDamage(aStack1) == Items.feather.getDamage(aStack2) || Items.feather.getDamage(aStack1) == W || Items.feather.getDamage(aStack2) == W); + } + + public static boolean areUnificationsEqual(ItemStack aStack1, ItemStack aStack2) { + return areUnificationsEqual(aStack1, aStack2, false); + } + + public static boolean areUnificationsEqual(ItemStack aStack1, ItemStack aStack2, boolean aIgnoreNBT) { + return areStacksEqual(GT_OreDictUnificator.get(aStack1), GT_OreDictUnificator.get(aStack2), aIgnoreNBT); + } + + public static String getFluidName(Fluid aFluid, boolean aLocalized) { + if (aFluid == null) return E; + String rName = aLocalized ? aFluid.getLocalizedName(new FluidStack(aFluid, 0)) : aFluid.getUnlocalizedName(); + if (rName.contains("fluid.") || rName.contains("tile.")) + return capitalizeString(rName.replaceAll("fluid.", E).replaceAll("tile.", E)); + return rName; + } + + public static String getFluidName(FluidStack aFluid, boolean aLocalized) { + if (aFluid == null) return E; + return getFluidName(aFluid.getFluid(), aLocalized); + } + + public static void reInit() { + sFilledContainerToData.clear(); + sEmptyContainerToFluidToData.clear(); + for (FluidContainerData tData : sFluidContainerList) { + sFilledContainerToData.put(new GT_ItemStack(tData.filledContainer), tData); + Map tFluidToContainer = sEmptyContainerToFluidToData.get(new GT_ItemStack(tData.emptyContainer)); + if (tFluidToContainer == null) { + sEmptyContainerToFluidToData.put(new GT_ItemStack(tData.emptyContainer), tFluidToContainer = new /*Concurrent*/HashMap()); + GregTech_API.sFluidMappings.add(tFluidToContainer); + } + tFluidToContainer.put(tData.fluid.getFluid(), tData); + } + } + + public static void addFluidContainerData(FluidContainerData aData) { + sFluidContainerList.add(aData); + sFilledContainerToData.put(new GT_ItemStack(aData.filledContainer), aData); + Map tFluidToContainer = sEmptyContainerToFluidToData.get(new GT_ItemStack(aData.emptyContainer)); + if (tFluidToContainer == null) { + sEmptyContainerToFluidToData.put(new GT_ItemStack(aData.emptyContainer), tFluidToContainer = new /*Concurrent*/HashMap()); + GregTech_API.sFluidMappings.add(tFluidToContainer); + } + tFluidToContainer.put(aData.fluid.getFluid(), aData); + } + + public static ItemStack fillFluidContainer(FluidStack aFluid, ItemStack aStack, boolean aRemoveFluidDirectly, boolean aCheckIFluidContainerItems) { + if (isStackInvalid(aStack) || aFluid == null) return null; + if (GT_ModHandler.isWater(aFluid) && ItemList.Bottle_Empty.isStackEqual(aStack)) { + if (aFluid.amount >= 250) { + if (aRemoveFluidDirectly) aFluid.amount -= 250; + return new ItemStack(Items.potionitem, 1, 0); + } + return null; + } + if (aCheckIFluidContainerItems && aStack.getItem() instanceof IFluidContainerItem && ((IFluidContainerItem) aStack.getItem()).getFluid(aStack) == null && ((IFluidContainerItem) aStack.getItem()).getCapacity(aStack) <= aFluid.amount) { + if (aRemoveFluidDirectly) + aFluid.amount -= ((IFluidContainerItem) aStack.getItem()).fill(aStack = copyAmount(1, aStack), aFluid, true); + else + ((IFluidContainerItem) aStack.getItem()).fill(aStack = copyAmount(1, aStack), aFluid, true); + return aStack; + } + Map tFluidToContainer = sEmptyContainerToFluidToData.get(new GT_ItemStack(aStack)); + if (tFluidToContainer == null) return null; + FluidContainerData tData = tFluidToContainer.get(aFluid.getFluid()); + if (tData == null || tData.fluid.amount > aFluid.amount) return null; + if (aRemoveFluidDirectly) aFluid.amount -= tData.fluid.amount; + return copyAmount(1, tData.filledContainer); + } + + public static ItemStack getFluidDisplayStack(Fluid aFluid) { + return aFluid == null ? null : getFluidDisplayStack(new FluidStack(aFluid, 0), false); + } + + public static ItemStack getFluidDisplayStack(FluidStack aFluid, boolean aUseStackSize) { + if (aFluid == null || aFluid.getFluid() == null) return null; + int tmp = 0; + try { + tmp = aFluid.getFluid().getID(); + } catch (Exception e) { + System.err.println(e); + } + ItemStack rStack = ItemList.Display_Fluid.getWithDamage(aUseStackSize ? aFluid.amount / 1000 : 1, tmp); + NBTTagCompound tNBT = new NBTTagCompound(); + tNBT.setLong("mFluidDisplayAmount", aFluid.amount); + tNBT.setLong("mFluidDisplayHeat", aFluid.getFluid().getTemperature(aFluid)); + tNBT.setBoolean("mFluidState", aFluid.getFluid().isGaseous(aFluid)); + rStack.setTagCompound(tNBT); + return rStack; + } + + public static boolean containsFluid(ItemStack aStack, FluidStack aFluid, boolean aCheckIFluidContainerItems) { + if (isStackInvalid(aStack) || aFluid == null) return false; + if (aCheckIFluidContainerItems && aStack.getItem() instanceof IFluidContainerItem && ((IFluidContainerItem) aStack.getItem()).getCapacity(aStack) > 0) + return aFluid.isFluidEqual(((IFluidContainerItem) aStack.getItem()).getFluid(aStack = copyAmount(1, aStack))); + FluidContainerData tData = sFilledContainerToData.get(new GT_ItemStack(aStack)); + return tData == null ? false : tData.fluid.isFluidEqual(aFluid); + } + + public static FluidStack getFluidForFilledItem(ItemStack aStack, boolean aCheckIFluidContainerItems) { + if (isStackInvalid(aStack)) return null; + if (aCheckIFluidContainerItems && aStack.getItem() instanceof IFluidContainerItem && ((IFluidContainerItem) aStack.getItem()).getCapacity(aStack) > 0) + return ((IFluidContainerItem) aStack.getItem()).drain(copyAmount(1, aStack), Integer.MAX_VALUE, true); + FluidContainerData tData = sFilledContainerToData.get(new GT_ItemStack(aStack)); + return tData == null ? null : tData.fluid.copy(); + } + + public static ItemStack getContainerForFilledItem(ItemStack aStack, boolean aCheckIFluidContainerItems) { + if (isStackInvalid(aStack)) return null; + FluidContainerData tData = sFilledContainerToData.get(new GT_ItemStack(aStack)); + if (tData != null) return copyAmount(1, tData.emptyContainer); + if (aCheckIFluidContainerItems && aStack.getItem() instanceof IFluidContainerItem && ((IFluidContainerItem) aStack.getItem()).getCapacity(aStack) > 0) { + ((IFluidContainerItem) aStack.getItem()).drain(aStack = copyAmount(1, aStack), Integer.MAX_VALUE, true); + return aStack; + } + return null; + } + + public static ItemStack getContainerItem(ItemStack aStack, boolean aCheckIFluidContainerItems) { + if (isStackInvalid(aStack)) return null; + if (aStack.getItem().hasContainerItem(aStack)) return aStack.getItem().getContainerItem(aStack); + /** These are all special Cases, in which it is intended to have only GT Blocks outputting those Container Items */ + if (ItemList.Cell_Empty.isStackEqual(aStack, false, true)) return null; + if (ItemList.IC2_Fuel_Can_Filled.isStackEqual(aStack, false, true)) return ItemList.IC2_Fuel_Can_Empty.get(1); + if (aStack.getItem() == Items.potionitem || aStack.getItem() == Items.experience_bottle || ItemList.TF_Vial_FieryBlood.isStackEqual(aStack) || ItemList.TF_Vial_FieryTears.isStackEqual(aStack)) + return ItemList.Bottle_Empty.get(1); + + if (aCheckIFluidContainerItems && aStack.getItem() instanceof IFluidContainerItem && ((IFluidContainerItem) aStack.getItem()).getCapacity(aStack) > 0) { + ItemStack tStack = copyAmount(1, aStack); + ((IFluidContainerItem) aStack.getItem()).drain(tStack, Integer.MAX_VALUE, true); + if (!areStacksEqual(aStack, tStack)) return tStack; + return null; + } + + int tCapsuleCount = GT_ModHandler.getCapsuleCellContainerCount(aStack); + if (tCapsuleCount > 0) return ItemList.Cell_Empty.get(tCapsuleCount); + + if (ItemList.IC2_ForgeHammer.isStackEqual(aStack) || ItemList.IC2_WireCutter.isStackEqual(aStack)) + return copyMetaData(Items.feather.getDamage(aStack) + 1, aStack); + return null; + } + + public static synchronized boolean removeIC2BottleRecipe(ItemStack aContainer, ItemStack aInput, Map aRecipeList, ItemStack aOutput){ + if ((isStackInvalid(aInput) && isStackInvalid(aOutput) && isStackInvalid(aContainer)) || aRecipeList == null) return false; + boolean rReturn = false; + Iterator> tIterator = aRecipeList.entrySet().iterator(); + aOutput = GT_OreDictUnificator.get(aOutput); + while (tIterator.hasNext()) { + Map.Entry tEntry = tIterator.next(); + if (aInput == null || tEntry.getKey().matches(aContainer, aInput)) { + List tList = tEntry.getValue().items; + if (tList != null) for (ItemStack tOutput : tList) + if (aOutput == null || areStacksEqual(GT_OreDictUnificator.get(tOutput), aOutput)) { + tIterator.remove(); + rReturn = true; + break; + } + } + } + return rReturn; + } + + public static synchronized boolean removeSimpleIC2MachineRecipe(ItemStack aInput, Map aRecipeList, ItemStack aOutput) { + if ((isStackInvalid(aInput) && isStackInvalid(aOutput)) || aRecipeList == null) return false; + boolean rReturn = false; + Iterator> tIterator = aRecipeList.entrySet().iterator(); + aOutput = GT_OreDictUnificator.get(aOutput); + while (tIterator.hasNext()) { + Map.Entry tEntry = tIterator.next(); + if (aInput == null || tEntry.getKey().matches(aInput)) { + List tList = tEntry.getValue().items; + if (tList != null) for (ItemStack tOutput : tList) + if (aOutput == null || areStacksEqual(GT_OreDictUnificator.get(tOutput), aOutput)) { + tIterator.remove(); + rReturn = true; + break; + } + } + } + return rReturn; + } + + public static boolean addSimpleIC2MachineRecipe(ItemStack aInput, Map aRecipeList, NBTTagCompound aNBT, Object... aOutput) { + if (isStackInvalid(aInput) || aOutput.length == 0 || aRecipeList == null) return false; + ItemData tOreName = GT_OreDictUnificator.getAssociation(aInput); + for (int i = 0; i < aOutput.length; i++) { + if (aOutput[i] == null) { + GT_FML_LOGGER.info("EmptyIC2Output!" + aInput.getUnlocalizedName()); + return false; + } + } + ItemStack[] tStack = GT_OreDictUnificator.getStackArray(true, aOutput); + if(tStack==null||(tStack.length>0&>_Utility.areStacksEqual(aInput, tStack[0])))return false; + if (tOreName != null) { + if(tOreName.toString().equals("dustAsh")&&tStack[0].getUnlocalizedName().equals("tile.volcanicAsh"))return false; + aRecipeList.put(new RecipeInputOreDict(tOreName.toString(), aInput.stackSize), new RecipeOutput(aNBT, tStack)); + } else { + aRecipeList.put(new RecipeInputItemStack(copy(aInput), aInput.stackSize), new RecipeOutput(aNBT, tStack)); + } + return true; + } + + public static ItemStack getWrittenBook(String aMapping, ItemStack aStackToPutNBT) { + if (isStringInvalid(aMapping)) return null; + ItemStack rStack = GregTech_API.sBookList.get(aMapping); + if (rStack == null) return aStackToPutNBT; + if (aStackToPutNBT != null) { + aStackToPutNBT.setTagCompound(rStack.getTagCompound()); + return aStackToPutNBT; + } + return copyAmount(1, rStack); + } + + public static ItemStack getWrittenBook(String aMapping, String aTitle, String aAuthor, String... aPages) { + if (isStringInvalid(aMapping)) return null; + ItemStack rStack = GregTech_API.sBookList.get(aMapping); + if (rStack != null) return copyAmount(1, rStack); + if (isStringInvalid(aTitle) || isStringInvalid(aAuthor) || aPages.length <= 0) return null; + sBookCount++; + rStack = new ItemStack(Items.written_book, 1); + NBTTagCompound tNBT = new NBTTagCompound(); + tNBT.setString("title", GT_LanguageManager.addStringLocalization("Book." + aTitle + ".Name", aTitle)); + tNBT.setString("author", aAuthor); + NBTTagList tNBTList = new NBTTagList(); + for (byte i = 0; i < aPages.length; i++) { + aPages[i] = GT_LanguageManager.addStringLocalization("Book." + aTitle + ".Page" + ((i < 10) ? "0" + i : i), aPages[i]); + if (i < 48) { + if (aPages[i].length() < 256) + tNBTList.appendTag(new NBTTagString(aPages[i])); + else + GT_Log.err.println("WARNING: String for written Book too long! -> " + aPages[i]); + } else { + GT_Log.err.println("WARNING: Too much Pages for written Book! -> " + aTitle); + break; + } + } + tNBTList.appendTag(new NBTTagString("Credits to " + aAuthor + " for writing this Book. This was Book Nr. " + sBookCount + " at its creation. Gotta get 'em all!")); + tNBT.setTag("pages", tNBTList); + rStack.setTagCompound(tNBT); + GT_Log.out.println("GT_Mod: Added Book to Book List - Mapping: '" + aMapping + "' - Name: '" + aTitle + "' - Author: '" + aAuthor + "'"); + GregTech_API.sBookList.put(aMapping, rStack); + return copy(rStack); + } + + public static boolean doSoundAtClient(String aSoundName, int aTimeUntilNextSound, float aSoundStrength) { + return doSoundAtClient(aSoundName, aTimeUntilNextSound, aSoundStrength, GT.getThePlayer()); + } + + public static boolean doSoundAtClient(String aSoundName, int aTimeUntilNextSound, float aSoundStrength, Entity aEntity) { + if (aEntity == null) return false; + return doSoundAtClient(aSoundName, aTimeUntilNextSound, aSoundStrength, aEntity.posX, aEntity.posY, aEntity.posZ); + } + + public static boolean doSoundAtClient(String aSoundName, int aTimeUntilNextSound, float aSoundStrength, double aX, double aY, double aZ) { + return doSoundAtClient(aSoundName, aTimeUntilNextSound, aSoundStrength, 1.01818028F, aX, aY, aZ); + } + + public static boolean doSoundAtClient(String aSoundName, int aTimeUntilNextSound, float aSoundStrength, float aSoundModulation, double aX, double aY, double aZ) { + if (isStringInvalid(aSoundName) || !FMLCommonHandler.instance().getEffectiveSide().isClient() || GT.getThePlayer() == null || !GT.getThePlayer().worldObj.isRemote) + return false; + if (GregTech_API.sMultiThreadedSounds) + new Thread(new GT_Runnable_Sound(GT.getThePlayer().worldObj, MathHelper.floor_double(aX), MathHelper.floor_double(aY), MathHelper.floor_double(aZ), aTimeUntilNextSound, aSoundName, aSoundStrength, aSoundModulation), "Sound Effect").start(); + else + new GT_Runnable_Sound(GT.getThePlayer().worldObj, MathHelper.floor_double(aX), MathHelper.floor_double(aY), MathHelper.floor_double(aZ), aTimeUntilNextSound, aSoundName, aSoundStrength, aSoundModulation).run(); + return true; + } + + public static boolean sendSoundToPlayers(World aWorld, String aSoundName, float aSoundStrength, float aSoundModulation, int aX, int aY, int aZ) { + if (isStringInvalid(aSoundName) || aWorld == null || aWorld.isRemote) return false; + NW.sendPacketToAllPlayersInRange(aWorld, new GT_Packet_Sound(aSoundName, aSoundStrength, aSoundModulation, aX, (short) aY, aZ), aX, aZ); + return true; + } + + public static int stackToInt(ItemStack aStack) { + if (isStackInvalid(aStack)) return 0; + return Item.getIdFromItem(aStack.getItem()) | (Items.feather.getDamage(aStack) << 16); + } + + public static int stackToWildcard(ItemStack aStack) { + if (isStackInvalid(aStack)) return 0; + return Item.getIdFromItem(aStack.getItem()) | (W << 16); + } + + public static ItemStack intToStack(int aStack) { + int tID = aStack & (~0 >>> 16), tMeta = aStack >>> 16; + Item tItem = Item.getItemById(tID); + if (tItem != null) return new ItemStack(tItem, 1, tMeta); + return null; + } + + public static Integer[] stacksToIntegerArray(ItemStack... aStacks) { + Integer[] rArray = new Integer[aStacks.length]; + for (int i = 0; i < rArray.length; i++) { + rArray[i] = stackToInt(aStacks[i]); + } + return rArray; + } + + public static int[] stacksToIntArray(ItemStack... aStacks) { + int[] rArray = new int[aStacks.length]; + for (int i = 0; i < rArray.length; i++) { + rArray[i] = stackToInt(aStacks[i]); + } + return rArray; + } + + public static boolean arrayContains(Object aObject, Object... aObjects) { + return listContains(aObject, Arrays.asList(aObjects)); + } + + public static boolean listContains(Object aObject, Collection aObjects) { + if (aObjects == null) return false; + return aObjects.contains(aObject); + } + + public static boolean arrayContainsNonNull(T... aArray) { + if (aArray != null) for (Object tObject : aArray) if (tObject != null) return true; + return false; + } + + public static ArrayList getArrayListWithoutNulls(T... aArray) { + if (aArray == null) return new ArrayList(); + ArrayList rList = new ArrayList(Arrays.asList(aArray)); + for (int i = 0; i < rList.size(); i++) if (rList.get(i) == null) rList.remove(i--); + return rList; + } + + public static ArrayList getArrayListWithoutTrailingNulls(T... aArray) { + if (aArray == null) return new ArrayList(); + ArrayList rList = new ArrayList(Arrays.asList(aArray)); + for (int i = rList.size() - 1; i >= 0 && rList.get(i) == null; ) rList.remove(i--); + return rList; + } + + public static Block getBlock(Object aBlock) { + return (Block) aBlock; + } + + public static Block getBlockFromStack(ItemStack itemStack) { + if (isStackInvalid(itemStack)) return Blocks.air; + return getBlockFromItem(itemStack.getItem()); + } + + public static Block getBlockFromItem(Item item) { + return Block.getBlockFromItem(item); + } + + public static boolean isBlockValid(Object aBlock) { + return (aBlock instanceof Block); + } + + public static boolean isBlockInvalid(Object aBlock) { + return aBlock == null || !(aBlock instanceof Block); + } + + public static boolean isStringValid(Object aString) { + return aString != null && !aString.toString().isEmpty(); + } + + public static boolean isStringInvalid(Object aString) { + return aString == null || aString.toString().isEmpty(); + } + + public static boolean isStackValid(Object aStack) { + return (aStack instanceof ItemStack) && ((ItemStack) aStack).getItem() != null && ((ItemStack) aStack).stackSize >= 0; + } + + public static boolean isStackInvalid(Object aStack) { + return aStack == null || !(aStack instanceof ItemStack) || ((ItemStack) aStack).getItem() == null || ((ItemStack) aStack).stackSize < 0; + } + + public static boolean isDebugItem(ItemStack aStack) { + return /*ItemList.Armor_Cheat.isStackEqual(aStack, T, T) || */areStacksEqual(GT_ModHandler.getIC2Item("debug", 1), aStack, true); + } + + public static ItemStack updateItemStack(ItemStack aStack) { + if (isStackValid(aStack) && aStack.getItem() instanceof GT_Generic_Item) + ((GT_Generic_Item) aStack.getItem()).isItemStackUsable(aStack); + return aStack; + } + + public static boolean isOpaqueBlock(World aWorld, int aX, int aY, int aZ) { + return aWorld.getBlock(aX, aY, aZ).isOpaqueCube(); + } + + public static boolean isBlockAir(World aWorld, int aX, int aY, int aZ) { + return aWorld.getBlock(aX, aY, aZ).isAir(aWorld, aX, aY, aZ); + } + + public static boolean hasBlockHitBox(World aWorld, int aX, int aY, int aZ) { + return aWorld.getBlock(aX, aY, aZ).getCollisionBoundingBoxFromPool(aWorld, aX, aY, aZ) != null; + } + + public static void setCoordsOnFire(World aWorld, int aX, int aY, int aZ, boolean aReplaceCenter) { + if (aReplaceCenter) + if (aWorld.getBlock(aX, aY, aZ).getCollisionBoundingBoxFromPool(aWorld, aX, aY, aZ) == null) + aWorld.setBlock(aX, aY, aZ, Blocks.fire); + if (aWorld.getBlock(aX + 1, aY, aZ).getCollisionBoundingBoxFromPool(aWorld, aX + 1, aY, aZ) == null) + aWorld.setBlock(aX + 1, aY, aZ, Blocks.fire); + if (aWorld.getBlock(aX - 1, aY, aZ).getCollisionBoundingBoxFromPool(aWorld, aX - 1, aY, aZ) == null) + aWorld.setBlock(aX - 1, aY, aZ, Blocks.fire); + if (aWorld.getBlock(aX, aY + 1, aZ).getCollisionBoundingBoxFromPool(aWorld, aX, aY + 1, aZ) == null) + aWorld.setBlock(aX, aY + 1, aZ, Blocks.fire); + if (aWorld.getBlock(aX, aY - 1, aZ).getCollisionBoundingBoxFromPool(aWorld, aX, aY - 1, aZ) == null) + aWorld.setBlock(aX, aY - 1, aZ, Blocks.fire); + if (aWorld.getBlock(aX, aY, aZ + 1).getCollisionBoundingBoxFromPool(aWorld, aX, aY, aZ + 1) == null) + aWorld.setBlock(aX, aY, aZ + 1, Blocks.fire); + if (aWorld.getBlock(aX, aY, aZ - 1).getCollisionBoundingBoxFromPool(aWorld, aX, aY, aZ - 1) == null) + aWorld.setBlock(aX, aY, aZ - 1, Blocks.fire); + } + + public static ItemStack getProjectile(SubTag aProjectileType, IInventory aInventory) { + if (aInventory != null) for (int i = 0, j = aInventory.getSizeInventory(); i < j; i++) { + ItemStack rStack = aInventory.getStackInSlot(i); + if (isStackValid(rStack) && rStack.getItem() instanceof IProjectileItem && ((IProjectileItem) rStack.getItem()).hasProjectile(aProjectileType, rStack)) + return updateItemStack(rStack); + } + return null; + } + + public static void removeNullStacksFromInventory(IInventory aInventory) { + if (aInventory != null) for (int i = 0, j = aInventory.getSizeInventory(); i < j; i++) { + ItemStack tStack = aInventory.getStackInSlot(i); + if (tStack != null && (tStack.stackSize == 0 || tStack.getItem() == null)) + aInventory.setInventorySlotContents(i, null); + } + } + + /** + * Initializes a new texture page. + */ + public static boolean addTexturePage(byte page){ + if(Textures.BlockIcons.casingTexturePages[page]==null){ + Textures.BlockIcons.casingTexturePages[page]=new ITexture[128]; + return true; + } + return false; + } + + /** + * Converts a Number to a String + */ + public static String parseNumberToString(int aNumber) { + boolean temp = true, negative = false; + + if (aNumber < 0) { + aNumber *= -1; + negative = true; + } + + StringBuilder tStringB = new StringBuilder(); + for (int i = 1000000000; i > 0; i /= 10) { + int tDigit = (aNumber / i) % 10; + if (temp && tDigit != 0) temp = false; + if (!temp) { + tStringB.append(tDigit); + if (i != 1) for (int j = i; j > 0; j /= 1000) if (j == 1) tStringB.append(","); + } + } + + String tString = tStringB.toString(); + + if (tString.equals(E)) tString = "0"; + + return negative ? "-" + tString : tString; + } + + public static NBTTagCompound getNBTContainingBoolean(NBTTagCompound aNBT, Object aTag, boolean aValue) { + if (aNBT == null) aNBT = new NBTTagCompound(); + aNBT.setBoolean(aTag.toString(), aValue); + return aNBT; + } + + public static NBTTagCompound getNBTContainingByte(NBTTagCompound aNBT, Object aTag, byte aValue) { + if (aNBT == null) aNBT = new NBTTagCompound(); + aNBT.setByte(aTag.toString(), aValue); + return aNBT; + } + + public static NBTTagCompound getNBTContainingShort(NBTTagCompound aNBT, Object aTag, short aValue) { + if (aNBT == null) aNBT = new NBTTagCompound(); + aNBT.setShort(aTag.toString(), aValue); + return aNBT; + } + + public static NBTTagCompound getNBTContainingInteger(NBTTagCompound aNBT, Object aTag, int aValue) { + if (aNBT == null) aNBT = new NBTTagCompound(); + aNBT.setInteger(aTag.toString(), aValue); + return aNBT; + } + + public static NBTTagCompound getNBTContainingFloat(NBTTagCompound aNBT, Object aTag, float aValue) { + if (aNBT == null) aNBT = new NBTTagCompound(); + aNBT.setFloat(aTag.toString(), aValue); + return aNBT; + } + + public static NBTTagCompound getNBTContainingDouble(NBTTagCompound aNBT, Object aTag, double aValue) { + if (aNBT == null) aNBT = new NBTTagCompound(); + aNBT.setDouble(aTag.toString(), aValue); + return aNBT; + } + + public static NBTTagCompound getNBTContainingString(NBTTagCompound aNBT, Object aTag, Object aValue) { + if (aNBT == null) aNBT = new NBTTagCompound(); + if (aValue == null) return aNBT; + aNBT.setString(aTag.toString(), aValue.toString()); + return aNBT; + } + + public static boolean isWearingFullFrostHazmat(EntityLivingBase aEntity) { + for (byte i = 1; i < 5; i++) + if (!isStackInList(aEntity.getEquipmentInSlot(i), GregTech_API.sFrostHazmatList)) return false; + return true; + } + + public static boolean isWearingFullHeatHazmat(EntityLivingBase aEntity) { + for (byte i = 1; i < 5; i++) + if (!isStackInList(aEntity.getEquipmentInSlot(i), GregTech_API.sHeatHazmatList)) return false; + return true; + } + + public static boolean isWearingFullBioHazmat(EntityLivingBase aEntity) { + for (byte i = 1; i < 5; i++) + if (!isStackInList(aEntity.getEquipmentInSlot(i), GregTech_API.sBioHazmatList)) return false; + return true; + } + + public static boolean isWearingFullRadioHazmat(EntityLivingBase aEntity) { + for (byte i = 1; i < 5; i++) + if (!isStackInList(aEntity.getEquipmentInSlot(i), GregTech_API.sRadioHazmatList)) return false; + return true; + } + + public static boolean isWearingFullElectroHazmat(EntityLivingBase aEntity) { + for (byte i = 1; i < 5; i++) + if (!isStackInList(aEntity.getEquipmentInSlot(i), GregTech_API.sElectroHazmatList)) return false; + return true; + } + + public static boolean isWearingFullGasHazmat(EntityLivingBase aEntity) { + for (byte i = 1; i < 5; i++) + if (!isStackInList(aEntity.getEquipmentInSlot(i), GregTech_API.sGasHazmatList)) return false; + return true; + } + + public static float getHeatDamageFromItem(ItemStack aStack) { + ItemData tData = GT_OreDictUnificator.getItemData(aStack); + return tData == null ? 0 : (tData.mPrefix == null ? 0 : tData.mPrefix.mHeatDamage) + (tData.hasValidMaterialData() ? tData.mMaterial.mMaterial.mHeatDamage : 0); + } + + public static int getRadioactivityLevel(ItemStack aStack) { + ItemData tData = GT_OreDictUnificator.getItemData(aStack); + if (tData != null && tData.hasValidMaterialData()) { + if (tData.mMaterial.mMaterial.mEnchantmentArmors instanceof Enchantment_Radioactivity) + return tData.mMaterial.mMaterial.mEnchantmentArmorsLevel; + if (tData.mMaterial.mMaterial.mEnchantmentTools instanceof Enchantment_Radioactivity) + return tData.mMaterial.mMaterial.mEnchantmentToolsLevel; + } + return EnchantmentHelper.getEnchantmentLevel(Enchantment_Radioactivity.INSTANCE.effectId, aStack); + } + + public static boolean isImmuneToBreathingGasses(EntityLivingBase aEntity) { + return isWearingFullGasHazmat(aEntity); + } + + public static boolean applyHeatDamage(EntityLivingBase aEntity, float aDamage) { + if (aDamage > 0 && aEntity != null && aEntity.getActivePotionEffect(Potion.fireResistance) == null && !isWearingFullHeatHazmat(aEntity)) { + aEntity.attackEntityFrom(GT_DamageSources.getHeatDamage(), aDamage); + return true; + } + return false; + } + + public static boolean applyFrostDamage(EntityLivingBase aEntity, float aDamage) { + if (aDamage > 0 && aEntity != null && !isWearingFullFrostHazmat(aEntity)) { + aEntity.attackEntityFrom(GT_DamageSources.getFrostDamage(), aDamage); + return true; + } + return false; + } + + public static boolean applyElectricityDamage(EntityLivingBase aEntity, long aVoltage, long aAmperage) { + long aDamage = getTier(aVoltage) * aAmperage * 4; + if (aDamage > 0 && aEntity != null && !isWearingFullElectroHazmat(aEntity)) { + aEntity.attackEntityFrom(GT_DamageSources.getElectricDamage(), aDamage); + return true; + } + return false; + } + + public static boolean applyRadioactivity(EntityLivingBase aEntity, int aLevel, int aAmountOfItems) { + if (aLevel > 0 && aEntity != null && aEntity.getCreatureAttribute() != EnumCreatureAttribute.UNDEAD && aEntity.getCreatureAttribute() != EnumCreatureAttribute.ARTHROPOD && !isWearingFullRadioHazmat(aEntity)) { + PotionEffect tEffect = null; + aEntity.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, aLevel * 140 * aAmountOfItems + Math.max(0, ((tEffect = aEntity.getActivePotionEffect(Potion.moveSlowdown)) == null ? 0 : tEffect.getDuration())), Math.max(0, (5 * aLevel) / 7))); + aEntity.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, aLevel * 150 * aAmountOfItems + Math.max(0, ((tEffect = aEntity.getActivePotionEffect(Potion.digSlowdown)) == null ? 0 : tEffect.getDuration())), Math.max(0, (5 * aLevel) / 7))); + aEntity.addPotionEffect(new PotionEffect(Potion.confusion.id, aLevel * 130 * aAmountOfItems + Math.max(0, ((tEffect = aEntity.getActivePotionEffect(Potion.confusion)) == null ? 0 : tEffect.getDuration())), Math.max(0, (5 * aLevel) / 7))); + aEntity.addPotionEffect(new PotionEffect(Potion.weakness.id, aLevel * 150 * aAmountOfItems + Math.max(0, ((tEffect = aEntity.getActivePotionEffect(Potion.weakness)) == null ? 0 : tEffect.getDuration())), Math.max(0, (5 * aLevel) / 7))); + aEntity.addPotionEffect(new PotionEffect(Potion.hunger.id, aLevel * 130 * aAmountOfItems + Math.max(0, ((tEffect = aEntity.getActivePotionEffect(Potion.hunger)) == null ? 0 : tEffect.getDuration())), Math.max(0, (5 * aLevel) / 7))); + aEntity.addPotionEffect(new PotionEffect(24 /* IC2 Radiation */, aLevel * 180 * aAmountOfItems + Math.max(0, ((tEffect = aEntity.getActivePotionEffect(Potion.potionTypes[24])) == null ? 0 : tEffect.getDuration())), Math.max(0, (5 * aLevel) / 7))); + return true; + } + return false; + } + + public static ItemStack setStack(Object aSetStack, Object aToStack) { + if (isStackInvalid(aSetStack) || isStackInvalid(aToStack)) return null; + ((ItemStack) aSetStack).func_150996_a(((ItemStack) aToStack).getItem()); + ((ItemStack) aSetStack).stackSize = ((ItemStack) aToStack).stackSize; + Items.feather.setDamage((ItemStack) aSetStack, Items.feather.getDamage((ItemStack) aToStack)); + ((ItemStack) aSetStack).setTagCompound(((ItemStack) aToStack).getTagCompound()); + return (ItemStack) aSetStack; + } + + public static FluidStack[] copyFluidArray(FluidStack... aStacks) { + FluidStack[] rStacks = new FluidStack[aStacks.length]; + for (int i = 0; i < aStacks.length; i++) if (aStacks[i] != null) rStacks[i] = aStacks[i].copy(); + return rStacks; + } + + public static ItemStack[] copyStackArray(Object... aStacks) { + ItemStack[] rStacks = new ItemStack[aStacks.length]; + for (int i = 0; i < aStacks.length; i++) rStacks[i] = copy(aStacks[i]); + return rStacks; + } + + public static ItemStack copy(Object... aStacks) { + for (Object tStack : aStacks) if (isStackValid(tStack)) return ((ItemStack) tStack).copy(); + return null; + } + + public static ItemStack copyAmount(long aAmount, Object... aStacks) { + ItemStack rStack = copy(aStacks); + if (isStackInvalid(rStack)) return null; + if (aAmount > 64) aAmount = 64; + else if (aAmount == -1) aAmount = 111; + else if (aAmount < 0) aAmount = 0; + rStack.stackSize = (byte) aAmount; + return rStack; + } + + public static ItemStack copyMetaData(long aMetaData, Object... aStacks) { + ItemStack rStack = copy(aStacks); + if (isStackInvalid(rStack)) return null; + Items.feather.setDamage(rStack, (short) aMetaData); + return rStack; + } + + public static ItemStack copyAmountAndMetaData(long aAmount, long aMetaData, Object... aStacks) { + ItemStack rStack = copyAmount(aAmount, aStacks); + if (isStackInvalid(rStack)) return null; + Items.feather.setDamage(rStack, (short) aMetaData); + return rStack; + } + + /** + * returns a copy of an ItemStack with its Stacksize being multiplied by aMultiplier + */ + public static ItemStack mul(long aMultiplier, Object... aStacks) { + ItemStack rStack = copy(aStacks); + if (rStack == null) return null; + rStack.stackSize *= aMultiplier; + return rStack; + } + + /** + * Loads an ItemStack properly. + */ + public static ItemStack loadItem(NBTTagCompound aNBT, String aTagName) { + return loadItem(aNBT.getCompoundTag(aTagName)); + } + + public static FluidStack loadFluid(NBTTagCompound aNBT, String aTagName) { + return loadFluid(aNBT.getCompoundTag(aTagName)); + } + + /** + * Loads an ItemStack properly. + */ + public static ItemStack loadItem(NBTTagCompound aNBT) { + if (aNBT == null) return null; + ItemStack rStack = ItemStack.loadItemStackFromNBT(aNBT); + try { + if (rStack != null && (rStack.getItem().getClass().getName().startsWith("ic2.core.migration"))) { + rStack.getItem().onUpdate(rStack, DW, null, 0, false); + } + } catch (Throwable e) { + e.printStackTrace(GT_Log.err); + } + return GT_OreDictUnificator.get(true, rStack); + } + + /** + * Loads an FluidStack properly. + */ + public static FluidStack loadFluid(NBTTagCompound aNBT) { + if (aNBT == null) return null; + return FluidStack.loadFluidStackFromNBT(aNBT); + } + + public static E selectItemInList(int aIndex, E aReplacement, List aList) { + if (aList == null || aList.isEmpty()) return aReplacement; + if (aList.size() <= aIndex) return aList.get(aList.size() - 1); + if (aIndex < 0) return aList.get(0); + return aList.get(aIndex); + } + + public static E selectItemInList(int aIndex, E aReplacement, E... aList) { + if (aList == null || aList.length == 0) return aReplacement; + if (aList.length <= aIndex) return aList[aList.length - 1]; + if (aIndex < 0) return aList[0]; + return aList[aIndex]; + } + + public static boolean isStackInList(ItemStack aStack, Collection aList) { + if (aStack == null) { + return false; + } + return isStackInList(new GT_ItemStack(aStack), aList); + } + + public static boolean isStackInList(GT_ItemStack aStack, Collection aList) { + return aStack != null && (aList.contains(aStack) || aList.contains(new GT_ItemStack(aStack.mItem, aStack.mStackSize, W))); + } + + /** + * re-maps all Keys of a Map after the Keys were weakened. + */ + public static Map reMap(Map aMap) { + Map tMap = new /*Concurrent*/HashMap(); + tMap.putAll(aMap); + aMap.clear(); + aMap.putAll(tMap); + return aMap; + } + + /** + * Why the fuck do neither Java nor Guava have a Function to do this? + */ + public static LinkedHashMap sortMapByValuesAcending(Map aMap) { + List> tEntrySet = new LinkedList>(aMap.entrySet()); + Collections.sort(tEntrySet, new Comparator>() { + @Override + public int compare(Entry aValue1, Entry aValue2) { + return aValue1.getValue().compareTo(aValue2.getValue()); + } + }); + LinkedHashMap rMap = new LinkedHashMap(); + for (Map.Entry tEntry : tEntrySet) rMap.put(tEntry.getKey(), tEntry.getValue()); + return rMap; + } + + /** + * Why the fuck do neither Java nor Guava have a Function to do this? + */ + public static LinkedHashMap sortMapByValuesDescending(Map aMap) { + List> tEntrySet = new LinkedList>(aMap.entrySet()); + Collections.sort(tEntrySet, new Comparator>() { + @Override + public int compare(Entry aValue1, Entry aValue2) { + return aValue2.getValue().compareTo(aValue1.getValue());//FB: RV - RV_NEGATING_RESULT_OF_COMPARETO + } + }); + LinkedHashMap rMap = new LinkedHashMap(); + for (Map.Entry tEntry : tEntrySet) rMap.put(tEntry.getKey(), tEntry.getValue()); + return rMap; + } + + /** + * Translates a Material Amount into an Amount of Fluid in Fluid Material Units. + */ + public static long translateMaterialToFluidAmount(long aMaterialAmount, boolean aRoundUp) { + return translateMaterialToAmount(aMaterialAmount, L, aRoundUp); + } + + /** + * Translates a Material Amount into an Amount of Fluid. Second Parameter for things like Bucket Amounts (1000) and similar + */ + public static long translateMaterialToAmount(long aMaterialAmount, long aAmountPerUnit, boolean aRoundUp) { + return Math.max(0, ((aMaterialAmount * aAmountPerUnit) / M) + (aRoundUp && (aMaterialAmount * aAmountPerUnit) % M > 0 ? 1 : 0)); + } + + /** + * This checks if the Dimension is really a Dimension and not another Planet or something. + * Used for my Teleporter. + */ + public static boolean isRealDimension(int aDimensionID) { + if(aDimensionID<=1 && aDimensionID>=-1 && !GregTech_API.sDimensionalList.contains(aDimensionID)) return true; + return !GregTech_API.sDimensionalList.contains(aDimensionID) && DimensionManager.isDimensionRegistered(aDimensionID); + } + + //public static boolean isRealDimension(int aDimensionID) { + // try { + // if (DimensionManager.getProvider(aDimensionID).getClass().getName().contains("com.xcompwiz.mystcraft")) + // return true; + // } catch (Throwable e) {/*Do nothing*/} + // try { + // if (DimensionManager.getProvider(aDimensionID).getClass().getName().contains("TwilightForest")) return true; + // } catch (Throwable e) {/*Do nothing*/} + // try { + // if (DimensionManager.getProvider(aDimensionID).getClass().getName().contains("galacticraft")) return true; + // } catch (Throwable e) {/*Do nothing*/} + // return GregTech_API.sDimensionalList.contains(aDimensionID); + //} + + public static boolean moveEntityToDimensionAtCoords(Entity entity, int aDimension, double aX, double aY, double aZ) { + //Credit goes to BrandonCore Author :!: + + if (entity == null || entity.worldObj.isRemote) return false; + if (entity.ridingEntity != null) entity.mountEntity(null); + if (entity.riddenByEntity != null) entity.riddenByEntity.mountEntity(null); + + World startWorld = entity.worldObj; + World destinationWorld = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(aDimension); + + if (destinationWorld == null) {return false;} + + boolean interDimensional = startWorld.provider.dimensionId != destinationWorld.provider.dimensionId; + if(!interDimensional)return false; + startWorld.updateEntityWithOptionalForce(entity, false);//added + + if ((entity instanceof EntityPlayerMP) && interDimensional) { + EntityPlayerMP player = (EntityPlayerMP) entity; + player.closeScreen();//added + player.dimension = aDimension; + player.playerNetServerHandler.sendPacket(new S07PacketRespawn(player.dimension, player.worldObj.difficultySetting, destinationWorld.getWorldInfo().getTerrainType(), player.theItemInWorldManager.getGameType())); + ((WorldServer) startWorld).getPlayerManager().removePlayer(player); + + startWorld.playerEntities.remove(player); + startWorld.updateAllPlayersSleepingFlag(); + int i = entity.chunkCoordX; + int j = entity.chunkCoordZ; + if ((entity.addedToChunk) && (startWorld.getChunkProvider().chunkExists(i, j))) { + startWorld.getChunkFromChunkCoords(i, j).removeEntity(entity); + startWorld.getChunkFromChunkCoords(i, j).isModified = true; + } + startWorld.loadedEntityList.remove(entity); + startWorld.onEntityRemoved(entity); + } + + entity.setLocationAndAngles(aX, aY, aZ, entity.rotationYaw, entity.rotationPitch); + + ((WorldServer) destinationWorld).theChunkProviderServer.loadChunk((int) aX >> 4, (int) aZ >> 4); + + destinationWorld.theProfiler.startSection("placing"); + if (interDimensional) { + if (!(entity instanceof EntityPlayer)) { + NBTTagCompound entityNBT = new NBTTagCompound(); + entity.isDead = false; + entityNBT.setString("id", EntityList.getEntityString(entity)); + entity.writeToNBT(entityNBT); + entity.isDead = true; + entity = EntityList.createEntityFromNBT(entityNBT, destinationWorld); + if (entity == null) { + return false; + } + entity.dimension = destinationWorld.provider.dimensionId; + } + destinationWorld.spawnEntityInWorld(entity); + entity.setWorld(destinationWorld); + } + entity.setLocationAndAngles(aX, aY, aZ, entity.rotationYaw, entity.rotationPitch); + + destinationWorld.updateEntityWithOptionalForce(entity, false); + entity.setLocationAndAngles(aX, aY, aZ, entity.rotationYaw, entity.rotationPitch); + + if ((entity instanceof EntityPlayerMP)) { + EntityPlayerMP player = (EntityPlayerMP) entity; + if (interDimensional) { + player.mcServer.getConfigurationManager().func_72375_a(player, (WorldServer) destinationWorld); + } + player.playerNetServerHandler.setPlayerLocation(aX, aY, aZ, player.rotationYaw, player.rotationPitch); + } + + destinationWorld.updateEntityWithOptionalForce(entity, false); + + if (((entity instanceof EntityPlayerMP)) && interDimensional) { + EntityPlayerMP player = (EntityPlayerMP) entity; + player.theItemInWorldManager.setWorld((WorldServer) destinationWorld); + player.mcServer.getConfigurationManager().updateTimeAndWeatherForPlayer(player, (WorldServer) destinationWorld); + player.mcServer.getConfigurationManager().syncPlayerInventory(player); + + for (PotionEffect potionEffect : (Iterable) player.getActivePotionEffects()) { + player.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(player.getEntityId(), potionEffect)); + } + + player.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel)); + FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, startWorld.provider.dimensionId, destinationWorld.provider.dimensionId); + } + entity.setLocationAndAngles(aX, aY, aZ, entity.rotationYaw, entity.rotationPitch); + + destinationWorld.theProfiler.endSection(); + entity.fallDistance = 0; + return true; + } + + public static int getScaleCoordinates(double aValue, int aScale) { + return (int)Math.floor(aValue / aScale); + } + + public static int getCoordinateScan(ArrayList aList, EntityPlayer aPlayer, World aWorld, int aScanLevel, int aX, int aY, int aZ, int aSide, float aClickX, float aClickY, float aClickZ) { + if (aList == null) return 0; + + ArrayList tList = new ArrayList(); + int rEUAmount = 0; + + TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); + + Block tBlock = aWorld.getBlock(aX, aY, aZ); + + tList.add("----- X: " +EnumChatFormatting.AQUA+ aX +EnumChatFormatting.RESET+ " Y: " +EnumChatFormatting.AQUA+ aY +EnumChatFormatting.RESET+ " Z: " +EnumChatFormatting.AQUA+ aZ +EnumChatFormatting.RESET+ " D: " +EnumChatFormatting.AQUA+ aWorld.provider.dimensionId +EnumChatFormatting.RESET+ " -----"); + try { + if (tTileEntity != null && tTileEntity instanceof IInventory) + tList.add(trans("162","Name: ") +EnumChatFormatting.BLUE+ ((IInventory) tTileEntity).getInventoryName() +EnumChatFormatting.RESET+ trans("163"," MetaData: ") +EnumChatFormatting.AQUA+ aWorld.getBlockMetadata(aX, aY, aZ) +EnumChatFormatting.RESET); + else + tList.add(trans("162","Name: ") +EnumChatFormatting.BLUE+ tBlock.getUnlocalizedName() +EnumChatFormatting.RESET+ trans("163"," MetaData: ") +EnumChatFormatting.AQUA+ aWorld.getBlockMetadata(aX, aY, aZ) +EnumChatFormatting.RESET); + + tList.add(trans("164","Hardness: ") +EnumChatFormatting.YELLOW+ tBlock.getBlockHardness(aWorld, aX, aY, aZ) +EnumChatFormatting.RESET+ trans("165"," Blast Resistance: ") +EnumChatFormatting.YELLOW+ tBlock.getExplosionResistance(aPlayer, aWorld, aX, aY, aZ, aPlayer.posX, aPlayer.posY, aPlayer.posZ) +EnumChatFormatting.RESET); + if (tBlock.isBeaconBase(aWorld, aX, aY, aZ, aX, aY + 1, aZ)) tList.add(EnumChatFormatting.GOLD+ trans("166","Is valid Beacon Pyramid Material") +EnumChatFormatting.RESET); + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + if (tTileEntity != null) { + try { + if (tTileEntity instanceof IFluidHandler) { + rEUAmount += 500; + FluidTankInfo[] tTanks = ((IFluidHandler) tTileEntity).getTankInfo(ForgeDirection.getOrientation(aSide)); + if (tTanks != null) for (byte i = 0; i < tTanks.length; i++) { + tList.add(trans("167","Tank ") + i + ": " +EnumChatFormatting.GREEN+ GT_Utility.formatNumbers((tTanks[i].fluid == null ? 0 : tTanks[i].fluid.amount)) +EnumChatFormatting.RESET+ " L / " +EnumChatFormatting.YELLOW+ GT_Utility.formatNumbers(tTanks[i].capacity) +EnumChatFormatting.RESET+ " L " +EnumChatFormatting.GOLD+ getFluidName(tTanks[i].fluid, true)+EnumChatFormatting.RESET); + } + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + try { + if (tTileEntity instanceof ic2.api.reactor.IReactorChamber) { + rEUAmount += 500; + tTileEntity = (TileEntity) (((ic2.api.reactor.IReactorChamber) tTileEntity).getReactor()); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + try { + if (tTileEntity instanceof ic2.api.reactor.IReactor) { + rEUAmount += 500; + tList.add(trans("168","Heat: ") +EnumChatFormatting.GREEN+ ((ic2.api.reactor.IReactor) tTileEntity).getHeat() +EnumChatFormatting.RESET+ " / " +EnumChatFormatting.YELLOW+ ((ic2.api.reactor.IReactor) tTileEntity).getMaxHeat()+EnumChatFormatting.RESET); + tList.add(trans("169","HEM: ") +EnumChatFormatting.YELLOW+((ic2.api.reactor.IReactor) tTileEntity).getHeatEffectModifier() +EnumChatFormatting.RESET/*+ trans("170"," Base EU Output: ")/* + ((ic2.api.reactor.IReactor)tTileEntity).getOutput()*/); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + try { + if (tTileEntity instanceof ic2.api.tile.IWrenchable) { + rEUAmount += 100; + tList.add(trans("171","Facing: ") +EnumChatFormatting.GREEN+ ((ic2.api.tile.IWrenchable) tTileEntity).getFacing() +EnumChatFormatting.RESET+ trans("172"," / Chance: ") +EnumChatFormatting.YELLOW+ (((ic2.api.tile.IWrenchable) tTileEntity).getWrenchDropRate() * 100) +EnumChatFormatting.RESET+ "%"); + tList.add(((ic2.api.tile.IWrenchable) tTileEntity).wrenchCanRemove(aPlayer) ? EnumChatFormatting.GREEN+ trans("173","You can remove this with a Wrench") +EnumChatFormatting.RESET : EnumChatFormatting.RED+ trans("174","You can NOT remove this with a Wrench") +EnumChatFormatting.RESET); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + try { + if (tTileEntity instanceof ic2.api.energy.tile.IEnergyTile) { + rEUAmount += 200; + //aList.add(((ic2.api.energy.tile.IEnergyTile)tTileEntity).isAddedToEnergyNet()?"Added to E-net":"Not added to E-net! Bug?"); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + try { + if (tTileEntity instanceof ic2.api.energy.tile.IEnergySink) { + rEUAmount += 400; + //aList.add("Demanded Energy: " + ((ic2.api.energy.tile.IEnergySink)tTileEntity).demandsEnergy()); + //tList.add("Max Safe Input: " + getTier(((ic2.api.energy.tile.IEnergySink)tTileEntity).getSinkTier())); + //tList.add("Max Safe Input: " + ((ic2.api.energy.tile.IEnergySink)tTileEntity).getMaxSafeInput()); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + try { + if (tTileEntity instanceof ic2.api.energy.tile.IEnergySource) { + rEUAmount += 400; + //aList.add("Max Energy Output: " + ((ic2.api.energy.tile.IEnergySource)tTileEntity).getMaxEnergyOutput()); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + try { + if (tTileEntity instanceof ic2.api.energy.tile.IEnergyConductor) { + rEUAmount += 200; + tList.add(trans("175","Conduction Loss: ") +EnumChatFormatting.YELLOW+ ((ic2.api.energy.tile.IEnergyConductor) tTileEntity).getConductionLoss()+EnumChatFormatting.RESET); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + try { + if (tTileEntity instanceof ic2.api.tile.IEnergyStorage) { + rEUAmount += 200; + tList.add(trans("176","Contained Energy: ") +EnumChatFormatting.YELLOW+ ((ic2.api.tile.IEnergyStorage) tTileEntity).getStored() +EnumChatFormatting.RESET+ " EU / " +EnumChatFormatting.YELLOW+ ((ic2.api.tile.IEnergyStorage) tTileEntity).getCapacity()+EnumChatFormatting.RESET+" EU"); + //aList.add(((ic2.api.tile.IEnergyStorage)tTileEntity).isTeleporterCompatible(ic2.api.Direction.YP)?"Teleporter Compatible":"Not Teleporter Compatible"); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + try { + if (tTileEntity instanceof IUpgradableMachine) { + rEUAmount += 500; + if (((IUpgradableMachine) tTileEntity).hasMufflerUpgrade()) tList.add(EnumChatFormatting.GREEN+ trans("177","Has Muffler Upgrade") +EnumChatFormatting.RESET); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + try { + if (tTileEntity instanceof IMachineProgress) { + rEUAmount += 400; + int tValue = 0; + if (0 < (tValue = ((IMachineProgress) tTileEntity).getMaxProgress())) + tList.add(trans("178","Progress/Load: ") +EnumChatFormatting.GREEN+GT_Utility.formatNumbers(((IMachineProgress) tTileEntity).getProgress()) +EnumChatFormatting.RESET+ " / " +EnumChatFormatting.YELLOW+GT_Utility.formatNumbers(tValue) +EnumChatFormatting.RESET); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + try { + if (tTileEntity instanceof ICoverable) { + rEUAmount += 300; + String tString = ((ICoverable) tTileEntity).getCoverBehaviorAtSide((byte) aSide).getDescription((byte) aSide, ((ICoverable) tTileEntity).getCoverIDAtSide((byte) aSide), ((ICoverable) tTileEntity).getCoverDataAtSide((byte) aSide), (ICoverable) tTileEntity); + if (tString != null && !tString.equals(E)) tList.add(tString); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + try { + if (tTileEntity instanceof IBasicEnergyContainer && ((IBasicEnergyContainer) tTileEntity).getEUCapacity() > 0) { + tList.add(trans("179","Max IN: ") +EnumChatFormatting.RED+ ((IBasicEnergyContainer) tTileEntity).getInputVoltage() + " (" + GT_Values.VN[GT_Utility.getTier(((IBasicEnergyContainer) tTileEntity).getInputVoltage())] + ") " +EnumChatFormatting.RESET+ trans("182"," EU at ") +EnumChatFormatting.RED+((IBasicEnergyContainer)tTileEntity).getInputAmperage()+EnumChatFormatting.RESET+trans("183"," A")); + tList.add(trans("181","Max OUT: ") +EnumChatFormatting.RED+ ((IBasicEnergyContainer) tTileEntity).getOutputVoltage() + " (" + GT_Values.VN[GT_Utility.getTier(((IBasicEnergyContainer) tTileEntity).getOutputVoltage())] + ") " +EnumChatFormatting.RESET+ trans("182"," EU at ") +EnumChatFormatting.RED+ ((IBasicEnergyContainer) tTileEntity).getOutputAmperage() +EnumChatFormatting.RESET+ trans("183"," A")); + tList.add(trans("184","Energy: ") +EnumChatFormatting.GREEN+ GT_Utility.formatNumbers(((IBasicEnergyContainer) tTileEntity).getStoredEU()) +EnumChatFormatting.RESET+ " EU / " +EnumChatFormatting.YELLOW+ GT_Utility.formatNumbers(((IBasicEnergyContainer) tTileEntity).getEUCapacity()) +EnumChatFormatting.RESET+ " EU"); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + try { + if (tTileEntity instanceof IGregTechTileEntity) { + tList.add(trans("186","Owned by: ") +EnumChatFormatting.BLUE+ ((IGregTechTileEntity) tTileEntity).getOwnerName()+EnumChatFormatting.RESET); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + try { + if (tTileEntity instanceof IGregTechDeviceInformation && ((IGregTechDeviceInformation) tTileEntity).isGivingInformation()) { + tList.addAll(Arrays.asList(((IGregTechDeviceInformation) tTileEntity).getInfoData())); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + try { + if (tTileEntity instanceof ic2.api.crops.ICropTile) { + if (((ic2.api.crops.ICropTile) tTileEntity).getScanLevel() < 4) { + rEUAmount += 10000; + ((ic2.api.crops.ICropTile) tTileEntity).setScanLevel((byte) 4); + } + if (((ic2.api.crops.ICropTile) tTileEntity).getID() >= 0 && ((ic2.api.crops.ICropTile) tTileEntity).getID() < ic2.api.crops.Crops.instance.getCropList().length && ic2.api.crops.Crops.instance.getCropList()[((ic2.api.crops.ICropTile) tTileEntity).getID()] != null) { + rEUAmount += 1000; + tList.add(trans("187","Type -- Crop-Name: ") + ic2.api.crops.Crops.instance.getCropList()[((ic2.api.crops.ICropTile) tTileEntity).getID()].name() + + trans("188"," Growth: ") + ((ic2.api.crops.ICropTile) tTileEntity).getGrowth() + + trans("189"," Gain: ") + ((ic2.api.crops.ICropTile) tTileEntity).getGain() + + trans("190"," Resistance: ") + ((ic2.api.crops.ICropTile) tTileEntity).getResistance() + ); + tList.add(trans("191","Plant -- Fertilizer: ") + ((ic2.api.crops.ICropTile) tTileEntity).getNutrientStorage() + + trans("192"," Water: ") + ((ic2.api.crops.ICropTile) tTileEntity).getHydrationStorage() + + trans("193"," Weed-Ex: ") + ((ic2.api.crops.ICropTile) tTileEntity).getWeedExStorage() + + trans("194"," Scan-Level: ") + ((ic2.api.crops.ICropTile) tTileEntity).getScanLevel() + ); + tList.add(trans("195","Environment -- Nutrients: ") + ((ic2.api.crops.ICropTile) tTileEntity).getNutrients() + + trans("196"," Humidity: ") + ((ic2.api.crops.ICropTile) tTileEntity).getHumidity() + + trans("197"," Air-Quality: ") + ((ic2.api.crops.ICropTile) tTileEntity).getAirQuality() + ); + StringBuilder tStringB = new StringBuilder(); + for (String tAttribute : ic2.api.crops.Crops.instance.getCropList()[((ic2.api.crops.ICropTile) tTileEntity).getID()].attributes()) { + tStringB.append(", ").append(tAttribute); + } + String tString = tStringB.toString(); + tList.add(trans("198","Attributes:") + tString.replaceFirst(",", E)); + tList.add(trans("199","Discovered by: ") + ic2.api.crops.Crops.instance.getCropList()[((ic2.api.crops.ICropTile) tTileEntity).getID()].discoveredBy()); + } + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + } + + if (aPlayer.capabilities.isCreativeMode) { + FluidStack tFluid = undergroundOilReadInformation(aWorld.getChunkFromBlockCoords(aX,aZ));//-# to only read + if (tFluid!=null) + tList.add(EnumChatFormatting.GOLD+tFluid.getLocalizedName()+EnumChatFormatting.RESET+": " +EnumChatFormatting.YELLOW+ tFluid.amount +EnumChatFormatting.RESET+" L"); + else + tList.add(EnumChatFormatting.GOLD+trans("201","Nothing")+EnumChatFormatting.RESET+": " +EnumChatFormatting.YELLOW+ '0' +EnumChatFormatting.RESET+" L"); + } +// if(aPlayer.capabilities.isCreativeMode){ + int[] chunkData = GT_Proxy.dimensionWiseChunkData.get(aWorld.provider.dimensionId).get(aWorld.getChunkFromBlockCoords(aX,aZ).getChunkCoordIntPair()); + if(chunkData !=null){ + if(chunkData[GTPOLLUTION]>0){ + tList.add(trans("202","Pollution in Chunk: ")+EnumChatFormatting.RED+chunkData[GTPOLLUTION]+EnumChatFormatting.RESET+trans("203"," gibbl")); + }else{ + tList.add(EnumChatFormatting.GREEN+trans("204","No Pollution in Chunk! HAYO!")+EnumChatFormatting.RESET); + } + }else{ + tList.add(EnumChatFormatting.GREEN+trans("204","No Pollution in Chunk! HAYO!")+EnumChatFormatting.RESET); + } + + try { + if (tBlock instanceof IDebugableBlock) { + rEUAmount += 500; + ArrayList temp = ((IDebugableBlock) tBlock).getDebugInfo(aPlayer, aX, aY, aZ, 3); + if (temp != null) tList.addAll(temp); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + + BlockScanningEvent tEvent = new BlockScanningEvent(aWorld, aPlayer, aX, aY, aZ, (byte) aSide, aScanLevel, tBlock, tTileEntity, tList, aClickX, aClickY, aClickZ); + tEvent.mEUCost = rEUAmount; + MinecraftForge.EVENT_BUS.post(tEvent); + if (!tEvent.isCanceled()) aList.addAll(tList); + return tEvent.mEUCost; + } + + public static String trans(String aKey, String aEnglish){ + return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_"+aKey, aEnglish, false); + } + + /** + * @return an Array containing the X and the Y Coordinate of the clicked Point, with the top left Corner as Origin, like on the Texture Sheet. return values should always be between [0.0F and 0.99F]. + */ + public static float[] getClickedFacingCoords(byte aSide, float aX, float aY, float aZ) { + switch (aSide) { + case 0: + return new float[]{Math.min(0.99F, Math.max(0, 1 - aX)), Math.min(0.99F, Math.max(0, aZ))}; + case 1: + return new float[]{Math.min(0.99F, Math.max(0, aX)), Math.min(0.99F, Math.max(0, aZ))}; + case 2: + return new float[]{Math.min(0.99F, Math.max(0, 1 - aX)), Math.min(0.99F, Math.max(0, 1 - aY))}; + case 3: + return new float[]{Math.min(0.99F, Math.max(0, aX)), Math.min(0.99F, Math.max(0, 1 - aY))}; + case 4: + return new float[]{Math.min(0.99F, Math.max(0, aZ)), Math.min(0.99F, Math.max(0, 1 - aY))}; + case 5: + return new float[]{Math.min(0.99F, Math.max(0, 1 - aZ)), Math.min(0.99F, Math.max(0, 1 - aY))}; + default: + return new float[]{0.5F, 0.5F}; + } + } + + /** + * This Function determines the direction a Block gets when being Wrenched. + * returns -1 if invalid. Even though that could never happen. + */ + public static byte determineWrenchingSide(byte aSide, float aX, float aY, float aZ) { + byte tBack = getOppositeSide(aSide); + switch (aSide) { + case 0: + case 1: + if (aX < 0.25) { + if (aZ < 0.25) return tBack; + if (aZ > 0.75) return tBack; + return 4; + } + if (aX > 0.75) { + if (aZ < 0.25) return tBack; + if (aZ > 0.75) return tBack; + return 5; + } + if (aZ < 0.25) return 2; + if (aZ > 0.75) return 3; + return aSide; + case 2: + case 3: + if (aX < 0.25) { + if (aY < 0.25) return tBack; + if (aY > 0.75) return tBack; + return 4; + } + if (aX > 0.75) { + if (aY < 0.25) return tBack; + if (aY > 0.75) return tBack; + return 5; + } + if (aY < 0.25) return 0; + if (aY > 0.75) return 1; + return aSide; + case 4: + case 5: + if (aZ < 0.25) { + if (aY < 0.25) return tBack; + if (aY > 0.75) return tBack; + return 2; + } + if (aZ > 0.75) { + if (aY < 0.25) return tBack; + if (aY > 0.75) return tBack; + return 3; + } + if (aY < 0.25) return 0; + if (aY > 0.75) return 1; + return aSide; + } + return -1; + } + + public static String formatNumbers(long aNumber) { + DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.US); + DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols(); + symbols.setGroupingSeparator(' '); + return formatter.format(aNumber); + } + + /* + * Check if stack has enough items of given type and subtract from stack, if there's no creative or 111 stack. + */ + public static boolean consumeItems(EntityPlayer player, ItemStack stack, Item item, int count) { + if (stack != null && stack.getItem() == item && stack.stackSize >= count) { + if ((!player.capabilities.isCreativeMode) && (stack.stackSize != 111)) + stack.stackSize -= count; + return true; + } + return false; + } + + /* + * Check if stack has enough items of given gregtech material (will be oredicted) + * and subtract from stack, if there's no creative or 111 stack. + */ + public static boolean consumeItems(EntityPlayer player, ItemStack stack, gregtech.api.enums.Materials mat, int count) { + if (stack != null + && GT_OreDictUnificator.getItemData(stack).mMaterial.mMaterial == mat + && stack.stackSize >= count) { + if ((!player.capabilities.isCreativeMode) && (stack.stackSize != 111)) + stack.stackSize -= count; + return true; + } + return false; + } + + public static ArrayList sortByValueToList( Map map ) { + List> list = + new LinkedList>( map.entrySet() ); + Collections.sort( list, new Comparator>() + { + public int compare( Map.Entry o1, Map.Entry o2 ) + { + return o2.getValue() - o1.getValue(); + } + } ); + + ArrayList result = new ArrayList(); + for (Map.Entry e : list) + result.add(e.getKey()); + return result; + } + + public static String joinListToString(List list) { + StringBuilder result = new StringBuilder(32); + for (String s : list) + result.append(result.length()==0?s:'|'+s); + return result.toString(); + } + + public static ItemStack getIntegratedCircuit(int config){ + return ItemList.Circuit_Integrated.getWithDamage(0, config, new Object[0]); + } + + public static float getBlockHardnessAt(World aWorld, int aX, int aY, int aZ) { + return aWorld.getBlock(aX, aY, aZ).getBlockHardness(aWorld, aX, aY, aZ); + } + + public static FakePlayer getFakePlayer(IGregTechTileEntity aBaseMetaTileEntity) { + if (aBaseMetaTileEntity.getWorld() instanceof WorldServer) { + return FakePlayerFactory.get((WorldServer) aBaseMetaTileEntity.getWorld(), new GameProfile(aBaseMetaTileEntity.getOwnerUuid(), aBaseMetaTileEntity.getOwnerName())); + } + return null; + } + + public static boolean eraseBlockByFakePlayer(FakePlayer aPlayer, int aX, int aY, int aZ, boolean isSimulate) { + if (aPlayer == null) return false; + World aWorld = aPlayer.worldObj; + BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(aX, aY, aZ, aWorld, aWorld.getBlock(aX, aY, aZ), aWorld.getBlockMetadata(aX, aY, aZ), aPlayer); + MinecraftForge.EVENT_BUS.post(event); + if (!event.isCanceled()) { + if (!isSimulate) return aWorld.setBlockToAir(aX, aY, aZ); + return true; + } + return false; + } + + public static boolean setBlockByFakePlayer(FakePlayer aPlayer, int aX, int aY, int aZ, Block aBlock, int aMeta, boolean isSimulate) { + if (aPlayer == null) return false; + World aWorld = aPlayer.worldObj; + BlockEvent.PlaceEvent event = ForgeEventFactory.onPlayerBlockPlace(aPlayer, new BlockSnapshot(aWorld, aX, aY, aZ, aBlock, aMeta), ForgeDirection.UNKNOWN); + if (!event.isCanceled()) { + if (!isSimulate) return aWorld.setBlock(aX, aY, aZ, aBlock, aMeta, 3); + return true; + } + return false; + } + + public static class ItemNBT { + public static void setNBT(ItemStack aStack, NBTTagCompound aNBT) { + if (aNBT == null) { + aStack.setTagCompound(null); + return; + } + ArrayList tTagsToRemove = new ArrayList(); + for (Object tKey : aNBT.func_150296_c()) { + NBTBase tValue = aNBT.getTag((String) tKey); + if (tValue == null || (tValue instanceof NBTPrimitive && ((NBTPrimitive) tValue).func_150291_c() == 0) || (tValue instanceof NBTTagString && isStringInvalid(((NBTTagString) tValue).func_150285_a_()))) + tTagsToRemove.add((String) tKey); + } + for (Object tKey : tTagsToRemove) aNBT.removeTag((String) tKey); + aStack.setTagCompound(aNBT.hasNoTags() ? null : aNBT); + } + + public static NBTTagCompound getNBT(ItemStack aStack) { + NBTTagCompound rNBT = aStack.getTagCompound(); + return rNBT == null ? new NBTTagCompound() : rNBT; + } + + public static void setPunchCardData(ItemStack aStack, String aPunchCardData) { + NBTTagCompound tNBT = getNBT(aStack); + tNBT.setString("GT.PunchCardData", aPunchCardData); + setNBT(aStack, tNBT); + } + + public static String getPunchCardData(ItemStack aStack) { + NBTTagCompound tNBT = getNBT(aStack); + return tNBT.getString("GT.PunchCardData"); + } + + public static void setLighterFuel(ItemStack aStack, long aFuel) { + NBTTagCompound tNBT = getNBT(aStack); + tNBT.setLong("GT.LighterFuel", aFuel); + setNBT(aStack, tNBT); + } + + public static long getLighterFuel(ItemStack aStack) { + NBTTagCompound tNBT = getNBT(aStack); + return tNBT.getLong("GT.LighterFuel"); + } + + public static void setMapID(ItemStack aStack, short aMapID) { + NBTTagCompound tNBT = getNBT(aStack); + tNBT.setShort("map_id", aMapID); + setNBT(aStack, tNBT); + } + + public static short getMapID(ItemStack aStack) { + NBTTagCompound tNBT = getNBT(aStack); + if (!tNBT.hasKey("map_id")) return -1; + return tNBT.getShort("map_id"); + } + + public static void setBookTitle(ItemStack aStack, String aTitle) { + NBTTagCompound tNBT = getNBT(aStack); + tNBT.setString("title", aTitle); + setNBT(aStack, tNBT); + } + + public static String getBookTitle(ItemStack aStack) { + NBTTagCompound tNBT = getNBT(aStack); + return tNBT.getString("title"); + } + + public static void setBookAuthor(ItemStack aStack, String aAuthor) { + NBTTagCompound tNBT = getNBT(aStack); + tNBT.setString("author", aAuthor); + setNBT(aStack, tNBT); + } + + public static String getBookAuthor(ItemStack aStack) { + NBTTagCompound tNBT = getNBT(aStack); + return tNBT.getString("author"); + } + + public static void setProspectionData(ItemStack aStack, int aX, int aY, int aZ, int aDim, FluidStack aFluid, String... aOres) { + NBTTagCompound tNBT = getNBT(aStack); + String tData = aX + "," + aY + "," + aZ + "," + aDim + ","; + if (aFluid!=null) + tData += (aFluid.amount) + "," + aFluid.getLocalizedName() + ",";//TODO CHECK IF THAT /5000 is needed (Not needed) + for (String tString : aOres) { + tData += tString + ","; + } + tNBT.setString("prospection", tData); + setNBT(aStack, tNBT); + } + + public static void setAdvancedProspectionData( + byte aTier, + ItemStack aStack, + int aX, short aY, int aZ, int aDim, + ArrayList aOils, + ArrayList aOres, + int aRadius) { + + setBookTitle(aStack, "Raw Prospection Data"); + + NBTTagCompound tNBT = GT_Utility.ItemNBT.getNBT(aStack); + + tNBT.setByte("prospection_tier", aTier); + tNBT.setString("prospection_pos", "Dim: " + aDim + "\nX: " + aX + " Y: " + aY + " Z: " + aZ); + + // ores + Collections.sort(aOres); + tNBT.setString("prospection_ores", joinListToString(aOres)); + + // oils + ArrayList tOilsTransformed = new ArrayList(aOils.size()); + for (String aStr : aOils) { + String[] aStats = aStr.split(","); + tOilsTransformed.add(aStats[0] + ": " + aStats[1] + "L " + aStats[2]); + } + + tNBT.setString("prospection_oils", joinListToString(tOilsTransformed)); + + String tOilsPosStr = "X: " + Math.floorDiv(aX, 16*8)*16*8 + " Z: " + Math.floorDiv(aZ, 16*8)*16*8 + "\n"; + int xOff = aX - Math.floorDiv(aX, 16*8)*16*8; + xOff = xOff/16; + int xOffRemain = 7 - xOff; + + int zOff = aZ - Math.floorDiv(aZ, 16*8)*16*8; + zOff = zOff/16; + int zOffRemain = 7 - zOff; + + for( ; zOff > 0; zOff-- ) { + tOilsPosStr = tOilsPosStr.concat("--------\n"); + } + for( ; xOff > 0; xOff-- ) { + tOilsPosStr = tOilsPosStr.concat("-"); + } + + tOilsPosStr = tOilsPosStr.concat("P"); + + for( ; xOffRemain > 0; xOffRemain-- ) { + tOilsPosStr = tOilsPosStr.concat("-"); + } + tOilsPosStr = tOilsPosStr.concat("\n"); + for( ; zOffRemain > 0; zOffRemain-- ) { + tOilsPosStr = tOilsPosStr.concat("--------\n"); + } + tOilsPosStr = tOilsPosStr.concat( " X: " + (Math.floorDiv(aX, 16*8) + 1)*16*8 + " Z: " + (Math.floorDiv(aZ, 16*8) + 1)*16*8 ); // +1 oilfied to find bottomright of [5] + + tNBT.setString("prospection_oils_pos", tOilsPosStr); + + tNBT.setString("prospection_radius", String.valueOf(aRadius)); + + setNBT(aStack, tNBT); + } + + public static void convertProspectionData(ItemStack aStack) { + NBTTagCompound tNBT = getNBT(aStack); + byte tTier = tNBT.getByte("prospection_tier"); + + if (tTier == 0) { // basic prospection data + String tData = tNBT.getString("prospection"); + String[] tDataArray = tData.split(","); + if (tDataArray.length > 6) { + tNBT.setString("author", " Dim: " + tDataArray[3] + "X: " + tDataArray[0] + " Y: " + tDataArray[1] + " Z: " + tDataArray[2]); + NBTTagList tNBTList = new NBTTagList(); + String tOres = " Prospected Ores: "; + for (int i = 6; tDataArray.length > i; i++) { + tOres += (tDataArray[i] + " "); + } + tNBTList.appendTag(new NBTTagString("Tier " + tTier + " Prospecting Data From: X" + tDataArray[0] + " Z:" + tDataArray[2] + " Dim:" + tDataArray[3] + " Produces " + tDataArray[4] + "L " + tDataArray[5] + " " + tOres)); + tNBT.setTag("pages", tNBTList); + } + setNBT(aStack, tNBT); + } else { // advanced prospection data + String tPos = tNBT.getString("prospection_pos"); + String tRadius = tNBT.getString("prospection_radius"); + + String tOresStr = tNBT.getString("prospection_ores"); + String tOilsStr = tNBT.getString("prospection_oils"); + String tOilsPosStr = tNBT.getString("prospection_oils_pos"); + + String[] tOres = tOresStr.isEmpty() ? null : tOresStr.split("\\|"); + String[] tOils = tOilsStr.isEmpty() ? null : tOilsStr.split("\\|"); + + NBTTagList tNBTList = new NBTTagList(); + + String tPageText = "Prospector report\n" + + tPos + "\n\n" + + "Oils: " + (tOils != null ? tOils.length : 0) + "\n\n" + + "Ores within " + tRadius + " blocks\n\n" + + "Location is center of orevein\n\n" + + +"Check NEI to confirm orevein type"; + tNBTList.appendTag(new NBTTagString(tPageText)); + + if (tOres != null) + fillBookWithList(tNBTList, "Ores Found %s\n\n", "\n", 7, tOres); + + + if (tOils != null) + fillBookWithList(tNBTList, "Oils%s\n\n", "\n", 9, tOils); + + tPageText = "Oil notes\n\n" + + "Prospects from NW to SE 576 chunks" + + "(9 8x8 oilfields)\n around and gives min-max amount" + "\n\n" + + "[1][2][3]" + "\n" + + "[4][5][6]" + "\n" + + "[7][8][9]" + "\n" + + "\n" + + "[5] - Prospector in this 8x8 area"; + tNBTList.appendTag(new NBTTagString(tPageText)); + + tPageText = "Corners of [5] are \n" + + tOilsPosStr + "\n" + + "P - Prospector in 8x8 field"; + tNBTList.appendTag(new NBTTagString(tPageText)); + + tNBT.setString("author", tPos.replace("\n"," ")); + tNBT.setTag("pages", tNBTList); + setNBT(aStack, tNBT); + } + } + + public static void fillBookWithList(NBTTagList aBook, String aPageHeader, String aListDelimiter, int aItemsPerPage, String[] list) { + String aPageFormatter = " %d/%d"; + int tTotalPages = list.length / aItemsPerPage + (list.length % aItemsPerPage > 0 ? 1 : 0); + int tPage = 0; + String tPageText; + do { + tPageText = ""; + for (int i = tPage*aItemsPerPage; i < (tPage+1)*aItemsPerPage && i < list.length; i += 1) + tPageText += (tPageText.isEmpty() ? "" : aListDelimiter) + list[i]; + + if (!tPageText.isEmpty()) { + String tPageCounter = tTotalPages > 1 ? String.format(aPageFormatter, tPage + 1, tTotalPages) : ""; + NBTTagString tPageTag = new NBTTagString(String.format(aPageHeader, tPageCounter) + tPageText); + aBook.appendTag(tPageTag); + } + + ++tPage; + } while (!tPageText.isEmpty()); + } + + public static void addEnchantment(ItemStack aStack, Enchantment aEnchantment, int aLevel) { + NBTTagCompound tNBT = getNBT(aStack), tEnchantmentTag; + if (!tNBT.hasKey("ench", 9)) tNBT.setTag("ench", new NBTTagList()); + NBTTagList tList = tNBT.getTagList("ench", 10); + + boolean temp = true; + + for (int i = 0; i < tList.tagCount(); i++) { + tEnchantmentTag = tList.getCompoundTagAt(i); + if (tEnchantmentTag.getShort("id") == aEnchantment.effectId) { + tEnchantmentTag.setShort("id", (short) aEnchantment.effectId); + tEnchantmentTag.setShort("lvl", (byte) aLevel); + temp = false; + break; + } + } + + if (temp) { + tEnchantmentTag = new NBTTagCompound(); + tEnchantmentTag.setShort("id", (short) aEnchantment.effectId); + tEnchantmentTag.setShort("lvl", (byte) aLevel); + tList.appendTag(tEnchantmentTag); + } + aStack.setTagCompound(tNBT); + } + } + + /** + * THIS IS BULLSHIT!!! WHY DO I HAVE TO DO THIS SHIT JUST TO HAVE ENCHANTS PROPERLY!?! + */ + public static class GT_EnchantmentHelper { + private static final BullshitIteratorA mBullshitIteratorA = new BullshitIteratorA(); + private static final BullshitIteratorB mBullshitIteratorB = new BullshitIteratorB(); + + private static void applyBullshit(IBullshit aBullshitModifier, ItemStack aStack) { + if (aStack != null) { + NBTTagList nbttaglist = aStack.getEnchantmentTagList(); + if (nbttaglist != null) { + try { + for (int i = 0; i < nbttaglist.tagCount(); ++i) { + short short1 = nbttaglist.getCompoundTagAt(i).getShort("id"); + short short2 = nbttaglist.getCompoundTagAt(i).getShort("lvl"); + if (Enchantment.enchantmentsList[short1] != null) + aBullshitModifier.calculateModifier(Enchantment.enchantmentsList[short1], short2); + } + } catch (Throwable e) {/**/} + } + } + } + + private static void applyArrayOfBullshit(IBullshit aBullshitModifier, ItemStack[] aStacks) { + ItemStack[] aitemstack1 = aStacks; + int i = aStacks.length; + for (int j = 0; j < i; ++j) { + ItemStack itemstack = aitemstack1[j]; + applyBullshit(aBullshitModifier, itemstack); + } + } + + public static void applyBullshitA(EntityLivingBase aPlayer, Entity aEntity, ItemStack aStack) { + mBullshitIteratorA.mPlayer = aPlayer; + mBullshitIteratorA.mEntity = aEntity; + if (aPlayer != null) applyArrayOfBullshit(mBullshitIteratorA, aPlayer.getLastActiveItems()); + if (aStack != null) applyBullshit(mBullshitIteratorA, aStack); + } + + public static void applyBullshitB(EntityLivingBase aPlayer, Entity aEntity, ItemStack aStack) { + mBullshitIteratorB.mPlayer = aPlayer; + mBullshitIteratorB.mEntity = aEntity; + if (aPlayer != null) applyArrayOfBullshit(mBullshitIteratorB, aPlayer.getLastActiveItems()); + if (aStack != null) applyBullshit(mBullshitIteratorB, aStack); + } + + interface IBullshit { + void calculateModifier(Enchantment aEnchantment, int aLevel); + } + + static final class BullshitIteratorA implements IBullshit { + public EntityLivingBase mPlayer; + public Entity mEntity; + + BullshitIteratorA() { + } + + @Override + public void calculateModifier(Enchantment aEnchantment, int aLevel) { + aEnchantment.func_151367_b(mPlayer, mEntity, aLevel); + } + } + + static final class BullshitIteratorB implements IBullshit { + public EntityLivingBase mPlayer; + public Entity mEntity; + + BullshitIteratorB() { + } + + @Override + public void calculateModifier(Enchantment aEnchantment, int aLevel) { + aEnchantment.func_151368_a(mPlayer, mEntity, aLevel); + } + } + } + + public static String toSubscript(long no){ + char[] chars=Long.toString(no).toCharArray(); + for(int i=0;i= GregTech_API.METATILEENTITIES.length)) { - return; - } - - if (GregTech_API.METATILEENTITIES[tDamage] != null) { - IGregTechTileEntity tTileEntity = GregTech_API.METATILEENTITIES[tDamage].getBaseMetaTileEntity(); - if (tTileEntity.getDescription() != null) { - int i = 0; - for (String tDescription : tTileEntity.getDescription()) { - if (GT_Utility.isStringValid(tDescription)) { - if(tDescription.contains("%%%")){ - String[] tString = tDescription.split("%%%"); - if(tString.length>=2){ - StringBuffer tBuffer = new StringBuffer(); - Object tRep[] = new String[tString.length / 2]; - for (int j = 0; j < tString.length; j++) - if (j % 2 == 0) tBuffer.append(tString[j]); - else {tBuffer.append(" %s"); tRep[j / 2] = tString[j];} - aList.add(String.format(GT_LanguageManager.addStringLocalization("TileEntity_DESCRIPTION_" + tDamage + "_Index_" + i++, tBuffer.toString(), !GregTech_API.sPostloadFinished), tRep)); - } - }else{String tTranslated = GT_LanguageManager.addStringLocalization("TileEntity_DESCRIPTION_" + tDamage + "_Index_" + i++, tDescription, !GregTech_API.sPostloadFinished ); - aList.add(tTranslated.equals("") ? tDescription : tTranslated);} - }else i++; - } - } - if (tTileEntity.getEUCapacity() > 0L) { - if (tTileEntity.getInputVoltage() > 0L) { - aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_IN", "Voltage IN: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.GREEN + tTileEntity.getInputVoltage() + " (" + GT_Values.VN[GT_Utility.getTier(tTileEntity.getInputVoltage())] + ")" + EnumChatFormatting.GRAY); - } - if (tTileEntity.getOutputVoltage() > 0L) { - aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_OUT", "Voltage OUT: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.GREEN + tTileEntity.getOutputVoltage() + " (" + GT_Values.VN[GT_Utility.getTier(tTileEntity.getOutputVoltage())] + ")" + EnumChatFormatting.GRAY); - } - if (tTileEntity.getOutputAmperage() > 1L) { - aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_AMOUNT", "Amperage: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.YELLOW + tTileEntity.getOutputAmperage() + EnumChatFormatting.GRAY); - } - aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_STORE", "Capacity: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.BLUE + tTileEntity.getEUCapacity() + EnumChatFormatting.GRAY); - } - } - NBTTagCompound aNBT = aStack.getTagCompound(); - if (aNBT != null) { - if (aNBT.getBoolean("mMuffler")) { - aList.add(GT_LanguageManager.addStringLocalization("GT_TileEntity_MUFFLER", "has Muffler Upgrade", !GregTech_API.sPostloadFinished )); - } - if (aNBT.getBoolean("mSteamConverter")) { - aList.add(GT_LanguageManager.addStringLocalization("GT_TileEntity_STEAMCONVERTER", "has Steam Upgrade", !GregTech_API.sPostloadFinished )); - } - int tAmount = 0; - if ((tAmount = aNBT.getByte("mSteamTanks")) > 0) { - aList.add(tAmount + " " + GT_LanguageManager.addStringLocalization("GT_TileEntity_STEAMTANKS", "Steam Tank Upgrades", !GregTech_API.sPostloadFinished )); - } - } - } catch (Throwable e) { - e.printStackTrace(GT_Log.err); - } - } - - public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { - return false; - } - - public String getUnlocalizedName(ItemStack aStack) { - short tDamage = (short) getDamage(aStack); - if ((tDamage < 0) || (tDamage >= GregTech_API.METATILEENTITIES.length)) { - return ""; - } - if (GregTech_API.METATILEENTITIES[tDamage] != null) { - return getUnlocalizedName() + "." + GregTech_API.METATILEENTITIES[tDamage].getMetaName(); - } - return ""; - } - - public String getItemStackDisplayName(ItemStack aStack) { - String aName = super.getItemStackDisplayName(aStack); - short aDamage = (short) getDamage(aStack); - if (aDamage >= 0 && aDamage < GregTech_API.METATILEENTITIES.length && GregTech_API.METATILEENTITIES[aDamage] != null) { - Materials aMaterial = null; - if (GregTech_API.METATILEENTITIES[aDamage] instanceof GT_MetaPipeEntity_Item) { - aMaterial = ((GT_MetaPipeEntity_Item) GregTech_API.METATILEENTITIES[aDamage]).mMaterial; - } else if (GregTech_API.METATILEENTITIES[aDamage] instanceof GT_MetaPipeEntity_Fluid) { - aMaterial = ((GT_MetaPipeEntity_Fluid) GregTech_API.METATILEENTITIES[aDamage]).mMaterial; - } else if (GregTech_API.METATILEENTITIES[aDamage] instanceof GT_MetaPipeEntity_Cable) { - aMaterial = ((GT_MetaPipeEntity_Cable) GregTech_API.METATILEENTITIES[aDamage]).mMaterial; - } else if (GregTech_API.METATILEENTITIES[aDamage] instanceof GT_MetaPipeEntity_Frame) { - aMaterial = ((GT_MetaPipeEntity_Frame) GregTech_API.METATILEENTITIES[aDamage]).mMaterial; - } - if (aMaterial != null) { - aName = aMaterial.getLocalizedNameForItem(aName); - } - } - return aName; - } - - public void onCreated(ItemStack aStack, World aWorld, EntityPlayer aPlayer) { - super.onCreated(aStack, aWorld, aPlayer); - short tDamage = (short) getDamage(aStack); - if ((tDamage < 0) || ((tDamage >= GregTech_API.METATILEENTITIES.length) && (GregTech_API.METATILEENTITIES[tDamage] != null))) { - GregTech_API.METATILEENTITIES[tDamage].onCreated(aStack, aWorld, aPlayer); - } - } - - public boolean placeBlockAt(ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, int side, float hitX, float hitY, float hitZ, int aMeta) { - short tDamage = (short) getDamage(aStack); - if (tDamage > 0) { - if (GregTech_API.METATILEENTITIES[tDamage] == null) { - return false; - } - int tMetaData = GregTech_API.METATILEENTITIES[tDamage].getTileEntityBaseType(); - if (!aWorld.setBlock(aX, aY, aZ, this.field_150939_a, tMetaData, 3)) { - return false; - } - if (aWorld.getBlock(aX, aY, aZ) != this.field_150939_a) { - throw new GT_ItsNotMyFaultException("Failed to place Block even though World.setBlock returned true. It COULD be MCPC/Bukkit causing that. In case you really have that installed, don't report this Bug to me, I don't know how to fix it."); - } - if (aWorld.getBlockMetadata(aX, aY, aZ) != tMetaData) { - throw new GT_ItsNotMyFaultException("Failed to set the MetaValue of the Block even though World.setBlock returned true. It COULD be MCPC/Bukkit causing that. In case you really have that installed, don't report this Bug to me, I don't know how to fix it."); - } - IGregTechTileEntity tTileEntity = (IGregTechTileEntity) aWorld.getTileEntity(aX, aY, aZ); - if (tTileEntity != null) { - tTileEntity.setInitialValuesAsNBT(tTileEntity.isServerSide() ? aStack.getTagCompound() : null, tDamage); - if (aPlayer != null) { - tTileEntity.setOwnerName(aPlayer.getDisplayName()); - } - tTileEntity.getMetaTileEntity().initDefaultModes(aStack.getTagCompound()); - final byte aSide = GT_Utility.getOppositeSide(side); - if (tTileEntity.getMetaTileEntity() instanceof IConnectable) { - // If we're connectable, try connecting to whatever we're up against - ((IConnectable) tTileEntity.getMetaTileEntity()).connect(aSide); - } else if (aPlayer != null && aPlayer.isSneaking()) { - // If we're being placed against something that is connectable, try telling it to connect to us - IGregTechTileEntity aTileEntity = tTileEntity.getIGregTechTileEntityAtSide(aSide); - if (aTileEntity != null && aTileEntity.getMetaTileEntity() instanceof IConnectable) { - ((IConnectable) aTileEntity.getMetaTileEntity()).connect((byte)side); - } - } - } - } else if (!aWorld.setBlock(aX, aY, aZ, this.field_150939_a, tDamage, 3)) { - return false; - } - if (aWorld.getBlock(aX, aY, aZ) == this.field_150939_a) { - this.field_150939_a.onBlockPlacedBy(aWorld, aX, aY, aZ, aPlayer, aStack); - this.field_150939_a.onPostBlockPlaced(aWorld, aX, aY, aZ, tDamage); - } - return true; - } -} +package gregtech.common.blocks; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Materials; +import gregtech.api.interfaces.metatileentity.IConnectable; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Cable; +import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Fluid; +import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Frame; +import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Item; +import gregtech.api.util.GT_ItsNotMyFaultException; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_Log; +import gregtech.api.util.GT_Utility; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; + +import java.util.List; + +public class GT_Item_Machines + extends ItemBlock { + public GT_Item_Machines(Block par1) { + super(par1); + setMaxDamage(0); + setHasSubtypes(true); + setCreativeTab(GregTech_API.TAB_GREGTECH); + } + + public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean par4) { + try { + int tDamage = getDamage(aStack); + if ((tDamage <= 0) || (tDamage >= GregTech_API.METATILEENTITIES.length)) { + return; + } + + if (GregTech_API.METATILEENTITIES[tDamage] != null) { + IGregTechTileEntity tTileEntity = GregTech_API.METATILEENTITIES[tDamage].getBaseMetaTileEntity(); + if (tTileEntity.getDescription() != null) { + int i = 0; + for (String tDescription : tTileEntity.getDescription()) { + if (GT_Utility.isStringValid(tDescription)) { + if(tDescription.contains("%%%")){ + String[] tString = tDescription.split("%%%"); + if(tString.length>=2){ + StringBuffer tBuffer = new StringBuffer(); + Object tRep[] = new String[tString.length / 2]; + for (int j = 0; j < tString.length; j++) + if (j % 2 == 0) tBuffer.append(tString[j]); + else {tBuffer.append(" %s"); tRep[j / 2] = tString[j];} + aList.add(String.format(GT_LanguageManager.addStringLocalization("TileEntity_DESCRIPTION_" + tDamage + "_Index_" + i++, tBuffer.toString(), !GregTech_API.sPostloadFinished), tRep)); + } + }else{String tTranslated = GT_LanguageManager.addStringLocalization("TileEntity_DESCRIPTION_" + tDamage + "_Index_" + i++, tDescription, !GregTech_API.sPostloadFinished ); + aList.add(tTranslated.equals("") ? tDescription : tTranslated);} + }else i++; + } + } + if (tTileEntity.getEUCapacity() > 0L) { + if (tTileEntity.getInputVoltage() > 0L) { + aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_IN", "Voltage IN: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.GREEN + tTileEntity.getInputVoltage() + " (" + GT_Values.VN[GT_Utility.getTier(tTileEntity.getInputVoltage())] + ")" + EnumChatFormatting.GRAY); + } + if (tTileEntity.getOutputVoltage() > 0L) { + aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_OUT", "Voltage OUT: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.GREEN + tTileEntity.getOutputVoltage() + " (" + GT_Values.VN[GT_Utility.getTier(tTileEntity.getOutputVoltage())] + ")" + EnumChatFormatting.GRAY); + } + if (tTileEntity.getOutputAmperage() > 1L) { + aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_AMOUNT", "Amperage: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.YELLOW + tTileEntity.getOutputAmperage() + EnumChatFormatting.GRAY); + } + aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_STORE", "Capacity: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.BLUE + tTileEntity.getEUCapacity() + EnumChatFormatting.GRAY); + } + } + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + if (aNBT.getBoolean("mMuffler")) { + aList.add(GT_LanguageManager.addStringLocalization("GT_TileEntity_MUFFLER", "has Muffler Upgrade", !GregTech_API.sPostloadFinished )); + } + if (aNBT.getBoolean("mSteamConverter")) { + aList.add(GT_LanguageManager.addStringLocalization("GT_TileEntity_STEAMCONVERTER", "has Steam Upgrade", !GregTech_API.sPostloadFinished )); + } + int tAmount = 0; + if ((tAmount = aNBT.getByte("mSteamTanks")) > 0) { + aList.add(tAmount + " " + GT_LanguageManager.addStringLocalization("GT_TileEntity_STEAMTANKS", "Steam Tank Upgrades", !GregTech_API.sPostloadFinished )); + } + } + } catch (Throwable e) { + e.printStackTrace(GT_Log.err); + } + } + + public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { + return false; + } + + public String getUnlocalizedName(ItemStack aStack) { + short tDamage = (short) getDamage(aStack); + if ((tDamage < 0) || (tDamage >= GregTech_API.METATILEENTITIES.length)) { + return ""; + } + if (GregTech_API.METATILEENTITIES[tDamage] != null) { + return getUnlocalizedName() + "." + GregTech_API.METATILEENTITIES[tDamage].getMetaName(); + } + return ""; + } + + public String getItemStackDisplayName(ItemStack aStack) { + String aName = super.getItemStackDisplayName(aStack); + short aDamage = (short) getDamage(aStack); + if (aDamage >= 0 && aDamage < GregTech_API.METATILEENTITIES.length && GregTech_API.METATILEENTITIES[aDamage] != null) { + Materials aMaterial = null; + if (GregTech_API.METATILEENTITIES[aDamage] instanceof GT_MetaPipeEntity_Item) { + aMaterial = ((GT_MetaPipeEntity_Item) GregTech_API.METATILEENTITIES[aDamage]).mMaterial; + } else if (GregTech_API.METATILEENTITIES[aDamage] instanceof GT_MetaPipeEntity_Fluid) { + aMaterial = ((GT_MetaPipeEntity_Fluid) GregTech_API.METATILEENTITIES[aDamage]).mMaterial; + } else if (GregTech_API.METATILEENTITIES[aDamage] instanceof GT_MetaPipeEntity_Cable) { + aMaterial = ((GT_MetaPipeEntity_Cable) GregTech_API.METATILEENTITIES[aDamage]).mMaterial; + } else if (GregTech_API.METATILEENTITIES[aDamage] instanceof GT_MetaPipeEntity_Frame) { + aMaterial = ((GT_MetaPipeEntity_Frame) GregTech_API.METATILEENTITIES[aDamage]).mMaterial; + } + if (aMaterial != null) { + aName = aMaterial.getLocalizedNameForItem(aName); + } + } + return aName; + } + + public void onCreated(ItemStack aStack, World aWorld, EntityPlayer aPlayer) { + super.onCreated(aStack, aWorld, aPlayer); + short tDamage = (short) getDamage(aStack); + if ((tDamage < 0) || ((tDamage >= GregTech_API.METATILEENTITIES.length) && (GregTech_API.METATILEENTITIES[tDamage] != null))) { + GregTech_API.METATILEENTITIES[tDamage].onCreated(aStack, aWorld, aPlayer); + } + } + + public boolean placeBlockAt(ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, int side, float hitX, float hitY, float hitZ, int aMeta) { + short tDamage = (short) getDamage(aStack); + if (tDamage > 0) { + if (GregTech_API.METATILEENTITIES[tDamage] == null) { + return false; + } + int tMetaData = GregTech_API.METATILEENTITIES[tDamage].getTileEntityBaseType(); + if (!aWorld.setBlock(aX, aY, aZ, this.field_150939_a, tMetaData, 3)) { + return false; + } + if (aWorld.getBlock(aX, aY, aZ) != this.field_150939_a) { + throw new GT_ItsNotMyFaultException("Failed to place Block even though World.setBlock returned true. It COULD be MCPC/Bukkit causing that. In case you really have that installed, don't report this Bug to me, I don't know how to fix it."); + } + if (aWorld.getBlockMetadata(aX, aY, aZ) != tMetaData) { + throw new GT_ItsNotMyFaultException("Failed to set the MetaValue of the Block even though World.setBlock returned true. It COULD be MCPC/Bukkit causing that. In case you really have that installed, don't report this Bug to me, I don't know how to fix it."); + } + IGregTechTileEntity tTileEntity = (IGregTechTileEntity) aWorld.getTileEntity(aX, aY, aZ); + if (tTileEntity != null) { + tTileEntity.setInitialValuesAsNBT(tTileEntity.isServerSide() ? aStack.getTagCompound() : null, tDamage); + if (aPlayer != null) { + tTileEntity.setOwnerName(aPlayer.getDisplayName()); + tTileEntity.setOwnerUuid(aPlayer.getUniqueID()); + } + tTileEntity.getMetaTileEntity().initDefaultModes(aStack.getTagCompound()); + final byte aSide = GT_Utility.getOppositeSide(side); + if (tTileEntity.getMetaTileEntity() instanceof IConnectable) { + // If we're connectable, try connecting to whatever we're up against + ((IConnectable) tTileEntity.getMetaTileEntity()).connect(aSide); + } else if (aPlayer != null && aPlayer.isSneaking()) { + // If we're being placed against something that is connectable, try telling it to connect to us + IGregTechTileEntity aTileEntity = tTileEntity.getIGregTechTileEntityAtSide(aSide); + if (aTileEntity != null && aTileEntity.getMetaTileEntity() instanceof IConnectable) { + ((IConnectable) aTileEntity.getMetaTileEntity()).connect((byte)side); + } + } + } + } else if (!aWorld.setBlock(aX, aY, aZ, this.field_150939_a, tDamage, 3)) { + return false; + } + if (aWorld.getBlock(aX, aY, aZ) == this.field_150939_a) { + this.field_150939_a.onBlockPlacedBy(aWorld, aX, aY, aZ, aPlayer, aStack); + this.field_150939_a.onPostBlockPlaced(aWorld, aX, aY, aZ, tDamage); + } + return true; + } +} -- cgit