Posted December 11, 20213 yr I'm trying to use the anvilUpdateEvent, but it's actually doesn't work, and idk why. Could someone help me? Here is my code: package com.thanatos0173.magicgems.init; import com.thanatos0173.magicgems.main; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.event.AnvilUpdateEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(modid = main.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class ModCrafts { @SubscribeEvent public static void AnvilCraft(AnvilUpdateEvent anvilUpdateEvent){ if(anvilUpdateEvent.getLeft().isItemEqual(new ItemStack(Items.ACACIA_BOAT,1)) && anvilUpdateEvent.getRight().isEmpty()) { anvilUpdateEvent.setOutput(new ItemStack(Items.ACACIA_FENCE,1)); } } }
December 11, 20213 yr Author I do what you say, but nothing changing... package com.thanatos0173.magicgems.init; import com.thanatos0173.magicgems.main; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.event.AnvilUpdateEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(modid = main.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.DEDICATED_SERVER) public class ModCrafts { @SubscribeEvent public static void AnvilCraft(AnvilUpdateEvent anvilUpdateEvent){ if(anvilUpdateEvent.getLeft().isItemEqual(new ItemStack(Items.ACACIA_BOAT,1)) && anvilUpdateEvent.getRight().isItemEqual(new ItemStack(Items.ACACIA_BOAT,1))) { anvilUpdateEvent.setOutput(new ItemStack(Items.ACACIA_FENCE,1)); } } }
December 11, 20213 yr Author Well, don't blame me but I actuelly follow an tuto on youtube... I remove this line right now
December 12, 20213 yr 11 hours ago, Thanatos_0173 said: but I can't take it out of the anvil... It's normal? what are you talking about?
December 17, 20213 yr Author OK, I found my problem, it was that I had'nt added the xp cost. But I have a new problem: I'm trying to put an enchant on my armor but it's didn't work... Can you help me? package com.thanatos0173.magicgems.init; import com.thanatos0173.magicgems.main; import net.minecraft.enchantment.Enchantments; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraftforge.event.AnvilUpdateEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(modid = main.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class ModCrafts { @SubscribeEvent public static void AnvilCraft(AnvilUpdateEvent anvilUpdateEvent) { ItemStack left = anvilUpdateEvent.getLeft(); if (left.isItemEqualIgnoreDurability(new ItemStack(Items.NETHERITE_SWORD, 1)) && anvilUpdateEvent.getRight().isItemEqual(new ItemStack(ModItems.poison_gem.get(), 1))) { anvilUpdateEvent.setOutput(anvilUpdateEvent.getLeft().copy().addEnchantment(Enchantments.FIRE_ASPECT,2)); anvilUpdateEvent.setCost(6); } } }
December 18, 20213 yr 13 hours ago, Thanatos_0173 said: if (left.isItemEqualIgnoreDurability(new ItemStack(Items.NETHERITE_SWORD, 1)) && anvilUpdateEvent.getRight().isItemEqual(new ItemStack(ModItems.poison_gem.get(), 1))) use debugger to check this condition, since you other code looks okay. I would also recommend you to check the Items and not the ItemStacks: if (left == Items.NETHERITE_SWORD) Edited December 18, 20213 yr by Luis_ST
December 18, 20213 yr Author I gonna do it, but without adding a enchant, it's work. The problem is that I have an error with the addEnchantement method
December 18, 20213 yr 1 hour ago, Thanatos_0173 said: The problem is that I have an error with the addEnchantement method define 'problem'
December 18, 20213 yr On 12/12/2021 at 12:25 AM, Thanatos_0173 said: Well, don't blame me but I actuelly follow an tuto on youtube... do you hava a link
December 22, 20213 yr Author Quote define 'problem' Here it is : 'setOutput(net.minecraft.item.ItemStack)' in 'net.minecraftforge.event.AnvilUpdateEvent' cannot be applied to '(void)'
December 22, 20213 yr Author I was knowing that someone will tell me that, and I know (nearly) what is the error. But, my question is : how can I add an enchantement on the sword if this method can't work ? Please answer me...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.