Make AnvilUpdateEvent fire even if the second input is empty, which means it fires even if only changing the item name. (#8905)

This commit is contained in:
Luis authored and GitHub committed 2022-08-09 12:48:46 -07:00
1 parent 7981093591
commit 130953e519
4 files changed
+44 -2

No files matched your search

@@ -24,9 +24,9 @@
this.f_39000_ = 0;
+ boolean flag = false;
+
+ if (!net.minecraftforge.common.ForgeHooks.onAnvilChange(this, itemstack, itemstack2, f_39768_, f_39001_, j, this.f_39771_)) return;
if (!itemstack2.m_41619_()) {
- boolean flag = itemstack2.m_150930_(Items.f_42690_) && !EnchantedBookItem.m_41163_(itemstack2).isEmpty();
+ if (!net.minecraftforge.common.ForgeHooks.onAnvilChange(this, itemstack, itemstack2, f_39768_, f_39001_, j, this.f_39771_)) return;
+ flag = itemstack2.m_41720_() == Items.f_42690_ && !EnchantedBookItem.m_41163_(itemstack2).isEmpty();
if (itemstack1.m_41763_() && itemstack1.m_41720_().m_6832_(itemstack, itemstack2)) {
int l2 = Math.min(itemstack1.m_41773_(), itemstack1.m_41776_() / 4);
@@ -14,7 +14,7 @@ import org.jetbrains.annotations.Nullable;
/**
*
* AnvilUpdateEvent is fired when the inputs (either input stack, or the name) to an anvil are changed. <br>
* AnvilUpdateEvent is fired whenever the input stacks (left or right) or the name in an anvil changed. <br>
* It is called from {@link AnvilMenu#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>
@@ -0,0 +1,40 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.debug.misc;
import org.slf4j.Logger;
import com.mojang.logging.LogUtils;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.AnvilUpdateEvent;
import net.minecraftforge.fml.common.Mod;
/**
* This class provides a way to test the AnvilUpdateEvent. <br>
* The event is now fired as described in the javadoc (of AnvilUpdateEvent). <br>
* "AnvilUpdateEvent is fired whenever the input stacks (left or right) or the name in an anvil changed."
*/
@Mod(AnvilUpdateEventTest.MOD_ID)
public class AnvilUpdateEventTest
{
private static final boolean ENABLED = false;
private static final Logger LOGGER = LogUtils.getLogger();
static final String MOD_ID = "anvil_update_event_fix";
public AnvilUpdateEventTest()
{
if (ENABLED)
{
MinecraftForge.EVENT_BUS.addListener(this::anvilUpdate);
}
}
private void anvilUpdate(AnvilUpdateEvent event)
{
LOGGER.info("Anvil input or name changed!");
}
}
+2
View File
@@ -242,6 +242,8 @@ modId="custom_transformtype_test"
modId="mega_model_test"
[[mods]]
modId="emissive_elements_test"
[[mods]]
modId="anvil_update_event_fix"