Jump to content

Changing IProperty does not update model?


Big_Bad_E

Recommended Posts

I am trying to make the block model change depending on the IProperty, and the initial value is set correctly, but when I call IBlockState#cycleValue(property), the model (and value) is not changed.

I tried using TileEntity#markDirty() and overriding markDirty() and explicit calling it after I cycle the value, but the value doesn't change.

Current code to change values:

    @Override
    public void update() {
        if (lastConsume == 0) {
            System.out.println("Consuming coal");
            if (coal.getCount() > 0) {
                lastConsume = 400;
                power += 5;
                coal.setCount(coal.getCount()-1);
                markDirty();
            } else {
                System.out.println("Out of coal!");
                getWorld().getBlockState(getPos()).cycleProperty(CoalGeneratorBlock.LIT);
                lastConsume -= 1;
                markDirty();
            }
        } else if(lastConsume == -1) {
            if(coal.getCount() > 0) {
                power += 5;
                lastConsume = 400;
                System.out.println(getWorld().getBlockState(getPos()).getValue(CoalGeneratorBlock.LIT) + " consume");
                getWorld().getBlockState(getPos()).cycleProperty(CoalGeneratorBlock.LIT);
                System.out.println(getWorld().getBlockState(getPos()).getValue(CoalGeneratorBlock.LIT) + " consume");
                coal.setCount(coal.getCount()-1);
                markDirty();
            }
        } else {
            lastConsume -= 1;
            power += 20;
        }
    }

I added markDirty() after it did not work normally.

Current markDirty method:

    @Override
    public void markDirty() {
        System.out.println("Dirty!");
        world.markChunkDirty(pos, this);
        world.updateComparatorOutputLevel(pos, this.getBlockType());
        System.out.println(getWorld().getBlockState(getPos()).getValue(CoalGeneratorBlock.LIT) + " dirty");
    }

 

The code outprints "false consume" twice whenever lastConsume == -1, when it should print "false consume" then "true consume". Next it prints "Dirty!", then prints "false dirty".

Link to comment
Share on other sites

On 3/28/2019 at 3:57 AM, diesieben07 said:

IBlockState is immutable. Changing one of it's properties returns a new IBlockState. You have to use World#setBlockState to set the block state at a position.

Suprised Intellij didn’t tell me that, thanks for the response.

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.