diff --git a/doc/index.html b/doc/index.html index 2ab040b..95f3b72 100644 --- a/doc/index.html +++ b/doc/index.html @@ -43,6 +43,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • @@ -129,6 +130,10 @@ inventoryutil A util for working with inventories. + + entityutil + Provides various utility methods for manipulating entities. + scheduler The Scheduler allows you to easily schedule functions for execution. diff --git a/doc/modules/arraymanipulator.html b/doc/modules/arraymanipulator.html index a62bc38..facda54 100644 --- a/doc/modules/arraymanipulator.html +++ b/doc/modules/arraymanipulator.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/arrayutil.html b/doc/modules/arrayutil.html index e2d1349..bbc14a0 100644 --- a/doc/modules/arrayutil.html +++ b/doc/modules/arrayutil.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/blockedcache.html b/doc/modules/blockedcache.html index 3232892..a91f55c 100644 --- a/doc/modules/blockedcache.html +++ b/doc/modules/blockedcache.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/blockutil.html b/doc/modules/blockutil.html index b298cc1..7cc4430 100644 --- a/doc/modules/blockutil.html +++ b/doc/modules/blockutil.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/color.html b/doc/modules/color.html index 8c50061..3e08d58 100644 --- a/doc/modules/color.html +++ b/doc/modules/color.html @@ -51,6 +51,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/constants.html b/doc/modules/constants.html index 7d4d6a5..b41b872 100644 --- a/doc/modules/constants.html +++ b/doc/modules/constants.html @@ -51,6 +51,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/directmapmanipulator.html b/doc/modules/directmapmanipulator.html index 81916b1..3366bfe 100644 --- a/doc/modules/directmapmanipulator.html +++ b/doc/modules/directmapmanipulator.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/entityutil.html b/doc/modules/entityutil.html new file mode 100644 index 0000000..12bf7ac --- /dev/null +++ b/doc/modules/entityutil.html @@ -0,0 +1,148 @@ + + + + + utils + + + + +
    + +
    + +
    +
    +
    + + +
    + + + + + + +
    + +

    Module entityutil

    +

    Provides various utility methods for manipulating entities.

    +

    + + +

    Functions

    + + + + + +
    move_to (entity, position, acceleration_x, acceleration_y, acceleration_z)Moves the given entity towards the given point by setting its velocity into + the correct direction.
    + +
    +
    + + +

    Functions

    +
    +
    + + move_to (entity, position, acceleration_x, acceleration_y, acceleration_z) +
    +
    + Moves the given entity towards the given point by setting its velocity into + the correct direction. + + +

    Parameters:

    +
      +
    • entity + The entity to move, a LuaEntitySAO. +
    • +
    • position + The position to move the entity towards. +
    • +
    • acceleration_x + Optional. The acceleration to use in the x direction, + defaults to 1. +
    • +
    • acceleration_y + Optional. The acceleration to use in the y direction, + defaults to acceleration_x. +
    • +
    • acceleration_z + Optional. The acceleration to use in the x direction, + defaults to acceleration_x. +
    • +
    + + + + + +
    +
    + + +
    +
    +
    +generated by LDoc 1.4.2 +
    +
    + + diff --git a/doc/modules/facedirutil.html b/doc/modules/facedirutil.html index 6594a0d..483ae95 100644 --- a/doc/modules/facedirutil.html +++ b/doc/modules/facedirutil.html @@ -52,6 +52,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/fisheryates.html b/doc/modules/fisheryates.html index e11fe37..4f07501 100644 --- a/doc/modules/fisheryates.html +++ b/doc/modules/fisheryates.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/interpolate.html b/doc/modules/interpolate.html index 925e5f4..d3b32d5 100644 --- a/doc/modules/interpolate.html +++ b/doc/modules/interpolate.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/inventoryutil.html b/doc/modules/inventoryutil.html index 86ad269..21bd63a 100644 --- a/doc/modules/inventoryutil.html +++ b/doc/modules/inventoryutil.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/itemutil.html b/doc/modules/itemutil.html index 29ec307..c0e202a 100644 --- a/doc/modules/itemutil.html +++ b/doc/modules/itemutil.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/list.html b/doc/modules/list.html index 1395ca2..f3fded6 100644 --- a/doc/modules/list.html +++ b/doc/modules/list.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/log.html b/doc/modules/log.html index b68ed2f..8fe8819 100644 --- a/doc/modules/log.html +++ b/doc/modules/log.html @@ -51,6 +51,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/mapmanipulator.html b/doc/modules/mapmanipulator.html index 81a6c76..d09b8d5 100644 --- a/doc/modules/mapmanipulator.html +++ b/doc/modules/mapmanipulator.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/mathutil.html b/doc/modules/mathutil.html index bc39455..b46c75a 100644 --- a/doc/modules/mathutil.html +++ b/doc/modules/mathutil.html @@ -51,6 +51,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/minetestex.html b/doc/modules/minetestex.html index f03788b..c611353 100644 --- a/doc/modules/minetestex.html +++ b/doc/modules/minetestex.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/nodeutil.html b/doc/modules/nodeutil.html index 56a3a6e..c483f5b 100644 --- a/doc/modules/nodeutil.html +++ b/doc/modules/nodeutil.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/noisemanager.html b/doc/modules/noisemanager.html index 062b674..7fe2385 100644 --- a/doc/modules/noisemanager.html +++ b/doc/modules/noisemanager.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/numberutil.html b/doc/modules/numberutil.html index 2424c49..c25499d 100644 --- a/doc/modules/numberutil.html +++ b/doc/modules/numberutil.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/pathutil.html b/doc/modules/pathutil.html index caaa0c4..b419292 100644 --- a/doc/modules/pathutil.html +++ b/doc/modules/pathutil.html @@ -51,6 +51,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/posutil.html b/doc/modules/posutil.html index 46bf47a..11787ef 100644 --- a/doc/modules/posutil.html +++ b/doc/modules/posutil.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/random.html b/doc/modules/random.html index e51e6eb..7cf4861 100644 --- a/doc/modules/random.html +++ b/doc/modules/random.html @@ -51,6 +51,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/rotationutil.html b/doc/modules/rotationutil.html index 393c3bf..24a9643 100644 --- a/doc/modules/rotationutil.html +++ b/doc/modules/rotationutil.html @@ -51,6 +51,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/scheduler.html b/doc/modules/scheduler.html index 63745fd..da24f96 100644 --- a/doc/modules/scheduler.html +++ b/doc/modules/scheduler.html @@ -51,6 +51,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/settings.html b/doc/modules/settings.html index 492e800..f0c185e 100644 --- a/doc/modules/settings.html +++ b/doc/modules/settings.html @@ -51,6 +51,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/stopwatch.html b/doc/modules/stopwatch.html index 9bfd062..233c09b 100644 --- a/doc/modules/stopwatch.html +++ b/doc/modules/stopwatch.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/stringutil.html b/doc/modules/stringutil.html index 68a1229..43b34be 100644 --- a/doc/modules/stringutil.html +++ b/doc/modules/stringutil.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/tableutil.html b/doc/modules/tableutil.html index 8999558..8f6bef0 100644 --- a/doc/modules/tableutil.html +++ b/doc/modules/tableutil.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/tango.html b/doc/modules/tango.html index b39b99e..f4102aa 100644 --- a/doc/modules/tango.html +++ b/doc/modules/tango.html @@ -46,6 +46,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/test.html b/doc/modules/test.html index 2d60525..8019039 100644 --- a/doc/modules/test.html +++ b/doc/modules/test.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/textureutil.html b/doc/modules/textureutil.html index 2c3c923..c5e109b 100644 --- a/doc/modules/textureutil.html +++ b/doc/modules/textureutil.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/transform.html b/doc/modules/transform.html index 028b455..cfdb4a3 100644 --- a/doc/modules/transform.html +++ b/doc/modules/transform.html @@ -50,6 +50,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/doc/modules/wallmountedutil.html b/doc/modules/wallmountedutil.html index b0f5e61..8ef3389 100644 --- a/doc/modules/wallmountedutil.html +++ b/doc/modules/wallmountedutil.html @@ -52,6 +52,7 @@
  • tango
  • arraymanipulator
  • inventoryutil
  • +
  • entityutil
  • scheduler
  • blockedcache
  • mathutil
  • diff --git a/mods/utils/entityutil.lua b/mods/utils/entityutil.lua new file mode 100644 index 0000000..aae2c42 --- /dev/null +++ b/mods/utils/entityutil.lua @@ -0,0 +1,57 @@ +--[[ +Copyright (c) 2015, Robert 'Bobby' Zenz +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--]] + + +--- Provides various utility methods for manipulating entities. +entityutil = {} + + +--- Moves the given entity towards the given point by setting its velocity into +-- the correct direction. +-- +-- @param entity The entity to move, a LuaEntitySAO. +-- @param position The position to move the entity towards. +-- @param acceleration_x Optional. The acceleration to use in the x direction, +-- defaults to 1. +-- @param acceleration_y Optional. The acceleration to use in the y direction, +-- defaults to acceleration_x. +-- @param acceleration_z Optional. The acceleration to use in the x direction, +-- defaults to acceleration_x. +function entityutil.move_to(entity, position, acceleration_x, acceleration_y, acceleration_z) + acceleration_x = acceleration_x or 1 + acceleration_y = acceleration_y or acceleration_x + acceleration_z = acceleration_z or acceleration_x + + local direction = vector.direction(entity:getpos(), position) + local velocity = entity:getvelocity() + + velocity.x = velocity.x + (acceleration_x * direction.x) + velocity.y = velocity.y + (acceleration_y * direction.y) + velocity.z = velocity.z + (acceleration_z * direction.z) + + entity:setvelocity(velocity) +end + diff --git a/mods/utils/init.lua b/mods/utils/init.lua index 02b19f9..fbbe20e 100644 --- a/mods/utils/init.lua +++ b/mods/utils/init.lua @@ -41,6 +41,7 @@ dofile(base_path .. "/noisemanager.lua") dofile(base_path .. "/arrayutil.lua") dofile(base_path .. "/blockutil.lua") dofile(base_path .. "/constants.lua") +dofile(base_path .. "/entityutil.lua") dofile(base_path .. "/facedirutil.lua") dofile(base_path .. "/fisheryates.lua") dofile(base_path .. "/interpolate.lua")