Removed env reference
Added support for animation speed changing (requires core patch)
This commit is contained in:
parent
02e02b0350
commit
5d48fbcfee
@ -37,7 +37,7 @@ minetest.register_craftitem("barn:barn_empty", {
|
||||
if pointed_thing.type == "node" then
|
||||
local pos = pointed_thing.above
|
||||
|
||||
local newobject = minetest.env:add_entity(pos,"barn:barn_empty_ent")
|
||||
local newobject = minetest.add_entity(pos,"barn:barn_empty_ent")
|
||||
|
||||
item:take_item()
|
||||
|
||||
@ -53,7 +53,7 @@ minetest.register_craftitem("barn:barn_small_empty", {
|
||||
if pointed_thing.type == "node" then
|
||||
local pos = pointed_thing.above
|
||||
|
||||
local newobject = minetest.env:add_entity(pos,"barn:barn_small_empty_ent")
|
||||
local newobject = minetest.add_entity(pos,"barn:barn_small_empty_ent")
|
||||
|
||||
item:take_item()
|
||||
|
||||
@ -95,7 +95,7 @@ end
|
||||
function breed(breedpairs,self,now)
|
||||
|
||||
local pos = self.object:getpos()
|
||||
local objectlist = minetest.env:get_objects_inside_radius(pos,2)
|
||||
local objectlist = minetest.get_objects_inside_radius(pos,2)
|
||||
local le_animal1 = nil
|
||||
local le_animal2 = nil
|
||||
|
||||
@ -150,7 +150,7 @@ function breed(breedpairs,self,now)
|
||||
|
||||
local result = breedpairs[math.random(3,4)]
|
||||
|
||||
local breeded = minetest.env:add_entity(pos_to_breed ,result .. "__default")
|
||||
local breeded = minetest.add_entity(pos_to_breed ,result .. "__default")
|
||||
|
||||
local breeded_lua = breeded:get_luaentity()
|
||||
breeded_lua.dynamic_data.spawning.player_spawned = true
|
||||
@ -188,7 +188,7 @@ minetest.register_entity(":barn:barn_ent",
|
||||
--remove barn and add empty one
|
||||
self.object:remove()
|
||||
|
||||
local barn_empty = minetest.env:add_entity(pos,"barn:barn_empty_ent")
|
||||
local barn_empty = minetest.add_entity(pos,"barn:barn_empty_ent")
|
||||
local barn_empty_lua = barn_empty:get_luaentity()
|
||||
barn_empty_lua.last_breed_time = now
|
||||
end
|
||||
@ -239,7 +239,7 @@ minetest.register_entity(":barn:barn_empty_ent",
|
||||
|
||||
self.object:remove()
|
||||
|
||||
local barn = minetest.env:add_entity(pos,"barn:barn_ent")
|
||||
local barn = minetest.add_entity(pos,"barn:barn_ent")
|
||||
|
||||
local barn_lua = barn:get_luaentity()
|
||||
|
||||
@ -286,7 +286,7 @@ minetest.register_entity(":barn:barn_small_ent",
|
||||
--remove barn and add empty one
|
||||
self.object:remove()
|
||||
|
||||
local barn_empty = minetest.env:add_entity(pos,"barn:barn_small_empty_ent")
|
||||
local barn_empty = minetest.add_entity(pos,"barn:barn_small_empty_ent")
|
||||
local barn_empty_lua = barn_empty:get_luaentity()
|
||||
barn_empty_lua.last_breed_time = now
|
||||
end
|
||||
@ -337,7 +337,7 @@ minetest.register_entity(":barn:barn_small_empty_ent",
|
||||
|
||||
self.object:remove()
|
||||
|
||||
local barn = minetest.env:add_entity(pos,"barn:barn_small_ent")
|
||||
local barn = minetest.add_entity(pos,"barn:barn_small_ent")
|
||||
|
||||
local barn_lua = barn:get_luaentity()
|
||||
|
||||
|
@ -141,7 +141,7 @@ function attention.callback(entity,now)
|
||||
|
||||
--get list of all objects in attention range
|
||||
local objectlist =
|
||||
minetest.env:get_objects_inside_radius(own_pos,attention_distance)
|
||||
minetest.get_objects_inside_radius(own_pos,attention_distance)
|
||||
|
||||
if #objectlist > 0 then
|
||||
for i = 1 , #objectlist, 1 do
|
||||
|
@ -20,8 +20,8 @@ minetest.register_abm({
|
||||
chance = 1,
|
||||
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.env:add_node(pos,{name="wool:white"})
|
||||
minetest.remove_node(pos)
|
||||
minetest.add_node(pos,{name="wool:white"})
|
||||
end
|
||||
|
||||
})
|
||||
@ -32,8 +32,8 @@ minetest.register_abm({
|
||||
chance = 1,
|
||||
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.env:add_node(pos,{name="wool:grey"})
|
||||
minetest.remove_node(pos)
|
||||
minetest.add_node(pos,{name="wool:grey"})
|
||||
end
|
||||
|
||||
})
|
||||
@ -44,8 +44,8 @@ minetest.register_abm({
|
||||
chance = 1,
|
||||
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.env:add_node(pos,{name="wool:brown"})
|
||||
minetest.remove_node(pos)
|
||||
minetest.add_node(pos,{name="wool:brown"})
|
||||
end
|
||||
|
||||
})
|
||||
@ -56,8 +56,8 @@ minetest.register_abm({
|
||||
chance = 1,
|
||||
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.env:add_node(pos,{name="wool:black"})
|
||||
minetest.remove_node(pos)
|
||||
minetest.add_node(pos,{name="wool:black"})
|
||||
end
|
||||
|
||||
})
|
||||
|
@ -108,7 +108,7 @@ function mobf_debug.spawn_mob(name,param)
|
||||
else
|
||||
--todo find random pos
|
||||
|
||||
local player = minetest.env:get_player_by_name(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
|
||||
if player == nil then
|
||||
|
||||
@ -220,7 +220,7 @@ end
|
||||
--! @param param parameters received
|
||||
------------------------------------------------------------------------------
|
||||
function mobf_debug.add_tools(name,param)
|
||||
local player = minetest.env:get_player_by_name(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
|
||||
if player ~= nil then
|
||||
player:get_inventory():add_item("main", "animalmaterials:lasso 20")
|
||||
@ -378,7 +378,7 @@ function mobf_debug.rightclick_callback(entity,player)
|
||||
print("MOBF: \t\tpath: " .. dump(entity.dynamic_data.p_movement.path))
|
||||
if entity.dynamic_data.p_movement.path ~= nil then
|
||||
for i,v in ipairs(entity.dynamic_data.p_movement.path) do
|
||||
local objects = minetest.env:get_objects_inside_radius(v,0.5)
|
||||
local objects = minetest.get_objects_inside_radius(v,0.5)
|
||||
local found = false;
|
||||
for i=1,#objects,1 do
|
||||
local luaentity = objects[i]:get_luaentity()
|
||||
@ -389,7 +389,7 @@ function mobf_debug.rightclick_callback(entity,player)
|
||||
end
|
||||
end
|
||||
|
||||
local node_at = minetest.env:get_node(v)
|
||||
local node_at = minetest.get_node(v)
|
||||
|
||||
if not found and
|
||||
node_at.name ~= nil and
|
||||
@ -426,6 +426,9 @@ function mobf_debug.rightclick_callback(entity,player)
|
||||
print("MOBF: \t\t " .. k .. ": " .. v.value)
|
||||
end
|
||||
end
|
||||
if entity.dynamic_data.graphics.last_fps ~= nil then
|
||||
print("MOBF: Animating with: " .. entity.dynamic_data.graphics.last_fps .. " fps")
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
@ -199,7 +199,7 @@ end
|
||||
------------------------------------------------------------------------------
|
||||
function environment.get_absolute_min_max_pos(env,pos)
|
||||
|
||||
local node = minetest.env:get_node(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
--if is not within environment it should be return current position
|
||||
--as min max
|
||||
@ -277,7 +277,7 @@ function environment.checksurface(pos,surface)
|
||||
|
||||
local pos_below = {x=pos.x,y=pos.y-1,z=pos.z}
|
||||
|
||||
local node_below = minetest.env:get_node(pos_below)
|
||||
local node_below = minetest.get_node(pos_below)
|
||||
|
||||
|
||||
if node_below == nil then
|
||||
@ -374,7 +374,7 @@ function environment.pos_is_ok(pos,entity,dont_do_jumpcheck)
|
||||
--check if mob at pos will be in correct environment
|
||||
for i=1,#cornerpositions,1 do
|
||||
if not mobf_pos_is_same(lastpos,cornerpositions[i]) then
|
||||
local node_to_check = minetest.env:get_node(cornerpositions[i])
|
||||
local node_to_check = minetest.get_node(cornerpositions[i])
|
||||
|
||||
if node_to_check == nil then
|
||||
mobf_bug_warning(LOGLEVEL_ERROR,"MOBF: BUG!!!! checking position with invalid node")
|
||||
@ -482,7 +482,7 @@ function environment.get_default_gravity(pos,media,canfly)
|
||||
return nil
|
||||
end
|
||||
|
||||
local node = minetest.env:get_node(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
--if an mob can't fly or isn't within it's medium default acceleration
|
||||
-- for it's current medium is applied
|
||||
@ -527,10 +527,10 @@ function environment.fix_base_pos(entity, center_to_bottom)
|
||||
|
||||
local pos = entity.object:getpos()
|
||||
|
||||
local node_pos = minetest.env:get_node(pos)
|
||||
local node_pos = minetest.get_node(pos)
|
||||
|
||||
local pos_to_check = {x=pos.x,y=pos.y-center_to_bottom+0.1,z=pos.z}
|
||||
local node_pos_check = minetest.env:get_node(pos_to_check)
|
||||
local node_pos_check = minetest.get_node(pos_to_check)
|
||||
|
||||
if node_pos ~= nil and
|
||||
node_pos_check ~= nil then
|
||||
|
@ -190,7 +190,7 @@ function fighting.hit(entity,attacker)
|
||||
end
|
||||
else
|
||||
--todo check if spawning a stack is possible
|
||||
minetest.env:add_item(mob_pos,result)
|
||||
minetest.add_item(mob_pos,result)
|
||||
end
|
||||
spawning.remove(entity, "killed")
|
||||
else
|
||||
@ -633,7 +633,7 @@ function fighting.get_target(entity)
|
||||
range = entity.data.combat.distance.range
|
||||
end
|
||||
|
||||
local objectlist = minetest.env:get_objects_inside_radius(
|
||||
local objectlist = minetest.get_objects_inside_radius(
|
||||
entity.object:getpos(),range)
|
||||
|
||||
local count = 0
|
||||
@ -796,10 +796,10 @@ function fighting.self_destruct_handler(entity,now)
|
||||
for k=pos.z-entity.data.combat.self_destruct.range/2,
|
||||
pos.z+entity.data.combat.self_destruct.range/2, 1 do
|
||||
|
||||
local current = minetest.env:get_node({x=i,y=j,z=k})
|
||||
local current = minetest.get_node({x=i,y=j,z=k})
|
||||
|
||||
if (current.name == "air") then
|
||||
minetest.env:set_node({x=i,y=j,z=k},
|
||||
minetest.set_node({x=i,y=j,z=k},
|
||||
{name="fire:basic_flame"})
|
||||
end
|
||||
|
||||
@ -944,7 +944,7 @@ function fighting.distance_attack_handler(entity,targetpos,mob_pos,now,distance)
|
||||
sound.play(mob_pos,entity.data.sound.distance);
|
||||
end
|
||||
|
||||
local newobject=minetest.env:add_entity({ x=mob_pos.x+dir.x,
|
||||
local newobject=minetest.add_entity({ x=mob_pos.x+dir.x,
|
||||
y=mob_pos.y+dir.y+1,
|
||||
z=mob_pos.z+dir.z
|
||||
},
|
||||
@ -1022,7 +1022,7 @@ function fighting.sun_damage_handler(entity,now)
|
||||
local pos = entity.object:getpos()
|
||||
local current_state = mob_state.get_state_by_name(entity,
|
||||
entity.dynamic_data.state.current)
|
||||
local current_light = minetest.env:get_node_light(pos)
|
||||
local current_light = minetest.get_node_light(pos)
|
||||
|
||||
if current_light == nil then
|
||||
minetest.log(LOGLEVEL_ERROR,"MOBF: Bug!!! didn't get a light value for "
|
||||
|
@ -18,6 +18,22 @@
|
||||
--! @brief graphic features
|
||||
graphics = {}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: init_dynamic_data(entity,velocity)
|
||||
--
|
||||
--! @brief initialize values required by graphics
|
||||
--! @memberof graphics
|
||||
--
|
||||
--! @param entity mob to calculate direction
|
||||
--! @param current_velocity data to calculate direction from
|
||||
-------------------------------------------------------------------------------
|
||||
function graphics.init_dynamic_data(entity,now)
|
||||
local data = {
|
||||
last_scalar_speed = nil,
|
||||
}
|
||||
|
||||
entity.dynamic_data.graphics = data
|
||||
end
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: update_orientation_simple(entity,velocity)
|
||||
--
|
||||
@ -46,7 +62,85 @@ function graphics.update_orientation_simple(entity,current_velocity)
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: update_orientation(entity)
|
||||
-- name: update(entity,now,dtime)
|
||||
--
|
||||
--! @brief callback for updating graphics of mob
|
||||
--! @memberof graphics
|
||||
--
|
||||
--! @param entity mob to calculate direction
|
||||
--! @param now current time
|
||||
--! @param dtime current dtime
|
||||
-------------------------------------------------------------------------------
|
||||
function graphics.update(entity,now,dtime)
|
||||
|
||||
--updating orientation
|
||||
graphics.update_orientation(entity,now,dtime)
|
||||
|
||||
|
||||
--update animation speed
|
||||
graphics.update_animation(entity,now,dtime)
|
||||
|
||||
--update attention
|
||||
if entity.dynamic_data.attention ~= nil and
|
||||
entity.data.attention ~= nil and
|
||||
entity.dynamic_data.attention.current_value >
|
||||
entity.data.attention.watch_threshold then
|
||||
dbg_mobf.graphics_lvl3("MOBF: attention mode orientation update")
|
||||
local direction = mobf_get_direction(entity.object:getpos(),
|
||||
entity.dynamic_data.attention.most_relevant_target:getpos())
|
||||
|
||||
if entity.mode == "3d" then
|
||||
entity.object:setyaw(
|
||||
mobf_calc_yaw(direction.x,direction.z))
|
||||
else
|
||||
entity.object:setyaw(
|
||||
mobf_calc_yaw(direction.x,direction.z)+math.pi/2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: update_animation(entity,now,dtime)
|
||||
--
|
||||
--! @brief callback for updating graphics of mob
|
||||
--! @memberof graphics
|
||||
--
|
||||
--! @param entity mob to calculate direction
|
||||
--! @param now current time
|
||||
--! @param dtime current dtime
|
||||
-------------------------------------------------------------------------------
|
||||
function graphics.update_animation(entity,now,dtime)
|
||||
if entity.dynamic_data.animation ~= nil then
|
||||
|
||||
local animdata = entity.data.animation[entity.dynamic_data.animation]
|
||||
if animdata ~= nil and
|
||||
animdata.basevelocity ~= nil then
|
||||
|
||||
local current_velocity = entity.object:getvelocity()
|
||||
local scalar_velocity = mobf_calc_scalar_speed(current_velocity.x,current_velocity.z)
|
||||
|
||||
if entity.dynamic_data.graphics.last_scalar_speed ~= nil then
|
||||
local speeddiff =
|
||||
DELTA(scalar_velocity,
|
||||
entity.dynamic_data.graphics.last_scalar_speed)
|
||||
|
||||
if speeddiff > 0.1 then
|
||||
local current_fps = scalar_velocity/animdata.basevelocity * 15
|
||||
|
||||
entity.object:set_animation_speed(current_fps)
|
||||
|
||||
entity.dynamic_data.graphics.last_scalar_speed = scalar_velocity
|
||||
entity.dynamic_data.graphics.last_fps = current_fps
|
||||
end
|
||||
else
|
||||
entity.dynamic_data.graphics.last_scalar_speed = scalar_velocity
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: update_orientation(entity,now,dtime)
|
||||
--
|
||||
--! @brief callback for calculating a mobs direction
|
||||
--! @memberof graphics
|
||||
@ -111,26 +205,6 @@ function graphics.update_orientation(entity,now,dtime)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- make mobs face a specific player
|
||||
-- TODO move from dynamics data inventory to somewhere else
|
||||
|
||||
if entity.dynamic_data.attention ~= nil and
|
||||
entity.data.attention ~= nil and
|
||||
entity.dynamic_data.attention.current_value >
|
||||
entity.data.attention.watch_threshold then
|
||||
dbg_mobf.graphics_lvl3("MOBF: attention mode orientation update")
|
||||
local direction = mobf_get_direction(entity.object:getpos(),
|
||||
entity.dynamic_data.attention.most_relevant_target:getpos())
|
||||
|
||||
if entity.mode == "3d" then
|
||||
entity.object:setyaw(
|
||||
mobf_calc_yaw(direction.x,direction.z))
|
||||
else
|
||||
entity.object:setyaw(
|
||||
mobf_calc_yaw(direction.x,direction.z)+math.pi/2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
@ -3,7 +3,7 @@
|
||||
--
|
||||
-- You may copy, use, modify or do nearly anything except removing this
|
||||
-- copyright notice.
|
||||
-- And of course you are NOT allow to pretend you have written it.
|
||||
-- And of course you are NOT allowed to pretend you have written it.
|
||||
--
|
||||
--! @file init.lua
|
||||
--! @brief main module file responsible for including all parts of mob framework mod
|
||||
@ -58,8 +58,9 @@ end
|
||||
dofile (mobf_modpath .. "/debug_trace.lua")
|
||||
|
||||
--include engine
|
||||
dofile (mobf_modpath .. "/utils/generic_functions.lua")
|
||||
dofile (mobf_modpath .. "/utils/error_handling.lua")
|
||||
dofile (mobf_modpath .. "/utils/settings.lua")
|
||||
dofile (mobf_modpath .. "/utils/generic_functions.lua")
|
||||
dofile (mobf_modpath .. "/utils/data_storage.lua")
|
||||
dofile (mobf_modpath .. "/utils/tracing.lua")
|
||||
dofile (mobf_modpath .. "/utils/geometry.lua")
|
||||
@ -294,9 +295,9 @@ function mobf_init_modules()
|
||||
|
||||
--visual change hook
|
||||
mobf.register_on_step_callback({
|
||||
name = "update_orientation",
|
||||
handler = graphics.update_orientation,
|
||||
init = nil,
|
||||
name = "update_graphics",
|
||||
handler = graphics.update,
|
||||
init = graphics.init_dynamic_data,
|
||||
configcheck = function(entity)
|
||||
return true
|
||||
end
|
||||
|
@ -74,7 +74,7 @@ function mobf_lifebar.add(entity)
|
||||
local BS = 10
|
||||
pos.y = pos.y + entity.collisionbox[5] + 0.1
|
||||
|
||||
local lifebar = minetest.env:add_entity(pos,"mobf:lifebar")
|
||||
local lifebar = minetest.add_entity(pos,"mobf:lifebar")
|
||||
|
||||
if lifebar ~= nil then
|
||||
|
||||
|
@ -73,18 +73,18 @@ function mgen_jordan4ibanez.callback(entity,now)
|
||||
--open a door [alpha]
|
||||
if entity.dynamic_data.movement.direction ~= nil then
|
||||
if entity.dynamic_data.movement.door_timer > 2 then
|
||||
local is_a_door = minetest.env:get_node({x=entity.object:getpos().x + entity.dynamic_data.movement.direction.x,
|
||||
local is_a_door = minetest.get_node({x=entity.object:getpos().x + entity.dynamic_data.movement.direction.x,
|
||||
y=entity.object:getpos().y,z=entity.object:getpos().
|
||||
z + entity.dynamic_data.movement.direction.z}).name
|
||||
if is_a_door == "doors:door_wood_t_1" then
|
||||
minetest.env:punch_node({x=entity.object:getpos().x + entity.dynamic_data.movement.direction.x,
|
||||
minetest.punch_node({x=entity.object:getpos().x + entity.dynamic_data.movement.direction.x,
|
||||
y=entity.object:getpos().y-1,
|
||||
z=entity.object:getpos().z + entity.dynamic_data.movement.direction.z})
|
||||
entity.dynamic_data.movement.door_timer = 0
|
||||
end
|
||||
local is_in_door = minetest.env:get_node(entity.object:getpos()).name
|
||||
local is_in_door = minetest.get_node(entity.object:getpos()).name
|
||||
if is_in_door == "doors:door_wood_t_1" then
|
||||
minetest.env:punch_node(entity.object:getpos())
|
||||
minetest.punch_node(entity.object:getpos())
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -92,7 +92,7 @@ function mgen_jordan4ibanez.callback(entity,now)
|
||||
--jump
|
||||
if entity.dynamic_data.movement.direction ~= nil then
|
||||
if entity.dynamic_data.movement.jump_timer > 0.3 then
|
||||
if minetest.registered_nodes[minetest.env:get_node({x=entity.object:getpos().x + entity.dynamic_data.movement.direction.x,
|
||||
if minetest.registered_nodes[minetest.get_node({x=entity.object:getpos().x + entity.dynamic_data.movement.direction.x,
|
||||
y=entity.object:getpos().y-1,
|
||||
z=entity.object:getpos().z + entity.dynamic_data.movement.direction.z}).name].walkable then
|
||||
entity.object:setvelocity({x=entity.object:getvelocity().x,y=5,z=entity.object:getvelocity().z})
|
||||
|
@ -242,20 +242,18 @@ function p_mov_gen.set_target(entity,target)
|
||||
entity.dynamic_data.movement.max_distance = 0.5
|
||||
|
||||
--try to find path on our own
|
||||
if type(minetest.env.find_path) == "function" then
|
||||
print("trying to find path to: " .. printpos(targetpos))
|
||||
entity.dynamic_data.p_movement.path =
|
||||
minetest.env:find_path(current_pos,targetpos,5,1,1,nil)
|
||||
|
||||
if entity.dynamic_data.p_movement.path ~= nil then
|
||||
entity.dynamic_data.p_movement.path =
|
||||
minetest.find_path(current_pos,targetpos,5,1,1,nil)
|
||||
|
||||
if entity.dynamic_data.p_movement.path ~= nil then
|
||||
|
||||
--a valid path has at least 2 positions
|
||||
mobf_assert_backtrace(#entity.dynamic_data.p_movement.path > 1)
|
||||
entity.dynamic_data.movement.target =
|
||||
entity.dynamic_data.p_movement.path[2]
|
||||
return true
|
||||
end
|
||||
--a valid path has at least 2 positions
|
||||
mobf_assert_backtrace(#entity.dynamic_data.p_movement.path > 1)
|
||||
entity.dynamic_data.movement.target =
|
||||
entity.dynamic_data.p_movement.path[2]
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
if entity.dynamic_data.p_movement.path == nil then
|
||||
print(
|
||||
|
@ -250,7 +250,7 @@ function direction_control.precheck_movement(entity,movement_state,pos_predicted
|
||||
dbg_mobf.movement_lvl1("mob is about to collide")
|
||||
if environment.pos_is_ok({x=pos_predicted.x,y=pos_predicted.y+1,z=pos_predicted.z},entity) == "ok" then
|
||||
if math.random() < ( entity.dynamic_data.movement.mpattern.jump_up * PER_SECOND_CORRECTION_FACTOR) then
|
||||
local node_at_predicted_pos = minetest.env:get_node(pos_predicted)
|
||||
local node_at_predicted_pos = minetest.get_node(pos_predicted)
|
||||
dbg_mobf.pmovement_lvl2("MOBF: velocity is:" .. printpos(movement_state.current_velocity) .. " position is: "..printpos(pos) )
|
||||
dbg_mobf.pmovement_lvl2("MOBF: estimated position was: "..printpos(pos_predicted))
|
||||
dbg_mobf.pmovement_lvl2("MOBF: predicted node state is: " .. environment.pos_is_ok(pos_predicted,entity))
|
||||
|
@ -556,7 +556,7 @@ function movement_gen.fix_current_pos(entity,movement_state)
|
||||
|
||||
if current_state == "collision" then
|
||||
local current_pos = mobf_round_pos(movement_state.basepos);
|
||||
local current_node = minetest.env:get_node( current_pos );
|
||||
local current_node = minetest.get_node( current_pos );
|
||||
|
||||
local walkable = false
|
||||
if minetest.registered_nodes[current_node.name] then
|
||||
|
@ -182,7 +182,7 @@ function mgen_raster.onground(entity,now,basepos)
|
||||
local fp = { x= posbelow.x + (0.5*dx),
|
||||
y= posbelow.y,
|
||||
z= posbelow.z + (0.5*dz) }
|
||||
local n = minetest.env:get_node(fp)
|
||||
local n = minetest.get_node(fp)
|
||||
if mobf_is_walkable(n) then
|
||||
return true
|
||||
end
|
||||
|
@ -539,7 +539,7 @@ function mob_state.prepare_states(mob)
|
||||
local pos = self.object:getpos()
|
||||
self.object:remove()
|
||||
|
||||
minetest.env:add_entity(pos,self.new_name)
|
||||
minetest.add_entity(pos,self.new_name)
|
||||
end
|
||||
})
|
||||
|
||||
|
@ -241,7 +241,7 @@ end
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf.get_basepos(entity)
|
||||
local pos = entity.object:getpos()
|
||||
local nodeatpos = minetest.env:get_node(pos)
|
||||
local nodeatpos = minetest.get_node(pos)
|
||||
|
||||
dbg_mobf.mobf_core_helper_lvl3("MOBF: " .. entity.data.name
|
||||
.. " Center Position: " .. printpos(pos) .. " is: " .. nodeatpos.name)
|
||||
@ -254,7 +254,7 @@ function mobf.get_basepos(entity)
|
||||
.. entity.collisionbox[2])
|
||||
end
|
||||
|
||||
nodeatpos = minetest.env:get_node(pos)
|
||||
nodeatpos = minetest.get_node(pos)
|
||||
dbg_mobf.mobf_core_helper_lvl3("MOBF: Base Position: " .. printpos(pos)
|
||||
.. " is: " .. nodeatpos.name)
|
||||
|
||||
@ -280,7 +280,7 @@ function mobf.activate_handler(self,staticdata)
|
||||
if pos == nil then
|
||||
minetest.log(LOGLEVEL_ERROR,"MOBF: mob at nil pos!")
|
||||
end
|
||||
local current_node = minetest.env:get_node(pos)
|
||||
local current_node = minetest.get_node(pos)
|
||||
|
||||
|
||||
if current_node == nil then
|
||||
@ -589,7 +589,7 @@ function mobf.register_entity(name, graphics, mob)
|
||||
local fp = { x= posbelow.x + (0.5*dx),
|
||||
y= posbelow.y,
|
||||
z= posbelow.z + (0.5*dz) }
|
||||
local n = minetest.env:get_node(fp)
|
||||
local n = minetest.get_node(fp)
|
||||
if not mobf_is_walkable(n) then
|
||||
return true
|
||||
end
|
||||
|
@ -39,7 +39,7 @@ function movement_generic.get_accel_to(new_pos,entity)
|
||||
end
|
||||
|
||||
local old_pos = entity.object:getpos()
|
||||
local node = minetest.env:get_node(old_pos)
|
||||
local node = minetest.get_node(old_pos)
|
||||
local maxaccel = entity.data.movement.max_accel
|
||||
local minaccel = entity.data.movement.min_accel
|
||||
|
||||
|
@ -328,7 +328,7 @@ function mobf_path.button_handler(player, formname, fields)
|
||||
|
||||
if data.buttonid == "show_points" then
|
||||
for i,v in ipairs(mobf_rtd.path_data.users[data.ownername].paths[data.pathname].points) do
|
||||
local objects = minetest.env:get_objects_inside_radius(v,0.5)
|
||||
local objects = minetest.get_objects_inside_radius(v,0.5)
|
||||
|
||||
dbg_mobf.path_lvl3("MOBF: got " .. #objects ..
|
||||
" around pos checking for marker")
|
||||
@ -342,7 +342,7 @@ function mobf_path.button_handler(player, formname, fields)
|
||||
end
|
||||
end
|
||||
|
||||
local node_at = minetest.env:get_node(v)
|
||||
local node_at = minetest.get_node(v)
|
||||
|
||||
if not found and
|
||||
node_at.name ~= nil and
|
||||
|
@ -54,7 +54,7 @@ function random_drop.callback(entity,now)
|
||||
local toput = environment.get_suitable_pos_same_level(entitybasepos,1,entity)
|
||||
|
||||
if toput ~= nil then
|
||||
minetest.env:add_entity(toput,entity.data.random_drop.result.."_ent")
|
||||
minetest.add_entity(toput,entity.data.random_drop.result.."_ent")
|
||||
dbg_mobf.random_drop_lvl3("MOBF: adding random drop for "..entity.data.name .. ": "..entity.data.random_drop.result.."_ent" .. " at " .. printpos(toput))
|
||||
if entity.data.sound ~= nil then
|
||||
sound.play(entitybasepos,entity.data.sound.random_drop)
|
||||
|
@ -46,7 +46,7 @@ function mobf_spawn_at_night(mob_name,mob_transform,spawning_data,environment)
|
||||
chance = math.floor(1/spawning_data.rate),
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
|
||||
local gametime = minetest.env:get_timeofday()
|
||||
local gametime = minetest.get_timeofday()
|
||||
|
||||
if gametime > 0.25 and
|
||||
gametime < 0.75 then
|
||||
@ -73,7 +73,7 @@ function mobf_spawn_at_night(mob_name,mob_transform,spawning_data,environment)
|
||||
return
|
||||
end
|
||||
|
||||
local gametime = minetest.env:get_timeofday()
|
||||
local gametime = minetest.get_timeofday()
|
||||
|
||||
if gametime > 0.25 and
|
||||
gametime < 0.75 then
|
||||
@ -81,7 +81,7 @@ function mobf_spawn_at_night(mob_name,mob_transform,spawning_data,environment)
|
||||
end
|
||||
|
||||
|
||||
local node_above = minetest.env:get_node(pos_above)
|
||||
local node_above = minetest.get_node(pos_above)
|
||||
|
||||
|
||||
if mob_name == nil then
|
||||
@ -89,9 +89,9 @@ function mobf_spawn_at_night(mob_name,mob_transform,spawning_data,environment)
|
||||
else
|
||||
--print("Find mobs of same type around:"..mob_name.. " pop dens: ".. population_density)
|
||||
if mobf_mob_around(mob_name,mob_transform,pos,spawning_data.density,true) == 0 then
|
||||
if minetest.env:get_node_light(pos_above,0.5) == LIGHT_MAX +1 and
|
||||
minetest.env:get_node_light(pos_above,0.0) < 7 and
|
||||
minetest.env:get_node_light(pos_above) < 6 then
|
||||
if minetest.get_node_light(pos_above,0.5) == LIGHT_MAX +1 and
|
||||
minetest.get_node_light(pos_above,0.0) < 7 and
|
||||
minetest.get_node_light(pos_above) < 6 then
|
||||
|
||||
local entity = spawning.spawn_and_check(mob_name,"__default",pos_above,"at_night_spawner")
|
||||
|
||||
@ -125,7 +125,7 @@ function mobf_spawn_at_night_entity(mob_name,mob_transform,spawning_data,environ
|
||||
|
||||
spawning.register_spawner_entity(mob_name,mob_transform,spawning_data,environment,
|
||||
function(self)
|
||||
local gametime = minetest.env:get_timeofday()
|
||||
local gametime = minetest.get_timeofday()
|
||||
|
||||
if gametime > 0.25 and
|
||||
gametime < 0.75 then
|
||||
@ -161,7 +161,7 @@ function mobf_spawn_at_night_entity(mob_name,mob_transform,spawning_data,environ
|
||||
|
||||
--check if own position is good
|
||||
local pos_below = {x=newpos.x,y=newpos.y-1,z=newpos.z}
|
||||
local node_below = minetest.env:get_node(pos_below)
|
||||
local node_below = minetest.get_node(pos_below)
|
||||
|
||||
if good and not mobf_contains(at_night_surfaces,node_below.name) then
|
||||
reason = "wrong surface"
|
||||
@ -174,8 +174,8 @@ function mobf_spawn_at_night_entity(mob_name,mob_transform,spawning_data,environ
|
||||
good = false
|
||||
end
|
||||
|
||||
local light_day = minetest.env:get_node_light(newpos,0.5)
|
||||
local light_midnight = minetest.env:get_node_light(newpos,0.0)
|
||||
local light_day = minetest.get_node_light(newpos,0.5)
|
||||
local light_midnight = minetest.get_node_light(newpos,0.0)
|
||||
|
||||
--check if area is in day/night cycle
|
||||
if good and (light_day ~= LIGHT_MAX +1 or
|
||||
@ -197,7 +197,7 @@ function mobf_spawn_at_night_entity(mob_name,mob_transform,spawning_data,environ
|
||||
|
||||
|
||||
--check if current light is dark enough
|
||||
if minetest.env:get_node_light(pos) > 6 then
|
||||
if minetest.get_node_light(pos) > 6 then
|
||||
self.spawner_time_passed = self.spawner_mob_spawndata.respawndelay
|
||||
self.spawner_last_result = "at_night: to much light"
|
||||
return
|
||||
@ -238,7 +238,7 @@ function mobf_spawn_at_night_entity(mob_name,mob_transform,spawning_data,environ
|
||||
if surface then
|
||||
pos.y= surface -1
|
||||
|
||||
local node = minetest.env:get_node(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
if not mobf_contains(at_night_surfaces,node.name) then
|
||||
dbg_mobf.spawning_lvl3("MOBF: node ain't of correct type: " .. node.name)
|
||||
@ -246,13 +246,13 @@ function mobf_spawn_at_night_entity(mob_name,mob_transform,spawning_data,environ
|
||||
end
|
||||
|
||||
local pos_above = {x=pos.x,y=pos.y+1,z=pos.z}
|
||||
local node_above = minetest.env:get_node(pos_above)
|
||||
local node_above = minetest.get_node(pos_above)
|
||||
if not mobf_contains({"air"},node_above.name) then
|
||||
dbg_mobf.spawning_lvl3("MOBF: node above ain't air but: " .. node_above.name)
|
||||
return false
|
||||
end
|
||||
|
||||
local light_day = minetest.env:get_node_light(pos_above,0.5)
|
||||
local light_day = minetest.get_node_light(pos_above,0.5)
|
||||
|
||||
if light_day ~= (LIGHT_MAX +1) then
|
||||
dbg_mobf.spawning_lvl3("MOBF: node above ain't in sunlight")
|
||||
|
@ -71,7 +71,7 @@ function mobf_spawn_on_big_willow(mob_name,mob_transform,spawning_data,environme
|
||||
|
||||
for x=pos.x-2,pos.x+2,1 do
|
||||
for z=pos.z-2,pos.z+2,1 do
|
||||
local node_to_check = minetest.env:getnode({x=x,y=pos.y,z=z})
|
||||
local node_to_check = minetest.getnode({x=x,y=pos.y,z=z})
|
||||
|
||||
if node_to_check == nil or
|
||||
node_to_check.name ~= "default:dirt_with_grass" then
|
||||
@ -121,7 +121,7 @@ function mobf_spawn_on_big_willow_mapgen(mob_name,mob_transform,spawning_data,en
|
||||
|
||||
for x=pos.x-2,pos.x+2,1 do
|
||||
for z=pos.z-2,pos.z+2,1 do
|
||||
local node_to_check = minetest.env:get_node({x=x,y=pos.y,z=z})
|
||||
local node_to_check = minetest.get_node({x=x,y=pos.y,z=z})
|
||||
if node_to_check == nil or
|
||||
node_to_check.name ~= "default:dirt_with_grass" then
|
||||
pos_is_big_willow = false
|
||||
|
@ -72,14 +72,14 @@ function mobf_spawn_in_deep_large_caves(mob_name,mob_transform,spawning_data,env
|
||||
return
|
||||
end
|
||||
|
||||
local node_above = minetest.env:get_node(pos_above)
|
||||
local node_above = minetest.get_node(pos_above)
|
||||
|
||||
if mob_name == nil then
|
||||
minetest.log(LOGLEVEL_ERROR,"MOBF: Bug!!! mob name not available")
|
||||
else
|
||||
dbg_mobf.spawning_lvl3("MOBF: trying to spawn " .. mob_name)
|
||||
if mobf_mob_around(mob_name,mob_transform,pos,spawning_data.density,true) == 0 then
|
||||
local newobject = minetest.env:add_entity(pos_above,mob_name .. "__default")
|
||||
local newobject = minetest.add_entity(pos_above,mob_name .. "__default")
|
||||
|
||||
local newentity = mobf_find_entity(newobject)
|
||||
|
||||
@ -145,7 +145,7 @@ function mobf_spawn_in_deep_large_caves_entity(mob_name,mob_transform,spawning_d
|
||||
if newpos.y ~= nil then
|
||||
--check if own position is good
|
||||
local pos_below = {x=newpos.x,y=newpos.y-1,z=newpos.z}
|
||||
local node_below = minetest.env:get_node(pos_below)
|
||||
local node_below = minetest.get_node(pos_below)
|
||||
|
||||
|
||||
if not mobf_contains({ "default:stone","default:gravel","default:dirt" },node_below.name) then
|
||||
@ -225,7 +225,7 @@ function mobf_spawn_in_deep_large_caves_entity(mob_name,mob_transform,spawning_d
|
||||
if surface then
|
||||
pos.y= surface -1
|
||||
|
||||
local node = minetest.env:get_node(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
if not mobf_contains({ "default:stone","default:gravel","default:dirt","default:sand" },node.name) then
|
||||
dbg_mobf.spawning_lvl3("MOBF: node ain't of correct type: " .. node.name)
|
||||
@ -233,7 +233,7 @@ function mobf_spawn_in_deep_large_caves_entity(mob_name,mob_transform,spawning_d
|
||||
end
|
||||
|
||||
local pos_above = {x=pos.x,y=pos.y+1,z=pos.z}
|
||||
local node_above = minetest.env:get_node(pos_above)
|
||||
local node_above = minetest.get_node(pos_above)
|
||||
if not mobf_contains({"air"},node_above.name) then
|
||||
dbg_mobf.spawning_lvl3("MOBF: node above ain't air but: " .. node_above.name)
|
||||
return
|
||||
|
@ -64,7 +64,7 @@ function mobf_spawn_in_forrest(mob_name,mob_transform,spawning_data,environment)
|
||||
end
|
||||
|
||||
|
||||
local node_above = minetest.env:get_node(pos_above)
|
||||
local node_above = minetest.get_node(pos_above)
|
||||
|
||||
if mob_name == nil then
|
||||
minetest.log(LOGLEVEL_ERROR,"MOBF Bug!!!: mob name not available")
|
||||
@ -75,10 +75,10 @@ function mobf_spawn_in_forrest(mob_name,mob_transform,spawning_data,environment)
|
||||
--print("Find mobs of same type around:"..mob_name.. " pop dens: ".. population_density)
|
||||
if mobf_mob_around(mob_name,mob_transform,pos,spawning_data.density,true) == 0 then
|
||||
|
||||
if minetest.env:find_node_near(pos, 3, { "default:leaves",
|
||||
if minetest.find_node_near(pos, 3, { "default:leaves",
|
||||
"default:tree"} ) ~= nil then
|
||||
|
||||
local newobject = minetest.env:add_entity(pos_above,mob_name .. "__default")
|
||||
local newobject = minetest.add_entity(pos_above,mob_name .. "__default")
|
||||
|
||||
local newentity = mobf_find_entity(newobject)
|
||||
|
||||
@ -111,9 +111,9 @@ function mobf_spawn_in_forrest_mapgen(mob_name,mob_transform,spawning_data,envir
|
||||
dbg_mobf.spawning_lvl3("enough air above " ..printpos(centerpos)
|
||||
.. " minimum is: " .. spawning_data.height )
|
||||
|
||||
if minetest.env:find_node_near(pos, 3, { "default:leaves",
|
||||
if minetest.find_node_near(pos, 3, { "default:leaves",
|
||||
"default:tree"} ) ~= nil or
|
||||
minetest.env:find_node_near(pos, 3, growing_trees_nodes ) ~= nil then
|
||||
minetest.find_node_near(pos, 3, growing_trees_nodes ) ~= nil then
|
||||
local spawnpos = {x=pos.x,y=pos.y+1,z=pos.z}
|
||||
spawning.spawn_and_check(name,"__default",spawnpos,"in_forrest_mapgen")
|
||||
return true
|
||||
|
@ -51,7 +51,7 @@ function mobf_spawn_in_air1(mob_name,mob_transform,spawning_data,environment)
|
||||
z = pos.z
|
||||
}
|
||||
|
||||
local node_above = minetest.env:get_node(pos_above)
|
||||
local node_above = minetest.get_node(pos_above)
|
||||
|
||||
if node_above.name ~= "air" then
|
||||
mobf_warn_long_fct(starttime,"mobf_spawn_in_air1")
|
||||
@ -65,7 +65,7 @@ function mobf_spawn_in_air1(mob_name,mob_transform,spawning_data,environment)
|
||||
z = pos.z
|
||||
}
|
||||
|
||||
local node_spawn = minetest.env:get_node(pos_spawn)
|
||||
local node_spawn = minetest.get_node(pos_spawn)
|
||||
|
||||
|
||||
|
||||
@ -113,7 +113,7 @@ function mobf_spawn_in_air1_spawner(mob_name,mob_transform,spawning_data,environ
|
||||
for y=pos.y-1,pos.y+1,1 do
|
||||
for z=pos.z-1,pos.z+1,1 do
|
||||
|
||||
local node_to_check = minetest.env:get_node({x=x,y=y,z=z})
|
||||
local node_to_check = minetest.get_node({x=x,y=y,z=z})
|
||||
|
||||
if node_to_check == nil then
|
||||
good = false
|
||||
|
@ -69,12 +69,12 @@ function mobf_spawn_in_shallow_water(mob_name,mob_transform,spawning_data,enviro
|
||||
else
|
||||
--print("Try to spawn mob: "..mob_name)
|
||||
|
||||
if mobf_mob_around(mob_name,mob_transform,pos,spawning_data.density,true) == 0 then
|
||||
if mobf_mob_around(mob_name,mob_transform,pos,spawning_data.density,true) == 0 then
|
||||
|
||||
if minetest.env:find_node_near(pos, 10, {"default:dirt",
|
||||
"default:dirt_with_grass"}) ~= nil then
|
||||
if minetest.find_node_near(pos, 10, {"default:dirt",
|
||||
"default:dirt_with_grass"}) ~= nil then
|
||||
|
||||
local newobject = minetest.env:add_entity(pos,mob_name .. "__default")
|
||||
local newobject = minetest.add_entity(pos,mob_name .. "__default")
|
||||
|
||||
local newentity = mobf_find_entity(newobject)
|
||||
|
||||
@ -115,7 +115,7 @@ function mobf_spawn_in_shallow_water_entity(mob_name,mob_transform,spawning_data
|
||||
dbg_mobf.spawning_lvl3("MOBF: " .. dump(self.spawner_mob_env))
|
||||
|
||||
--check if own position is good
|
||||
local node_to_check = minetest.env:get_node(pos)
|
||||
local node_to_check = minetest.get_node(pos)
|
||||
|
||||
if node_to_check ~= nil and
|
||||
node_to_check.name ~= "default:water_flowing" and
|
||||
@ -124,7 +124,7 @@ function mobf_spawn_in_shallow_water_entity(mob_name,mob_transform,spawning_data
|
||||
good = false
|
||||
end
|
||||
|
||||
local found_nodes = minetest.env:find_nodes_in_area({x=pos.x-1,y=pos.y-1,z=pos.z-1},
|
||||
local found_nodes = minetest.find_nodes_in_area({x=pos.x-1,y=pos.y-1,z=pos.z-1},
|
||||
{x=pos.x+1,y=pos.y+1,z=pos.z+1},
|
||||
{ "default:water_flowing","default:water_source"} )
|
||||
if #found_nodes < 4 then
|
||||
@ -139,7 +139,7 @@ function mobf_spawn_in_shallow_water_entity(mob_name,mob_transform,spawning_data
|
||||
end
|
||||
|
||||
--make sure we're near green coast
|
||||
if minetest.env:find_node_near(pos, 10,
|
||||
if minetest.find_node_near(pos, 10,
|
||||
{"default:dirt","default:dirt_with_grass"}) == nil then
|
||||
dbg_mobf.spawning_lvl2("MOBF: spawner " .. printpos(pos) .. " no dirt around")
|
||||
good = false
|
||||
@ -178,7 +178,7 @@ function mobf_spawn_in_shallow_water_entity(mob_name,mob_transform,spawning_data
|
||||
if surface then
|
||||
pos.y=surface - math.random(2,10)
|
||||
|
||||
local node_to_check = minetest.env:get_node(pos)
|
||||
local node_to_check = minetest.get_node(pos)
|
||||
|
||||
if node_to_check ~= nil and
|
||||
node_to_check.name == "default:water_source" or
|
||||
|
@ -67,7 +67,7 @@ function mobf_spawn_in_shadows(mob_name,mob_transform,spawning_data,environment)
|
||||
return
|
||||
end
|
||||
|
||||
local node_above = minetest.env:get_node(pos_above)
|
||||
local node_above = minetest.get_node(pos_above)
|
||||
|
||||
if mob_name == nil then
|
||||
minetest.log(LOGLEVEL_ERROR,"MOBF: Bug!!! mob name not available")
|
||||
@ -83,7 +83,7 @@ function mobf_spawn_in_shadows(mob_name,mob_transform,spawning_data,environment)
|
||||
if maxlight < 3 then
|
||||
|
||||
local newobject =
|
||||
minetest.env:add_entity(pos_above,mob_name .. "__default")
|
||||
minetest.add_entity(pos_above,mob_name .. "__default")
|
||||
|
||||
local newentity = mobf_find_entity(newobject)
|
||||
|
||||
@ -163,7 +163,7 @@ function mobf_spawn_in_shadows_entity(mob_name,mob_transform,spawning_data,envir
|
||||
|
||||
--check if own position is good
|
||||
local pos_below = {x=newpos.x,y=newpos.y-1,z=newpos.z}
|
||||
local node_below = minetest.env:get_node(pos_below)
|
||||
local node_below = minetest.get_node(pos_below)
|
||||
|
||||
|
||||
if not mobf_contains({ "default:stone",
|
||||
@ -180,7 +180,7 @@ function mobf_spawn_in_shadows_entity(mob_name,mob_transform,spawning_data,envir
|
||||
end
|
||||
|
||||
for i=0.0,1,0.1 do
|
||||
local light_val = minetest.env:get_node_light(pos,i)
|
||||
local light_val = minetest.get_node_light(pos,i)
|
||||
if light_val == nil or light_val > 6 then
|
||||
good = false
|
||||
reason = reason .. ":to much light"
|
||||
@ -242,7 +242,7 @@ function mobf_spawn_in_shadows_entity(mob_name,mob_transform,spawning_data,envir
|
||||
if surface then
|
||||
pos.y= surface -1
|
||||
|
||||
local node = minetest.env:get_node(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
if not mobf_contains({ "default:stone",
|
||||
"default:gravel",
|
||||
@ -254,7 +254,7 @@ function mobf_spawn_in_shadows_entity(mob_name,mob_transform,spawning_data,envir
|
||||
end
|
||||
|
||||
local pos_above = {x=pos.x,y=pos.y+1,z=pos.z}
|
||||
local node_above = minetest.env:get_node(pos_above)
|
||||
local node_above = minetest.get_node(pos_above)
|
||||
if not mobf_contains({"air"},node_above.name) then
|
||||
dbg_mobf.spawning_lvl3(
|
||||
"MOBF: node above ain't air but: " .. node_above.name)
|
||||
@ -263,7 +263,7 @@ function mobf_spawn_in_shadows_entity(mob_name,mob_transform,spawning_data,envir
|
||||
|
||||
--check if its always in shadows
|
||||
for i=0.0,1,0.1 do
|
||||
if minetest.env:get_node_light(pos_above,i) > 6 then
|
||||
if minetest.get_node_light(pos_above,i) > 6 then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
@ -63,7 +63,7 @@ function mobf_spawn_on_willow(mob_name,mob_transform,spawning_data,environment)
|
||||
return
|
||||
end
|
||||
|
||||
local node_above = minetest.env:get_node(pos_above)
|
||||
local node_above = minetest.get_node(pos_above)
|
||||
|
||||
if mob_name == nil then
|
||||
mobf_bug_warning(LOGLEVEL_ERROR,"MOBF: BUG!!! mob name not available")
|
||||
@ -72,7 +72,7 @@ function mobf_spawn_on_willow(mob_name,mob_transform,spawning_data,environment)
|
||||
if node_above.name == "air" then
|
||||
--print("Find mobs of same type around:"..mob_name.. " pop dens: ".. population_density)
|
||||
if mobf_mob_around(mob_name,mob_transform,pos,spawning_data.density,true) == 0 then
|
||||
local newobject = minetest.env:add_entity(pos_above,mob_name .. "__default")
|
||||
local newobject = minetest.add_entity(pos_above,mob_name .. "__default")
|
||||
|
||||
local newentity = mobf_find_entity(newobject)
|
||||
|
||||
|
@ -257,7 +257,7 @@ function spawning.replace_entity(entity,name,preserve)
|
||||
--removing is done after exiting lua!
|
||||
spawning.remove(entity,"replaced")
|
||||
|
||||
local newobject = minetest.env:add_entity(pos,name)
|
||||
local newobject = minetest.add_entity(pos,name)
|
||||
local newentity = mobf_find_entity(newobject)
|
||||
|
||||
if newentity ~= nil then
|
||||
@ -357,7 +357,7 @@ function spawning.spawn_and_check(name,suffix,pos,text)
|
||||
mobf_assert_backtrace(pos.y ~= nil)
|
||||
mobf_assert_backtrace(name ~= nil)
|
||||
mobf_assert_backtrace(suffix ~= nil)
|
||||
local newobject = minetest.env:add_entity(pos,name .. suffix)
|
||||
local newobject = minetest.add_entity(pos,name .. suffix)
|
||||
|
||||
if newobject then
|
||||
local newentity = mobf_find_entity(newobject)
|
||||
|
29
mobf/utils/error_handling.lua
Normal file
29
mobf/utils/error_handling.lua
Normal file
@ -0,0 +1,29 @@
|
||||
-------------------------------------------------------------------------------
|
||||
-- Mob Framework Mod by Sapier
|
||||
--
|
||||
-- You may copy, use, modify or do nearly anything except removing this
|
||||
-- copyright notice.
|
||||
-- And of course you are NOT allowed to pretend you have written it.
|
||||
--
|
||||
--! @file error_handling.lua
|
||||
--! @brief code required to do error handling
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2013-05-010
|
||||
--!
|
||||
-- Contact sapier a t gmx net
|
||||
-------------------------------------------------------------------------------
|
||||
--
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: mobf_assert_backtrace(value)
|
||||
--
|
||||
--! @brief assert in case value is false
|
||||
--
|
||||
--! @param value to evaluate
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_assert_backtrace(value)
|
||||
if value == false then
|
||||
print(debug.traceback("Current Callstack:\n"))
|
||||
assert(value)
|
||||
end
|
||||
end
|
@ -3,7 +3,7 @@
|
||||
--
|
||||
-- You may copy, use, modify or do nearly anything except removing this
|
||||
-- copyright notice.
|
||||
-- And of course you are NOT allow to pretend you have written it.
|
||||
-- And of course you are NOT allowed to pretend you have written it.
|
||||
--
|
||||
--! @file generic_functions.lua
|
||||
--! @brief generic functions used in many different places
|
||||
@ -185,10 +185,10 @@ function mobf_max_light_around(pos,distance,daytime)
|
||||
for z_run=pos.z-distance,pos.z+distance,1 do
|
||||
for x_run=pos.x-distance,pos.x+distance,1 do
|
||||
local current_pos = {x=x_run,y=y_run,z=z_run }
|
||||
local node = minetest.env:get_node(current_pos)
|
||||
local node = minetest.get_node(current_pos)
|
||||
|
||||
if node.name == "air" then
|
||||
local current_light = minetest.env:get_node_light(current_pos,daytime)
|
||||
local current_light = minetest.get_node_light(current_pos,daytime)
|
||||
|
||||
if current_light > max_light then
|
||||
max_light = current_light
|
||||
@ -219,7 +219,7 @@ function mobf_mob_around(mob_name,mob_transform,pos,range,ignore_playerspawned)
|
||||
|
||||
mobf_assert_backtrace(range ~= nil)
|
||||
|
||||
local objectlist = minetest.env:get_objects_inside_radius(pos,range)
|
||||
local objectlist = minetest.get_objects_inside_radius(pos,range)
|
||||
|
||||
if mob_transform == nil then
|
||||
mob_transform = ""
|
||||
@ -282,7 +282,7 @@ function mobf_spawner_around(mob_name,pos,range)
|
||||
local count = 0
|
||||
local objectcount = 0
|
||||
|
||||
local objectlist = minetest.env:get_objects_inside_radius(pos,range)
|
||||
local objectlist = minetest.get_objects_inside_radius(pos,range)
|
||||
|
||||
for index,value in pairs(objectlist) do
|
||||
|
||||
@ -325,7 +325,7 @@ end
|
||||
--! @return: true/false
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_line_of_sightX(pos1,pos2)
|
||||
return minetest.env:get_line_of_sight(pos1,pos2)
|
||||
return minetest.get_line_of_sight(pos1,pos2)
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
@ -354,7 +354,7 @@ function mobf_line_of_sight(pos1,pos2)
|
||||
y=pos1.y + (normalized_vector.y *i),
|
||||
z=pos1.z + (normalized_vector.z *i)}
|
||||
|
||||
local node = minetest.env:get_node(tocheck)
|
||||
local node = minetest.get_node(tocheck)
|
||||
|
||||
|
||||
if minetest.registered_nodes[node.name] == nil or
|
||||
@ -402,7 +402,7 @@ function mobf_air_above(pos,height)
|
||||
y = pos.y + 1,
|
||||
z = pos.z
|
||||
}
|
||||
local node_above = minetest.env:get_node(pos_above)
|
||||
local node_above = minetest.get_node(pos_above)
|
||||
|
||||
if node_above.name ~= "air" then
|
||||
return false
|
||||
@ -424,7 +424,7 @@ end
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_ground_distance(pos,media)
|
||||
|
||||
local node_to_check = minetest.env:get_node(pos)
|
||||
local node_to_check = minetest.get_node(pos)
|
||||
|
||||
local count = 0
|
||||
|
||||
@ -433,7 +433,7 @@ function mobf_ground_distance(pos,media)
|
||||
|
||||
count = count +1
|
||||
pos = {x=pos.x,y=pos.y-1,z=pos.z};
|
||||
node_to_check = minetest.env:get_node(pos)
|
||||
node_to_check = minetest.get_node(pos)
|
||||
end
|
||||
|
||||
return count
|
||||
@ -449,7 +449,7 @@ end
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_surface_distance(pos)
|
||||
|
||||
local node_to_check = minetest.env:get_node(pos)
|
||||
local node_to_check = minetest.get_node(pos)
|
||||
|
||||
local count = 0
|
||||
|
||||
@ -460,7 +460,7 @@ function mobf_surface_distance(pos)
|
||||
count = count +1
|
||||
|
||||
pos = {x=pos.x,y=pos.y-1,z=pos.z};
|
||||
node_to_check = minetest.env:get_node(pos)
|
||||
node_to_check = minetest.get_node(pos)
|
||||
end
|
||||
|
||||
return count
|
||||
@ -476,7 +476,7 @@ end
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_air_distance(pos)
|
||||
|
||||
local node_to_check = minetest.env:get_node(pos)
|
||||
local node_to_check = minetest.get_node(pos)
|
||||
|
||||
local count = 0
|
||||
|
||||
@ -486,7 +486,7 @@ function mobf_air_distance(pos)
|
||||
|
||||
count = count +1
|
||||
pos = {x=pos.x,y=pos.y+1,z=pos.z};
|
||||
node_to_check = minetest.env:get_node(pos)
|
||||
node_to_check = minetest.get_node(pos)
|
||||
end
|
||||
|
||||
if node_to_check.name == "air" then
|
||||
@ -506,13 +506,13 @@ end
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_above_water(pos)
|
||||
|
||||
local node_to_check = minetest.env:get_node(pos)
|
||||
local node_to_check = minetest.get_node(pos)
|
||||
|
||||
while node_to_check ~= nil and
|
||||
node_to_check.name == "air" do
|
||||
|
||||
pos = {x=pos.x,y=pos.y-1,z=pos.z};
|
||||
node_to_check = minetest.env:get_node(pos)
|
||||
node_to_check = minetest.get_node(pos)
|
||||
end
|
||||
|
||||
if node_to_check.name == "default:water_source" or
|
||||
@ -537,7 +537,7 @@ end
|
||||
function mobf_get_sunlight_surface(x,z, min_y, max_y)
|
||||
for runy = min_y, max_y,1 do
|
||||
local pos = { x=x,y=runy, z=z }
|
||||
local node_to_check = minetest.env:get_node(pos)
|
||||
local node_to_check = minetest.get_node(pos)
|
||||
|
||||
if node_to_check.name == "default:dirt_with_grass" then
|
||||
return pos.y
|
||||
@ -565,22 +565,25 @@ function mobf_get_surface(x,z, min_y, max_y)
|
||||
mobf_assert_backtrace(x ~= nil)
|
||||
mobf_assert_backtrace(z ~= nil)
|
||||
|
||||
if type(minetest.env.get_surface) == "function" then
|
||||
return minetest.env:get_surface({x=x,y=min_y,z=z},max_y-min_y)
|
||||
if type(minetest.get_surface) == "function" then
|
||||
local basepos = {x=x,y=min_y,z=z}
|
||||
local offset = max_y-min_y
|
||||
print("Values: " .. dump(basepos) .." " .. dump(offset))
|
||||
return minetest.get_surface(basepos,offset)
|
||||
end
|
||||
|
||||
local last_node = minetest.env:get_node({ x=x,y=min_y, z=z })
|
||||
for runy = min_y+1, max_y,1 do
|
||||
local pos = { x=x,y=runy, z=z }
|
||||
local node_to_check = minetest.env:get_node(pos)
|
||||
if node_to_check.name == "air" and
|
||||
last_node.name ~= "air" and
|
||||
last_node.mame ~= "ignore" then
|
||||
return pos.y
|
||||
end
|
||||
last_node = node_to_check
|
||||
end
|
||||
return nil
|
||||
local last_node = minetest.get_node({ x=x,y=min_y, z=z })
|
||||
for runy = min_y+1, max_y,1 do
|
||||
local pos = { x=x,y=runy, z=z }
|
||||
local node_to_check = minetest.get_node(pos)
|
||||
if node_to_check.name == "air" and
|
||||
last_node.name ~= "air" and
|
||||
last_node.mame ~= "ignore" then
|
||||
return pos.y
|
||||
end
|
||||
last_node = node_to_check
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
@ -593,7 +596,7 @@ end
|
||||
-------------------------------------------------------------------------------
|
||||
function entity_at_loaded_pos(pos)
|
||||
|
||||
local current_node = minetest.env:get_node(pos)
|
||||
local current_node = minetest.get_node(pos)
|
||||
|
||||
if current_node ~= nil then
|
||||
if current_node.name == "ignore" then
|
||||
@ -692,20 +695,4 @@ function mobf_is_pos(value)
|
||||
return true
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: mobf_assert_backtrace(value)
|
||||
--
|
||||
--! @brief assert in case value is false
|
||||
--
|
||||
--! @param value to evaluate
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_assert_backtrace(value)
|
||||
if value == false then
|
||||
print(debug.traceback("Current Callstack:\n"))
|
||||
assert(value)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
--!@}
|
||||
|
@ -45,7 +45,7 @@ function mobf_do_area_damage(pos,immune,damage_groups,range)
|
||||
--damage objects within inner blast radius
|
||||
mobf_assert_backtrace(type(range) ~= "table")
|
||||
|
||||
objs = minetest.env:get_objects_inside_radius(pos, range)
|
||||
objs = minetest.get_objects_inside_radius(pos, range)
|
||||
for k, obj in pairs(objs) do
|
||||
|
||||
--don't do damage to issuer
|
||||
@ -77,7 +77,7 @@ function mobf_do_node_damage(pos,immune_list,range,chance)
|
||||
for k=pos.z-range,pos.z+range,1 do
|
||||
--TODO create a little bit more sophisticated blast resistance
|
||||
if math.random() < chance then
|
||||
local toremove = minetest.env:get_node({x=i,y=j,z=k})
|
||||
local toremove = minetest.get_node({x=i,y=j,z=k})
|
||||
|
||||
if toremove ~= nil then
|
||||
local immune = false
|
||||
@ -92,7 +92,7 @@ function mobf_do_node_damage(pos,immune_list,range,chance)
|
||||
|
||||
|
||||
if immune ~= true then
|
||||
minetest.env:remove_node({x=i,y=j,z=k})
|
||||
minetest.remove_node({x=i,y=j,z=k})
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -158,15 +158,15 @@ function MOBF_FIREBALL_ENTITY.surfacefire(pos,range)
|
||||
for j=pos.y-range/2, pos.y+range/2, 1 do
|
||||
for k=pos.z-range/2, pos.z+range/2, 1 do
|
||||
|
||||
local current = minetest.env:get_node({x=i,y=j,z=k})
|
||||
local ontop = minetest.env:get_node({x=i,y=j+1,z=k})
|
||||
local current = minetest.get_node({x=i,y=j,z=k})
|
||||
local ontop = minetest.get_node({x=i,y=j+1,z=k})
|
||||
|
||||
--print("put fire? " .. printpos({x=i,y=j,z=k}) .. " " .. current.name .. " " ..ontop.name)
|
||||
|
||||
if (current.name ~= "air") and
|
||||
(current.name ~= "fire:basic_flame") and
|
||||
(ontop.name == "air") then
|
||||
minetest.env:set_node({x=i,y=j+1,z=k}, {name="fire:basic_flame"})
|
||||
minetest.set_node({x=i,y=j+1,z=k}, {name="fire:basic_flame"})
|
||||
end
|
||||
|
||||
end
|
||||
@ -189,11 +189,11 @@ end
|
||||
-------------------------------------------------------------------------------
|
||||
function MOBF_FIREBALL_ENTITY.on_step(self, dtime)
|
||||
local pos = self.object:getpos()
|
||||
local node = minetest.env:get_node(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
|
||||
--detect hit
|
||||
local objs=minetest.env:get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1)
|
||||
local objs=minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1)
|
||||
|
||||
local hit = false
|
||||
|
||||
@ -280,11 +280,11 @@ end
|
||||
-------------------------------------------------------------------------------
|
||||
function MOBF_PLASMABALL_ENTITY.on_step(self, dtime)
|
||||
local pos = self.object:getpos()
|
||||
local node = minetest.env:get_node(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
|
||||
--detect hit
|
||||
local objs=minetest.env:get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1)
|
||||
local objs=minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1)
|
||||
|
||||
local hit = false
|
||||
|
||||
@ -310,20 +310,20 @@ function MOBF_PLASMABALL_ENTITY.on_step(self, dtime)
|
||||
if node.name ~= "air" or
|
||||
hit then
|
||||
|
||||
--replace this loop by minetest.env:find_node_near?
|
||||
--replace this loop by minetest.find_node_near?
|
||||
--do node damage
|
||||
for i=pos.x-1, pos.x+1, 1 do
|
||||
for j=pos.y-1, pos.y+1, 1 do
|
||||
for k=pos.z-1,pos.z+1,1 do
|
||||
--TODO create a little bit more sophisticated blast resistance
|
||||
if math.random() < 0.5 then
|
||||
local toremove = minetest.env:get_node({x=i,y=j,z=k})
|
||||
local toremove = minetest.get_node({x=i,y=j,z=k})
|
||||
|
||||
if toremove ~= nil and
|
||||
toremove.name ~= "default:stone" and
|
||||
toremove.name ~= "default:cobble" then
|
||||
|
||||
minetest.env:remove_node({x=i,y=j,z=k})
|
||||
minetest.remove_node({x=i,y=j,z=k})
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -377,10 +377,10 @@ MOBF_ARROW_ENTITY={
|
||||
MOBF_ARROW_ENTITY.on_step = function(self, dtime)
|
||||
self.timer=self.timer+dtime
|
||||
local pos = self.object:getpos()
|
||||
local node = minetest.env:get_node(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
if self.timer>0.2 then
|
||||
local objs = minetest.env:get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
|
||||
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
|
||||
for k, obj in pairs(objs) do
|
||||
if obj:get_luaentity() ~= nil and
|
||||
obj ~= self.owner then
|
||||
@ -405,7 +405,7 @@ MOBF_ARROW_ENTITY.on_step = function(self, dtime)
|
||||
|
||||
if self.lastpos.x~=nil then
|
||||
if node.name ~= "air" then
|
||||
minetest.env:add_item(self.lastpos, 'mobf:arrow')
|
||||
minetest.add_item(self.lastpos, 'mobf:arrow')
|
||||
self.object:remove()
|
||||
end
|
||||
end
|
||||
|
File diff suppressed because it is too large
Load Diff
653
mobf_settings/init_old.lua
Normal file
653
mobf_settings/init_old.lua
Normal file
@ -0,0 +1,653 @@
|
||||
-------------------------------------------------------------------------------
|
||||
-- Mob Framework Settings Mod by Sapier
|
||||
--
|
||||
-- You may copy, use, modify or do nearly anything except removing this
|
||||
-- copyright notice.
|
||||
-- And of course you are NOT allow to pretend you have written it.
|
||||
--
|
||||
--! @file init.lua
|
||||
--! @brief settings gui for mobf
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2012-12-27
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
-------------------------------------------------------------------------------
|
||||
minetest.log("action","MOD: mobf_settings mod loading ... ")
|
||||
|
||||
mobf_settings = {}
|
||||
mobf_settings.version = "0.0.21"
|
||||
mobf_settings.max_list_page_num = 5
|
||||
mobf_settings.buttons = {}
|
||||
mobf_settings.buttons[1] = {}
|
||||
mobf_settings.buttons[2] = {}
|
||||
mobf_settings.tool_buttons = {}
|
||||
mobf_settings.tool_buttons[1] = {}
|
||||
mobf_settings.tool_buttons[2] = {}
|
||||
mobf_settings.menubutton = "button_exit[11,9.5;2,0.5;main; Exit]"
|
||||
mobf_settings.formspechandler = function(player,formspec)
|
||||
name = player:get_player_name()
|
||||
minetest.show_formspec(name,"mobf_settings:mainform",formspec)
|
||||
end
|
||||
|
||||
mobf_settings_debug = function () end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: get_animal_list
|
||||
--
|
||||
--! @brief get animal list form element for a page
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param page_number number of page to get list for
|
||||
--!
|
||||
--! @return formspec for page
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_settings.get_animal_list(page_number)
|
||||
|
||||
local mobf_mob_blacklist_string = minetest.world_setting_get("mobf_blacklist")
|
||||
local mobf_mobs_blacklisted = nil
|
||||
if mobf_mob_blacklist_string ~= nil then
|
||||
mobf_mobs_blacklisted = minetest.deserialize(mobf_mob_blacklist_string)
|
||||
end
|
||||
|
||||
local retval = ""
|
||||
local line = 3
|
||||
|
||||
local start_at = page_number -1
|
||||
|
||||
for i,val in ipairs(mobf_rtd.registred_mob) do
|
||||
|
||||
if i > (start_at*16) then
|
||||
if i <= (start_at*16 + 8) then
|
||||
retval = retval .. "label[1.0," .. line .. ";" .. val .. "]"
|
||||
local line_btn = line + 0.25
|
||||
if contains(mobf_mobs_blacklisted,val) then
|
||||
retval = retval .. "button[0.5," .. line_btn .. ";0.5,0.25;page"..page_number.."_enable_" .. val .. "; ]"
|
||||
else
|
||||
retval = retval .. "button[0.5," .. line_btn .. ";0.5,0.25;page"..page_number.."_disable_" .. val .. ";x]"
|
||||
end
|
||||
end
|
||||
|
||||
if i > (start_at*16 + 8 ) and
|
||||
i <= (start_at*16 + 16) then
|
||||
|
||||
local temp_line = line - (8*0.75)
|
||||
retval = retval .. "label[7.0," .. temp_line .. ";" .. val .. "]"
|
||||
|
||||
local line_btn = temp_line +0.25
|
||||
if contains(mobf_mobs_blacklisted,val) then
|
||||
retval = retval .. "button[6.5," .. line_btn .. ";0.5,0.25;page"..page_number.."_enable_" .. val .. "; ]"
|
||||
else
|
||||
retval = retval .. "button[6.5," .. line_btn .. ";0.5,0.25;page"..page_number.."_disable_" .. val .. ";x]"
|
||||
end
|
||||
end
|
||||
|
||||
line = line + 0.75
|
||||
end
|
||||
end
|
||||
|
||||
return retval
|
||||
end
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: contains
|
||||
--
|
||||
--! @brief check if element is in table
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param cur_table table to check for element
|
||||
--! @param element element to find in table
|
||||
--!
|
||||
--! @return true/false
|
||||
-------------------------------------------------------------------------------
|
||||
function contains(cur_table,element)
|
||||
|
||||
if cur_table == nil then
|
||||
--print("looking in empty table")
|
||||
return false
|
||||
end
|
||||
|
||||
--print("looking for " .. dump(element) .. " in " .. dump(cur_table))
|
||||
|
||||
for i,v in ipairs(cur_table) do
|
||||
if v == element then
|
||||
--print("found: " .. element .. " in table")
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
--print("didn't find " .. element)
|
||||
return false
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: contains_key
|
||||
--
|
||||
--! @brief check if table contains key
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param cur_table table to check for element
|
||||
--! @param element element to find in table
|
||||
--!
|
||||
--! @return true/false
|
||||
-------------------------------------------------------------------------------
|
||||
function get_value(cur_table,key)
|
||||
|
||||
if cur_table == nil or
|
||||
key == nil then
|
||||
--print("looking in empty table")
|
||||
return nil
|
||||
end
|
||||
|
||||
--print("looking for " .. dump(element) .. " in " .. dump(cur_table))
|
||||
|
||||
for k,v in pairs(cur_table) do
|
||||
if k == key then
|
||||
--print("found: " .. element .. " in table")
|
||||
return v
|
||||
end
|
||||
end
|
||||
|
||||
--print("didn't find " .. element)
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: get_known_animals_form
|
||||
--
|
||||
--! @brief create page to be shown
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param page name of page
|
||||
--!
|
||||
--! @return formspec of page
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_settings.get_main_settings_form(page)
|
||||
local retval = ""
|
||||
|
||||
for i=0,mobf_settings.max_list_page_num,1 do
|
||||
if page == "mobf_list_page" .. i then
|
||||
local nextpage = i +1
|
||||
local prevpage = i -1
|
||||
retval = "label[0.5,2.25;Known Mobs, Page ".. i .. "]"
|
||||
.."label[0.5,2.5;-------------------------------------------]"
|
||||
.."label[6.5,2.5;----------------------------------------]"
|
||||
.. mobf_settings.get_animal_list(i)
|
||||
|
||||
if i ~= mobf_settings.max_list_page_num then
|
||||
retval = retval .."button[3,9.5;2,0.5;mobf_list_page" .. nextpage ..";Next]"
|
||||
end
|
||||
if i ~= 1 then
|
||||
retval = retval .."button[0.5,9.5;2,0.5;mobf_list_page" .. prevpage ..";Prev]"
|
||||
end
|
||||
|
||||
return retval
|
||||
end
|
||||
end
|
||||
|
||||
if page == "mobf_restart_required" then
|
||||
retval = "label[0.5,2.25;This settings require to restart Game!]"
|
||||
.."label[0.5,2.5;-------------------------------------------]"
|
||||
.."label[6.5,2.5;----------------------------------------]"
|
||||
|
||||
retval = retval .. mobf_settings.draw_buttons(mobf_settings.buttons[1],0.5)
|
||||
retval = retval .. mobf_settings.draw_buttons(mobf_settings.buttons[2],6.5)
|
||||
|
||||
return retval
|
||||
end
|
||||
|
||||
if page == "mobf_tools" then
|
||||
retval = "label[0.5,2.25;Tools to be used with mobf]"
|
||||
.."label[0.5,2.5;-------------------------------------------]"
|
||||
.."label[6.5,2.5;----------------------------------------]"
|
||||
|
||||
retval = retval .. mobf_settings.draw_tool_buttons(mobf_settings.tool_buttons[1],0.5)
|
||||
retval = retval .. mobf_settings.draw_tool_buttons(mobf_settings.tool_buttons[2],6.5)
|
||||
|
||||
return retval
|
||||
end
|
||||
|
||||
return ""
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: draw_buttons
|
||||
--
|
||||
--! @brief get formspec for button drawing
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param buttons buttons to show
|
||||
--! @param xpos pos to show buttons at
|
||||
--!
|
||||
--! @return formspec for button list
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_settings.draw_buttons(buttons,xpos)
|
||||
local retval = ""
|
||||
|
||||
local y_pos = 3.75
|
||||
|
||||
for i=1,#buttons,1 do
|
||||
local current_setting = minetest.world_setting_get(buttons[i].value)
|
||||
|
||||
if buttons[i].inverted then
|
||||
if not current_setting then
|
||||
retval = retval .. "button[" .. xpos .. ",".. y_pos .. ";6,0.5;" ..
|
||||
"en_" .. buttons[i].value .. ";" ..
|
||||
buttons[i].text .. " is enabled]"
|
||||
else
|
||||
retval = retval .. "button[" .. xpos .. ",".. y_pos .. ";6,0.5;" ..
|
||||
"dis_" .. buttons[i].value .. ";" ..
|
||||
buttons[i].text .. " is disabled]"
|
||||
end
|
||||
|
||||
else
|
||||
if current_setting then
|
||||
retval = retval .. "button[" .. xpos .. ",".. y_pos .. ";6,0.5;" ..
|
||||
"dis_" .. buttons[i].value .. ";" ..
|
||||
buttons[i].text .. " is enabled]"
|
||||
else
|
||||
retval = retval .. "button[" .. xpos .. ",".. y_pos .. ";6,0.5;" ..
|
||||
"en_" .. buttons[i].value .. ";" ..
|
||||
buttons[i].text .. " is disabled]"
|
||||
end
|
||||
end
|
||||
|
||||
y_pos = y_pos + 0.75
|
||||
end
|
||||
|
||||
return retval
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: draw_tool_buttons
|
||||
--
|
||||
--! @brief get formspec for button drawing
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param buttons buttons to show
|
||||
--! @param xpos pos to show buttons at
|
||||
--!
|
||||
--! @return formspec for button list
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_settings.draw_tool_buttons(buttons,xpos)
|
||||
local retval = ""
|
||||
|
||||
local y_pos = 3.75
|
||||
|
||||
for i=1,#buttons,1 do
|
||||
|
||||
retval = retval .. "button[" .. xpos .. ",".. y_pos .. ";6,0.5;" ..
|
||||
buttons[i].id .. ";" ..
|
||||
buttons[i].text .."]"
|
||||
|
||||
y_pos = y_pos + 0.75
|
||||
end
|
||||
|
||||
return retval
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: handle_mob_en_disable_button
|
||||
--
|
||||
--! @brief handle press of en_disable button for a mob
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param fields
|
||||
--!
|
||||
--! @return
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_settings.handle_mob_en_disable_button(fields)
|
||||
for i,val in ipairs(mobf_rtd.registred_mob) do
|
||||
|
||||
local page = nil
|
||||
|
||||
for i = 0 , 5 , 1 do
|
||||
if fields["page".. i .. "_enable_" .. val] ~= nil then
|
||||
local mobf_mob_blacklist_string = minetest.world_setting_get("mobf_blacklist")
|
||||
local mobf_mobs_blacklisted = nil
|
||||
if mobf_mob_blacklist_string ~= nil then
|
||||
mobf_mobs_blacklisted = minetest.deserialize(mobf_mob_blacklist_string)
|
||||
end
|
||||
|
||||
if mobf_mobs_blacklisted == nil then
|
||||
mobf_settings_debug("MOBF_SETTINGS: trying to enable mob but no mobs were blacklisted!?")
|
||||
else
|
||||
|
||||
local new_blacklist = {}
|
||||
|
||||
for i,v in ipairs(mobf_mobs_blacklisted) do
|
||||
if v ~= val then
|
||||
table.insert(new_blacklist,v)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.world_setting_set("mobf_blacklist",minetest.serialize(new_blacklist))
|
||||
mobf_settings_debug("MOBF_SETTINGS: Enabling: " .. val .. " blacklist is now: " .. dump(new_blacklist))
|
||||
end
|
||||
page = i
|
||||
end
|
||||
end
|
||||
|
||||
for i = 0 , 5 , 1 do
|
||||
if fields["page".. i .. "_disable_" .. val] ~= nil then
|
||||
|
||||
local mobf_mob_blacklist_string = minetest.world_setting_get("mobf_blacklist")
|
||||
local mobf_mobs_blacklisted = nil
|
||||
if mobf_mob_blacklist_string ~= nil then
|
||||
mobf_mobs_blacklisted = minetest.deserialize(mobf_mob_blacklist_string)
|
||||
end
|
||||
|
||||
if mobf_mobs_blacklisted == nil then
|
||||
mobf_mobs_blacklisted = {}
|
||||
end
|
||||
|
||||
table.insert(mobf_mobs_blacklisted,val)
|
||||
|
||||
minetest.world_setting_set("mobf_blacklist",minetest.serialize(mobf_mobs_blacklisted))
|
||||
page = i
|
||||
mobf_settings_debug("MOBF_SETTINGS: Disabling: " .. val)
|
||||
end
|
||||
end
|
||||
|
||||
if page ~= nil then
|
||||
return "mobf_list_page" .. page
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: handle_config_changed_button
|
||||
--
|
||||
--! @brief handle press of a settings button
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param fields
|
||||
--!
|
||||
--! @return
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_settings.handle_config_changed_button(fields)
|
||||
|
||||
local config_setting = nil
|
||||
local enable = false
|
||||
|
||||
for j=1,2,1 do
|
||||
for i=1,#mobf_settings.buttons[j],1 do
|
||||
local fieldname = "en_" .. mobf_settings.buttons[j][i].value
|
||||
if fields[fieldname] ~= nil then
|
||||
config_setting = mobf_settings.buttons[j][i]
|
||||
enable = true
|
||||
break
|
||||
end
|
||||
|
||||
fieldname = "dis_" .. mobf_settings.buttons[j][i].value
|
||||
if fields[fieldname] ~= nil then
|
||||
config_setting = mobf_settings.buttons[j][i]
|
||||
enable = false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if config_setting ~= nil then
|
||||
mobf_settings_debug("MOBF_SETTINGS: detected changed value " .. config_setting.value)
|
||||
if enable then
|
||||
minetest.world_setting_set(config_setting.value,"true")
|
||||
else
|
||||
minetest.world_setting_set(config_setting.value,"false")
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: handle_tool_button
|
||||
--
|
||||
--! @brief handle press of a settings button
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param player whoever clicked the button
|
||||
--! @param fields
|
||||
--!
|
||||
--! @return
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_settings.handle_tool_button(player,fields)
|
||||
|
||||
for i=1,2,1 do
|
||||
for j=1,#mobf_settings.tool_buttons[i],1 do
|
||||
local id = nil
|
||||
|
||||
if mobf_settings.tool_buttons[i][j] ~= nil then
|
||||
id = mobf_settings.tool_buttons[i][j].id
|
||||
end
|
||||
|
||||
local value = get_value(fields,id)
|
||||
if value ~= nil then
|
||||
|
||||
if type(mobf_settings.tool_buttons[i][j].param) == "function" then
|
||||
mobf_settings.tool_buttons[i][j].param(player,fields)
|
||||
else
|
||||
mobf_settings_debug("MOBF_SETTINGS: invalid use of tool_button")
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: get_formspec
|
||||
--
|
||||
--! @brief generate page form for mobf_settings
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param player player to create page for
|
||||
--! @param page pagename to create
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_settings.get_formspec(player,page)
|
||||
local version = "< 1.4.5"
|
||||
|
||||
if (type(mobf_get_version) == "function") then
|
||||
version = mobf_get_version()
|
||||
end
|
||||
|
||||
local playername = player:get_player_name()
|
||||
|
||||
if minetest.check_player_privs(playername, {mobfw_admin=true}) then
|
||||
local pageform = mobf_settings.get_main_settings_form(page)
|
||||
|
||||
return "size[13,10]"
|
||||
..mobf_settings.menubutton
|
||||
.."button[0.5,0.75;3,0.5;mobf_list_page1; Known Mobs ]"
|
||||
.."button[4,0.75;3,0.5;mobf_restart_required; Settings ]"
|
||||
.."button[7.5,0.75;3,0.5;mobf_tools; Tools ]"
|
||||
.."label[5.5,0;MOBF " .. version .. "]"
|
||||
.. pageform
|
||||
else
|
||||
local pageform = mobf_settings.get_main_settings_form("mobf_tools")
|
||||
return "size[13,10]"
|
||||
..mobf_settings.menubutton
|
||||
.."label[0.5,0.75;You are not allowed to change any setting!]"
|
||||
.."label[5.5,0;MOBF " .. version .. "]"
|
||||
..pageform
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: set_mob_list_page(fields)
|
||||
--
|
||||
--! @brief check if requested page is a list page and show it
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @oaram player
|
||||
--! @param fields data for callback
|
||||
--
|
||||
--! @return true if handled false if not
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_settings.set_mob_list_page(player,fields)
|
||||
if fields.mobf then
|
||||
mobf_settings.formspechandler(player, mobf_settings.get_formspec(player,"mobf_list_page1"))
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
for i=1,5,1 do
|
||||
local namestring = "mobf_list_page" .. i
|
||||
|
||||
if fields[namestring] ~= nil then
|
||||
mobf_settings.formspechandler(player, mobf_settings.get_formspec(player,namestring))
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: register_config_button(index,configvalue,buttontext,inverted)
|
||||
--
|
||||
--! @brief register a button to be shown on config page
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param index column to draw button at
|
||||
--! @param configvalue config value to change by this button
|
||||
--! @param buttontext to set for this value
|
||||
--! @param inverted invert enable/disable text on button
|
||||
--
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_settings.register_config_button(index,configvalue,buttontext,inverted)
|
||||
|
||||
local toadd = {
|
||||
value = configvalue,
|
||||
text = buttontext,
|
||||
inverted = inverted,
|
||||
}
|
||||
|
||||
table.insert(mobf_settings.buttons[index],toadd)
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: register_tool_button(index,id,buttontext,param)
|
||||
--
|
||||
--! @brief register a button to be shown on config page
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param index column to draw button at
|
||||
--! @param id to use for button (has to be unique)
|
||||
--! @param buttontext to set for this value
|
||||
--! @param param function to call
|
||||
--
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_settings.register_tool_button(index,id,buttontext,param)
|
||||
|
||||
local toadd = {
|
||||
param = param,
|
||||
text = buttontext,
|
||||
id = id,
|
||||
}
|
||||
|
||||
table.insert(mobf_settings.tool_buttons[index],toadd)
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- register handler for pressed buttons
|
||||
------------------------------------------------------------------------------
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
--if one of your page buttons is pressed show another moblist page
|
||||
if mobf_settings.set_mob_list_page(player,fields) then
|
||||
mobf_settings_debug("mobf_settings: abort button processing")
|
||||
return true
|
||||
end
|
||||
|
||||
--handle tool buttons (no redraw of menu as this could be done by fct
|
||||
if mobf_settings.handle_tool_button(player,fields) then
|
||||
mobf_settings_debug("mobf_settings: abort button processing")
|
||||
return true
|
||||
end
|
||||
|
||||
--handle menu buttons
|
||||
if mobf_settings.handle_config_changed_button(fields) or
|
||||
fields.mobf_tools ~= nil or fields.mobf_restart_required ~= nil then
|
||||
local page = "mobf_restart_required"
|
||||
if fields.mobf_tools ~= nil then
|
||||
page = "mobf_tools"
|
||||
mobf_settings_debug("MOBF_SETTINGS: show tool page")
|
||||
else
|
||||
mobf_settings_debug("MOBF_SETTINGS: settings have been changed, show settings page: " .. dump(fields.mobf_restart_required))
|
||||
end
|
||||
|
||||
mobf_settings.formspechandler(player, mobf_settings.get_formspec(player,page))
|
||||
mobf_settings_debug("mobf_settings: abort button processing")
|
||||
return true
|
||||
end
|
||||
|
||||
local blacklist_changed_page = mobf_settings.handle_mob_en_disable_button(fields)
|
||||
|
||||
if blacklist_changed_page ~= nil then
|
||||
mobf_settings.formspechandler(player, mobf_settings.get_formspec(player,blacklist_changed_page))
|
||||
mobf_settings_debug("mobf_settings: abort button processing")
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end)
|
||||
|
||||
|
||||
--register chatcommand
|
||||
minetest.register_chatcommand("mobf_settings",
|
||||
{
|
||||
params = "",
|
||||
description = "show mobf settings" ,
|
||||
privs = {},
|
||||
func = function(name,param)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
mobf_settings.formspechandler(player,mobf_settings.get_formspec(player,"mobf_list_page1"))
|
||||
end
|
||||
})
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- register mobf_settings buttons
|
||||
------------------------------------------------------------------------------
|
||||
mobf_settings.register_config_button(1,"mobf_disable_animal_spawning","Animal spawning",true)
|
||||
mobf_settings.register_config_button(1,"mobf_disable_3d_mode","3D mode",true)
|
||||
mobf_settings.register_config_button(1,"mobf_animal_spawning_secondary","Secondary spawning algorithm",false)
|
||||
mobf_settings.register_config_button(1,"mobf_delete_disabled_mobs","Delete disabled mob entities",false)
|
||||
mobf_settings.register_config_button(1,"mobf_log_bug_warnings","Show noisy bug warnings",false)
|
||||
mobf_settings.register_config_button(1,"vombie_3d_burn_animation_enabled","Vombie 3d burn animation",false)
|
||||
mobf_settings.register_config_button(1,"mobf_log_removed_entities","Log all removed mobs",false)
|
||||
mobf_settings.register_config_button(1,"mobf_grief_protection","Disallow mob stealing",false)
|
||||
mobf_settings.register_config_button(2,"mobf_lifebar","lifebar",false)
|
||||
|
||||
mobf_settings.register_tool_button(1,"give_pathmaker_tool","Give pathmaker tool",
|
||||
function(player)
|
||||
player:get_inventory():add_item("main", "mobf:path_marker 1")
|
||||
end)
|
||||
|
||||
mobf_settings.register_tool_button(1,"show_mobstore","Show preserved mobs",
|
||||
function(player)
|
||||
local name = player:get_player_name()
|
||||
|
||||
if name ~= nil then
|
||||
mob_preserve.handle_command(name,nil)
|
||||
end
|
||||
end)
|
||||
|
||||
mobf_settings.register_tool_button(1,"show_pathmanager","Manage paths",
|
||||
function(player)
|
||||
local name = player:get_player_name()
|
||||
|
||||
if name ~= nil then
|
||||
mobf_path.show_manage_menu(name,nil)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.log("action","MOD: mobf_settings mod version "..mobf_settings.version.." loaded")
|
@ -9,7 +9,7 @@ minetest.register_craftitem("trap:undead", {
|
||||
if pointed_thing.type == "node" then
|
||||
local pos = pointed_thing.above
|
||||
|
||||
local newobject = minetest.env:add_entity(pos,"trap:undead_ent")
|
||||
local newobject = minetest.add_entity(pos,"trap:undead_ent")
|
||||
|
||||
item:take_item()
|
||||
|
||||
@ -43,7 +43,7 @@ minetest.register_entity(":trap:undead_ent",
|
||||
|
||||
local pos = self.object:getpos()
|
||||
|
||||
local objectlist = minetest.env:get_objects_inside_radius(pos,2)
|
||||
local objectlist = minetest.get_objects_inside_radius(pos,2)
|
||||
|
||||
for index,value in pairs(objectlist) do
|
||||
|
||||
@ -57,7 +57,7 @@ minetest.register_entity(":trap:undead_ent",
|
||||
|
||||
self.object:remove()
|
||||
|
||||
minetest.env:add_node(pos,{name="trap:cought_vombie"})
|
||||
minetest.add_node(pos,{name="trap:cought_vombie"})
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user