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

        Hi, I'm trying to add a click event to a sign, so when i right click the sign, it will run a command. I have everything ready except the nbt data (nbttagcompound.setTag());) and I'm not sure what to put in it. Heres my nbt code:

NBTTagCompound nbttagcompound = new NBTTagCompound();

nbttagcompound.setTag());

itemstack.writeToNBT(nbttagcompound);

itemstack.setTagInfo("BlockEntityTag", nbttagcompound);

 

Thanks.

Where do you run this code? What is it supposed to do? What does NBT have to do with commands or right-clicking blocks?

  • Author

I'm trying to use a ClickEvent on the sign, so when a player riht clicks it runs a command.

Heres a command of what I'm trying to do: /give @p sign 1 0 {BlockEntityTag:{Text1:"{\"clickEvent\":{\"action\":\"run_command\",\"value\":\"say hi\"}}"},display:{Name:"Custom Sign"}}

You might want to check eventhandlers and in particular the PlayerInteractEvent event which returns the player, the world and the location of the block. 

 

From there you can get the block at X location (Which should be your sign) 

 

consider using something like 

BlockPos blockPos = new BlockPos(x,y,z);
String text = ((TileEntitySign)world.getTileEntity(blockPos)).signText[0].toString();

to get the text.  I believe that only returns the first line.  for next lines you want to increase the signText number.

I believe the text is able to be null, so make sure you check for that when you use java to decipher the lines. if your sign contains a specific text you should be able to decipher it and parse it to do whatever you want.

 

Since you have a world and an Entity you can either give something directly to the entity, or you can spawn an item right on your player by doing something like this: 

 

ItemStack stack = new ItemStack(your items);
World.spawnEntityInWorld(new EntityItem(world, player.posX, player.posY, player.posZ, stack));

 

that way the item will spawn on the player, it'll go in his intentory or remain on the ground if his inventory is full. remember to run that code on the server, not the client. Otherwise you'll end up with a 'ghost' item.

Edited by oldcheese

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.