Jump to content

Recommended Posts

Posted

Hello guys,

I'm trying to make a mod that adds auto miner block. To do this I created a block and a block entity that save the itemStack when a user right click on the block (the auo miner will generate item depending on the itemStack set), and I need to save this itemstack in order to keep it even after a game restart.

If I understood correctly, we need to use the "saveAdditional" function in order to save some tag on the entity. The thing is, how do you trigger this function everytime a user right click on the corresponding block entity ?  In my case this function is sometimes called when we right click on the block entity and sometimes it takes many seconds before the function is called.

Just below it's the saveAdditional fuction I'm using in a class that extends BlockEntity.

@Override
    protected void saveAdditional(CompoundTag pTag) {
        if (target != null) {
            System.out.println("target not null");
            pTag.put("target", target.serializeNBT());
        }
        super.saveAdditional(pTag);
    }

Thanks

Posted

Thanks @diesieben07 for your answer.

I noticed that when I apply a modification on the BlockEntity and immediately exit the game, the state of the blockEntity is not properly saved. It seems that it takes some seconds for the game to save it, but sometime it is immediately saved. Is there a way to avoid that ?

Posted

I have 2 classes : Miner (extends BaseEntityBlock) and MinerEntity (extends BlockEntity).

Miner

  Reveal hidden contents

 

MinerEntity

  Reveal hidden contents

Everytime a user right click on Miner block, it calls MinerEntity#update. When debugging I noticed that when I call setChanged(), it takes many seconds to print "target not null" in the terminal.

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.