Jump to content

[1.10.2] Potion effect on complete set of armor is worn


caliban

Recommended Posts

Hello guys,

After watching differents tutorials, i decide to put an effect on an armor set but i don't understood where put the method onArmorTick().
I read several old post on the forum but i didn't learn more ....
So i hope you will be able what is missing in my code.

 

Thanks

 

Here is my method:
 

	public void onArmorTick(World world, EntityPlayer player, ItemStack item)
	{
		
		//Testing if player is wearing an armor
		
		if(player.inventory.armorItemInSlot(0) != null &&
			player.inventory.armorItemInSlot(1) != null && 
			player.inventory.armorItemInSlot(2) != null &&
			player.inventory.armorItemInSlot(3) != null)
		{
			
			//Testing if player is wearing the right armor
			
			if(player.inventory.armorItemInSlot(0).getItem() == volcanite_chestplate &&
				player.inventory.armorItemInSlot(1).getItem() == volcanite_leggings && 
				player.inventory.armorItemInSlot(2).getItem() == volcanite_boots &&
				player.inventory.armorItemInSlot(3).getItem() == volcanite_helmet)
			{
				//Application of effect
				
				player.addPotionEffect(new PotionEffect(Potion.getPotionById(12), 40));
			}
		}
	}

 

The rest if that interest you is here: https://github.com/TheCaliban/CaliArmor/tree/master/src/main/java/com/mod/CaliArmor

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

public class MyForgeEventHandler {
    @SubscribeEvent
    public void pickupItem(EntityItemPickupEvent event) {
        System.out.println("Item picked up!");
    }
}


...


MinecraftForge.EVENT_BUS.register(new MyForgeEventHandler());

 

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.

Link to comment
Share on other sites

onArmorTick is a method of Item, so you need to override it from a class that extends Item (or a subclass of it). It's only called on the Items that the player has equipped, so override it in your armour's Item class.

 

It's not an event, I think Draco is confused.

Edited by Choonster

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Just now, Choonster said:

It's not an event, I think Draco is confused.

Sorry, I haven't been all here.

You can do this with an event, too.

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.

Link to comment
Share on other sites

The tag @Override cannot be applicate to my method, eclipse tell me to remove it.
 

I don't want to abuse your help but if you can check my code, you could be able to help me better

 

My class ModArmors extend of ModItems

 

package com.mod.CaliArmor.init;

import java.util.ArrayList;
import static java.util.Arrays.asList;

import com.mod.CaliArmor.items.armor.*;
import com.mod.CaliArmor.utils.ArmorMaterials;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;

public class ModArmors extends ModItems
{
	//Armor
	public static ItemArmor stone_helmet, stone_chestplate, stone_leggings, stone_boots;
	public static ItemArmor kevlar_helmet, kevlar_chestplate, kevlar_leggings, kevlar_boots;
	public static ItemArmor volcanite_helmet, volcanite_chestplate, volcanite_leggings, volcanite_boots;
	
	private static Item[] armors;

	public ModArmors()
	{
		initArmor();
	}
	
	public static void initArmor()
	{
		stone_helmet = new Helmet("stone_helmet", ArmorMaterials.stoneMat, 2, EntityEquipmentSlot.HEAD);
		stone_chestplate = new Chestplate("stone_chestplate", ArmorMaterials.stoneMat, 2, EntityEquipmentSlot.CHEST);
		stone_leggings = new Leggings("stone_leggings", ArmorMaterials.stoneMat, 2, EntityEquipmentSlot.LEGS);
		stone_boots = new Boots("stone_boots", ArmorMaterials.stoneMat, 2, EntityEquipmentSlot.FEET);
		
		kevlar_helmet = new Helmet("kevlar_helmet", ArmorMaterials.kevlarMat, 2, EntityEquipmentSlot.HEAD);
		kevlar_chestplate = new Chestplate("kevlar_chestplate", ArmorMaterials.kevlarMat, 2, EntityEquipmentSlot.CHEST);
		kevlar_leggings = new Leggings("kevlar_leggings", ArmorMaterials.kevlarMat, 2, EntityEquipmentSlot.LEGS);
		kevlar_boots = new Boots("kevlar_boots", ArmorMaterials.kevlarMat, 2, EntityEquipmentSlot.FEET);
		
		volcanite_helmet = new Helmet("volcanite_helmet", ArmorMaterials.volcaniteMat, 2, EntityEquipmentSlot.HEAD);
		volcanite_chestplate = new Chestplate("volcanite_chestplate", ArmorMaterials.volcaniteMat, 2, EntityEquipmentSlot.CHEST);
		volcanite_leggings = new Leggings("volcanite_leggings", ArmorMaterials.volcaniteMat, 2, EntityEquipmentSlot.LEGS);
		volcanite_boots = new Boots("volcanite_boots", ArmorMaterials.volcaniteMat, 2, EntityEquipmentSlot.FEET);
		
		armors = new Item[]{stone_helmet, stone_chestplate, stone_leggings, stone_boots, kevlar_helmet, kevlar_chestplate, kevlar_leggings, kevlar_boots, volcanite_helmet, volcanite_chestplate, volcanite_leggings, volcanite_boots};

	}

	//List to initialize ItemArmor and not have to copy/paste
	@Override //Tag give me an error cause there is no onArmorTick() method up
	public void onArmorTick(World world, EntityPlayer player, ItemStack item)
	{
		
		//Testing if player is wearing an armor
		
		if(player.inventory.armorItemInSlot(0) != null && player.inventory.armorItemInSlot(1) != null && player.inventory.armorItemInSlot(2) != null && player.inventory.armorItemInSlot(3) != null)
		{
			
			//Testing if player is wearing the right armor
			
			if(player.inventory.armorItemInSlot(0).getItem() == ModArmors.volcanite_chestplate && player.inventory.armorItemInSlot(1).getItem() == ModArmors.volcanite_leggings && player.inventory.armorItemInSlot(2).getItem() == ModArmors.volcanite_boots && player.inventory.armorItemInSlot(3).getItem() == ModArmors.volcanite_helmet)
			{
				//Application of effect
				
				player.addPotionEffect(new PotionEffect(Potion.getPotionById(12), 40));
			}
		}
	}
	
	public static Item[] getArmors()
	{
		return armors;
	}
}

 

 

And my class ModItems:

 

package com.mod.CaliArmor.init;

import java.util.ArrayList;

import com.mod.CaliArmor.CaliArmor;
import com.mod.CaliArmor.items.armor.*;
import com.mod.CaliArmor.items.tools.*;
import com.mod.CaliArmor.utils.*;

import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ModItems
{
	/*
	
	public static Item stone_helmet, stone_chestplate, stone_leggings, stone_boots;
	public static Item kevlar_helmet, kevlar_chestplate, kevlar_leggings, kevlar_boots;
	public static Item volcanite_helmet, volcanite_chestplate, volcanite_leggings, volcanite_boots;
	
	*/
	
	public static Item volcanite_ingot;
	public static Item kevlar_plate;
	public static Item volcanite_pickaxe, volcanite_axe, volcanite_shovel, volcanite_hoe, volcanite_sword;
	
	private static ArrayList<Item> items;
	
	public static void initItems()
	{
		
		new ModArmors();
		
		//Initializing material
		
		volcanite_ingot = new Item().setRegistryName("volcanite_ingot").setUnlocalizedName("volcanite_ingot").setCreativeTab(CaliArmor.armorTab);
		kevlar_plate = new Item().setRegistryName("kevlar_plate").setUnlocalizedName("kevlar_plate").setCreativeTab(CaliArmor.armorTab);
		
		//Initializing tool
		
		volcanite_pickaxe = new Pickaxe("volcanite_pickaxe", ToolMaterials.volcaniteMat);
		volcanite_axe = new Axe("volcanite_axe", ToolMaterials.volcaniteMat);
		volcanite_shovel = new Shovel("volcanite_shovel", ToolMaterials.volcaniteMat);
		volcanite_sword = new Sword("volcanite_sword", ToolMaterials.volcaniteMat);
		volcanite_hoe = new Hoe("volcanite_hoe", ToolMaterials.volcaniteMat);
		
		//Add all item in array list to register easier
		
		items = new ArrayList<Item>();
		items.add(volcanite_ingot);
		items.add(kevlar_plate);
		items.add(volcanite_axe);
		items.add(volcanite_pickaxe);
		items.add(volcanite_shovel);
		items.add(volcanite_sword);
		items.add(volcanite_hoe);
		
		for (Item armor : ModArmors.getArmors())
		{
			items.add(armor);
		}
	}
	
	public static void registerItems()
	{
		for(Item item : items)
		{
			registerItem(item);
		}
	}
	
	@SideOnly(Side.CLIENT)
	public static void registerRenders()
	{
		for(Item item : items)
		{
			registerRender(item, 0);
		}
	}
	
	private static void registerItem(Item item)
	{
		GameRegistry.register(item);
	}
	
	private static void registerRender(Item item, int meta)
	{
		ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(new ResourceLocation(References.MODID, item.getUnlocalizedName().substring(5)), "inventory"));
	}
}

 

 

Thanks

Link to comment
Share on other sites

Your ModArmors class doesn't extend Item, so there's no onArmorTick method to override. You need to override it from the Item class used for your armour, not the class that registers the Items.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I did like you said, i extended my class ModArmors from Item, i have no error now but in game nothing happend when i'm wearing the armour.

Maybe i did some mistakes in my method to give the effect, can you check it and tell me if something seems strange to you

 

(i changed the id of slot by the new references and this the same)


Thank you 

Edited by caliban
Link to comment
Share on other sites

You need to create a new class for your armors, rather than using new Chestplate

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.

Link to comment
Share on other sites

My class modArmors where i declare all my armours:

 

package com.mod.CaliArmor.init;

import java.util.ArrayList;
import static java.util.Arrays.asList;

import com.mod.CaliArmor.items.armor.*;
import com.mod.CaliArmor.utils.ArmorMaterials;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;

public class ModArmors extends Item
{
	//Armor
	public static ItemArmor stone_helmet, stone_chestplate, stone_leggings, stone_boots;
	public static ItemArmor kevlar_helmet, kevlar_chestplate, kevlar_leggings, kevlar_boots;
	public static ItemArmor volcanite_helmet, volcanite_chestplate, volcanite_leggings, volcanite_boots;
	
	private static Item[] armors;

	public ModArmors()
	{
		initArmor();
	}
	
	public static void initArmor()
	{
		stone_helmet = new Helmet("stone_helmet", ArmorMaterials.stoneMat, 2, EntityEquipmentSlot.HEAD);
		stone_chestplate = new Chestplate("stone_chestplate", ArmorMaterials.stoneMat, 2, EntityEquipmentSlot.CHEST);
		stone_leggings = new Leggings("stone_leggings", ArmorMaterials.stoneMat, 2, EntityEquipmentSlot.LEGS);
		stone_boots = new Boots("stone_boots", ArmorMaterials.stoneMat, 2, EntityEquipmentSlot.FEET);
		
		kevlar_helmet = new Helmet("kevlar_helmet", ArmorMaterials.kevlarMat, 2, EntityEquipmentSlot.HEAD);
		kevlar_chestplate = new Chestplate("kevlar_chestplate", ArmorMaterials.kevlarMat, 2, EntityEquipmentSlot.CHEST);
		kevlar_leggings = new Leggings("kevlar_leggings", ArmorMaterials.kevlarMat, 2, EntityEquipmentSlot.LEGS);
		kevlar_boots = new Boots("kevlar_boots", ArmorMaterials.kevlarMat, 2, EntityEquipmentSlot.FEET);
		
		volcanite_helmet = new Helmet("volcanite_helmet", ArmorMaterials.volcaniteMat, 2, EntityEquipmentSlot.HEAD);
		volcanite_chestplate = new Chestplate("volcanite_chestplate", ArmorMaterials.volcaniteMat, 2, EntityEquipmentSlot.CHEST);
		volcanite_leggings = new Leggings("volcanite_leggings", ArmorMaterials.volcaniteMat, 2, EntityEquipmentSlot.LEGS);
		volcanite_boots = new Boots("volcanite_boots", ArmorMaterials.volcaniteMat, 2, EntityEquipmentSlot.FEET);
		
		armors = new Item[]{stone_helmet, stone_chestplate, stone_leggings, stone_boots, kevlar_helmet, kevlar_chestplate, kevlar_leggings, kevlar_boots, volcanite_helmet, volcanite_chestplate, volcanite_leggings, volcanite_boots};

	}

	//List to initialize ItemArmor and not have to copy/paste
	@Override
	public void onArmorTick(World world, EntityPlayer player, ItemStack item)
	{
		
		//Testing if player is wearing an armor
		
		if(player.inventory.armorItemInSlot(0) != null)
		{
			
			//Testing if player is wearing the right armor
			System.out.println("Test_1234828");
			player.addPotionEffect(new PotionEffect(Potion.getPotionById(12), 40));

			
			if(player.inventory.armorItemInSlot(0).getItem() == volcanite_helmet)
			{
				//Application of effect
				
				player.addPotionEffect(new PotionEffect(Potion.getPotionById(12), 40));
			}
		}
	}
	
	public static Item[] getArmors()
	{
		return armors;
	}
}

 

 

My class ModItems, initilizing item, textures anbd other items

 

package com.mod.CaliArmor.init;

import java.util.ArrayList;

import com.mod.CaliArmor.CaliArmor;
import com.mod.CaliArmor.items.armor.*;
import com.mod.CaliArmor.items.tools.*;
import com.mod.CaliArmor.utils.*;

import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ModItems
{
	/*
	
	public static Item stone_helmet, stone_chestplate, stone_leggings, stone_boots;
	public static Item kevlar_helmet, kevlar_chestplate, kevlar_leggings, kevlar_boots;
	public static Item volcanite_helmet, volcanite_chestplate, volcanite_leggings, volcanite_boots;
	
	*/
	
	public static Item volcanite_ingot;
	public static Item kevlar_plate;
	public static Item volcanite_pickaxe, volcanite_axe, volcanite_shovel, volcanite_hoe, volcanite_sword;
	
	private static ArrayList<Item> items;
	
	public static void initItems()
	{
		
		new ModArmors();
		
		//Initializing material
		
		volcanite_ingot = new Item().setRegistryName("volcanite_ingot").setUnlocalizedName("volcanite_ingot").setCreativeTab(CaliArmor.armorTab);
		kevlar_plate = new Item().setRegistryName("kevlar_plate").setUnlocalizedName("kevlar_plate").setCreativeTab(CaliArmor.armorTab);
		
		//Initializing tool
		
		volcanite_pickaxe = new Pickaxe("volcanite_pickaxe", ToolMaterials.volcaniteMat);
		volcanite_axe = new Axe("volcanite_axe", ToolMaterials.volcaniteMat);
		volcanite_shovel = new Shovel("volcanite_shovel", ToolMaterials.volcaniteMat);
		volcanite_sword = new Sword("volcanite_sword", ToolMaterials.volcaniteMat);
		volcanite_hoe = new Hoe("volcanite_hoe", ToolMaterials.volcaniteMat);
		
		//Add all item in array list to register easier
		
		items = new ArrayList<Item>();
		items.add(volcanite_ingot);
		items.add(kevlar_plate);
		items.add(volcanite_axe);
		items.add(volcanite_pickaxe);
		items.add(volcanite_shovel);
		items.add(volcanite_sword);
		items.add(volcanite_hoe);
		
		for (Item armor : ModArmors.getArmors())
		{
			items.add(armor);
		}
	}
	
	public static void registerItems()
	{
		for(Item item : items)
		{
			registerItem(item);
		}
	}
	
	@SideOnly(Side.CLIENT)
	public static void registerRenders()
	{
		for(Item item : items)
		{
			registerRender(item, 0);
		}
	}
	
	private static void registerItem(Item item)
	{
		GameRegistry.register(item);
	}
	
	private static void registerRender(Item item, int meta)
	{
		ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(new ResourceLocation(References.MODID, item.getUnlocalizedName().substring(5)), "inventory"));
	}
}

 

Thee rest of my code is here : https://github.com/TheCaliban/CaliArmor/tree/master/src/main/java/com/mod/CaliArmor

 

Thank

Link to comment
Share on other sites

8 hours ago, Choonster said:

Your ModArmors class doesn't extend Item, so there's no onArmorTick method to override. You need to override it from the Item class used for your armour, not the class that registers the Items.

I suppose he was right so i did like he said, i extended my class ModArmors from Item

Link to comment
Share on other sites

2 hours ago, caliban said:

I suppose he was right so i did like he said, i extended my class ModArmors from Item

 

The solution is to override the method in the class that already extends Item (i.e. Chestplate, Helmet, etc.), not to make your registration class extend Item.

Edited by Choonster

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.