Jump to content

Recommended Posts

Posted

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

Posted

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.

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/

Posted

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]

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.