diff --git a/nms-patches/net/minecraft/network/PacketDataSerializer.patch b/nms-patches/net/minecraft/network/PacketDataSerializer.patch deleted file mode 100644 index 459f0978..00000000 --- a/nms-patches/net/minecraft/network/PacketDataSerializer.patch +++ /dev/null @@ -1,71 +0,0 @@ ---- a/net/minecraft/network/PacketDataSerializer.java -+++ b/net/minecraft/network/PacketDataSerializer.java -@@ -139,7 +139,7 @@ - - public > C readCollection(IntFunction intfunction, StreamDecoder streamdecoder) { - int i = this.readVarInt(); -- C c0 = (Collection) intfunction.apply(i); -+ C c0 = intfunction.apply(i); // CraftBukkit - decompile error - - for (int j = 0; j < i; ++j) { - c0.add(streamdecoder.decode(this)); -@@ -150,7 +150,7 @@ - - public void writeCollection(Collection collection, StreamEncoder streamencoder) { - this.writeVarInt(collection.size()); -- Iterator iterator = collection.iterator(); -+ Iterator iterator = collection.iterator(); // CraftBukkit - decompile error - - while (iterator.hasNext()) { - T t0 = iterator.next(); -@@ -177,12 +177,12 @@ - - public void writeIntIdList(IntList intlist) { - this.writeVarInt(intlist.size()); -- intlist.forEach(this::writeVarInt); -+ intlist.forEach((java.util.function.IntConsumer) this::writeVarInt); // CraftBukkit - decompile error - } - - public > M readMap(IntFunction intfunction, StreamDecoder streamdecoder, StreamDecoder streamdecoder1) { - int i = this.readVarInt(); -- M m0 = (Map) intfunction.apply(i); -+ M m0 = intfunction.apply(i); // CraftBukkit - decompile error - - for (int j = 0; j < i; ++j) { - K k0 = streamdecoder.decode(this); -@@ -216,7 +216,7 @@ - } - - public > void writeEnumSet(EnumSet enumset, Class oclass) { -- E[] ae = (Enum[]) oclass.getEnumConstants(); -+ E[] ae = oclass.getEnumConstants(); // CraftBukkit - decompile error - BitSet bitset = new BitSet(ae.length); - - for (int i = 0; i < ae.length; ++i) { -@@ -227,7 +227,7 @@ - } - - public > EnumSet readEnumSet(Class oclass) { -- E[] ae = (Enum[]) oclass.getEnumConstants(); -+ E[] ae = oclass.getEnumConstants(); // CraftBukkit - decompile error - BitSet bitset = this.readFixedBitSet(ae.length); - EnumSet enumset = EnumSet.noneOf(oclass); - -@@ -498,7 +498,7 @@ - } - - public > T readEnum(Class oclass) { -- return ((Enum[]) oclass.getEnumConstants())[this.readVarInt()]; -+ return ((T[]) oclass.getEnumConstants())[this.readVarInt()]; // CraftBukkit - fix decompile error - } - - public PacketDataSerializer writeEnum(Enum oenum) { -@@ -565,7 +565,7 @@ - - try { - NBTCompressedStreamTools.writeAnyTag((NBTBase) nbtbase, new ByteBufOutputStream(bytebuf)); -- } catch (IOException ioexception) { -+ } catch (Exception ioexception) { // CraftBukkit - IOException -> Exception - throw new EncoderException(ioexception); - } - } diff --git a/nms-patches/net/minecraft/network/chat/ChatHexColor.patch b/nms-patches/net/minecraft/network/chat/ChatHexColor.patch deleted file mode 100644 index 8924ab3f..00000000 --- a/nms-patches/net/minecraft/network/chat/ChatHexColor.patch +++ /dev/null @@ -1,35 +0,0 @@ ---- a/net/minecraft/network/chat/ChatHexColor.java -+++ b/net/minecraft/network/chat/ChatHexColor.java -@@ -17,7 +17,7 @@ - private static final String CUSTOM_COLOR_PREFIX = "#"; - public static final Codec CODEC = Codec.STRING.comapFlatMap(ChatHexColor::parseColor, ChatHexColor::serialize); - private static final Map LEGACY_FORMAT_TO_COLOR = (Map) Stream.of(EnumChatFormat.values()).filter(EnumChatFormat::isColor).collect(ImmutableMap.toImmutableMap(Function.identity(), (enumchatformat) -> { -- return new ChatHexColor(enumchatformat.getColor(), enumchatformat.getName()); -+ return new ChatHexColor(enumchatformat.getColor(), enumchatformat.getName(), enumchatformat); // CraftBukkit - })); - private static final Map NAMED_COLORS = (Map) ChatHexColor.LEGACY_FORMAT_TO_COLOR.values().stream().collect(ImmutableMap.toImmutableMap((chathexcolor) -> { - return chathexcolor.name; -@@ -25,16 +25,22 @@ - private final int value; - @Nullable - public final String name; -+ // CraftBukkit start -+ @Nullable -+ public final EnumChatFormat format; - -- private ChatHexColor(int i, String s) { -+ private ChatHexColor(int i, String s, EnumChatFormat format) { - this.value = i & 16777215; - this.name = s; -+ this.format = format; - } - - private ChatHexColor(int i) { - this.value = i & 16777215; - this.name = null; -+ this.format = null; - } -+ // CraftBukkit end - - public int getValue() { - return this.value; diff --git a/nms-patches/net/minecraft/network/chat/IChatBaseComponent.patch b/nms-patches/net/minecraft/network/chat/IChatBaseComponent.patch deleted file mode 100644 index 783abb4d..00000000 --- a/nms-patches/net/minecraft/network/chat/IChatBaseComponent.patch +++ /dev/null @@ -1,26 +0,0 @@ ---- a/net/minecraft/network/chat/IChatBaseComponent.java -+++ b/net/minecraft/network/chat/IChatBaseComponent.java -@@ -38,7 +38,22 @@ - import net.minecraft.util.FormattedString; - import net.minecraft.world.level.ChunkCoordIntPair; - --public interface IChatBaseComponent extends Message, IChatFormatted { -+// CraftBukkit start -+import java.util.stream.Stream; -+// CraftBukkit end -+ -+public interface IChatBaseComponent extends Message, IChatFormatted, Iterable { // CraftBukkit -+ -+ // CraftBukkit start -+ default Stream stream() { -+ return com.google.common.collect.Streams.concat(new Stream[]{Stream.of(this), this.getSiblings().stream().flatMap(IChatBaseComponent::stream)}); -+ } -+ -+ @Override -+ default Iterator iterator() { -+ return this.stream().iterator(); -+ } -+ // CraftBukkit end - - ChatModifier getStyle(); - diff --git a/nms-patches/net/minecraft/world/IInventory.patch b/nms-patches/net/minecraft/world/IInventory.patch deleted file mode 100644 index 90d9dcf5..00000000 --- a/nms-patches/net/minecraft/world/IInventory.patch +++ /dev/null @@ -1,48 +0,0 @@ ---- a/net/minecraft/world/IInventory.java -+++ b/net/minecraft/world/IInventory.java -@@ -9,6 +9,11 @@ - import net.minecraft.world.level.World; - import net.minecraft.world.level.block.entity.TileEntity; - -+// CraftBukkit start -+import net.minecraft.world.item.crafting.RecipeHolder; -+import org.bukkit.craftbukkit.entity.CraftHumanEntity; -+// CraftBukkit end -+ - public interface IInventory extends Clearable { - - float DEFAULT_DISTANCE_BUFFER = 4.0F; -@@ -25,9 +30,7 @@ - - void setItem(int i, ItemStack itemstack); - -- default int getMaxStackSize() { -- return 99; -- } -+ int getMaxStackSize(); // CraftBukkit - - default int getMaxStackSize(ItemStack itemstack) { - return Math.min(this.getMaxStackSize(), itemstack.getMaxStackSize()); -@@ -91,4 +94,22 @@ - - return world == null ? false : (world.getBlockEntity(blockposition) != tileentity ? false : entityhuman.canInteractWithBlock(blockposition, (double) f)); - } -+ -+ // CraftBukkit start -+ java.util.List getContents(); -+ -+ void onOpen(CraftHumanEntity who); -+ -+ void onClose(CraftHumanEntity who); -+ -+ java.util.List getViewers(); -+ -+ org.bukkit.inventory.InventoryHolder getOwner(); -+ -+ void setMaxStackSize(int size); -+ -+ org.bukkit.Location getLocation(); -+ -+ int MAX_STACK = 99; -+ // CraftBukkit end - } diff --git a/nms-patches/net/minecraft/world/inventory/ContainerAccess.patch b/nms-patches/net/minecraft/world/inventory/ContainerAccess.patch deleted file mode 100644 index 72e419a3..00000000 --- a/nms-patches/net/minecraft/world/inventory/ContainerAccess.patch +++ /dev/null @@ -1,42 +0,0 @@ ---- a/net/minecraft/world/inventory/ContainerAccess.java -+++ b/net/minecraft/world/inventory/ContainerAccess.java -@@ -8,6 +8,20 @@ - - public interface ContainerAccess { - -+ // CraftBukkit start -+ default World getWorld() { -+ throw new UnsupportedOperationException("Not supported yet."); -+ } -+ -+ default BlockPosition getPosition() { -+ throw new UnsupportedOperationException("Not supported yet."); -+ } -+ -+ default org.bukkit.Location getLocation() { -+ return new org.bukkit.Location(getWorld().getWorld(), getPosition().getX(), getPosition().getY(), getPosition().getZ()); -+ } -+ // CraftBukkit end -+ - ContainerAccess NULL = new ContainerAccess() { - @Override - public Optional evaluate(BiFunction bifunction) { -@@ -17,6 +31,18 @@ - - static ContainerAccess create(final World world, final BlockPosition blockposition) { - return new ContainerAccess() { -+ // CraftBukkit start -+ @Override -+ public World getWorld() { -+ return world; -+ } -+ -+ @Override -+ public BlockPosition getPosition() { -+ return blockposition; -+ } -+ // CraftBukkit end -+ - @Override - public Optional evaluate(BiFunction bifunction) { - return Optional.of(bifunction.apply(world, blockposition)); diff --git a/nms-patches/net/minecraft/world/inventory/ContainerLectern.patch b/nms-patches/net/minecraft/world/inventory/ContainerLectern.patch deleted file mode 100644 index 5c2cf6b8..00000000 --- a/nms-patches/net/minecraft/world/inventory/ContainerLectern.patch +++ /dev/null @@ -1,84 +0,0 @@ ---- a/net/minecraft/world/inventory/ContainerLectern.java -+++ b/net/minecraft/world/inventory/ContainerLectern.java -@@ -5,8 +5,33 @@ - import net.minecraft.world.entity.player.EntityHuman; - import net.minecraft.world.item.ItemStack; - -+// CraftBukkit start -+import net.minecraft.world.level.block.entity.TileEntityLectern.LecternInventory; -+import net.minecraft.world.entity.player.PlayerInventory; -+import org.bukkit.Bukkit; -+import org.bukkit.craftbukkit.inventory.CraftInventoryLectern; -+import org.bukkit.craftbukkit.inventory.view.CraftLecternView; -+import org.bukkit.entity.Player; -+import org.bukkit.event.player.PlayerTakeLecternBookEvent; -+// CraftBukkit end -+ - public class ContainerLectern extends Container { - -+ // CraftBukkit start -+ private CraftLecternView bukkitEntity = null; -+ private Player player; -+ -+ @Override -+ public CraftLecternView getBukkitView() { -+ if (bukkitEntity != null) { -+ return bukkitEntity; -+ } -+ -+ CraftInventoryLectern inventory = new CraftInventoryLectern(this.lectern); -+ bukkitEntity = new CraftLecternView(this.player, inventory, this); -+ return bukkitEntity; -+ } -+ // CraftBukkit end - private static final int DATA_COUNT = 1; - private static final int SLOT_COUNT = 1; - public static final int BUTTON_PREV_PAGE = 1; -@@ -16,11 +41,13 @@ - private final IInventory lectern; - private final IContainerProperties lecternData; - -- public ContainerLectern(int i) { -- this(i, new InventorySubcontainer(1), new ContainerProperties(1)); -+ // CraftBukkit start - add player -+ public ContainerLectern(int i, PlayerInventory playerinventory) { -+ this(i, new InventorySubcontainer(1), new ContainerProperties(1), playerinventory); - } - -- public ContainerLectern(int i, IInventory iinventory, IContainerProperties icontainerproperties) { -+ public ContainerLectern(int i, IInventory iinventory, IContainerProperties icontainerproperties, PlayerInventory playerinventory) { -+ // CraftBukkit end - super(Containers.LECTERN, i); - checkContainerSize(iinventory, 1); - checkContainerDataCount(icontainerproperties, 1); -@@ -34,6 +61,7 @@ - } - }); - this.addDataSlots(icontainerproperties); -+ player = (Player) playerinventory.player.getBukkitEntity(); // CraftBukkit - } - - @Override -@@ -59,6 +87,13 @@ - return false; - } - -+ // CraftBukkit start - Event for taking the book -+ PlayerTakeLecternBookEvent event = new PlayerTakeLecternBookEvent(player, ((CraftInventoryLectern) getBukkitView().getTopInventory()).getHolder()); -+ Bukkit.getServer().getPluginManager().callEvent(event); -+ if (event.isCancelled()) { -+ return false; -+ } -+ // CraftBukkit end - ItemStack itemstack = this.lectern.removeItemNoUpdate(0); - - this.lectern.setChanged(); -@@ -86,6 +121,8 @@ - - @Override - public boolean stillValid(EntityHuman entityhuman) { -+ if (lectern instanceof LecternInventory && !((LecternInventory) lectern).getLectern().hasBook()) return false; // CraftBukkit -+ if (!this.checkReachable) return true; // CraftBukkit - return this.lectern.stillValid(entityhuman); - } - diff --git a/nms-patches/net/minecraft/world/inventory/ContainerPlayer.patch b/nms-patches/net/minecraft/world/inventory/ContainerPlayer.patch deleted file mode 100644 index 35cd2ec5..00000000 --- a/nms-patches/net/minecraft/world/inventory/ContainerPlayer.patch +++ /dev/null @@ -1,59 +0,0 @@ ---- a/net/minecraft/world/inventory/ContainerPlayer.java -+++ b/net/minecraft/world/inventory/ContainerPlayer.java -@@ -12,6 +12,12 @@ - import net.minecraft.world.item.crafting.RecipeHolder; - import net.minecraft.world.level.World; - -+// CraftBukkit start -+import net.minecraft.network.chat.IChatBaseComponent; -+import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting; -+import org.bukkit.craftbukkit.inventory.CraftInventoryView; -+// CraftBukkit end -+ - public class ContainerPlayer extends AbstractCraftingMenu { - - public static final int CONTAINER_ID = 0; -@@ -38,9 +44,15 @@ - private static final EnumItemSlot[] SLOT_IDS = new EnumItemSlot[]{EnumItemSlot.HEAD, EnumItemSlot.CHEST, EnumItemSlot.LEGS, EnumItemSlot.FEET}; - public final boolean active; - private final EntityHuman owner; -+ // CraftBukkit start -+ private CraftInventoryView bukkitEntity = null; -+ // CraftBukkit end - - public ContainerPlayer(PlayerInventory playerinventory, boolean flag, final EntityHuman entityhuman) { -- super((Containers) null, 0, 2, 2); -+ // CraftBukkit start -+ super((Containers) null, 0, 2, 2, playerinventory); // CraftBukkit - save player -+ setTitle(IChatBaseComponent.translatable("container.crafting")); // SPIGOT-4722: Allocate title for player inventory -+ // CraftBukkit end - this.active = flag; - this.owner = entityhuman; - this.addResultSlot(entityhuman, 154, 28); -@@ -54,7 +66,7 @@ - } - - this.addStandardInventorySlots(playerinventory, 8, 84); -- this.addSlot(new Slot(this, playerinventory, 40, 77, 62) { -+ this.addSlot(new Slot(playerinventory, 40, 77, 62) { // CraftBukkit - decompile error - @Override - public void setByPlayer(ItemStack itemstack, ItemStack itemstack1) { - entityhuman.onEquipItem(EnumItemSlot.OFFHAND, itemstack1, itemstack); -@@ -190,4 +202,17 @@ - protected EntityHuman owner() { - return this.owner; - } -+ -+ // CraftBukkit start -+ @Override -+ public CraftInventoryView getBukkitView() { -+ if (bukkitEntity != null) { -+ return bukkitEntity; -+ } -+ -+ CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftSlots, this.resultSlots); -+ bukkitEntity = new CraftInventoryView(this.owner.getBukkitEntity(), inventory, this); -+ return bukkitEntity; -+ } -+ // CraftBukkit end - } diff --git a/nms-patches/net/minecraft/world/inventory/ContainerShulkerBox.patch b/nms-patches/net/minecraft/world/inventory/ContainerShulkerBox.patch deleted file mode 100644 index 5109b7b8..00000000 --- a/nms-patches/net/minecraft/world/inventory/ContainerShulkerBox.patch +++ /dev/null @@ -1,48 +0,0 @@ ---- a/net/minecraft/world/inventory/ContainerShulkerBox.java -+++ b/net/minecraft/world/inventory/ContainerShulkerBox.java -@@ -6,10 +6,29 @@ - import net.minecraft.world.entity.player.PlayerInventory; - import net.minecraft.world.item.ItemStack; - -+// CraftBukkit start -+import org.bukkit.craftbukkit.inventory.CraftInventory; -+import org.bukkit.craftbukkit.inventory.CraftInventoryView; -+// CraftBukkit end -+ - public class ContainerShulkerBox extends Container { - - private static final int CONTAINER_SIZE = 27; - private final IInventory container; -+ // CraftBukkit start -+ private CraftInventoryView bukkitEntity; -+ private PlayerInventory player; -+ -+ @Override -+ public CraftInventoryView getBukkitView() { -+ if (bukkitEntity != null) { -+ return bukkitEntity; -+ } -+ -+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), new CraftInventory(this.container), this); -+ return bukkitEntity; -+ } -+ // CraftBukkit end - - public ContainerShulkerBox(int i, PlayerInventory playerinventory) { - this(i, playerinventory, new InventorySubcontainer(27)); -@@ -19,6 +38,7 @@ - super(Containers.SHULKER_BOX, i); - checkContainerSize(iinventory, 27); - this.container = iinventory; -+ this.player = playerinventory; // CraftBukkit - save player - iinventory.startOpen(playerinventory.player); - boolean flag = true; - boolean flag1 = true; -@@ -34,6 +54,7 @@ - - @Override - public boolean stillValid(EntityHuman entityhuman) { -+ if (!this.checkReachable) return true; // CraftBukkit - return this.container.stillValid(entityhuman); - } - diff --git a/nms-patches/net/minecraft/world/inventory/ContainerSmithing.patch b/nms-patches/net/minecraft/world/inventory/ContainerSmithing.patch deleted file mode 100644 index 39be79fc..00000000 --- a/nms-patches/net/minecraft/world/inventory/ContainerSmithing.patch +++ /dev/null @@ -1,60 +0,0 @@ ---- a/net/minecraft/world/inventory/ContainerSmithing.java -+++ b/net/minecraft/world/inventory/ContainerSmithing.java -@@ -18,6 +18,8 @@ - import net.minecraft.world.level.block.Blocks; - import net.minecraft.world.level.block.state.IBlockData; - -+import org.bukkit.craftbukkit.inventory.CraftInventoryView; // CraftBukkit -+ - public class ContainerSmithing extends ContainerAnvilAbstract { - - public static final int TEMPLATE_SLOT = 0; -@@ -34,6 +36,9 @@ - private final RecipePropertySet templateItemTest; - private final RecipePropertySet additionItemTest; - private final ContainerProperty hasRecipeError; -+ // CraftBukkit start -+ private CraftInventoryView bukkitEntity; -+ // CraftBukkit end - - public ContainerSmithing(int i, PlayerInventory playerinventory) { - this(i, playerinventory, ContainerAccess.NULL); -@@ -117,7 +122,7 @@ - public void createResult() { - SmithingRecipeInput smithingrecipeinput = this.createRecipeInput(); - World world = this.level; -- Optional optional; -+ Optional> optional; // CraftBukkit - decompile error - - if (world instanceof WorldServer worldserver) { - optional = worldserver.recipeAccess().getRecipeFor(Recipes.SMITHING, smithingrecipeinput, worldserver); -@@ -129,7 +134,9 @@ - ItemStack itemstack = ((SmithingRecipe) recipeholder.value()).assemble(smithingrecipeinput, this.level.registryAccess()); - - this.resultSlots.setRecipeUsed(recipeholder); -- this.resultSlots.setItem(0, itemstack); -+ // CraftBukkit start -+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareSmithingEvent(getBukkitView(), itemstack); -+ // CraftBukkit end - }, () -> { - this.resultSlots.setRecipeUsed((RecipeHolder) null); - this.resultSlots.setItem(0, ItemStack.EMPTY); -@@ -149,4 +156,18 @@ - public boolean hasRecipeError() { - return this.hasRecipeError.get() > 0; - } -+ -+ // CraftBukkit start -+ @Override -+ public CraftInventoryView getBukkitView() { -+ if (bukkitEntity != null) { -+ return bukkitEntity; -+ } -+ -+ org.bukkit.craftbukkit.inventory.CraftInventory inventory = new org.bukkit.craftbukkit.inventory.CraftInventorySmithing( -+ access.getLocation(), this.inputSlots, this.resultSlots); -+ bukkitEntity = new CraftInventoryView(this.player.getBukkitEntity(), inventory, this); -+ return bukkitEntity; -+ } -+ // CraftBukkit end - } diff --git a/nms-patches/net/minecraft/world/inventory/ContainerStonecutter.patch b/nms-patches/net/minecraft/world/inventory/ContainerStonecutter.patch deleted file mode 100644 index 88d26948..00000000 --- a/nms-patches/net/minecraft/world/inventory/ContainerStonecutter.patch +++ /dev/null @@ -1,77 +0,0 @@ ---- a/net/minecraft/world/inventory/ContainerStonecutter.java -+++ b/net/minecraft/world/inventory/ContainerStonecutter.java -@@ -17,6 +17,13 @@ - import net.minecraft.world.level.World; - import net.minecraft.world.level.block.Blocks; - -+// CraftBukkit start -+import org.bukkit.Location; -+import org.bukkit.craftbukkit.inventory.CraftInventoryStonecutter; -+import org.bukkit.craftbukkit.inventory.view.CraftStonecutterView; -+import org.bukkit.entity.Player; -+// CraftBukkit end -+ - public class ContainerStonecutter extends Container { - - public static final int INPUT_SLOT = 0; -@@ -36,6 +43,21 @@ - Runnable slotUpdateListener; - public final IInventory container; - final InventoryCraftResult resultContainer; -+ // CraftBukkit start -+ private CraftStonecutterView bukkitEntity = null; -+ private Player player; -+ -+ @Override -+ public CraftStonecutterView getBukkitView() { -+ if (bukkitEntity != null) { -+ return bukkitEntity; -+ } -+ -+ CraftInventoryStonecutter inventory = new CraftInventoryStonecutter(this.container, this.resultContainer); -+ bukkitEntity = new CraftStonecutterView(this.player, inventory, this); -+ return bukkitEntity; -+ } -+ // CraftBukkit end - - public ContainerStonecutter(int i, PlayerInventory playerinventory) { - this(i, playerinventory, ContainerAccess.NULL); -@@ -55,6 +77,13 @@ - ContainerStonecutter.this.slotsChanged(this); - ContainerStonecutter.this.slotUpdateListener.run(); - } -+ -+ // CraftBukkit start -+ @Override -+ public Location getLocation() { -+ return containeraccess.getLocation(); -+ } -+ // CraftBukkit end - }; - this.resultContainer = new InventoryCraftResult(); - this.access = containeraccess; -@@ -94,6 +123,7 @@ - }); - this.addStandardInventorySlots(playerinventory, 8, 84); - this.addDataSlot(this.selectedRecipeIndex); -+ player = (Player) playerinventory.player.getBukkitEntity(); // CraftBukkit - } - - public int getSelectedRecipeIndex() { -@@ -114,6 +144,7 @@ - - @Override - public boolean stillValid(EntityHuman entityhuman) { -+ if (!this.checkReachable) return true; // CraftBukkit - return stillValid(this.access, entityhuman, Blocks.STONECUTTER); - } - -@@ -158,7 +189,7 @@ - } - - void setupResultSlot(int i) { -- Optional optional; -+ Optional> optional; // CraftBukkit - decompile error - - if (!this.recipesForInput.isEmpty() && this.isValidRecipeIndex(i)) { - SelectableRecipe.a selectablerecipe_a = (SelectableRecipe.a) this.recipesForInput.entries().get(i); diff --git a/nms-patches/net/minecraft/world/inventory/ContainerWorkbench.patch b/nms-patches/net/minecraft/world/inventory/ContainerWorkbench.patch deleted file mode 100644 index 4e456f85..00000000 --- a/nms-patches/net/minecraft/world/inventory/ContainerWorkbench.patch +++ /dev/null @@ -1,75 +0,0 @@ ---- a/net/minecraft/world/inventory/ContainerWorkbench.java -+++ b/net/minecraft/world/inventory/ContainerWorkbench.java -@@ -16,6 +16,12 @@ - import net.minecraft.world.item.crafting.Recipes; - import net.minecraft.world.level.block.Blocks; - -+// CraftBukkit start -+import net.minecraft.world.item.crafting.RecipeRepair; -+import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting; -+import org.bukkit.craftbukkit.inventory.CraftInventoryView; -+// CraftBukkit end -+ - public class ContainerWorkbench extends AbstractCraftingMenu { - - private static final int CRAFTING_GRID_WIDTH = 3; -@@ -31,13 +37,16 @@ - public final ContainerAccess access; - private final EntityHuman player; - private boolean placingRecipe; -+ // CraftBukkit start -+ private CraftInventoryView bukkitEntity = null; -+ // CraftBukkit end - - public ContainerWorkbench(int i, PlayerInventory playerinventory) { - this(i, playerinventory, ContainerAccess.NULL); - } - - public ContainerWorkbench(int i, PlayerInventory playerinventory, ContainerAccess containeraccess) { -- super(Containers.CRAFTING, i, 3, 3); -+ super(Containers.CRAFTING, i, 3, 3, playerinventory); // CraftBukkit - pass player - this.access = containeraccess; - this.player = playerinventory.player; - this.addResultSlot(this.player, 124, 35); -@@ -50,6 +59,7 @@ - EntityPlayer entityplayer = (EntityPlayer) entityhuman; - ItemStack itemstack = ItemStack.EMPTY; - Optional> optional = worldserver.getServer().getRecipeManager().getRecipeFor(Recipes.CRAFTING, craftinginput, worldserver, recipeholder); -+ inventorycrafting.setCurrentRecipe(optional.orElse(null)); // CraftBukkit - - if (optional.isPresent()) { - RecipeHolder recipeholder1 = (RecipeHolder) optional.get(); -@@ -63,6 +73,7 @@ - } - } - } -+ itemstack = org.bukkit.craftbukkit.event.CraftEventFactory.callPreCraftEvent(inventorycrafting, inventorycraftresult, itemstack, container.getBukkitView(), optional.map(RecipeHolder::value).orElse(null) instanceof RecipeRepair); // CraftBukkit - - inventorycraftresult.setItem(0, itemstack); - container.setRemoteSlot(0, itemstack); -@@ -103,6 +114,7 @@ - - @Override - public boolean stillValid(EntityHuman entityhuman) { -+ if (!this.checkReachable) return true; // CraftBukkit - return stillValid(this.access, entityhuman, Blocks.CRAFTING_TABLE); - } - -@@ -181,4 +193,17 @@ - protected EntityHuman owner() { - return this.player; - } -+ -+ // CraftBukkit start -+ @Override -+ public CraftInventoryView getBukkitView() { -+ if (bukkitEntity != null) { -+ return bukkitEntity; -+ } -+ -+ CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftSlots, this.resultSlots); -+ bukkitEntity = new CraftInventoryView(this.player.getBukkitEntity(), inventory, this); -+ return bukkitEntity; -+ } -+ // CraftBukkit end - } diff --git a/nms-patches/net/minecraft/world/inventory/Containers.patch b/nms-patches/net/minecraft/world/inventory/Containers.patch deleted file mode 100644 index 0febcbd2..00000000 --- a/nms-patches/net/minecraft/world/inventory/Containers.patch +++ /dev/null @@ -1,22 +0,0 @@ ---- a/net/minecraft/world/inventory/Containers.java -+++ b/net/minecraft/world/inventory/Containers.java -@@ -8,6 +8,10 @@ - import net.minecraft.world.flag.FeatureFlagSet; - import net.minecraft.world.flag.FeatureFlags; - -+// CraftBukkit start -+import net.minecraft.world.entity.player.PlayerInventory; -+// CraftBukkit end -+ - public class Containers implements FeatureElement { - - public static final Containers GENERIC_9x1 = register("generic_9x1", ContainerChest::oneRow); -@@ -28,7 +32,7 @@ - public static final Containers GRINDSTONE = register("grindstone", ContainerGrindstone::new); - public static final Containers HOPPER = register("hopper", ContainerHopper::new); - public static final Containers LECTERN = register("lectern", (i, playerinventory) -> { -- return new ContainerLectern(i); -+ return new ContainerLectern(i, playerinventory); // CraftBukkit - }); - public static final Containers LOOM = register("loom", ContainerLoom::new); - public static final Containers MERCHANT = register("merchant", ContainerMerchant::new); diff --git a/nms-patches/net/minecraft/world/inventory/InventoryEnderChest.patch b/nms-patches/net/minecraft/world/inventory/InventoryEnderChest.patch deleted file mode 100644 index ba63be9d..00000000 --- a/nms-patches/net/minecraft/world/inventory/InventoryEnderChest.patch +++ /dev/null @@ -1,36 +0,0 @@ ---- a/net/minecraft/world/inventory/InventoryEnderChest.java -+++ b/net/minecraft/world/inventory/InventoryEnderChest.java -@@ -9,13 +9,32 @@ - import net.minecraft.world.item.ItemStack; - import net.minecraft.world.level.block.entity.TileEntityEnderChest; - -+// CraftBukkit start -+import org.bukkit.Location; -+import org.bukkit.craftbukkit.util.CraftLocation; -+import org.bukkit.inventory.InventoryHolder; -+// CraftBukkit end -+ - public class InventoryEnderChest extends InventorySubcontainer { - - @Nullable - private TileEntityEnderChest activeChest; -+ // CraftBukkit start -+ private final EntityHuman owner; - -- public InventoryEnderChest() { -+ public InventoryHolder getBukkitOwner() { -+ return owner.getBukkitEntity(); -+ } -+ -+ @Override -+ public Location getLocation() { -+ return this.activeChest != null ? CraftLocation.toBukkit(this.activeChest.getBlockPos(), this.activeChest.getLevel().getWorld()) : null; -+ } -+ -+ public InventoryEnderChest(EntityHuman owner) { - super(27); -+ this.owner = owner; -+ // CraftBukkit end - } - - public void setActiveChest(TileEntityEnderChest tileentityenderchest) { diff --git a/nms-patches/net/minecraft/world/inventory/InventoryMerchant.patch b/nms-patches/net/minecraft/world/inventory/InventoryMerchant.patch deleted file mode 100644 index a2dec896..00000000 --- a/nms-patches/net/minecraft/world/inventory/InventoryMerchant.patch +++ /dev/null @@ -1,66 +0,0 @@ ---- a/net/minecraft/world/inventory/InventoryMerchant.java -+++ b/net/minecraft/world/inventory/InventoryMerchant.java -@@ -11,6 +11,16 @@ - import net.minecraft.world.item.trading.MerchantRecipe; - import net.minecraft.world.item.trading.MerchantRecipeList; - -+// CraftBukkit start -+import java.util.List; -+import net.minecraft.world.entity.npc.EntityVillager; -+import net.minecraft.world.entity.npc.EntityVillagerAbstract; -+import org.bukkit.Location; -+import org.bukkit.craftbukkit.entity.CraftHumanEntity; -+import org.bukkit.craftbukkit.entity.CraftAbstractVillager; -+import org.bukkit.entity.HumanEntity; -+// CraftBukkit end -+ - public class InventoryMerchant implements IInventory { - - private final IMerchant merchant; -@@ -20,6 +30,46 @@ - public int selectionHint; - private int futureXp; - -+ // CraftBukkit start - add fields and methods -+ public List transaction = new java.util.ArrayList(); -+ private int maxStack = MAX_STACK; -+ -+ public List getContents() { -+ return this.itemStacks; -+ } -+ -+ public void onOpen(CraftHumanEntity who) { -+ transaction.add(who); -+ } -+ -+ public void onClose(CraftHumanEntity who) { -+ transaction.remove(who); -+ merchant.setTradingPlayer((EntityHuman) null); // SPIGOT-4860 -+ } -+ -+ public List getViewers() { -+ return transaction; -+ } -+ -+ @Override -+ public int getMaxStackSize() { -+ return maxStack; -+ } -+ -+ public void setMaxStackSize(int i) { -+ maxStack = i; -+ } -+ -+ public org.bukkit.inventory.InventoryHolder getOwner() { -+ return (merchant instanceof EntityVillagerAbstract) ? (CraftAbstractVillager) ((EntityVillagerAbstract) this.merchant).getBukkitEntity() : null; -+ } -+ -+ @Override -+ public Location getLocation() { -+ return (merchant instanceof EntityVillager) ? ((EntityVillager) this.merchant).getBukkitEntity().getLocation() : null; -+ } -+ // CraftBukkit end -+ - public InventoryMerchant(IMerchant imerchant) { - this.itemStacks = NonNullList.withSize(3, ItemStack.EMPTY); - this.merchant = imerchant; diff --git a/nms-patches/net/minecraft/world/inventory/SlotFurnaceResult.patch b/nms-patches/net/minecraft/world/inventory/SlotFurnaceResult.patch deleted file mode 100644 index f8a6dc26..00000000 --- a/nms-patches/net/minecraft/world/inventory/SlotFurnaceResult.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/net/minecraft/world/inventory/SlotFurnaceResult.java -+++ b/net/minecraft/world/inventory/SlotFurnaceResult.java -@@ -51,7 +51,7 @@ - IInventory iinventory = this.container; - - if (iinventory instanceof TileEntityFurnace tileentityfurnace) { -- tileentityfurnace.awardUsedRecipesAndPopExperience(entityplayer); -+ tileentityfurnace.awardUsedRecipesAndPopExperience(entityplayer, itemstack, this.removeCount); // CraftBukkit - } - } - diff --git a/patches/net/minecraft/network/Connection.java.patch b/patches/net/minecraft/network/Connection.java.patch index 9415aaa7..5e0587d2 100644 --- a/patches/net/minecraft/network/Connection.java.patch +++ b/patches/net/minecraft/network/Connection.java.patch @@ -70,6 +70,15 @@ } } +@@ -441,7 +_,7 @@ + } + + if (this.isConnected()) { +- this.channel.close().awaitUninterruptibly(); ++ this.channel.close(); // We can't wait as this may be called from an event loop. + this.disconnectionDetails = p_350867_; + } + } @@ -470,6 +_,7 @@ } diff --git a/patches/net/minecraft/network/chat/Component.java.patch b/patches/net/minecraft/network/chat/Component.java.patch new file mode 100644 index 00000000..ca8a5e3f --- /dev/null +++ b/patches/net/minecraft/network/chat/Component.java.patch @@ -0,0 +1,35 @@ +--- a/net/minecraft/network/chat/Component.java ++++ b/net/minecraft/network/chat/Component.java +@@ -20,9 +_,11 @@ + import java.util.ArrayList; + import java.util.Collections; + import java.util.Date; ++import java.util.Iterator; + import java.util.List; + import java.util.Optional; + import java.util.UUID; ++import java.util.stream.Stream; + import javax.annotation.Nullable; + import net.minecraft.commands.arguments.selector.SelectorPattern; + import net.minecraft.core.HolderLookup; +@@ -37,7 +_,19 @@ + import net.minecraft.util.FormattedCharSequence; + import net.minecraft.world.level.ChunkPos; + +-public interface Component extends Message, FormattedText { ++public interface Component extends Message, FormattedText, Iterable { ++ ++ // CraftBukkit start ++ default Stream stream() { ++ return com.google.common.collect.Streams.concat(new Stream[]{Stream.of(this), this.getSiblings().stream().flatMap(Component::stream)}); ++ } ++ ++ @Override ++ default Iterator iterator() { ++ return this.stream().iterator(); ++ } ++ // CraftBukkit end ++ + Style getStyle(); + + ComponentContents getContents(); diff --git a/patches/net/minecraft/network/chat/TextColor.java.patch b/patches/net/minecraft/network/chat/TextColor.java.patch new file mode 100644 index 00000000..d9a3d4b7 --- /dev/null +++ b/patches/net/minecraft/network/chat/TextColor.java.patch @@ -0,0 +1,37 @@ +--- a/net/minecraft/network/chat/TextColor.java ++++ b/net/minecraft/network/chat/TextColor.java +@@ -17,22 +_,33 @@ + public static final Codec CODEC = Codec.STRING.comapFlatMap(TextColor::parseColor, TextColor::serialize); + private static final Map LEGACY_FORMAT_TO_COLOR = Stream.of(ChatFormatting.values()) + .filter(ChatFormatting::isColor) +- .collect(ImmutableMap.toImmutableMap(Function.identity(), p_237301_ -> new TextColor(p_237301_.getColor(), p_237301_.getName()))); ++ .collect(ImmutableMap.toImmutableMap(Function.identity(), p_237301_ -> new TextColor(p_237301_.getColor(), p_237301_.getName(), p_237301_))); + private static final Map NAMED_COLORS = LEGACY_FORMAT_TO_COLOR.values() + .stream() + .collect(ImmutableMap.toImmutableMap(p_237297_ -> p_237297_.name, Function.identity())); + private final int value; + @Nullable + public final String name; ++ // CraftBukkit start ++ @Nullable ++ public final ChatFormatting format; ++ ++ private TextColor(int p_131263_, String p_131264_, ChatFormatting format) { ++ this.value = p_131263_ & 16777215; ++ this.name = p_131264_; ++ this.format = format; ++ } + + private TextColor(int p_131263_, String p_131264_) { + this.value = p_131263_ & 16777215; + this.name = p_131264_; ++ this.format = null; + } + + private TextColor(int p_131261_) { + this.value = p_131261_ & 16777215; + this.name = null; ++ this.format = null; + } + + public int getValue() { diff --git a/nms-patches/net/minecraft/util/TickThrottler.patch b/patches/net/minecraft/util/TickThrottler.java.patch similarity index 75% rename from nms-patches/net/minecraft/util/TickThrottler.patch rename to patches/net/minecraft/util/TickThrottler.java.patch index 38e6ddbc..ecd6afc6 100644 --- a/nms-patches/net/minecraft/util/TickThrottler.patch +++ b/patches/net/minecraft/util/TickThrottler.java.patch @@ -1,39 +1,31 @@ --- a/net/minecraft/util/TickThrottler.java +++ b/net/minecraft/util/TickThrottler.java -@@ -1,10 +1,14 @@ +@@ -1,9 +_,11 @@ package net.minecraft.util; -+// CraftBukkit start +import java.util.concurrent.atomic.AtomicInteger; -+// CraftBukkit end + public class TickThrottler { - private final int incrementStep; private final int threshold; - private int count; + private final AtomicInteger count = new AtomicInteger(); // CraftBukkit - multithreaded field - public TickThrottler(int i, int j) { - this.incrementStep = i; -@@ -12,17 +16,32 @@ + public TickThrottler(int p_374110_, int p_374074_) { + this.incrementStep = p_374110_; +@@ -11,16 +_,24 @@ } public void increment() { -- this.count += this.incrementStep; +- this.count = this.count + this.incrementStep; + this.count.addAndGet(this.incrementStep); // CraftBukkit - use thread-safe field access instead } public void tick() { -+ // CraftBukkit start +- if (this.count > 0) { +- this.count--; +- } + for (int val; (val = this.count.get()) > 0 && !count.compareAndSet(val, val - 1); ) ; -+ /* Use thread-safe field access instead - if (this.count > 0) { - --this.count; - } -+ */ -+ // CraftBukkit end - } public boolean isUnderThreshold() { diff --git a/nms-patches/net/minecraft/world/InventoryLargeChest.patch b/patches/net/minecraft/world/CompoundContainer.java.patch similarity index 65% rename from nms-patches/net/minecraft/world/InventoryLargeChest.patch rename to patches/net/minecraft/world/CompoundContainer.java.patch index 871fff1b..6a0b3991 100644 --- a/nms-patches/net/minecraft/world/InventoryLargeChest.patch +++ b/patches/net/minecraft/world/CompoundContainer.java.patch @@ -1,23 +1,20 @@ ---- a/net/minecraft/world/InventoryLargeChest.java -+++ b/net/minecraft/world/InventoryLargeChest.java -@@ -3,11 +3,62 @@ - import net.minecraft.world.entity.player.EntityHuman; - import net.minecraft.world.item.ItemStack; +--- a/net/minecraft/world/CompoundContainer.java ++++ b/net/minecraft/world/CompoundContainer.java +@@ -1,11 +_,58 @@ + package net.minecraft.world; -+// CraftBukkit start +import java.util.ArrayList; +import java.util.List; + import net.minecraft.world.entity.player.Player; + import net.minecraft.world.item.ItemStack; +import org.bukkit.Location; -+ +import org.bukkit.craftbukkit.entity.CraftHumanEntity; +import org.bukkit.entity.HumanEntity; -+// CraftBukkit end -+ - public class InventoryLargeChest implements IInventory { - - public final IInventory container1; - public final IInventory container2; + public class CompoundContainer implements Container { + public final Container container1; + public final Container container2; ++ + // CraftBukkit start - add fields and methods + public List transaction = new java.util.ArrayList(); + @@ -59,16 +56,6 @@ + return container1.getLocation(); // TODO: right? + } + // CraftBukkit end -+ - public InventoryLargeChest(IInventory iinventory, IInventory iinventory1) { - this.container1 = iinventory; - this.container2 = iinventory1; -@@ -54,7 +105,7 @@ - - @Override - public int getMaxStackSize() { -- return this.container1.getMaxStackSize(); -+ return Math.min(this.container1.getMaxStackSize(), this.container2.getMaxStackSize()); // CraftBukkit - check both sides - } - @Override + public CompoundContainer(Container p_18913_, Container p_18914_) { + this.container1 = p_18913_; diff --git a/patches/net/minecraft/world/Container.java.patch b/patches/net/minecraft/world/Container.java.patch new file mode 100644 index 00000000..fd87fd25 --- /dev/null +++ b/patches/net/minecraft/world/Container.java.patch @@ -0,0 +1,33 @@ +--- a/net/minecraft/world/Container.java ++++ b/net/minecraft/world/Container.java +@@ -8,6 +_,7 @@ + import net.minecraft.world.item.ItemStack; + import net.minecraft.world.level.Level; + import net.minecraft.world.level.block.entity.BlockEntity; ++import org.bukkit.craftbukkit.entity.CraftHumanEntity; + + public interface Container extends Clearable { + float DEFAULT_DISTANCE_BUFFER = 4.0F; +@@ -91,4 +_,22 @@ + return level.getBlockEntity(blockpos) != p_272877_ ? false : p_272670_.canInteractWithBlock(blockpos, (double)p_320837_); + } + } ++ ++ // CraftBukkit start ++ java.util.List getContents(); ++ ++ void onOpen(CraftHumanEntity who); ++ ++ void onClose(CraftHumanEntity who); ++ ++ java.util.List getViewers(); ++ ++ org.bukkit.inventory.InventoryHolder getOwner(); ++ ++ void setMaxStackSize(int size); ++ ++ org.bukkit.Location getLocation(); ++ ++ int MAX_STACK = 99; ++ // CraftBukkit end + } diff --git a/nms-patches/net/minecraft/world/InventorySubcontainer.patch b/patches/net/minecraft/world/SimpleContainer.java.patch similarity index 65% rename from nms-patches/net/minecraft/world/InventorySubcontainer.patch rename to patches/net/minecraft/world/SimpleContainer.java.patch index c77b2aa7..869bc05e 100644 --- a/nms-patches/net/minecraft/world/InventorySubcontainer.patch +++ b/patches/net/minecraft/world/SimpleContainer.java.patch @@ -1,21 +1,18 @@ ---- a/net/minecraft/world/InventorySubcontainer.java -+++ b/net/minecraft/world/InventorySubcontainer.java -@@ -14,6 +14,12 @@ +--- a/net/minecraft/world/SimpleContainer.java ++++ b/net/minecraft/world/SimpleContainer.java +@@ -12,6 +_,9 @@ + import net.minecraft.world.inventory.StackedContentsCompatible; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; - -+// CraftBukkit start +import org.bukkit.Location; +import org.bukkit.craftbukkit.entity.CraftHumanEntity; +import org.bukkit.entity.HumanEntity; -+// CraftBukkit end -+ - public class InventorySubcontainer implements IInventory, AutoRecipeOutput { + public class SimpleContainer implements Container, StackedContentsCompatible { private final int size; -@@ -21,7 +27,59 @@ +@@ -19,7 +_,61 @@ @Nullable - private List listeners; + private List listeners; + // CraftBukkit start - add fields and methods + public List transaction = new java.util.ArrayList(); @@ -56,20 +53,22 @@ + return null; + } + -+ public InventorySubcontainer(InventorySubcontainer original) { ++ public SimpleContainer(SimpleContainer original) { + this(original.size); + for (int slot = 0; slot < original.size; slot++) { + this.items.set(slot, original.items.get(slot).copy()); + } + } + - public InventorySubcontainer(int i) { -+ this(i, null); + public SimpleContainer(int p_19150_) { ++ this.bukkitOwner = null; ++ this.size = p_19150_; ++ this.items = NonNullList.withSize(p_19150_, ItemStack.EMPTY); + } + -+ public InventorySubcontainer(int i, org.bukkit.inventory.InventoryHolder owner) { ++ public SimpleContainer(int p_19150_, org.bukkit.inventory.InventoryHolder owner) { + this.bukkitOwner = owner; + // CraftBukkit end - this.size = i; - this.items = NonNullList.withSize(i, ItemStack.EMPTY); + this.size = p_19150_; + this.items = NonNullList.withSize(p_19150_, ItemStack.EMPTY); } diff --git a/patches/net/minecraft/world/entity/player/Player.java.patch b/patches/net/minecraft/world/entity/player/Player.java.patch index 52a2dd2d..450ecc73 100644 --- a/patches/net/minecraft/world/entity/player/Player.java.patch +++ b/patches/net/minecraft/world/entity/player/Player.java.patch @@ -1,7 +1,10 @@ --- a/net/minecraft/world/entity/player/Player.java +++ b/net/minecraft/world/entity/player/Player.java -@@ -117,7 +_,8 @@ +@@ -115,9 +_,11 @@ + import net.minecraft.world.scores.PlayerTeam; + import net.minecraft.world.scores.Scoreboard; import net.minecraft.world.scores.Team; ++import org.bukkit.craftbukkit.entity.CraftHumanEntity; import org.slf4j.Logger; -public abstract class Player extends LivingEntity { @@ -10,7 +13,7 @@ private static final Logger LOGGER = LogUtils.getLogger(); public static final HumanoidArm DEFAULT_MAIN_HAND = HumanoidArm.RIGHT; public static final int DEFAULT_MODEL_CUSTOMIZATION = 0; -@@ -200,6 +_,10 @@ +@@ -200,6 +_,20 @@ public Entity currentExplosionCause; private boolean ignoreFallDamageFromCurrentImpulse; private int currentImpulseContextResetGraceTime; @@ -18,6 +21,16 @@ + private final java.util.Collection suffixes = new java.util.LinkedList<>(); + @Nullable private Pose forcedPose; + private long lastDayTimeTick = -1L; // Neo: Used to limit TIME_SINCE_REST increases when day length is non-standard. No need to persist, at most Phantoms will spawn one tick too early for each save/load cycle. ++ ++ // CraftBukkit start ++ public boolean fauxSleeping; ++ public int oldLevel = -1; ++ ++ @Override ++ public CraftHumanEntity getBukkitEntity() { ++ return (CraftHumanEntity) super.getBukkitEntity(); ++ } ++ // CraftBukkit end public Player(Level p_250508_, BlockPos p_250289_, float p_251702_, GameProfile p_252153_) { super(EntityType.PLAYER, p_250508_); diff --git a/patches/net/minecraft/world/inventory/AbstractContainerMenu.java.patch b/patches/net/minecraft/world/inventory/AbstractContainerMenu.java.patch index d23a1d76..325cc347 100644 --- a/patches/net/minecraft/world/inventory/AbstractContainerMenu.java.patch +++ b/patches/net/minecraft/world/inventory/AbstractContainerMenu.java.patch @@ -1,5 +1,57 @@ --- a/net/minecraft/world/inventory/AbstractContainerMenu.java +++ b/net/minecraft/world/inventory/AbstractContainerMenu.java +@@ -1,5 +_,6 @@ + package net.minecraft.world.inventory; + ++import com.google.common.base.Preconditions; + import com.google.common.base.Suppliers; + import com.google.common.collect.HashBasedTable; + import com.google.common.collect.Lists; +@@ -20,6 +_,7 @@ + import net.minecraft.core.BlockPos; + import net.minecraft.core.NonNullList; + import net.minecraft.core.registries.BuiltInRegistries; ++import net.minecraft.network.chat.Component; + import net.minecraft.server.level.ServerPlayer; + import net.minecraft.util.Mth; + import net.minecraft.world.Container; +@@ -33,6 +_,8 @@ + import net.minecraft.world.level.Level; + import net.minecraft.world.level.block.Block; + import net.minecraft.world.level.block.entity.BlockEntity; ++import org.bukkit.craftbukkit.inventory.CraftInventory; ++import org.bukkit.inventory.InventoryView; + import org.slf4j.Logger; + + public abstract class AbstractContainerMenu { +@@ -66,6 +_,27 @@ + private ContainerSynchronizer synchronizer; + private boolean suppressRemoteUpdates; + ++ // CraftBukkit start ++ public boolean checkReachable = true; ++ public abstract InventoryView getBukkitView(); ++ public void transferTo(AbstractContainerMenu other, org.bukkit.craftbukkit.entity.CraftHumanEntity player) { ++ InventoryView source = this.getBukkitView(), destination = other.getBukkitView(); ++ ((CraftInventory) source.getTopInventory()).getInventory().onClose(player); ++ ((CraftInventory) source.getBottomInventory()).getInventory().onClose(player); ++ ((CraftInventory) destination.getTopInventory()).getInventory().onOpen(player); ++ ((CraftInventory) destination.getBottomInventory()).getInventory().onOpen(player); ++ } ++ private Component title; ++ public final Component getTitle() { ++ Preconditions.checkState(this.title != null, "Title not set"); ++ return this.title; ++ } ++ public final void setTitle(Component title) { ++ Preconditions.checkState(this.title == null, "Title already set"); ++ this.title = title; ++ } ++ // CraftBukkit end ++ + protected AbstractContainerMenu(@Nullable MenuType p_38851_, int p_38852_) { + this.menuType = p_38851_; + this.containerId = p_38852_; @@ -559,6 +_,11 @@ } diff --git a/patches/net/minecraft/world/inventory/ContainerLevelAccess.java.patch b/patches/net/minecraft/world/inventory/ContainerLevelAccess.java.patch new file mode 100644 index 00000000..21490391 --- /dev/null +++ b/patches/net/minecraft/world/inventory/ContainerLevelAccess.java.patch @@ -0,0 +1,44 @@ +--- a/net/minecraft/world/inventory/ContainerLevelAccess.java ++++ b/net/minecraft/world/inventory/ContainerLevelAccess.java +@@ -7,6 +_,21 @@ + import net.minecraft.world.level.Level; + + public interface ContainerLevelAccess { ++ ++ // CraftBukkit start ++ default Level getWorld() { ++ throw new UnsupportedOperationException("Not supported yet."); ++ } ++ ++ default BlockPos getPosition() { ++ throw new UnsupportedOperationException("Not supported yet."); ++ } ++ ++ default org.bukkit.Location getLocation() { ++ return new org.bukkit.Location(getWorld().getWorld(), getPosition().getX(), getPosition().getY(), getPosition().getZ()); ++ } ++ // CraftBukkit end ++ + ContainerLevelAccess NULL = new ContainerLevelAccess() { + @Override + public Optional evaluate(BiFunction p_39304_) { +@@ -16,6 +_,19 @@ + + static ContainerLevelAccess create(final Level p_39290_, final BlockPos p_39291_) { + return new ContainerLevelAccess() { ++ ++ // CraftBukkit start ++ @Override ++ public Level getWorld() { ++ return p_39290_; ++ } ++ ++ @Override ++ public BlockPos getPosition() { ++ return p_39291_; ++ } ++ // CraftBukkit end ++ + @Override + public Optional evaluate(BiFunction p_39311_) { + return Optional.of(p_39311_.apply(p_39290_, p_39291_)); diff --git a/nms-patches/net/minecraft/world/inventory/CrafterMenu.patch b/patches/net/minecraft/world/inventory/CrafterMenu.java.patch similarity index 74% rename from nms-patches/net/minecraft/world/inventory/CrafterMenu.patch rename to patches/net/minecraft/world/inventory/CrafterMenu.java.patch index 0f552aba..4cd0bbf2 100644 --- a/nms-patches/net/minecraft/world/inventory/CrafterMenu.patch +++ b/patches/net/minecraft/world/inventory/CrafterMenu.java.patch @@ -1,16 +1,13 @@ --- a/net/minecraft/world/inventory/CrafterMenu.java +++ b/net/minecraft/world/inventory/CrafterMenu.java -@@ -10,8 +10,27 @@ - import net.minecraft.world.item.crafting.RecipeCrafting; +@@ -9,8 +_,24 @@ + import net.minecraft.world.item.crafting.CraftingInput; + import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.level.block.CrafterBlock; - -+// CraftBukkit start +import org.bukkit.craftbukkit.inventory.CraftInventoryCrafter; +import org.bukkit.craftbukkit.inventory.view.CraftCrafterView; -+// CraftBukkit end -+ - public class CrafterMenu extends Container implements ICrafting { + public class CrafterMenu extends AbstractContainerMenu implements ContainerListener { + // CraftBukkit start + private CraftCrafterView bukkitEntity = null; + @@ -28,11 +25,11 @@ protected static final int SLOT_COUNT = 9; private static final int INV_SLOT_START = 9; private static final int INV_SLOT_END = 36; -@@ -106,6 +125,7 @@ +@@ -101,6 +_,7 @@ @Override - public boolean stillValid(EntityHuman entityhuman) { + public boolean stillValid(Player p_307229_) { + if (!this.checkReachable) return true; // CraftBukkit - return this.container.stillValid(entityhuman); + return this.container.stillValid(p_307229_); } diff --git a/nms-patches/net/minecraft/world/inventory/InventoryCrafting.patch b/patches/net/minecraft/world/inventory/CraftingContainer.java.patch similarity index 63% rename from nms-patches/net/minecraft/world/inventory/InventoryCrafting.patch rename to patches/net/minecraft/world/inventory/CraftingContainer.java.patch index 32f823c9..d2d05484 100644 --- a/nms-patches/net/minecraft/world/inventory/InventoryCrafting.patch +++ b/patches/net/minecraft/world/inventory/CraftingContainer.java.patch @@ -1,20 +1,18 @@ ---- a/net/minecraft/world/inventory/InventoryCrafting.java -+++ b/net/minecraft/world/inventory/InventoryCrafting.java -@@ -5,6 +5,10 @@ +--- a/net/minecraft/world/inventory/CraftingContainer.java ++++ b/net/minecraft/world/inventory/CraftingContainer.java +@@ -4,6 +_,7 @@ + import net.minecraft.world.Container; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.CraftingInput; - -+// CraftBukkit start +import net.minecraft.world.item.crafting.RecipeHolder; -+// CraftBukkit end -+ - public interface InventoryCrafting extends IInventory, AutoRecipeOutput { + public interface CraftingContainer extends Container, StackedContentsCompatible { int getWidth(); -@@ -13,6 +17,15 @@ +@@ -11,6 +_,15 @@ + int getHeight(); List getItems(); - ++ + // CraftBukkit start + default RecipeHolder getCurrentRecipe() { + return null; @@ -23,7 +21,6 @@ + default void setCurrentRecipe(RecipeHolder recipe) { + } + // CraftBukkit end -+ + default CraftingInput asCraftInput() { return this.asPositionedCraftInput().input(); - } diff --git a/patches/net/minecraft/world/inventory/CraftingMenu.java.patch b/patches/net/minecraft/world/inventory/CraftingMenu.java.patch new file mode 100644 index 00000000..0d79830c --- /dev/null +++ b/patches/net/minecraft/world/inventory/CraftingMenu.java.patch @@ -0,0 +1,67 @@ +--- a/net/minecraft/world/inventory/CraftingMenu.java ++++ b/net/minecraft/world/inventory/CraftingMenu.java +@@ -15,8 +_,11 @@ + import net.minecraft.world.item.crafting.CraftingRecipe; + import net.minecraft.world.item.crafting.RecipeHolder; + import net.minecraft.world.item.crafting.RecipeType; ++import net.minecraft.world.item.crafting.RepairItemRecipe; + import net.minecraft.world.level.Level; + import net.minecraft.world.level.block.Blocks; ++import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting; ++import org.bukkit.craftbukkit.inventory.CraftInventoryView; + + public class CraftingMenu extends AbstractCraftingMenu { + private static final int CRAFTING_GRID_WIDTH = 3; +@@ -32,6 +_,9 @@ + public final ContainerLevelAccess access; + private final Player player; + private boolean placingRecipe; ++ // CraftBukkit start ++ private CraftInventoryView bukkitEntity = null; ++ // CraftBukkit end + + public CraftingMenu(int p_39353_, Inventory p_39354_) { + this(p_39353_, p_39354_, ContainerLevelAccess.NULL); +@@ -60,6 +_,7 @@ + Optional> optional = p_379963_.getServer() + .getRecipeManager() + .getRecipeFor(RecipeType.CRAFTING, craftinginput, p_379963_, p_345124_); ++ p_150550_.setCurrentRecipe(optional.orElse(null)); // CraftBukkit + if (optional.isPresent()) { + RecipeHolder recipeholder = optional.get(); + CraftingRecipe craftingrecipe = recipeholder.value(); +@@ -71,6 +_,8 @@ + } + } + ++ itemstack = org.bukkit.craftbukkit.event.CraftEventFactory.callPreCraftEvent(p_150550_, p_150551_, itemstack, p_150547_.getBukkitView(), optional.map(RecipeHolder::value).orElse(null) instanceof RepairItemRecipe); // CraftBukkit ++ + p_150551_.setItem(0, itemstack); + p_150547_.setRemoteSlot(0, itemstack); + serverplayer.connection.send(new ClientboundContainerSetSlotPacket(p_150547_.containerId, p_150547_.incrementStateId(), 0, itemstack)); +@@ -106,6 +_,7 @@ + + @Override + public boolean stillValid(Player p_39368_) { ++ if (!this.checkReachable) return true; // CraftBukkit + return stillValid(this.access, p_39368_, Blocks.CRAFTING_TABLE); + } + +@@ -180,4 +_,17 @@ + protected Player owner() { + return this.player; + } ++ ++ // CraftBukkit start ++ @Override ++ public CraftInventoryView getBukkitView() { ++ if (bukkitEntity != null) { ++ return bukkitEntity; ++ } ++ ++ CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftSlots, this.resultSlots); ++ bukkitEntity = new CraftInventoryView(this.player.getBukkitEntity(), inventory, this); ++ return bukkitEntity; ++ } ++ // CraftBukkit end + } diff --git a/patches/net/minecraft/world/inventory/FurnaceResultSlot.java.patch b/patches/net/minecraft/world/inventory/FurnaceResultSlot.java.patch index e7e60046..af56f72f 100644 --- a/patches/net/minecraft/world/inventory/FurnaceResultSlot.java.patch +++ b/patches/net/minecraft/world/inventory/FurnaceResultSlot.java.patch @@ -1,7 +1,10 @@ --- a/net/minecraft/world/inventory/FurnaceResultSlot.java +++ b/net/minecraft/world/inventory/FurnaceResultSlot.java -@@ -48,6 +_,9 @@ +@@ -46,8 +_,12 @@ + p_39558_.onCraftedBy(this.player.level(), this.player, this.removeCount); + if (this.player instanceof ServerPlayer serverplayer && this.container instanceof AbstractFurnaceBlockEntity abstractfurnaceblockentity) { abstractfurnaceblockentity.awardUsedRecipesAndPopExperience(serverplayer); ++ // abstractfurnaceblockentity.awardUsedRecipesAndPopExperience(serverplayer, p_39558_, this.removeCount); // CraftBukkit // Youer TODO } + if (this.removeCount != 0) { diff --git a/patches/net/minecraft/world/inventory/InventoryMenu.java.patch b/patches/net/minecraft/world/inventory/InventoryMenu.java.patch new file mode 100644 index 00000000..e58a668a --- /dev/null +++ b/patches/net/minecraft/world/inventory/InventoryMenu.java.patch @@ -0,0 +1,54 @@ +--- 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; +@@ -9,6 +_,8 @@ + import net.minecraft.world.entity.player.Inventory; + import net.minecraft.world.entity.player.Player; + import net.minecraft.world.item.ItemStack; ++import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting; ++import org.bukkit.craftbukkit.inventory.CraftInventoryView; + + public class InventoryMenu extends AbstractCraftingMenu { + public static final int CONTAINER_ID = 0; +@@ -44,9 +_,15 @@ + 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 CraftInventoryView bukkitEntity = null; ++ // CraftBukkit end + + public InventoryMenu(Inventory p_39706_, boolean p_39707_, final Player p_39708_) { +- super(null, 0, 2, 2); ++ // CraftBukkit start ++ super(null, 0, 2, 2); // Youer TODO ++ setTitle(Component.translatable("container.crafting")); // SPIGOT-4722: Allocate title for player inventory ++ // CraftBukkit end + this.active = p_39707_; + this.owner = p_39708_; + this.addResultSlot(p_39708_, 154, 28); +@@ -188,4 +_,17 @@ + protected Player owner() { + return this.owner; + } ++ ++ // CraftBukkit start ++ @Override ++ public CraftInventoryView getBukkitView() { ++ if (bukkitEntity != null) { ++ return bukkitEntity; ++ } ++ ++ CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftSlots, this.resultSlots); ++ bukkitEntity = new CraftInventoryView(this.owner.getBukkitEntity(), inventory, this); ++ return bukkitEntity; ++ } ++ // CraftBukkit end + } diff --git a/patches/net/minecraft/world/inventory/LecternMenu.java.patch b/patches/net/minecraft/world/inventory/LecternMenu.java.patch new file mode 100644 index 00000000..4ebc33d4 --- /dev/null +++ b/patches/net/minecraft/world/inventory/LecternMenu.java.patch @@ -0,0 +1,103 @@ +--- a/net/minecraft/world/inventory/LecternMenu.java ++++ b/net/minecraft/world/inventory/LecternMenu.java +@@ -2,10 +_,33 @@ + + import net.minecraft.world.Container; + import net.minecraft.world.SimpleContainer; ++import net.minecraft.world.entity.player.Inventory; + import net.minecraft.world.entity.player.Player; + import net.minecraft.world.item.ItemStack; ++import net.minecraft.world.level.block.entity.LecternBlockEntity.LecternInventory; ++import org.bukkit.Bukkit; ++import org.bukkit.craftbukkit.inventory.CraftInventoryLectern; ++import org.bukkit.craftbukkit.inventory.view.CraftLecternView; ++import org.bukkit.event.player.PlayerTakeLecternBookEvent; + + public class LecternMenu extends AbstractContainerMenu { ++ ++ // CraftBukkit start ++ private CraftLecternView bukkitEntity = null; ++ private org.bukkit.entity.Player player; ++ ++ @Override ++ public CraftLecternView getBukkitView() { ++ if (bukkitEntity != null) { ++ return bukkitEntity; ++ } ++ ++ CraftInventoryLectern inventory = new CraftInventoryLectern(this.lectern); ++ bukkitEntity = new CraftLecternView(this.player, inventory, this); ++ return bukkitEntity; ++ } ++ // CraftBukkit end ++ + private static final int DATA_COUNT = 1; + private static final int SLOT_COUNT = 1; + public static final int BUTTON_PREV_PAGE = 1; +@@ -19,6 +_,10 @@ + this(p_39822_, new SimpleContainer(1), new SimpleContainerData(1)); + } + ++ public LecternMenu(int p_39822_, Inventory playerinventory) { ++ this(p_39822_, new SimpleContainer(1), new SimpleContainerData(1), playerinventory); ++ } ++ + public LecternMenu(int p_39824_, Container p_39825_, ContainerData p_39826_) { + super(MenuType.LECTERN, p_39824_); + checkContainerSize(p_39825_, 1); +@@ -35,6 +_,29 @@ + this.addDataSlots(p_39826_); + } + ++ // Mohist start ++ public LecternMenu player(Inventory playerinventory) { ++ player = (org.bukkit.entity.Player) playerinventory.player.getBukkitEntity(); // CraftBukkit ++ return this; ++ } ++ ++ public LecternMenu(int p_39824_, Container p_39825_, ContainerData p_39826_, Inventory playerinventory) { ++ super(MenuType.LECTERN, p_39824_); ++ checkContainerSize(p_39825_, 1); ++ checkContainerDataCount(p_39826_, 1); ++ this.lectern = p_39825_; ++ this.lecternData = p_39826_; ++ this.addSlot(new Slot(p_39825_, 0, 0, 0) { ++ public void setChanged() { ++ super.setChanged(); ++ LecternMenu.this.slotsChanged(this.container); ++ } ++ }); ++ this.addDataSlots(p_39826_); ++ player = (org.bukkit.entity.Player) playerinventory.player.getBukkitEntity(); // CraftBukkit ++ } ++ // Mohist end ++ + @Override + public boolean clickMenuButton(Player p_39833_, int p_39834_) { + if (p_39834_ >= 100) { +@@ -56,6 +_,16 @@ + return false; + } + ++ // CraftBukkit start - Event for taking the book ++ if (player != null) { ++ PlayerTakeLecternBookEvent event = new PlayerTakeLecternBookEvent(player, ((CraftInventoryLectern) getBukkitView().getTopInventory()).getHolder()); ++ Bukkit.getServer().getPluginManager().callEvent(event); ++ if (event.isCancelled()) { ++ return false; ++ } ++ } ++ // CraftBukkit end ++ + ItemStack itemstack = this.lectern.removeItemNoUpdate(0); + this.lectern.setChanged(); + if (!p_39833_.getInventory().add(itemstack)) { +@@ -82,6 +_,8 @@ + + @Override + public boolean stillValid(Player p_39831_) { ++ if (lectern instanceof LecternInventory && !((LecternInventory) lectern).getLectern().hasBook()) return false; // CraftBukkit ++ if (!this.checkReachable) return true; // CraftBukkit + return this.lectern.stillValid(p_39831_); + } + diff --git a/patches/net/minecraft/world/inventory/MenuType.java.patch b/patches/net/minecraft/world/inventory/MenuType.java.patch index 7d0eaf4e..d884c7c8 100644 --- a/patches/net/minecraft/world/inventory/MenuType.java.patch +++ b/patches/net/minecraft/world/inventory/MenuType.java.patch @@ -9,6 +9,15 @@ public static final MenuType GENERIC_9x1 = register("generic_9x1", ChestMenu::oneRow); public static final MenuType GENERIC_9x2 = register("generic_9x2", ChestMenu::twoRows); public static final MenuType GENERIC_9x3 = register("generic_9x3", ChestMenu::threeRows); +@@ -26,7 +_,7 @@ + public static final MenuType FURNACE = register("furnace", FurnaceMenu::new); + public static final MenuType GRINDSTONE = register("grindstone", GrindstoneMenu::new); + public static final MenuType HOPPER = register("hopper", HopperMenu::new); +- public static final MenuType LECTERN = register("lectern", (p_39992_, p_39993_) -> new LecternMenu(p_39992_)); ++ public static final MenuType LECTERN = register("lectern", (p_39992_, p_39993_) -> new LecternMenu(p_39992_).player(p_39993_)); // CraftBukkit // Youer + public static final MenuType LOOM = register("loom", LoomMenu::new); + public static final MenuType MERCHANT = register("merchant", MerchantMenu::new); + public static final MenuType SHULKER_BOX = register("shulker_box", ShulkerBoxMenu::new); @@ -52,6 +_,14 @@ public T create(int p_39986_, Inventory p_39987_) { diff --git a/patches/net/minecraft/world/inventory/MerchantContainer.java.patch b/patches/net/minecraft/world/inventory/MerchantContainer.java.patch new file mode 100644 index 00000000..5ce1542f --- /dev/null +++ b/patches/net/minecraft/world/inventory/MerchantContainer.java.patch @@ -0,0 +1,71 @@ +--- a/net/minecraft/world/inventory/MerchantContainer.java ++++ b/net/minecraft/world/inventory/MerchantContainer.java +@@ -1,14 +_,21 @@ + package net.minecraft.world.inventory; + ++import java.util.List; + import javax.annotation.Nullable; + import net.minecraft.core.NonNullList; + import net.minecraft.world.Container; + import net.minecraft.world.ContainerHelper; ++import net.minecraft.world.entity.npc.AbstractVillager; ++import net.minecraft.world.entity.npc.Villager; + import net.minecraft.world.entity.player.Player; + import net.minecraft.world.item.ItemStack; + import net.minecraft.world.item.trading.Merchant; + import net.minecraft.world.item.trading.MerchantOffer; + import net.minecraft.world.item.trading.MerchantOffers; ++import org.bukkit.Location; ++import org.bukkit.craftbukkit.entity.CraftAbstractVillager; ++import org.bukkit.craftbukkit.entity.CraftHumanEntity; ++import org.bukkit.entity.HumanEntity; + + public class MerchantContainer implements Container { + private final Merchant merchant; +@@ -17,6 +_,46 @@ + private MerchantOffer activeOffer; + public int selectionHint; + private int futureXp; ++ ++ // CraftBukkit start - add fields and methods ++ public List transaction = new java.util.ArrayList(); ++ private int maxStack = MAX_STACK; ++ ++ public List getContents() { ++ return this.itemStacks; ++ } ++ ++ public void onOpen(CraftHumanEntity who) { ++ transaction.add(who); ++ } ++ ++ public void onClose(CraftHumanEntity who) { ++ transaction.remove(who); ++ merchant.setTradingPlayer((Player) null); // SPIGOT-4860 ++ } ++ ++ public List getViewers() { ++ return transaction; ++ } ++ ++ @Override ++ public int getMaxStackSize() { ++ return maxStack; ++ } ++ ++ public void setMaxStackSize(int i) { ++ maxStack = i; ++ } ++ ++ public org.bukkit.inventory.InventoryHolder getOwner() { ++ return (merchant instanceof AbstractVillager) ? (CraftAbstractVillager) ((AbstractVillager) this.merchant).getBukkitEntity() : null; ++ } ++ ++ @Override ++ public Location getLocation() { ++ return (merchant instanceof Villager) ? ((Villager) this.merchant).getBukkitEntity().getLocation() : null; ++ } ++ // CraftBukkit end + + public MerchantContainer(Merchant p_40003_) { + this.merchant = p_40003_; diff --git a/patches/net/minecraft/world/inventory/PlayerEnderChestContainer.java.patch b/patches/net/minecraft/world/inventory/PlayerEnderChestContainer.java.patch new file mode 100644 index 00000000..645df242 --- /dev/null +++ b/patches/net/minecraft/world/inventory/PlayerEnderChestContainer.java.patch @@ -0,0 +1,37 @@ +--- a/net/minecraft/world/inventory/PlayerEnderChestContainer.java ++++ b/net/minecraft/world/inventory/PlayerEnderChestContainer.java +@@ -8,13 +_,34 @@ + import net.minecraft.world.entity.player.Player; + import net.minecraft.world.item.ItemStack; + import net.minecraft.world.level.block.entity.EnderChestBlockEntity; ++import org.bukkit.Location; ++import org.bukkit.craftbukkit.util.CraftLocation; ++import org.bukkit.inventory.InventoryHolder; + + public class PlayerEnderChestContainer extends SimpleContainer { + @Nullable + private EnderChestBlockEntity activeChest; ++ // CraftBukkit start ++ private final Player owner; ++ ++ public InventoryHolder getBukkitOwner() { ++ return owner.getBukkitEntity(); ++ } ++ ++ @Override ++ public Location getLocation() { ++ return this.activeChest != null ? CraftLocation.toBukkit(this.activeChest.getBlockPos(), this.activeChest.getLevel().getWorld()) : null; ++ } + + public PlayerEnderChestContainer() { + super(27); ++ this.owner = null; ++ } ++ ++ public PlayerEnderChestContainer(Player owner) { ++ super(27); ++ this.owner = owner; ++ // CraftBukkit end + } + + public void setActiveChest(EnderChestBlockEntity p_40106_) { diff --git a/nms-patches/net/minecraft/world/inventory/InventoryCraftResult.patch b/patches/net/minecraft/world/inventory/ResultContainer.java.patch similarity index 72% rename from nms-patches/net/minecraft/world/inventory/InventoryCraftResult.patch rename to patches/net/minecraft/world/inventory/ResultContainer.java.patch index 8b0b0e95..5380f34c 100644 --- a/nms-patches/net/minecraft/world/inventory/InventoryCraftResult.patch +++ b/patches/net/minecraft/world/inventory/ResultContainer.java.patch @@ -1,21 +1,18 @@ ---- a/net/minecraft/world/inventory/InventoryCraftResult.java -+++ b/net/minecraft/world/inventory/InventoryCraftResult.java -@@ -9,12 +9,51 @@ +--- a/net/minecraft/world/inventory/ResultContainer.java ++++ b/net/minecraft/world/inventory/ResultContainer.java +@@ -7,11 +_,47 @@ + import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.RecipeHolder; - -+// CraftBukkit start +import org.bukkit.Location; +import org.bukkit.craftbukkit.entity.CraftHumanEntity; +import org.bukkit.entity.HumanEntity; -+// CraftBukkit end -+ - public class InventoryCraftResult implements IInventory, RecipeCraftingHolder { - private final NonNullList itemStacks; + public class ResultContainer implements Container, RecipeCraftingHolder { + private final NonNullList itemStacks = NonNullList.withSize(1, ItemStack.EMPTY); @Nullable private RecipeHolder recipeUsed; - ++ + // CraftBukkit start + private int maxStack = MAX_STACK; + @@ -48,7 +45,6 @@ + return null; + } + // CraftBukkit end -+ - public InventoryCraftResult() { - this.itemStacks = NonNullList.withSize(1, ItemStack.EMPTY); - } + + @Override + public int getContainerSize() { diff --git a/patches/net/minecraft/world/inventory/ShulkerBoxMenu.java.patch b/patches/net/minecraft/world/inventory/ShulkerBoxMenu.java.patch new file mode 100644 index 00000000..ce2f14b4 --- /dev/null +++ b/patches/net/minecraft/world/inventory/ShulkerBoxMenu.java.patch @@ -0,0 +1,47 @@ +--- a/net/minecraft/world/inventory/ShulkerBoxMenu.java ++++ b/net/minecraft/world/inventory/ShulkerBoxMenu.java +@@ -5,11 +_,28 @@ + import net.minecraft.world.entity.player.Inventory; + import net.minecraft.world.entity.player.Player; + import net.minecraft.world.item.ItemStack; ++import org.bukkit.craftbukkit.inventory.CraftInventory; ++import org.bukkit.craftbukkit.inventory.CraftInventoryView; + + public class ShulkerBoxMenu extends AbstractContainerMenu { + private static final int CONTAINER_SIZE = 27; + private final Container container; + ++ // CraftBukkit start ++ private CraftInventoryView bukkitEntity; ++ private Inventory player; ++ ++ @Override ++ public CraftInventoryView getBukkitView() { ++ if (bukkitEntity != null) { ++ return bukkitEntity; ++ } ++ ++ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), new CraftInventory(this.container), this); ++ return bukkitEntity; ++ } ++ // CraftBukkit end ++ + public ShulkerBoxMenu(int p_40188_, Inventory p_40189_) { + this(p_40188_, p_40189_, new SimpleContainer(27)); + } +@@ -18,6 +_,7 @@ + super(MenuType.SHULKER_BOX, p_40191_); + checkContainerSize(p_40193_, 27); + this.container = p_40193_; ++ this.player = p_40192_; // CraftBukkit - save player + p_40193_.startOpen(p_40192_.player); + int i = 3; + int j = 9; +@@ -33,6 +_,7 @@ + + @Override + public boolean stillValid(Player p_40195_) { ++ if (!this.checkReachable) return true; // CraftBukkit + return this.container.stillValid(p_40195_); + } + diff --git a/patches/net/minecraft/world/inventory/SmithingMenu.java.patch b/patches/net/minecraft/world/inventory/SmithingMenu.java.patch new file mode 100644 index 00000000..83227006 --- /dev/null +++ b/patches/net/minecraft/world/inventory/SmithingMenu.java.patch @@ -0,0 +1,50 @@ +--- a/net/minecraft/world/inventory/SmithingMenu.java ++++ b/net/minecraft/world/inventory/SmithingMenu.java +@@ -17,6 +_,7 @@ + import net.minecraft.world.level.Level; + import net.minecraft.world.level.block.Blocks; + import net.minecraft.world.level.block.state.BlockState; ++import org.bukkit.craftbukkit.inventory.CraftInventoryView; + + public class SmithingMenu extends ItemCombinerMenu { + public static final int TEMPLATE_SLOT = 0; +@@ -33,6 +_,9 @@ + private final RecipePropertySet templateItemTest; + private final RecipePropertySet additionItemTest; + private final DataSlot hasRecipeError = DataSlot.standalone(); ++ // CraftBukkit start ++ private CraftInventoryView bukkitEntity; ++ // CraftBukkit end + + public SmithingMenu(int p_40245_, Inventory p_40246_) { + this(p_40245_, p_40246_, ContainerLevelAccess.NULL); +@@ -116,7 +_,9 @@ + optional.ifPresentOrElse(p_379190_ -> { + ItemStack itemstack = p_379190_.value().assemble(smithingrecipeinput, this.level.registryAccess()); + this.resultSlots.setRecipeUsed((RecipeHolder)p_379190_); +- this.resultSlots.setItem(0, itemstack); ++ // CraftBukkit start ++ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareSmithingEvent(getBukkitView(), itemstack); ++ // CraftBukkit end + }, () -> { + this.resultSlots.setRecipeUsed(null); + this.resultSlots.setItem(0, ItemStack.EMPTY); +@@ -140,4 +_,18 @@ + public boolean hasRecipeError() { + return this.hasRecipeError.get() > 0; + } ++ ++ // CraftBukkit start ++ @Override ++ public CraftInventoryView getBukkitView() { ++ if (bukkitEntity != null) { ++ return bukkitEntity; ++ } ++ ++ org.bukkit.craftbukkit.inventory.CraftInventory inventory = new org.bukkit.craftbukkit.inventory.CraftInventorySmithing( ++ access.getLocation(), this.inputSlots, this.resultSlots); ++ bukkitEntity = new CraftInventoryView(this.player.getBukkitEntity(), inventory, this); ++ return bukkitEntity; ++ } ++ // CraftBukkit end + } diff --git a/patches/net/minecraft/world/inventory/StonecutterMenu.java.patch b/patches/net/minecraft/world/inventory/StonecutterMenu.java.patch new file mode 100644 index 00000000..fb9a26d5 --- /dev/null +++ b/patches/net/minecraft/world/inventory/StonecutterMenu.java.patch @@ -0,0 +1,61 @@ +--- a/net/minecraft/world/inventory/StonecutterMenu.java ++++ b/net/minecraft/world/inventory/StonecutterMenu.java +@@ -17,6 +_,9 @@ + import net.minecraft.world.item.crafting.StonecutterRecipe; + import net.minecraft.world.level.Level; + import net.minecraft.world.level.block.Blocks; ++import org.bukkit.Location; ++import org.bukkit.craftbukkit.inventory.CraftInventoryStonecutter; ++import org.bukkit.craftbukkit.inventory.view.CraftStonecutterView; + + public class StonecutterMenu extends AbstractContainerMenu { + public static final int INPUT_SLOT = 0; +@@ -42,9 +_,32 @@ + StonecutterMenu.this.slotsChanged(this); + StonecutterMenu.this.slotUpdateListener.run(); + } ++ ++ // CraftBukkit start ++ @Override ++ public Location getLocation() { ++ return StonecutterMenu.this.access.getLocation(); ++ } ++ // CraftBukkit end + }; + final ResultContainer resultContainer = new ResultContainer(); + ++ // CraftBukkit start ++ private CraftStonecutterView bukkitEntity = null; ++ private org.bukkit.entity.Player player; ++ ++ @Override ++ public CraftStonecutterView getBukkitView() { ++ if (bukkitEntity != null) { ++ return bukkitEntity; ++ } ++ ++ CraftInventoryStonecutter inventory = new CraftInventoryStonecutter(this.container, this.resultContainer); ++ bukkitEntity = new CraftStonecutterView(this.player, inventory, this); ++ return bukkitEntity; ++ } ++ // CraftBukkit end ++ + public StonecutterMenu(int p_40294_, Inventory p_40295_) { + this(p_40294_, p_40295_, ContainerLevelAccess.NULL); + } +@@ -85,6 +_,7 @@ + }); + this.addStandardInventorySlots(p_40298_, 8, 84); + this.addDataSlot(this.selectedRecipeIndex); ++ player = (org.bukkit.entity.Player) p_40298_.player.getBukkitEntity(); // CraftBukkit + } + + public int getSelectedRecipeIndex() { +@@ -105,6 +_,7 @@ + + @Override + public boolean stillValid(Player p_40307_) { ++ if (!this.checkReachable) return true; // CraftBukkit + return stillValid(this.access, p_40307_, Blocks.STONECUTTER); + } + diff --git a/nms-patches/net/minecraft/world/inventory/TransientCraftingContainer.patch b/patches/net/minecraft/world/inventory/TransientCraftingContainer.java.patch similarity index 69% rename from nms-patches/net/minecraft/world/inventory/TransientCraftingContainer.patch rename to patches/net/minecraft/world/inventory/TransientCraftingContainer.java.patch index 7c539ac5..44aae081 100644 --- a/nms-patches/net/minecraft/world/inventory/TransientCraftingContainer.patch +++ b/patches/net/minecraft/world/inventory/TransientCraftingContainer.java.patch @@ -1,31 +1,31 @@ --- a/net/minecraft/world/inventory/TransientCraftingContainer.java +++ b/net/minecraft/world/inventory/TransientCraftingContainer.java -@@ -8,6 +8,16 @@ +@@ -2,16 +_,84 @@ + + import java.util.List; + import net.minecraft.core.NonNullList; ++import net.minecraft.world.Container; + import net.minecraft.world.ContainerHelper; + import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.StackedItemContents; import net.minecraft.world.item.ItemStack; - -+// CraftBukkit start -+import java.util.List; -+import net.minecraft.world.IInventory; +import net.minecraft.world.item.crafting.RecipeHolder; +import org.bukkit.Location; +import org.bukkit.craftbukkit.entity.CraftHumanEntity; +import org.bukkit.entity.HumanEntity; +import org.bukkit.event.inventory.InventoryType; -+// CraftBukkit end -+ - public class TransientCraftingContainer implements InventoryCrafting { + public class TransientCraftingContainer implements CraftingContainer { private final NonNullList items; -@@ -15,6 +25,68 @@ + private final int width; private final int height; - private final Container menu; - + private final AbstractContainerMenu menu; ++ + // CraftBukkit start - add fields + public List transaction = new java.util.ArrayList(); + private RecipeHolder currentRecipe; -+ public IInventory resultInventory; -+ private EntityHuman owner; ++ public Container resultInventory; ++ private Player owner; + private int maxStack = MAX_STACK; + + public List getContents() { @@ -64,7 +64,7 @@ + + @Override + public Location getLocation() { -+ return menu instanceof ContainerWorkbench ? ((ContainerWorkbench) menu).access.getLocation() : owner.getBukkitEntity().getLocation(); ++ return menu instanceof CraftingMenu ? ((CraftingMenu) menu).access.getLocation() : owner.getBukkitEntity().getLocation(); + } + + @Override @@ -77,12 +77,11 @@ + this.currentRecipe = currentRecipe; + } + -+ public TransientCraftingContainer(Container container, int i, int j, EntityHuman player) { ++ public TransientCraftingContainer(AbstractContainerMenu container, int i, int j, Player player) { + this(container, i, j); + this.owner = player; + } + // CraftBukkit end -+ - public TransientCraftingContainer(Container container, int i, int j) { - this(container, i, j, NonNullList.withSize(i * j, ItemStack.EMPTY)); - } + + public TransientCraftingContainer(AbstractContainerMenu p_287684_, int p_287629_, int p_287593_) { + this(p_287684_, p_287629_, p_287593_, NonNullList.withSize(p_287629_ * p_287593_, ItemStack.EMPTY)); diff --git a/patches/net/minecraft/world/level/block/entity/LecternBlockEntity.java.patch b/patches/net/minecraft/world/level/block/entity/LecternBlockEntity.java.patch new file mode 100644 index 00000000..797b1a48 --- /dev/null +++ b/patches/net/minecraft/world/level/block/entity/LecternBlockEntity.java.patch @@ -0,0 +1,34 @@ +--- a/net/minecraft/world/level/block/entity/LecternBlockEntity.java ++++ b/net/minecraft/world/level/block/entity/LecternBlockEntity.java +@@ -26,13 +_,17 @@ + import net.minecraft.world.level.block.state.BlockState; + import net.minecraft.world.phys.Vec2; + import net.minecraft.world.phys.Vec3; ++import org.bukkit.Location; ++import org.bukkit.craftbukkit.util.CraftLocation; + + public class LecternBlockEntity extends BlockEntity implements Clearable, MenuProvider { + public static final int DATA_PAGE = 0; + public static final int NUM_DATA = 1; + public static final int SLOT_BOOK = 0; + public static final int NUM_SLOTS = 1; +- public final Container bookAccess = new Container() { ++ public final Container bookAccess = new LecternInventory(); ++ ++ public class LecternInventory implements Container { + @Override + public int getContainerSize() { + return 1; +@@ -100,6 +_,12 @@ + + @Override + public void clearContent() { ++ } ++ ++ @Override ++ public Location getLocation() { ++ if (level == null) return null; ++ return CraftLocation.toBukkit(worldPosition, level.getWorld()); + } + }; + private final ContainerData dataAccess = new ContainerData() {