jameshyland Posted December 13, 2015 Share Posted December 13, 2015 This is my second time modding, and I am new to java so please cut me some slack. I am trying to create an item that give the player an item when a specific block is right clicked. The problem is, when I run the game, nothing happens, it doesnt even call onUpdate, onItemUse or onItemRightClick! Please help! Here is my main mod class package com.MoneyMod; import net.minecraft.item.Item.ToolMaterial; import net.minecraftforge.common.util.EnumHelper; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import com.MoneyMod.init.MoneyModBlocks; import com.MoneyMod.init.MoneyModItems; import com.MoneyMod.proxy.CommonProxy; @Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.VERSION) public class MoneyMod { @SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS) public static CommonProxy proxy; public static final MoneyModTab tabCreative = new MoneyModTab("tabCreative"); @EventHandler public void preInit(FMLPreInitializationEvent event) { MoneyModBlocks.init(); MoneyModBlocks.register(); MoneyModItems.init(); MoneyModItems.register(); //MoneyModItems.registerRenders(); } @EventHandler public void init (FMLInitializationEvent event) { { proxy.registerRenders(); } } @EventHandler public void postInit(FMLPostInitializationEvent event) { } Item declaration class: package com.MoneyMod.init; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.item.Item; import net.minecraft.item.Item.ToolMaterial; import net.minecraftforge.common.util.EnumHelper; import net.minecraftforge.fml.common.registry.GameRegistry; import com.MoneyMod.MoneyMod; import com.MoneyMod.Reference; public class MoneyModItems { public static Item itemPoundCoin; public static Item itemMoneyDust; public static Item itemTwoPoundCoin; public static Item itemFivePoundNote; public static Item itemTenPoundNote; public static Item itemTwentyPoundNote; public static Block blockFiverBlock; public static Item MoneyPickaxe; public static Item itemMoneyPutty; public static Item itemMoneyIngot; public static Item itemMoneyWand; public static final Item.ToolMaterial MoneyToolMaterial = EnumHelper.addToolMaterial("MoneyToolMaterial", 2, 1250 , 8.0F, 5.0F, 10); public static void init() { System.out.println("setting up item"); itemPoundCoin = new Item().setUnlocalizedName("itemPoundCoin").setCreativeTab(MoneyMod.tabCreative); itemMoneyIngot = new Item().setUnlocalizedName("ItemMoneyIngot").setCreativeTab(MoneyMod.tabCreative); itemTwentyPoundNote = new Item().setUnlocalizedName("ItemTwentyPoundNote").setCreativeTab(MoneyMod.tabCreative); itemMoneyPutty = new Item().setUnlocalizedName("ItemMoneyPutty").setCreativeTab(MoneyMod.tabCreative); itemTwoPoundCoin = new Item().setUnlocalizedName("ItemTwoPoundCoin").setCreativeTab(MoneyMod.tabCreative); itemFivePoundNote = new Item().setUnlocalizedName("ItemFivePoundNote").setCreativeTab(MoneyMod.tabCreative); itemTenPoundNote = new Item().setUnlocalizedName("ItemTenPoundNote").setCreativeTab(MoneyMod.tabCreative); itemMoneyDust = new Item().setUnlocalizedName("ItemMoneyDust").setCreativeTab(MoneyMod.tabCreative); itemMoneyWand = new Item().setUnlocalizedName("ItemMoneyWand").setCreativeTab(MoneyMod.tabCreative); } public static void register() { GameRegistry.registerItem(itemPoundCoin, itemPoundCoin.getUnlocalizedName().substring(5)); GameRegistry.registerItem(itemMoneyIngot, itemMoneyIngot.getUnlocalizedName().substring(5)); GameRegistry.registerItem(itemTwentyPoundNote, itemTwentyPoundNote.getUnlocalizedName().substring(5)); GameRegistry.registerItem(itemMoneyPutty, itemMoneyPutty.getUnlocalizedName().substring(5)); GameRegistry.registerItem(itemFivePoundNote, itemFivePoundNote.getUnlocalizedName().substring(5)); GameRegistry.registerItem(itemTenPoundNote, itemTenPoundNote.getUnlocalizedName().substring(5)); GameRegistry.registerItem(itemTwoPoundCoin, itemTwoPoundCoin.getUnlocalizedName().substring(5)); GameRegistry.registerItem(itemMoneyWand, itemMoneyWand.getUnlocalizedName().substring(5)); GameRegistry.registerItem(itemMoneyDust, itemMoneyDust.getUnlocalizedName().substring(5)); } public static void registerRenders() { registerRender(itemPoundCoin); registerRender(itemMoneyIngot); registerRender(itemTwentyPoundNote); registerRender(itemMoneyPutty); registerRender(itemFivePoundNote); registerRender(itemTwoPoundCoin); registerRender(itemMoneyDust); registerRender(itemTenPoundNote); registerRender(itemMoneyWand); } public static void registerRender(Item item) { Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item,0,new ModelResourceLocation(Reference.MOD_ID + ":"+ item.getUnlocalizedName().substring(5),"inventory")); } } and the item in question: package com.MoneyMod.items; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import com.MoneyMod.init.MoneyModItems; public class ItemMoneyWand extends Item { @Override public void onUpdate(ItemStack itemstack, World world, Entity entity, int metadata, boolean bool) { if (itemstack.getTagCompound() == null) { ItemStack s = new ItemStack(MoneyModItems.itemMoneyDust); itemstack.setTagCompound(new NBTTagCompound()); //or itemstack.setTagCompound(new NBTTagCompound()); } } public ItemStack onItemUse(ItemStack itemstack, World world, EntityPlayer player) { itemstack.getTagCompound().setInteger( "Coins", 100); ItemStack s = new ItemStack(MoneyModItems.itemMoneyDust); return itemstack; } public void onItemRightClick(ItemStack itemstack, World world, EntityPlayer playerIn, int metadata, boolean bool) { if (itemstack.getTagCompound() .getInteger("Coins") >= 100) { ItemStack s = new ItemStack(MoneyModItems.itemMoneyDust); playerIn.inventory.addItemStackToInventory(s); } } } //@Override /*public ItemStack onItemRightClick1(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) if(worldIn.isRemote); System.out.println("james smells"); ItemStack s = new ItemStack(MoneyModItems.itemMoneyDust); playerIn.inventory.addItemStackToInventory(s); return itemStackIn; } } */ Quote Link to comment Share on other sites More sharing options...
jabelar Posted December 13, 2015 Share Posted December 13, 2015 You can't just make up your own method and hope it gets called by Minecraft. You need to @Override an existing method. There is no such thing as public ItemStack onItemUse(ItemStack itemstack, World world, EntityPlayer player) method in the item class. There is a method public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) which you can override though. You must get in the habit of using the @Override annotation on every method that is supposed to replace a method from the super class. Then your IDE (like Eclipse) can warn you if you didn't define a method that exists. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/ Link to comment Share on other sites More sharing options...
Choonster Posted December 13, 2015 Share Posted December 13, 2015 You never create an instance of ItemMoneyWand , so its code is never used. Your onItemUse and onItemRightClick methods have the wrong signature, so they don't override the super methods with those names. Use the @Override annotation to ensure that your methods actually override the corresponding super methods - if it gives you an error, you haven't overridden a super method. Your IDE should have an option to automatically generate an override method, I suggest you use it. I wouldn't recommend overriding onUpdate unless you actually need to do something every tick. You should initialise the ItemStack 's NBT tag when it's actually needed - in onItemUse and onItemRightClick . Your onUpdate and onItemUse methods both create an ItemStack of MoneyModItems.itemMoneyDust , but neither of them use it. Your onItemRightClick method tries to add an ItemStack of MoneyModItems.itemMoneyDust to the player's inventory, but it doesn't check if the item was actually added; so it won't drop on the ground if the player's inventory was full like Buckets, Glass Bottles, etc. do. I told you how to do this in your previous thread. 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. Link to comment Share on other sites More sharing options...
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.