mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-30 19:40:37 +01:00
Fix 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 <lukas.planz@web.de>
This commit is contained in:
parent
7139479d40
commit
6e271dc9e4
3 changed files with 30 additions and 7 deletions
paper-server/patches/sources/net/minecraft/world
|
@ -1,6 +1,6 @@
|
|||
--- a/net/minecraft/world/SimpleContainer.java
|
||||
+++ b/net/minecraft/world/SimpleContainer.java
|
||||
@@ -14,16 +14,74 @@
|
||||
@@ -14,16 +14,84 @@
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
|
@ -50,9 +50,19 @@
|
|||
+ public org.bukkit.inventory.InventoryHolder getOwner() {
|
||||
+ return this.bukkitOwner;
|
||||
+ }
|
||||
+
|
||||
|
||||
+ @Override
|
||||
+ public Location getLocation() {
|
||||
+ // Paper start - Fix inventories returning null Locations
|
||||
+ // 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 - Fix inventories returning null Locations
|
||||
+ return null;
|
||||
+ }
|
||||
+
|
||||
|
@ -62,7 +72,7 @@
|
|||
+ this.items.set(slot, original.items.get(slot).copy());
|
||||
+ }
|
||||
+ }
|
||||
|
||||
+
|
||||
public SimpleContainer(int size) {
|
||||
- this.size = size;
|
||||
- this.items = NonNullList.withSize(size, ItemStack.EMPTY);
|
||||
|
|
|
@ -35,7 +35,20 @@
|
|||
@Override
|
||||
public boolean canPlaceItem(int slot, ItemStack stack) {
|
||||
return stack.is(ItemTags.BEACON_PAYMENT_ITEMS);
|
||||
@@ -69,6 +77,7 @@
|
||||
@@ -44,6 +52,12 @@
|
||||
public int getMaxStackSize() {
|
||||
return 1;
|
||||
}
|
||||
+ // Paper start - Fix inventories returning null Locations
|
||||
+ @Override
|
||||
+ public org.bukkit.Location getLocation() {
|
||||
+ return context.getLocation();
|
||||
+ }
|
||||
+ // Paper end - Fix inventories returning null Locations
|
||||
};
|
||||
checkContainerDataCount(propertyDelegate, 3);
|
||||
this.beaconData = propertyDelegate;
|
||||
@@ -69,6 +83,7 @@
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player player) {
|
||||
|
@ -43,7 +56,7 @@
|
|||
return stillValid(this.access, player, Blocks.BEACON);
|
||||
}
|
||||
|
||||
@@ -148,12 +157,30 @@
|
||||
@@ -148,12 +163,30 @@
|
||||
return BeaconMenu.decodeEffect(this.beaconData.get(2));
|
||||
}
|
||||
|
||||
|
@ -76,7 +89,7 @@
|
|||
}
|
||||
|
||||
}
|
||||
@@ -178,4 +205,17 @@
|
||||
@@ -178,4 +211,17 @@
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
+
|
||||
+ @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 - Fix inventories returning null Locations
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
|
|
Loading…
Add table
Reference in a new issue