MenuType API addition InventoryView Builders (#11816)

This commit is contained in:
Miles
2025-01-11 19:21:24 +00:00
committed by GitHub
parent 775002a357
commit c94922514a
27 changed files with 759 additions and 95 deletions

View File

@@ -9,7 +9,7 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.Container;
@@ -63,6 +_,31 @@
@@ -63,6 +_,32 @@
@Nullable
private ContainerSynchronizer synchronizer;
private boolean suppressRemoteUpdates;
@@ -37,6 +37,7 @@
+ com.google.common.base.Preconditions.checkState(this.title == null, "Title already set");
+ this.title = title;
+ }
+ public void startOpen() {}
+ // CraftBukkit end
protected AbstractContainerMenu(@Nullable MenuType<?> menuType, int containerId) {

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/world/inventory/ChestMenu.java
+++ b/net/minecraft/world/inventory/ChestMenu.java
@@ -9,6 +_,29 @@
@@ -9,6 +_,34 @@
public class ChestMenu extends AbstractContainerMenu {
private final Container container;
private final int containerRows;
@@ -26,14 +26,21 @@
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return this.bukkitEntity;
+ }
+
+ @Override
+ public void startOpen() {
+ this.container.startOpen(this.player.player);
+ }
+ // CraftBukkit end
private ChestMenu(MenuType<?> type, int containerId, Inventory playerInventory, int rows) {
this(type, containerId, playerInventory, new SimpleContainer(9 * rows), rows);
@@ -52,6 +_,9 @@
@@ -51,7 +_,10 @@
checkContainerSize(container, rows * 9);
this.container = container;
this.containerRows = rows;
container.startOpen(playerInventory.player);
- container.startOpen(playerInventory.player);
+ // container.startOpen(playerInventory.player); // Paper - don't startOpen until menu actually opens
+ // CraftBukkit start - Save player
+ this.player = playerInventory;
+ // CraftBukkit end

View File

@@ -27,6 +27,14 @@
this.addStandardInventorySlots(playerInventory, 108, 84);
}
@@ -61,6 +_,7 @@
@Override
public boolean stillValid(Player player) {
+ if (!checkReachable) return true; // Paper - checkReachable
return this.trader.stillValid(player);
}
@@ -105,12 +_,12 @@
ItemStack item = slot.getItem();
itemStack = item.copy();

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/world/inventory/ShulkerBoxMenu.java
+++ b/net/minecraft/world/inventory/ShulkerBoxMenu.java
@@ -9,6 +_,20 @@
@@ -9,6 +_,25 @@
public class ShulkerBoxMenu extends AbstractContainerMenu {
private static final int CONTAINER_SIZE = 27;
private final Container container;
@@ -17,18 +17,25 @@
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.player.player.getBukkitEntity(), new org.bukkit.craftbukkit.inventory.CraftInventory(this.container), this);
+ return this.bukkitEntity;
+ }
+
+ @Override
+ public void startOpen() {
+ container.startOpen(player.player);
+ }
+ // CraftBukkit end
public ShulkerBoxMenu(int containerId, Inventory playerInventory) {
this(containerId, playerInventory, new SimpleContainer(27));
@@ -18,6 +_,7 @@
@@ -18,7 +_,8 @@
super(MenuType.SHULKER_BOX, containerId);
checkContainerSize(container, 27);
this.container = container;
- container.startOpen(playerInventory.player);
+ this.player = playerInventory; // CraftBukkit - save player
container.startOpen(playerInventory.player);
+ // container.startOpen(playerInventory.player); // Paper - don't startOpen until menu actually opens
int i = 3;
int i1 = 9;
@@ -33,6 +_,7 @@
@Override