Jump to content

1.7.10 onItemRightClick problems


killedzezima

Recommended Posts

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;

}

 

 

}

 

 

}

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;

}

 

 

}

 

 

}

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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