Jump to content

Recommended Posts

Posted

I have added an inventory menu to my custom entity which is based off the chest boat class, and the container entity interface, but when I put an item in its inventory and close and reopen then inventory menu, the items disappear.

 

I suspect it has somethings to do with the two additional save data methods, but I can't seem to fix it.

@Nullable
private ResourceLocation lootTable;
private long lootTableSeed;

@Override
@Nullable
public ResourceLocation getLootTable() {
    return this.lootTable;
}

@Override
public void setLootTable(@Nullable ResourceLocation pLootTable) {
    this.lootTable = pLootTable;
}

@Override
public long getLootTableSeed() {
    return this.lootTableSeed;
}

@Override
public void setLootTableSeed(long pLootTableSeed) {
    this.lootTableSeed = pLootTableSeed;
}

@Override
    protected void readAdditionalSaveData(CompoundTag pCompound) {
        if (pCompound.contains("Type", 0)) {
            this.setType(RocketEntity.Type.byName(pCompound.getString("Type")));
        }
        this.clearItemStacks();
        if (pCompound.contains("LootTable", 0)) {
            this.setLootTable(new ResourceLocation(pCompound.getString("LootTable")));
            this.setLootTableSeed(pCompound.getLong("LootTableSeed"));
        } else {
            ContainerHelper.loadAllItems(pCompound, this.getItemStacks());
        }
    }

    @Override
    protected void addAdditionalSaveData(CompoundTag pCompound) {
        pCompound.putString("Type", this.getRocketType().getName());
        if (this.getLootTable() != null) {
            pCompound.putString("LootTable", this.getLootTable().toString());
            if (this.getLootTableSeed() != 0L) {
                pCompound.putLong("LootTableSeed", this.getLootTableSeed());
            }
        } else {
            ContainerHelper.saveAllItems(pCompound, this.getItemStacks());
        }
    }

 

Posted
7 hours ago, Master_J said:

I suspect it has somethings to do with the two additional save data methods, but I can't seem to fix it.

Do you set the loottable field to null after the inventory is populated or when the inventory is populated?

Posted
On 3/5/2023 at 2:07 AM, ChampionAsh5357 said:

Do you set the loottable field to null

I did some testing, and discovered that 

this.getLootTable()

always equals null. Upon looking at the chest boat class, it does not seem to ever assign a value to it.

 

I also discovered that the output of this.getItemStacks() was

[1 air, 1 air, 1 air, 1 air, 1 air, 1 air, 1 air, 1 air, 1 air]

 

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.