Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (โ‹ฎ) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • 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

ย 

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

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions โ†’ Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.