some cleaning and improvement

replace nodemeta by context, localize vector.add, some cleaning, remove commented code,
template: update content
clockgen: fix owner = "", move /clockgen in init
constructor: improve constructor_process
enviro: fix player_sneak init value
keypad: improve repeat code, add action_off
machines_configuration: reset keypad count
technic_power: fix owner = "" for generator (initialize step)
This commit is contained in:
waxtatect 2022-11-02 23:34:50 +01:00
parent 6bf32eaa18
commit 615ba06213
19 changed files with 393 additions and 339 deletions

View File

@ -100,11 +100,7 @@ local function normalize(item_list)
end
local function on_output_change(pos, inventory, stack)
if not stack then
inventory:set_stack("output", 1, ItemStack(""))
-- inventory:set_list("output", {}) -- using saved map, it crashes the server... but why
inventory:set_list("recipe", {})
else
if stack then
local input = minetest.get_craft_recipe(stack:get_name())
if not input.items or input.type ~= "normal" then return end
local items, width = normalize(input.items), input.width
@ -118,7 +114,11 @@ local function on_output_change(pos, inventory, stack)
end
width_idx = (width_idx < 3) and (width_idx + 1) or 1
end
else
-- we'll set the output slot in after_recipe_change to the actual result of the new recipe
inventory:set_stack("output", 1, ItemStack(""))
-- inventory:set_list("output", {}) -- using saved map, it crashes the server... but why
inventory:set_list("recipe", {})
end
after_recipe_change(pos, inventory)
end
@ -285,4 +285,4 @@ if basic_machines.settings.register_crafts then
{"default:steel_ingot", "default:mese_crystal", "default:steel_ingot"}
}
})
end
end

View File

@ -9,8 +9,8 @@ local F, S = basic_machines.F, basic_machines.S
local machines_TTL = basic_machines.properties.machines_TTL
local machines_minstep = basic_machines.properties.machines_minstep
local machines_timer = basic_machines.properties.machines_timer
local max_range = basic_machines.properties.max_range
local max_balls = math.max(0, basic_machines.settings.max_balls)
local max_range = basic_machines.properties.max_range
local max_damage = minetest.PLAYER_MAX_HP_DEFAULT / 2 -- player health 20
-- to be used with bounce setting 2 in ball spawner:
-- 1: bounce in x direction, 2: bounce in z direction, otherwise it bounces in y direction
@ -69,7 +69,6 @@ minetest.register_entity("basic_machines:ball", {
_owner = "",
_elasticity = 0.9, -- speed gets multiplied by this after bounce
_is_arrow = false, -- advanced mob protection
-- _lastpos = {x = 0, y = 0, z = 0}, -- last not-colliding position
_timer = 0,
_speed = ball_default.speed, -- velocity when punched
@ -107,7 +106,6 @@ minetest.register_entity("basic_machines:ball", {
end
if not walkable then
-- self._lastpos = pos
if self._hurt ~= 0 then -- check for colliding nearby objects
local objects = minetest.get_objects_inside_radius(pos, 2)
if #objects > 1 then
@ -237,6 +235,7 @@ minetest.register_entity("basic_machines:ball", {
end
end
local bpos = vector.add(pos, vector.multiply(n, 0.2)) -- point placed a bit further away from box
local elasticity = self._elasticity
-- bounce
@ -248,9 +247,7 @@ minetest.register_entity("basic_machines:ball", {
v.z = -elasticity * v.z
end
local bpos = vector.add(pos, vector.multiply(n, 0.2)) -- point placed a bit further away from box
self.object:set_pos(bpos) -- place object at last known outside point
self.object:set_velocity(v)
minetest.sound_play("default_dig_cracky", {pos = pos, gain = 1, max_hear_distance = 8}, true)
@ -364,7 +361,6 @@ minetest.register_node("basic_machines:ball_spawner", {
local stack; local inv = digger:get_inventory()
if (digger:get_player_control() or {}).sneak then
if basic_machines.creative(digger:get_player_name()) then return end
stack = ItemStack("basic_machines:ball_spawner")
else
local meta = oldmetadata["fields"]

View File

@ -1,21 +1,7 @@
local S = basic_machines.S
local machines_TTL = basic_machines.properties.machines_TTL
local machines_timer = basic_machines.properties.machines_timer
-- test: toggle machine running with clockgen/keypad repeats, useful for debugging
-- i.e. seeing how machines running affect server performance
minetest.register_chatcommand("clockgen", {
description = S("Toggle clock generator/keypad repeats"),
privs = {privs = true},
func = function(name, _)
if basic_machines.properties.clockgen == 0 then
basic_machines.properties.clockgen = 1
else
basic_machines.properties.clockgen = 0
end
minetest.chat_send_player(name, S("clockgen set to @1", basic_machines.properties.clockgen))
end
})
local no_clock = basic_machines.properties.no_clock
minetest.register_abm({
label = "[basic_machines] Clock Generator",
@ -25,7 +11,7 @@ minetest.register_abm({
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
if basic_machines.properties.clockgen == 0 then return end
if no_clock then return end
local meta = minetest.get_meta(pos)
-- owner online or machines privilege
if minetest.get_player_by_name(meta:get_string("owner")) or meta:get_int("machines") == 1 then
@ -68,7 +54,8 @@ minetest.register_node("basic_machines:clockgen", {
end,
can_dig = function(pos, player)
return minetest.get_meta(pos):get_string("owner") == player:get_player_name()
local owner = minetest.get_meta(pos):get_string("owner")
return owner == player:get_player_name() or owner == ""
end
})

View File

@ -7,11 +7,9 @@ local craft_recipes = {}
local recipes_order = {}
local recipes_order_translated = {}
local function constructor_update_form(pos, meta)
local constructor = minetest.get_node(pos).name
local function constructor_update_form(constructor, meta)
local description = craft_recipes[constructor][meta:get_string("craft")]
local item = ""
local item
if description then
item = description.item
@ -27,6 +25,8 @@ local function constructor_update_form(pos, meta)
end
description = description.description
else
description, item = "", ""
end
meta:set_string("formspec", ([[
@ -43,34 +43,43 @@ local function constructor_update_form(pos, meta)
listring[current_player;main]
%s
]]):format(recipes_order_translated[constructor], meta:get_int("selected"),
item, F(S("CRAFT")), F(S(description or "")), default.get_hotbar_bg(0, 6)))
item, F(S("CRAFT")), F(S(description)), default.get_hotbar_bg(0, 6)))
end
local function constructor_process(pos, name)
local function constructor_process(pos, constructor, name)
local meta = minetest.get_meta(pos)
local craft = craft_recipes[constructor][meta:get_string("craft")]
local craft = craft_recipes[minetest.get_node(pos).name][meta:get_string("craft")]
if not craft then return end
if craft then
local item = craft.item
local stack = ItemStack(item)
local def = stack:get_definition()
local inv, item = meta:get_inventory(), craft.item
local stack = ItemStack(item)
if inv:room_for_item("main", stack) then
if not basic_machines.creative(name or "") then
local recipe = craft.craft
if def then
local inv = meta:get_inventory()
for _, v in ipairs(recipe) do
if not inv:contains_item("main", ItemStack(v)) then
meta:set_string("infotext", S("#CRAFTING: you need '@1' to craft '@2'", v, item)); return
if inv:room_for_item("main", stack) then
if basic_machines.creative(name or "") then
inv:add_item("main", stack)
else
local recipe = craft.craft
for _, v in ipairs(recipe) do
if not inv:contains_item("main", ItemStack(v)) then
meta:set_string("infotext", S("#CRAFTING: you need '@1' to craft '@2'", v, item)); return
end
end
for _, v in ipairs(recipe) do
inv:remove_item("main", ItemStack(v))
end
inv:add_item("main", stack)
end
end
for _, v in ipairs(recipe) do
inv:remove_item("main", ItemStack(v))
end
end
inv:add_item("main", stack)
if name or meta:get_string("infotext") == "" then
local def = minetest.registered_items[item:split(" ")[1]]
meta:set_string("infotext", S("#CRAFTING: '@1' (@2)",
def and def.description or S("Unknown item"), item))
end
@ -108,7 +117,7 @@ local function add_constructor(name, def)
inv:set_size("main", 24)
inv:set_size("recipe", 6)
constructor_update_form(pos, meta)
constructor_update_form(name, meta)
end,
can_dig = function(pos, player) -- main inv must be empty to be dug
@ -121,19 +130,19 @@ local function add_constructor(name, def)
if fields.quit or minetest.is_protected(pos, player_name) then return end
if fields.CRAFT then
constructor_process(pos, player_name)
constructor_process(pos, name, player_name)
elseif fields.craft then
if fields.craft:sub(1, 3) == "CHG" then
local sel = tonumber(fields.craft:sub(5)) or 1
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "")
for i, v in ipairs(recipes_order[minetest.get_node(pos).name]) do
for i, v in ipairs(recipes_order[name]) do
if i == sel then meta:set_string("craft", v); break end
end
meta:set_int("selected", sel)
constructor_update_form(pos, meta)
constructor_update_form(name, meta)
end
end
end,
@ -158,7 +167,7 @@ local function add_constructor(name, def)
effector = {
action_on = function(pos, _)
constructor_process(pos, nil)
constructor_process(pos, name, nil)
end
}
})

View File

@ -4,6 +4,7 @@ local detector_oplist = {["-"] = 1, ["AND"] = 2, ["OR"] = 3}
local detector_modelist = {["node"] = 1, ["player"] = 2, ["object"] = 3, ["inventory"] = 4,
["infotext"] = 5, ["light"] = 6}
local detector_modelist_translated = {}
local vector_add = vector.add
for k, v in pairs(detector_modelist) do
detector_modelist_translated[v] = F(S(k))
@ -44,10 +45,10 @@ minetest.register_node("basic_machines:detector", {
local pos11 = {x = meta:get_int("x1"), y = meta:get_int("y1"), z = meta:get_int("z1")}
local pos2 = {x = meta:get_int("x2"), y = meta:get_int("y2"), z = meta:get_int("z2")}
local pos1_abs = vector.add(pos, pos1)
local pos1_abs = vector_add(pos, pos1)
machines.mark_pos1(name, pos1_abs) -- mark pos1
machines.mark_pos2(name, vector.add(pos, pos2)) -- mark pos2
machines.mark_pos2(name, vector_add(pos, pos2)) -- mark pos2
local op = detector_oplist[meta:get_string("op")] or 1
local mode_string = meta:get_string("mode")
@ -55,7 +56,7 @@ minetest.register_node("basic_machines:detector", {
-- pos11 and logical operations are only available with node/inventory mode
if mode_string == "node" or mode_string == "inventory" and node_filter ~= "" then
machines.mark_pos11(name, vector.add(pos, pos11)) -- mark pos11
machines.mark_pos11(name, vector_add(pos, pos11)) -- mark pos11
end
local inventory_list
@ -97,21 +98,6 @@ minetest.register_node("basic_machines:detector", {
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
--[[
local mode = "node"
local meta = minetest.get_meta(pos)
if to_index == 2 then
mode = "player"
meta:set_int("r", math.max(meta:get_int("r"), 1))
end
if to_index == 3 then
mode = "object"
meta:set_int("r", math.max(meta:get_int("r"), 1))
end
meta:set_string("mode", mode)
minetest.chat_send_player(player:get_player_name(), S("DETECTOR: Mode of operation set to: @1", S(mode)))
return count
--]]
return 0
end,
@ -147,7 +133,7 @@ minetest.register_node("basic_machines:detector", {
return
end
local pos1 = vector.add(pos, {x = meta:get_int("x0"), y = meta:get_int("y0"), z = meta:get_int("z0")})
local pos1 = vector_add(pos, {x = meta:get_int("x0"), y = meta:get_int("y0"), z = meta:get_int("z0")})
local mode = meta:get_string("mode")
local node = meta:get_string("node") -- detection filter
@ -171,7 +157,7 @@ minetest.register_node("basic_machines:detector", {
-- operation: AND, OR... look at other source position too
if op ~= "-" then
local pos11 = vector.add(pos, {x = meta:get_int("x1"), y = meta:get_int("y1"), z = meta:get_int("z1")})
local pos11 = vector_add(pos, {x = meta:get_int("x1"), y = meta:get_int("y1"), z = meta:get_int("z1")})
tnode = minetest.get_node(pos11).name -- read node at source position
local trigger1 = false
@ -211,7 +197,7 @@ minetest.register_node("basic_machines:detector", {
-- operation: AND, OR... look at other source position too
if op ~= "-" then
local pos11 = vector.add(pos, {x = meta:get_int("x1"), y = meta:get_int("y1"), z = meta:get_int("z1")})
local pos11 = vector_add(pos, {x = meta:get_int("x1"), y = meta:get_int("y1"), z = meta:get_int("z1")})
local trigger1 = minetest.get_meta(pos11):get_inventory():contains_item(inv1m, ItemStack(node))
if op == "AND" then
@ -274,7 +260,7 @@ minetest.register_node("basic_machines:detector", {
local nstate = trigger and 1 or 0 -- next detector output state
if nstate ~= state then meta:set_int("state", nstate) end -- update state if changed
local pos2 = vector.add(pos, {x = meta:get_int("x2"), y = meta:get_int("y2"), z = meta:get_int("z2")})
local pos2 = vector_add(pos, {x = meta:get_int("x2"), y = meta:get_int("y2"), z = meta:get_int("z2")})
node = minetest.get_node_or_nil(pos2); if not node then return end -- error
local def = minetest.registered_nodes[node.name]

View File

@ -1,6 +1,7 @@
local F, S = basic_machines.F, basic_machines.S
local machines_minstep = basic_machines.properties.machines_minstep
local machines_timer = basic_machines.properties.machines_timer
local vector_add = vector.add
local function pos_to_string(pos) return ("%s,%s,%s"):format(pos.x, pos.y, pos.z) end
@ -30,7 +31,7 @@ basic_machines.get_distributor_form = function(pos)
for i = 1, n do
local posi = {x = meta:get_int("x" .. i), y = meta:get_int("y" .. i), z = meta:get_int("z" .. i)}
local y1, y2 = 0.5 + (i - 1) * 0.75, 0.25 + (i - 1) * 0.75
local tname = minetest.get_node(vector.add(pos, posi)).name
local tname = minetest.get_node(vector_add(pos, posi)).name
tname = posi.x .. " " .. posi.y .. " " .. posi.z .. " " .. tname:sub((tname:find(":") or 0) + 1)
form[i + 2] = "field[0.25," .. y1 .. ";3,1;text;;" .. tname ..
"]field[3.25," .. y1 .. ";1,1;active" .. i .. ";;" .. meta:get_int("active" .. i) ..
@ -128,7 +129,7 @@ minetest.register_node("basic_machines:distributor", {
for i = 1, meta:get_int("n") do
local activei = meta:get_int("active" .. i)
if activei ~= 0 then
local posi = vector.add(pos, {x = meta:get_int("x" .. i), y = meta:get_int("y" .. i), z = meta:get_int("z" .. i)})
local posi = vector_add(pos, {x = meta:get_int("x" .. i), y = meta:get_int("y" .. i), z = meta:get_int("z" .. i)})
local node = minetest.get_node(posi)
local def = minetest.registered_nodes[node.name]
@ -195,7 +196,7 @@ minetest.register_node("basic_machines:distributor", {
for i = 1, meta:get_int("n") do
local activei = meta:get_int("active" .. i)
if activei ~= 0 then
local posi = vector.add(pos, {x = meta:get_int("x" .. i), y = meta:get_int("y" .. i), z = meta:get_int("z" .. i)})
local posi = vector_add(pos, {x = meta:get_int("x" .. i), y = meta:get_int("y" .. i), z = meta:get_int("z" .. i)})
local node = minetest.get_node(posi)
local def = minetest.registered_nodes[node.name]

View File

@ -18,12 +18,12 @@ if use_player_monoids then
combine = function(p, q) return p or q end,
fold = function(elems)
for _, v in pairs(elems) do
if v then return true end
if not v then return false end
end
return false
return true
end,
identity = false,
identity = true,
apply = function(can_sneak, player)
local ov = player:get_physics_override()
ov.sneak = can_sneak
@ -51,9 +51,8 @@ for k, v in pairs(skyboxes) do
end
enviro_skylist_translated = table.concat(enviro_skylist_translated, ",")
local function enviro_update_form(pos, meta)
local function enviro_update_form(meta)
local skybox = meta:get_string("skybox")
local list_name = "nodemeta:" .. pos.x .. ',' .. pos.y .. ',' .. pos.z
meta:set_string("formspec", ([[
size[8,8]
@ -66,12 +65,12 @@ local function enviro_update_form(pos, meta)
field[2.25,1.5;1,1;gravity;%s;%.2f]
field[3.25,1.5;1,1;sneak;%s;%i]
label[-0.02,1.9;%s]dropdown[-0.02,2.3;1.5,1;skybox;%s;%i]
label[5,0;%s]list[%s;fuel;5,0.5;1,1;]
label[5,0;%s]list[context;fuel;5,0.5;1,1;]
button_exit[6.5,0;1,1;OK;%s]
button[6.5,1;1,1;help;%s]
list[current_player;main;0,3.75;8,1;]
list[current_player;main;0,5;8,3;8]
listring[%s;fuel]
listring[context;fuel]
listring[current_player;main]
%s
]]):format(F(S("Target")), meta:get_int("x0"), meta:get_int("y0"), meta:get_int("z0"),
@ -79,7 +78,7 @@ local function enviro_update_form(pos, meta)
F(S("Jump")), meta:get_float("jump"), F(S("Gravity")), meta:get_float("gravity"),
F(S("Sneak")), meta:get_int("sneak"), F(S("Sky")),
enviro_skylist_translated, skyboxes[skybox] and skyboxes[skybox].id or 1, F(S("FUEL")),
list_name, F(S("OK")), F(S("help")), list_name, default.get_hotbar_bg(0, 3.75)
F(S("OK")), F(S("help")), default.get_hotbar_bg(0, 3.75)
))
end
@ -120,7 +119,7 @@ minetest.register_node("basic_machines:enviro", {
meta:get_inventory():set_size("fuel", 1)
enviro_update_form(pos, meta)
enviro_update_form(meta)
end,
can_dig = function(pos, player) -- don't dig if fuel is inside, cause it will be destroyed
@ -171,7 +170,7 @@ minetest.register_node("basic_machines:enviro", {
fields.skybox = fields.skybox or "-"
meta:set_string("skybox", fields.skybox:match("%)([%w_-]+)") or "-")
enviro_update_form(pos, meta)
enviro_update_form(meta)
elseif fields.help then
minetest.show_formspec(name, "basic_machines:help_enviro",
@ -213,7 +212,7 @@ Sky: -, surface, cave or space
gravity = tonumber(fields.g); fields.g, fields.gravity = nil, gravity
skybox = "-"; fields.skybox = "-"; fields.public = nil
if minetest.get_meta(pos):from_table(meta_new) then meta = minetest.get_meta(pos) else return end
enviro_update_form(pos, meta)
enviro_update_form(meta)
end
if radius <= 0 then return end

View File

@ -243,32 +243,28 @@ if basic_machines.settings.grinder_register_dusts then
end
end
local function grinder_update_form(pos)
local meta = minetest.get_meta(pos)
local list_name = "nodemeta:" .. pos.x .. ',' .. pos.y .. ',' .. pos.z
local function grinder_update_form(meta)
meta:set_string("formspec", ([[
size[8,8]
label[0,-0.25;%s]list[%s;src;0,0.25;1,1;]
label[1,-0.25;%s]list[%s;dst;1,0.25;3,3;]
label[5,0;%s]list[%s;upgrade;5,0.5;1,1;]
label[0,-0.25;%s]list[context;src;0,0.25;1,1;]
label[1,-0.25;%s]list[context;dst;1,0.25;3,3;]
label[5,0;%s]list[context;upgrade;5,0.5;1,1;]
button[6.5,0;1,1;OK;%s]
button[6.5,1;1,1;help;%s]
label[0,1.75;%s]list[%s;fuel;0,2.25;1,1;]
label[0,1.75;%s]list[context;fuel;0,2.25;1,1;]
list[current_player;main;0,3.75;8,1;]
list[current_player;main;0,5;8,3;8]
listring[%s;dst]
listring[context;dst]
listring[current_player;main]
listring[%s;src]
listring[context;src]
listring[current_player;main]
listring[%s;upgrade]
listring[context;upgrade]
listring[current_player;main]
listring[%s;fuel]
listring[context;fuel]
listring[current_player;main]
%s
]]):format(F(S("IN")), list_name, F(S("OUT")), list_name, F(S("UPGRADE")),
list_name, F(S("OK")), F(S("help")), F(S("FUEL")), list_name, list_name,
list_name, list_name, list_name, default.get_hotbar_bg(0, 3.75)
]]):format(F(S("IN")), F(S("OUT")), F(S("UPGRADE")),
F(S("OK")), F(S("help")), F(S("FUEL")), default.get_hotbar_bg(0, 3.75)
))
end
@ -307,7 +303,7 @@ local function grinder_process(pos)
-- FUEL CHECK
local fuel, fuel_req = meta:get_float("fuel"), def[1] * steps
local msg = nil
local msg
if fuel < fuel_req then -- we need new fuel
local fuellist = inv:get_list("fuel"); if not fuellist then return end
@ -386,7 +382,7 @@ minetest.register_node("basic_machines:grinder", {
inv:set_size("upgrade", 1)
inv:set_size("fuel", 1)
grinder_update_form(pos)
grinder_update_form(meta)
end,
can_dig = function(pos, player)
@ -403,7 +399,6 @@ minetest.register_node("basic_machines:grinder", {
if fields.OK and not minetest.is_protected(pos, sender:get_player_name()) then
grinder_process(pos)
grinder_update_form(pos)
elseif fields.help then
if grinder_recipes_help == nil then
@ -434,12 +429,18 @@ minetest.register_node("basic_machines:grinder", {
if listname == "src" then
grinder_process(pos)
elseif listname == "upgrade" then
grinder_upgrade(minetest.get_meta(pos))
local meta = minetest.get_meta(pos)
grinder_upgrade(meta)
grinder_update_form(meta)
end
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
if listname == "upgrade" then grinder_upgrade(minetest.get_meta(pos)) end
if listname == "upgrade" then
local meta = minetest.get_meta(pos)
grinder_upgrade(meta)
grinder_update_form(meta)
end
end,
effector = {

View File

@ -21,13 +21,13 @@ basic_machines = {
S = minetest.get_translator("basic_machines"),
version = "10/02/2021a custom",
properties = {
clockgen = 1, -- if 0 all background continuously running activity (clockgen/keypad) repeating is disabled
machines_TTL = 16, -- time to live for signals, how many hops before signal dissipates
machines_minstep = 1, -- minimal allowed activation timestep, if faster machines overheat
machines_operations = 10, -- 1 coal will provide 10 mover basic operations (moving dirt 1 block distance)
machines_timer = 5, -- main timestep
max_range = 10, -- machines normal range of operation
mover_upgrade_max = 10 -- upgrade mover to increase range and to reduce fuel consumption
no_clock = false, -- if true all continuously running activities (clockgen/keypad) are disabled
machines_TTL = 16, -- time to live for signals, how many hops before signal dissipates
machines_minstep = 1, -- minimal allowed activation timestep, if faster machines overheat
machines_operations = 10, -- 1 coal will provide 10 mover basic operations (moving dirt 1 block distance)
machines_timer = 5, -- main timestep
max_range = 10, -- machines normal range of operation
mover_upgrade_max = 10 -- upgrade mover to increase range and to reduce fuel consumption
},
settings = { -- can be added to server configuration file, example: basic_machines_energy_multiplier = 1
-- ball spawner
@ -44,10 +44,9 @@ basic_machines = {
generator_upgrade = 0, -- upgrade available in addition to the current limit (50)
-- space
space_start_eff = 1500, -- space efficiency height
space_start = 1100, -- space.lua needed
exclusion_height = 6666, -- space.lua needed:
-- above, without "include" priv, player is teleported to a random location
space_effects = false, -- space.lua needed: enable damage mechanism
space_start = 1100, -- space height
exclusion_height = 6666, -- above, without "include" priv, player is teleported to a random location
space_effects = false, -- enable damage mechanism
--
register_crafts = false -- machines crafts recipes
},
@ -116,7 +115,7 @@ if minetest.global_exists("mesecon") then
dofile(MP .. "mesecon_adapter.lua")
end
-- OPTIONAL stuff (comment to disable)
-- OPTIONAL content
dofile(MP .. "crafts.lua") -- adds additional craft recipes
if minetest.global_exists("gravelsieve") then
dofile(MP .. "control_gravelsieve.lua") -- adds compatibility to gravelsieve mod
@ -129,6 +128,17 @@ dofile(MP .. "space.lua") -- change global physics
local S = basic_machines.S
-- test: toggle machine running with clockgen/keypad repeats, useful for debugging
-- i.e. seeing how machines running affect server performance
minetest.register_chatcommand("clockgen", {
description = S("Toggle clock generator/keypad repeats"),
privs = {privs = true},
func = function(name, _)
basic_machines.properties.no_clock = not basic_machines.properties.no_clock
minetest.chat_send_player(name, S("No clock set to @1", tostring(basic_machines.properties.no_clock)))
end
})
-- "machines" privilege
minetest.register_privilege("machines", {
description = S("Player is expert basic_machines user: his machines work while not present on server," ..

View File

@ -2,6 +2,7 @@ local F, S = basic_machines.F, basic_machines.S
local machines_TTL = basic_machines.properties.machines_TTL
local machines_minstep = basic_machines.properties.machines_minstep
local machines_timer = basic_machines.properties.machines_timer
local no_clock = basic_machines.properties.no_clock
local byte = string.byte
local use_signs_lib = minetest.global_exists("signs_lib")
local signs = { -- when activated with keypad these will be "punched" to update their text too
@ -22,8 +23,8 @@ local signs = { -- when activated with keypad these will be "punched" to update
}
-- position, time to live (how many times can signal travel before vanishing to prevent infinite recursion),
-- do we want to activate again
basic_machines.use_keypad = function(pos, ttl, again)
-- do we want to stop repeating
basic_machines.use_keypad = function(pos, ttl, reset, reset_msg)
if ttl < 1 then return end
local meta = minetest.get_meta(pos)
@ -49,48 +50,52 @@ basic_machines.use_keypad = function(pos, ttl, again)
end
if minetest.is_protected(pos, meta:get_string("owner")) then
meta:set_int("count", 0)
meta:set_string("infotext", S("Protection fail. Reset."))
meta:set_int("count", 0)
return
end
local count = meta:get_int("count") -- counts how many repeats left
local repeating = meta:get_int("repeating")
local iter = meta:get_int("iter")
local count = 0 -- counts repeats
if repeating == 1 and again ~= 1 then
-- stop it
meta:set_int("repeating", 0)
meta:set_int("count", 0)
meta:set_int("T", 4)
meta:set_string("infotext", S("KEYPAD: Resetting. Punch again after @1s to activate.", machines_timer))
return
end
if iter > 1 then
if no_clock then return end
count = meta:get_int("count")
if count > 0 then -- this is keypad repeating activation
count = count - 1; meta:set_int("count", count)
else
meta:set_int("repeating", 0)
-- return
end
if reset and count > 0 or count == iter then
meta:set_int("count", 0)
meta:set_int("T", 4)
meta:set_string("infotext", reset_msg or
S("KEYPAD: Resetting. Punch again after @1s to activate.", machines_timer))
return
end
if count >= 0 then
meta:set_string("infotext", S("Keypad operation: @1 cycles left", count))
else
meta:set_string("infotext", S("Keypad operation: activation @1", -count))
end
if count < iter - 1 then
minetest.after(machines_timer, function()
basic_machines.use_keypad(pos, machines_TTL)
end)
end
if count > 0 then -- only trigger repeat if count on
if repeating == 0 then meta:set_int("repeating", 1) end -- repeating now
if basic_machines.properties.clockgen == 0 then return end
minetest.after(machines_timer, function()
basic_machines.use_keypad(pos, machines_TTL, 1)
end)
if count < iter then -- this is keypad repeating activation
count = count + 1; meta:set_int("count", count)
count = iter - count
end
end
local tpos = vector.add(pos, {x = meta:get_int("x0"), y = meta:get_int("y0"), z = meta:get_int("z0")})
local node = minetest.get_node_or_nil(tpos); if not node then return end -- error
local text, name = meta:get_string("text"), node.name
if text == "" or name ~= "basic_machines:keypad" and not vector.equals(pos, tpos) then
local msg
if count < 2 then
msg = S("Keypad operation: @1 cycle left", count)
else
msg = S("Keypad operation: @1 cycles left", count)
end
meta:set_string("infotext", msg)
end
if text ~= "" then -- TEXT MODE; set text on target
if text == "@" and meta:get_string("pass") ~= "" then -- keyboard mode, set text from input
text = meta:get_string("input")
@ -145,15 +150,11 @@ basic_machines.use_keypad = function(pos, ttl, again)
text = text:sub(2); if text == "" then tmeta:set_string("text", ""); return end -- clear target keypad text
-- read words [j] from blocks above keypad:
local j = 0
text = text:gsub("@",
function()
j = j + 1
return minetest.get_meta({x = pos.x, y = pos.y + 1, z = pos.z}):get_string("infotext")
end
) -- replace every @ in ttext with string on blocks above
text = text:gsub("@", function()
j = j + 1; return minetest.get_meta({x = pos.x, y = pos.y + 1, z = pos.z}):get_string("infotext")
end) -- replace every @ in ttext with string on blocks above
-- set target keypad's text
-- tmeta = minetest.get_meta(tpos)
tmeta:set_string("text", text)
elseif bit == 37 then -- target keypad's text starts with % (ascii code 37) -> word extraction
local ttext = minetest.get_meta({x = pos.x, y = pos.y + 1, z = pos.z}):get_string("infotext")
@ -165,11 +166,9 @@ basic_machines.use_keypad = function(pos, ttl, again)
end
-- set target keypad's target's text
-- tmeta = minetest.get_meta(tpos)
tmeta:set_string("text", text)
else
-- just set text..
-- tmeta = minetest.get_meta(tpos)
tmeta:set_string("infotext", text)
end
return
@ -220,7 +219,7 @@ basic_machines.use_keypad = function(pos, ttl, again)
if mode == 3 then -- keypad in toggle mode
local state = meta:get_int("state"); state = 1 - state; meta:set_int("state", state)
if state == 0 then mode = 1 else mode = 2 end
if state == 0 then mode = 2 else mode = 1 end
end
local effector = def.effector or def.mesecons.effector
@ -250,8 +249,9 @@ minetest.register_node("basic_machines:keypad", {
meta:set_string("owner", placer:get_player_name())
meta:set_int("mode", 2); meta:set_string("pass", "") -- mode, pasword of operation
meta:set_int("iter", 1); meta:set_int("count", 0) -- how many repeats to do, current repeat count
meta:set_int("iter", 1); meta:set_int("count", 0) -- current repeat count
meta:set_int("x0", 0); meta:set_int("y0", 0); meta:set_int("z0", 0) -- target
meta:set_int("input", 0); meta:set_int("state", 0)
end,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
@ -274,7 +274,13 @@ minetest.register_node("basic_machines:keypad", {
effector = {
action_on = function(pos, _)
if minetest.get_meta(pos):get_string("pass") == "" then
basic_machines.use_keypad(pos, 1, 0) -- activate just 1 time
basic_machines.use_keypad(pos, 1)
end
end,
action_off = function(pos, _)
if minetest.get_meta(pos):get_string("pass") == "" then
basic_machines.use_keypad(pos, 1, true) -- can stop repeats
end
end
}

View File

@ -8,16 +8,10 @@ minetest.register_node("basic_machines:light_off", {
effector = {
action_on = function(pos, _)
minetest.swap_node(pos, {name = "basic_machines:light_on"})
local meta = minetest.get_meta(pos)
local deactivate = meta:get_int("deactivate")
local deactivate = minetest.get_meta(pos):get_int("deactivate")
if deactivate > 0 then
-- meta:set_int("active", 0)
minetest.after(deactivate, function()
-- if meta:get_int("active") ~= 1 then -- was not activated again, so turn it off
minetest.swap_node(pos, {name = "basic_machines:light_off"}) -- turn off again
-- meta:set_int("active", 0)
-- end
minetest.swap_node(pos, {name = "basic_machines:light_off"}) -- turn off again
end)
end
end
@ -33,8 +27,9 @@ minetest.register_node("basic_machines:light_on", {
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",
"size[2,1.75]field[0.25,0.5;2,1;deactivate;" .. F(S("deactivate after")) .. ";" .. meta:get_int("deactivate") ..
"size[2,1.75]field[0.25,0.5;2,1;deactivate;" .. F(S("Deactivate after:")) .. ";0" ..
"]button_exit[0,1;1,1;OK;" .. F(S("OK")) .. "]")
meta:set_int("deactivate", 0)
end,
on_receive_fields = function(pos, formname, fields, sender)
@ -44,7 +39,7 @@ minetest.register_node("basic_machines:light_on", {
if deactivate < 0 or deactivate > 600 then deactivate = 0 end
meta:set_int("deactivate", deactivate)
meta:set_string("formspec",
"size[2,1.75]field[0.25,0.5;2,1;deactivate;" .. F(S("deactivate after")) .. ";" .. deactivate ..
"size[2,1.75]field[0.25,0.5;2,1;deactivate;" .. F(S("Deactivate after:")) .. ";" .. deactivate ..
"]button_exit[0,1;1,1;OK;" .. F(S("OK")) .. "]")
end
end,

View File

@ -55,8 +55,6 @@ Overheat: temperature @1=
Ball Spawner=
# clockgen.lua
Toggle clock generator/keypad repeats=
clockgen set to @1=
Clock Generator - use sparingly, continually activates top block=
Clock Generator: Interference from nearby clock generator detected=
Clock Generator (owned by @1): place machine to be activated on top=
@ -120,7 +118,6 @@ Detection filter=
Radius=
Filter out -2/-1/0/1/2/3/4=
MODE selection=
#DETECTOR: Mode of operation set to: @1=
Detector: on=
Detector: off=
@ -210,6 +207,8 @@ GRINDER HELP=
To upgrade grinder, put grinders in upgrade slot. Each upgrade adds ability to process additional materials.@n@n=
# init.lua
Toggle clock generator/keypad repeats=
No clock set to @1=
Player is expert basic_machines user: his machines work while not present on server, can spawn more than @1 balls at once=
Wood Charcoal=
Machines and Components=
@ -217,8 +216,8 @@ Machines and Components=
# keypad.lua
Protection fail. Reset.=
KEYPAD: Resetting. Punch again after @1s to activate.=
Keypad operation: @1 cycle left=
Keypad operation: @1 cycles left=
Keypad operation: activation @1=
Keypad - basic way to activate machines by sending signal=
Keypad. Right click to set it up or punch it. Set any password and text "@@" to work as keyboard.=
Repeat=
@ -230,7 +229,7 @@ Text=
# light.lua
Light Off=
Light On=
deactivate after=
Deactivate after:=
# machines_configuration.lua
Enter text:=
@ -265,8 +264,8 @@ MOVER: Position is protected. Aborting.=
MOVER: All coordinates must be between @1 and @2. For increased range set up positions by punching.=
MOVER: Wrong filter - must be name of existing minetest block=
Mover block. Set up with source coordinates @1,@2,@3 -> @4,@5,@6 and target coordinates @7,@8,@9. Put charged battery next to it and start it with keypad/mese signal.=
MOVER: Please put battery nearby=
MOVER: Battery found - displaying mark 1=
MOVER: Please put battery nearby=
## mover help
MOVER HELP=
#
@ -400,7 +399,6 @@ Mover block refueled. Fuel status @1.=
Cow=
Cows=
Mover block. Fuel status @1.=
Mover block. Must set nodes to move (filter) in inventory mode.=
MOVER: Wrong filter (@1) at @2,@3,@4.=
# recycler.lua
@ -434,16 +432,18 @@ Battery provides power to machines or furnace. It can either use power crystals
@nUPGRADE with diamond blocks for more available power output or with mese blocks for more power storage capacity.=
##
Furnace needs at least 1 energy=
Error: max upgrade is @1=
High upgrade: power rod=
Medium upgrade: power block=
Low upgrade: power cell=
initialize=
POWER CRYSTALS=
Power: @1 (high)=
Power: @1 (medium)=
Power: @1 (low)=
Generator - very expensive, generates power crystals that provide power, it's upgradeable=
Error: max upgrade is @1=
Generator - not enough energy to operate=
High upgrade: power rod=
Medium upgrade: power block=
Low upgrade: power cell=
Generator: Interference from nearby generator detected=
Generator - very expensive, generates power crystals that provide power, it's upgradeable=
Generator - generates power crystals that provide power, upgrade with up to @1 generators=
## generator help
GENERATOR HELP=
@ -454,4 +454,4 @@ Generator slowly produces power crystals. Those can be used to recharge batterie
##
Power Cell - provides @1 energy=
Power Block - provides @1 energy=
Power Rod - provides @1 energy=
Power Rod - provides @1 energy=

View File

@ -21,13 +21,9 @@ local punchable_nodes = {
local function check_keypad(pos, name) -- called only when manually activated via punch
local meta = minetest.get_meta(pos)
if meta:get_string("pass") == "" then
local count = meta:get_int("count")
local iter = meta:get_int("iter")
-- so that keypad can work again, at least one operation must have occured though
if count < iter - 1 or iter < 2 then meta:set_int("active_repeats", 0) end
meta:set_int("count", iter); basic_machines.use_keypad(pos, machines_TTL, 0) -- time to live set when punched
return
basic_machines.use_keypad(pos, machines_TTL, true); return -- time to live set when punched
end
if name == "" then return end
@ -76,7 +72,7 @@ minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
node = node.name,
state = 1
}
local msg = ""
local msg
if punchset_desc == "MOVER" then
msg = "MOVER: Now punch source1, source2, end position to set up mover."
elseif punchset_desc == "KEYPAD" then
@ -84,7 +80,7 @@ minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
elseif punchset_desc == "DETECTOR" then
msg = "DETECTOR: Now punch the source block."
end
if msg ~= "" then
if msg then
minetest.chat_send_player(name, S(msg))
end
return
@ -424,16 +420,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if meta:get_float("fuel") < 0 then meta:set_float("fuel", 0) end -- reset block
-- display battery
local fpos = basic_machines.find_and_connect_battery(pos)
if not fpos then
if meta:get_int("upgrade") > -1 then
minetest.chat_send_player(name, S("MOVER: Please put battery nearby"))
end
else
if fpos then
minetest.chat_send_player(name, S("MOVER: Battery found - displaying mark 1"))
machines.mark_pos1(name, fpos)
machines.mark_pos1(name, fpos) -- display battery
elseif meta:get_int("upgrade") > -1 then
minetest.chat_send_player(name, S("MOVER: Please put battery nearby"))
end
end
@ -654,6 +646,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
meta:set_int("mode", tonumber(fields.mode) or 2)
meta:set_int("iter", math.min(tonumber(fields.iter) or 1, 500))
meta:set_int("count", 0)
local pass = fields.pass or ""
@ -666,7 +659,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
meta:set_string("text", text)
if text:sub(1,1) == "!" then
minetest.log("action", ("%s set up keypad for message display at %s,%s,%s"):format(name, pos.x, pos.y, pos.z))
minetest.log("action", ("[basic_machines] %s set up keypad for message display at %s,%s,%s"):format(name, pos.x, pos.y, pos.z))
end
meta:set_int("x0", x0); meta:set_int("y0", y0); meta:set_int("z0", z0)
@ -714,8 +707,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if meta:get_string("text") == "@" then -- keyboard mode
meta:set_string("input", pass)
meta:set_int("count", 1)
basic_machines.use_keypad(pos, machines_TTL, 0)
basic_machines.use_keypad(pos, machines_TTL)
return
end
@ -726,14 +718,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
minetest.chat_send_player(name, S("ACCESS GRANTED"))
local count = meta:get_int("count")
if meta:get_int("count") <= 0 then -- only accept new operation requests if idle
meta:set_int("count", meta:get_int("iter"))
meta:set_int("active_repeats", 0)
basic_machines.use_keypad(pos, machines_TTL, 0)
if count == 0 or count == meta:get_int("iter") then -- only accept new operation requests if idle
basic_machines.use_keypad(pos, machines_TTL)
else
meta:set_int("count", 0)
meta:set_string("infotext", S("Operation aborted by user. Punch to activate.")) -- reset
basic_machines.use_keypad(pos, 1, true, S("Operation aborted by user. Punch to activate.")) -- reset
end
end
@ -788,4 +778,4 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
"-2=only OFF, -1=NOT, 0/1=normal, 2=only ON, 3=only if changed, 4=if target is keypad set its text to detected object name.")) .. "]")
end
end
end)
end)

View File

@ -55,7 +55,6 @@ end
minetest.register_entity(":machines:pos1", {
initial_properties = {
physical = false,
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
visual = "cube",
visual_size = {x = 1.1, y = 1.1},
@ -86,7 +85,6 @@ minetest.register_entity(":machines:pos1", {
minetest.register_entity(":machines:pos11", {
initial_properties = {
physical = false,
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
visual = "cube",
visual_size = {x = 1.1, y = 1.1},
@ -117,7 +115,6 @@ minetest.register_entity(":machines:pos11", {
minetest.register_entity(":machines:pos2", {
initial_properties = {
physical = false,
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
visual = "cube",
visual_size = {x = 1.1, y = 1.1},

View File

@ -8,6 +8,7 @@ local F, S = basic_machines.F, basic_machines.S
local machines_minstep = basic_machines.properties.machines_minstep
local machines_operations = basic_machines.properties.machines_operations
local max_range = basic_machines.properties.max_range
local vector_add = vector.add
local abs = math.abs
local vplayer = {}
local have_bucket_liquids = minetest.global_exists("bucket") and bucket.liquids
@ -210,7 +211,7 @@ end
basic_machines.check_target_chest = function(mode, pos, meta)
if mode == "normal" and meta:get_int("reverse") == 0 then
local pos2 = vector.add(pos, {x = meta:get_int("x2"), y = meta:get_int("y2"), z = meta:get_int("z2")})
local pos2 = vector_add(pos, {x = meta:get_int("x2"), y = meta:get_int("y2"), z = meta:get_int("z2")})
if mover.chests[minetest.get_node(pos2).name] then
return true
end
@ -218,8 +219,8 @@ basic_machines.check_target_chest = function(mode, pos, meta)
return false
end
local function stack_with_palette(item, palette_index)
local stack = ItemStack(item)
local function itemstring_to_stack(itemstring, palette_index)
local stack = ItemStack(itemstring)
if palette_index then
stack:get_meta():set_int("palette_index", palette_index)
end
@ -299,8 +300,8 @@ basic_machines.get_mover_form = function(pos, name)
local inventory_list1, inventory_list2 = "", ""
if mode_string == "inventory" then
local meta1 = minetest.get_meta(vector.add(pos, pos1)) -- source1 meta
local meta2 = minetest.get_meta(vector.add(pos, pos2)) -- target meta
local meta1 = minetest.get_meta(vector_add(pos, pos1)) -- source1 meta
local meta2 = minetest.get_meta(vector_add(pos, pos2)) -- target meta
local inv1m, inv2m = meta:get_string("inv1"), meta:get_string("inv2")
local inv1, inv2 = 1, 1
@ -344,7 +345,7 @@ end
basic_machines.find_and_connect_battery = function(pos)
for i = 0, 2 do
local positions = minetest.find_nodes_in_area( -- find battery
vector.subtract(pos, 1), vector.add(pos, 1), "basic_machines:battery_" .. i)
vector.subtract(pos, 1), vector_add(pos, 1), "basic_machines:battery_" .. i)
if #positions > 0 then
local meta = minetest.get_meta(pos)
local fpos = positions[1] -- pick first battery found
@ -430,11 +431,11 @@ minetest.register_node("basic_machines:mover", {
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local name, meta = player:get_player_name(), minetest.get_meta(pos)
machines.mark_pos1(name, vector.add(pos,
machines.mark_pos1(name, vector_add(pos,
{x = meta:get_int("x0"), y = meta:get_int("y0"), z = meta:get_int("z0")})) -- mark pos1
machines.mark_pos11(name, vector.add(pos,
machines.mark_pos11(name, vector_add(pos,
{x = meta:get_int("x1"), y = meta:get_int("y1"), z = meta:get_int("z1")})) -- mark pos11
machines.mark_pos2(name, vector.add(pos,
machines.mark_pos2(name, vector_add(pos,
{x = meta:get_int("x2"), y = meta:get_int("y2"), z = meta:get_int("z2")})) -- mark pos2
minetest.show_formspec(name, "basic_machines:mover_" .. minetest.pos_to_string(pos),
@ -449,6 +450,7 @@ minetest.register_node("basic_machines:mover", {
local name = player:get_player_name()
if minetest.is_protected(pos, name) then return 0 end
local meta = minetest.get_meta(pos)
if listname == "filter" then
local inv = meta:get_inventory()
local inv_stack = inv:get_stack("filter", 1)
@ -468,7 +470,7 @@ minetest.register_node("basic_machines:mover", {
basic_machines.check_target_chest(mode, pos, meta)
then
meta:set_string("prefer", prefer)
local filter_stack = stack_with_palette(prefer, palette_index)
local filter_stack = itemstring_to_stack(prefer, palette_index)
inv:set_stack("filter", 1, filter_stack) -- inv:add_item("filter", filter_stack)
else
minetest.chat_send_player(name, S("MOVER: Wrong filter - must be name of existing minetest block")); return 0
@ -503,6 +505,7 @@ minetest.register_node("basic_machines:mover", {
local name = player:get_player_name()
if minetest.is_protected(pos, name) then return 0 end
local meta = minetest.get_meta(pos)
if listname == "filter" then
local inv = meta:get_inventory()
local inv_stack = inv:get_stack("filter", 1)
@ -516,7 +519,7 @@ minetest.register_node("basic_machines:mover", {
else
local prefer = item.name .. (item.count > 1 and (" " .. item.count) or "")
meta:set_string("prefer", prefer)
local filter_stack = stack_with_palette(prefer, tonumber(inv_stack:get_meta():get("palette_index")))
local filter_stack = itemstring_to_stack(prefer, tonumber(inv_stack:get_meta():get("palette_index")))
inv:set_stack("filter", 1, filter_stack) -- inv:add_item("filter", filter_stack)
end
minetest.show_formspec(name, "basic_machines:mover_" .. minetest.pos_to_string(pos),
@ -555,7 +558,7 @@ minetest.register_node("basic_machines:mover", {
local mreverse = meta:get_int("reverse")
local pos1 = {} -- where to take from
local pos2 = vector.add(pos, {x = x2, y = y2, z = z2}) -- where to put
local pos2 = vector_add(pos, {x = x2, y = y2, z = z2}) -- where to put
local object = mode == "object" -- object mode
@ -563,7 +566,7 @@ minetest.register_node("basic_machines:mover", {
if meta:get_int("dim") ~= -1 then
meta:set_string("infotext", S("MOVER: Must reconfigure sources position.")); return
end
pos1 = vector.add(pos, {x = x0, y = y0, z = z0})
pos1 = vector_add(pos, {x = x0, y = y0, z = z0})
x1, y1, z1 = meta:get_int("x1"), meta:get_int("y1"), meta:get_int("z1")
else
if meta:get_int("dim") < 1 then
@ -576,14 +579,14 @@ minetest.register_node("basic_machines:mover", {
pos1.y = y0 + (pc % y1); pc = (pc - (pc % y1)) / y1
pos1.x = x0 + (pc % x1); pc = (pc - (pc % x1)) / x1
pos1.z = z0 + pc
pos1 = vector.add(pos, pos1)
pos1 = vector_add(pos, pos1)
end
local transport = mode == "transport" -- transports nodes
-- special mode that use its own source/target positions:
if transport and mreverse < 2 then
pos2 = vector.add(pos1, {x = x2 - x0, y = y2 - y0, z = z2 - z0}) -- translation from pos1
pos2 = vector_add(pos1, {x = x2 - x0, y = y2 - y0, z = z2 - z0}) -- translation from pos1
end
if mreverse ~= 0 and mreverse ~= 2 then -- reverse pos1, pos2
@ -653,13 +656,10 @@ minetest.register_node("basic_machines:mover", {
-- FUEL OPERATIONS
if fuel < fuel_cost then -- needs fuel to operate, find nearby battery
local found_fuel = nil
-- cached battery position
local fpos = {x = meta:get_int("batx"), y = meta:get_int("baty"), z = meta:get_int("batz")}
local power_draw = fuel_cost
if power_draw < 1 then power_draw = 1 end -- at least 10 one block operations with 1 refuel
local supply = basic_machines.check_power(fpos, power_draw)
local power_draw = fuel_cost; if power_draw < 1 then power_draw = 1 end -- at least 10 one block operations with 1 refuel
local supply = basic_machines.check_power(
{x = meta:get_int("batx"), y = meta:get_int("baty"), z = meta:get_int("batz")}, power_draw)
local found_fuel
if supply > 0 then
found_fuel = supply
@ -688,13 +688,13 @@ minetest.register_node("basic_machines:mover", {
if object then -- teleport objects and return
-- local radius = math.max(abs(x1), abs(y1), abs(z1)); r = math.min(r, max_range)
local radius = math.min(vector.distance(pos1, vector.add(pos, {x = x1, y = y1, z = z1})), max_range)
local radius = math.min(vector.distance(pos1, vector_add(pos, {x = x1, y = y1, z = z1})), max_range)
if meta:get_int("elevator") == 1 and radius == 0 then radius = 1 end -- for compatibility
local teleport_any = false
if target_chest then -- put objects in target chest
local inv = minetest.get_meta(pos2):get_inventory()
local mucca = nil
local mucca
for _, obj in ipairs(minetest.get_objects_inside_radius(pos1, radius)) do
if not obj:is_player() then
@ -805,10 +805,6 @@ minetest.register_node("basic_machines:mover", {
end
if inventory then -- inventory mode
-- if prefer == "" then
-- meta:set_string("infotext", S("Mover block. Must set nodes to move (filter) in inventory mode.")); return
-- end
local invName1, invName2 = meta:get_string("inv1"), meta:get_string("inv2")
if mreverse == 1 then -- reverse inventory names too
@ -823,7 +819,7 @@ minetest.register_node("basic_machines:mover", {
end
end
local stack, inv1 = nil
local stack, inv1
if prefer ~= "" then
stack = ItemStack(prefer)
@ -953,7 +949,7 @@ minetest.register_node("basic_machines:mover", {
return
end
end
elseif prefer == "" and source_chest then -- doesn't know what to take out of chest/inventory
elseif source_chest then -- doesn't know what to take out of chest/inventory
return
end
@ -977,15 +973,12 @@ minetest.register_node("basic_machines:mover", {
{x = pos1.x + r, y = pos1.y + h, z = pos1.z + r},
node1_name)
local count = 0
for _, pos3 in ipairs(positions) do
-- if count > h then break end
minetest.set_node(pos3, {name = "air"}); count = count + 1
minetest.set_node(pos3, {name = "air"})
end
check_for_falling(pos1)
local stacks, stack_max = {}, ItemStack(node1_name):get_stack_max()
local count, stack_max, stacks = #positions, ItemStack(node1_name):get_stack_max(), {}
if count > stack_max then
local stacks_n = count / stack_max
@ -997,14 +990,16 @@ minetest.register_node("basic_machines:mover", {
not_special = false
for _, v in ipairs(stacks)do
local item = node1_name .. " " .. v
local i = 1
repeat
local item = node1_name .. " " .. stacks[i]
if inv:room_for_item("main", item) then
inv:add_item("main", item) -- if tree or cactus was dug up
else
minetest.add_item(pos1, item)
end
end
i = i + 1
until(i > #stacks)
else
local liquiddef = have_bucket_liquids and bucket.liquids[node1_name]
local harvest_node1 = mover.harvest_table[node1_name]
@ -1060,7 +1055,7 @@ minetest.register_node("basic_machines:mover", {
end
for _, add_item in ipairs(item.items) do -- pick all items from list
if inherit_color and palette_index then
add_item = stack_with_palette(add_item, palette_index)
add_item = itemstring_to_stack(add_item, palette_index)
end
inv:add_item("main", add_item)
end
@ -1140,4 +1135,4 @@ if basic_machines.settings.register_crafts then
{"default:stone", "basic_machines:keypad", "default:stone"}
}
})
end
end

View File

@ -4,9 +4,9 @@
-- Registers dig attempts in radius 10 around
-- Distributor must have first target filter set to 0 (disabled) to handle dig events
local machines_TTL = basic_machines.properties.machines_TTL
local old_is_protected = minetest.is_protected
local round = math.floor
local machines_TTL = basic_machines.properties.machines_TTL
function minetest.is_protected(pos, digger)
local is_protected = old_is_protected(pos, digger)

View File

@ -6,8 +6,7 @@
local F, S = basic_machines.F, basic_machines.S
local machines_minstep = basic_machines.properties.machines_minstep
-- prevent unrealistic recycling
local no_recycle_list = {
local no_recycle_list = { -- prevent unrealistic recycling
["default:bronze_ingot"] = 1, ["default:gold_ingot"] = 1,
["default:copper_ingot"] = 1, ["default:steel_ingot"] = 1,
["dye:black"] = 1, ["dye:blue"] = 1, ["dye:brown"] = 1, ["dye:cyan"] = 1,
@ -17,22 +16,20 @@ local no_recycle_list = {
["dye:white"] = 1, ["dye:yellow"] = 1
}
local function recycler_update_form(pos, meta)
local list_name = "nodemeta:" .. pos.x .. ',' .. pos.y .. ',' .. pos.z
local function recycler_update_form(meta)
meta:set_string("formspec", "size[8,8]" .. -- width, height
"label[0,-0.25;" .. F(S("IN")) .. "]list[" .. list_name .. ";src;0,0.25;1,1;]" ..
"label[1,-0.25;" .. F(S("OUT")) .. "]list[" .. list_name .. ";dst;1,0.25;3,3;]" ..
"label[0,-0.25;" .. F(S("IN")) .. "]list[context;src;0,0.25;1,1;]" ..
"label[1,-0.25;" .. F(S("OUT")) .. "]list[context;dst;1,0.25;3,3;]" ..
"field[4.5,0.65;2,1;recipe;" .. F(S("Select recipe:")) .. ";" .. meta:get_int("recipe") ..
"]button[6.5,0;1,1;OK;" .. F(S("OK")) ..
"]label[0,1.75;" .. F(S("FUEL")) .. "]list[" .. list_name .. ";fuel;0,2.25;1,1;]" ..
"]label[0,1.75;" .. F(S("FUEL")) .. "]list[context;fuel;0,2.25;1,1;]" ..
"list[current_player;main;0,3.75;8,1;]" ..
"list[current_player;main;0,5;8,3;8]" ..
"listring[" .. list_name .. ";dst]" ..
"listring[context;dst]" ..
"listring[current_player;main]" ..
"listring[" .. list_name .. ";src]" ..
"listring[context;src]" ..
"listring[current_player;main]" ..
"listring[" .. list_name .. ";fuel]" ..
"listring[context;fuel]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0, 3.75))
end
@ -50,7 +47,7 @@ local function recycler_process(pos)
end
local inv = meta:get_inventory()
local msg = nil
local msg
if fuel < fuel_req then -- we need new fuel
local fuellist = inv:get_list("fuel"); if not fuellist then return end
@ -195,7 +192,7 @@ minetest.register_node("basic_machines:recycler", {
inv:set_size("dst", 9)
inv:set_size("fuel", 1)
recycler_update_form(pos, meta)
recycler_update_form(meta)
end,
can_dig = function(pos, player)
@ -216,7 +213,7 @@ minetest.register_node("basic_machines:recycler", {
meta:set_int("recipe", tonumber(fields.recipe) or 1)
recycler_process(pos)
recycler_update_form(pos, meta)
recycler_update_form(meta)
end
end,

View File

@ -1,7 +1,7 @@
local S = basic_machines.S
local space_start = basic_machines.settings.space_start
local exclusion_height = basic_machines.settings.exclusion_height
local space_effects = basic_machines.settings.space_effects
local space_start = basic_machines.settings.space_start
local space_start_eff = basic_machines.settings.space_start_eff
local use_player_monoids = minetest.global_exists("player_monoids")
local use_basic_protect = minetest.global_exists("basic_protect")
@ -124,7 +124,7 @@ minetest.register_globalstep(function(dtime)
if space_effects and inspace == 1 then -- special space code
local hp = player:get_hp()
if hp > 0 and not minetest.check_player_privs(name, "kick") then
if pos.y > space_start_eff - 380 and pos.y < space_start_eff then
if pos.y < space_start_eff and pos.y > space_start_eff - 380 then
minetest.chat_send_player(name, S("WARNING: you entered DEADLY RADIATION ZONE")); player:set_hp(hp - 15)
elseif use_basic_protect then
local ppos = protector_position(pos)

View File

@ -1,33 +1,30 @@
local F, S = basic_machines.F, basic_machines.S
local energy_multiplier = basic_machines.settings.energy_multiplier
local space_start_eff = basic_machines.settings.space_start_eff
local generator_upgrade_max = 50 + math.max(0, basic_machines.settings.generator_upgrade)
local power_stackmax = basic_machines.settings.power_stackmax
local machines_minstep = basic_machines.properties.machines_minstep
local machines_timer = basic_machines.properties.machines_timer
local power_stackmax = basic_machines.settings.power_stackmax
local space_start_eff = basic_machines.settings.space_start_eff
-- BATTERY
local function battery_update_form(pos)
local meta = minetest.get_meta(pos)
local list_name = "nodemeta:" .. pos.x .. ',' .. pos.y .. ',' .. pos.z
local function battery_update_form(meta)
meta:set_string("formspec", ([[
size[8,7]
label[0,0;%s]list[%s;fuel;0,0.5;1,1;]
label[0,0;%s]list[context;fuel;0,0.5;1,1;]
box[1.45,0.48;1.85,1;#222222]
label[1.5,0.5;%s]label[1.5,1;%s]
image_button[4.3,0.65;1.5,0.5;basic_machines_wool_black.png;help;%s]
label[6,0;%s]list[%s;upgrade;6,0.5;2,2;]
label[6,0;%s]list[context;upgrade;6,0.5;2,2;]
list[current_player;main;0,2.75;8,1;]
list[current_player;main;0,4;8,3;8]
listring[%s;upgrade]
listring[context;upgrade]
listring[current_player;main]
listring[%s;fuel]
listring[context;fuel]
listring[current_player;main]
%s
]]):format(F(S("FUEL")), list_name, F(S("Power: @1", meta:get_float("maxpower"))),
F(S("Capacity: @1", meta:get_float("capacity"))), F(S("help")), F(S("UPGRADE")),
list_name, list_name, list_name, default.get_hotbar_bg(0, 2.75)
]]):format(F(S("FUEL")), F(S("Power: @1", meta:get_float("maxpower"))),
F(S("Capacity: @1", meta:get_float("capacity"))), F(S("help")),
F(S("UPGRADE")), default.get_hotbar_bg(0, 2.75)
))
end
@ -134,8 +131,7 @@ basic_machines.check_power = function(pos, power_draw)
return power_draw
end
local function battery_upgrade(pos)
local meta = minetest.get_meta(pos)
local function battery_upgrade(meta, pos)
local inv = meta:get_inventory()
local count1, count2 = 0, 0
@ -195,7 +191,7 @@ minetest.register_node("basic_machines:battery_0", {
inv:set_size("fuel", 1) -- place to put crystals
inv:set_size("upgrade", 2 * 2)
battery_update_form(pos)
battery_update_form(meta)
end,
can_dig = function(pos, player)
@ -235,15 +231,17 @@ minetest.register_node("basic_machines:battery_0", {
if listname == "fuel" then
battery_recharge(pos)
elseif listname == "upgrade" then
battery_upgrade(pos)
battery_update_form(pos)
local meta = minetest.get_meta(pos)
battery_upgrade(meta, pos)
battery_update_form(meta)
end
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
if listname == "upgrade" then
battery_upgrade(pos)
battery_update_form(pos)
local meta = minetest.get_meta(pos)
battery_upgrade(meta, pos)
battery_update_form(meta)
end
end,
@ -254,11 +252,11 @@ minetest.register_node("basic_machines:battery_0", {
-- try to power furnace on top of it
if energy > 0 then -- need at least 1 energy
local node = minetest.get_node({x = pos.x, y = pos.y + 1, z = pos.z}).name
local fpos = {x = pos.x, y = pos.y + 1, z = pos.z} -- furnace pos
local node = minetest.get_node(fpos).name
if node == "default:furnace_active" or node == "default:furnace" then
local t0 = meta:get_int("ftime") -- furnace time
local t1 = minetest.get_gametime()
local fpos = vector.add(pos, {x = 0, y = 1, z = 0})
local fmeta = minetest.get_meta(fpos)
if t1 - t0 < machines_minstep then -- to prevent too quick furnace acceleration, punishment is cooking reset
@ -332,6 +330,53 @@ end
-- GENERATOR
local minenergy = 17500 -- amount of energy required to initialize a generator
local function generator_update_form(meta, not_init)
if not_init then
local upgrade = meta:get_float("upgrade")
local _, f = math.modf(upgrade)
if f > 0 then upgrade = ("%.2f"):format(upgrade) end
meta:set_string("formspec", ([[
size[8,6.5]
label[0,0;%s]list[context;fuel;0,0.5;1,1;]
box[1.45,0.48;2.5,1;#222222]
label[1.5,0.5;%s]label[1.5,1;%s]
image_button[4.5,0.65;1.5,0.5;basic_machines_wool_black.png;init;%s]
list[current_player;main;0,2.25;8,1;]
list[current_player;main;0,3.5;8,3;8]
listring[context;fuel]
listring[current_player;main]
%s
]]):format(F(S("FUEL")), F(S("Power: @1", -1)),
F(S("Energy: @1 / @2", upgrade, minenergy)),
F(S("initialize")), default.get_hotbar_bg(0, 2.25)
))
else
local upgrade = meta:get_int("upgrade")
local level = upgrade >= 20 and "high" or (upgrade >= 5 and "medium" or "low")
meta:set_string("formspec", ([[
size[8,6.5]
label[0,0;%s]list[context;fuel;0,0.5;1,1;]
box[1.45,0.48;2,0.85;#222222]
label[1.5,0.5;%s]
image_button[4.5,0.65;1.5,0.5;basic_machines_wool_black.png;help;%s]
label[6,0;%s]list[context;upgrade;6,0.5;2,1;]
list[current_player;main;0,2.25;8,1;]
list[current_player;main;0,3.5;8,3;8]
listring[context;fuel]
listring[current_player;main]
listring[context;upgrade]
listring[current_player;main]
%s
]]):format(F(S("POWER CRYSTALS")), F(S("Power: @1 (" .. level .. ")", upgrade)),
F(S("help")), F(S("UPGRADE")), default.get_hotbar_bg(0, 2.25)
))
end
end
minetest.register_abm({
label = "[basic_machines] Generator",
nodenames = {"basic_machines:generator"},
@ -346,6 +391,17 @@ minetest.register_abm({
meta:set_string("infotext", S("Error: max upgrade is @1", generator_upgrade_max)); return
end
if meta:get_string("owner") == "" then
local inv = meta:get_inventory()
if inv:get_size("fuel") == 0 then
meta:set_string("infotext", S("Generator - not enough energy to operate"))
meta:set_float("upgrade", 0)
inv:set_size("fuel", 1)
generator_update_form(meta, true)
end
return
end
local inv = meta:get_inventory()
local stack = inv:get_stack("fuel", 1)
local crystal, text
@ -367,35 +423,7 @@ minetest.register_abm({
end
})
local function generator_update_form(pos)
local meta = minetest.get_meta(pos)
local upgrade = meta:get_int("upgrade")
local list_name = "nodemeta:" .. pos.x .. ',' .. pos.y .. ',' .. pos.z
local level = upgrade >= 20 and "high" or (upgrade >= 5 and "medium" or "low")
meta:set_string("formspec", ([[
size[8,6.5]
label[0,0;%s]list[%s;fuel;0,0.5;1,1;]
box[1.45,0.48;2,0.85;#222222]
label[1.5,0.5;%s]
image_button[4.5,0.65;1.5,0.5;basic_machines_wool_black.png;help;%s]
label[6,0;%s]list[%s;upgrade;6,0.5;2,1;]
list[current_player;main;0,2.25;8,1;]
list[current_player;main;0,3.5;8,3;8]
listring[%s;fuel]
listring[current_player;main]
listring[%s;upgrade]
listring[current_player;main]
%s
]]):format(F(S("POWER CRYSTALS")), list_name,
F(S("Power: @1 (" .. level .. ")", upgrade)),
F(S("help")), F(S("UPGRADE")), list_name, list_name, list_name,
default.get_hotbar_bg(0, 2.25)
))
end
local function generator_upgrade(pos)
local meta = minetest.get_meta(pos)
local function generator_upgrade(meta)
local inv = meta:get_inventory()
local count = 0
for i = 1, 2 do
@ -407,6 +435,15 @@ local function generator_upgrade(pos)
meta:set_int("upgrade", count)
end
local function generator_near_found(pos, name) -- check to prevent too many generators being placed at one place
if minetest.find_node_near(pos, 15, {"basic_machines:generator"}) then
minetest.set_node(pos, {name = "air"})
minetest.add_item(pos, "basic_machines:generator")
minetest.chat_send_player(name, S("Generator: Interference from nearby generator detected"))
return true
end
end
minetest.register_node("basic_machines:generator", {
description = S("Generator - very expensive, generates power crystals that provide power, it's upgradeable"),
groups = {cracky = 3},
@ -415,15 +452,9 @@ minetest.register_node("basic_machines:generator", {
after_place_node = function(pos, placer)
if not placer then return end
local name = placer:get_player_name()
-- check to prevent too many generators being placed at one place
if minetest.find_node_near(pos, 15, {"basic_machines:generator"}) then
minetest.set_node(pos, {name = "air"})
minetest.add_item(pos, "basic_machines:generator")
minetest.chat_send_player(name, S("Generator: Interference from nearby generator detected"))
return
end
if generator_near_found(pos, name) then return end
local meta = minetest.get_meta(pos)
meta:set_string("infotext", S("Generator - generates power crystals that provide power," ..
@ -436,7 +467,7 @@ minetest.register_node("basic_machines:generator", {
inv:set_size("fuel", 1) -- here generated power crystals are placed
inv:set_size("upgrade", 2)
generator_update_form(pos)
generator_update_form(meta)
end,
can_dig = function(pos, player) -- fuel inv is not so important as generator generates it
@ -452,6 +483,22 @@ minetest.register_node("basic_machines:generator", {
"Low (0-4), medium (5-19) and high level (20+)." ..
" Upgrading the generator (upgrade with generators) will increase the rate at which the crystals are produced.\n\n" ..
"You can automate the process of battery recharging by using mover in inventory mode, taking from inventory \"fuel\".")) .. "]")
elseif fields.init then
local name = sender:get_player_name()
if minetest.is_protected(pos, name) or generator_near_found(pos, name) then return end
local meta = minetest.get_meta(pos)
if meta:get_float("upgrade") >= minenergy then
meta:set_string("owner", name)
meta:set_string("infotext", S("Generator - generates power crystals that provide power," ..
" upgrade with up to @1 generators", generator_upgrade_max))
meta:set_int("upgrade", 0) -- upgrade level determines quality of produced crystals
meta:get_inventory():set_size("upgrade", 2)
generator_update_form(meta)
end
end
end,
@ -471,15 +518,53 @@ minetest.register_node("basic_machines:generator", {
on_metadata_inventory_put = function(pos, listname, index, stack, player)
if listname == "upgrade" then
generator_upgrade(pos)
generator_update_form(pos)
local meta = minetest.get_meta(pos)
generator_upgrade(meta)
generator_update_form(meta)
elseif listname == "fuel" then
local meta = minetest.get_meta(pos)
if meta:get_string("owner") == "" then
local inv = meta:get_inventory()
local inv_stack = inv:get_stack("fuel", 1)
local add_energy = energy_crystals[inv_stack:get_name()] or 0
local energy = meta:get_float("upgrade")
if add_energy > 0 then
add_energy = add_energy * inv_stack:get_count()
if add_energy <= minenergy then
inv:set_stack("fuel", 1, ItemStack(""))
else
return
end
else -- try do determine caloric value of fuel inside battery
local fueladd, _ = minetest.get_craft_result({method = "fuel", width = 1, items = {inv_stack}})
if fueladd.time > 0 then
add_energy = (fueladd.time / 40) * inv_stack:get_count()
if energy + add_energy <= minenergy + 3 then
inv:set_stack("fuel", 1, ItemStack(""))
else
return
end
end
end
if add_energy > 0 then
energy = energy + add_energy
if energy < 0 then energy = 0 end
if energy > minenergy then energy = minenergy end -- excess energy is wasted
meta:set_float("upgrade", energy)
minetest.sound_play("basic_machines_electric_zap", {pos = pos, gain = 0.05, max_hear_distance = 8}, true)
generator_update_form(meta, true)
end
end
end
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
if listname == "upgrade" then
generator_upgrade(pos)
generator_update_form(pos)
local meta = minetest.get_meta(pos)
generator_upgrade(meta)
generator_update_form(meta)
end
end
})