Posted December 31, 20213 yr so i made this code for my item and i thought that it was going to print "Ruby that is the name i used in lang" but is not doing it, public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { CommandSource source = playerIn.getCommandSource(); BlockPos pos = playerIn.getPosition(); ItemStack stack = playerIn.getHeldItemMainhand(); float number = 10 ^ 5; if(!worldIn.isRemote) { String ene2 = stack.getItem().getDisplayName(stack); System.out.println(ene2); } return new ActionResult<ItemStack>(ActionResultType.SUCCESS,stack); } Is printing: item.totismod.rubyTranslatableComponent{key='item.totismod.ruby', args=[], siblings=[], style=Style{ color=null, bold=null, italic=null, underlined=null, strikethrough=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null, font=minecraft:default}} and i want to get the name of the current item tha is Ruby, even if i change its name with a anvil the name that the string changes to to the new name Edited December 31, 20213 yr by ElTotisPro50
January 1, 20223 yr Author so @diesieben07your idea didnt work, ITextComponent test = stack.getTextComponent(); String test2 = test.toString(); playerIn.sendStatusMessage(new StringTextComponent(test2),false); and @Luis_ST your idea didnt work either(if i use item.getDisplayName() i cant call .getName after it, i tried to use directly ItemStack but .getName doesnt exist in ItemStack) Item item = stack.getItem(); String test = item.getName().toString(); playerIn.sendStatusMessage(new StringTextComponent(test),false); String test = item.getDisplayName().getName();//cant call .getName
January 1, 20223 yr Author @diesieben07 and @Luis_ST, luis i want to make this ITextComponent test = stack.getTextComponent(); Commands command = new Commands(Commands.EnvironmentType.ALL); command.handleCommand(playerIn.getCommandSource(),"kill @e[name=" + test + "]"); diesieben, im not calling .toString or converting to string but is the same is printing item.ruby.item and things like hoverover,obfuscated etc (i know commands in code are not too good for this but i dont care what i care is how to get the name of my item(even if i change it with a anvil))
January 1, 20223 yr Author 1 hour ago, diesieben07 said: Yes... yes you are. You cannot do this with a command. You need to actually write code that will compare the text components. ok i used ITextComponent test = stack.getTextComponent(); and im using System.out.print, im not putting it in a command or in player.sendStatusMessage, and is still printing random things about the item TranslatableComponent{key='chat.square_brackets', args=[TextComponent{text='', siblings=[TranslatableComponent{key='item.totismod.ruby', args=[], siblings=[], style=Style{ color=null, bold=null, italic=null, underlined=null, strikethrough=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null, font=minecraft:default}}], style=Style{ color=null, bold=null, italic=null, underlined=null, strikethrough=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null, font=minecraft:default}}], siblings=[], style=Style{ color=white, bold=null, italic=null, underlined=null, strikethrough=null, obfuscated=null, clickEvent=null, hoverEvent=HoverEvent{action=<action show_item>, value='net.minecraft.util.text.event.HoverEvent$ItemHover@83a89074'}, insertion=null, font=minecraft:default}}
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.