Jump to content

[1.8] Problem with moving TileEntites


Failender

Recommended Posts

Hey everyone,

I am triing to create a block that, when placed, is removing itself and placing himself at pos.x 100 pos z .

Everything is working fine. Problem is that I have problems to store the information I need inside the TileEntity. I need the name of the placer stored inside the TE ( on server side client side doenst matter) , but its always storing null.

I am not sure if this is a problem with how I move the TE or sth else.

 

Block code


        @Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state,
		EntityLivingBase placer, ItemStack stack) {


	if(!worldIn.isRemote && placer instanceof EntityPlayer)
	{
		worldIn.setBlockToAir(pos);
		worldIn.removeTileEntity(pos);

		pos = new BlockPos(pos.getX(), 100, pos.getZ());
		worldIn.setBlockState(pos, ShadowsRising.baseBlock.getDefaultState());
		worldIn.setTileEntity(pos, new TileEntityBase());

		TileEntityBase base = (TileEntityBase) worldIn.getTileEntity(pos);

		base.setOwner(placer.getName());

		ExtendedPlayer.get((EntityPlayer) placer).setBasePos(pos);


	}
}

        @Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos,
		Entity entityIn) {

	if(entityIn instanceof EntityPlayer && !worldIn.isRemote) {
		EntityPlayer player = (EntityPlayer) entityIn;
		TileEntityBase base = (TileEntityBase) worldIn.getTileEntity(pos);

		System.out.println(base.getOwner()); //null always
		if(base.getOwner()!=null && base.getOwner().equals(player.getName())) player.addPotionEffect(new PotionEffect(23, 210));
	}
}

 

TE code

private String owner;


public void setOwner(String owner) {
	System.out.println("set: " +pos); //sanity checks
	System.out.println("set: "+worldObj.isRemote); //sanity checks
	this.owner = owner;
}

public String getOwner() {

	return owner;
}

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.