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

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.

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.

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.