From 1565d9b3ce8e74cdf8d2c95181f98531794f2c36 Mon Sep 17 00:00:00 2001 From: mBornand <63592189+mBornand@users.noreply.github.com> Date: Fri, 8 May 2020 11:04:07 +0200 Subject: Use Vector3 for cLineBlockTracer and cBlockTracer (#4715) * cLineBlockTracer uses Vector --- Server/Plugins/APIDump/Classes/Geometry.lua | 87 ++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 21 deletions(-) (limited to 'Server/Plugins/APIDump/Classes/Geometry.lua') diff --git a/Server/Plugins/APIDump/Classes/Geometry.lua b/Server/Plugins/APIDump/Classes/Geometry.lua index 475cab2f2..9d289632c 100644 --- a/Server/Plugins/APIDump/Classes/Geometry.lua +++ b/Server/Plugins/APIDump/Classes/Geometry.lua @@ -1011,25 +1011,44 @@ the most popular tracing reasons - line of sight and solid hits. }, -- LineOfSightTrace Trace = { - IsStatic = true, - Params = { - { Name = "World", Type = "cWorld" }, - { Name = "Callbacks", Type = "table" }, - { Name = "StartX", Type = "number" }, - { Name = "StartY", Type = "number" }, - { Name = "StartZ", Type = "number" }, - { Name = "EndX", Type = "number" }, - { Name = "EndY", Type = "number" }, - { Name = "EndZ", Type = "number" }, + IsStatic = true, + Params = + { + { Name = "World", Type = "cWorld" }, + { Name = "Callbacks", Type = "table" }, + { Name = "StartX", Type = "number" }, + { Name = "StartY", Type = "number" }, + { Name = "StartZ", Type = "number" }, + { Name = "EndX", Type = "number" }, + { Name = "EndY", Type = "number" }, + { Name = "EndZ", Type = "number" }, + }, + Returns = + { + { + Type = "boolean", + }, + }, + Notes = "(OBSOLETE, use the Vector3-based overload instead) Performs the trace on the specified line. Returns true if the entire trace was processed (no callback returned true)", }, - Returns = { + IsStatic = true, + Params = { - Type = "boolean", + { Name = "World", Type = "cWorld" }, + { Name = "Callbacks", Type = "table" }, + { Name = "Start", Type = "Vector3d" }, + { Name = "End", Type = "Vector3d" }, }, + Returns = + { + { + Type = "boolean", + }, + }, + Notes = "Performs the trace on the specified line. Returns true if the entire trace was processed (no callback returned true)", }, - Notes = "Performs the trace on the specified line. Returns true if the entire trace was processed (no callback returned true)", }, }, Constants = @@ -1064,21 +1083,24 @@ The Callbacks in the Trace() function is a table that contains named functions. 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.

+aborted and Trace() returns false.
+Note: The folowing can only be used when using the Vector3-based Trace() function. When using +the number-based overload, the callbacks receive number-based coordinates (see Deprecated +Callbacks below).

- + - + - + - +
NameParametersNotes
OnNextBlockBlockX, BlockY, BlockZ, BlockType, BlockMeta, EntryFace
OnNextBlockBlockPos, BlockType, BlockMeta, EntryFace Called when the ray hits a new valid block. The block type and meta is given. EntryFace is one of the BLOCK_FACE_ constants indicating which "side" of the block got hit by the ray.
OnNextBlockNoDataBlockX, BlockY, BlockZ, EntryFace
OnNextBlockNoDataBlockPos, EntryFace Called when the ray hits a new block, but the block is in an unloaded chunk - no valid data is available. Only the coords and the entry face are given.
OnOutOfWorldX, Y, Z
OnOutOfWorldBlockPos Called when the ray goes outside of the world (Y-wise); the coords specify the exact exit point. Note that for other paths than lines (considered for future implementations) the path may leave the world and go back in again later, in such a case this callback is followed by OnIntoWorld() and further OnNextBlock() calls.
OnIntoWorldX, Y, Z
OnIntoWorldBlockPos Called when the ray enters the world (Y-wise); the coords specify the exact entry point.
OnNoMoreHits  Called when the path is sure not to hit any more blocks. This is the final callback, no more @@ -1090,6 +1112,29 @@ aborted and Trace() returns false.

]], }, + { + Header = "Deprecated Callbacks", + Contents = [[ +When using the deprecated number-based Trace function, Cuberite will instead assume the following signatures for the callbacks:

+

+ + + + + + + + + +
NameParametersNotes
OnNextBlockBlockX, BlockY, BlockZ, BlockType, BlockMeta, EntryFaceCalled when the ray hits a new valid block. The block type and meta is given. EntryFace is one of the + BLOCK_FACE_ constants indicating which "side" of the block got hit by the ray.
OnNextBlockNoDataBlockX, BlockY, BlockZ, EntryFaceCalled when the ray hits a new block, but the block is in an unloaded chunk - no valid data is + available. Only the coords and the entry face are given.
OnOutOfWorldX, Y, ZCalled when the ray goes outside of the world (Y-wise); the coords specify the exact exit point. Note + that for other paths than lines (considered for future implementations) the path may leave the world and + go back in again later, in such a case this callback is followed by OnIntoWorld() and further + OnNextBlock() calls.
OnIntoWorldX, Y, ZCalled when the ray enters the world (Y-wise); the coords specify the exact entry point.
+ + ]], + }, { Header = "Example", Contents = [[ @@ -1101,12 +1146,12 @@ 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) + OnNextBlock = function(a_BlockPos, 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); + World:SetBlock(a_BlockPos, E_BLOCK_COBWEB, 0); end }; @@ -1118,7 +1163,7 @@ function HandleSpideyCmd(a_Split, a_Player) 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); + cLineBlockTracer.Trace(World, Callbacks, Start, End); return true; end -- cgit v1.2.3