From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Wed, 15 Mar 2023 18:29:45 -0700 Subject: [PATCH] Fix certain inventories returning null Locations Wandering Trader, AbstractHorse, Beacon and Composter inventories returned null locations when a block or entity location is readily available Co-authored-by: Lukas Planz diff --git a/src/main/java/net/minecraft/world/SimpleContainer.java b/src/main/java/net/minecraft/world/SimpleContainer.java index d5eeb2fcb119b815213aeffb3811d4a843502e50..061e870e0cdd5bf00351b7e8104361bce86809f3 100644 --- a/src/main/java/net/minecraft/world/SimpleContainer.java +++ b/src/main/java/net/minecraft/world/SimpleContainer.java @@ -63,6 +63,16 @@ public class SimpleContainer implements Container, StackedContentsCompatible { @Override public Location getLocation() { + // Paper start + // When the block inventory does not have a tile state that implements getLocation, e. g. composters + if (this.bukkitOwner instanceof org.bukkit.inventory.BlockInventoryHolder blockInventoryHolder) { + return blockInventoryHolder.getBlock().getLocation(); + } + // When the bukkit owner is a bukkit entity, but does not implement Container itself, e. g. horses + if (this.bukkitOwner instanceof org.bukkit.entity.Entity entity) { + return entity.getLocation(); + } + // Paper end return null; } diff --git a/src/main/java/net/minecraft/world/inventory/BeaconMenu.java b/src/main/java/net/minecraft/world/inventory/BeaconMenu.java index 0b1a0be964d799f1706c273092dc653fa04e8014..a6e712606ece631502ae4c7513403092df77524f 100644 --- a/src/main/java/net/minecraft/world/inventory/BeaconMenu.java +++ b/src/main/java/net/minecraft/world/inventory/BeaconMenu.java @@ -51,6 +51,12 @@ public class BeaconMenu extends AbstractContainerMenu { public int getMaxStackSize() { return 1; } + // Paper start + @Override + public org.bukkit.Location getLocation() { + return context.getLocation(); + } + // Paper end }; checkContainerDataCount(propertyDelegate, 3); this.beaconData = propertyDelegate; diff --git a/src/main/java/net/minecraft/world/inventory/MerchantContainer.java b/src/main/java/net/minecraft/world/inventory/MerchantContainer.java index 083e50e27685f441ede4c75e913d671fe45d1d15..98cbcf67d8fdb1c80fb7ba8ba7734821e2818da6 100644 --- a/src/main/java/net/minecraft/world/inventory/MerchantContainer.java +++ b/src/main/java/net/minecraft/world/inventory/MerchantContainer.java @@ -65,7 +65,7 @@ public class MerchantContainer implements Container { @Override public Location getLocation() { - return (this.merchant instanceof Villager) ? ((Villager) this.merchant).getBukkitEntity().getLocation() : null; + return (this.merchant instanceof AbstractVillager) ? ((AbstractVillager) this.merchant).getBukkitEntity().getLocation() : null; // Paper } // CraftBukkit end