-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
base: 1.21.x
Are you sure you want to change the base?
Changes from all commits
7700460
a3ce9b6
9af14bc
65ae5a2
c1c50ee
7514bf3
12da915
73e72d3
2d01c58
386defe
8e3cee0
090aeb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -387,39 +387,130 @@ public String getPlayerUUID() { | |
} | ||
} | ||
|
||
/** | ||
* An event triggered when a player crafts an item. | ||
* <p> | ||
* This event is fired at the following stages: | ||
* <ul> | ||
* <li>After clicking the craft button in the crafting interface.</li> | ||
* <li>Before awarding the used recipe and resizing the stacks.</li> | ||
* </ul> | ||
* <p> | ||
* The event is fired via {@link EventHooks#firePlayerCraftingEvent(Player, ItemStack, Container)}<br> | ||
* 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. | ||
* <p> | ||
* This event is fired at the following stages: | ||
* <ul> | ||
* <li>After awarding the used recipe.</li> | ||
* <li>Before resizing the stacks.</li> | ||
* </ul> | ||
* <p> | ||
* The event is fired via {@link EventHooks#firePlayerSmithingEvent(Player, ItemStack, ItemStack, ItemStack, ItemStack)} <br> | ||
* and is posted to the {@link NeoForge#EVENT_BUS}. | ||
*/ | ||
public static class ItemSmithingEvent extends PlayerEvent { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understood, i will see to this asap There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
||
/** | ||
* {@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. | ||
* <p> | ||
* This event is fired after: | ||
* <ul> | ||
* <li>Awarding the used recipe.</li> | ||
* <li>Resizing the item stacks.</li> | ||
* </ul> | ||
* <p> | ||
* The event is fired via {@link EventHooks#firePlayerSmeltedEvent(Player, ItemStack, int)} <br> | ||
* 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; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This Method name, and the same method from the
ItemSmeltedEvent
are misleading.I recommend renaming them to
getResult
orgetCrafted
(for theItemSmeltedEvent
,getSmelted
) since they return the result, and not the matrix/item that is being smelted.Since this is a Breaking Change i was requested in the Discord to make a comment about it