Jump to content

Recommended Posts

Posted

Hi,

 

I've got a small problem.

I want to have a random boolean in my tile entity which get's saved, but I don't know where

to initialize the random boolean.

 

It could be done in the constructor, but the constructor get's called when an object get's created. So wouldn't then be a new

random boolean created when for example MC get's restarted instead of using the saved one?

 

Thx in advance.

Bektor

Developer of Primeval Forest.

Posted

Hi,

 

I've got a small problem.

I want to have a random boolean in my tile entity which get's saved, but I don't know where

to initialize the random boolean.

 

It could be done in the constructor, but the constructor get's called when an object get's created. So wouldn't then be a new

random boolean created when for example MC get's restarted instead of using the saved one?

 

Thx in advance.

Bektor

Developer of Primeval Forest.

Posted

Make global PRIVATE Boolean. In your read/write NBTmethods make "this.bool = nbt.getBoolean("B");" and "nbt.setBoolean("B");".

Create getter for said boolean such as:

private static Random RAND = new Random();

public boolean getBool()
{
    if (this.bool == null)
    {
        this.bool = RAND.nextBoolean();
    }
    return this.bool;
}

1.7.10 is no longer supported by forge, you are on your own.

Posted

Make global PRIVATE Boolean. In your read/write NBTmethods make "this.bool = nbt.getBoolean("B");" and "nbt.setBoolean("B");".

Create getter for said boolean such as:

private static Random RAND = new Random();

public boolean getBool()
{
    if (this.bool == null)
    {
        this.bool = RAND.nextBoolean();
    }
    return this.bool;
}

1.7.10 is no longer supported by forge, you are on your own.

Posted

Make global PRIVATE boolean. In your read/write NBTmethods make "this.bool = nbt.getBoolean("B");" and "nbt.setBoolean("B");".

Create getter for said boolean such as:

private static Random RAND = new Random();

public boolean getBool()
{
    if (this.bool == null)
    {
        this.bool = RAND.nextBoolean();
    }
    return this.bool;
}

There is just one problem. A boolean is NEVER null. If it has no value, it gets assigned I think true.

Developer of Primeval Forest.

Posted

Make global PRIVATE boolean. In your read/write NBTmethods make "this.bool = nbt.getBoolean("B");" and "nbt.setBoolean("B");".

Create getter for said boolean such as:

private static Random RAND = new Random();

public boolean getBool()
{
    if (this.bool == null)
    {
        this.bool = RAND.nextBoolean();
    }
    return this.bool;
}

There is just one problem. A boolean is NEVER null. If it has no value, it gets assigned I think true.

Developer of Primeval Forest.

Posted

boolean - will ne false. (generic primitive) (I messed up)

Boolean - will be null. (object)

1.7.10 is no longer supported by forge, you are on your own.

Posted

boolean - will ne false. (generic primitive) (I messed up)

Boolean - will be null. (object)

1.7.10 is no longer supported by forge, you are on your own.

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.