Jump to content

[1.7.10] Multiple Tile Entities


EmperorZelos

Recommended Posts

Sure, an example of where it has occured

 

package aerosteam.tileentity;

import java.util.Random;

import aerosteam.AeroSteam;
import aerosteam.SteamFuel;
import aerosteam.blocks.DeviceBoiler;
import aerosteam.recipes.AlloyRecipes;
import aerosteam.steam.ISteamContainment;
import aerosteam.steam.ISteamTransporter;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;	
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
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.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;

public class TileEntityBoiler extends TileEntity
implements IFluidHandler, ISidedInventory, ISteamTransporter, ISteamContainment{
private String localizedName;

private static final int[] slot_m1= new int[]{0};
private static final int[] slot_m2= new int[]{1};
private static final int[] slot_fuel= new int[]{2};
private static final int[] slot_alloy= new int[]{3};

private ItemStack[] slots=new ItemStack [4]; //amount of stacks the item uses

public static int ratioSteamWater=2;
public static int boilSpeed=3;
public int burnTime;
public int temperature;
public static int maxtmp=1000;
public int burnTemperature;
public int steam;
public static int maxsteam=6000;
public int water;
public int condense;
public static int maxwater=6000;
public int currentItemBurnTime;
public FluidTank myTank = new FluidTank(new FluidStack(FluidRegistry.WATER, 1), 10000);

//Steam stuff


//Ordinary stuff
public void setGuiDisplayName(String DisplayName) {
	this.localizedName=DisplayName;
}
public String getInventoryName(){
	return this.hasCustomInventoryName()? this.localizedName:"container.boiler";
}
public boolean hasCustomInventoryName(){
	return this.localizedName != null && this.localizedName.length()>	0;
}
public int getSizeInventory(){
	return this.slots.length;
}
@Override
public ItemStack getStackInSlot(int i) {
	return this.slots[i];
}
@Override
public ItemStack decrStackSize(int i1, int i2) {
	if(this.slots[i1] != null){
		ItemStack itemstack;
		if(this.slots[i1].stackSize <= i2){
			itemstack =this.slots[i1];
			this.slots[i1]=null;
			return itemstack;
		}else{
			itemstack =this.slots[i1].splitStack(i2);
			if(this.slots[i1].stackSize==0){
				this.slots[i1]=null;
			}
			return itemstack;
		}
	}else{
		return null;
	}
}
@Override
public ItemStack getStackInSlotOnClosing(int i) {
	if(this.slots[i] != null){
		ItemStack itemstack =this.slots[i];
		this.slots[i]=null;
		return itemstack;
	}
	return null;
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
	this.slots[i]=itemstack;
	if(itemstack != null &&itemstack.stackSize>this.getInventoryStackLimit()){
		itemstack.stackSize=this.getInventoryStackLimit();
	}
}
@Override
public int getInventoryStackLimit() {
	return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false:player.getDistanceSq((double)this.xCoord+0.5D, (double)this.yCoord+0.5D, (double)this.zCoord+0.5D) < 64.0D;
}
public void openInventory() {}
public void closeInventory() {}
@Override
public boolean isItemValidForSlot(int i, ItemStack stack) {
	return i==0 && isItemFuel(stack) ? true:i==3?false:true;
}

public boolean isItemFuel(ItemStack stack) {
	return getItemBurnTime(stack)>0;
}

private static int getItemBurnTime(ItemStack stack){
	if(stack==null){
		return 0;
	}else{
		Item item=stack.getItem();
		if(item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air){

		}
		if(item==Items.coal) return 1800;
	}
	return 0;
}

private int getItem	(ItemStack stack) {
	if(stack==null){
		return 0;
	}else{
		Item item=stack.getItem();
		if(item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air){
			Block block=Block.getBlockFromItem(item);
			//blook fuels
		}
	}
	return GameRegistry.getFuelValue(stack);
}
public boolean isBurning(){
	return this.burnTime>0;
}

public boolean isBoiling(){
	return this.temperature==this.maxtmp;
}

public boolean canBoil(){
	if (slots[1]==null){
		return false;
	}
	ItemStack itemstack = slots[1];
	if (slots[1].getItem() == Items.water_bucket) {
		return true;
	}else{
		return false;
	}
}

public int condenseRate(int tmp){
	return 10+tmp/100;
}

public void updateEntity(){
	boolean flag = this.isBurning();
	boolean flag1 = false;
	Random generator = new Random(); 

	if(this.isBurning()){
		this.burnTime--;
		if(this.temperature < this.maxtmp ){
			this.temperature++;
		}
	}else if(this.temperature > 0){
		int rnd = generator.nextInt(2) + 2;
		this.temperature -= rnd;
		//this.decrSteam(1);
		if(this.temperature<0)this.temperature=0;
	}
	if (this.temperature < this.maxtmp && this.steam > 0 && this.water < this.maxwater){
		this.condense++;
		if(this.condense >= condenseRate(this.temperature)){
			this.condense=0;
			this.steam-=this.ratioSteamWater;
			if(this.steam < 0) this.steam=0;
			this.water++;
		}
	}
	if(!this.worldObj.isRemote){
		if(this.burnTime == 0 ){
			this.currentItemBurnTime=getItemBurnTime(this.slots[0]);
			this.burnTime=getItemBurnTime(this.slots[0]);
			if(this.isBurning()){
				System.out.println("Burnflag" + flag);
				System.out.println("Burntime increased");
				flag1=true;
				if(this.slots[0]!=null){
					this.slots[0].stackSize--;
					if(this.slots[0].stackSize == 0)
						this.slots[0]=this.slots[0].getItem().getContainerItem(this.slots[0]);
				}
			}
		}
		if (canBoil()){
			this.water+=1000;
			slots[1]=new ItemStack(Items.bucket);
		}
		if (isBurning() && isBoiling() && this.water>0 ){
			if(this.burnTime % this.boilSpeed == 0){
				this.water--;
				this.steam+=this.ratioSteamWater;
			}

		}
	}


	if(flag!=this.isBurning()){
		DeviceBoiler.updateBoilerBlockState(this.burnTime>0,this.worldObj,this.xCoord,this.yCoord,this.zCoord);
		System.out.println("Statechanged");
	}
	if(flag1){
		this.markDirty();
	}
}
@Override
public int[] getAccessibleSlotsFromSide(int p_94128_1_) {
	return null;
}
@Override
public boolean canInsertItem(int i, ItemStack stack, int j) {
	return this.isItemValidForSlot(i, stack);
}
@Override
public boolean canExtractItem(int i, ItemStack stack,int j) {
	return j != 0 || i!= 1 || stack.getItem()==Items.bucket;
}

public int getBurnTimeRemainingScaled(int i){
	return this.burnTime*i/this.currentItemBurnTime;

}
public int getTemperatureScaled(int i){
	return this.temperature*i/this.maxtmp;
}
public int getWaterScaled(int i){
	return this.water*i/this.maxwater;
}
public int getSteamScaled(int i){
	return this.steam*i/this.maxsteam;
}


@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
	return this.myTank.fill(resource, doFill);
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource,
		boolean doDrain) {
	// TODO Auto-generated method stub
	return null;
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
	// TODO Auto-generated method stub
	return null;
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid) {
	// TODO Auto-generated method stub
	return false;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid) {
	// TODO Auto-generated method stub
	return false;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
	// TODO Auto-generated method stub
	return null;
}
@Override
public float getPressure() {
	return ((float) this.getSteam())/((float)this.getCapacity());
}
@Override
public boolean canInsert(ForgeDirection paramForgeDirection) {
	return true;
}
@Override
public int getCapacity() {
	return 5000;
}
@Override
public int getSteam() {
	//System.out.println("Boiler Steam: " + this.steam);
	return this.steam;
}
@Override
public void explode() {
	// TODO Auto-generated method stub

}
@Override
public void insertSteam(int amount) {
	this.steam += amount;

}
@Override
public void decrSteam(int paramInt) {
	this.steam -= paramInt;
}
@Override
public boolean doesConnect(ForgeDirection paramForgeDirection) {
	return true;
}
@Override
public boolean acceptsGauge(ForgeDirection paramForgeDirection) {
	return false;
}
public void readFromNBT(NBTTagCompound nbt){
	super.readFromNBT(nbt);
	NBTTagList list=nbt.getTagList("Items",10);
	this.slots=new ItemStack[this.getSizeInventory()];
	for(int i=0; i<list.tagCount();i++){
		NBTTagCompound compound = (NBTTagCompound) list.getCompoundTagAt(i);
		byte b=compound.getByte("Slot");

		if (b>=0 && b<this.slots.length){
			this.slots[b]=ItemStack.loadItemStackFromNBT(compound);
		}
	}
	this.burnTime=(int)nbt.getShort("BurnTime");
	this.temperature=(int)nbt.getShort("Temperature");
	this.water=(int)nbt.getShort("Water");
	this.steam=(int)nbt.getShort("Steam");
	this.currentItemBurnTime=(int)nbt.getShort("CurrentItemBurnTime");

	if(nbt.hasKey("CustomName")){
		this.localizedName=nbt.getString("CustomName");
	}
}
public void writeToNBT(NBTTagCompound nbt){
	super.writeToNBT(nbt);
	nbt.setShort("BurnTime",(short)this.burnTime);
	nbt.setShort("Temperature",(short)this.temperature);
	nbt.setShort("Water",(short)this.water);
	nbt.setShort("Steam",(short)this.steam);
	nbt.setShort("CurrentItemBurnTime",(short)this.currentItemBurnTime);

	NBTTagList list = new NBTTagList();
	for(int i=0; i<this.slots.length;i++){
		if(this.slots[i] != null){
			NBTTagCompound compound=new NBTTagCompound();
			compound.setByte("Slot",(byte)i);
			this.slots[i].writeToNBT(compound);
			list.appendTag(compound);
		}
	}

	nbt.setTag("Items",list);
	if(this.hasCustomInventoryName()){
		nbt.setString("CustomName",this.localizedName);
	}
}
@Override
public void changeSteam(int amount) {
	//System.out.println("Boiler had steam of: " + this.steam + ", was given amount:" + amount);
	this.steam += amount;
	//System.out.println("so now it has: " + this.steam);
}
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.