Extracted more functions.
parent
139accddfa
commit
11a64f90fa
|
@ -60,6 +60,10 @@
|
|||
<td class="summary">Activates the system, without checking the configuration.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#has_been_collected">has_been_collected (entity)</a></td>
|
||||
<td class="summary">Checks if the given entity has already been collected.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#has_just_been_dropped_by">has_just_been_dropped_by (entity, player)</a></td>
|
||||
<td class="summary">Checks if the given entity has just been dropped by the given player within
|
||||
the configured time.</td>
|
||||
|
@ -74,6 +78,10 @@
|
|||
<td class="summary">Checks if the given entity should be picked up automatically or not.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#is_autopickupable">is_autopickupable (entity, player)</a></td>
|
||||
<td class="summary">Checks if the given entity can be automatically picked up.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#move_towards">move_towards (object, target_pos)</a></td>
|
||||
<td class="summary">Moves the given object towards the given location with the given velocity.</td>
|
||||
</tr>
|
||||
|
@ -182,6 +190,31 @@
|
|||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "has_been_collected"></a>
|
||||
<strong>has_been_collected (entity)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Checks if the given entity has already been collected.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">entity</span>
|
||||
The LuaEntity to check.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3>Returns:</h3>
|
||||
<ol>
|
||||
|
||||
true if the entity has already been collected.
|
||||
</ol>
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "has_just_been_dropped_by"></a>
|
||||
|
@ -262,6 +295,34 @@
|
|||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "is_autopickupable"></a>
|
||||
<strong>is_autopickupable (entity, player)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Checks if the given entity can be automatically picked up.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">entity</span>
|
||||
The LuaEntity to check.
|
||||
</li>
|
||||
<li><span class="parameter">player</span>
|
||||
The Player which would like to pick it up.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3>Returns:</h3>
|
||||
<ol>
|
||||
|
||||
true if the entity can be automatically picked up.
|
||||
</ol>
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "move_towards"></a>
|
||||
|
|
|
@ -92,6 +92,14 @@ function autopickup.activate_internal()
|
|||
end
|
||||
end
|
||||
|
||||
--- Checks if the given entity has already been collected.
|
||||
--
|
||||
-- @param entity The LuaEntity to check.
|
||||
-- @return true if the entity has already been collected.
|
||||
function autopickup.has_been_collected(entity)
|
||||
return entity.auto_pickup_collected == nil
|
||||
end
|
||||
|
||||
--- Checks if the given entity has just been dropped by the given player within
|
||||
-- the configured time.
|
||||
--
|
||||
|
@ -109,6 +117,8 @@ end
|
|||
-- @param entity The LuaEntity to check.
|
||||
-- @return true if the given entity can be picked up automatically.
|
||||
function autopickup.has_timedout(entity)
|
||||
print(tableutil.to_string(entity))
|
||||
|
||||
return entity.autopickup_timeout == nil
|
||||
or entity.age >= entity.autopickup_timeout
|
||||
end
|
||||
|
@ -121,6 +131,18 @@ function autopickup.is_allowed(entity)
|
|||
return entity.autopickup_disable ~= true
|
||||
end
|
||||
|
||||
--- Checks if the given entity can be automatically picked up.
|
||||
--
|
||||
-- @param entity The LuaEntity to check.
|
||||
-- @param player The Player which would like to pick it up.
|
||||
-- @return true if the entity can be automatically picked up.
|
||||
function autopickup.is_autopickupable(entity, player)
|
||||
return autopickup.has_been_collected(entity)
|
||||
and autopickup.is_allowed(entity)
|
||||
and autopickup.has_timedout(entity)
|
||||
and not autopickup.has_just_been_dropped_by(entity, player)
|
||||
end
|
||||
|
||||
--- Moves the given object towards the given location with the given velocity.
|
||||
--
|
||||
-- @param object The object to move.
|
||||
|
@ -146,11 +168,7 @@ function autopickup.pickup_items(player)
|
|||
if entityutil.is_builtin_item(object) then
|
||||
local entity = object:get_luaentity()
|
||||
|
||||
if entity.auto_pickup_collected == nil
|
||||
and autopickup.is_allowed(entity)
|
||||
and not autopickup.has_just_been_dropped_by(entity, player)
|
||||
and autopickup.has_timedout(entity) then
|
||||
|
||||
if autopickup.is_autopickupable(entity, player) then
|
||||
local stack = ItemStack(entity.itemstring)
|
||||
|
||||
if target_inventory:room_for_item("main", stack) then
|
||||
|
|
Loading…
Reference in New Issue