Pancake Posted June 23, 2015 Posted June 23, 2015 Greetings! It's been a while since I've asked a question here. I was wondering if it's necessary to save the metadata in the NBT data of the TileEntity of a block. BlockFurnace does not do that, yet it managas to save the direction it's facing. I took a look at the Transposer from Redpower, it uses NBT. (link to redpower TileMachine) This is my current code: public class BlockItemRelay extends BlockSingularityBlock{ public static final String NAME = "ItemRelay"; private IIcon topIcon,bottomIcon,sideIcon; public BlockItemRelay() { super(); setBlockName(NAME); setBlockTextureName(Singularity.MODID + ":" + NAME); } @Override public TileEntity createNewTileEntity(World world, int meta) { return new TileEntityItemRelay(); } @Override public void registerBlockIcons(IIconRegister register) { topIcon=register.registerIcon(getTextureName()+"_top"); bottomIcon=register.registerIcon(getTextureName()+"_bottom"); sideIcon=register.registerIcon(getTextureName()+"_side"); } @Override public IIcon getIcon(int side, int meta){ if(meta==side) return bottomIcon; if(meta/2==side/2) return topIcon; return sideIcon; } @Override public void onBlockPlacedBy(World world, int x,int y, int z, EntityLivingBase entity,ItemStack stack){ super.onBlockPlacedBy(world,x,y,z,entity,stack); world.setBlockMetadataWithNotify(x,y,z,Utils.getMetaFromDirection(entity.rotationYaw,entity.rotationPitch),1); } } The metadata returned from Utils.getMetaFromDirection(yaw,pitch) is correct, and I added a line to the TileEntity of this block that prints the metadata of the block. It has the correct value. Now, when I exit the world and enter again, it prints -1. What. Am I really supposed to use NBT data here? I thought metadata was something saved automatically? Thanks in advance, Pancake Quote
larsgerrits Posted June 23, 2015 Posted June 23, 2015 Yes, metadata is saved automatically. But what Eloraam has done there is not metadata, but rather just a simple field in TileMachine that has to be saved to NBT. The vanilla furnace does use metadata to store it's rotation. Quote Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
Pancake Posted June 23, 2015 Author Posted June 23, 2015 I just figured it out! I was using the TileEntity's blockMetadata. It said -1, but worldObj.getBlockMetadata(xCoord,yCoord,zCoord) gave me the correct metadata. I know I have to use the getBlockMetadata method now, which initialises the blockMetadata if it's -1. My bad! :3 It's weird that that field isn't initialised from the start though. [sOLVED] Quote
Recommended Posts
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.