caliban Posted April 14, 2017 Posted April 14, 2017 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 Quote
Draco18s Posted April 14, 2017 Posted April 14, 2017 In an event handler class. http://mcforge.readthedocs.io/en/latest/events/intro/ Quote 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.
caliban Posted April 14, 2017 Author Posted April 14, 2017 I'm a little new in the world of modder, can you be a little more specific or give me an example according to my case. (i tried different solution before asking you again and none worked) Quote
Draco18s Posted April 14, 2017 Posted April 14, 2017 public class MyForgeEventHandler { @SubscribeEvent public void pickupItem(EntityItemPickupEvent event) { System.out.println("Item picked up!"); } } ... MinecraftForge.EVENT_BUS.register(new MyForgeEventHandler()); Quote 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.
caliban Posted April 14, 2017 Author Posted April 14, 2017 I saw this example on the guide page but i did not understand how it works. That's why i said be more specific Thanks you for your help Quote
Choonster Posted April 14, 2017 Posted April 14, 2017 (edited) 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 April 14, 2017 by Choonster Quote 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.
Draco18s Posted April 14, 2017 Posted April 14, 2017 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. Quote 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.
caliban Posted April 14, 2017 Author Posted April 14, 2017 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 Quote
Choonster Posted April 14, 2017 Posted April 14, 2017 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. Quote 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.
caliban Posted April 14, 2017 Author Posted April 14, 2017 (edited) 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 April 14, 2017 by caliban Quote
Draco18s Posted April 14, 2017 Posted April 14, 2017 You need to create a new class for your armors, rather than using new Chestplate Quote 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.
caliban Posted April 14, 2017 Author Posted April 14, 2017 I already created a class for my Chestplate. For each part of the armour, there is a class named by the specific part. So i have 4 class (Boots, Chestplate, Helmet and Leggings) that i have created Quote
caliban Posted April 14, 2017 Author Posted April 14, 2017 That's what i done, I'm a little bit confused because when i'm testing my mod, this method is never called ..... so i supposed the @Override is not sufficient and i have to put my method in a specific place. Quote
caliban Posted April 14, 2017 Author Posted April 14, 2017 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 Quote
caliban Posted April 14, 2017 Author Posted April 14, 2017 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 Quote
Choonster Posted April 14, 2017 Posted April 14, 2017 (edited) 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 April 14, 2017 by Choonster Quote 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.
caliban Posted April 14, 2017 Author Posted April 14, 2017 I change it and now it works Thank you very much ! Quote
Recommended Posts
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.