cLineBlockTracer
Index: Articles Classes Hooks Quick navigation: cArrowEntity cBeaconEntity cBlockArea cBlockEntity cBlockEntityWithItems cBlockInfo cBoundingBox cBrewingstandEntity cChatColor cChestEntity cChunkDesc cClientHandle cCommandBlockEntity cCompositeChat cCraftingGrid cCraftingRecipe cCryptoHash cCuboid cDispenserEntity cDropperEntity cDropSpenserEntity cEnchantments cEntity cEntityEffect cExpBottleEntity cFile cFireChargeEntity cFireworkEntity cFloater cFlowerPotEntity cFurnaceEntity cGhastFireballEntity cHangingEntity cHopperEntity cIniFile cInventory cItem cItemFrame cItemGrid cItems cJson cJukeboxEntity cLineBlockTracer cLuaWindow cMap cMapManager cMobHeadEntity cMobSpawnerEntity cMojangAPI cMonster cNetwork cNoteEntity cObjective cPainting cPawn cPickup cPlayer cPlugin cPluginLua cPluginManager cProjectileEntity cRankManager cRoot cScoreboard cServer cServerHandle cSignEntity cSplashPotionEntity cStatManager cStringCompression cTCPLink cTeam cThrownEggEntity cThrownEnderPearlEntity cThrownSnowballEntity cTNTEntity cTracer cUDPEndpoint cUrlClient cUrlParser cWebAdmin cWindow cWitherSkullEntity cWorld HTTPFormData HTTPRequest HTTPTemplateRequest ItemCategory lxp sqlite3 TakeDamageInfo tolua Vector3d Vector3f Vector3i Globals | ContentscLineBlockTracer classThis class provides an easy-to-use interface for tracing lines through individual blocks in the world. It will call the provided callbacks according to what events it encounters along the way. For the Lua API, there's only one static function exported that takes all the parameters necessary to do the tracing. The Callbacks parameter is a table containing all the functions that will be called upon the various events. See below for further information. Functions
CallbacksThe Callbacks in the Trace() function is a table that contains named functions. Cuberite will call individual functions from that table for the events that occur on the line - hitting a block, going out of valid world data etc. The following table lists all the available callbacks. If the callback function is not defined, Cuberite skips it. Each function can return a bool value, if it returns true, the tracing is aborted and Trace() returns false.
ExampleThe following example is taken from the Debuggers plugin. It is a command handler function for the "/spidey" command that creates a line of cobweb blocks from the player's eyes up to 50 blocks away in the direction they're looking, but only through the air. function HandleSpideyCmd(a_Split, a_Player) local World = a_Player:GetWorld(); local Callbacks = { OnNextBlock = function(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta) if (a_BlockType ~= E_BLOCK_AIR) then -- abort the trace return true; end World:SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_COBWEB, 0); end }; local EyePos = a_Player:GetEyePosition(); local LookVector = a_Player:GetLookVector(); LookVector:Normalize(); -- Make the vector 1 m long -- Start cca 2 blocks away from the eyes local Start = EyePos + LookVector + LookVector; local End = EyePos + LookVector * 50; cLineBlockTracer.Trace(World, Callbacks, Start.x, Start.y, Start.z, End.x, End.y, End.z); return true; end |