From fb05ea7cf740ecd59b24d4f7417ad44c30ba53d5 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 12 Apr 2020 13:34:24 +0200 Subject: Fixed entity teleport for just-spawned entities. Includes a test code in the Debuggers plugin - throwing a cake-as-fallingblock. --- Server/Plugins/Debuggers/Debuggers.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'Server/Plugins') diff --git a/Server/Plugins/Debuggers/Debuggers.lua b/Server/Plugins/Debuggers/Debuggers.lua index 4cf825f12..1505904a8 100644 --- a/Server/Plugins/Debuggers/Debuggers.lua +++ b/Server/Plugins/Debuggers/Debuggers.lua @@ -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; -- cgit v1.2.3