Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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}

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.

  • 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.

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.

  • Author

Thanks for your suggestions, I will spend some time trying to understand what you have written. Once again, thanks for your help.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.