Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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());
        }
    }

 

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?

  • Author
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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.