killedzezima Posted August 31, 2015 Posted August 31, 2015 I have it all setup and building with no errors, however, in the game when I right click it does not do anything! Here is my code: import java.util.Random; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.eventhandler.*; import cpw.mods.fml.common.gameevent.InputEvent; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityTNTPrimed; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.potion.PotionEffect; import net.minecraft.util.WeightedRandomChestContent; import net.minecraft.world.World; import net.minecraftforge.common.ChestGenHooks; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerInteractEvent; public class itemJoint{ public itemJoint(){} static class smokeJoint extends Item{ public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player){ if(true){ if(player instanceof EntityPlayer)((EntityPlayer)player).inventory.consumeInventoryItem(CannaCraft.itemJoint); } return null; } } } Quote
JimiIT92 Posted August 31, 2015 Posted August 31, 2015 First at all, why you do this check? if(player instanceof EntityPlayer) Your variable player is yet an EntityPlayer, so it's useless. Second, after the if statement you do this return null; so whatever the condition is true or false it will ALWAYS return null (and so your item does nothing) So your function will looks like this: public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player){ player.inventory.consumeInventoryItem(CannaCraft.itemJoint); return item } Quote Don't blame me if i always ask for your help. I just want to learn to be better
killedzezima Posted August 31, 2015 Author Posted August 31, 2015 I have done what you said, still doesn't work. This is my code now: import java.util.Random; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.eventhandler.*; import cpw.mods.fml.common.gameevent.InputEvent; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityTNTPrimed; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.potion.PotionEffect; import net.minecraft.util.WeightedRandomChestContent; import net.minecraft.world.World; import net.minecraftforge.common.ChestGenHooks; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerInteractEvent; public class itemJoint{ public itemJoint(){} static class smokeJoint extends Item{ public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player){ player.inventory.consumeInventoryItem(CannaCraft.itemJoint); return item; } } } Quote
Failender Posted August 31, 2015 Posted August 31, 2015 what the hell is this code? public class itemJoint{ public itemJoint(){} static class smokeJoint extends Item{ the item u return is the item that got right clicked. so if u want to consume the inventory u just need to decrement the stack u get in the args, or return null if the stack is empty Quote
JimiIT92 Posted August 31, 2015 Posted August 31, 2015 try adding the @Override annotation above your function Also, no constructor? Quote Don't blame me if i always ask for your help. I just want to learn to be better
killedzezima Posted August 31, 2015 Author Posted August 31, 2015 import java.util.Random; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.eventhandler.*; import cpw.mods.fml.common.gameevent.InputEvent; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityTNTPrimed; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.potion.PotionEffect; import net.minecraft.util.WeightedRandomChestContent; import net.minecraft.world.World; import net.minecraftforge.common.ChestGenHooks; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerInteractEvent; public class itemJoint{ public itemJoint(){ class smokeJoint extends Item{ @Override public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player){ player.inventory.consumeInventoryItem(CannaCraft.itemJoint); return item; } } } } Still not working Quote
Failender Posted August 31, 2015 Posted August 31, 2015 Java experts at work... couldnt agree more :'D Quote
killedzezima Posted August 31, 2015 Author Posted August 31, 2015 Thank you guys for the tremendously useful input... Quote
Failender Posted August 31, 2015 Posted August 31, 2015 the item u return is the item that got right clicked. so if u want to consume the inventory u just need to decrement the stack u get in the args, or return null if the stack is empty i already told you. Quote
JimiIT92 Posted August 31, 2015 Posted August 31, 2015 Oh my god.... i've just noticed what is the OBVIOUS problem and i was like hitting the wall with my head. WHAT THE HELL IS THIS? public class itemJoint{ public itemJoint(){} static class smokeJoint extends Item{ ... } why don't you just do public class ItemJoint extends Item { .... //onItemRightClick method -> return --stack; .... } This will work for sure! PS: To who says "java experts at works", i didn't notice that before, he was asking for a method in particular so i don't look the entire class, i wanna say that "knowing how to mod minecraft" doesn't make you a java expert. Also myself is not an expert with a graduation in programming, so stop being "superior", everyone can make mistakes or oversights. Quote Don't blame me if i always ask for your help. I just want to learn to be better
Failender Posted August 31, 2015 Posted August 31, 2015 u need to know java to mod minecraft. there is no way around it. learn java. then come to minecraft. there is no other way and ppl need to understand that Quote
JimiIT92 Posted August 31, 2015 Posted August 31, 2015 yes, this is sure. But not spotting an error in the code, in a place not mentioned before, doesn't mean that you don't know java. As you can see in my post above, as soon as i noticed that i report that, because THAT is the error that clearly come by not knowing the language too much Quote Don't blame me if i always ask for your help. I just want to learn to be better
JimiIT92 Posted August 31, 2015 Posted August 31, 2015 Override allows you to redefine a method of the superclass. Because i didn't notice before the error in his definition of class i suggested him to try that (beacuse i was thinking he was extending another class, not the base Item class) Quote Don't blame me if i always ask for your help. I just want to learn to be better
Failender Posted August 31, 2015 Posted August 31, 2015 thats wrong. it tells the compiler to check if u are overriding correct. Quote
Failender Posted August 31, 2015 Posted August 31, 2015 But you should ALLWAYS use the @Override annotation, because its not harming and helps you prevent dumb errors, like spelling the method u want to override wrong Quote
JimiIT92 Posted August 31, 2015 Posted August 31, 2015 Well, it's not my fault if here in Italy the courses about programming sucks and don't goes into compiler stuff. I answered like this because that is what my teacher tells us in our course of Java programming. I learned a new thing, good to know! EDIT: Method overriding, in object oriented programming, is a language feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes. The implementation in the subclass overrides (replaces) the implementation in the superclass by providing a method that has same name, same parameters or signature, and same return type as the method in the parent class.[1] The version of a method that is executed will be determined by the object that is used to invoke it. If an object of a parent class is used to invoke the method, then the version in the parent class will be executed, but if an object of the subclass is used to invoke the method, then the version in the child class will be executed.[2] Some languages allow a programmer to prevent a method from being overridden. Source: Wikipedia Maybe in Minecraft code works like this but in "standard" Java i'm totally sure i'm not wrong Quote Don't blame me if i always ask for your help. I just want to learn to be better
killedzezima Posted August 31, 2015 Author Posted August 31, 2015 For anyone that is curious, this is actually how I fixed it: I had registered the item incorrectly: itemJoint = new itemJoint(itemJointID, null).setUnlocalizedName("Joint"); GameRegistry.registerItem(itemJoint, itemJoint.getUnlocalizedName().substring(5)); Quote
Failender Posted August 31, 2015 Posted August 31, 2015 so. why do you have an argument in the constructor of the item if u are passing null there anyway. Quote
killedzezima Posted August 31, 2015 Author Posted August 31, 2015 The null is setting the creative tab to null. I did this because I made the creative tab after registering the item, and it was easier to just set the creative tab in the itemJoint class. Quote
Failender Posted August 31, 2015 Posted August 31, 2015 how about removing the argument if u are not using it..? Quote
killedzezima Posted August 31, 2015 Author Posted August 31, 2015 Because it is required The constructor itemJoint(int) is undefined Quote
Failender Posted August 31, 2015 Posted August 31, 2015 seriously. learn java. google the problem. Quote
killedzezima Posted August 31, 2015 Author Posted August 31, 2015 There is no problem. This works exactly how I want it to. Quote
Draco18s Posted August 31, 2015 Posted August 31, 2015 Because it is required The constructor itemJoint(int) is undefined Make a new constructor that only takes one argument. Done. Magic! 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.
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.