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

Hi All,

 

I'm having some trouble with an armor class.   When the player remove the boots, the change in step height does not go away.   Is there a different way I should be implementing this or am I missing something important?

 

Any guidance would help.

 

Thank you.

 

package com.kwpugh.gobber2.items.armor;

import com.kwpugh.gobber2.lists.ItemList;
import com.kwpugh.gobber2.util.SpecialAbilities;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.IArmorMaterial;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Effect;
import net.minecraft.world.World;

public class ItemCustomArmor extends ArmorItem
{
	public ItemCustomArmor(IArmorMaterial materialIn, EquipmentSlotType slots, Properties builder)
	{
		super(materialIn, slots, builder);
	}
	
	
	public void onArmorTick(final ItemStack stack, final World world, final PlayerEntity player)
	{
		if(player instanceof PlayerEntity)
		{	
			ItemStack head = player.getItemStackFromSlot(EquipmentSlotType.HEAD);
			ItemStack chest = player.getItemStackFromSlot(EquipmentSlotType.CHEST);
			ItemStack legs = player.getItemStackFromSlot(EquipmentSlotType.LEGS);
		    ItemStack feet = player.getItemStackFromSlot(EquipmentSlotType.FEET);	
		 
		    //Full Set

	    	if(head != null && head.getItem() == ItemList.gobber2_helmet && 
	    			chest != null && chest.getItem() == ItemList.gobber2_chestplate && 
	    			legs != null && legs.getItem() == ItemList.gobber2_leggings && 
	    			feet != null && feet.getItem() == ItemList.gobber2_boots)
	    	{
	    		((LivingEntity) player).removePotionEffect(Effect.get(19)); //Poison
	    	}	
		    
		    //Helmet
		    if(head.getItem() == ItemList.gobber2_helmet)
			{
				int newfoodlevel = 1;
				float newsatlevel = 0.0F;
				SpecialAbilities.giveRegenffect(world, player, stack, newfoodlevel, newsatlevel);			
			}
			else
			{
				
			}
		    
		    //Chestplate
		    if(chest.getItem() == ItemList.gobber2_chestplate)
			{
		 		if(player.isInWater())
		 		{
		 			SpecialAbilities.giveBreathing(world, player, chest);
		 		}
			}
		    
		    //Leggings
		    if(legs.getItem() == ItemList.gobber2_leggings)
			{
				player.fallDistance = 0.0F;
			}
			else
			{
				player.fallDistance = 1.0F;
			}	
		    
		    //Boots
		    if(feet.getItem() == ItemList.gobber2_boots)
			{
				player.stepHeight = 2.1F;
				
				if(!player.onGround)
				{
					//player.jumpMovementFactor += 0.09F;
				}
		    }
			else
		    {
				player.stepHeight = 0.0F;
		    }		 	
		}
	}
	
	@Override
	public boolean isBookEnchantable(ItemStack stack, ItemStack book)
	{
		return true;
	}

	@Override
	public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
	{
		return repair.getItem() == ItemList.gobber2_armor_repair;
	}
}

 

  • Author

ok, I should use inventroyTick to remove?

 

From an educational perspective, why do potion effects stop when the armor piece is removed, but no step height?

 

 

30 minutes ago, kwpugh said:

if(head != null ...

ItemStacks can't be null.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

So, this seems to work.   Is this a proper way to do it?

 

package com.kwpugh.gobber2.items.armor;

import com.kwpugh.gobber2.lists.ItemList;
import com.kwpugh.gobber2.util.SpecialAbilities;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.IArmorMaterial;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Effects;
import net.minecraft.world.World;
import net.minecraftforge.registries.ForgeRegistries;

public class ItemCustomArmor extends ArmorItem
{
	public ItemCustomArmor(IArmorMaterial materialIn, EquipmentSlotType slots, Properties builder)
	{
		super(materialIn, slots, builder);
	}	
	
	public void onArmorTick(final ItemStack stack, final World world, final PlayerEntity player)
	{
		if(player instanceof PlayerEntity)
		{	
		    
			ItemStack head = player.getItemStackFromSlot(EquipmentSlotType.HEAD);
			ItemStack chest = player.getItemStackFromSlot(EquipmentSlotType.CHEST);
			ItemStack legs = player.getItemStackFromSlot(EquipmentSlotType.LEGS);
		    ItemStack feet = player.getItemStackFromSlot(EquipmentSlotType.FEET);
		    
		    //Full Set
	    	if(head.getItem() == ItemList.gobber2_helmet && 
	    			chest.getItem() == ItemList.gobber2_chestplate && 
	    			legs.getItem() == ItemList.gobber2_leggings && 
	    			feet.getItem() == ItemList.gobber2_boots)
	    	{
	    		((LivingEntity) ForgeRegistries.POTIONS).removePotionEffect(Effects.POISON);
	    	}	
		    
		    //Helmet
		    if(head.getItem() == ItemList.gobber2_helmet)
			{
				int newfoodlevel = 1;
				float newsatlevel = 0.0F;
				SpecialAbilities.giveRegenffect(world, player, stack, newfoodlevel, newsatlevel);			
			}
		    
		    //Chestplate
		    if(chest.getItem() == ItemList.gobber2_chestplate)
			{
		 		if(player.isInWater())
		 		{
		 			SpecialAbilities.giveBreathing(world, player, chest);
		 		}
			}
		    
		    //Leggings
		    if(legs.getItem() == ItemList.gobber2_leggings)
			{
				player.fallDistance = 0.0F;
			}	
		    
		    //Boots
		    if(feet.getItem() == ItemList.gobber2_boots)
			{
				player.stepHeight = 2.1F;
				
				if(!player.onGround)
				{
					//player.jumpMovementFactor += 0.09F;
				}
		    }		 	
		}
	}
	
	public void inventoryTick(ItemStack stack, World world, PlayerEntity player, int itemSlot, boolean isSelected)
	{			
		ItemStack head = player.getItemStackFromSlot(EquipmentSlotType.HEAD);
		ItemStack chest = player.getItemStackFromSlot(EquipmentSlotType.CHEST);
		ItemStack legs = player.getItemStackFromSlot(EquipmentSlotType.LEGS);
	    ItemStack feet = player.getItemStackFromSlot(EquipmentSlotType.FEET);
	    
		if(!(legs.getItem() == ItemList.gobber2_leggings))
		{
			player.fallDistance = 1.0F;
		}	
		
		if(!(feet.getItem() == ItemList.gobber2_boots))
		{
			player.stepHeight = 0.0F;
	    }		
	}
	
	@Override
	public boolean isBookEnchantable(ItemStack stack, ItemStack book)
	{
		return true;
	}

	@Override
	public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
	{
		return repair.getItem() == ItemList.gobber2_armor_repair;
	}
}

 

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.