1
0

Debuggers: Added the "/come" command to test mob pathfinding. (#3734)

This commit is contained in:
Mattes D 2017-05-27 19:22:09 +02:00 committed by GitHub
parent a0341d561a
commit 226272fc63
2 changed files with 56 additions and 0 deletions

View File

@ -1576,6 +1576,56 @@ end
function HandleComeCmd(a_Split, a_Player)
-- Find the first solid block under the player (in case they are flying):
local playerWorld = a_Player:GetWorld()
local playerPos = a_Player:GetPosition()
local toPos = Vector3i(playerPos)
if (toPos.y < 1) then
a_Player:SendMessageFailure("Cannot navigate to you, you're too low in the world")
return true
end
while not(cBlockInfo:IsSolid(playerWorld:GetBlock(toPos.x, toPos.y, toPos.z))) do
if (toPos.y <= 0) then
a_Player:SendMessageFailure("Cannot navigate to you, there's no solid block below you")
return true
end
toPos.y = toPos.y - 1
end
-- Find the mob to navigate:
local mob
local playerLook = a_Player:GetLookVector():NormalizeCopy()
local maxDot = 0
playerWorld:ForEachEntity(
function (a_CBEntity)
local dir = (a_CBEntity:GetPosition() - playerPos)
dir:Normalize()
local dot = dir:Dot(playerLook)
if (dot > maxDot) then
maxDot = dot
mob = a_CBEntity
end
end
)
if not(mob) then
a_Player:SendMessageFailure("Cannot navigate to you, there's no mob this way")
return true
end
mob:MoveToPosition(Vector3d(toPos))
a_Player:SendMessageSuccess((
string.format("Navigating the %s to position {%d, %d, %d}",
cMonster:MobTypeToString(mob:GetMobType()), toPos.x, toPos.y, toPos.z
)
))
return true
end
function HandleCompo(a_Split, a_Player)
-- Send one composite message to self:
local msg = cCompositeChat()

View File

@ -34,6 +34,12 @@ g_PluginInfo =
Handler = HandleClientVersionCmd,
HelpString = "Shows your client's protocol version",
},
["/come"] =
{
Permission = "debuggers.come",
Handler = HandleComeCmd,
HelpString = "Instruct the mob you're looking at to navigate to your position",
},
["/compo"] =
{
Permission = "debuggers",