package gregtech.api.metatileentity; import static gregtech.api.enums.GT_Values.GT; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Objects; 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.EntityLivingBase; 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 cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gnu.trove.list.TIntList; import gnu.trove.list.array.TIntArrayList; import gregtech.api.GregTech_API; import gregtech.api.enums.Dyes; import gregtech.api.enums.GT_Values; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IConnectable; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IColoredTileEntity; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.GT_Config; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Util; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; import gregtech.api.util.WorldSpawnedEventBuilder; import gregtech.common.GT_Client; import gregtech.common.covers.CoverInfo; /** * NEVER INCLUDE THIS FILE IN YOUR MOD!!! *
* Extend this Class to add a new MetaPipe 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 MetaPipeEntity implements IMetaTileEntity, IConnectable { /** * The Inventory of the MetaTileEntity. Amount of Slots can be larger than 256. HAYO! */ public final ItemStack[] mInventory; /** * This variable tells, which directions the Block is connected to. It is a Bitmask. */ public byte mConnections = 0; protected boolean mCheckConnections = false; /** * Only assigned for the MetaTileEntity in the List! Also only used to get the localized Name for the ItemStack and * for getInvName. */ public String mName; public boolean doTickProfilingInThisTick = true; /** * accessibility to this Field is no longer given, see below */ private IGregTechTileEntity mBaseMetaTileEntity; /** * This registers your Machine at the List. Use only ID's larger than 2048 - the ones lower are reserved by GT. * See also the list in the API package - it has a description that contains all the reservations. ** The constructor can be overloaded as follows: *
*
*
*
* public GT_MetaTileEntity_EBench(int id, String name, String nameRegional) {
* super(id, name, nameRegional);
* }
*
*
*
*
* @param aID the machine ID
*/
public MetaPipeEntity(int aID, String aBasicName, String aRegionalName, int aInvSlotCount) {
this(aID, aBasicName, aRegionalName, aInvSlotCount, true);
}
public MetaPipeEntity(int aID, String aBasicName, String aRegionalName, int aInvSlotCount, boolean aAddInfo) {
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(new BaseMetaPipeEntity());
getBaseMetaTileEntity().setMetaTileID((short) aID);
GT_LanguageManager.addStringLocalization("gt.blockmachines." + mName + ".name", aRegionalName);
mInventory = new ItemStack[aInvSlotCount];
if (aAddInfo && GT.isClientSide()) {
addInfo(aID);
}
}
protected final void addInfo(int aID) {
if (!GT.isClientSide()) return;
ItemStack tStack = new ItemStack(GregTech_API.sBlockMachines, 1, aID);
Objects.requireNonNull(tStack.getItem())
.addInformation(tStack, null, new ArrayList<>(), true);
}
/**
* This is the normal Constructor.
*/
public MetaPipeEntity(String aName, int aInvSlotCount) {
mInventory = new ItemStack[aInvSlotCount];
mName = aName;
}
/**
* For Pipe Rendering
*/
public abstract float getThickNess();
/**
* For Pipe Rendering
*/
public abstract boolean renderInside(ForgeDirection side);
public boolean isDisplaySecondaryDescription() {
return false;
}
@Override
public ITexture[] getTexture(IGregTechTileEntity baseMetaTileEntity, ForgeDirection side, ForgeDirection facing,
int colorIndex, boolean active, boolean redstoneLevel) {
return Textures.BlockIcons.ERROR_RENDERING;
}
public ITexture[] getTexture(IGregTechTileEntity baseMetaTileEntity, ForgeDirection sideDirection, int connections,
int colorIndex, boolean active, boolean redstoneLevel) {
return Textures.BlockIcons.ERROR_RENDERING;
}
@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 boolean isCoverOnSide(BaseMetaPipeEntity aPipe, EntityLivingBase aEntity) {
ForgeDirection side = ForgeDirection.UNKNOWN;
double difference = aEntity.posY - (double) aPipe.yCoord;
if (difference > 0.6 && difference < 0.99) {
side = ForgeDirection.UP;
}
if (difference < -1.5 && difference > -1.99) {
side = ForgeDirection.DOWN;
}
difference = aEntity.posZ - (double) aPipe.zCoord;
if (difference < -0.05 && difference > -0.4) {
side = ForgeDirection.NORTH;
}
if (difference > 1.05 && difference < 1.4) {
side = ForgeDirection.SOUTH;
}
difference = aEntity.posX - (double) aPipe.xCoord;
if (difference < -0.05 && difference > -0.4) {
side = ForgeDirection.WEST;
}
if (difference > 1.05 && difference < 1.4) {
side = ForgeDirection.EAST;
}
boolean tCovered = side != ForgeDirection.UNKNOWN && mBaseMetaTileEntity.getCoverIDAtSide(side) > 0;
if (isConnectedAtSide(side)) {
tCovered = true;
}
// GT_FML_LOGGER.info("Cover: "+mBaseMetaTileEntity.getCoverIDAtSide(aSide));
// toDo: filter cover ids that actually protect against temperature (rubber/plastic maybe?, more like asbestos)
return tCovered;
}
@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(ForgeDirection side, GT_ItemStack aCoverID) {
return true;
}
@Override
public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) {
/* Do nothing */
}
@Override
public boolean onWrenchRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer entityPlayer,
float aX, float aY, float aZ) {
return false;
}
@Override
public boolean onWireCutterRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer aPlayer,
float aX, float aY, float aZ) {
return false;
}
@Override
public boolean onSolderingToolRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer aPlayer,
float aX, float aY, float aZ) {
return false;
}
@Override
public void onExplosion() {
/* Do nothing */
}
@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) {
if (aBaseMetaTileEntity.isClientSide() && GT_Client.changeDetected == 4) {
/*
* Client tick counter that is set to 5 on hiding pipes and covers. It triggers a texture update next client
* tick when reaching 4, with provision for 3 more update tasks, spreading client change detection related
* work and network traffic on different ticks, until it reaches 0.
*/
aBaseMetaTileEntity.issueTextureUpdate();
}
}
@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 */
}
/**
* Called when a Player rightclicks the Machine. Sneaky rightclicks are not getting passed to this!
*/
@Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side,
float aX, float aY, float aZ) {
return false;
}
@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(GregTechTileClientEvents.DO_SOUND, aIndex);
}
@Override
public final void sendLoopStart(byte aIndex) {
if (!getBaseMetaTileEntity().hasMufflerUpgrade())
getBaseMetaTileEntity().sendBlockEvent(GregTechTileClientEvents.START_SOUND_LOOP, aIndex);
}
@Override
public final void sendLoopEnd(byte aIndex) {
if (!getBaseMetaTileEntity().hasMufflerUpgrade())
getBaseMetaTileEntity().sendBlockEvent(GregTechTileClientEvents.STOP_SOUND_LOOP, aIndex);
}
@Override
public boolean isFacingValid(ForgeDirection facing) {
return false;
}
@Override
public boolean isAccessAllowed(EntityPlayer aPlayer) {
return true;
}
@Override
public boolean isValidSlot(int aIndex) {
return true;
}
@Override
public boolean shouldDropItemAt(int index) {
return true;
}
@Override
public boolean setStackToZeroInsteadOfNull(int aIndex) {
return false;
}
@Override
public ArrayList