Skip to content

Unpack loot table throw NPE #9917

@KioProject123

Description

@KioProject123

Expected behavior

No errors will be reported and the correct value will be returned

Observed/Actual behavior

java.lang.NullPointerException: Cannot invoke "net.minecraft.world.level.World.n()" because "this.o" is null
        at net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity.unpackLootTable(RandomizableContainerBlockEntity.java:73) ~[?:?]
        at net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity.isEmpty(RandomizableContainerBlockEntity.java:97) ~[?:?]
        at org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventory.isEmpty(CraftInventory.java:259) ~[paper-1.20.2.jar:git-Paper-280]
        at com.kiocg.TEST.TEST.onEnable(TEST.java:38) ~[KioCG-TEST.jar:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:281) ~[paper-api-1.20.2-R0.1-SNAPSHOT.jar:?]
        at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:189) ~[paper-1.20.2.jar:git-Paper-280]
        at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.enablePlugin(PaperPluginManagerImpl.java:104) ~[paper-1.20.2.jar:git-Paper-280]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:507) ~[paper-api-1.20.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_20_R2.CraftServer.enablePlugin(CraftServer.java:644) ~[paper-1.20.2.jar:git-Paper-280]
        at org.bukkit.craftbukkit.v1_20_R2.CraftServer.enablePlugins(CraftServer.java:555) ~[paper-1.20.2.jar:git-Paper-280]
        at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:627) ~[paper-1.20.2.jar:git-Paper-280]
        at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:424) ~[paper-1.20.2.jar:git-Paper-280]
        at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:308) ~[paper-1.20.2.jar:git-Paper-280]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1086) ~[paper-1.20.2.jar:git-Paper-280]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:315) ~[paper-1.20.2.jar:git-Paper-280]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]

I'm not sure if the error below is the same as the one above, so I'm posting it just in case.

java.lang.NullPointerException: Cannot invoke "net.minecraft.world.level.World.paperConfig()" because the return value of "com.destroystokyo.paper.loottable.PaperLootableInventory.getNMSWorld()" is null
        at com.destroystokyo.paper.loottable.PaperLootableInventoryData.shouldReplenish(PaperLootableInventoryData.java:54) ~[kiocg-1.20.2.jar:git-kiocg-"14af6a7"]
        at net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity.unpackLootTable(RandomizableContainerBlockEntity.java:73) ~[?:?]
        at net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity.isEmpty(RandomizableContainerBlockEntity.java:97) ~[?:?]
        at org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventory.isEmpty(CraftInventory.java:259) ~[kiocg-1.20.2.jar:git-kiocg-"14af6a7"]
        at com.kiocg.TEST.TEST.onPlayerInteract(TEST.java:44) ~[KioCG-TEST.jar:?]

Steps/models to reproduce

@Override
    public void onEnable() {
        ItemStack itemStack = new ItemStack(Material.CHEST);
        BlockState blockState = ((BlockStateMeta) itemStack.getItemMeta()).getBlockState();
        Chest chest = (Chest) blockState;
        chest.setLootTable(LootTables.ABANDONED_MINESHAFT.getLootTable());
        // NPE
        chest.getInventory().isEmpty();
    }
@EventHandler
    public void onPlayerInteract(final @NotNull PlayerInteractEvent e) {
        // NPE when clicking on a loot chest
        ((Chest) e.getClickedBlock().getState()).getSnapshotInventory().isEmpty();
    }

Plugin and Datapack List

N/A

Paper version

This server is running Paper version git-Paper-280 (MC: 1.20.2) (Implementing API version 1.20.2-R0.1-SNAPSHOT) (Git: 4675152)
You are running the latest version

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: acceptedDisputed bug is accepted as valid or Feature accepted as desired to be added.type: bugSomething doesn't work as it was intended to.

    Type

    No fields configured for Bug.

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions