Posted April 26, 20196 yr I have a problem with the code: I was trying to create a repair gem compatible with baubles, the problem is when I try to check the metadata of the item. The item is unlocalized with "repair_gem" and it has 4 different variants (weak, normal, advanced and extreme) which have less cooldown between 2 repair public boolean canRepair() { for (int i = 0; i < RepairGemTypes.values().length; i++) { // weak = 0; // normal = 1; // advanced = 2; // extreme = 3; ItemStack stack = new ItemStack(InitItems.REPAIR_GEM, 1, i); if (stack.getItemDamage() == 0) { if (r.tickCount >= 200) { r.tickCount = 0; r.shouldUpdate = false; return true; } } else if (stack.getItemDamage() == 1) { if (r.tickCount >= 120) { r.tickCount = 0; r.shouldUpdate = false; return true; } } else if (stack.getItemDamage() == 2) { if (r.tickCount >= 60) { r.tickCount = 0; r.shouldUpdate = false; return true; } } else if (stack.getItemDamage() == 3) { if (r.tickCount >= 20) { r.tickCount = 0; r.shouldUpdate = false; return true; } } } return false; } but it always prints the metadata 0 How can I fix this?
April 27, 20196 yr On 4/26/2019 at 11:44 PM, X_Khan_X said: How can I fix this? 1. Use Item#getMetadata Stack#getMetadata and pass in the ItemStack you want to check. 2. Your else ifs are rather messy and unnecessary. Use math to generalize the relationship between tiers and cool downs. 3. On 4/26/2019 at 11:44 PM, X_Khan_X said: I was trying to create a repair gem compatible with baubles If you are talking about this: https://minecraft.curseforge.com/projects/repair-gem, then I am making it baubles compatible (I almost forgot about that mod...). Edited April 27, 20196 yr by DavidM Some tips: Reveal hidden contents Modder Support: Reveal hidden contents 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Reveal hidden contents 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
April 27, 20196 yr Author On 4/27/2019 at 12:22 AM, DavidM said: 1. Use Item#getMetadata and pass in the ItemStack you want to check. Do you mean: ItemStack stack = new ItemStack(InitItems.REPAIR_GEM, 1, i); if (stack.getMetadata() == 0) { On 4/27/2019 at 12:22 AM, DavidM said: If you are talking about this: https://minecraft.curseforge.com/projects/repair-gem, then I am making it baubles compatible (I almost forgot I have that mod...). Oh... No no, I was trying to implement a repair gem (an original name lol) into my mod
April 27, 20196 yr Yes basically (I posted the wrong method). Don't obtain the ItemStack in such a way though; use the one that is passed in. Some tips: Reveal hidden contents Modder Support: Reveal hidden contents 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Reveal hidden contents 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
April 27, 20196 yr Author On 4/27/2019 at 12:43 AM, DavidM said: Yes basically (I posted the wrong method). Don't obtain the ItemStack in such a way though; use the one that is passed in. Can you help me to do it? I don't know how to do it
April 27, 20196 yr On 4/27/2019 at 12:58 AM, X_Khan_X said: Can you help me to do it? I don't know how to do it I'm not going to write your code for you, as you won't learn that way. If you want your repair gem to repair items while the gem is in the player's inventory, you will probably need to override Item#onUpdate, which is defined as: public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) See the ItemStack in the parameter? You should use that stack instead of creating a new one, so you should call stack.getMetaData() on that ItemStack. Some tips: Reveal hidden contents Modder Support: Reveal hidden contents 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Reveal hidden contents 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
April 27, 20196 yr Author On 4/27/2019 at 1:29 AM, DavidM said: I'm not going to write your code for you, as you won't learn that way. If you want your repair gem to repair items while the gem is in the player's inventory, you will probably need to override Item#onUpdate, which is defined as: public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) See the ItemStack in the parameter? You should use that stack instead of creating a new one, so you should call stack.getMetaData() on that ItemStack. I know but I have it in another class that manage my cooldowns and I cant add "ItemStack stack" to that method, that's why I need to get the itemstack and the item damage Edited April 27, 20196 yr by X_Khan_X
April 27, 20196 yr Why do you need another class for the cool down? Just store the cool down value in the NBTTag of the stack or something. Alternatively, you can get the meta from the stack and pass it to methods in the other class. Some tips: Reveal hidden contents Modder Support: Reveal hidden contents 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Reveal hidden contents 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
April 27, 20196 yr Author On 4/27/2019 at 2:48 AM, DavidM said: Alternatively, you can get the meta from the stack and pass it to methods in the other class. How can I do this?
April 27, 20196 yr Quote How can I do this? This should be basic Java. If you do not know how to pass objects as parameters, then I'm afraid you are not ready to make a mod. Learn Java first. Some tips: Reveal hidden contents Modder Support: Reveal hidden contents 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Reveal hidden contents 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
April 27, 20196 yr Author On 4/27/2019 at 3:34 AM, DavidM said: This should be basic Java. If you do not know how to pass objects as parameters, then I'm afraid you are not ready to make a mod. Learn Java first. LOL. I've solved, was really stupid and thanks for your help, you really helped me. For mods: This thread can be closed
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.