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.

Thanatos_0173

Members
  • Joined

  • Last visited

  1. Sorry, I forgot to mention : I'm in 1.17.1
  2. Hello. I've created an enchantment, applied on Sword and wich give a poison effect to a entity when hitten with this sword. In the code everything seems ok, but when I'm trying to put the enchantment on the Netherite sword, it says: Netherite Sword cannot support that enchantment Can someone help me to fix that problem ? Here is the code: EnchantmentInit Class: public class EnchantementInit { public static final DeferredRegister<Enchantment> ENCHANTMENTS = DeferredRegister.create(ForgeRegistries.ENCHANTMENTS, main.MODID); public static final RegistryObject<Enchantment> POISON_ENCHANT = ENCHANTMENTS.register("poison_enchant",()-> new PoisonEnchant( Enchantment.Rarity.COMMON,EnchantmentCategory.WEAPON,EquipmentSlot.MAINHAND)); public static void register(IEventBus eventBus){ ENCHANTMENTS.register(eventBus); } } PoisonEnchant Class: public class PoisonEnchant extends Enchantment { public PoisonEnchant(Rarity rarity, EnchantmentCategory type, EquipmentSlot... slots) { super(rarity, type, slots); } @Override public int getMaxLevel() { return 6; } @Override public int getMinLevel() { return 1; } @Override public boolean canApplyAtEnchantingTable(ItemStack p_canApplyAtEnchantingTable_1_) { return false; } @Override public boolean isCurse() { return false; } @Override public boolean isAllowedOnBooks() { return false; } @Override public void doPostAttack(LivingEntity entity, Entity target, int level) { if(target instanceof LivingEntity){ ((LivingEntity) target).addEffect(new MobEffectInstance(MobEffects.POISON)); } } } Main Class: public main() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup); IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); EnchantementInit.register(bus); ModItems.ITEMS.register(bus); ModBlocks.BLOCKS.register(bus); } Thanks for helping
  3. Do I have a mean to know if an entity is hurt by a player? I have tried to use LivingHurtEvent, but I fail to do what I want. Can anyone help me?
  4. 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...
  5. Here it is : 'setOutput(net.minecraft.item.ItemStack)' in 'net.minecraftforge.event.AnvilUpdateEvent' cannot be applied to '(void)'
  6. I gonna do it, but without adding a enchant, it's work. The problem is that I have an error with the addEnchantement method
  7. 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); } } }
  8. It's work, but I can't take it out of the anvil... It's normal?
  9. Well, don't blame me but I actuelly follow an tuto on youtube... I remove this line right now
  10. 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. 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)); } } }

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.