Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PlayerEvent.ItemSmithingEvent #1693

Open
wants to merge 12 commits into
base: 1.21.x
Choose a base branch
from
10 changes: 10 additions & 0 deletions patches/net/minecraft/world/inventory/SmithingMenu.java.patch
Original file line number Diff line number Diff line change
@@ -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);
4 changes: 4 additions & 0 deletions src/main/java/net/neoforged/neoforge/event/EventHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,37 @@ public Container getInventory() {
}
}

public static class ItemSmithingEvent extends PlayerEvent {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see some documentation on this class. Most of our events should have a javadoc explaining:

  • What the event's purpose is (e.g. "An event for when a player smiths an item")
  • When the event is fired (e.g. "After awarding used recipes, but before resizing the stacks")
  • Where the event is fired (e.g. on the logical server, client, both)
  • Which bus it's fired on (e.g. the game bus)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, i will see to this asap

Copy link
Author

@MeAlam1 MeAlam1 Dec 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been completely resolved!

I will not close this conversation since i do not want to hide it before it has been confirmed by a Maintainer

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;
Expand Down