SpongePowered / Sponge

The SpongeAPI implementation targeting vanilla Minecraft and 3rd party platforms.
MIT License
390 stars 211 forks source link

ClassCastException when querying inventory #4017

Closed SamB440 closed 5 months ago

SamB440 commented 5 months ago

Affected Product(s)

SpongeVanilla

Version

1.20.6-11.0.0-RC1613

Operating System

Linux

Java Version

21

Plugins/Mods

Battlegrounds + dependents

Describe the bug

Querying an inventory with:

final Optional<Container> openContainer = player.openInventory();
if (openContainer.isPresent()) {
    amount += openContainer.get().query(QueryTypes.ITEM_TYPE, material).totalQuantity();
}

Will give the following error:

[16:11:27] [Server thread/ERROR] [sponge]: Could not pass ChangeInventoryEvent$Pickup$Pre$Impl to battlegrounds
java.lang.ClassCastException: class net.minecraft.world.inventory.ResultContainer cannot be cast to class net.minecraft.world.entity.player.Inventory (net.minecraft.world.inventory.ResultContainer and net.minecraft.world.entity.player.Inventory are in unnamed module of loader cpw.mods.modlauncher.TransformingClassLoader @34819867)
        at org.spongepowered.common.inventory.lens.impl.slot.HeldHandSlotLens.getInventoryPlayer(HeldHandSlotLens.java:63) ~[HeldHandSlotLens.class:1.20.6-11.0.0-RC1613]
        at org.spongepowered.common.inventory.lens.impl.slot.HeldHandSlotLens.getStack(HeldHandSlotLens.java:68) ~[HeldHandSlotLens.class:1.20.6-11.0.0-RC1613]
        at org.spongepowered.common.inventory.query.type.ItemStackQuery.matches(ItemStackQuery.java:48) ~[ItemStackQuery.class:1.20.6-11.0.0-RC1613]
        at org.spongepowered.common.inventory.query.SpongeDepthQuery.depthFirstSearch(SpongeDepthQuery.java:65) ~[SpongeDepthQuery.class:1.20.6-11.0.0-RC1613]
        at org.spongepowered.common.inventory.query.SpongeDepthQuery.depthFirstSearch(SpongeDepthQuery.java:63) ~[SpongeDepthQuery.class:1.20.6-11.0.0-RC1613]
        at org.spongepowered.common.inventory.query.SpongeDepthQuery.depthFirstSearch(SpongeDepthQuery.java:63) ~[SpongeDepthQuery.class:1.20.6-11.0.0-RC1613]
        at org.spongepowered.common.inventory.query.SpongeDepthQuery.execute(SpongeDepthQuery.java:52) ~[SpongeDepthQuery.class:1.20.6-11.0.0-RC1613]
        at org.spongepowered.common.inventory.query.SpongeQuery.execute(SpongeQuery.java:54) ~[SpongeQuery.class:1.20.6-11.0.0-RC1613]
        at org.spongepowered.common.inventory.adapter.impl.DefaultImplementedAdapterInventory.query(DefaultImplementedAdapterInventory.java:231) ~[DefaultImplementedAdapterInventory.class:1.20.6-11.0.0-RC1613]
        at org.spongepowered.api.item.inventory.Inventory.query(Inventory.java:342) ~[Inventory.class:1.20.6-11.0.0-RC1613]

Link to logs

No response