Unable to get TileEntity contents
Derp33 opened this issue · 6 comments
The getItemStackArray
method using the Items
key always returns null. Even if the TileEntity has the tag with items present.
To reproduce
@EventHandler
public void onInventoryOpen(InventoryOpenEvent event) {
if (event.getView().getTopInventory().getHolder() instanceof Barrel barrel) {
var barrelNBT = new NBTTileEntity(barrel);
var barrelContents = barrelNBT.getItemStackArray("Items");
this.getLogger().info("Barrel items '" + Arrays.toString(barrelContents) + "'");
}
}
Noteworthy, this item stack array method does not use the vanilla format. That's why it's not working.
(Added to that, there should be no reason to use the API to access items from a gui/barrel?)
Check how the data is setup(by printing the NBTTileEntity straight into the console/chat/whatever). Vanilla servers probably delete the "invalid" data on load. Then get the Items compound list and iterate over that, converting the tags to item stacks via the NBT class.
Ah, I see. Would there be a way to convert between them?
The reason behind this is a server was using a plugin to extend the inventory of barrels. They somehow did this by injecting the additional items directly into the item array. When the server reset they provided a world download but I'm unable to find the exact plugin they were using. It's possible it was custom.
The goal here is to allow players to open that world without losing half their items. I understand it's a bit of a niche problem.
@Derp33 Purpur offers a way to increase the number of rows in a barrel. https://purpurmc.org/docs/Configuration/barrel