From 8cbaba0a8ab095b495a1492df016768117304f5d Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sun, 18 Apr 2021 18:03:23 +1000 Subject: [PATCH] SPIGOT-6078: Add SmithItemEvent and expand SmithingInventory API By: Julian van den Berkmortel --- .../server/network/PlayerConnection.patch | 117 ++++++++++-------- .../inventory/ContainerAnvilAbstract.patch | 33 ++++- .../world/inventory/ContainerSmithing.patch | 9 +- .../inventory/CraftInventorySmithing.java | 19 +++ 4 files changed, 122 insertions(+), 56 deletions(-) diff --git a/paper-server/nms-patches/net/minecraft/server/network/PlayerConnection.patch b/paper-server/nms-patches/net/minecraft/server/network/PlayerConnection.patch index baf95c43ce..4deb59963f 100644 --- a/paper-server/nms-patches/net/minecraft/server/network/PlayerConnection.patch +++ b/paper-server/nms-patches/net/minecraft/server/network/PlayerConnection.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/network/PlayerConnection.java +++ b/net/minecraft/server/network/PlayerConnection.java -@@ -158,6 +158,59 @@ +@@ -158,6 +158,61 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -36,6 +36,7 @@ +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCreativeEvent; +import org.bukkit.event.inventory.InventoryType.SlotType; ++import org.bukkit.event.inventory.SmithItemEvent; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerAnimationEvent; +import org.bukkit.event.player.PlayerChatEvent; @@ -54,13 +55,14 @@ +import org.bukkit.inventory.CraftingInventory; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.InventoryView; ++import org.bukkit.inventory.SmithingInventory; +import org.bukkit.util.NumberConversions; +// CraftBukkit end + public class PlayerConnection implements PacketListenerPlayIn { private static final Logger LOGGER = LogManager.getLogger(); -@@ -168,7 +221,10 @@ +@@ -168,7 +223,10 @@ private long lastKeepAlive; private boolean awaitingKeepAlive; private long h; @@ -72,7 +74,7 @@ private int j; private final Int2ShortMap k = new Int2ShortOpenHashMap(); private double l; -@@ -206,8 +262,33 @@ +@@ -206,8 +264,33 @@ itextfilter.a(); } @@ -106,7 +108,7 @@ public void tick() { this.syncPosition(); this.player.lastX = this.player.locX(); -@@ -255,7 +336,7 @@ +@@ -255,7 +338,7 @@ this.minecraftServer.getMethodProfiler().enter("keepAlive"); long i = SystemUtils.getMonotonicMillis(); @@ -115,7 +117,7 @@ if (this.awaitingKeepAlive) { this.disconnect(new ChatMessage("disconnect.timeout")); } else { -@@ -267,15 +348,21 @@ +@@ -267,15 +350,21 @@ } this.minecraftServer.getMethodProfiler().exit(); @@ -137,7 +139,7 @@ this.disconnect(new ChatMessage("multiplayer.disconnect.idling")); } -@@ -299,16 +386,46 @@ +@@ -299,16 +388,46 @@ return this.minecraftServer.a(this.player.getProfile()); } @@ -185,7 +187,7 @@ } private void a(T t0, Consumer consumer, BiFunction>> bifunction) { -@@ -324,7 +441,7 @@ +@@ -324,7 +443,7 @@ ITextFilter itextfilter = this.player.Q(); if (itextfilter != null) { @@ -194,7 +196,7 @@ optional.ifPresent(consumer1); }, iasynctaskhandler); } else { -@@ -381,7 +498,34 @@ +@@ -381,7 +500,34 @@ double d9 = entity.getMot().g(); double d10 = d6 * d6 + d7 * d7 + d8 * d8; @@ -230,7 +232,7 @@ PlayerConnection.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", entity.getDisplayName().getString(), this.player.getDisplayName().getString(), d6, d7, d8); this.networkManager.sendPacket(new PacketPlayOutVehicleMove(entity)); return; -@@ -411,14 +555,72 @@ +@@ -411,14 +557,72 @@ } entity.setLocation(d3, d4, d5, f, f1); @@ -303,7 +305,7 @@ this.player.getWorldServer().getChunkProvider().movePlayer(this.player); this.player.checkMovement(this.player.locX() - d0, this.player.locY() - d1, this.player.locZ() - d2); this.D = d11 >= -0.03125D && !this.minecraftServer.getAllowFlight() && this.a(entity); -@@ -437,7 +639,7 @@ +@@ -437,7 +641,7 @@ @Override public void a(PacketPlayInTeleportAccept packetplayinteleportaccept) { PlayerConnectionUtils.ensureMainThread(packetplayinteleportaccept, this, this.player.getWorldServer()); @@ -312,7 +314,7 @@ this.player.setLocation(this.teleportPos.x, this.teleportPos.y, this.teleportPos.z, this.player.yaw, this.player.pitch); this.o = this.teleportPos.x; this.p = this.teleportPos.y; -@@ -447,6 +649,7 @@ +@@ -447,6 +651,7 @@ } this.teleportPos = null; @@ -320,7 +322,7 @@ } } -@@ -454,7 +657,7 @@ +@@ -454,7 +659,7 @@ @Override public void a(PacketPlayInRecipeDisplayed packetplayinrecipedisplayed) { PlayerConnectionUtils.ensureMainThread(packetplayinrecipedisplayed, this, this.player.getWorldServer()); @@ -329,7 +331,7 @@ RecipeBookServer recipebookserver = this.player.getRecipeBook(); optional.ifPresent(recipebookserver::e); -@@ -483,6 +686,12 @@ +@@ -483,6 +688,12 @@ @Override public void a(PacketPlayInTabComplete packetplayintabcomplete) { PlayerConnectionUtils.ensureMainThread(packetplayintabcomplete, this, this.player.getWorldServer()); @@ -342,7 +344,7 @@ StringReader stringreader = new StringReader(packetplayintabcomplete.c()); if (stringreader.canRead() && stringreader.peek() == '/') { -@@ -492,6 +701,7 @@ +@@ -492,6 +703,7 @@ ParseResults parseresults = this.minecraftServer.getCommandDispatcher().a().parse(stringreader, this.player.getCommandListener()); this.minecraftServer.getCommandDispatcher().a().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> { @@ -350,7 +352,7 @@ this.networkManager.sendPacket(new PacketPlayOutTabComplete(packetplayintabcomplete.b(), suggestions)); }); } -@@ -720,6 +930,7 @@ +@@ -720,6 +932,7 @@ if (container instanceof ContainerMerchant) { ContainerMerchant containermerchant = (ContainerMerchant) container; @@ -358,7 +360,7 @@ containermerchant.d(i); containermerchant.g(i); -@@ -729,6 +940,13 @@ +@@ -729,6 +942,13 @@ @Override public void a(PacketPlayInBEdit packetplayinbedit) { @@ -372,7 +374,7 @@ ItemStack itemstack = packetplayinbedit.b(); if (itemstack.getItem() == Items.WRITABLE_BOOK) { -@@ -744,13 +962,15 @@ +@@ -744,13 +964,15 @@ NBTTagList nbttaglist = nbttagcompound.getList("pages", 8); @@ -391,7 +393,7 @@ if (PlayerInventory.d(i) || i == 40) { this.a((List) list, flag ? (list1) -> { this.a((String) list1.get(0), list1.subList(1, list1.size()), i); -@@ -769,7 +989,9 @@ +@@ -769,7 +991,9 @@ NBTTagList nbttaglist = new NBTTagList(); list.stream().map(NBTTagString::a).forEach(nbttaglist::add); @@ -401,7 +403,7 @@ } } -@@ -798,7 +1020,7 @@ +@@ -798,7 +1022,7 @@ } itemstack1.a("pages", (NBTBase) nbttaglist); @@ -410,7 +412,7 @@ } } -@@ -836,7 +1058,7 @@ +@@ -836,7 +1060,7 @@ } else { WorldServer worldserver = this.player.getWorldServer(); @@ -419,7 +421,7 @@ if (this.e == 0) { this.syncPosition(); } -@@ -846,13 +1068,21 @@ +@@ -846,13 +1070,21 @@ this.A = this.e; this.a(this.teleportPos.x, this.teleportPos.y, this.teleportPos.z, this.player.yaw, this.player.pitch); } @@ -442,7 +444,7 @@ double d0 = this.player.locX(); double d1 = this.player.locY(); double d2 = this.player.locZ(); -@@ -877,15 +1107,33 @@ +@@ -877,15 +1109,33 @@ ++this.receivedMovePackets; int i = this.receivedMovePackets - this.processedMovePackets; @@ -478,7 +480,7 @@ PlayerConnection.LOGGER.warn("{} moved too quickly! {},{},{}", this.player.getDisplayName().getString(), d7, d8, d9); this.a(this.player.locX(), this.player.locY(), this.player.locZ(), this.player.yaw, this.player.pitch); return; -@@ -904,6 +1152,7 @@ +@@ -904,6 +1154,7 @@ } this.player.move(EnumMoveType.PLAYER, new Vec3D(d7, d8, d9)); @@ -486,7 +488,7 @@ double d12 = d8; d7 = d4 - this.player.locX(); -@@ -925,10 +1174,74 @@ +@@ -925,10 +1176,74 @@ if (!this.player.noclip && !this.player.isSleeping() && (flag1 && worldserver.getCubes(this.player, axisalignedbb) || this.a((IWorldReader) worldserver, axisalignedbb))) { this.a(d0, d1, d2, f, f1); } else { @@ -563,7 +565,7 @@ if (flag) { this.player.fallDistance = 0.0F; } -@@ -957,10 +1270,66 @@ +@@ -957,10 +1272,66 @@ } public void a(double d0, double d1, double d2, float f, float f1) { @@ -631,7 +633,7 @@ double d3 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.X) ? this.player.locX() : 0.0D; double d4 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Y) ? this.player.locY() : 0.0D; double d5 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Z) ? this.player.locZ() : 0.0D; -@@ -972,6 +1341,14 @@ +@@ -972,6 +1343,14 @@ this.teleportAwait = 0; } @@ -646,7 +648,7 @@ this.A = this.e; this.player.setLocation(d0, d1, d2, f, f1); this.player.playerConnection.sendPacket(new PacketPlayOutPosition(d0 - d3, d1 - d4, d2 - d5, f - f2, f1 - f3, set, this.teleportAwait)); -@@ -980,6 +1357,7 @@ +@@ -980,6 +1359,7 @@ @Override public void a(PacketPlayInBlockDig packetplayinblockdig) { PlayerConnectionUtils.ensureMainThread(packetplayinblockdig, this, this.player.getWorldServer()); @@ -654,7 +656,7 @@ BlockPosition blockposition = packetplayinblockdig.b(); this.player.resetIdleTimer(); -@@ -990,14 +1368,46 @@ +@@ -990,14 +1370,46 @@ if (!this.player.isSpectator()) { ItemStack itemstack = this.player.b(EnumHand.OFF_HAND); @@ -703,7 +705,7 @@ this.player.dropItem(false); } -@@ -1034,6 +1444,7 @@ +@@ -1034,6 +1446,7 @@ @Override public void a(PacketPlayInUseItem packetplayinuseitem) { PlayerConnectionUtils.ensureMainThread(packetplayinuseitem, this, this.player.getWorldServer()); @@ -711,7 +713,7 @@ WorldServer worldserver = this.player.getWorldServer(); EnumHand enumhand = packetplayinuseitem.b(); ItemStack itemstack = this.player.b(enumhand); -@@ -1044,6 +1455,14 @@ +@@ -1044,6 +1457,14 @@ this.player.resetIdleTimer(); if (blockposition.getY() < this.minecraftServer.getMaxBuildHeight()) { if (this.teleportPos == null && this.player.h((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) < 64.0D && worldserver.a((EntityHuman) this.player, blockposition)) { @@ -726,7 +728,7 @@ EnumInteractionResult enuminteractionresult = this.player.playerInteractManager.a(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock); if (enumdirection == EnumDirection.UP && !enuminteractionresult.a() && blockposition.getY() >= this.minecraftServer.getMaxBuildHeight() - 1 && a(this.player, itemstack)) { -@@ -1067,12 +1486,51 @@ +@@ -1067,12 +1488,51 @@ @Override public void a(PacketPlayInBlockPlace packetplayinblockplace) { PlayerConnectionUtils.ensureMainThread(packetplayinblockplace, this, this.player.getWorldServer()); @@ -778,7 +780,7 @@ EnumInteractionResult enuminteractionresult = this.player.playerInteractManager.a(this.player, worldserver, itemstack, enumhand); if (enuminteractionresult.b()) { -@@ -1093,7 +1551,7 @@ +@@ -1093,7 +1553,7 @@ Entity entity = packetplayinspectate.a(worldserver); if (entity != null) { @@ -787,7 +789,7 @@ return; } } -@@ -1102,7 +1560,12 @@ +@@ -1102,7 +1562,12 @@ } @Override @@ -801,7 +803,7 @@ @Override public void a(PacketPlayInBoatMove packetplayinboatmove) { -@@ -1117,11 +1580,26 @@ +@@ -1117,11 +1582,26 @@ @Override public void a(IChatBaseComponent ichatbasecomponent) { @@ -829,7 +831,7 @@ ITextFilter itextfilter = this.player.Q(); if (itextfilter != null) { -@@ -1153,6 +1631,15 @@ +@@ -1153,6 +1633,15 @@ } } @@ -845,7 +847,7 @@ try { this.networkManager.sendPacket(packet, genericfuturelistener); } catch (Throwable throwable) { -@@ -1169,7 +1656,16 @@ +@@ -1169,7 +1658,16 @@ @Override public void a(PacketPlayInHeldItemSlot packetplayinhelditemslot) { PlayerConnectionUtils.ensureMainThread(packetplayinhelditemslot, this, this.player.getWorldServer()); @@ -862,7 +864,7 @@ if (this.player.inventory.itemInHandIndex != packetplayinhelditemslot.b() && this.player.getRaisedHand() == EnumHand.MAIN_HAND) { this.player.clearActiveItem(); } -@@ -1178,65 +1674,286 @@ +@@ -1178,65 +1676,286 @@ this.player.resetIdleTimer(); } else { PlayerConnection.LOGGER.warn("{} tried to set an invalid carried item", this.player.getDisplayName().getString()); @@ -1158,7 +1160,7 @@ this.player.resetIdleTimer(); IJumpable ijumpable; -@@ -1294,6 +2011,7 @@ +@@ -1294,6 +2013,7 @@ @Override public void a(PacketPlayInUseEntity packetplayinuseentity) { PlayerConnectionUtils.ensureMainThread(packetplayinuseentity, this, this.player.getWorldServer()); @@ -1166,7 +1168,7 @@ WorldServer worldserver = this.player.getWorldServer(); Entity entity = packetplayinuseentity.a((World) worldserver); -@@ -1307,18 +2025,72 @@ +@@ -1307,18 +2027,72 @@ ItemStack itemstack = enumhand != null ? this.player.b(enumhand).cloneItemStack() : ItemStack.b; Optional optional = Optional.empty(); @@ -1240,7 +1242,7 @@ } if (optional.isPresent() && ((EnumInteractionResult) optional.get()).a()) { -@@ -1365,15 +2137,21 @@ +@@ -1365,15 +2139,21 @@ @Override public void a(PacketPlayInCloseWindow packetplayinclosewindow) { PlayerConnectionUtils.ensureMainThread(packetplayinclosewindow, this, this.player.getWorldServer()); @@ -1264,7 +1266,7 @@ NonNullList nonnulllist = NonNullList.a(); for (int i = 0; i < this.player.activeContainer.slots.size(); ++i) { -@@ -1382,8 +2160,274 @@ +@@ -1382,8 +2162,285 @@ this.player.a(this.player.activeContainer, nonnulllist); } else { @@ -1467,13 +1469,24 @@ + } + } + ++ if (packetplayinwindowclick.c() == 2 && top instanceof SmithingInventory) { ++ org.bukkit.inventory.ItemStack result = ((SmithingInventory) top).getResult(); ++ if (result != null) { ++ if (click == ClickType.NUMBER_KEY) { ++ event = new SmithItemEvent(inventory, type, packetplayinwindowclick.c(), click, action, packetplayinwindowclick.d()); ++ } else { ++ event = new SmithItemEvent(inventory, type, packetplayinwindowclick.c(), click, action); ++ } ++ } ++ } ++ + event.setCancelled(cancelled); + Container oldContainer = this.player.activeContainer; // SPIGOT-1224 + server.getPluginManager().callEvent(event); + if (this.player.activeContainer != oldContainer) { + return; + } - ++ + switch (event.getResult()) { + case ALLOW: + case DEFAULT: @@ -1482,7 +1495,7 @@ + case DENY: + /* Needs enum constructor in InventoryAction + if (action.modifiesOtherSlots()) { -+ + + } else { + if (action.modifiesCursor()) { + this.player.playerConnection.sendPacket(new Packet103SetSlot(-1, -1, this.player.inventory.getCarried())); @@ -1530,7 +1543,7 @@ + return; + } + -+ if (event instanceof CraftItemEvent) { ++ if (event instanceof CraftItemEvent || event instanceof SmithItemEvent) { + // Need to update the inventory on crafting to + // correctly support custom recipes + player.updateInventory(player.activeContainer); @@ -1540,7 +1553,7 @@ if (ItemStack.matches(packetplayinwindowclick.f(), itemstack)) { this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.b(), packetplayinwindowclick.e(), true)); this.player.e = true; -@@ -1423,6 +2467,7 @@ +@@ -1423,6 +2480,7 @@ @Override public void a(PacketPlayInEnchantItem packetplayinenchantitem) { PlayerConnectionUtils.ensureMainThread(packetplayinenchantitem, this, this.player.getWorldServer()); @@ -1548,7 +1561,7 @@ this.player.resetIdleTimer(); if (this.player.activeContainer.windowId == packetplayinenchantitem.b() && this.player.activeContainer.c(this.player) && !this.player.isSpectator()) { this.player.activeContainer.a((EntityHuman) this.player, packetplayinenchantitem.c()); -@@ -1455,6 +2500,43 @@ +@@ -1455,6 +2513,43 @@ boolean flag1 = packetplayinsetcreativeslot.b() >= 1 && packetplayinsetcreativeslot.b() <= 45; boolean flag2 = itemstack.isEmpty() || itemstack.getDamage() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty(); @@ -1592,7 +1605,7 @@ if (flag1 && flag2) { if (itemstack.isEmpty()) { -@@ -1476,6 +2558,7 @@ +@@ -1476,6 +2571,7 @@ @Override public void a(PacketPlayInTransaction packetplayintransaction) { PlayerConnectionUtils.ensureMainThread(packetplayintransaction, this, this.player.getWorldServer()); @@ -1600,7 +1613,7 @@ int i = this.player.activeContainer.windowId; if (i == packetplayintransaction.b() && this.k.getOrDefault(i, (short) (packetplayintransaction.c() + 1)) == packetplayintransaction.c() && !this.player.activeContainer.c(this.player) && !this.player.isSpectator()) { -@@ -1494,6 +2577,7 @@ +@@ -1494,6 +2590,7 @@ } private void a(PacketPlayInUpdateSign packetplayinupdatesign, List list) { @@ -1608,7 +1621,7 @@ this.player.resetIdleTimer(); WorldServer worldserver = this.player.getWorldServer(); BlockPosition blockposition = packetplayinupdatesign.b(); -@@ -1510,12 +2594,28 @@ +@@ -1510,12 +2607,28 @@ if (!tileentitysign.d() || tileentitysign.f() != this.player) { PlayerConnection.LOGGER.warn("Player {} just tried to change non-editable sign", this.player.getDisplayName().getString()); @@ -1638,7 +1651,7 @@ tileentitysign.update(); worldserver.notify(blockposition, iblockdata, iblockdata, 3); -@@ -1525,6 +2625,7 @@ +@@ -1525,6 +2638,7 @@ @Override public void a(PacketPlayInKeepAlive packetplayinkeepalive) { @@ -1646,7 +1659,7 @@ if (this.awaitingKeepAlive && packetplayinkeepalive.b() == this.h) { int i = (int) (SystemUtils.getMonotonicMillis() - this.lastKeepAlive); -@@ -1539,7 +2640,17 @@ +@@ -1539,7 +2653,17 @@ @Override public void a(PacketPlayInAbilities packetplayinabilities) { PlayerConnectionUtils.ensureMainThread(packetplayinabilities, this, this.player.getWorldServer()); @@ -1665,7 +1678,7 @@ } @Override -@@ -1548,8 +2659,50 @@ +@@ -1548,8 +2672,50 @@ this.player.a(packetplayinsettings); } diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerAnvilAbstract.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerAnvilAbstract.patch index 422886eaf0..78de61f7d0 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerAnvilAbstract.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerAnvilAbstract.patch @@ -1,6 +1,37 @@ --- a/net/minecraft/world/inventory/ContainerAnvilAbstract.java +++ b/net/minecraft/world/inventory/ContainerAnvilAbstract.java -@@ -85,6 +85,7 @@ +@@ -11,13 +11,7 @@ + public abstract class ContainerAnvilAbstract extends Container { + + protected final InventoryCraftResult resultInventory = new InventoryCraftResult(); +- protected final IInventory repairInventory = new InventorySubcontainer(2) { +- @Override +- public void update() { +- super.update(); +- ContainerAnvilAbstract.this.a((IInventory) this); +- } +- }; ++ protected final IInventory repairInventory; // CraftBukkit - instantiate repairInventory in the constructor + protected final ContainerAccess containerAccess; + protected final EntityHuman player; + +@@ -31,6 +25,15 @@ + super(containers, i); + this.containerAccess = containeraccess; + this.player = playerinventory.player; ++ // CraftBukkit start ++ this.repairInventory = new InventoryCrafting(this, 1, 2, player) { ++ @Override ++ public void update() { ++ super.update(); ++ ContainerAnvilAbstract.this.a((IInventory) this); ++ } ++ }; ++ // CraftBukkit end + this.a(new Slot(this.repairInventory, 0, 27, 47)); + this.a(new Slot(this.repairInventory, 1, 76, 47)); + this.a(new Slot(this.resultInventory, 2, 134, 47) { +@@ -85,6 +88,7 @@ @Override public boolean canUse(EntityHuman entityhuman) { diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerSmithing.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerSmithing.patch index 92550150f5..d640809921 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerSmithing.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerSmithing.patch @@ -18,7 +18,7 @@ public ContainerSmithing(int i, PlayerInventory playerinventory) { this(i, playerinventory, ContainerAccess.a); -@@ -63,13 +68,13 @@ +@@ -63,13 +68,16 @@ List list = this.g.getCraftingManager().b(Recipes.SMITHING, this.repairInventory, this.g); if (list.isEmpty()) { @@ -30,11 +30,14 @@ this.resultInventory.a((IRecipe) this.h); - this.resultInventory.setItem(0, itemstack); -+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareSmithingEvent(getBukkitView(), itemstack); // CraftBukkit ++ // CraftBukkit start ++ this.repairInventory.setCurrentRecipe(this.h); ++ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareSmithingEvent(getBukkitView(), itemstack); ++ // CraftBukkit end } } -@@ -85,4 +90,18 @@ +@@ -85,4 +93,18 @@ public boolean a(ItemStack itemstack, Slot slot) { return slot.inventory != this.resultInventory && super.a(itemstack, slot); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventorySmithing.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventorySmithing.java index 4c540c8e3b..4b1b617666 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventorySmithing.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventorySmithing.java @@ -1,7 +1,10 @@ package org.bukkit.craftbukkit.inventory; import net.minecraft.world.IInventory; +import net.minecraft.world.item.crafting.IRecipe; import org.bukkit.Location; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.Recipe; import org.bukkit.inventory.SmithingInventory; public class CraftInventorySmithing extends CraftResultInventory implements SmithingInventory { @@ -17,4 +20,20 @@ public class CraftInventorySmithing extends CraftResultInventory implements Smit public Location getLocation() { return location; } + + @Override + public ItemStack getResult() { + return getItem(2); + } + + @Override + public void setResult(ItemStack item) { + setItem(2, item); + } + + @Override + public Recipe getRecipe() { + IRecipe recipe = getInventory().getCurrentRecipe(); + return (recipe == null) ? null : recipe.toBukkitRecipe(); + } }