Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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));
        }
    }
}

 

  • 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));
        }
    }
}

 

11 hours ago, Thanatos_0173 said:

but I can't take it out of the anvil... It's normal?

what are you talking about?

  • 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);
        }
    }
}

 

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 by Luis_ST

1 hour ago, Thanatos_0173 said:

The problem is that I have an error with the addEnchantement method

define 'problem'

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

  • Author
Quote

define 'problem'

Here it is :

'setOutput(net.minecraft.item.ItemStack)' in 'net.minecraftforge.event.AnvilUpdateEvent' cannot be applied to '(void)'

 

  • 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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.