Fix Inventory#getLocation not working for the composter (#9596)

This commit is contained in:
Md5Lukas 2023-08-21 06:49:29 +02:00 committed by GitHub
parent d12916255a
commit 67a1a8caf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,30 +3,32 @@ From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Wed, 15 Mar 2023 18:29:45 -0700
Subject: [PATCH] Fix certain inventories returning null Locations
Wandering Trader, AbstractHorse, and Beacon inventories returned null locations
Wandering Trader, AbstractHorse, Beacon and Composter inventories returned null locations
when a block or entity location is readily available
diff --git a/src/main/java/net/minecraft/world/entity/animal/horse/AbstractHorse.java b/src/main/java/net/minecraft/world/entity/animal/horse/AbstractHorse.java
index 49d7109b6ca63c8073db777549a65b2fcb70967e..9b35a50eb99551f28d45fd5114e0401b4c54646e 100644
--- a/src/main/java/net/minecraft/world/entity/animal/horse/AbstractHorse.java
+++ b/src/main/java/net/minecraft/world/entity/animal/horse/AbstractHorse.java
@@ -345,7 +345,15 @@ public abstract class AbstractHorse extends Animal implements ContainerListener,
public void createInventory() {
SimpleContainer inventorysubcontainer = this.inventory;
Co-authored-by: Lukas Planz <lukas.planz@web.de>
- this.inventory = new SimpleContainer(this.getInventorySize(), (org.bukkit.entity.AbstractHorse) this.getBukkitEntity()); // CraftBukkit
diff --git a/src/main/java/net/minecraft/world/SimpleContainer.java b/src/main/java/net/minecraft/world/SimpleContainer.java
index e938e46a142f3764f8224a1fd035e7d541b59c56..9d1ee40456a8d7001eee654a62e62cab2626305a 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
+ this.inventory = new SimpleContainer(this.getInventorySize(), (org.bukkit.entity.AbstractHorse) this.getBukkitEntity()) // CraftBukkit
+ {
+ @Override
+ public org.bukkit.Location getLocation() {
+ return AbstractHorse.this.getBukkitEntity().getLocation();
+ // 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
if (inventorysubcontainer != null) {
inventorysubcontainer.removeListener(this);
int i = Math.min(inventorysubcontainer.getContainerSize(), this.inventory.getContainerSize());
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 335d0a85378c04dd466fafd42048b2474c815cb9..fb1d71143a0344432af9dc5c3085e217a2778f10 100644
--- a/src/main/java/net/minecraft/world/inventory/BeaconMenu.java