ABM optimizations, doors cleanup, sponge small fixes

This commit is contained in:
MoNTE48 2019-06-29 01:46:24 +02:00
parent 6c594aa26a
commit 35d9c39631
7 changed files with 94 additions and 146 deletions

View File

@ -1,33 +1,41 @@
local jobs = {}
local time = 0.0
local time_next = math.huge
core.register_globalstep(function(dtime)
time = time + dtime
if #jobs < 1 then
if time < time_next then
return
end
time_next = math.huge
-- Iterate backwards so that we miss any new timers added by
-- a timer callback, and so that we don't skip the next timer
-- in the list if we remove one.
-- a timer callback.
for i = #jobs, 1, -1 do
local job = jobs[i]
if time >= job.expire then
core.set_last_run_mod(job.mod_origin)
job.func(unpack(job.arg))
table.remove(jobs, i)
local jobs_l = #jobs
jobs[i] = jobs[jobs_l]
jobs[jobs_l] = nil
elseif job.expire < time_next then
time_next = job.expire
end
end
end)
function core.after(after, func, ...)
assert(tonumber(after) and type(func) == "function",
"Invalid core.after invocation")
"Invalid minetest.after invocation")
local expire = time + after
jobs[#jobs + 1] = {
func = func,
expire = time + after,
expire = expire,
arg = {...},
mod_origin = core.get_last_run_mod()
}
end
time_next = math.min(time_next, expire)
end

View File

@ -187,7 +187,7 @@ end)
local time = 0
local update_time = 0.5
local update_time = 1
core.register_globalstep(function(dtime)
time = time + dtime
if time > update_time then

View File

@ -161,8 +161,8 @@ if minetest.settings:get_bool("enable_lavacooling") ~= false then
label = "Lava cooling",
nodenames = {"default:lava_source", "default:lava_flowing"},
neighbors = {"group:cools_lava", "group:water"},
interval = 2,
chance = 2,
interval = 4,
chance = 1,
catch_up = false,
action = function(...)
default.cool_lava(...)
@ -249,8 +249,8 @@ minetest.register_abm({
label = "Grow cactus",
nodenames = {"default:cactus"},
neighbors = {"group:sand"},
interval = 12,
chance = 83,
interval = 15,
chance = 75,
action = function(...)
default.grow_cactus(...)
end
@ -260,8 +260,8 @@ minetest.register_abm({
label = "Grow sugarcane",
nodenames = {"default:sugarcane"},
neighbors = {"default:dirt", "default:dirt_with_grass", "default:sand"},
interval = 14,
chance = 71,
interval = 15,
chance = 70,
action = function(...)
default.grow_papyrus(...)
end
@ -425,8 +425,8 @@ minetest.register_abm({
"group:dry_grass",
"default:snow",
},
interval = 6,
chance = 50,
interval = 10,
chance = 25,
catch_up = false,
action = function(pos, node)
-- Check for darkness: night, shadow or under a light-blocking node
@ -466,8 +466,8 @@ minetest.register_abm({
minetest.register_abm({
label = "Grass covered",
nodenames = {"group:spreading_dirt_type"},
interval = 8,
chance = 50,
interval = 10,
chance = 40,
catch_up = false,
action = function(pos, node)
local above = {x = pos.x, y = pos.y + 1, z = pos.z}

View File

@ -878,18 +878,20 @@ minetest.register_node("default:cactus", {
},
})
minetest.register_abm({
label = "Cactus damage",
nodenames = {"default:cactus"},
interval = 1,
chance = 1,
action = function(pos)
local players = minetest.get_objects_inside_radius(pos, 1)
for i, player in ipairs(players) do
player:set_hp(player:get_hp() - 2)
end
end,
})
if not minetest.settings:get_bool("creative_mode") then
minetest.register_abm({
label = "Cactus damage",
nodenames = {"default:cactus"},
interval = 1,
chance = 1,
action = function(pos)
local players = minetest.get_objects_inside_radius(pos, 1)
for i, player in ipairs(players) do
player:set_hp(player:get_hp() - 2)
end
end,
})
end
minetest.register_node("default:sugarcane", {
description = "Sugarcane",

View File

@ -68,38 +68,6 @@ function doors.get(pos)
end
end
-- this hidden node is placed on top of the bottom, and prevents
-- nodes from being placed in the top half of the door.
minetest.register_node("doors:hidden", {
description = "Hidden Door Segment",
-- can't use airlike otherwise falling nodes will turn to entities
-- and will be forever stuck until door is removed.
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
-- has to be walkable for falling nodes to stop falling.
walkable = true,
pointable = false,
diggable = false,
buildable_to = false,
floodable = false,
drop = "",
groups = {not_in_creative_inventory = 1},
on_blast = function() end,
tiles = {"blank.png"},
-- 1px transparent block inside door hinge near node top.
node_box = {
type = "fixed",
fixed = {-15/32, 13/32, -15/32, -13/32, 1/2, -13/32},
},
-- collision_box needed otherise selection box would be full node size
collision_box = {
type = "fixed",
fixed = {-15/32, 13/32, -15/32, -13/32, 1/2, -13/32},
},
})
-- table used to aid door opening/closing
local transform = {
{
@ -281,10 +249,8 @@ function doors.register(name, def)
if minetest.get_item_group(minetest.get_node(aside).name, "door") == 1 then
state = state + 2
minetest.set_node(pos, {name = name .. "_b", param2 = dir})
minetest.set_node(above, {name = "doors:hidden", param2 = (dir + 3) % 4})
else
minetest.set_node(pos, {name = name .. "_a", param2 = dir})
minetest.set_node(above, {name = "doors:hidden", param2 = dir})
end
local meta = minetest.get_meta(pos)
@ -382,8 +348,6 @@ function doors.register(name, def)
else
def.on_blast = function(pos, intensity)
minetest.remove_node(pos)
-- hidden node doesn't get blasted away.
minetest.remove_node({x = pos.x, y = pos.y + 1, z = pos.z})
return {name}
end
end
@ -413,95 +377,72 @@ function doors.register(name, def)
end
doors.register("door_wood", {
tiles = {{ name = "doors_door_wood.png", backface_culling = true }},
description = "Wooden Door",
inventory_image = "doors_item_wood.png",
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
recipe = {
{"group:wood", "group:wood"},
{"group:wood", "group:wood"},
{"group:wood", "group:wood"},
}
tiles = {{ name = "doors_door_wood.png", backface_culling = true }},
description = "Wooden Door",
inventory_image = "doors_item_wood.png",
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
recipe = {
{"group:wood", "group:wood"},
{"group:wood", "group:wood"},
{"group:wood", "group:wood"},
}
})
doors.register("door_steel", {
tiles = {{name = "doors_door_steel.png", backface_culling = true}},
description = "Steel Door",
inventory_image = "doors_item_steel.png",
protected = true,
groups = {cracky = 1, level = 2},
sounds = default.node_sound_metal_defaults(),
sound_open = "doors_steel_door_open",
sound_close = "doors_steel_door_close",
recipe = {
{"default:steel_ingot", "default:steel_ingot"},
{"default:steel_ingot", "default:steel_ingot"},
{"default:steel_ingot", "default:steel_ingot"},
}
tiles = {{name = "doors_door_steel.png", backface_culling = true}},
description = "Steel Door",
inventory_image = "doors_item_steel.png",
protected = true,
groups = {cracky = 1, level = 2},
sounds = default.node_sound_metal_defaults(),
sound_open = "doors_steel_door_open",
sound_close = "doors_steel_door_close",
recipe = {
{"default:steel_ingot", "default:steel_ingot"},
{"default:steel_ingot", "default:steel_ingot"},
{"default:steel_ingot", "default:steel_ingot"},
}
})
-- Aliases
local doors_aliases = {
{"acacia_b_1", "door_wood_a"},
{"acacia_b_2", "door_wood_b"},
{"acacia_t_1", "hidden"},
{"acacia_t_2", "hidden"},
{"birch_b_1", "door_wood_a"},
{"birch_b_2", "door_wood_b"},
{"birch_t_1", "hidden"},
{"birch_t_2", "hidden"},
{"dark_oak_b_1", "door_wood_a"},
{"dark_oak_b_2", "door_wood_b"},
{"dark_oak_t_1", "hidden"},
{"dark_oak_t_2", "hidden"},
{"jungle_b_1", "door_wood_a"},
{"jungle_b_2", "door_wood_b"},
{"jungle_t_1", "hidden"},
{"jungle_t_2", "hidden"},
{"wood_b_1", "door_wood_a"},
{"wood_b_2", "door_wood_b"},
{"wood_t_1", "hidden"},
{"wood_t_2", "hidden"},
{"steel_b_1", "door_steel_a"},
{"steel_b_2", "door_steel_b"},
{"steel_t_1", "hidden"},
{"steel_t_2", "hidden"},
{"acacia_b_1", "doors:door_wood_a"},
{"acacia_b_2", "doors:door_wood_b"},
{"acacia_t_1", "air"},
{"acacia_t_2", "air"},
{"birch_b_1", "doors:door_wood_a"},
{"birch_b_2", "doors:door_wood_b"},
{"birch_t_1", "air"},
{"birch_t_2", "air"},
{"dark_oak_b_1", "doors:door_wood_a"},
{"dark_oak_b_2", "doors:door_wood_b"},
{"dark_oak_t_1", "air"},
{"dark_oak_t_2", "air"},
{"jungle_b_1", "doors:door_wood_a"},
{"jungle_b_2", "doors:door_wood_b"},
{"jungle_t_1", "air"},
{"jungle_t_2", "air"},
{"wood_b_1", "doors:door_wood_a"},
{"wood_b_2", "doors:door_wood_b"},
{"wood_t_1", "air"},
{"wood_t_2", "air"},
{"steel_b_1", "doors:door_steel_a"},
{"steel_b_2", "doors:door_steel_b"},
{"steel_t_1", "air"},
{"steel_t_2", "air"},
}
for i = 1, #doors_aliases do
local old, new = unpack(doors_aliases[i])
minetest.register_alias("doors:door_" .. old, "doors:" .. new)
minetest.register_alias("doors:door_" .. old, new)
end
minetest.register_alias("doors:door_acacia", "doors:door_wood")
minetest.register_alias("doors:door_birch", "doors:door_wood")
minetest.register_alias("doors:door_dark_oak", "doors:door_wood")
minetest.register_alias("doors:door_jungle", "doors:door_wood")
-- Capture mods using the old API as best as possible.
function doors.register_door(name, def)
if def.only_placer_can_open then
def.protected = true
end
def.only_placer_can_open = nil
local i = name:find(":")
local modname = name:sub(1, i - 1)
if not def.tiles then
if def.protected then
def.tiles = {{name = "doors_door_steel.png", backface_culling = true}}
else
def.tiles = {{name = "doors_door_wood.png", backface_culling = true}}
end
minetest.log("warning", modname .. " registered door \"" .. name .. "\" " ..
"using deprecated API method \"doors.register_door()\" but " ..
"did not provide the \"tiles\" parameter. A fallback tiledef " ..
"will be used instead.")
end
doors.register(name, def)
end
minetest.register_alias("doors:hidden", "air")
---- Trapdoor ----

View File

@ -152,8 +152,8 @@ end
minetest.register_abm({
label = "Flower spread",
nodenames = {"group:flora"},
interval = 13,
chance = 300,
interval = 20,
chance = 200,
action = function(...)
flowers.flower_spread(...)
end,
@ -229,8 +229,8 @@ end
minetest.register_abm({
label = "Mushroom spread",
nodenames = {"flowers:mushroom_brown", "flowers:mushroom_red"},
interval = 11,
chance = 150,
interval = 20,
chance = 100,
action = function(...)
flowers.mushroom_spread(...)
end,

View File

@ -1,4 +1,4 @@
local area = 2
local area = 3
local destruct = function(pos) -- removing the air-like nodes
for x = pos.x-area, pos.x+area do
@ -15,7 +15,6 @@ end
minetest.register_node("sponge:liquid_stop", { -- air-like node
description = "liquid blocker for sponges",
drawtype = "airlike",
drop = "",
groups = {not_in_creative_inventory = 1},
@ -31,7 +30,6 @@ minetest.register_node("sponge:sponge", { -- dry sponge
description = "Sponge",
tiles = {"sponge_sponge.png"},
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, flammable = 3},
sounds = default.node_sound_dirt_defaults(),
after_place_node = function(pos, placer, itemstack, pointed_thing)
local name = placer:get_player_name()
@ -56,7 +54,7 @@ minetest.register_node("sponge:sponge", { -- dry sponge
end
end
if count > 2 then -- turns wet if it removed more than 2 nodes
if count > area then -- turns wet if it removed more than * nodes
minetest.set_node(pos, {name="sponge:wet_sponge"})
end
end
@ -70,7 +68,6 @@ minetest.register_node("sponge:wet_sponge", { -- wet sponge
description = "Wet Sponge",
tiles = {"sponge_sponge_wet.png"},
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, flammable = 3, not_in_creative_inventory = 1},
sounds = default.node_sound_dirt_defaults(),
on_destruct = destruct
})