Posted September 11, 201510 yr 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; }
September 11, 201510 yr Author dumb me thought if i set the blocks manually I also need to add the TE's . thank you I guess
September 11, 201510 yr Author never used UUID by now.. How do I store them as nbt? Can I use UUID#toString and UUID#fromString?
September 11, 201510 yr Author perfect. by the way why are there the methods getUniqueID? Both seem to return the same obj..
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.