Fix some logical bugs related to the Grindstone Event (#9089)

This commit is contained in:
KnightMiner authored and GitHub committed 2022-11-30 14:00:59 -08:00
1 parent b25a092cf1
commit 8358b800e9
5 files changed
+112 -12

No files matched your search

@@ -759,7 +759,11 @@ public class ForgeHooks
public static int onGrindstoneChange(@NotNull ItemStack top, @NotNull ItemStack bottom, Container outputSlot, int xp)
{
GrindstoneEvent.OnplaceItem e = new GrindstoneEvent.OnplaceItem(top, bottom, xp);
if (MinecraftForge.EVENT_BUS.post(e)) return e.getXp();
if (MinecraftForge.EVENT_BUS.post(e))
{
outputSlot.setItem(0, ItemStack.EMPTY);
return -1;
}
if (e.getOutput().isEmpty()) return Integer.MIN_VALUE;
outputSlot.setItem(0, e.getOutput());
@@ -41,10 +41,7 @@ public abstract class GrindstoneEvent extends Event
}
/**
* This is the experience amount determined by the event, not the vanilla behavior. <br>
* If you are the first receiver of this event, it is guaranteed to be -1. <br>
* The value must be set to a positive value to override vanilla behavior. <br>
* if the value is equal to -1, the vanilla behavior for calculating experience will run. <br>
* This is the experience amount determined by the event. It will be {@code -1} unless {@link #setXp(int)} is called. <br>
* @return The experience amount given to the player. <br>
*/
public int getXp()
@@ -64,11 +61,22 @@ public abstract class GrindstoneEvent extends Event
/**
* This event is {@link Cancelable} <br>
* {@link OnplaceItem} is fired when the inputs to a grindstone are changed. <br>
* It is called from {@link GrindstoneMenu#createResult()}. <br>
* If the event is canceled, vanilla behavior will not run, and the output will be set to {@link ItemStack#EMPTY}. <br>
* If the event is not canceled, but the output is not empty, it will set the output and not run vanilla behavior. <br>
* if the output is empty, and the event is not canceled, vanilla behavior will execute. <br>
* if the amount of experience is larger than or equal 0, the vanilla behavior for calculating experience will not run. <br>
*
* The following rules apply:
* <ul>
* <li>If the event is canceled, vanilla behavior will not run, and the output will be {@linkplain ItemStack#EMPTY empty}.</li>
* <li>If the event is not canceled</li>
* <ul>
* <li>and the output is empty, the output will be determined by vanilla.</li>
* <li>and the output is not empty, the output will be set, without running vanilla behavior.</li>
* </ul>
* <li>Vanilla XP calculation logic will be used unless all of the following criterias are met:</li>
* <ul>
* <li>the amount of experience is greater than or equal to {@code 0};</li>
* <li>the event is not {@linkplain #isCanceled() canceled};</li>
* <li>the {@linkplain #getOutput() output} is not empty.</li>
* </ul>
* </ul>
*/
@Cancelable
public static class OnplaceItem extends GrindstoneEvent