Jump to content

Recommended Posts

Posted

I have a tile entity that holds a EMSLiquidStack (basically a LiquidStack but with my own liquid) and I'm trying to get the block for the tile entity to chat the liquid and the amount of liquid it contains.  The only problem is when I right click on the block it seems to call onBlockActivated() twice.  Any help would be appreciated.

 

Code:

 

 

Block class:


package QuantumMagic.Blocks;

import QuantumMagic.Core.CreativeTabQuantumMagic;
import QuantumMagic.ElectroMagneticSuspension.TileEntityWithEMSTank;
import QuantumMagic.TileEntities.TileEntityEMSPipe;
import QuantumMagic.TileEntities.TileEntityEMSTank;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatMessageComponent;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockWithEMSTank extends BlockContainer {

Class <? extends TileEntityWithEMSTank> Tile;

public BlockWithEMSTank(int par1, Class <? extends TileEntityWithEMSTank> tile, String s) {
	super(par1, Material.iron);
	Tile = tile;
	setUnlocalizedName(s);
	setCreativeTab(CreativeTabQuantumMagic.tabQuantumMagic);
}

@Override
public TileEntity createNewTileEntity(World world) {
	try {
		return Tile.newInstance();
	} catch (InstantiationException e) {
		e.printStackTrace();
		return null;
	} catch (IllegalAccessException e) {
		e.printStackTrace();
		return null;
	}
}

@Override
public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side)
{		

	TileEntityEMSPipe tile = (TileEntityEMSPipe) world.getBlockTileEntity(x, y, z);

	if(tile == null)
		return 1;


	return tile.getAmount() > 0 ? 15 : 0;
}


public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float pX, float pY, float pZ)
    {

	TileEntityWithEMSTank tank = (TileEntityWithEMSTank)world.getBlockTileEntity(x, y, z);

	if(tank != null && tank.getLiquidStack() != null && tank.getLiquid() != null)
		player.sendChatToPlayer(ChatMessageComponent.createFromTranslationKey("This EMS tank contains " + tank.getAmount() + "   " units of " + tank.getLiquid().getName()));

	System.out.println("This EMS tank contains " + tank.getAmount() + " units of " + tank.getLiquid().getName());



        return true;
    }

}

 

TileEntity:


package QuantumMagic.ElectroMagneticSuspension;

import QuantumMagic.ElectroMagneticSuspension.EMSLiquids.EMSLiquid;
import QuantumMagic.ElectroMagneticSuspension.EMSLiquids.EMSLiquids;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

public abstract class TileEntityWithEMSTank extends TileEntity implements IEMSTank {

protected EMSLiquidStack liquStack;

@Override
public boolean canFill(EMSLiquidStack stack) {
	return this.getLiquid().equals(stack.getLiquid());
}

@Override
public EMSLiquid getLiquid() {

	if(getLiquidStack() == null)
		return null;

	return getLiquidStack().getLiquid();
}

@Override
public int getAmount() {
	if(getLiquidStack() != null){
		if(getLiquidStack().getAmount() < 0)
			getLiquidStack().incremtAmount(-getLiquidStack().getAmount());

		return getLiquidStack().getAmount();
	}
	return 0;
}

@Override
public EMSLiquidStack getLiquidStack() {
	return liquStack;
}

@Override
public EMSLiquidStack fill(EMSLiquidStack stack) {
	if(stack != null && stack.getLiquid() != null){
		if(liquStack != null){
			if(!stack.getLiquid().equals(this.getLiquid()))
				return stack;


			while(getAmount() < getCapacity() && stack.getAmount() > 0){
				getLiquidStack().incremtAmount(1);
				stack.incremtAmount(-1);
			}

		} else if(liquStack == null || getLiquid() != null || this.getAmount() == 0){

			liquStack = new EMSLiquidStack(stack.getLiquid(), 0);

			while(getAmount() < getCapacity() && stack.getAmount() > 0){
				getLiquidStack().incremtAmount(1);
				stack.incremtAmount(-1);
			}

		}

	}
	return stack;

}

@Override
public EMSLiquidStack take(int wanted) {

	if(getLiquidStack() == null || getLiquid() == null){
		return null;
	}

	if(getAmount() == 0)
		return new EMSLiquidStack(getLiquid(), 0);

	EMSLiquidStack stack = new EMSLiquidStack(getLiquid(), 0);

	while(getAmount() > 0){
		stack.incremtAmount(1);
		getLiquidStack().incremtAmount(-1);
	}

	return stack;
}

public void fillFrom(IEMSTank tank) {

	if(tank != null && tank.getLiquidStack() != null && tank.getLiquid() != null){
		if(this.getLiquidStack() == null || this.getLiquid() == null || this.getAmount() == 0){

			liquStack = new EMSLiquidStack(tank.getLiquid(), 0);
			while(getAmount() < getCapacity() && tank.getAmount() > 0){
				liquStack.incremtAmount(1);
				tank.getLiquidStack().incremtAmount(-1);
			}

		}else{

			if(!this.getLiquid().equals(tank.getLiquid()))
				return;

			while(getAmount() < getCapacity() && tank.getAmount() > 0){
				liquStack.incremtAmount(1);
				tank.getLiquidStack().incremtAmount(-1);
			}

		}

	}

}

@Override
public void writeToNBT(NBTTagCompound compound){
	super.writeToNBT(compound);

	compound.setInteger("Amount", this.getAmount());
	compound.setInteger("LiquidId", this.getLiquid().getID());

}

public void readFromNBT(NBTTagCompound compound)
{
	super.readFromNBT(compound);

	liquStack = new EMSLiquidStack(EMSLiquids.getLiquidFromId(compound.getInteger("LiquidId")) , compound.getInteger("Amount"));


}



}


 

 

 

 

 

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.