Posted August 27, 20178 yr 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.
August 27, 20178 yr Where do you run this code? What is it supposed to do? What does NBT have to do with commands or right-clicking blocks?
August 28, 20178 yr 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"}}
August 28, 20178 yr 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 August 28, 20178 yr 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.