Get Button from Block - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html) +--- Forum: Discussion (https://forum.cuberite.org/forum-5.html) +--- Thread: Get Button from Block (/thread-2277.html) |
Get Button from Block - greguso - 12-28-2015 Hi there I am writing an plugin and wanted to know if a selcted Block (x,y,z Coords) has one ore more buttons or a torch or ..... How can i get this information ? RE: Get Button from Block - NiLSPACE - 12-28-2015 Hello, and welcome to the forum. You mean if it has a block attached to it? You'll have to check the block next to it with cWorld:GetBlock() You'll have to check the meta to see if it's actually attached though. function IsAttached(a_World, a_BlockX, a_BlockY, a_BlockZ, a_RequiredMeta) local Block, Meta = a_World:GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ) if ((Block == E_BLOCK_TORCH) or (Block == E_BLOCK_STONE_BUTTON)) then -- return true if the meta is correct end return false end function OnPlayerLeftClick(a_Player, X, Y, Z) local World = a_Player:GetWorld() -- I used some random numbers as meta value if (not IsAttached(World, X + 1, Y, Z, 5) and not IsAttached(World, X - 1, Y, Z, 2) and not IsAttached(World, X, Y, Z + 1, 1) and not IsAttached(World, X, Y, Z - 1, 0) ) then -- Block is not attached, bail out. return false end -- Do whatever you want to do if there is a torch or button attached end RE: Get Button from Block - xoft - 12-28-2015 @NiLSPACE: Basically, yes, but a_RequiredMeta is a bad idea - what if there are blocks for which the meta differs from button's metas. A better approach would be a_BlockFace, specifying which blockface we're checking for attachment. Then each block type would check the meta for that specific blockface. |