Posted March 4, 20232 yr 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()); } }
March 4, 20232 yr 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?
March 7, 20232 yr 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.