package gregtech.api.metatileentity; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.GregTech_API; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Cable; import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.*; import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Locale; import static gregtech.api.enums.GT_Values.V; /** * NEVER INCLUDE THIS FILE IN YOUR MOD!!! *
* Extend this Class to add a new MetaMachine * Call the Constructor with the desired ID at the load-phase (not preload and also not postload!) * Implement the newMetaEntity-Method to return a new ready instance of your MetaTileEntity * * Call the Constructor like the following example inside the Load Phase, to register it. * "new GT_MetaTileEntity_E_Furnace(54, "GT_E_Furnace", "Automatic E-Furnace");" */ public abstract class MetaTileEntity implements IMetaTileEntity { /** * Only assigned for the MetaTileEntity in the List! Also only used to get the localized Name for the ItemStack and for getInvName. */ public final String mName; /** * The Inventory of the MetaTileEntity. Amount of Slots can be larger than 256. HAYO! */ public final ItemStack[] mInventory; public boolean doTickProfilingInThisTick = true; /** * accessibility to this Field is no longer given, see below */ private IGregTechTileEntity mBaseMetaTileEntity; public long mSoundRequests=0; /** * This registers your Machine at the List. * Use only ID's larger than 2048, because i reserved these ones. * See also the List in the API, as it has a Description containing all the reservations. * * @param aID the ID * @example for Constructor overload. * * public GT_MetaTileEntity_EBench(int aID, String mName, String mNameRegional) { * super(aID, mName, mNameRegional); * } */ public MetaTileEntity(int aID, String aBasicName, String aRegionalName, int aInvSlotCount) { if (GregTech_API.sPostloadStarted || !GregTech_API.sPreloadStarted) throw new IllegalAccessError("This Constructor has to be called in the load Phase"); if (GregTech_API.METATILEENTITIES[aID] == null) { GregTech_API.METATILEENTITIES[aID] = this; } else { throw new IllegalArgumentException("MetaMachine-Slot Nr. " + aID + " is already occupied!"); } mName = aBasicName.replaceAll(" ", "_").toLowerCase(Locale.ENGLISH); setBaseMetaTileEntity(GregTech_API.constructBaseMetaTileEntity()); getBaseMetaTileEntity().setMetaTileID((short) aID); GT_LanguageManager.addStringLocalization("gt.blockmachines." + mName + ".name", aRegionalName); mInventory = new ItemStack[aInvSlotCount]; } /** * This is the normal Constructor. */ public MetaTileEntity(String aName, int aInvSlotCount) { mInventory = new ItemStack[aInvSlotCount]; mName = aName; } @Override public IGregTechTileEntity getBaseMetaTileEntity() { return mBaseMetaTileEntity; } @Override public void setBaseMetaTileEntity(IGregTechTileEntity aBaseMetaTileEntity) { if (mBaseMetaTileEntity != null && aBaseMetaTileEntity == null) { mBaseMetaTileEntity.getMetaTileEntity().inValidate(); mBaseMetaTileEntity.setMetaTileEntity(null); } mBaseMetaTileEntity = aBaseMetaTileEntity; if (mBaseMetaTileEntity != null) { mBaseMetaTileEntity.setMetaTileEntity(this); } } @Override public ItemStack getStackForm(long aAmount) { return new ItemStack(GregTech_API.sBlockMachines, (int) aAmount, getBaseMetaTileEntity().getMetaTileID()); } public String getLocalName() { return GT_LanguageManager.getTranslation("gt.blockmachines." + mName + ".name"); } @Override public void onServerStart() {/*Do nothing*/} @Override public void onWorldSave(File aSaveDirectory) {/*Do nothing*/} @Override public void onWorldLoad(File aSaveDirectory) {/*Do nothing*/} @Override public void onConfigLoad(GT_Config aConfig) {/*Do nothing*/} @Override public void setItemNBT(NBTTagCompound aNBT) {/*Do nothing*/} @Override @SideOnly(Side.CLIENT) public void registerIcons(IIconRegister aBlockIconRegister) {/*Do nothing*/} @Override public boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack) { return true; } @Override public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {/*Do nothing*/} @Override public boolean onWrenchRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { if (getBaseMetaTileEntity().isValidFacing(aWrenchingSide)) { getBaseMetaTileEntity().setFrontFacing(aWrenchingSide); return true; } return false; } @Override public boolean onWireCutterRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { if(!aPlayer.isSneaking()) return false; byte tSide = GT_Utility.getOppositeSide(aWrenchingSide); TileEntity tTileEntity = getBaseMetaTileEntity().getTileEntityAtSide(aWrenchingSide); if (tTileEntity != null && (tTileEntity instanceof IGregTechTileEntity) && (((IGregTechTileEntity) tTileEntity).getMetaTileEntity() instanceof GT_MetaPipeEntity_Cable)) { // The tile entity we're facing is a cable, let's try to connect to it return ((IGregTechTileEntity) tTileEntity).getMetaTileEntity().onWireCutterRightClick(aWrenchingSide, tSide, aPlayer, aX, aY, aZ); } return false; } @Override public boolean onSolderingToolRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { if(!aPlayer.isSneaking()) return false; byte tSide = GT_Utility.getOppositeSide(aWrenchingSide); TileEntity tTileEntity = getBaseMetaTileEntity().getTileEntityAtSide(aWrenchingSide); if (tTileEntity != null && (tTileEntity instanceof IGregTechTileEntity) && (((IGregTechTileEntity) tTileEntity).getMetaTileEntity() instanceof GT_MetaPipeEntity_Cable)) { // The tile entity we're facing is a cable, let's try to connect to it return ((IGregTechTileEntity) tTileEntity).getMetaTileEntity().onSolderingToolRightClick(aWrenchingSide, tSide, aPlayer, aX, aY, aZ); } return false; } @Override public void onExplosion() { GT_Log.exp.println("Machine at "+this.getBaseMetaTileEntity().getXCoord()+" | "+this.getBaseMetaTileEntity().getYCoord()+" | "+this.getBaseMetaTileEntity().getZCoord()+" DIMID: "+ this.getBaseMetaTileEntity().getWorld().provider.dimensionId+ " exploded."); } @Override public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) {/*Do nothing*/} @Override public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {/*Do nothing*/} @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {/*Do nothing*/} @Override public void inValidate() {/*Do nothing*/} @Override public void onRemoval() {/*Do nothing*/} @Override public void initDefaultModes(NBTTagCompound aNBT) {/*Do nothing*/} /** * When a GUI is opened */ public void onOpenGUI() {/*Do nothing*/} /** * When a GUI is closed */ public void onCloseGUI() {/*Do nothing*/} /** * a Player rightclicks the Machine * Sneaky rightclicks are not getting passed to this! */ public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { return false; } @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { return onRightclick(aBaseMetaTileEntity, aPlayer); } @Override public void onLeftclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {/*Do nothing*/} @Override public void onValueUpdate(byte aValue) {/*Do nothing*/} @Override public byte getUpdateData() { return 0; } @Override public void doSound(byte aIndex, double aX, double aY, double aZ) {/*Do nothing*/} @Override public void startSoundLoop(byte aIndex, double aX, double aY, double aZ) {/*Do nothing*/} @Override public void stopSoundLoop(byte aValue, double aX, double aY, double aZ) {/*Do nothing*/} @Override public final void sendSound(byte aIndex) { if (!getBaseMetaTileEntity().hasMufflerUpgrade()) getBaseMetaTileEntity().sendBlockEvent((byte) 4, aIndex); } @Override public final void sendLoopStart(byte aIndex) { if (!getBaseMetaTileEntity().hasMufflerUpgrade()) getBaseMetaTileEntity().sendBlockEvent((byte) 5, aIndex); mSoundRequests++; } @Override public final void sendLoopEnd(byte aIndex) { if (!getBaseMetaTileEntity().hasMufflerUpgrade()) getBaseMetaTileEntity().sendBlockEvent((byte) 6, aIndex); } /** * @return true if this Device emits Energy at all */ public boolean isElectric() { return true; } /** * @return true if this Device emits Energy at all */ public boolean isPneumatic() { return false; } /** * @return true if this Device emits Energy at all */ public boolean isSteampowered() { return false; } /** * @return true if this Device emits Energy at all */ public boolean isEnetOutput() { return false; } /** * @return true if this Device consumes Energy at all */ public boolean isEnetInput() { return false; } /** * @return the amount of EU, which can be stored in this Device. Default is 0 EU. */ public long maxEUStore() { return 0; } /** * @return the amount of EU/t, which can be accepted by this Device before it explodes. */ public long maxEUInput() { return 0; } /** * @return the amount of EU/t, which can be outputted by this Device. */ public long maxEUOutput() { return 0; } /** * @return the amount of E-net Impulses of the maxEUOutput size, which can be outputted by this Device. * Default is 1 Pulse, this shouldn't be set to smaller Values than 1, as it won't output anything in that Case! */ public long maxAmperesOut() { return 1; } /** * How many Amperes this Block can suck at max. Surpassing this value won't blow it up. */ public long maxAmperesIn() { return 1; } /** * @return true if that Side is an Output. */ public boolean isOutputFacing(byte aSide) { return false; } /** * @return true if that Side is an Input. */ public boolean isInputFacing(byte aSide) { return false; } /** * @return true if Transformer Upgrades increase Packet Amount. */ public boolean isTransformingLowEnergy() { return true; } @Override public boolean isFacingValid(byte aFacing) { return false; } @Override public boolean isAccessAllowed(EntityPlayer aPlayer) { return false; } @Override public boolean isValidSlot(int aIndex) { return true; } @Override public boolean setStackToZeroInsteadOfNull(int aIndex) { return false; } /** * This is used to get the internal Energy. I use this for the IDSU. */ public long getEUVar() { return ((BaseMetaTileEntity) mBaseMetaTileEntity).mStoredEnergy; } /** * This is used to set the internal Energy to the given Parameter. I use this for the IDSU. */ public void setEUVar(long aEnergy) { ((BaseMetaTileEntity) mBaseMetaTileEntity).mStoredEnergy = aEnergy; } /** * This is used to get the internal Steam Energy. */ public long getSteamVar() { return ((BaseMetaTileEntity) mBaseMetaTileEntity).mStoredSteam; } /** * This is used to set the internal Steam Energy to the given Parameter. */ public void setSteamVar(long aSteam) { ((BaseMetaTileEntity) mBaseMetaTileEntity).mStoredSteam = aSteam; } /** * @return the amount of Steam, which can be stored in this Device. Default is 0 EU. */ public long maxSteamStore() { return 0; } /** * @return the amount of EU, which this Device stores before starting to emit Energy. * useful if you don't want to emit stored Energy until a certain Level is reached. */ public long getMinimumStoredEU() { return 512; } /** * Determines the Tier of the Machine, used for de-charging Tools. */ public long getInputTier() { return GT_Utility.getTier(getBaseMetaTileEntity().getInputVoltage()); } /** * Determines the Tier of the Machine, used for charging Tools. */ public long getOutputTier() { return GT_Utility.getTier(getBaseMetaTileEntity().getOutputVoltage()); } /** * gets the first RechargerSlot */ public int rechargerSlotStartIndex() { return 0; } /** * gets the amount of RechargerSlots */ public int rechargerSlotCount() { return 0; } /** * gets the first DechargerSlot */ public int dechargerSlotStartIndex() { return 0; } /** * gets the amount of DechargerSlots */ public int dechargerSlotCount() { return 0; } /** * gets if this is protected from other Players per default or not */ public boolean ownerControl() { return false; } @Override public ArrayList