Co-authored-by: Bjarne Koll <git@lynxplay.dev>
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
Co-authored-by: MiniDigger | Martin <admin@minidigger.dev>
Co-authored-by: Nassim Jahnke <nassim@njahnke.dev>
Co-authored-by: Noah van der Aa <ndvdaa@gmail.com>
Co-authored-by: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Co-authored-by: Shane Freeder <theboyetronic@gmail.com>
Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>
Co-authored-by: Tamion <70228790+notTamion@users.noreply.github.com>
Co-authored-by: Warrior <50800980+Warriorrrr@users.noreply.github.com>
This commit is contained in:
Nassim Jahnke
2025-04-12 17:26:44 +02:00
parent 0767902699
commit f00727c57e
2092 changed files with 50551 additions and 48729 deletions

View File

@@ -1,21 +1,13 @@
--- a/net/minecraft/world/inventory/AbstractContainerMenu.java
+++ b/net/minecraft/world/inventory/AbstractContainerMenu.java
@@ -19,6 +_,8 @@
import net.minecraft.ReportedException;
import net.minecraft.core.NonNullList;
import net.minecraft.core.registries.BuiltInRegistries;
+import net.minecraft.network.chat.Component;
+import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.Container;
@@ -63,6 +_,32 @@
@@ -65,6 +_,36 @@
@Nullable
private ContainerSynchronizer synchronizer;
private boolean suppressRemoteUpdates;
+ // CraftBukkit start
+ public boolean checkReachable = true;
+ public abstract org.bukkit.inventory.InventoryView getBukkitView();
+
+ public void transferTo(AbstractContainerMenu other, org.bukkit.craftbukkit.entity.CraftHumanEntity player) {
+ org.bukkit.inventory.InventoryView source = this.getBukkitView(), destination = other.getBukkitView();
+ ((org.bukkit.craftbukkit.inventory.CraftInventory) source.getTopInventory()).getInventory().onClose(player);
@@ -23,47 +15,51 @@
+ ((org.bukkit.craftbukkit.inventory.CraftInventory) destination.getTopInventory()).getInventory().onOpen(player);
+ ((org.bukkit.craftbukkit.inventory.CraftInventory) destination.getBottomInventory()).getInventory().onOpen(player);
+ }
+ private Component title;
+ public final Component getTitle() {
+
+ @Nullable
+ private net.minecraft.network.chat.Component title;
+ public final net.minecraft.network.chat.Component getTitle() {
+ // Paper start - return chat component with empty text instead of throwing error
+ // Preconditions.checkState(this.title != null, "Title not set");
+ if (this.title == null){
+ return Component.literal("");
+ if (this.title == null) {
+ return net.minecraft.network.chat.Component.empty();
+ }
+ // Paper end - return chat component with empty text instead of throwing error
+ return this.title;
+ }
+ public final void setTitle(Component title) {
+
+ public final void setTitle(net.minecraft.network.chat.Component title) {
+ 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) {
this.menuType = menuType;
@@ -168,8 +_,18 @@
@@ -176,8 +_,19 @@
if (this.synchronizer != null) {
this.synchronizer.sendInitialData(this, this.remoteSlots, this.remoteCarried, this.remoteDataSlots.toIntArray());
this.synchronizer.sendInitialData(this, list, carried.copy(), this.remoteDataSlots.toIntArray());
- }
- }
+ this.synchronizer.sendOffHandSlotChange(); // Paper - Sync offhand slot in menus; update player's offhand since the offhand slot is not added to the slots for menus but can be changed by swapping from a menu slot
+ }
+ }
+
+ // CraftBukkit start
+ // CraftBukkit start - from synchronizeCarriedToRemote
+ public void broadcastCarriedItem() {
+ this.remoteCarried = this.getCarried().copy();
+ ItemStack carried = this.getCarried();
+ this.remoteCarried.force(carried);
+ if (this.synchronizer != null) {
+ this.synchronizer.sendCarriedChange(this, this.remoteCarried);
+ this.synchronizer.sendCarriedChange(this, carried.copy());
+ }
+ }
+ // CraftBukkit end
public void removeSlotListener(ContainerListener listener) {
this.containerListeners.remove(listener);
@@ -235,7 +_,7 @@
@@ -243,7 +_,7 @@
this.lastSlots.set(slotIndex, itemStack1);
for (ContainerListener containerListener : this.containerListeners) {
@@ -72,42 +68,7 @@
}
}
}
@@ -243,7 +_,7 @@
private void synchronizeSlotToRemote(int slotIndex, ItemStack stack, Supplier<ItemStack> supplier) {
if (!this.suppressRemoteUpdates) {
ItemStack itemStack = this.remoteSlots.get(slotIndex);
- if (!ItemStack.matches(itemStack, stack)) {
+ if (!this.matchesRemote(itemStack, stack)) { // Paper - add flag to simplify remote matching logic
ItemStack itemStack1 = supplier.get();
this.remoteSlots.set(slotIndex, itemStack1);
if (this.synchronizer != null) {
@@ -267,7 +_,7 @@
private void synchronizeCarriedToRemote() {
if (!this.suppressRemoteUpdates) {
- if (!ItemStack.matches(this.getCarried(), this.remoteCarried)) {
+ if (!this.matchesRemote(this.getCarried(), this.remoteCarried)) { // Paper - add flag to simplify remote matching logic
this.remoteCarried = this.getCarried().copy();
if (this.synchronizer != null) {
this.synchronizer.sendCarriedChange(this, this.remoteCarried);
@@ -276,6 +_,16 @@
}
}
+ // Paper start - add flag to simplify remote matching logic
+ private boolean matchesRemote(final ItemStack stack, final ItemStack other) {
+ if (this.synchronizer != null && this.synchronizer.player() != null && this.synchronizer.player().getBukkitEntity().simplifyContainerDesyncCheck()) {
+ // Only check the item type and count
+ return stack == other || (stack.getCount() == other.getCount() && ItemStack.isSameItem(stack, other));
+ }
+ return ItemStack.matches(stack, other);
+ }
+ // Paper end - add flag to simplify remote matching logic
+
public void setRemoteSlot(int slot, ItemStack stack) {
this.remoteSlots.set(slot, stack.copy());
}
@@ -343,6 +_,7 @@
@@ -351,6 +_,7 @@
this.resetQuickCraft();
}
} else if (this.quickcraftStatus == 1) {
@@ -115,7 +76,7 @@
Slot slot = this.slots.get(slotId);
ItemStack carried = this.getCarried();
if (canItemQuickReplace(slot, carried, true)
@@ -367,6 +_,7 @@
@@ -375,6 +_,7 @@
}
int count = this.getCarried().getCount();
@@ -123,7 +84,7 @@
for (Slot slot1 : this.quickcraftSlots) {
ItemStack carried1 = this.getCarried();
@@ -379,12 +_,48 @@
@@ -387,12 +_,48 @@
int min = Math.min(itemStack.getMaxStackSize(), slot1.getMaxStackSize(itemStack));
int min1 = Math.min(getQuickCraftPlaceCount(this.quickcraftSlots, this.quickcraftType, itemStack) + i2, min);
count -= min1 - i2;
@@ -152,9 +113,9 @@
+ this.setCarried(org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(newcursor));
+
+ org.bukkit.event.inventory.InventoryDragEvent event = new org.bukkit.event.inventory.InventoryDragEvent(view, (newcursor.getType() != org.bukkit.Material.AIR ? newcursor : null), org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(oldCursor), this.quickcraftType == 1, eventmap);
+ player.level().getCraftServer().getPluginManager().callEvent(event);
+ event.callEvent();
+
+ // Whether or not a change was made to the inventory that requires an update.
+ // Whether a change was made to the inventory that requires an update.
+ boolean needsUpdate = event.getResult() != org.bukkit.event.Event.Result.DEFAULT;
+
+ if (event.getResult() != org.bukkit.event.Event.Result.DENY) {
@@ -178,7 +139,7 @@
}
this.resetQuickCraft();
@@ -398,8 +_,11 @@
@@ -406,8 +_,11 @@
if (slotId == -999) {
if (!this.getCarried().isEmpty()) {
if (clickAction == ClickAction.PRIMARY) {
@@ -191,16 +152,16 @@
} else {
player.drop(this.getCarried().split(1), true);
}
@@ -461,8 +_,18 @@
@@ -469,8 +_,18 @@
}
slot.setChanged();
+ // CraftBukkit start - Make sure the client has the right slot contents
+ if (player instanceof ServerPlayer serverPlayer && slot.getMaxStackSize() != 64) {
+ serverPlayer.connection.send(new ClientboundContainerSetSlotPacket(this.containerId, this.incrementStateId(), slot.index, slot.getItem()));
+ serverPlayer.connection.send(new net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket(this.containerId, this.incrementStateId(), slot.index, slot.getItem()));
+ // Updating a crafting inventory makes the client reset the result slot, have to send it again
+ if (this.getBukkitView().getType() == org.bukkit.event.inventory.InventoryType.WORKBENCH || this.getBukkitView().getType() == org.bukkit.event.inventory.InventoryType.CRAFTING) {
+ serverPlayer.connection.send(new ClientboundContainerSetSlotPacket(this.containerId, this.incrementStateId(), 0, this.getSlot(0).getItem()));
+ serverPlayer.connection.send(new net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket(this.containerId, this.incrementStateId(), 0, this.getSlot(0).getItem()));
+ }
+ }
+ // CraftBukkit end
@@ -210,7 +171,7 @@
ItemStack item = inventory.getItem(button);
Slot slot = this.slots.get(slotId);
ItemStack carried = slot.getItem();
@@ -582,8 +_,9 @@
@@ -590,8 +_,9 @@
if (player instanceof ServerPlayer) {
ItemStack carried = this.getCarried();
if (!carried.isEmpty()) {
@@ -221,7 +182,7 @@
}
}
}
@@ -629,6 +_,14 @@
@@ -637,6 +_,14 @@
public abstract boolean stillValid(Player player);
protected boolean moveItemStackTo(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection) {
@@ -236,7 +197,7 @@
boolean flag = false;
int i = startIndex;
if (reverseDirection) {
@@ -639,18 +_,27 @@
@@ -647,18 +_,27 @@
while (!stack.isEmpty() && (reverseDirection ? i >= startIndex : i < endIndex)) {
Slot slot = this.slots.get(i);
ItemStack item = slot.getItem();
@@ -264,7 +225,7 @@
flag = true;
}
}
@@ -673,10 +_,21 @@
@@ -681,10 +_,21 @@
while (reverseDirection ? i >= startIndex : i < endIndex) {
Slot slotx = this.slots.get(i);
ItemStack itemx = slotx.getItem();
@@ -286,7 +247,7 @@
flag = true;
break;
}
@@ -760,6 +_,11 @@
@@ -768,6 +_,11 @@
}
public ItemStack getCarried() {
@@ -298,7 +259,7 @@
return this.carried;
}
@@ -808,4 +_,15 @@
@@ -820,4 +_,15 @@
this.stateId = this.stateId + 1 & 32767;
return this.stateId;
}

View File

@@ -15,8 +15,8 @@
this.height = height;
- this.craftSlots = new TransientCraftingContainer(this, width, height);
+ // CraftBukkit start
+ this.craftSlots = new TransientCraftingContainer(this, width, height, playerInventory.player); // CraftBukkit - pass player
+ this.craftSlots.resultInventory = this.resultSlots; // CraftBukkit - let InventoryCrafting know about its result slot
+ this.craftSlots = new TransientCraftingContainer(this, width, height, playerInventory.player);
+ this.craftSlots.resultInventory = this.resultSlots; // let InventoryCrafting know about its result slot
+ // CraftBukkit end
}

View File

@@ -5,18 +5,18 @@
private final RecipePropertySet acceptedInputs;
private final RecipeBookType recipeBookType;
+ // CraftBukkit start
+ private org.bukkit.craftbukkit.inventory.view.CraftFurnaceView bukkitEntity = null;
+ private Inventory player;
+ private @javax.annotation.Nullable org.bukkit.craftbukkit.inventory.view.CraftFurnaceView view = null;
+ private final Inventory inventory;
+
+ @Override
+ public org.bukkit.craftbukkit.inventory.view.CraftFurnaceView getBukkitView() {
+ if (this.bukkitEntity != null) {
+ return this.bukkitEntity;
+ if (this.view != null) {
+ return this.view;
+ }
+
+ org.bukkit.craftbukkit.inventory.CraftInventoryFurnace inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryFurnace((net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity) this.container);
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.view.CraftFurnaceView(this.player.player.getBukkitEntity(), inventory, this);
+ return this.bukkitEntity;
+ this.view = new org.bukkit.craftbukkit.inventory.view.CraftFurnaceView(this.inventory.player.getBukkitEntity(), inventory, this);
+ return this.view;
+ }
+ // CraftBukkit end
@@ -26,7 +26,7 @@
this.addSlot(new Slot(container, 0, 56, 17));
this.addSlot(new FurnaceFuelSlot(this, container, 1, 56, 53));
this.addSlot(new FurnaceResultSlot(inventory.player, container, 2, 116, 35));
+ this.player = inventory; // CraftBukkit - save player
+ this.inventory = inventory; // CraftBukkit
this.addStandardInventorySlots(inventory, 8, 84);
this.addDataSlots(data);
}

View File

@@ -46,7 +46,7 @@
if (blockState1 == null) {
level.removeBlock(blockPos, false);
level.levelEvent(1029, blockPos, 0);
@@ -128,8 +_,8 @@
@@ -127,8 +_,8 @@
if (itemStack.isDamageableItem() && item.isValidRepairItem(item1)) {
int min = Math.min(itemStack.getDamageValue(), itemStack.getMaxDamage() / 4);
if (min <= 0) {
@@ -57,7 +57,7 @@
return;
}
@@ -144,8 +_,8 @@
@@ -143,8 +_,8 @@
this.repairItemCountCost = i2;
} else {
if (!hasStoredEnchantments && (!itemStack.is(item1.getItem()) || !itemStack.isDamageableItem())) {
@@ -68,7 +68,7 @@
return;
}
@@ -191,7 +_,7 @@
@@ -190,7 +_,7 @@
flag1 = true;
} else {
flag = true;
@@ -77,7 +77,7 @@
intValue = enchantment.getMaxLevel();
}
@@ -209,8 +_,8 @@
@@ -208,8 +_,8 @@
}
if (flag1 && !flag) {
@@ -88,7 +88,7 @@
return;
}
}
@@ -235,14 +_,16 @@
@@ -234,14 +_,16 @@
}
if (i1 == i && i1 > 0) {
@@ -103,12 +103,12 @@
this.onlyRenaming = true;
}
- if (this.cost.get() >= 40 && !this.player.getAbilities().instabuild) {
+ if (this.cost.get() >= this.maximumRepairCost && !this.player.getAbilities().instabuild) { // CraftBukkit
- if (this.cost.get() >= 40 && !this.player.hasInfiniteMaterials()) {
+ if (this.cost.get() >= this.maximumRepairCost && !this.player.hasInfiniteMaterials()) { // CraftBukkit
itemStack = ItemStack.EMPTY;
}
@@ -260,12 +_,13 @@
@@ -259,12 +_,13 @@
EnchantmentHelper.setEnchantments(itemStack, mutable.toImmutable());
}
@@ -125,7 +125,7 @@
}
public static int calculateIncreasedRepairCost(int oldRepairCost) {
@@ -286,6 +_,7 @@
@@ -285,6 +_,7 @@
}
this.createResult();
@@ -133,7 +133,7 @@
return true;
} else {
return false;
@@ -301,4 +_,19 @@
@@ -300,4 +_,19 @@
public int getCost() {
return this.cost.get();
}

View File

@@ -21,17 +21,17 @@
private final ContainerLevelAccess access;
private final ContainerData beaconData;
+ // CraftBukkit start
+ private org.bukkit.craftbukkit.inventory.view.CraftBeaconView bukkitEntity = null;
+ private net.minecraft.world.entity.player.Inventory player;
+ private @Nullable org.bukkit.craftbukkit.inventory.view.CraftBeaconView view = null;
+ private final net.minecraft.world.entity.player.Inventory inventory;
+ // CraftBukkit end
public BeaconMenu(int containerId, Container container) {
this(containerId, container, new SimpleContainerData(3), ContainerLevelAccess.NULL);
@@ -43,6 +_,27 @@
@@ -43,6 +_,25 @@
public BeaconMenu(int containerId, Container container, ContainerData beaconData, ContainerLevelAccess access) {
super(MenuType.BEACON, containerId);
+ this.player = (net.minecraft.world.entity.player.Inventory) container; // CraftBukkit - TODO: check this
+ this.inventory = (net.minecraft.world.entity.player.Inventory) container; // CraftBukkit - TODO: check this
+ // Paper - Add missing InventoryHolders
+ this.beacon = new SimpleContainer(this.createBlockHolder(access), 1) {
+ @Override
@@ -44,12 +44,10 @@
+ return 1;
+ }
+
+ // Paper start - Fix inventories returning null Locations
+ @Override
+ public org.bukkit.Location getLocation() {
+ return access.getLocation();
+ }
+ // Paper end - Fix inventories returning null Locations
+ };
+ // Paper end
checkContainerDataCount(beaconData, 3);
@@ -83,7 +81,7 @@
- this.beaconData.set(1, encodeEffect(primaryEffect.orElse(null)));
- this.beaconData.set(2, encodeEffect(secondaryEffect.orElse(null)));
+ // Paper start - Add PlayerChangeBeaconEffectEvent
+ io.papermc.paper.event.player.PlayerChangeBeaconEffectEvent event = new io.papermc.paper.event.player.PlayerChangeBeaconEffectEvent((org.bukkit.entity.Player) this.player.player.getBukkitEntity(), convert(primaryEffect), convert(secondaryEffect), this.access.getLocation().getBlock());
+ io.papermc.paper.event.player.PlayerChangeBeaconEffectEvent event = new io.papermc.paper.event.player.PlayerChangeBeaconEffectEvent((org.bukkit.entity.Player) this.inventory.player.getBukkitEntity(), convert(primaryEffect), convert(secondaryEffect), this.access.getLocation().getBlock());
+ if (event.callEvent()) {
+ // Paper end - Add PlayerChangeBeaconEffectEvent
+ this.beaconData.set(1, BeaconMenu.encodeEffect(event.getPrimary() == null ? null : org.bukkit.craftbukkit.potion.CraftPotionEffectType.bukkitToMinecraftHolder(event.getPrimary())));// CraftBukkit - decompile error
@@ -104,13 +102,13 @@
+ // CraftBukkit start
+ @Override
+ public org.bukkit.craftbukkit.inventory.view.CraftBeaconView getBukkitView() {
+ if (this.bukkitEntity != null) {
+ return this.bukkitEntity;
+ if (this.view != null) {
+ return this.view;
+ }
+
+ org.bukkit.craftbukkit.inventory.CraftInventoryBeacon inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryBeacon(this.beacon);
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.view.CraftBeaconView(this.player.player.getBukkitEntity(), inventory, this);
+ return this.bukkitEntity;
+ this.view = new org.bukkit.craftbukkit.inventory.view.CraftBeaconView(this.inventory.player.getBukkitEntity(), inventory, this);
+ return this.view;
+ }
+ // CraftBukkit end
}

View File

@@ -5,8 +5,8 @@
public final ContainerData brewingStandData;
private final Slot ingredientSlot;
+ // CraftBukkit start
+ private org.bukkit.craftbukkit.inventory.view.CraftBrewingStandView bukkitEntity = null;
+ private Inventory player;
+ private @javax.annotation.Nullable org.bukkit.craftbukkit.inventory.view.CraftBrewingStandView view = null;
+ private final Inventory inventory;
+ // CraftBukkit end
public BrewingStandMenu(int containerId, Inventory playerInventory) {
@@ -16,7 +16,7 @@
public BrewingStandMenu(int containerId, Inventory playerInventory, Container brewingStandContainer, ContainerData brewingStandData) {
super(MenuType.BREWING_STAND, containerId);
+ this.player = playerInventory; // CraftBukkit
+ this.inventory = playerInventory; // CraftBukkit
checkContainerSize(brewingStandContainer, 5);
- checkContainerDataCount(brewingStandData, 2);
+ checkContainerDataCount(brewingStandData, 3); // Paper - Add recipeBrewTime
@@ -62,7 +62,7 @@
return ItemStack.EMPTY;
}
- } else if (BrewingStandMenu.PotionSlot.mayPlaceItem(itemStack)) {
+ } else if (BrewingStandMenu.PotionSlot.mayPlaceItem(itemStack, this.player.player.level().potionBrewing())) { // Paper - custom potion mixes
+ } else if (BrewingStandMenu.PotionSlot.mayPlaceItem(itemStack, this.inventory.player.level().potionBrewing())) { // Paper - custom potion mixes
if (!this.moveItemStackTo(item, 0, 3, false)) {
return ItemStack.EMPTY;
}
@@ -102,13 +102,13 @@
+ // CraftBukkit start
+ @Override
+ public org.bukkit.craftbukkit.inventory.view.CraftBrewingStandView getBukkitView() {
+ if (this.bukkitEntity != null) {
+ return this.bukkitEntity;
+ if (this.view != null) {
+ return this.view;
+ }
+
+ org.bukkit.craftbukkit.inventory.CraftInventoryBrewer inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryBrewer(this.brewingStand);
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.view.CraftBrewingStandView(this.player.player.getBukkitEntity(), inventory, this);
+ return this.bukkitEntity;
+ this.view = new org.bukkit.craftbukkit.inventory.view.CraftBrewingStandView(this.inventory.player.getBukkitEntity(), inventory, this);
+ return this.view;
+ }
+ // CraftBukkit end
}

View File

@@ -5,18 +5,18 @@
public class CartographyTableMenu extends AbstractContainerMenu {
+ // CraftBukkit start
+ private org.bukkit.craftbukkit.inventory.CraftInventoryView bukkitEntity = null;
+ private org.bukkit.entity.Player player;
+ private @javax.annotation.Nullable org.bukkit.craftbukkit.inventory.CraftInventoryView view = null;
+ private final org.bukkit.entity.Player player;
+
+ @Override
+ public org.bukkit.craftbukkit.inventory.CraftInventoryView getBukkitView() {
+ if (this.bukkitEntity != null) {
+ return this.bukkitEntity;
+ if (this.view != null) {
+ return this.view;
+ }
+
+ org.bukkit.craftbukkit.inventory.CraftInventoryCartography inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryCartography(this.container, this.resultContainer);
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.player, inventory, this);
+ return this.bukkitEntity;
+ this.view = new org.bukkit.craftbukkit.inventory.CraftInventoryView<>(this.player, inventory, this);
+ return this.view;
+ }
+ // CraftBukkit end
public static final int MAP_SLOT = 0;
@@ -50,7 +50,7 @@
public CartographyTableMenu(int containerId, Inventory playerInventory, final ContainerLevelAccess access) {
super(MenuType.CARTOGRAPHY_TABLE, containerId);
+ // Paper start - Add missing InventoryHolders - move down
+ this.container = new SimpleContainer(this.createBlockHolder(access), 2) { // Paper - Add missing InventoryHolders
+ this.container = new SimpleContainer(this.createBlockHolder(access), 2) {
+ @Override
+ public void setChanged() {
+ CartographyTableMenu.this.slotsChanged(this);
@@ -63,7 +63,7 @@
+ }
+ // CraftBukkit end
+ };
+ this.resultContainer = new ResultContainer(this.createBlockHolder(access)) { // Paper - Add missing InventoryHolders
+ this.resultContainer = new ResultContainer(this.createBlockHolder(access)) {
+ @Override
+ public void setChanged() {
+ // CartographyTableMenu.this.slotsChanged(this); // Paper - Add CartographyItemEvent - do not recompute results if the result slot changes - allows to set the result slot via api

View File

@@ -5,13 +5,13 @@
private final Container container;
private final int containerRows;
+ // CraftBukkit start
+ private org.bukkit.craftbukkit.inventory.CraftInventoryView bukkitEntity = null;
+ private Inventory player;
+ private @javax.annotation.Nullable org.bukkit.craftbukkit.inventory.CraftInventoryView view = null;
+ private final Inventory inventory;
+
+ @Override
+ public org.bukkit.craftbukkit.inventory.CraftInventoryView getBukkitView() {
+ if (this.bukkitEntity != null) {
+ return this.bukkitEntity;
+ if (this.view != null) {
+ return this.view;
+ }
+
+ org.bukkit.craftbukkit.inventory.CraftInventory inventory;
@@ -23,13 +23,13 @@
+ inventory = new org.bukkit.craftbukkit.inventory.CraftInventory(this.container);
+ }
+
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return this.bukkitEntity;
+ this.view = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.inventory.player.getBukkitEntity(), inventory, this);
+ return this.view;
+ }
+
+ @Override
+ public void startOpen() {
+ this.container.startOpen(this.player.player);
+ this.container.startOpen(this.inventory.player);
+ }
+ // CraftBukkit end
@@ -42,7 +42,7 @@
- container.startOpen(playerInventory.player);
+ // container.startOpen(playerInventory.player); // Paper - don't startOpen until menu actually opens
+ // CraftBukkit start - Save player
+ this.player = playerInventory;
+ this.inventory = playerInventory;
+ // CraftBukkit end
int i = 18;
this.addChestGrid(container, 8, 18);

View File

@@ -51,7 +51,7 @@
+ }
+
+ default org.bukkit.Location getLocation() {
+ return new org.bukkit.Location(this.getWorld().getWorld(), this.getPosition().getX(), this.getPosition().getY(), this.getPosition().getZ());
+ return org.bukkit.craftbukkit.util.CraftLocation.toBukkit(this.getPosition(), this.getWorld());
+ }
+ // CraftBukkit end
+ // Paper start - Add missing InventoryHolders

View File

@@ -1,9 +1,9 @@
--- a/net/minecraft/world/inventory/ContainerSynchronizer.java
+++ b/net/minecraft/world/inventory/ContainerSynchronizer.java
@@ -11,4 +_,12 @@
void sendCarriedChange(AbstractContainerMenu containerMenu, ItemStack stack);
@@ -13,4 +_,12 @@
void sendDataChange(AbstractContainerMenu container, int id, int value);
RemoteSlot createSlot();
+
+ default void sendOffHandSlotChange() {} // Paper - Sync offhand slot in menus
+

View File

@@ -5,17 +5,17 @@
private final Player player;
private final CraftingContainer container;
+ // CraftBukkit start
+ private org.bukkit.craftbukkit.inventory.view.CraftCrafterView bukkitEntity = null;
+ private @javax.annotation.Nullable org.bukkit.craftbukkit.inventory.view.CraftCrafterView view = null;
+
+ @Override
+ public org.bukkit.craftbukkit.inventory.view.CraftCrafterView getBukkitView() {
+ if (this.bukkitEntity != null) {
+ return this.bukkitEntity;
+ if (this.view != null) {
+ return this.view;
+ }
+
+ org.bukkit.craftbukkit.inventory.CraftInventoryCrafter inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryCrafter(this.container, this.resultContainer);
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.view.CraftCrafterView(this.player.getBukkitEntity(), inventory, this);
+ return this.bukkitEntity;
+ this.view = new org.bukkit.craftbukkit.inventory.view.CraftCrafterView(this.player.getBukkitEntity(), inventory, this);
+ return this.view;
+ }
+ // CraftBukkit end

View File

@@ -1,12 +1,10 @@
--- a/net/minecraft/world/inventory/CraftingMenu.java
+++ b/net/minecraft/world/inventory/CraftingMenu.java
@@ -30,13 +_,16 @@
@@ -30,13 +_,14 @@
public final ContainerLevelAccess access;
private final Player player;
private boolean placingRecipe;
+ // CraftBukkit start
+ private org.bukkit.craftbukkit.inventory.CraftInventoryView bukkitEntity = null;
+ // CraftBukkit end
+ private @Nullable org.bukkit.craftbukkit.inventory.CraftInventoryView view = null; // CraftBukkit
public CraftingMenu(int containerId, Inventory playerInventory) {
this(containerId, playerInventory, ContainerLevelAccess.NULL);
@@ -75,13 +73,13 @@
+ // CraftBukkit start
+ @Override
+ public org.bukkit.craftbukkit.inventory.CraftInventoryView getBukkitView() {
+ if (this.bukkitEntity != null) {
+ return this.bukkitEntity;
+ if (this.view != null) {
+ return this.view;
+ }
+
+ org.bukkit.craftbukkit.inventory.CraftInventoryCrafting inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryCrafting(this.craftSlots, this.resultSlots);
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.player.getBukkitEntity(), inventory, this);
+ return this.bukkitEntity;
+ this.view = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.player.getBukkitEntity(), inventory, this);
+ return this.view;
+ }
+ // CraftBukkit end
}

View File

@@ -5,8 +5,8 @@
private static final int USE_ROW_SLOT_END = 45;
public final Container dispenser;
+ // CraftBukkit start
+ private org.bukkit.craftbukkit.inventory.CraftInventoryView bukkitEntity = null;
+ private Inventory player;
+ private @javax.annotation.Nullable org.bukkit.craftbukkit.inventory.CraftInventoryView view = null;
+ private final Inventory inventory;
+ // CraftBukkit end
public DispenserMenu(int containerId, Inventory playerInventory) {
@@ -16,7 +16,7 @@
public DispenserMenu(int containerId, Inventory playerInventory, Container container) {
super(MenuType.GENERIC_3x3, containerId);
+ // CraftBukkit start - Save player
+ this.player = playerInventory;
+ this.inventory = playerInventory;
+ // CraftBukkit end
checkContainerSize(container, 9);
this.dispenser = container;
@@ -37,13 +37,13 @@
+ // CraftBukkit start
+ @Override
+ public org.bukkit.craftbukkit.inventory.CraftInventoryView getBukkitView() {
+ if (this.bukkitEntity != null) {
+ return this.bukkitEntity;
+ if (this.view != null) {
+ return this.view;
+ }
+
+ org.bukkit.craftbukkit.inventory.CraftInventory inventory = new org.bukkit.craftbukkit.inventory.CraftInventory(this.dispenser);
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return this.bukkitEntity;
+ this.view = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.inventory.player.getBukkitEntity(), inventory, this);
+ return this.view;
+ }
+ // CraftBukkit end
}

View File

@@ -19,7 +19,7 @@
public final int[] enchantClue = new int[]{-1, -1, -1};
public final int[] levelClue = new int[]{-1, -1, -1};
+ // CraftBukkit start
+ private org.bukkit.craftbukkit.inventory.view.CraftEnchantmentView bukkitEntity = null;
+ private @javax.annotation.Nullable org.bukkit.craftbukkit.inventory.view.CraftEnchantmentView view = null;
+ private final org.bukkit.entity.Player player;
+ // CraftBukkit end
@@ -107,7 +107,7 @@
this.broadcastChanges();
});
} else {
@@ -145,19 +_,53 @@
@@ -145,19 +_,52 @@
return false;
} else {
this.access.execute((level, blockPos) -> {
@@ -121,7 +121,7 @@
+ // player.onEnchantmentPerformed(item, i); // Moved down
+ java.util.Map<org.bukkit.enchantments.Enchantment, Integer> enchants = new java.util.HashMap<>();
+ for (EnchantmentInstance instance : enchantmentList) {
+ enchants.put(org.bukkit.craftbukkit.enchantments.CraftEnchantment.minecraftHolderToBukkit(instance.enchantment), instance.level);
+ enchants.put(org.bukkit.craftbukkit.enchantments.CraftEnchantment.minecraftHolderToBukkit(instance.enchantment()), instance.level());
+ }
+ org.bukkit.craftbukkit.inventory.CraftItemStack craftItemStack = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack);
+ Holder<Enchantment> holder = registry.byId(this.enchantClue[id]);
@@ -148,13 +148,12 @@
+
+ // CraftBukkit start
+ for (java.util.Map.Entry<org.bukkit.enchantments.Enchantment, Integer> entry : event.getEnchantsToAdd().entrySet()) {
+ Holder<Enchantment> nms = org.bukkit.craftbukkit.enchantments.CraftEnchantment.bukkitToMinecraftHolder(entry.getKey());
+ if (nms == null) {
+ Holder<Enchantment> enchant = org.bukkit.craftbukkit.enchantments.CraftEnchantment.bukkitToMinecraftHolder(entry.getKey());
+ if (enchant == null) {
+ continue;
+ }
+
+ EnchantmentInstance weightedrandomenchant = new EnchantmentInstance(nms, entry.getValue());
+ itemStack.enchant(weightedrandomenchant.enchantment, weightedrandomenchant.level);
+ itemStack.enchant(enchant, entry.getValue());
+ }
player.onEnchantmentPerformed(item, i);
- if (item.is(Items.BOOK)) {
@@ -163,7 +162,7 @@
- }
-
- for (EnchantmentInstance enchantmentInstance : enchantmentList) {
- itemStack.enchant(enchantmentInstance.enchantment, enchantmentInstance.level);
- itemStack.enchant(enchantmentInstance.enchantment(), enchantmentInstance.level());
- }
-
+ // CraftBukkit end
@@ -172,6 +171,19 @@
item1.consume(i, player);
if (item1.isEmpty()) {
this.enchantSlots.setItem(1, ItemStack.EMPTY);
@@ -202,6 +_,12 @@
return item.isEmpty() ? 0 : item.getCount();
}
+ // Paper start - add enchantment seed update API
+ public void setEnchantmentSeed(int seed) {
+ this.enchantmentSeed.set(seed);
+ }
+ // Paper end - add enchantment seed update API
+
public int getEnchantmentSeed() {
return this.enchantmentSeed.get();
}
@@ -214,6 +_,7 @@
@Override
@@ -180,7 +192,7 @@
return stillValid(this.access, player, Blocks.ENCHANTING_TABLE);
}
@@ -261,4 +_,23 @@
@@ -261,4 +_,17 @@
return itemStack;
}
@@ -188,19 +200,13 @@
+ // CraftBukkit start
+ @Override
+ public org.bukkit.craftbukkit.inventory.view.CraftEnchantmentView getBukkitView() {
+ if (this.bukkitEntity != null) {
+ return this.bukkitEntity;
+ if (this.view != null) {
+ return this.view;
+ }
+
+ org.bukkit.craftbukkit.inventory.CraftInventoryEnchanting inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryEnchanting(this.enchantSlots);
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.view.CraftEnchantmentView(this.player, inventory, this);
+ return this.bukkitEntity;
+ this.view = new org.bukkit.craftbukkit.inventory.view.CraftEnchantmentView(this.player, inventory, this);
+ return this.view;
+ }
+ // CraftBukkit end
+
+ // Paper start - add enchantment seed update API
+ public void setEnchantmentSeed(int seed) {
+ this.enchantmentSeed.set(seed);
+ }
+ // Paper end - add enchantment seed update API
}

View File

@@ -2,7 +2,7 @@
+++ b/net/minecraft/world/inventory/FurnaceResultSlot.java
@@ -45,7 +_,7 @@
protected void checkTakeAchievements(ItemStack stack) {
stack.onCraftedBy(this.player.level(), this.player, this.removeCount);
stack.onCraftedBy(this.player, this.removeCount);
if (this.player instanceof ServerPlayer serverPlayer && this.container instanceof AbstractFurnaceBlockEntity abstractFurnaceBlockEntity) {
- abstractFurnaceBlockEntity.awardUsedRecipesAndPopExperience(serverPlayer);
+ abstractFurnaceBlockEntity.awardUsedRecipesAndPopExperience(serverPlayer, stack, this.removeCount); // CraftBukkit

View File

@@ -5,18 +5,18 @@
public class GrindstoneMenu extends AbstractContainerMenu {
+ // CraftBukkit start
+ private org.bukkit.craftbukkit.inventory.CraftInventoryView bukkitEntity = null;
+ private org.bukkit.entity.Player player;
+ private @javax.annotation.Nullable org.bukkit.craftbukkit.inventory.CraftInventoryView view = null;
+ private final org.bukkit.entity.Player player;
+
+ @Override
+ public org.bukkit.craftbukkit.inventory.CraftInventoryView getBukkitView() {
+ if (this.bukkitEntity != null) {
+ return this.bukkitEntity;
+ if (this.view != null) {
+ return this.view;
+ }
+
+ org.bukkit.craftbukkit.inventory.CraftInventoryGrindstone inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryGrindstone(this.repairSlots, this.resultSlots);
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.player, inventory, this);
+ return this.bukkitEntity;
+ this.view = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.player, inventory, this);
+ return this.view;
+ }
+ // CraftBukkit end
public static final int MAX_NAME_LENGTH = 35;

View File

@@ -5,18 +5,18 @@
public static final int CONTAINER_SIZE = 5;
private final Container hopper;
+ // CraftBukkit start
+ private org.bukkit.craftbukkit.inventory.CraftInventoryView bukkitEntity = null;
+ private Inventory player;
+ private @javax.annotation.Nullable org.bukkit.craftbukkit.inventory.CraftInventoryView view = null;
+ private final Inventory inventory;
+
+ @Override
+ public org.bukkit.craftbukkit.inventory.CraftInventoryView getBukkitView() {
+ if (this.bukkitEntity != null) {
+ return this.bukkitEntity;
+ if (this.view != null) {
+ return this.view;
+ }
+
+ org.bukkit.craftbukkit.inventory.CraftInventory inventory = new org.bukkit.craftbukkit.inventory.CraftInventory(this.hopper);
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return this.bukkitEntity;
+ this.view = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.inventory.player.getBukkitEntity(), inventory, this);
+ return this.view;
+ }
+ // CraftBukkit end
@@ -26,7 +26,7 @@
public HopperMenu(int containerId, Inventory playerInventory, Container container) {
super(MenuType.HOPPER, containerId);
this.hopper = container;
+ this.player = playerInventory; // CraftBukkit - save player
+ this.inventory = playerInventory; // CraftBukkit
checkContainerSize(container, 5);
container.startOpen(playerInventory.player);

View File

@@ -1,26 +1,26 @@
--- a/net/minecraft/world/inventory/HorseInventoryMenu.java
+++ b/net/minecraft/world/inventory/HorseInventoryMenu.java
@@ -19,9 +_,23 @@
public final AbstractHorse horse;
public static final int SLOT_SADDLE = 0;
public static final int SLOT_BODY_ARMOR = 1;
private static final int SLOT_HORSE_INVENTORY_START = 2;
public static final int SLOT_HORSE_INVENTORY_START = 2;
+ // CraftBukkit start
+ org.bukkit.craftbukkit.inventory.CraftInventoryView bukkitEntity;
+ Inventory player;
+ private @javax.annotation.Nullable org.bukkit.craftbukkit.inventory.CraftInventoryView view;
+ private final Inventory inventory;
+
+ @Override
+ public org.bukkit.inventory.InventoryView getBukkitView() {
+ if (this.bukkitEntity != null) {
+ return this.bukkitEntity;
+ if (this.view != null) {
+ return this.view;
+ }
+
+ return this.bukkitEntity = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.player.player.getBukkitEntity(), this.horseContainer.getOwner().getInventory(), this);
+ return this.view = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.inventory.player.getBukkitEntity(), this.horseContainer.getOwner().getInventory(), this);
+ }
+ // CraftBukkit end
public HorseInventoryMenu(int containerId, Inventory inventory, Container horseContainer, final AbstractHorse horse, int columns) {
super(null, containerId);
+ this.player = inventory; // CraftBukkit - save player
+ this.inventory = inventory; // CraftBukkit
this.horseContainer = horseContainer;
this.armorContainer = horse.getBodyArmorAccess();
this.horse = horse;
horseContainer.startOpen(inventory.player);

View File

@@ -1,26 +1,16 @@
--- a/net/minecraft/world/inventory/InventoryMenu.java
+++ b/net/minecraft/world/inventory/InventoryMenu.java
@@ -2,6 +_,7 @@
import java.util.List;
import java.util.Map;
+import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.Container;
@@ -44,9 +_,15 @@
@@ -44,9 +_,13 @@
private static final EquipmentSlot[] SLOT_IDS = new EquipmentSlot[]{EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET};
public final boolean active;
private final Player owner;
+ // CraftBukkit start
+ private org.bukkit.craftbukkit.inventory.CraftInventoryView bukkitEntity = null;
+ // CraftBukkit end
+ private @javax.annotation.Nullable org.bukkit.craftbukkit.inventory.CraftInventoryView view = null; // CraftBukkit
public InventoryMenu(Inventory playerInventory, boolean active, final Player owner) {
- super(null, 0, 2, 2);
+ // CraftBukkit start
+ super((MenuType) null, 0, 2, 2, playerInventory); // CraftBukkit - save player
+ this.setTitle(Component.translatable("container.crafting")); // SPIGOT-4722: Allocate title for player inventory
+ super(null, 0, 2, 2, playerInventory); // CraftBukkit
+ this.setTitle(net.minecraft.network.chat.Component.translatable("container.crafting")); // SPIGOT-4722: Allocate title for player inventory
+ // CraftBukkit end
this.active = active;
this.owner = owner;
@@ -33,13 +23,13 @@
+ // CraftBukkit start
+ @Override
+ public org.bukkit.craftbukkit.inventory.CraftInventoryView getBukkitView() {
+ if (this.bukkitEntity != null) {
+ return this.bukkitEntity;
+ if (this.view != null) {
+ return this.view;
+ }
+
+ org.bukkit.craftbukkit.inventory.CraftInventoryCrafting inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryCrafting(this.craftSlots, this.resultSlots);
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.owner.getBukkitEntity(), inventory, this);
+ return this.bukkitEntity;
+ this.view = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.owner.getBukkitEntity(), inventory, this);
+ return this.view;
+ }
+ // CraftBukkit end
}

View File

@@ -11,18 +11,18 @@
-
- public LecternMenu(int containerId, Container lectern, ContainerData lecternData) {
+ // CraftBukkit start
+ private org.bukkit.craftbukkit.inventory.view.CraftLecternView bukkitEntity = null;
+ private org.bukkit.entity.Player player;
+ private @javax.annotation.Nullable org.bukkit.craftbukkit.inventory.view.CraftLecternView view = null;
+ private final org.bukkit.entity.Player player;
+
+ @Override
+ public org.bukkit.craftbukkit.inventory.view.CraftLecternView getBukkitView() {
+ if (this.bukkitEntity != null) {
+ return this.bukkitEntity;
+ if (this.view != null) {
+ return this.view;
+ }
+
+ org.bukkit.craftbukkit.inventory.CraftInventoryLectern inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryLectern(this.lectern);
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.view.CraftLecternView(this.player, inventory, this);
+ return this.bukkitEntity;
+ this.view = new org.bukkit.craftbukkit.inventory.view.CraftLecternView(this.player, inventory, this);
+ return this.view;
+ }
+ // CraftBukkit end
+
@@ -83,7 +83,7 @@
}
+ // CraftBukkit start - Event for taking the book
+ org.bukkit.event.player.PlayerTakeLecternBookEvent event = new org.bukkit.event.player.PlayerTakeLecternBookEvent(this.player, ((org.bukkit.craftbukkit.inventory.CraftInventoryLectern) this.getBukkitView().getTopInventory()).getHolder());
+ org.bukkit.event.player.PlayerTakeLecternBookEvent event = new org.bukkit.event.player.PlayerTakeLecternBookEvent(this.player, this.getBukkitView().getTopInventory().getHolder());
+ org.bukkit.Bukkit.getServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return false;

View File

@@ -22,18 +22,18 @@
+ private final Container inputContainer; // Paper - Add missing InventoryHolders - move down
+ private final Container outputContainer; // Paper - Add missing InventoryHolders - move down
+ // CraftBukkit start
+ private org.bukkit.craftbukkit.inventory.view.CraftLoomView bukkitEntity = null;
+ private org.bukkit.entity.Player player;
+ private @javax.annotation.Nullable org.bukkit.craftbukkit.inventory.view.CraftLoomView view = null;
+ private final org.bukkit.entity.Player player;
+
+ @Override
+ public org.bukkit.craftbukkit.inventory.view.CraftLoomView getBukkitView() {
+ if (this.bukkitEntity != null) {
+ return this.bukkitEntity;
+ if (this.view != null) {
+ return this.view;
+ }
+
+ org.bukkit.craftbukkit.inventory.CraftInventoryLoom inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryLoom(this.inputContainer, this.outputContainer);
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.view.CraftLoomView(this.player, inventory, this);
+ return this.bukkitEntity;
+ this.view = new org.bukkit.craftbukkit.inventory.view.CraftLoomView(this.player, inventory, this);
+ return this.view;
+ }
+ // CraftBukkit end
@@ -88,7 +88,7 @@
- this.setupResultSlot(this.selectablePatterns.get(id));
+ // Paper start - Add PlayerLoomPatternSelectEvent
+ int selectablePatternIndex = id;
+ io.papermc.paper.event.player.PlayerLoomPatternSelectEvent event = new io.papermc.paper.event.player.PlayerLoomPatternSelectEvent((org.bukkit.entity.Player) player.getBukkitEntity(), ((org.bukkit.craftbukkit.inventory.CraftInventoryLoom) getBukkitView().getTopInventory()), org.bukkit.craftbukkit.block.banner.CraftPatternType.minecraftHolderToBukkit(this.selectablePatterns.get(selectablePatternIndex)));
+ io.papermc.paper.event.player.PlayerLoomPatternSelectEvent event = new io.papermc.paper.event.player.PlayerLoomPatternSelectEvent((org.bukkit.entity.Player) player.getBukkitEntity(), this.getBukkitView().getTopInventory(), org.bukkit.craftbukkit.block.banner.CraftPatternType.minecraftHolderToBukkit(this.selectablePatterns.get(selectablePatternIndex)));
+ if (!event.callEvent()) {
+ player.containerMenu.sendAllDataToRemote();
+ return false;
@@ -115,7 +115,7 @@
return true;
} else {
return false;
@@ -180,7 +_,8 @@
@@ -181,7 +_,8 @@
this.resultSlot.set(ItemStack.EMPTY);
}
@@ -125,7 +125,7 @@
} else {
this.resultSlot.set(ItemStack.EMPTY);
this.selectablePatterns = List.of();
@@ -269,7 +_,14 @@
@@ -270,7 +_,14 @@
itemStack.update(
DataComponents.BANNER_PATTERNS,
BannerPatternLayers.EMPTY,

View File

@@ -30,16 +30,16 @@
+ return this.maxStack;
+ }
+
+ public void setMaxStackSize(int i) {
+ this.maxStack = i;
+ public void setMaxStackSize(int size) {
+ this.maxStack = size;
+ }
+
+ public org.bukkit.inventory.InventoryHolder getOwner() {
+ public @javax.annotation.Nullable org.bukkit.inventory.InventoryHolder getOwner() {
+ return (this.merchant instanceof net.minecraft.world.entity.npc.AbstractVillager abstractVillager) ? (org.bukkit.craftbukkit.entity.CraftAbstractVillager) abstractVillager.getBukkitEntity() : null;
+ }
+
+ @Override
+ public org.bukkit.Location getLocation() {
+ public @javax.annotation.Nullable org.bukkit.Location getLocation() {
+ return (this.merchant instanceof net.minecraft.world.entity.npc.AbstractVillager abstractVillager) ? abstractVillager.getBukkitEntity().getLocation() : null; // Paper - Fix inventories returning null Locations
+ }
+ // CraftBukkit end

View File

@@ -5,15 +5,15 @@
private boolean showProgressBar;
private boolean canRestock;
+ // CraftBukkit start
+ private org.bukkit.craftbukkit.inventory.view.CraftMerchantView bukkitEntity = null;
+ private Inventory player;
+ private @javax.annotation.Nullable org.bukkit.craftbukkit.inventory.view.CraftMerchantView view = null;
+ private final Inventory inventory;
+
+ @Override
+ public org.bukkit.craftbukkit.inventory.view.CraftMerchantView getBukkitView() {
+ if (this.bukkitEntity == null) {
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.view.CraftMerchantView(this.player.player.getBukkitEntity(), new org.bukkit.craftbukkit.inventory.CraftInventoryMerchant(this.trader, this.tradeContainer), this, this.trader);
+ if (this.view == null) {
+ this.view = new org.bukkit.craftbukkit.inventory.view.CraftMerchantView(this.inventory.player.getBukkitEntity(), new org.bukkit.craftbukkit.inventory.CraftInventoryMerchant(this.trader, this.tradeContainer), this, this.trader);
+ }
+ return this.bukkitEntity;
+ return this.view;
+ }
+ // CraftBukkit end
@@ -23,7 +23,7 @@
this.addSlot(new Slot(this.tradeContainer, 0, 136, 37));
this.addSlot(new Slot(this.tradeContainer, 1, 162, 37));
this.addSlot(new MerchantResultSlot(playerInventory.player, trader, this.tradeContainer, 2, 220, 37));
+ this.player = playerInventory; // CraftBukkit - save player
+ this.inventory = playerInventory; // CraftBukkit
this.addStandardInventorySlots(playerInventory, 108, 84);
}

View File

@@ -18,8 +18,8 @@
+ if (event != null) {
+ if (!event.callEvent()) {
+ stack.setCount(0);
+ event.getPlayer().updateInventory();
+ int level = merchant instanceof net.minecraft.world.entity.npc.Villager villager ? villager.getVillagerData().getLevel() : 1;
+ player.containerMenu.sendAllDataToRemote();
+ int level = merchant instanceof net.minecraft.world.entity.npc.Villager villager ? villager.getVillagerData().level() : 1;
+ serverPlayer.sendMerchantOffers(player.containerMenu.containerId, merchant.getOffers(), level, merchant.getVillagerXp(), merchant.showProgressBar(), merchant.canRestock());
+ return;
+ }

View File

@@ -14,7 +14,7 @@
+ }
+
+ @Override
+ public org.bukkit.Location getLocation() {
+ public @Nullable org.bukkit.Location getLocation() {
+ return this.activeChest != null ? org.bukkit.craftbukkit.util.CraftLocation.toBukkit(this.activeChest.getBlockPos(), this.activeChest.getLevel().getWorld()) : null;
+ }
+

View File

@@ -0,0 +1,27 @@
--- a/net/minecraft/world/inventory/RemoteSlot.java
+++ b/net/minecraft/world/inventory/RemoteSlot.java
@@ -29,12 +_,14 @@
public static class Synchronized implements RemoteSlot {
private final HashedPatchMap.HashGenerator hasher;
+ private final boolean simplifyMatching; // Paper - add flag to simplify remote matching logic
@Nullable
private ItemStack remoteStack = null;
@Nullable
private HashedStack remoteHash = null;
- public Synchronized(HashedPatchMap.HashGenerator hasher) {
+ public Synchronized(HashedPatchMap.HashGenerator hasher, final boolean simplifyMatching) { // Paper - add flag to simplify remote matching logic
+ this.simplifyMatching = simplifyMatching; // Paper - add flag to simplify remote matching logic
this.hasher = hasher;
}
@@ -54,7 +_,7 @@
public boolean matches(ItemStack stack) {
if (this.remoteStack != null) {
return ItemStack.matches(this.remoteStack, stack);
- } else if (this.remoteHash != null && this.remoteHash.matches(stack, this.hasher)) {
+ } else if (this.remoteHash != null && this.remoteHash.matches(stack, this.hasher, this.simplifyMatching)) { // Paper - add flag to simplify remote matching logic
this.remoteStack = stack.copy();
return true;
} else {

View File

@@ -1,17 +1,19 @@
--- a/net/minecraft/world/inventory/ResultContainer.java
+++ b/net/minecraft/world/inventory/ResultContainer.java
@@ -12,6 +_,53 @@
@@ -12,6 +_,55 @@
private final NonNullList<ItemStack> itemStacks = NonNullList.withSize(1, ItemStack.EMPTY);
@Nullable
private RecipeHolder<?> recipeUsed;
+ // CraftBukkit start
+ private int maxStack = MAX_STACK;
+
+ @Override
+ public java.util.List<ItemStack> getContents() {
+ return this.itemStacks;
+ }
+
+ public org.bukkit.inventory.InventoryHolder getOwner() {
+ @Override
+ public @Nullable org.bukkit.inventory.InventoryHolder getOwner() {
+ // Paper start - Add missing InventoryHolders
+ if (this.holder == null && this.holderCreator != null) {
+ this.holder = this.holderCreator.get();
@@ -37,7 +39,7 @@
+ }
+
+ @Override
+ public org.bukkit.Location getLocation() {
+ public @Nullable org.bukkit.Location getLocation() {
+ return null;
+ }
+ // CraftBukkit end

View File

@@ -5,22 +5,22 @@
private static final int CONTAINER_SIZE = 27;
private final Container container;
+ // CraftBukkit start
+ private org.bukkit.craftbukkit.inventory.CraftInventoryView bukkitEntity;
+ private Inventory player;
+ private @javax.annotation.Nullable org.bukkit.craftbukkit.inventory.CraftInventoryView view;
+ private final Inventory inventory;
+
+ @Override
+ public org.bukkit.craftbukkit.inventory.CraftInventoryView getBukkitView() {
+ if (this.bukkitEntity != null) {
+ return this.bukkitEntity;
+ if (this.view != null) {
+ return this.view;
+ }
+
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.player.player.getBukkitEntity(), new org.bukkit.craftbukkit.inventory.CraftInventory(this.container), this);
+ return this.bukkitEntity;
+ this.view = new org.bukkit.craftbukkit.inventory.CraftInventoryView(this.inventory.player.getBukkitEntity(), new org.bukkit.craftbukkit.inventory.CraftInventory(this.container), this);
+ return this.view;
+ }
+
+ @Override
+ public void startOpen() {
+ container.startOpen(player.player);
+ this.container.startOpen(this.inventory.player);
+ }
+ // CraftBukkit end
@@ -31,7 +31,7 @@
checkContainerSize(container, 27);
this.container = container;
- container.startOpen(playerInventory.player);
+ this.player = playerInventory; // CraftBukkit - save player
+ this.inventory = playerInventory; // CraftBukkit
+ // container.startOpen(playerInventory.player); // Paper - don't startOpen until menu actually opens
int i = 3;
int i1 = 9;

View File

@@ -22,20 +22,20 @@
+ public final Container container; // Paper - Add missing InventoryHolders - move down
+ final ResultContainer resultContainer; // Paper - Add missing InventoryHolders - move down
+ // CraftBukkit start
+ private org.bukkit.craftbukkit.inventory.view.CraftStonecutterView bukkitEntity = null;
+ private @javax.annotation.Nullable org.bukkit.craftbukkit.inventory.view.CraftStonecutterView view = null;
+ private final org.bukkit.entity.Player player;
+
+ @Override
+ public org.bukkit.craftbukkit.inventory.view.CraftStonecutterView getBukkitView() {
+ if (this.bukkitEntity != null) {
+ return this.bukkitEntity;
+ if (this.view != null) {
+ return this.view;
}
- };
- final ResultContainer resultContainer = new ResultContainer();
+
+ org.bukkit.craftbukkit.inventory.CraftInventoryStonecutter inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryStonecutter(this.container, this.resultContainer);
+ this.bukkitEntity = new org.bukkit.craftbukkit.inventory.view.CraftStonecutterView(this.player, inventory, this);
+ return this.bukkitEntity;
+ this.view = new org.bukkit.craftbukkit.inventory.view.CraftStonecutterView(this.player, inventory, this);
+ return this.view;
+ }
+ // CraftBukkit end

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/world/inventory/TransientCraftingContainer.java
+++ b/net/minecraft/world/inventory/TransientCraftingContainer.java
@@ -13,6 +_,68 @@
@@ -13,6 +_,70 @@
private final int height;
private final AbstractContainerMenu menu;
@@ -11,27 +11,28 @@
+ private Player owner;
+ private int maxStack = MAX_STACK;
+
+ @Override
+ public List<ItemStack> getContents() {
+ return this.items;
+ }
+
+ @Override
+ public void onOpen(org.bukkit.craftbukkit.entity.CraftHumanEntity player) {
+ this.transaction.add(player);
+ }
+
+ public org.bukkit.event.inventory.InventoryType getInvType() {
+ return this.items.size() == 4 ? org.bukkit.event.inventory.InventoryType.CRAFTING : org.bukkit.event.inventory.InventoryType.WORKBENCH;
+ }
+
+ @Override
+ public void onClose(org.bukkit.craftbukkit.entity.CraftHumanEntity player) {
+ this.transaction.remove(player);
+ }
+
+ @Override
+ public List<org.bukkit.entity.HumanEntity> getViewers() {
+ return this.transaction;
+ }
+
+ public org.bukkit.inventory.InventoryHolder getOwner() {
+ @Override
+ public @javax.annotation.Nullable org.bukkit.inventory.InventoryHolder getOwner() {
+ return (this.owner == null) ? null : this.owner.getBukkitEntity();
+ }
+
@@ -40,6 +41,7 @@
+ return this.maxStack;
+ }
+
+ @Override
+ public void setMaxStackSize(int size) {
+ this.maxStack = size;
+ this.resultInventory.setMaxStackSize(size);