summaryrefslogtreecommitdiffstats
path: root/Server
diff options
context:
space:
mode:
authormBornand <63592189+mBornand@users.noreply.github.com>2020-05-08 11:04:07 +0200
committerGitHub <noreply@github.com>2020-05-08 11:04:07 +0200
commit1565d9b3ce8e74cdf8d2c95181f98531794f2c36 (patch)
tree09f6d9158cd2c583789d5c23bc174be115178972 /Server
parentFix SetBlockMeta call in observer handler (#4728) (diff)
downloadcuberite-1565d9b3ce8e74cdf8d2c95181f98531794f2c36.tar
cuberite-1565d9b3ce8e74cdf8d2c95181f98531794f2c36.tar.gz
cuberite-1565d9b3ce8e74cdf8d2c95181f98531794f2c36.tar.bz2
cuberite-1565d9b3ce8e74cdf8d2c95181f98531794f2c36.tar.lz
cuberite-1565d9b3ce8e74cdf8d2c95181f98531794f2c36.tar.xz
cuberite-1565d9b3ce8e74cdf8d2c95181f98531794f2c36.tar.zst
cuberite-1565d9b3ce8e74cdf8d2c95181f98531794f2c36.zip
Diffstat (limited to 'Server')
-rw-r--r--Server/Plugins/APIDump/Classes/Geometry.lua87
-rw-r--r--Server/Plugins/Debuggers/Debuggers.lua98
-rw-r--r--Server/Plugins/Debuggers/Info.lua7
3 files changed, 161 insertions, 31 deletions
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.</p>
+aborted and Trace() returns false.<br>
+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).</p>
<p>
<table><tr><th>Name</th><th>Parameters</th><th>Notes</th></tr>
-<tr><td>OnNextBlock</td><td>BlockX, BlockY, BlockZ, BlockType, BlockMeta, EntryFace</td>
+<tr><td>OnNextBlock</td><td>BlockPos, BlockType, BlockMeta, EntryFace</td>
<td>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.</td></tr>
-<tr><td>OnNextBlockNoData</td><td>BlockX, BlockY, BlockZ, EntryFace</td>
+<tr><td>OnNextBlockNoData</td><td>BlockPos, EntryFace</td>
<td>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.</td></tr>
-<tr><td>OnOutOfWorld</td><td>X, Y, Z</td>
+<tr><td>OnOutOfWorld</td><td>BlockPos</td>
<td>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.</td></tr>
-<tr><td>OnIntoWorld</td><td>X, Y, Z</td>
+<tr><td>OnIntoWorld</td><td>BlockPos</td>
<td>Called when the ray enters the world (Y-wise); the coords specify the exact entry point.</td></tr>
<tr><td>OnNoMoreHits</td><td>&nbsp;</td>
<td>Called when the path is sure not to hit any more blocks. This is the final callback, no more
@@ -1091,6 +1113,29 @@ aborted and Trace() returns false.</p>
]],
},
{
+ Header = "Deprecated Callbacks",
+ Contents = [[
+When using the deprecated number-based Trace function, Cuberite will instead assume the following signatures for the callbacks:</p>
+<p>
+<table><tr><th>Name</th><th>Parameters</th><th>Notes</th></tr>
+<tr><td>OnNextBlock</td><td>BlockX, BlockY, BlockZ, BlockType, BlockMeta, EntryFace</td>
+ <td>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.</td></tr>
+<tr><td>OnNextBlockNoData</td><td>BlockX, BlockY, BlockZ, EntryFace</td>
+ <td>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.</td></tr>
+<tr><td>OnOutOfWorld</td><td>X, Y, Z</td>
+ <td>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.</td></tr>
+<tr><td>OnIntoWorld</td><td>X, Y, Z</td>
+ <td>Called when the ray enters the world (Y-wise); the coords specify the exact entry point.</td></tr>
+</table>
+
+ ]],
+ },
+ {
Header = "Example",
Contents = [[
<p>The following example is taken from the Debuggers plugin. It is a command handler function for the
@@ -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
diff --git a/Server/Plugins/Debuggers/Debuggers.lua b/Server/Plugins/Debuggers/Debuggers.lua
index 5f04d12ee..585b2e1cc 100644
--- a/Server/Plugins/Debuggers/Debuggers.lua
+++ b/Server/Plugins/Debuggers/Debuggers.lua
@@ -1178,12 +1178,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
};
@@ -1195,7 +1195,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
@@ -2424,6 +2424,89 @@ function HandleConsoleTestTracer(a_Split, a_EntireCmd)
-- Define the callbacks to use for tracing:
local Callbacks =
{
+ OnNextBlock = function(a_BlockPos, a_BlockType, a_BlockMeta, a_EntryFace)
+ LOG(string.format("{%d, %d, %d}: %s", a_Block.x, a_Block.y, a_Block.z, ItemToString(cItem(a_BlockType, 1, a_BlockMeta))))
+ end,
+ OnNextBlockNoData = function(a_BlockPos, a_EntryFace)
+ LOG(string.format("{%d, %d, %d} (no data)", a_Block.x, a_Block.y, a_Block.z))
+ end,
+ OnNoChunk = function()
+ LOG("Chunk not loaded")
+ end,
+ OnNoMoreHits = function()
+ LOG("Trace finished")
+ end,
+ OnOutOfWorld = function()
+ LOG("Out of world")
+ end,
+ OnIntoWorld = function()
+ LOG("Into world")
+ end,
+ }
+
+ -- Approximate the chunks needed for the trace by iterating over all chunks and measuring their center's distance from the traced line
+ local Chunks = {}
+ local sx = math.floor(Coords[1] / 16)
+ local sz = math.floor(Coords[3] / 16)
+ local ex = math.floor(Coords[4] / 16)
+ local ez = math.floor(Coords[6] / 16)
+ local sgnx = (sx < ex) and 1 or -1
+ local sgnz = (sz < ez) and 1 or -1
+ for z = sz, ez, sgnz do
+ local ChunkCenterZ = z * 16 + 8
+ for x = sx, ex, sgnx do
+ local ChunkCenterX = x * 16 + 8
+ local sqdist = SqDistPtFromLine(ChunkCenterX, ChunkCenterZ, Coords[1], Coords[3], Coords[4], Coords[6])
+ if (sqdist <= 128) then
+ table.insert(Chunks, {x, z})
+ end
+ end
+ end
+
+ -- Load the chunks and do the trace once loaded:
+ local startPos = Vector3i(Coords[1], Coords[2], Coords[3])
+ local endPos = Vector3i(Coords[4], Coords[5], Coords[6])
+ World:ChunkStay(Chunks,
+ nil,
+ function()
+ cLineBlockTracer:Trace(World, Callbacks, startPos, endPos)
+ end
+ )
+ return true
+end
+
+
+
+
+
+function HandleConsoleTestTracerDeprecated(a_Split, a_EntireCmd)
+ -- Check required params:
+ if not(a_Split[7]) then
+ return true, "Usage: " .. a_Split[1] .. " <x1> <y1> <z1> <x2> <y2> <z2> [<WorldName>]"
+ end
+ local Coords = {}
+ for i = 1, 6 do
+ local v = tonumber(a_Split[i + 1])
+ if not(v) then
+ return true, "Parameter " .. (i + 1) .. " (" .. tostring(a_Split[i + 1]) .. ") not a number "
+ end
+ Coords[i] = v
+ end
+
+ -- Get the world in which to test:
+ local World
+ if (a_Split[8]) then
+ World = cRoot:GetWorld(a_Split[2])
+ else
+ World = cRoot:Get():GetDefaultWorld()
+ end
+ if not(World) then
+ return true, "No such world"
+ end
+
+ -- Define the callbacks to use for tracing:
+ local Callbacks =
+ {
OnNextBlock = function(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_EntryFace)
LOG(string.format("{%d, %d, %d}: %s", a_BlockX, a_BlockY, a_BlockZ, ItemToString(cItem(a_BlockType, 1, a_BlockMeta))))
end,
@@ -2716,9 +2799,9 @@ function HandleBlkCmd(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
- a_Player:SendMessage("Block at " .. a_BlockX .. ", " .. a_BlockY .. ", " .. a_BlockZ .. " is " .. a_BlockType .. ":" .. a_BlockMeta)
+ a_Player:SendMessage("Block at " .. a_BlockPos.x .. ", " .. a_BlockPos.y .. ", " .. a_BlockPos.z .. " is " .. a_BlockType .. ":" .. a_BlockMeta)
return true;
end
end
@@ -2730,7 +2813,7 @@ function HandleBlkCmd(a_Split, a_Player)
local End = EyePos + LookVector * 50;
- cLineBlockTracer.Trace(World, Callbacks, EyePos.x, EyePos.y, EyePos.z, End.x, End.y, End.z);
+ cLineBlockTracer.Trace(World, Callbacks, EyePos, End);
return true;
end
@@ -2760,6 +2843,3 @@ function HandleTeamsCmd(a_Split, a_Player)
end
-
-
-
diff --git a/Server/Plugins/Debuggers/Info.lua b/Server/Plugins/Debuggers/Info.lua
index 6fbd90e58..6e81296aa 100644
--- a/Server/Plugins/Debuggers/Info.lua
+++ b/Server/Plugins/Debuggers/Info.lua
@@ -392,6 +392,12 @@ g_PluginInfo =
HelpString = "Tests the cLineBlockTracer",
},
+ ["testtracerdeprecated"] =
+ {
+ Handler = HandleConsoleTestTracerDeprecated,
+ HelpString = "Tests the cLineBlockTracer's deprecated API",
+ },
+
["testurlclient"] =
{
Handler = HandleConsoleTestUrlClient,
@@ -414,4 +420,3 @@ g_PluginInfo =
-