Jump to content

[1.7.2] Reading from TileEntity


SuperKid

Recommended Posts

Hello,

 

I am making a "multiblock" structure that requires 3 blocks one of top of the other to make it full, if it full it changes a variable called fullPole to true

 

I aint sure why, i change the variable when the last block is placed, but when i try to read it from other class it doesnt work.

 

public class TileEntityShowerPole  extends TileEntity 
{
public  boolean fullPole;
public void readFromNBT(NBTTagCompound nbtdata)
    {
        super.readFromNBT(nbtdata);
        this.fullPole = nbtdata.getBoolean("fullPole");
    }

    public void writeToNBT(NBTTagCompound nbtdata)
    {
        super.writeToNBT(nbtdata);
        nbtdata.setBoolean("fullPole", this.fullPole);
    }
public TileEntityShowerPole()
{
	fullPole=false;
}
public  void TestFullPole(World world,int x,int y,int z)
{
	if (world.getBlock(x, y-1, z) == OthersMod.showerPole)
	{
		if (world.getBlock(x, y-2, z) == OthersMod.showerPole)
		{
			fullPole=true;
			return;
		}
	}
	fullPole=false;
}
}

 

 

When i try to read it like

 

@Override
    public boolean canPlaceBlockAt(World world, int x, int y, int z)
    {
TileEntityShowerPole tileEntityShowerPole = (TileEntityShowerPole)world.getTileEntity(x, y, z-1);
        	if (tileEntityShowerPole!=null)     
        		System.out.println(tileEntityShowerPole.fullPole);
}

i always get false. when i right click the block

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
{
	if(!world.isRemote){
        TileEntityShowerPole tileEntityShowerPole = (TileEntityShowerPole)world.getTileEntity(x, y, z);
        if (tileEntityShowerPole!=null) 
        	System.out.println(tileEntityShowerPole.fullPole);
	}
	return true;
}

 

i get true.

 

i am running the TestFullPole on the ShowerPole onBlockAdded

 

Someone know what i am doing wrong?

 

 

 

Edit: The z-1 thing on can place is intentional, after printing the coordinates its the exact same.

Link to comment
Share on other sites

I fixed the issue, thanks anyways. the problem was with syncing to server

 

@Override

    public Packet getDescriptionPacket()

    {

    NBTTagCompound var1 = new NBTTagCompound();

    this.writeToNBT(var1);

    return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 2, var1);

    }

    @Override

    public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)

    {

    super.onDataPacket(net, packet);

readFromNBT(packet.func_148857_g());

    }

 

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.

×
×
  • Create New...

Important Information

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