Thanks you, but I don't understand. I gave the item an NBT value of "tex" and executed it with a PlayerInteractEvent.When executing a register command, write a line from the arguments of the command to the ItemStack NBT. After get the command from the NBT for the item in the onItemRigthClick method and execute command.
else if(args[0].equals("register")) {
ItemStack stack = getCommandSenderAsPlayer(sender).getHeldItem();
NBTTagCompound nbt;
if(stack.hasTagCompound()) {
nbt = stack.getTagCompound();
}
else {
nbt = new NBTTagCompound();
}
if(nbt.hasKey("tex")){
nbt.setString("tex", nbt.getString("tex"));
}
else {
nbt.setString("tex", "tex");
}
stack.setTagCompound(nbt);
}
@SubscribeEvent
public void onRightClick(PlayerInteractEvent event) {
if(event.action == Action.RIGHT_CLICK_AIR) {
ItemStack stack = event.entityPlayer.getHeldItem();
if(stack.hasTagCompound() && stack.getTagCompound().hasKey("tex")) {
event.entityPlayer.addChatMessage(new ChatComponentText(stack.getDisplayName()));
}
}
}
ItemStack stack = getCommandSenderAsPlayer(sender).getHeldItem();
if(stack != null){
NBTTagCompound nbt = stack.getTagCompound();
if(!stack.hasTagCompound()){
stack.setTagCompound(nbt = new NBTTagCompound());
}
nbt.setString("command", args[1]); // args[1] - second command argument
}
ItemStack stack = event.entityPlayer.getHeldItem();
if(!event.entityPlayer.worldObj.isRemote && stack != null && stack.hasTagCompound() && stack.getTagCompound().hasKey("command")) {
MinecraftServer.getServer().getCommandManager().executeCommand(event.entityPlayer, stack.getTagCompound().getString("command"));
}
package NarutoKF.tut.items;
import NarutoKF.tut.NarutoMod;
import NarutoKF.tut.lib.Reference;
import net.minecraft.item.ItemSword;
public class ItemNose extends ItemSword {
public ItemNose(ToolMaterial mat){
super(mat);
this.setCreativeTab(NarutoMod.tutTab);
setFull3D();
setTextureName(Reference.MOD_ID + ":hacha2filos");
setUnlocalizedName(Reference.MOD_ID + ".hacha2filos");
}
}