Jump to content

Recommended Posts

Posted (edited)
public class PeridotArmor extends ArmorItem{

	public PeridotArmor(IArmorMaterial materialIn, EquipmentSlotType slot, Properties builder) {
		super(materialIn, slot, builder);
	}

	@Override
	public void onArmorTick(ItemStack itemStack, World world, PlayerEntity player) {
		ItemStack boots = player.getItemStackFromSlot(EquipmentSlotType.FEET);
		if(boots.getItem() == ItemListOld.peridot_boots) {
			player.addPotionEffect(new EffectInstance(Effects.SPEED, 100, 4));
		} else player.removePotionEffect(Effects.SPEED);
			
		}
	}

I tried writing a class that allowed the player to move faster when wearing the armor. I'm getting no errors but when I apply the piece of armor in game it gives no effect. 

I've tried rewriting a few things and changing a few things here and there but nothing really seems to work

 

Edited by GAVINSIGHT
Posted
50 minutes ago, GAVINSIGHT said:

if(boots.getItem() == ItemListOld.peridot_boots) { player.addPotionEffect(new EffectInstance(Effects.SPEED, 100, 4)); } else player.removePotionEffect(Effects.SPEED); }

Are my eyes deceiving me or are you missing a bracket somewhere? Moreover, why are you removing the potion effect instead setting the effective time to something smaller. Third, potion effects should be added on the server side.

  • Like 1
Posted (edited)
Quote

Third, potion effects should be added on the server side

How would I go about adding potion effects on the server side?

 

Edited by GAVINSIGHT
Posted
public class PeridotArmor extends ArmorItem{

	public PeridotArmor(IArmorMaterial materialIn, EquipmentSlotType slot, Properties builder) {
		super(materialIn, slot, builder);
	}

	@Override
	public void onArmorTick(ItemStack itemStack, World world, PlayerEntity player) {
		ItemStack boots = player.getItemStackFromSlot(EquipmentSlotType.FEET);
		if(boots.getItem() == ItemListOld.peridot_boots) {
			if(!world.isRemote) {
				player.addPotionEffect(new EffectInstance(Effects.SPEED, 5, 4, false, false, true));
			} 
		} 
	}
}

I updated my code, but it seemed to unfortunately have no effect. 

I tried swapping the order of the IF statements and adding/removing the booleans

Posted
1 hour ago, DarKnighT_0_9 said:

I can help but notice you are calling "ItemListOld". Any chance you are comparing the wrong item?

No, I have ItemList which uses deferred registry and ItemListOld which doesn’t. I switched to deferred registries for a majority of my items but found it much easier to keep my armor and tools within ItemListOld.

Posted
8 hours ago, GAVINSIGHT said:

public class PeridotArmor extends ArmorItem{

	public PeridotArmor(IArmorMaterial materialIn, EquipmentSlotType slot, Properties builder) {
		super(materialIn, slot, builder);
	}

	@Override
	public void onArmorTick(ItemStack itemStack, World world, PlayerEntity player) {
		ItemStack boots = player.getItemStackFromSlot(EquipmentSlotType.FEET);
		if(boots.getItem() == ItemListOld.peridot_boots) {
			if(!world.isRemote) {
				player.addPotionEffect(new EffectInstance(Effects.SPEED, 5, 4, false, false, true));
			} 
		} 
	}
}

I updated my code, but it seemed to unfortunately have no effect. 

I tried swapping the order of the IF statements and adding/removing the booleans

Have you tried setting breakpoints? Just curious where in the code you make it to, and what is not doing as expected.

Posted
15 hours ago, ChampionAsh5357 said:

 

13 hours ago, DarKnighT_0_9 said:

I can help but notice you are calling "ItemListOld". Any chance you are comparing the wrong item?

 

6 hours ago, Ugdhar said:

Have you tried setting breakpoints? Just curious where in the code you make it to, and what is not doing as expected.

Issue solved! In the code I added "PeridotArmor peridotBoots = ItemListOld.peridot_boots" and in the ItemListOld class I referred to peridot_boots as "PeridotArmor" rather than "ArmorItem". Solved the issue! Thank you for your help.

 

Crazy, I dreamed the solution when I fell asleep last night. 

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.