From 7700460ad7e46e943d7a3fcc909a8d82ba7c66eb Mon Sep 17 00:00:00 2001 From: Aram Date: Mon, 18 Nov 2024 13:30:26 +0100 Subject: [PATCH 1/8] Added the ItemSmithingEvent --- .../minecraft/data/DataProvider.java.patch | 17 +--------- .../server/level/ServerPlayer.java.patch | 9 ------ .../world/effect/MobEffect.java.patch | 2 +- .../world/inventory/SmithingMenu.java.patch | 10 ++++++ .../neoforged/neoforge/event/EventHooks.java | 4 +++ .../event/entity/player/PlayerEvent.java | 31 +++++++++++++++++++ 6 files changed, 47 insertions(+), 26 deletions(-) create mode 100644 patches/net/minecraft/world/inventory/SmithingMenu.java.patch diff --git a/patches/net/minecraft/data/DataProvider.java.patch b/patches/net/minecraft/data/DataProvider.java.patch index 05ad535d98..07f5c14860 100644 --- a/patches/net/minecraft/data/DataProvider.java.patch +++ b/patches/net/minecraft/data/DataProvider.java.patch @@ -1,14 +1,8 @@ --- a/net/minecraft/data/DataProvider.java +++ b/net/minecraft/data/DataProvider.java -@@ -27,7 +_,15 @@ - import org.slf4j.Logger; +@@ -28,6 +_,9 @@ public interface DataProvider { -+ /** -+ * Neo: Allows changing the indentation width used by {@link #saveStable}. -+ */ -+ java.util.concurrent.atomic.AtomicInteger INDENT_WIDTH = new java.util.concurrent.atomic.AtomicInteger(2); -+ ToIntFunction FIXED_ORDER_FIELDS = Util.make(new Object2IntOpenHashMap<>(), p_236070_ -> { + // Neo: conditions go first + p_236070_.put("neoforge:conditions", -1); @@ -16,12 +10,3 @@ p_236070_.put("type", 0); p_236070_.put("parent", 1); p_236070_.defaultReturnValue(2); -@@ -72,7 +_,7 @@ - - try (JsonWriter jsonwriter = new JsonWriter(new OutputStreamWriter(hashingoutputstream, StandardCharsets.UTF_8))) { - jsonwriter.setSerializeNulls(false); -- jsonwriter.setIndent(" "); -+ jsonwriter.setIndent(" ".repeat(java.lang.Math.max(0, INDENT_WIDTH.get()))); // Neo: Allow changing the indent width without needing to mixin this lambda. - GsonHelper.writeValue(jsonwriter, p_254542_, KEY_COMPARATOR); - } - diff --git a/patches/net/minecraft/server/level/ServerPlayer.java.patch b/patches/net/minecraft/server/level/ServerPlayer.java.patch index db56f6eebe..a0e3dd567a 100644 --- a/patches/net/minecraft/server/level/ServerPlayer.java.patch +++ b/patches/net/minecraft/server/level/ServerPlayer.java.patch @@ -23,15 +23,6 @@ if (this.tickCount % 20 == 0) { CriteriaTriggers.LOCATION.trigger(this); } -@@ -781,7 +_,7 @@ - - private void synchronizeSpecialItemUpdates(ItemStack p_372884_) { - MapId mapid = p_372884_.get(DataComponents.MAP_ID); -- MapItemSavedData mapitemsaveddata = MapItem.getSavedData(mapid, this.level()); -+ MapItemSavedData mapitemsaveddata = MapItem.getSavedData(p_372884_, this.level()); - if (mapitemsaveddata != null) { - Packet packet = mapitemsaveddata.getUpdatePacket(mapid, this); - if (packet != null) { @@ -850,6 +_,7 @@ @Override public void die(DamageSource p_9035_) { diff --git a/patches/net/minecraft/world/effect/MobEffect.java.patch b/patches/net/minecraft/world/effect/MobEffect.java.patch index 1daf7ed3ab..94408844fa 100644 --- a/patches/net/minecraft/world/effect/MobEffect.java.patch +++ b/patches/net/minecraft/world/effect/MobEffect.java.patch @@ -50,7 +50,7 @@ } - static record AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation) { -+ static record AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation, @Nullable it.unimi.dsi.fastutil.ints.Int2DoubleFunction curve) { ++ public static record AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation, @Nullable it.unimi.dsi.fastutil.ints.Int2DoubleFunction curve) { + + public AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation) { + this(id, amount, operation, null); 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 0000000000..3dc44e06ed --- /dev/null +++ b/patches/net/minecraft/world/inventory/SmithingMenu.java.patch @@ -0,0 +1,10 @@ +--- a/net/minecraft/world/inventory/SmithingMenu.java ++++ b/net/minecraft/world/inventory/SmithingMenu.java +@@ -72,6 +_,7 @@ + protected void onTake(Player p_150663_, ItemStack p_150664_) { + p_150664_.onCraftedBy(p_150663_.level(), p_150663_, p_150664_.getCount()); + this.resultSlots.awardUsedRecipes(p_150663_, this.getRelevantItems()); ++ net.neoforged.neoforge.event.EventHooks.firePlayerSmithingEvent(p_150663_, this.inputSlots.getItem(0), this.inputSlots.getItem(1), this.inputSlots.getItem(2), p_150664_); + this.shrinkStackInSlot(0); + this.shrinkStackInSlot(1); + this.shrinkStackInSlot(2); diff --git a/src/main/java/net/neoforged/neoforge/event/EventHooks.java b/src/main/java/net/neoforged/neoforge/event/EventHooks.java index 7529a767d1..1d0c87faff 100644 --- a/src/main/java/net/neoforged/neoforge/event/EventHooks.java +++ b/src/main/java/net/neoforged/neoforge/event/EventHooks.java @@ -912,6 +912,10 @@ public static void firePlayerSmeltedEvent(Player player, ItemStack smelted, int NeoForge.EVENT_BUS.post(new PlayerEvent.ItemSmeltedEvent(player, smelted, amountRemoved)); } + public static void firePlayerSmithingEvent(Player player, ItemStack template, ItemStack mainItem, ItemStack addition, ItemStack result) { + NeoForge.EVENT_BUS.post(new PlayerEvent.ItemSmithingEvent(player, template, mainItem, addition, result)); + } + /** * Called by {@link Gui.HeartType#forPlayer} to allow for modification of the displayed heart type in the * health bar. diff --git a/src/main/java/net/neoforged/neoforge/event/entity/player/PlayerEvent.java b/src/main/java/net/neoforged/neoforge/event/entity/player/PlayerEvent.java index 66c55569e4..87cb29d87f 100644 --- a/src/main/java/net/neoforged/neoforge/event/entity/player/PlayerEvent.java +++ b/src/main/java/net/neoforged/neoforge/event/entity/player/PlayerEvent.java @@ -406,6 +406,37 @@ public Container getInventory() { } } + public static class ItemSmithingEvent extends PlayerEvent { + private final ItemStack template; + private final ItemStack mainItem; + private final ItemStack addition; + private final ItemStack result; + + public ItemSmithingEvent(Player player, ItemStack template, ItemStack mainItem, ItemStack addition, ItemStack result) { + super(player); + this.template = template; + this.mainItem = mainItem; + this.addition = addition; + this.result = result; + } + + public ItemStack getTemplate() { + return this.template; + } + + public ItemStack getMainItem() { + return this.mainItem; + } + + public ItemStack getAddition() { + return this.addition; + } + + public ItemStack getResult() { + return this.result; + } + } + public static class ItemSmeltedEvent extends PlayerEvent { private final ItemStack smelting; private final int amountRemoved; From a3ce9b6b1ecaf9fe66a674247888be272b7361ff Mon Sep 17 00:00:00 2001 From: Aram Date: Mon, 18 Nov 2024 13:57:14 +0100 Subject: [PATCH 2/8] Reverted Back Breaking Changes --- .../net/minecraft/data/DataProvider.java.patch | 18 ++++++++++++++++-- .../server/level/ServerPlayer.java.patch | 9 +++++++++ .../world/effect/MobEffect.java.patch | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/patches/net/minecraft/data/DataProvider.java.patch b/patches/net/minecraft/data/DataProvider.java.patch index 07f5c14860..6bdf77861b 100644 --- a/patches/net/minecraft/data/DataProvider.java.patch +++ b/patches/net/minecraft/data/DataProvider.java.patch @@ -1,8 +1,14 @@ --- a/net/minecraft/data/DataProvider.java +++ b/net/minecraft/data/DataProvider.java -@@ -28,6 +_,9 @@ - +@@ -27,7 +_,15 @@ + import org.slf4j.Logger; + public interface DataProvider { ++ /** ++ * Neo: Allows changing the indentation width used by {@link #saveStable}. ++ */ ++ java.util.concurrent.atomic.AtomicInteger INDENT_WIDTH = new java.util.concurrent.atomic.AtomicInteger(2); ++ ToIntFunction FIXED_ORDER_FIELDS = Util.make(new Object2IntOpenHashMap<>(), p_236070_ -> { + // Neo: conditions go first + p_236070_.put("neoforge:conditions", -1); @@ -10,3 +16,11 @@ p_236070_.put("type", 0); p_236070_.put("parent", 1); p_236070_.defaultReturnValue(2); +@@ -72,7 +_,7 @@ + + try (JsonWriter jsonwriter = new JsonWriter(new OutputStreamWriter(hashingoutputstream, StandardCharsets.UTF_8))) { + jsonwriter.setSerializeNulls(false); +- jsonwriter.setIndent(" "); ++ jsonwriter.setIndent(" ".repeat(java.lang.Math.max(0, INDENT_WIDTH.get()))); // Neo: Allow changing the indent width without needing to mixin this lambda. + GsonHelper.writeValue(jsonwriter, p_254542_, KEY_COMPARATOR); + } diff --git a/patches/net/minecraft/server/level/ServerPlayer.java.patch b/patches/net/minecraft/server/level/ServerPlayer.java.patch index a0e3dd567a..19c8ff4e30 100644 --- a/patches/net/minecraft/server/level/ServerPlayer.java.patch +++ b/patches/net/minecraft/server/level/ServerPlayer.java.patch @@ -23,6 +23,15 @@ if (this.tickCount % 20 == 0) { CriteriaTriggers.LOCATION.trigger(this); } +@@ -781,7 +_,7 @@ + + private void synchronizeSpecialItemUpdates(ItemStack p_372884_) { + MapId mapid = p_372884_.get(DataComponents.MAP_ID); +- MapItemSavedData mapitemsaveddata = MapItem.getSavedData(mapid, this.level()); ++ MapItemSavedData mapitemsaveddata = MapItem.getSavedData(p_372884_, this.level()); + if (mapitemsaveddata != null) { + Packet packet = mapitemsaveddata.getUpdatePacket(mapid, this); + if (packet != null) { @@ -850,6 +_,7 @@ @Override public void die(DamageSource p_9035_) { diff --git a/patches/net/minecraft/world/effect/MobEffect.java.patch b/patches/net/minecraft/world/effect/MobEffect.java.patch index 94408844fa..1daf7ed3ab 100644 --- a/patches/net/minecraft/world/effect/MobEffect.java.patch +++ b/patches/net/minecraft/world/effect/MobEffect.java.patch @@ -50,7 +50,7 @@ } - static record AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation) { -+ public static record AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation, @Nullable it.unimi.dsi.fastutil.ints.Int2DoubleFunction curve) { ++ static record AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation, @Nullable it.unimi.dsi.fastutil.ints.Int2DoubleFunction curve) { + + public AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation) { + this(id, amount, operation, null); From 9af14bc18a931509cb6d8757e691fe703db6c845 Mon Sep 17 00:00:00 2001 From: Aram Date: Mon, 18 Nov 2024 14:00:43 +0100 Subject: [PATCH 3/8] Followed Contributing.md Executed ``` Run gradlew genPatches to generate patch-files from the patched sources Run gradlew applyAllFormatting to automatically format sources Check correct formatting with gradlew spotlessCheck ``` --- .../net/minecraft/data/DataProvider.java.patch | 18 ++---------------- .../server/level/ServerPlayer.java.patch | 9 --------- .../world/effect/MobEffect.java.patch | 2 +- 3 files changed, 3 insertions(+), 26 deletions(-) diff --git a/patches/net/minecraft/data/DataProvider.java.patch b/patches/net/minecraft/data/DataProvider.java.patch index 6bdf77861b..07f5c14860 100644 --- a/patches/net/minecraft/data/DataProvider.java.patch +++ b/patches/net/minecraft/data/DataProvider.java.patch @@ -1,14 +1,8 @@ --- a/net/minecraft/data/DataProvider.java +++ b/net/minecraft/data/DataProvider.java -@@ -27,7 +_,15 @@ - import org.slf4j.Logger; - +@@ -28,6 +_,9 @@ + public interface DataProvider { -+ /** -+ * Neo: Allows changing the indentation width used by {@link #saveStable}. -+ */ -+ java.util.concurrent.atomic.AtomicInteger INDENT_WIDTH = new java.util.concurrent.atomic.AtomicInteger(2); -+ ToIntFunction FIXED_ORDER_FIELDS = Util.make(new Object2IntOpenHashMap<>(), p_236070_ -> { + // Neo: conditions go first + p_236070_.put("neoforge:conditions", -1); @@ -16,11 +10,3 @@ p_236070_.put("type", 0); p_236070_.put("parent", 1); p_236070_.defaultReturnValue(2); -@@ -72,7 +_,7 @@ - - try (JsonWriter jsonwriter = new JsonWriter(new OutputStreamWriter(hashingoutputstream, StandardCharsets.UTF_8))) { - jsonwriter.setSerializeNulls(false); -- jsonwriter.setIndent(" "); -+ jsonwriter.setIndent(" ".repeat(java.lang.Math.max(0, INDENT_WIDTH.get()))); // Neo: Allow changing the indent width without needing to mixin this lambda. - GsonHelper.writeValue(jsonwriter, p_254542_, KEY_COMPARATOR); - } diff --git a/patches/net/minecraft/server/level/ServerPlayer.java.patch b/patches/net/minecraft/server/level/ServerPlayer.java.patch index 19c8ff4e30..a0e3dd567a 100644 --- a/patches/net/minecraft/server/level/ServerPlayer.java.patch +++ b/patches/net/minecraft/server/level/ServerPlayer.java.patch @@ -23,15 +23,6 @@ if (this.tickCount % 20 == 0) { CriteriaTriggers.LOCATION.trigger(this); } -@@ -781,7 +_,7 @@ - - private void synchronizeSpecialItemUpdates(ItemStack p_372884_) { - MapId mapid = p_372884_.get(DataComponents.MAP_ID); -- MapItemSavedData mapitemsaveddata = MapItem.getSavedData(mapid, this.level()); -+ MapItemSavedData mapitemsaveddata = MapItem.getSavedData(p_372884_, this.level()); - if (mapitemsaveddata != null) { - Packet packet = mapitemsaveddata.getUpdatePacket(mapid, this); - if (packet != null) { @@ -850,6 +_,7 @@ @Override public void die(DamageSource p_9035_) { diff --git a/patches/net/minecraft/world/effect/MobEffect.java.patch b/patches/net/minecraft/world/effect/MobEffect.java.patch index 1daf7ed3ab..94408844fa 100644 --- a/patches/net/minecraft/world/effect/MobEffect.java.patch +++ b/patches/net/minecraft/world/effect/MobEffect.java.patch @@ -50,7 +50,7 @@ } - static record AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation) { -+ static record AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation, @Nullable it.unimi.dsi.fastutil.ints.Int2DoubleFunction curve) { ++ public static record AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation, @Nullable it.unimi.dsi.fastutil.ints.Int2DoubleFunction curve) { + + public AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation) { + this(id, amount, operation, null); From 65ae5a22b00bb335e15ef5dabdba885fbda691f2 Mon Sep 17 00:00:00 2001 From: Aram Date: Mon, 18 Nov 2024 15:44:14 +0100 Subject: [PATCH 4/8] Followed sciwhiz12 fix * Resolved the issue --- .../net/minecraft/data/DataProvider.java.patch | 17 ++++++++++++++++- .../server/level/ServerPlayer.java.patch | 9 +++++++++ .../minecraft/world/effect/MobEffect.java.patch | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/patches/net/minecraft/data/DataProvider.java.patch b/patches/net/minecraft/data/DataProvider.java.patch index 07f5c14860..05ad535d98 100644 --- a/patches/net/minecraft/data/DataProvider.java.patch +++ b/patches/net/minecraft/data/DataProvider.java.patch @@ -1,8 +1,14 @@ --- a/net/minecraft/data/DataProvider.java +++ b/net/minecraft/data/DataProvider.java -@@ -28,6 +_,9 @@ +@@ -27,7 +_,15 @@ + import org.slf4j.Logger; public interface DataProvider { ++ /** ++ * Neo: Allows changing the indentation width used by {@link #saveStable}. ++ */ ++ java.util.concurrent.atomic.AtomicInteger INDENT_WIDTH = new java.util.concurrent.atomic.AtomicInteger(2); ++ ToIntFunction FIXED_ORDER_FIELDS = Util.make(new Object2IntOpenHashMap<>(), p_236070_ -> { + // Neo: conditions go first + p_236070_.put("neoforge:conditions", -1); @@ -10,3 +16,12 @@ p_236070_.put("type", 0); p_236070_.put("parent", 1); p_236070_.defaultReturnValue(2); +@@ -72,7 +_,7 @@ + + try (JsonWriter jsonwriter = new JsonWriter(new OutputStreamWriter(hashingoutputstream, StandardCharsets.UTF_8))) { + jsonwriter.setSerializeNulls(false); +- jsonwriter.setIndent(" "); ++ jsonwriter.setIndent(" ".repeat(java.lang.Math.max(0, INDENT_WIDTH.get()))); // Neo: Allow changing the indent width without needing to mixin this lambda. + GsonHelper.writeValue(jsonwriter, p_254542_, KEY_COMPARATOR); + } + diff --git a/patches/net/minecraft/server/level/ServerPlayer.java.patch b/patches/net/minecraft/server/level/ServerPlayer.java.patch index a0e3dd567a..db56f6eebe 100644 --- a/patches/net/minecraft/server/level/ServerPlayer.java.patch +++ b/patches/net/minecraft/server/level/ServerPlayer.java.patch @@ -23,6 +23,15 @@ if (this.tickCount % 20 == 0) { CriteriaTriggers.LOCATION.trigger(this); } +@@ -781,7 +_,7 @@ + + private void synchronizeSpecialItemUpdates(ItemStack p_372884_) { + MapId mapid = p_372884_.get(DataComponents.MAP_ID); +- MapItemSavedData mapitemsaveddata = MapItem.getSavedData(mapid, this.level()); ++ MapItemSavedData mapitemsaveddata = MapItem.getSavedData(p_372884_, this.level()); + if (mapitemsaveddata != null) { + Packet packet = mapitemsaveddata.getUpdatePacket(mapid, this); + if (packet != null) { @@ -850,6 +_,7 @@ @Override public void die(DamageSource p_9035_) { diff --git a/patches/net/minecraft/world/effect/MobEffect.java.patch b/patches/net/minecraft/world/effect/MobEffect.java.patch index 94408844fa..1daf7ed3ab 100644 --- a/patches/net/minecraft/world/effect/MobEffect.java.patch +++ b/patches/net/minecraft/world/effect/MobEffect.java.patch @@ -50,7 +50,7 @@ } - static record AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation) { -+ public static record AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation, @Nullable it.unimi.dsi.fastutil.ints.Int2DoubleFunction curve) { ++ static record AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation, @Nullable it.unimi.dsi.fastutil.ints.Int2DoubleFunction curve) { + + public AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation) { + this(id, amount, operation, null); From 2d01c58304fae9f83c24923cf3c48e15ccd4ba10 Mon Sep 17 00:00:00 2001 From: Aram Date: Sun, 8 Dec 2024 15:42:04 +0100 Subject: [PATCH 5/8] Commented 3 Events * `ItemSmeltedEvent` * `ItemCraftedEvent` * ItemSmithingEvent` Using the Comment styling discussed in #neoforge-github (Discord) I also Commented the Methods within the Classes and renamed the parameters that were misleading --- .../neoforged/neoforge/event/EventHooks.java | 8 +- .../event/entity/player/PlayerEvent.java | 76 +++++++++++++++++-- 2 files changed, 72 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/event/EventHooks.java b/src/main/java/net/neoforged/neoforge/event/EventHooks.java index 1d0c87faff..1f76efd8c5 100644 --- a/src/main/java/net/neoforged/neoforge/event/EventHooks.java +++ b/src/main/java/net/neoforged/neoforge/event/EventHooks.java @@ -904,12 +904,12 @@ public static void firePlayerRespawnEvent(ServerPlayer player, boolean fromEndFi NeoForge.EVENT_BUS.post(new PlayerEvent.PlayerRespawnEvent(player, fromEndFight)); } - public static void firePlayerCraftingEvent(Player player, ItemStack crafted, Container craftMatrix) { - NeoForge.EVENT_BUS.post(new PlayerEvent.ItemCraftedEvent(player, crafted, craftMatrix)); + public static void firePlayerCraftingEvent(Player player, ItemStack result, Container craftMatrix) { + NeoForge.EVENT_BUS.post(new PlayerEvent.ItemCraftedEvent(player, result, craftMatrix)); } - public static void firePlayerSmeltedEvent(Player player, ItemStack smelted, int amountRemoved) { - NeoForge.EVENT_BUS.post(new PlayerEvent.ItemSmeltedEvent(player, smelted, amountRemoved)); + public static void firePlayerSmeltedEvent(Player player, ItemStack result, int amountRemoved) { + NeoForge.EVENT_BUS.post(new PlayerEvent.ItemSmeltedEvent(player, result, amountRemoved)); } public static void firePlayerSmithingEvent(Player player, ItemStack template, ItemStack mainItem, ItemStack addition, ItemStack result) { diff --git a/src/main/java/net/neoforged/neoforge/event/entity/player/PlayerEvent.java b/src/main/java/net/neoforged/neoforge/event/entity/player/PlayerEvent.java index 87cb29d87f..39d2389995 100644 --- a/src/main/java/net/neoforged/neoforge/event/entity/player/PlayerEvent.java +++ b/src/main/java/net/neoforged/neoforge/event/entity/player/PlayerEvent.java @@ -387,25 +387,55 @@ public String getPlayerUUID() { } } + /** + * An event triggered when a player crafts an item. + *

+ * This event is fired at the following stages: + *

    + *
  • After clicking the craft button in the crafting interface.
  • + *
  • Before awarding the used recipe and resizing the stacks.
  • + *
+ *

+ * The event is fired via {@link EventHooks#firePlayerCraftingEvent(Player, ItemStack, Container)}
+ * and is posted to the {@link NeoForge#EVENT_BUS}. + */ public static class ItemCraftedEvent extends PlayerEvent { - private final ItemStack crafting; + private final ItemStack result; private final Container craftMatrix; - public ItemCraftedEvent(Player player, ItemStack crafting, Container craftMatrix) { + public ItemCraftedEvent(Player player, ItemStack result, Container craftMatrix) { super(player); - this.crafting = crafting; + this.result = result; this.craftMatrix = craftMatrix; } + /** + * {@return the item that was crafted (ex. Diamond sword)} + */ public ItemStack getCrafting() { - return this.crafting; + return this.result; } + /** + * {@return the crafting matrix used to craft the item (ex. 2x diamond, 1x stick)} + */ public Container getInventory() { return this.craftMatrix; } } + /** + * An event triggered when a player smiths an item. + *

+ * This event is fired at the following stages: + *

    + *
  • After awarding the used recipe.
  • + *
  • Before resizing the stacks.
  • + *
+ *

+ * The event is fired via {@link EventHooks#firePlayerSmithingEvent(Player, ItemStack, ItemStack, ItemStack, ItemStack)}
+ * and is posted to the {@link NeoForge#EVENT_BUS}. + */ public static class ItemSmithingEvent extends PlayerEvent { private final ItemStack template; private final ItemStack mainItem; @@ -420,37 +450,67 @@ public ItemSmithingEvent(Player player, ItemStack template, ItemStack mainItem, this.result = result; } + /** + * {@return the template item used for smithing (ex. Smithing template)} + */ public ItemStack getTemplate() { return this.template; } + /** + * {@return the main item used for smithing (ex. Diamond sword)} + */ public ItemStack getMainItem() { return this.mainItem; } + /** + * {@return the item that is used as support to the item that is being smithed (ex. Netherite ingot} + */ public ItemStack getAddition() { return this.addition; } + /** + * {@return the result of the smithing in the final slot (ex. Netherite sword)} + */ public ItemStack getResult() { return this.result; } } + /** + * An event triggered when a player smelts an item. + *

+ * This event is fired after: + *

    + *
  • Awarding the used recipe.
  • + *
  • Resizing the item stacks.
  • + *
+ *

+ * The event is fired via {@link EventHooks#firePlayerSmeltedEvent(Player, ItemStack, int)}
+ * and is posted to the {@link NeoForge#EVENT_BUS}. + */ public static class ItemSmeltedEvent extends PlayerEvent { - private final ItemStack smelting; + private final ItemStack result; private final int amountRemoved; - public ItemSmeltedEvent(Player player, ItemStack crafting, int amountRemoved) { + public ItemSmeltedEvent(Player player, ItemStack result, int amountRemoved) { super(player); - this.smelting = crafting; + this.result = result; this.amountRemoved = amountRemoved; } + /** + * {@return the item result after smelting (ex. Iron ingot)} + */ public ItemStack getSmelting() { - return this.smelting; + return this.result; } + /** + * {@return the amount of items that were removed from the inventory (ex. 1)} + */ public int getAmountRemoved() { return this.amountRemoved; } From 386defe2ab89ffe6e958a510bd4ad79c4be21369 Mon Sep 17 00:00:00 2001 From: Aram Date: Sun, 8 Dec 2024 17:52:30 +0100 Subject: [PATCH 6/8] Added some comments to the EventHooks --- .../neoforged/neoforge/event/EventHooks.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/net/neoforged/neoforge/event/EventHooks.java b/src/main/java/net/neoforged/neoforge/event/EventHooks.java index 1f76efd8c5..cd05cf915f 100644 --- a/src/main/java/net/neoforged/neoforge/event/EventHooks.java +++ b/src/main/java/net/neoforged/neoforge/event/EventHooks.java @@ -904,14 +904,37 @@ public static void firePlayerRespawnEvent(ServerPlayer player, boolean fromEndFi NeoForge.EVENT_BUS.post(new PlayerEvent.PlayerRespawnEvent(player, fromEndFight)); } + /** + * Called by {@link net.minecraft.world.inventory.ResultSlot#checkTakeAchievements} after the player takes an item from the result slot in the crafting grid. + * + * @param player The player who took the item. + * @param result The item that was crafted. + * @param craftMatrix The crafting matrix that was used for the recipe. + */ public static void firePlayerCraftingEvent(Player player, ItemStack result, Container craftMatrix) { NeoForge.EVENT_BUS.post(new PlayerEvent.ItemCraftedEvent(player, result, craftMatrix)); } + /** + * Called by {@link net.minecraft.world.inventory.FurnaceResultSlot#checkTakeAchievements} after the player takes an item from the furnace output slot. + * + * @param player The player who took the item. + * @param result The item that was smelted. + * @param amountRemoved The amount of items removed from the output slot. + */ public static void firePlayerSmeltedEvent(Player player, ItemStack result, int amountRemoved) { NeoForge.EVENT_BUS.post(new PlayerEvent.ItemSmeltedEvent(player, result, amountRemoved)); } + /** + * Called by {@link net.minecraft.world.inventory.SmithingMenu#onTake} after the player takes an item from the output slot in the smithing table. + * + * @param player The player who took the item. + * @param template The template item used in the smithing recipe. (ex. Smithing template) + * @param mainItem The main item used in the smithing recipe. (ex. Diamond sword) + * @param addition The addition item used in the smithing recipe. (ex. Netherite ingot) + * @param result The item that was smithed. + */ public static void firePlayerSmithingEvent(Player player, ItemStack template, ItemStack mainItem, ItemStack addition, ItemStack result) { NeoForge.EVENT_BUS.post(new PlayerEvent.ItemSmithingEvent(player, template, mainItem, addition, result)); } From 8e3cee09a06800a6ee462d4adcec5938b5cdf75e Mon Sep 17 00:00:00 2001 From: Aram Date: Sun, 8 Dec 2024 17:58:34 +0100 Subject: [PATCH 7/8] Fixed the formatting --- .../net/neoforged/neoforge/event/EventHooks.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/event/EventHooks.java b/src/main/java/net/neoforged/neoforge/event/EventHooks.java index cd05cf915f..e27feef3a0 100644 --- a/src/main/java/net/neoforged/neoforge/event/EventHooks.java +++ b/src/main/java/net/neoforged/neoforge/event/EventHooks.java @@ -907,8 +907,8 @@ public static void firePlayerRespawnEvent(ServerPlayer player, boolean fromEndFi /** * Called by {@link net.minecraft.world.inventory.ResultSlot#checkTakeAchievements} after the player takes an item from the result slot in the crafting grid. * - * @param player The player who took the item. - * @param result The item that was crafted. + * @param player The player who took the item. + * @param result The item that was crafted. * @param craftMatrix The crafting matrix that was used for the recipe. */ public static void firePlayerCraftingEvent(Player player, ItemStack result, Container craftMatrix) { @@ -918,8 +918,8 @@ public static void firePlayerCraftingEvent(Player player, ItemStack result, Cont /** * Called by {@link net.minecraft.world.inventory.FurnaceResultSlot#checkTakeAchievements} after the player takes an item from the furnace output slot. * - * @param player The player who took the item. - * @param result The item that was smelted. + * @param player The player who took the item. + * @param result The item that was smelted. * @param amountRemoved The amount of items removed from the output slot. */ public static void firePlayerSmeltedEvent(Player player, ItemStack result, int amountRemoved) { @@ -929,11 +929,11 @@ public static void firePlayerSmeltedEvent(Player player, ItemStack result, int a /** * Called by {@link net.minecraft.world.inventory.SmithingMenu#onTake} after the player takes an item from the output slot in the smithing table. * - * @param player The player who took the item. + * @param player The player who took the item. * @param template The template item used in the smithing recipe. (ex. Smithing template) * @param mainItem The main item used in the smithing recipe. (ex. Diamond sword) * @param addition The addition item used in the smithing recipe. (ex. Netherite ingot) - * @param result The item that was smithed. + * @param result The item that was smithed. */ public static void firePlayerSmithingEvent(Player player, ItemStack template, ItemStack mainItem, ItemStack addition, ItemStack result) { NeoForge.EVENT_BUS.post(new PlayerEvent.ItemSmithingEvent(player, template, mainItem, addition, result)); From 612ef7c02a199e4f995ee9a6d595bc9964205cf2 Mon Sep 17 00:00:00 2001 From: Aram Date: Wed, 15 Jan 2025 13:22:15 +0100 Subject: [PATCH 8/8] Update PlayerEvent.java Removed all useless {} after Feedback from the discord! --- .../event/entity/player/PlayerEvent.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/event/entity/player/PlayerEvent.java b/src/main/java/net/neoforged/neoforge/event/entity/player/PlayerEvent.java index 39d2389995..00263171b7 100644 --- a/src/main/java/net/neoforged/neoforge/event/entity/player/PlayerEvent.java +++ b/src/main/java/net/neoforged/neoforge/event/entity/player/PlayerEvent.java @@ -410,14 +410,14 @@ public ItemCraftedEvent(Player player, ItemStack result, Container craftMatrix) } /** - * {@return the item that was crafted (ex. Diamond sword)} + * @return the item that was crafted (ex. Diamond sword) */ public ItemStack getCrafting() { return this.result; } /** - * {@return the crafting matrix used to craft the item (ex. 2x diamond, 1x stick)} + * @return the crafting matrix used to craft the item (ex. 2x diamond, 1x stick) */ public Container getInventory() { return this.craftMatrix; @@ -451,28 +451,28 @@ public ItemSmithingEvent(Player player, ItemStack template, ItemStack mainItem, } /** - * {@return the template item used for smithing (ex. Smithing template)} + * @return the template item used for smithing (ex. Smithing template) */ public ItemStack getTemplate() { return this.template; } /** - * {@return the main item used for smithing (ex. Diamond sword)} + * @return the main item used for smithing (ex. Diamond sword) */ public ItemStack getMainItem() { return this.mainItem; } /** - * {@return the item that is used as support to the item that is being smithed (ex. Netherite ingot} + * @return the item that is used as support to the item that is being smithed (ex. Netherite ingot) */ public ItemStack getAddition() { return this.addition; } /** - * {@return the result of the smithing in the final slot (ex. Netherite sword)} + * @return the result of the smithing in the final slot (ex. Netherite sword) */ public ItemStack getResult() { return this.result; @@ -502,14 +502,14 @@ public ItemSmeltedEvent(Player player, ItemStack result, int amountRemoved) { } /** - * {@return the item result after smelting (ex. Iron ingot)} + * @return the item result after smelting (ex. Iron ingot) */ public ItemStack getSmelting() { return this.result; } /** - * {@return the amount of items that were removed from the inventory (ex. 1)} + * @return the amount of items that were removed from the inventory (ex. 1) */ public int getAmountRemoved() { return this.amountRemoved;