Jump to content

Recommended Posts

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

 

Posted

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

 

Posted

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

 

Posted (edited)
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

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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