Jump to content

Recommended Posts

Posted

Hi,

I started to code one week ago, so I'm a beginner and i want to create an item Dice for my server. We have a plugin wich can make dice rolls, so i want to link my item to a command (/dndroll 2d6)...  I tried to use the "onItemRightClick" in my ItemDice class but I'm a bit lost when i have to create the line to send the command into the chat of Minecraft.

 

I hope someone can help me, thanks.

Posted (edited)
package init;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.World;

public class Des extends Item
{
	
	public static ItemStack itemdes;
	
    public ItemStack useItemRightClick(World world, EntityPlayer player)
    {
    	
    	IChatComponent jet = new ChatComponentText("/dndroll 2d6");
    	player.addChatComponentMessage(jet);
    	
    	return player;
    }
}

Des = Dice in french ;)

itemdes = new Des().setUnlocalizedName("des").setCreativeTab(Heimnor.HeimnorCreativeTabs).setTextureName(Heimnor.MODID + ":des");

 

Actually i did this. Please tell me if i did something wrong, i have no error but when i do a right click with my item it did nothing.

Edited by Joe L Chasseu
Posted

There's no method in Item called useItemRightClick, so your method doesn't override anything and is never called. You shouldn't be storing an ItemStack in your Item class, the ItemStack will be provided to most Item methods you override.

 

Always annotate override methods with @Override so you get a compilation error if they don't actually override a super methods. You should use your IDE to auto-generate override methods with the correct signature and annotation.

 

In this case, you'll want to override Item#onItemRightClick and use ICommandManager#executeCommand to execute the command. Use MinecraftServer#getCommandManager to get the server's ICommandManager instance and use World#getMinecraftServer to get the MinecraftServer instance. You should only do all of this on the logical server (when World#isRemote is false).

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.

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.