1
0
Fork 0

Fixed entity teleport for just-spawned entities.

Includes a test code in the Debuggers plugin - throwing a cake-as-fallingblock.
This commit is contained in:
Mattes D 2020-04-12 13:34:24 +02:00
parent ef2d5027d3
commit fb05ea7cf7
2 changed files with 26 additions and 1 deletions

View File

@ -30,6 +30,7 @@ function Initialize(a_Plugin)
PM:AddHook(cPluginManager.HOOK_CHUNK_UNLOADING, OnChunkUnloading);
PM:AddHook(cPluginManager.HOOK_WORLD_STARTED, OnWorldStarted);
PM:AddHook(cPluginManager.HOOK_PROJECTILE_HIT_BLOCK, OnProjectileHitBlock);
PM:AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK, OnPlayerRightClick)
-- _X: Disabled WECUI manipulation:
-- PM:AddHook(cPluginManager.HOOK_PLUGIN_MESSAGE, OnPluginMessage);
@ -714,6 +715,26 @@ end
function OnPlayerRightClick(a_Player)
-- If the player is holding a cake item, make them throw a cake block, using a FallingBlock entity:
if (a_Player:GetInventory():GetEquippedItem().m_ItemType == E_ITEM_CAKE) then
local World = a_Player:GetWorld()
local Position = a_Player:GetPosition() + Vector3d(0, 1.5, 0)
local EntityID = World:SpawnFallingBlock(Vector3i(Position), E_BLOCK_CAKE, 0)
World:DoWithEntityByID(EntityID,
function (Entity)
Entity:TeleportToCoords(Position.x, Position.y, Position.z)
Entity:SetSpeed(a_Player:GetLookVector() * 30)
end
)
end
end
function OnPlayerRightClickingEntity(a_Player, a_Entity)
LOG("Player " .. a_Player:GetName() .. " right-clicking entity ID " .. a_Entity:GetUniqueID() .. ", a " .. a_Entity:GetClass());
return false;

View File

@ -1893,7 +1893,11 @@ void cEntity::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ)
if (!cRoot::Get()->GetPluginManager()->CallHookEntityTeleport(*this, m_LastPosition, Vector3d(a_PosX, a_PosY, a_PosZ)))
{
ResetPosition({a_PosX, a_PosY, a_PosZ});
m_World->BroadcastTeleportEntity(*this);
auto world = m_World;
if (world != nullptr) // The entity might not be in a world yet (just spawned, in cWorld::m_EntitiesToAdd)
{
world->BroadcastTeleportEntity(*this);
}
}
}