Jump to content

How to add a click event to a sign


PintsizedSix40

Recommended Posts

        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.

Link to comment
Share on other sites

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