Jump to content

(1.16.5 MPC Mappings)g et the name of my item


ElTotisPro50

Recommended Posts

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 by ElTotisPro50
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

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.