Jump to content

Recommended Posts

Posted

I have a new issue haha, although not sure what to do about it.

 

Currently trying to save to my block a PART integer:

private int part;

And then when it gets read, it will set the Block's PART data:

public static final PropertyInteger PART = PropertyInteger.create("part", 0, 3);

To the correct part.

 

Currently it is throwing a NullPointer exception for grabbing the state from the block:

getWorld().setBlockState(pos, getWorld().getBlockState(pos).withProperty(BlockTanningRack.FACING, EnumFacing.NORTH).withProperty(BlockTanningRack.PART, part));

Probably doing something really bad here, haha. Any ideas?

 

Btw, I am trying to save my data and load it to a state since in the future I will have larger than 16 states for a multiblock, so I want to understand how to do this part of it :D 

Posted

You should not store the part integer in the block.

Blocks are singletons. This means, that there is only 1 of each type, that exists in multiple locations when placed. You change the data in one block, you change the data in all blocks of that type.

 

Non-final information should be stored in the BlockState directly, or in a TileEntity.

 

You also have to override shouldRefresh in the TileEntity. By default, the tile is replaced with a new instance if the blockstate changes. Common fix is to return newBlockstate.getBlock() != oldBlockstate.getBlock().

 

Oh, and the more-than-16-states... Lookup IExtendedBlockState. It can hold more information than normal blockstates (so more than 16 possible states) but the additional data can not actively affect the world like normal blockstates. Extended blockstates are used mostly for storing information that affects rendering etc.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Posted (edited)

Regular block states can hold more than 16 variants just fine.

You just can't encode all of that information in the metadata.

 

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/farming/block/BlockTanner.java#L56

Each LEATHER_STATE is an emum corresponding to 3 values: NONE, RAW, TANNED

SALT_LEVEL is an integer ranging from 0 to 6.

FACING is a horizontal facing enum, 4 states

3 * 3 * 7 * 4 = 252

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

We need to see your code in context to know exactly what it's doing (and what it should be doing). Where is your part field? Where are you using the line which causes an NPE? Post your whole block and TE classes.

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.