Jump to content

[1.11.2] Custom Furnace - Last Step, Saving Data Help [SOLVED]


HalestormXV

Recommended Posts

EnumFacing is a 6-value property.

If you don't want to have a block face up/down you can use EnumFacing.getHorizontalIndex instead.

  • Like 1

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.

Link to comment
Share on other sites

22 minutes ago, Draco18s said:

EnumFacing is a 6-value property.

If you don't want to have a block face up/down you can use EnumFacing.getHorizontalIndex instead.

 

Similar to what you did here: 

 

but wouldn't that mean I'd have to change all the code around for the block along with the JSON properties for it? Or  are you saying I have to do that anyway, because I cannot get the data for blockIsActive effectively because it is only going to be a 0 or a 1 and it won't be able to be stored correctly to begin with? I mean if EnumFacing is 6-value and this boolean is 1 Value (true or false) that is a total of 7. Can't the block store 16 bits? So why would have to change it, unless the boolean isn't able to be stored corretly.

 

Edited by HalestormXV
Link to comment
Share on other sites

15 minutes ago, HalestormXV said:

but wouldn't that mean I'd have to change all the code around for the block along with the JSON properties for it? Or  are you saying I have to do that anyway, because I cannot get the data for blockIsActive effectively because it is only going to be a 0 or a 1 and it won't be able to be stored correctly to begin with? I mean if EnumFacing is 6-value and this boolean is 1 Value (true or false) that is a total of 7. Can't the block store 16 bits? So why would have to change it, unless the boolean isn't able to be stored corretly.

 

That's not 7, that's 12.

2 possibilities * 6 possibilities = 12

You can also use a different bit (6 -> 8, uses bx0111, leaves bx1000 for the boolean)

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.

Link to comment
Share on other sites

Thanks. I think I got it. I shifted it one more spot over:

@Override
public int getMetaFromState(IBlockState state)
{
    int blockIsActive = (state.getValue(BURNING) ? 1 : 0) << 3;
    int facingDirection = ((EnumFacing)state.getValue(FACING)).getIndex();
    return facingDirection | blockIsActive;
}

 

And switched up the facing (to use horizontal) along with the ordering:

@Override
public IBlockState getStateFromMeta(int meta)
{
    EnumFacing facing = EnumFacing.getHorizontal(meta);
    if(facing.getAxis() == EnumFacing.Axis.Y)
        facing = EnumFacing.NORTH;

    boolean blockIsActive = (meta & 8) > 2;

    return this.getDefaultState().withProperty(FACING, facing).withProperty(BURNING, blockIsActive);
}

I imagine all of this is correct? Since it seems to be replicating properly in game. And that ( meta & 8 ) > 2 effectively takes whatever the 8th value of the meta is compares if it is greater than 2 and destroys the rest? 

 

I do apprecaite all the help you gave me through all of this. Now my last request. And this has nothing to do with the code. This purely has to do with me wanting to learn so I know how to manipulate the metadata/bits in the future. I started off with the original example shifting the bits over with this ? 1 : 0 << 2 which basically added 2 zeros to the 1 or the 0 right? Effectively multiplying the number by 2. So either 2 * 1 or 2* 0. Which shifted the bits over 2 places. But that wasn't good enough because I was using the Enum Facing which takes 6 spots. So when I was trying to pull the data out it was screwing crap up. So by changing the EnumFacing facing = EnumFacing.getFront(meta); to EnumFacing facing = EnumFacing.getHorizontal(meta) it freed up two extra spots or 1 Extra Spot? in the bit data. 

 

So once I changed that and then changed the shift over to a 3 with << 3 it moved the boolean value (1 or 2) over 6 bytes (3*2) or did it just add 3 zeros to the value? Regardless of what it did, the actual code effectively moved the boolean value (1 or 2) over enough spaces so that there was no conflict with the facing data and was able to extract the new reduced facing data (4 values instead of 6) and the boolean value (0 or 1). 

 

Does that sound right or is it somewhat right. Like I said, I don't just want answers I legeitametly want to learn by code what is going on. And tutorials, classes, etc. can only do so much (for me at least). For me i learn best by seeing an example and trying/doing a replication of it and then I can see its functionality. Everyone is different but that is just how I learn. And if at all possible in your explanation can you not use bx0111 etc. that quite literally confused the crap out of me. (I think it means decimal value of a number?)

Edited by HalestormXV
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

1 hour ago, Draco18s said:

I am aware of the wikipedia link and how the operators function. Thats why I used them in the code. What I am asking is how it works in his code in a simplified explanation for people like myself and others who may view this post and seek a more defining answer specifically to what is going on in this code. Different explanations or explaining something different ways help me learn as I am sure it helps others learn. This isn't about just getting answers and asking for stuff. It is about learning the code and how it functions in game without simply looking up definitions. People explain stuff in different ways. A wikipedia link gives you the definition sure, but it doesn't tell you how it is actually functioning in the above code. I am asking so that can see how @gummby8 explains it. The wiki link doesnt explain why he is using

i += 4;

or

 

if (facing >= 4) {
			facing -= 4;

etc. and then using 

return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta & 3)
Edited by HalestormXV
Link to comment
Share on other sites

TL;DR you're composing states into 4 bits worth of information and the decomposing those 4 bits back into states.

Booleans are 1 bit, integers are 1-4, depending on how many values they have (horizontal facing uses 2 bits, full facing uses 3).

Bitwise operators mask off the bits that aren't related to the bit(s) you care about.  & 3 means that only the lowest two bits retain their values:

  bx1010 //some arbitrary meta value

& bx0011 // & 3

========

  bx0010 //facing value (2)

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.

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.