diff --git a/patches/minecraft/net/minecraft/inventory/ContainerRepair.java.patch b/patches/minecraft/net/minecraft/inventory/ContainerRepair.java.patch index c2eb66a2c3..9616e4cdb3 100644 --- a/patches/minecraft/net/minecraft/inventory/ContainerRepair.java.patch +++ b/patches/minecraft/net/minecraft/inventory/ContainerRepair.java.patch @@ -1,6 +1,22 @@ --- ../src-base/minecraft/net/minecraft/inventory/ContainerRepair.java +++ ../src-work/minecraft/net/minecraft/inventory/ContainerRepair.java -@@ -373,6 +373,8 @@ +@@ -12,6 +12,7 @@ + import net.minecraft.init.Items; + import net.minecraft.item.ItemStack; + import net.minecraft.world.World; ++import net.minecraftforge.common.ForgeHooks; + import org.apache.commons.lang3.StringUtils; + import org.apache.logging.log4j.LogManager; + import org.apache.logging.log4j.Logger; +@@ -170,6 +171,7 @@ + + if (itemstack2 != null) + { ++ if (!ForgeHooks.onAnvilChange(this, itemstack, itemstack2, field_82852_f, field_82857_m, k2)) return; + flag = itemstack2.func_77973_b() == Items.field_151134_bR && Items.field_151134_bR.func_92110_g(itemstack2).func_74745_c() > 0; + + if (itemstack1.func_77984_f() && itemstack1.func_77973_b().func_82789_a(itemstack, itemstack2)) +@@ -373,6 +375,8 @@ k2 = Math.max(1, k2 / 2); } diff --git a/src/main/java/net/minecraftforge/common/ForgeHooks.java b/src/main/java/net/minecraftforge/common/ForgeHooks.java index 1ad659ef6b..3ebb8f7ad6 100644 --- a/src/main/java/net/minecraftforge/common/ForgeHooks.java +++ b/src/main/java/net/minecraftforge/common/ForgeHooks.java @@ -3,7 +3,6 @@ package net.minecraftforge.common; import java.util.ArrayList; import java.util.List; import java.util.Set; - import cpw.mods.fml.common.eventhandler.Event; import cpw.mods.fml.relauncher.ReflectionHelper; import net.minecraft.block.Block; @@ -14,6 +13,8 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.inventory.Container; +import net.minecraft.inventory.ContainerRepair; +import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemAxe; import net.minecraft.item.ItemPickaxe; @@ -33,6 +34,7 @@ import net.minecraft.util.MovingObjectPosition.MovingObjectType; import net.minecraft.util.WeightedRandom; import net.minecraft.world.World; import net.minecraft.world.WorldSettings.GameType; +import net.minecraftforge.event.AnvilUpdateEvent; import net.minecraftforge.event.ServerChatEvent; import net.minecraftforge.event.entity.item.ItemTossEvent; import net.minecraftforge.event.entity.living.LivingAttackEvent; @@ -423,4 +425,15 @@ public class ForgeHooks } return event; } + + public static boolean onAnvilChange(ContainerRepair container, ItemStack left, ItemStack right, IInventory outputSlot, String name, int baseCost) + { + AnvilUpdateEvent e = new AnvilUpdateEvent(left, right, name, baseCost); + if (MinecraftForge.EVENT_BUS.post(e)) return false; + if (e.output == null) return true; + + outputSlot.setInventorySlotContents(0, e.output); + container.maximumCost = e.cost; + return false; + } } diff --git a/src/main/java/net/minecraftforge/event/AnvilUpdateEvent.java b/src/main/java/net/minecraftforge/event/AnvilUpdateEvent.java new file mode 100644 index 0000000000..7a80daa861 --- /dev/null +++ b/src/main/java/net/minecraftforge/event/AnvilUpdateEvent.java @@ -0,0 +1,30 @@ +package net.minecraftforge.event; + +import cpw.mods.fml.common.eventhandler.Cancelable; +import cpw.mods.fml.common.eventhandler.Event; +import net.minecraft.item.ItemStack; + +/** + * + * AnvilUpdateEvent is fired when a player places items in both the left and right slots of a anvil. + * If the event is canceled, vanilla behavior will not run, and the output will be set to null. + * If the event is not canceled, but the output is not null, it will set the output and not run vanilla behavior. + * if the output is null, and the event is not canceled, vanilla behavior will execute. + */ +@Cancelable +public class AnvilUpdateEvent extends Event +{ + public final ItemStack left; // The left side of the input + public final ItemStack right; // The right side of the input + public final String name; // The name to set the item, if the user specified one. + public ItemStack output; // Set this to set the output stack + public int cost; // The base cost, set this to change it if output != null + + public AnvilUpdateEvent(ItemStack left, ItemStack right, String name, int cost) + { + this.left = left; + this.right = right; + this.name = name; + this.cost = cost; + } +}