Posted March 17, 201510 yr I started to create a custon enchantment,that can be put on any kind of helmets. I also created a server tick handler,but encountered an error: package net.Aethoscraft.mod.handler; import net.minecraft.client.Minecraft; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent; public class ServerTickHandler { private Minecraft mc; public ServerTickHandler(Minecraft mc){ this.mc = mc; } @SubscribeEvent public void onPlayer(PlayerTickEvent event){ if(event.player.getCurrentArmor(3)!= null){ ItemStack helmets = event.player.getCurrentArmor(3); if(helmets.getItem() == Items.diamond_helmet || helmets.getItem() == Items.golden_helmet ||helmets.getItem() == Items.iron_helmet ||helmets.getItem() == Items.leather_helmet || helmets.getItem() == Items.chainmail_helmet){ int j = EnchantmentHelper.getEnchantmentLevel(mainRegistry.SpeedBoost.effectId,helmets); if (j > 0){ event.player.addPotionEffect(new PotionEffect(Potion.moveSpeed.getId(), 60, j)); } } }} } Eclipse cant seem to find mainRegistry or anything related.In various guides I've watched this never error never popped up. If you'd write a solution,I'd be thankful!
March 17, 201510 yr Uhm... ServerTickHandler... private Minecraft mc; ? You know it's a client-only class, right? Also use proper code conventions, your classes should start with an uppercase letter. I also don't see you've imported your MainRegistry... Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! | mah twitter This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.
March 17, 201510 yr Fixed some of code for you: @SubscribeEvent public void onPlayer(PlayerTickEvent event) { if (event.phase == Phase.START && !event.player.worldObj.isRemote) { if (event.player.getCurrentArmor(3) != null) { ItemStack helmet = event.player.getCurrentArmor(3); if (helmet.getItem() == Items.diamond_helmet || helmet.getItem() == Items.golden_helmet || helmet.getItem() == Items.iron_helmet || helmet.getItem() == Items.leather_helmet || helmet.getItem() == Items.chainmail_helmet) { int j = EnchantmentHelper.getEnchantmentLevel(integerSomeId, helmet); // This will check if given itemstack (helmet) has an enchantment with given id. *** if (j > 0) { event.player.addPotionEffect(new PotionEffect(Potion.moveSpeed.getId(), 60, j)); // Adds speed potion effect to player. } } } } } Now you need to register the class contining it with FML. This event is launched twice per tick, you need to pick one phase. Also you want to add effect on server, vanilla will do rest for you. Finally - I have no idea why and what are you trying to do by using EnchantmentHelper, it's strictly reserved to read vanilla scroll enchantments. You need to either write your own NBT reader for ItemStack (that will find your buff-NBT) or use vanilla id's (which are defined there, check in IDE what methods are calling getEnchantmentLevel(...) and what are they putting there as an ID as an exerice. 1.7.10 is no longer supported by forge, you are on your own.
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.