Posted December 12, 201510 yr I am making an item that should give a specific item when blocks are clicked, however I cannot seem to get it to work. I havent actually ran the code to test it, only because I do not know the code. I am a beginner coder and so I would like some help. This is my code so far. package com.MoneyMod.items; 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 { public ItemStack onItemRightClick(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; } } {code}
December 12, 201510 yr Your code does nothing but set the ItemStack 's NBT tag to an empty compound tag. To do something when a player right clicks a block with your item, override Item#onItemUse . Item#onItemUseFirst should only be overridden if you need to do something before the block is activated and/or you need to prevent the block from being activated. To give the player an item, use InventoryPlayer#addItemStackToInventory (the player's inventory can be accessed from the EntityPlayer#inventory field). If this returns false the item wasn't added, so you should call EntityPlayer#dropPlayerItemWithRandomChoice to drop it on the ground. There are several examples of this in vanilla, like ItemEmptyMap#onItemRightClick and ItemGlassBottle#onItemRightClick . Use your IDE's Find Usages (IDEA)/Call Hierarchy (Eclipse) feature to find places where a method is called. You need a solid understanding of Java to write mods, there are lots of tutorials and other resources available online that you can use to learn Java. You also need to set up a ForgeGradle workspace by downloading the MDK (or src for 1.7.10 and earlier) and running gradlew setupDecompWorkspace . If you're using Eclipse, run gradlew eclipse to generate an Eclipse project. If you're using IDEA, open build.gradle and import the Gradle project then run the genIntellijRuns task and synchronise your project to generate the run configurations. LexManos has a workspace setup tutorial for Eclipse . There are probably various other tutorials available. 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.
December 12, 201510 yr Author Thanks for you reply! As I said in my post, I really dont know java that well and this is my first mod. I appreciate your help, but if you could edit my code with your suggestions, it would greatly benefit me. As a thank you (if you do so), I will credit you as a mod author and another Thanks on your account. Thanks again.
December 12, 201510 yr I won't write your code for you. Learn Java properly before trying to make a mod. thenewboston has a series of Java tutorials . Vswe has tutorials on Java and modding here. 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.
December 12, 201510 yr Author Thanks for your suggestions, I will spend some time trying to understand what you have written. Once again, thanks for your help.
December 13, 201510 yr The OP has a second thread here, which Jabelar and myself have responded to. 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.
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.