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 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;

}

 

 

}

 

 

}

 

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
} 

Don't blame me if i always ask for your help. I just want to learn to be better :)

  • Author

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;

}

 

 

}

 

 

}

 

 

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

try adding the

@Override

annotation above your function

 

Also, no constructor?

Don't blame me if i always ask for your help. I just want to learn to be better :)

  • Author

 

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  ???

 

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.

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.

Don't blame me if i always ask for your help. I just want to learn to be better :)

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

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

Don't blame me if i always ask for your help. I just want to learn to be better :)

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)

Don't blame me if i always ask for your help. I just want to learn to be better :)

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

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

Don't blame me if i always ask for your help. I just want to learn to be better :)

  • Author

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));

  • Author

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.

Because it is required

The constructor itemJoint(int) is undefined

 

Make a new constructor that only takes one argument.  Done.  Magic!

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.

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.