everything fine

cleaning againnn, fix /clockgen, read float with 2 digits precision
mark: looop, add 2 markers
mover: reeorganize things, reduce infotext overwriting, add upgradetype, add friendly overheat, add 2 buttons to formspec
recycler: no fuel check with priv privs
This commit is contained in:
мтест 2022-11-15 17:51:25 +01:00 committed by GitHub
parent 1d492fa105
commit de77ada483
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 526 additions and 465 deletions

View File

@ -353,6 +353,7 @@ minetest.register_node("basic_machines:ball_spawner", {
meta:set_string("texture", ball_default.texture)
meta:set_int("scale", ball_default.scale)
meta:set_string("visual", ball_default.visual) -- cube or sprite
meta:set_int("t", 0); meta:set_int("T", 0)
ball_spawner_update_form(meta)
end,
@ -382,7 +383,8 @@ minetest.register_node("basic_machines:ball_spawner", {
on_receive_fields = function(pos, formname, fields, sender)
local name = sender:get_player_name()
if fields.OK and not minetest.is_protected(pos, name) then
if fields.OK then
if minetest.is_protected(pos, name) then return end
local privs = minetest.check_player_privs(name, "privs")
local meta = minetest.get_meta(pos)
@ -502,20 +504,18 @@ max_damage, lifetime, bounce_materialslist)) .. "]")
if t0 > t1 - 2 * machines_minstep then -- activated before natural time
T = T + 1
else
if T > 0 then
elseif T > 0 then
if t1 - t0 > machines_timer then -- reset temperature if more than 5s elapsed since last activation
T = 0; meta:set_string("infotext", "")
else
T = T - 1
if t1 - t0 > machines_timer then -- reset temperature if more than 5s elapsed since last activation
T = 0; meta:set_string("infotext", "")
end
end
end
meta:set_int("T", T)
meta:set_int("t", t1) -- update last activation time
meta:set_int("t", t1); meta:set_int("T", T)
if T > 2 then -- overheat
minetest.sound_play("default_cool_lava", {pos = pos, max_hear_distance = 16, gain = 0.25}, true)
meta:set_string("infotext", S("Overheat: temperature @1", T))
meta:set_string("infotext", S("Overheat! Temperature: @1", T))
return
end
@ -608,20 +608,18 @@ max_damage, lifetime, bounce_materialslist)) .. "]")
if t0 > t1 - 2 * machines_minstep then -- activated before natural time
T = T + 1
else
if T > 0 then
elseif T > 0 then
if t1 - t0 > machines_timer then -- reset temperature if more than 5s elapsed since last activation
T = 0; meta:set_string("infotext", "")
else
T = T - 1
if t1 - t0 > machines_timer then -- reset temperature if more than 5s elapsed since last activation
T = 0; meta:set_string("infotext", "")
end
end
end
meta:set_int("T", T)
meta:set_int("t", t1) -- update last activation time
meta:set_int("t", t1); meta:set_int("T", T)
if T > 2 then -- overheat
minetest.sound_play("default_cool_lava", {pos = pos, max_hear_distance = 16, gain = 0.25}, true)
meta:set_string("infotext", S("Overheat: temperature @1", T))
meta:set_string("infotext", S("Overheat! Temperature: @1", T))
return
end

View File

@ -1,7 +1,6 @@
local S = basic_machines.S
local machines_TTL = basic_machines.properties.machines_TTL
local machines_timer = basic_machines.properties.machines_timer
local no_clock = basic_machines.properties.no_clock
minetest.register_abm({
label = "[basic_machines] Clock Generator",
@ -11,7 +10,7 @@ minetest.register_abm({
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
if no_clock then return end
if basic_machines.properties.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

View File

@ -126,8 +126,9 @@ local function add_constructor(name, def)
end,
on_receive_fields = function(pos, formname, fields, sender)
if fields.quit then return end
local player_name = sender:get_player_name()
if fields.quit or minetest.is_protected(pos, player_name) then return end
if minetest.is_protected(pos, player_name) then return end
if fields.CRAFT then
constructor_process(pos, name, player_name)

View File

@ -32,6 +32,7 @@ minetest.register_node("basic_machines:detector", {
meta:set_string("node", ""); meta:set_int("NOT", 2)
meta:set_string("mode", "node")
meta:set_int("state", 0)
meta:set_int("t", 0); meta:set_int("T", 0)
end,
can_dig = function(pos, player)
@ -111,7 +112,6 @@ minetest.register_node("basic_machines:detector", {
effector = {
action_on = function(pos, ttl)
if type(ttl) ~= "number" then ttl = 1 end
if ttl < 1 then return end -- machines_TTL prevents infinite recursion
local meta = minetest.get_meta(pos)
@ -121,15 +121,14 @@ minetest.register_node("basic_machines:detector", {
if t0 > t1 - machines_minstep then -- activated before natural time
T = T + 1
else
if T > 0 then T = T - 1 end
elseif T > 0 then
T = T - 1
end
meta:set_int("T", T)
meta:set_int("t", t1) -- update last activation time
meta:set_int("t", t1); meta:set_int("T", T)
if T > 2 then -- overheat
minetest.sound_play("default_cool_lava", {pos = pos, max_hear_distance = 16, gain = 0.25}, true)
meta:set_string("infotext", S("Overheat: temperature @1", T))
meta:set_string("infotext", S("Overheat! Temperature: @1", T))
return
end

View File

@ -44,7 +44,7 @@ basic_machines.get_distributor_form = function(pos)
local y = 0.25 + n * 0.75
form[#form + 1] = "label[0.25," .. (0.4 + n * 0.75) .. ";" .. minetest.colorize("lawngreen", F(S("delay"))) ..
"]field[1.25," .. (0.5 + n * 0.75) .. ";1,1;delay;;" .. meta:get_float("delay") ..
"]field[1.25," .. (0.5 + n * 0.75) .. ";1,1;delay;;" .. basic_machines.twodigits_float(meta:get_float("delay")) ..
"]button_exit[2.97," .. y .. ";1,1;OK;" .. F(S("OK")) .. "]button[4.25," .. y .. ";1,1;ADD;" .. F(S("ADD")) ..
"]button[5.25," .. y .. ";1,1;view;" .. F(S("view")) .. "]button[6.25," .. y .. ";1,1;help;" .. F(S("help")) .. "]"
@ -84,6 +84,7 @@ minetest.register_node("basic_machines:distributor", {
end
meta:set_int("n", 2) -- how many targets initially
meta:set_float("delay", 0) -- delay when transmitting signal
meta:set_int("t", 0); meta:set_int("T", 0)
end,
can_dig = function(pos, player)
@ -98,7 +99,6 @@ minetest.register_node("basic_machines:distributor", {
effector = {
action_on = function(pos, ttl)
if type(ttl) ~= "number" then ttl = 1 end
if ttl < 1 then return end -- machines_TTL prevents infinite recursion
local meta = minetest.get_meta(pos)
@ -108,20 +108,18 @@ minetest.register_node("basic_machines:distributor", {
if t0 > t1 - machines_minstep then -- activated before natural time
T = T + 1
else
if T > 0 then
elseif T > 0 then
if t1 - t0 > machines_timer then -- reset temperature if more than 5s elapsed since last activation
T = 0; meta:set_string("infotext", "")
else
T = T - 1
if t1 - t0 > machines_timer then -- reset temperature if more than 5s elapsed since last activation
T = 0; meta:set_string("infotext", "")
end
end
end
meta:set_int("T", T)
meta:set_int("t", t1) -- update last activation time
meta:set_int("t", t1); meta:set_int("T", T)
if T > 2 then -- overheat
minetest.sound_play("default_cool_lava", {pos = pos, max_hear_distance = 16, gain = 0.25}, true)
meta:set_string("infotext", S("Overheat: temperature @1", T))
meta:set_string("infotext", S("Overheat! Temperature: @1", T))
return
end
@ -165,7 +163,6 @@ minetest.register_node("basic_machines:distributor", {
end,
action_off = function(pos, ttl)
if type(ttl) ~= "number" then ttl = 1 end
if ttl < 1 then return end -- machines_TTL prevents infinite recursion
local meta = minetest.get_meta(pos)
@ -175,20 +172,18 @@ minetest.register_node("basic_machines:distributor", {
if t0 > t1 - machines_minstep then -- activated before natural time
T = T + 1
else
if T > 0 then
elseif T > 0 then
if t1 - t0 > machines_timer then -- reset temperature if more than 5s elapsed since last activation
T = 0; meta:set_string("infotext", "")
else
T = T - 1
if t1 - t0 > machines_timer then -- reset temperature if more than 5s elapsed since last activation
T = 0; meta:set_string("infotext", "")
end
end
end
meta:set_int("T", T)
meta:set_int("t", t1) -- update last activation time
meta:set_int("t", t1); meta:set_int("T", T)
if T > 2 then -- overheat
minetest.sound_play("default_cool_lava", {pos = pos, max_hear_distance = 16, gain = 0.25}, true)
meta:set_string("infotext", S("Overheat: temperature @1", T))
meta:set_string("infotext", S("Overheat! Temperature: @1", T))
return
end

View File

@ -129,7 +129,9 @@ minetest.register_node("basic_machines:enviro", {
on_receive_fields = function(pos, formname, fields, sender)
local name = sender:get_player_name()
if fields.OK and not minetest.is_protected(pos, name) then
if fields.OK then
if minetest.is_protected(pos, name) then return end
local meta = minetest.get_meta(pos)
meta:set_string("infotext", S("Right click to set it. Activate by signal."))
local privs = minetest.check_player_privs(name, "privs")

View File

@ -1,8 +1,9 @@
-- There is a certain fuel cost to operate
local F, S = basic_machines.F, basic_machines.S
local machines_minstep = basic_machines.properties.machines_minstep
local grinder_dusts_legacy = basic_machines.settings.grinder_dusts_legacy
local machines_minstep = basic_machines.properties.machines_minstep
local twodigits_float = basic_machines.twodigits_float
local use_unified_inventory = minetest.global_exists("unified_inventory")
local use_i3 = minetest.global_exists("i3")
-- grinder recipes:
@ -327,10 +328,10 @@ local function grinder_process(pos)
end
if fuel < fuel_req then
meta:set_string("infotext", S("Need at least @1 fuel to complete operation", fuel_req - fuel)); return
meta:set_string("infotext",
S("Need at least @1 fuel to complete operation", twodigits_float(fuel_req - fuel))); return
else
-- meta:set_string("infotext", S("Added fuel furnace burn time @1, fuel status @2", fueladd.time, fuel))
msg = S("Added fuel furnace burn time @1, fuel status @2", fueladd.time, fuel)
msg = S("Added fuel furnace burn time @1, fuel status @2", fueladd.time, twodigits_float(fuel))
end
end
@ -351,7 +352,7 @@ local function grinder_process(pos)
minetest.sound_play("basic_machines_grinder", {pos = pos, gain = 0.5, max_hear_distance = 16}, true)
fuel = fuel - fuel_req; meta:set_float("fuel", fuel) -- burn fuel
meta:set_string("infotext", S("Fuel status @1", fuel))
meta:set_string("infotext", S("Fuel status @1", twodigits_float(fuel)))
end
local function grinder_upgrade(meta)
@ -375,6 +376,7 @@ minetest.register_node("basic_machines:grinder", {
meta:set_string("owner", placer:get_player_name())
meta:set_float("fuel", 0)
meta:set_int("t", 0)
local inv = meta:get_inventory()
inv:set_size("src", 1)
@ -397,7 +399,8 @@ minetest.register_node("basic_machines:grinder", {
on_receive_fields = function(pos, formname, fields, sender)
if fields.quit then return end
if fields.OK and not minetest.is_protected(pos, sender:get_player_name()) then
if fields.OK then
if minetest.is_protected(pos, sender:get_player_name()) then return end
grinder_process(pos)
elseif fields.help then

View File

@ -40,6 +40,8 @@ basic_machines = {
grinder_dusts_quantity = 2, -- quantity of dusts produced by lump/ingot, minimum 0
grinder_dusts_legacy = false, -- legacy dust mode: dust_33 (smelt) -> dust_66 (smelt) -> ingot
grinder_extractors_type = 1, -- recipe priority if optional mod present, 1: farming_redo, 2: x_farming
-- mover
mover_max_temp = 176, -- overheat above this temperature, minimum 1
-- technic_power
generator_upgrade = 0, -- upgrade available in addition to the current limit (50)
-- space
@ -90,6 +92,19 @@ function basic_machines.creative(name)
{creative = true})
end
-- result: float with precision of two digits or unchanged number
local modf = math.modf
function basic_machines.twodigits_float(number)
local r
if number ~= 0 then
local _, f = modf(number)
if f ~= 0 then r = ("%.2f"):format(number) else r = number end
else
r = 0
end
return r
end
-- load files
local MP = minetest.get_modpath("basic_machines") .. "/"

View File

@ -2,7 +2,6 @@ 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
@ -34,18 +33,14 @@ basic_machines.use_keypad = function(pos, ttl, reset, reset_msg)
if t0 > t1 - machines_minstep then -- activated before natural time
T = T + 1
else
if T > 0 then
T = T - 1
if t1 - t0 > machines_timer then T = 0 end
end
elseif T > 0 then
if t1 - t0 > machines_timer then T = 0 else T = T - 1 end
end
meta:set_int("T", T)
meta:set_int("t", t1) -- update last activation time
meta:set_int("t", t1); meta:set_int("T", T)
if T > 2 then -- overheat
minetest.sound_play("default_cool_lava", {pos = pos, max_hear_distance = 16, gain = 0.25}, true)
meta:set_string("infotext", S("Overheat: temperature @1", T))
meta:set_string("infotext", S("Overheat! Temperature: @1", T))
return
end
@ -59,7 +54,7 @@ basic_machines.use_keypad = function(pos, ttl, reset, reset_msg)
local count = 0 -- counts repeats
if iter > 1 then
if no_clock then return end
if basic_machines.properties.no_clock then return end
count = meta:get_int("count")
if reset and count > 0 or count == iter then
@ -87,13 +82,11 @@ basic_machines.use_keypad = function(pos, ttl, reset, reset_msg)
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)
meta:set_string("infotext", S("Keypad operation: @1 cycle left", count))
else
msg = S("Keypad operation: @1 cycles left", count)
meta:set_string("infotext", S("Keypad operation: @1 cycles left", count))
end
meta:set_string("infotext", msg)
end
if text ~= "" then -- TEXT MODE; set text on target
@ -252,6 +245,7 @@ minetest.register_node("basic_machines:keypad", {
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)
meta:set_int("t", 0); meta:set_int("T", 0)
end,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)

View File

@ -33,7 +33,8 @@ minetest.register_node("basic_machines:light_on", {
end,
on_receive_fields = function(pos, formname, fields, sender)
if fields.OK and not minetest.is_protected(pos, sender:get_player_name()) then
if fields.OK then
if minetest.is_protected(pos, sender:get_player_name()) then return end
local meta = minetest.get_meta(pos)
local deactivate = tonumber(fields.deactivate) or 0
if deactivate < 0 or deactivate > 600 then deactivate = 0 end

View File

@ -51,7 +51,7 @@ Visual*: "cube" or "sprite"@
@n***: 0: not punchable, 1: only in protected area, 2: everywhere@
@nNote: Hold sneak while digging to get the Ball Spawner@n=
##
Overheat: temperature @1=
Overheat! Temperature: @1=
Ball Spawner=
# clockgen.lua
@ -246,9 +246,9 @@ MOVER: Punch closer to mover. Resetting.=
MOVER: Punch something else. Aborting.=
MOVER: Source1 position for mover set. Punch again to set source2 position.=
MOVER: Source2 position for mover set. Punch again to set target position.=
MOVER: Error while trying to make an elevator. Need at least @1 diamond block(s) in upgrade (1 for every 100 distance).=
ELEVATOR: Activate to use.=
MOVER: Elevator setup completed, upgrade level @1.=
MOVER: Error while trying to make an elevator. Need at least @1 diamond block(s) in upgrade (1 for every 100 distance).=
MOVER: Punch closer to mover. Aborting.=
MOVER: End position for mover set.=
DISTRIBUTOR: Punch closer to distributor. Aborting.=
@ -277,8 +277,8 @@ Inventory mode can exchange items between node inventories. You need to select i
@nADVANCED:@
You can reverse start/end position by setting reverse nonzero. This is useful for placing stuff at many locations-planting. If you put reverse @= 2/3 in transport mode it will disable parallel transport but will still do reverse effect with 3. If you activate mover with OFF signal it will toggle reverse.=
#
@n@nFUEL CONSUMPTION depends on blocks to be moved and distance. For example, stone or tree is harder to move than dirt, harvesting wheat is very cheap and and moving lava is very hard.@
@nUPGRADE mover by moving mese blocks in upgrade inventory. Each mese block increases mover range by @1, fuel consumption is divided by (number of mese blocks)+1 in upgrade. Max @2 blocks are used for upgrade.@
@n@nFUEL CONSUMPTION depends on blocks to be moved, distance and temperature. For example, stone or tree is harder to move than dirt, harvesting wheat is very cheap and and moving lava is very hard. High temperature increases fuel consumption while low temperature reduces it.@
@nUPGRADE mover by moving mese blocks in upgrade inventory. Each mese block increases mover range by @1, fuel consumption is divided by number of mese blocks in upgrade. Max @2 blocks are used for upgrade.@
@nActivate mover by keypad/detector signal or mese signal through mesecon adapter (if mesecons mod).=
##
DISTRIBUTOR: Position @1 is protected. Aborting.=
@ -373,6 +373,8 @@ recipe=
src=
upgrade=
Target inventory=
Now=
Show=
INPUT AREA - mover will dig here=
TARGET POSITION - mover will move to here=
REVERSE source and target (0/1/2/3)=
@ -398,7 +400,8 @@ Mover block refueled. Fuel status @1.=
@1 already milked!=
Cow=
Cows=
Mover block. Fuel status @1.=
Mover block. Temperature: @1, Fuel: @2.=
MOVER: Filter defined with unknown node (@1) at @2,@3,@4.=
MOVER: Wrong filter (@1) at @2,@3,@4.=
# recycler.lua

View File

@ -74,14 +74,14 @@ minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
}
local msg
if punchset_desc == "MOVER" then
msg = "MOVER: Now punch source1, source2, end position to set up mover."
msg = S("MOVER: Now punch source1, source2, end position to set up mover.")
elseif punchset_desc == "KEYPAD" then
msg = "KEYPAD: Now punch the target block."
msg = S("KEYPAD: Now punch the target block.")
elseif punchset_desc == "DETECTOR" then
msg = "DETECTOR: Now punch the source block."
msg = S("DETECTOR: Now punch the source block.")
end
if msg then
minetest.chat_send_player(name, S(msg))
minetest.chat_send_player(name, msg)
end
return
end
@ -99,7 +99,9 @@ minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
local privs = minetest.check_player_privs(name, "privs")
local range
if meta:get_inventory():get_stack("upgrade", 1):get_name() == "default:mese" then
if meta:get_int("upgradetype") == 1 or
meta:get_inventory():get_stack("upgrade", 1):get_name() == "default:mese" -- for compatibility
then
range = meta:get_int("upgrade") * max_range
else
range = max_range
@ -154,17 +156,16 @@ minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
if ecost > 3 then -- trying to make an elevator ?
-- count number of diamond blocks to determine if elevator can be set up with this height distance
local upgrade = meta:get_int("upgrade")
local requirement = math.floor(ecost / 100) + 1
if upgrade - 1 < requirement and
meta:get_inventory():get_stack("upgrade", 1):get_name() ~= "default:diamondblock" and upgrade ~= -1
if (upgrade - 1) >= requirement and (meta:get_int("upgradetype") == 2 or
meta:get_inventory():get_stack("upgrade", 1):get_name() == "default:diamondblock") or upgrade == -1 -- for compatibility
then
minetest.chat_send_player(name, S("MOVER: Error while trying to make an elevator. Need at least @1 diamond block(s) in upgrade (1 for every 100 distance).", requirement))
punchset[name] = {state = 0, node = ""}; return
else
meta:set_int("elevator", 1)
meta:set_string("infotext", S("ELEVATOR: Activate to use."))
minetest.chat_send_player(name, S("MOVER: Elevator setup completed, upgrade level @1.", upgrade - 1))
else
minetest.chat_send_player(name, S("MOVER: Error while trying to make an elevator. Need at least @1 diamond block(s) in upgrade (1 for every 100 distance).", requirement))
punchset[name] = {state = 0, node = ""}; return
end
end
end
@ -337,7 +338,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
-- MOVER
if formname_sub == "mover" then
if fields.OK and not minetest.is_protected(pos, name) then
if fields.OK then
if minetest.is_protected(pos, name) then return end
if meta:get_int("seltab") == 2 then -- POSITIONS
local x0, y0, z0 = tonumber(fields.x0) or 0, tonumber(fields.y0) or -1, tonumber(fields.z0) or 0
local x1, y1, z1 = tonumber(fields.x1) or 0, tonumber(fields.y1) or -1, tonumber(fields.z1) or 0
@ -435,6 +438,19 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
minetest.show_formspec(name, "basic_machines:mover_" .. minetest.pos_to_string(pos),
basic_machines.get_mover_form(pos, name))
elseif fields.now then -- mark current position
local markerN = machines.mark_posN(meta:get_string("owner"), pos)
if markerN then markerN:get_luaentity()._origin = pos end
elseif fields.show then -- display mover area defined by sources
local pos1 = {x = meta:get_int("x0"), y = meta:get_int("y0"), z = meta:get_int("z0")} -- source1
local pos11 = {x = meta:get_int("x1"), y = meta:get_int("y1"), z = meta:get_int("z1")} -- source2
local markerA = machines.mark_posA(name, vector.add(pos, vector.divide(vector.add(pos1, pos11), 2)))
if markerA then
markerA:set_properties({visual_size = {x = abs(pos11.x - pos1.x) + 1.11,
y = abs(pos11.y - pos1.y) + 1.11, z = abs(pos11.z - pos1.z) + 1.11}})
end
elseif fields.help then
minetest.show_formspec(name, "basic_machines:help_mover", "size[6,7]textarea[0,0;6.5,8.5;help;" ..
F(S("MOVER HELP")) .. ";" .. F(S("version @1\nSETUP: For interactive setup punch the mover and then punch source1, source2, target node (follow instructions)." ..
@ -451,27 +467,30 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
" This is useful for placing stuff at many locations-planting." ..
" If you put reverse = 2/3 in transport mode it will disable parallel transport but will still do reverse effect with 3." ..
" If you activate mover with OFF signal it will toggle reverse.")) ..
F(S("\n\nFUEL CONSUMPTION depends on blocks to be moved and distance." ..
F(S("\n\nFUEL CONSUMPTION depends on blocks to be moved, distance and temperature." ..
" For example, stone or tree is harder to move than dirt, harvesting wheat is very cheap and and moving lava is very hard." ..
" High temperature increases fuel consumption while low temperature reduces it." ..
"\n\nUPGRADE mover by moving mese blocks in upgrade inventory." ..
" Each mese block increases mover range by @1, fuel consumption is divided by (number of mese blocks)+1 in upgrade." ..
" Each mese block increases mover range by @1, fuel consumption is divided by number of mese blocks in upgrade." ..
" Max @2 blocks are used for upgrade." ..
"\n\nActivate mover by keypad/detector signal or mese signal through mesecon adapter (if mesecons mod).",
max_range, mover_upgrade_max)) .. "]")
elseif fields.mode and not minetest.is_protected(pos, name) then
elseif fields.mode then
if minetest.is_protected(pos, name) then return end
local mode = strip_translator_sequence(fields.mode, meta:get_string("mode"))
-- input validation
if not basic_machines.check_mover_filter(mode, meta:get_string("prefer"), meta:get_int("reverse")) and
not basic_machines.check_target_chest(mode, pos, meta)
if basic_machines.check_mover_filter(mode, meta:get_string("prefer"), meta:get_int("reverse")) or
basic_machines.check_target_chest(mode, pos, meta)
then
minetest.chat_send_player(name, S("MOVER: Wrong filter - must be name of existing minetest block")); return
meta:set_string("mode", mode)
minetest.show_formspec(name, "basic_machines:mover_" .. minetest.pos_to_string(pos),
basic_machines.get_mover_form(pos, name))
else
minetest.chat_send_player(name, S("MOVER: Wrong filter - must be name of existing minetest block"))
end
meta:set_string("mode", mode)
minetest.show_formspec(name, "basic_machines:mover_" .. minetest.pos_to_string(pos),
basic_machines.get_mover_form(pos, name))
end
@ -515,7 +534,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
end
meta:set_float("delay", tonumber(fields.delay) or 0)
meta:set_float("delay", basic_machines.twodigits_float(tonumber(fields.delay) or 0))
elseif fields.ADD then
if minetest.is_protected(pos, name) then return end
@ -630,7 +649,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
-- KEYPAD
elseif formname_sub == "keypad" then
if fields.OK and not minetest.is_protected(pos, name) then
if fields.OK then
if minetest.is_protected(pos, name) then return end
local x0, y0, z0 = tonumber(fields.x0) or 0, tonumber(fields.y0) or 1, tonumber(fields.z0) or 0
if minetest.is_protected(vector.add(pos, {x = x0, y = y0, z = z0}), name) then
@ -730,7 +751,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
-- DETECTOR
elseif formname_sub == "detector" then
if fields.OK and not minetest.is_protected(pos, name) then
if fields.OK then
if minetest.is_protected(pos, name) then return end
local x0, y0, z0 = tonumber(fields.x0) or 0, tonumber(fields.y0) or 0, tonumber(fields.z0) or 0
local x1, y1, z1 = tonumber(fields.x1) or 0, tonumber(fields.y1) or 0, tonumber(fields.z1) or 0
local x2, y2, z2 = tonumber(fields.x2) or 0, tonumber(fields.y2) or 0, tonumber(fields.z2) or 0

186
mark.lua
View File

@ -1,144 +1,66 @@
-- rnd: code borrowed from machines, mark.lua
-- Needed for marking
machines = {
marker1 = {}, marker11 = {}, marker2 = {}
}
machines = {}
-- mark position 1
machines.mark_pos1 = function(name, pos)
minetest.get_voxel_manip():read_from_map(pos, pos) -- make area stay loaded
for _, n in ipairs({"1", "11", "2", "N", "A"}) do
local markern = "marker" .. n
local posn = "machines:pos" .. n
local texturen, delay
if machines.marker1[name] then -- marker already exists
machines.marker1[name]:remove() -- remove marker
if n == "N" then
texturen = "machines_pos.png^[colorize:#ffd700"
delay = 27
elseif n == "A" then
texturen = "machines_pos.png^[colorize:#008080"
delay = 21
else
texturen = "machines_pos" .. n .. ".png"
delay = 9
end
-- add marker
machines.marker1[name] = minetest.add_entity(pos, "machines:pos1")
machines[markern] = {}
if machines.marker1[name] then
machines.marker1[name]:get_luaentity()._name = name
end
end
-- mark position 11
machines.mark_pos11 = function(name, pos)
minetest.get_voxel_manip():read_from_map(pos, pos) -- make area stay loaded
if machines.marker11[name] then -- marker already exists
machines.marker11[name]:remove() -- remove marker
end
-- add marker
machines.marker11[name] = minetest.add_entity(pos, "machines:pos11")
if machines.marker11[name] then
machines.marker11[name]:get_luaentity()._name = name
end
end
-- mark position 2
machines.mark_pos2 = function(name, pos)
minetest.get_voxel_manip():read_from_map(pos, pos) -- make area stay loaded
if machines.marker2[name] then -- marker already exists
machines.marker2[name]:remove() -- remove marker
end
-- add marker
machines.marker2[name] = minetest.add_entity(pos, "machines:pos2")
if machines.marker2[name] then
machines.marker2[name]:get_luaentity()._name = name
end
end
minetest.register_entity(":machines:pos1", {
initial_properties = {
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
visual = "cube",
visual_size = {x = 1.1, y = 1.1},
textures = {"machines_pos1.png", "machines_pos1.png",
"machines_pos1.png", "machines_pos1.png",
"machines_pos1.png", "machines_pos1.png"},
glow = 11,
static_save = false,
shaded = false
},
on_deactivate = function(self)
machines.marker1[self._name] = nil
end,
on_step = function(self, dtime)
self._timer = self._timer + dtime
if self._timer > 9 then
self.object:remove()
machines["mark_pos" .. n] = function(name, pos)
if machines[markern][name] then -- marker already exists
machines[markern][name]:remove() -- remove marker
end
end,
on_punch = function(self)
minetest.after(0.1, function()
self.object:remove()
end)
end,
_name = "",
_timer = 0
})
minetest.register_entity(":machines:pos11", {
initial_properties = {
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
visual = "cube",
visual_size = {x = 1.1, y = 1.1},
textures = {"machines_pos11.png", "machines_pos11.png",
"machines_pos11.png", "machines_pos11.png",
"machines_pos11.png", "machines_pos11.png"},
glow = 11,
static_save = false,
shaded = false
},
on_deactivate = function(self)
machines.marker11[self._name] = nil
end,
on_step = function(self, dtime)
self._timer = self._timer + dtime
if self._timer > 9 then
self.object:remove()
-- add marker
machines[markern][name] = minetest.add_entity(pos, posn)
if machines[markern][name] then
machines[markern][name]:get_luaentity()._name = name
end
end,
on_punch = function(self)
minetest.after(0.1, function()
self.object:remove()
end)
end,
_name = "",
_timer = 0
})
minetest.register_entity(":machines:pos2", {
initial_properties = {
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
visual = "cube",
visual_size = {x = 1.1, y = 1.1},
textures = {"machines_pos2.png", "machines_pos2.png",
"machines_pos2.png", "machines_pos2.png",
"machines_pos2.png", "machines_pos2.png"},
glow = 11,
static_save = false,
shaded = false
},
on_deactivate = function(self)
machines.marker2[self._name] = nil
end,
on_step = function(self, dtime)
self._timer = self._timer + dtime
if self._timer > 9 then
self.object:remove()
end
end,
on_punch = function(self)
minetest.after(0.1, function()
self.object:remove()
end)
end,
_name = "",
_timer = 0
})
return machines[markern][name]
end
minetest.register_entity(":" .. posn, {
initial_properties = {
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
visual = "cube",
visual_size = {x = 1.1, y = 1.1},
textures = {texturen, texturen, texturen,
texturen, texturen, texturen},
glow = 11,
static_save = false,
shaded = false
},
on_deactivate = function(self)
machines[markern][self._name] = nil
end,
on_step = function(self, dtime)
self._timer = self._timer + dtime
if self._timer > delay then
self.object:remove()
end
end,
on_punch = function(self)
minetest.after(0.1, function()
self.object:remove()
end)
end,
_name = "",
_timer = 0
})
end

View File

@ -18,8 +18,7 @@ local adapter_effector = {
else -- def.mesecons and def.mesecons.effector then -- activate mesecons
pos.y = pos.y - 1
mesecon.receptor_on(pos, mesecon.rules.buttonlike_get(node))
-- effector = def.mesecons.effector
-- effector.action_on(pos)
-- effector = def.mesecons.effector; effector.action_on(pos, node)
end
end,
@ -38,8 +37,7 @@ local adapter_effector = {
else -- def.mesecons and def.mesecons.effector then -- activate mesecons
pos.y = pos.y - 1
mesecon.receptor_off(pos, mesecon.rules.buttonlike_get(node))
-- effector = def.mesecons.effector
-- effector.action_off(pos, node)
-- effector = def.mesecons.effector; effector.action_off(pos, node)
end
end
}

490
mover.lua
View File

@ -7,8 +7,13 @@
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 machines_timer = basic_machines.properties.machines_timer
local max_range = basic_machines.properties.max_range
local mover_max_temp = math.max(1, basic_machines.settings.mover_max_temp)
local twodigits_float = basic_machines.twodigits_float
local vector_add = vector.add
local temp_80P = mover_max_temp > 12 and math.ceil(mover_max_temp * 0.8)
local temp_15P = math.ceil(mover_max_temp * 0.15)
local abs = math.abs
local vplayer = {}
local have_bucket_liquids = minetest.global_exists("bucket") and bucket.liquids
@ -69,7 +74,7 @@ local mover = {
["x_farming:cocoa_2"] = 999999,
["x_farming:cocoa_3"] = 999999,
-- move machines for free
-- move machines for free (mostly)
["basic_machines:ball_spawner"] = 0,
["basic_machines:battery_0"] = 0,
["basic_machines:battery_1"] = 0,
@ -130,6 +135,8 @@ local mover = {
[""] = true,
["3d_armor_stand:armor_entity"] = true,
["__builtin:item"] = true,
["machines:posA"] = true,
["machines:posN"] = true,
["painting:paintent"] = true,
["painting:picent"] = true,
["shield_frame:shield_entity"] = true,
@ -297,7 +304,7 @@ basic_machines.get_mover_form = function(pos, name)
local pos1 = {x = meta:get_int("x0"), y = meta:get_int("y0"), z = meta:get_int("z0")}
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 inventory_list1, inventory_list2 = "", ""
local inventory_list1, inventory_list2, btns_ns
if mode_string == "inventory" then
local meta1 = minetest.get_meta(vector_add(pos, pos1)) -- source1 meta
@ -325,9 +332,17 @@ basic_machines.get_mover_form = function(pos, name)
inv_list1:gsub(",$", "") .. ";" .. inv1 .. "]"
inventory_list2 = "label[4.5,3.1;" .. F(S("Target inventory")) .. "]dropdown[4.5,3.5;1.5,1;inv2;" ..
inv_list2:gsub(",$", "") .. ";" .. inv2 .. "]"
else
inventory_list1, inventory_list2 = "", ""
end
return ("size[6.25,6]tabheader[0,0;tabs;" ..
if mode_string == "object" then
btns_ns = ""
else
btns_ns = "button_exit[0,5.7;1,1;now;" .. F(S("Now")) .. "]button_exit[1,5.7;1,1;show;" .. F(S("Show")) .. "]"
end
return ("size[6.25,6.5]tabheader[0,0;tabs;" ..
F(S("MODE OF OPERATION")) .. "," .. F(S("WHERE TO MOVE")) .. ";" .. seltab .. ";true;true]" ..
"label[0,0;" .. minetest.colorize("lawngreen", F(S("INPUT AREA - mover will dig here"))) ..
"]field[0.25,1;1,1;x0;" .. F(S("Source1")) .. ";" .. pos1.x .. "]field[1.25,1;1,1;y0;;" .. pos1.y .. "]field[2.25,1;1,1;z0;;" .. pos1.z ..
@ -337,8 +352,8 @@ basic_machines.get_mover_form = function(pos, name)
"label[0,2.75;" .. minetest.colorize("red", F(S("TARGET POSITION - mover will move to here"))) ..
"]field[0.25,3.75;1,1;x2;" .. F(S("Target")) .. ";" .. pos2.x .. "]field[1.25,3.75;1,1;y2;;" .. pos2.y .. "]field[2.25,3.75;1,1;z2;;" .. pos2.z ..
"]image[3,3.5;1,1;machines_pos2.png]" .. inventory_list2 .. "label[0,4.4;" .. F(S("REVERSE source and target (0/1/2/3)")) ..
"]field[0.25,5;1,1;reverse;;" .. meta:get_int("reverse") ..
"]listring[current_player;main]button[4.1,4.7;1,1;help;" .. F(S("help")) .. "]button_exit[5.1,4.7;1,1;OK;" .. F(S("OK")) .. "]")
"]field[0.25,5;1,1;reverse;;" .. meta:get_int("reverse") .. "]" .. btns_ns ..
"button[4.1,5.7;1,1;help;" .. F(S("help")) .. "]button_exit[5.1,5.7;1,1;OK;" .. F(S("OK")) .. "]")
end
end
@ -372,7 +387,10 @@ minetest.register_chatcommand("mover_intro", {
end
})
local mover_upgrades = {["default:mese"] = basic_machines.properties.mover_upgrade_max, ["default:diamondblock"] = 99}
local mover_upgrades = {
["default:mese"] = {id = 1, max = basic_machines.properties.mover_upgrade_max},
["default:diamondblock"] = {id = 2, max = 99}
}
minetest.register_node("basic_machines:mover", {
description = S("Mover - universal digging/harvesting/teleporting/transporting machine, it's upgradeable"),
@ -395,9 +413,9 @@ minetest.register_node("basic_machines:mover", {
meta:set_float("fuel", 0)
meta:set_string("prefer", "")
meta:set_string("mode", "normal")
meta:set_int("upgrade", 1)
meta:set_int("upgradetype", 0); meta:set_int("upgrade", 1)
meta:set_int("seltab", 1) -- 0: undefined, 1: mode tab, 2: positions tab
meta:set_int("activation_count", 0); meta:set_int("t", 0)
meta:set_int("t", 0); meta:set_int("T", 0); meta:set_int("activation_count", 0)
basic_machines.find_and_connect_battery(pos) -- try to find battery early
if minetest.check_player_privs(name, "privs") then
@ -479,11 +497,13 @@ minetest.register_node("basic_machines:mover", {
basic_machines.get_mover_form(pos, name))
elseif listname == "upgrade" then
local stack_name = stack:get_name()
local mover_upgrade_max = mover_upgrades[stack_name]
if mover_upgrade_max then
local mover_upgrade = mover_upgrades[stack_name]
if mover_upgrade then
local inv_stack = meta:get_inventory():get_stack("upgrade", 1)
if inv_stack:is_empty() or stack_name == inv_stack:get_name() then
local inv_stack_is_empty = inv_stack:is_empty()
if inv_stack_is_empty or stack_name == inv_stack:get_name() then
local upgrade = inv_stack:get_count()
local mover_upgrade_max = mover_upgrade.max
if upgrade < mover_upgrade_max then
local stack_count = stack:get_count()
local new_upgrade = upgrade + stack_count
@ -491,6 +511,7 @@ minetest.register_node("basic_machines:mover", {
new_upgrade = mover_upgrade_max -- not more than max
stack_count = math.min(stack_count, mover_upgrade_max - upgrade)
end
if inv_stack_is_empty then meta:set_int("upgradetype", mover_upgrade.id) end
meta:set_int("upgrade", new_upgrade + 1)
return stack_count
end
@ -527,16 +548,17 @@ minetest.register_node("basic_machines:mover", {
return 0
elseif listname == "upgrade" then
if minetest.check_player_privs(name, "privs") then
meta:set_int("upgrade", -1) -- means operation will be for free
meta:set_int("upgrade", -1) -- means operations will be for free
else
local stack_name = stack:get_name()
local mover_upgrade_max = mover_upgrades[stack_name]
if mover_upgrade_max then
local mover_upgrade = mover_upgrades[stack_name]
if mover_upgrade then
local inv_stack = meta:get_inventory():get_stack("upgrade", 1)
if stack_name == inv_stack:get_name() then
local upgrade = inv_stack:get_count()
upgrade = upgrade - stack:get_count()
if upgrade < 0 or upgrade > mover_upgrade_max then upgrade = 0 end -- not less than 0 and not more than max
if upgrade < 0 or upgrade > mover_upgrade.max then upgrade = 0 end -- not less than 0 and not more than max
if upgrade == 0 then meta:set_int("upgradetype", 0) end
meta:set_int("upgrade", upgrade + 1)
end
end
@ -550,91 +572,144 @@ minetest.register_node("basic_machines:mover", {
action_on = function(pos, _)
local meta = minetest.get_meta(pos)
local x0, y0, z0 = meta:get_int("x0"), meta:get_int("y0"), meta:get_int("z0") -- source1
local x1, y1, z1 -- source2
local x2, y2, z2 = meta:get_int("x2"), meta:get_int("y2"), meta:get_int("z2") -- target
local fuel = meta:get_float("fuel")
-- TEMPERATURE
local t0, t1 = meta:get_int("t"), minetest.get_gametime()
local tn, T = t1 - machines_minstep, meta:get_int("T") -- temperature
if t0 <= tn and T < mover_max_temp then
T = 0
end
if t0 > tn then -- activated before natural time
T = T + 1
elseif T > mover_max_temp then
if t1 - t0 > machines_timer then -- reset temperature if more than 5s elapsed since last activation
T = 0; meta:set_string("infotext", "")
else
T = T - 1
end
end
meta:set_int("t", t1); meta:set_int("T", T)
if T > mover_max_temp then
minetest.sound_play("default_cool_lava", {pos = pos, max_hear_distance = 16, gain = 0.25}, true)
meta:set_string("infotext", S("Overheat! Temperature: @1", T))
return
end
local mode = meta:get_string("mode")
local object = mode == "object"
local mreverse = meta:get_int("reverse")
local transport
local owner = meta:get_string("owner")
local pos1 = {} -- where to take from
local pos2 = vector_add(pos, {x = x2, y = y2, z = z2}) -- where to put
local object = mode == "object" -- object mode
-- POSITIONS
local pos1 -- where to take from
local pos2 -- where to put
if object then
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})
x1, y1, z1 = meta:get_int("x1"), meta:get_int("y1"), meta:get_int("z1")
if mreverse == 1 then -- reverse pos1, pos2
pos1 = vector_add(pos, {x = meta:get_int("x2"), y = meta:get_int("y2"), z = meta:get_int("z2")})
pos2 = vector_add(pos, {x = meta:get_int("x0"), y = meta:get_int("y0"), z = meta:get_int("z0")})
else
pos1 = vector_add(pos, {x = meta:get_int("x0"), y = meta:get_int("y0"), z = meta:get_int("z0")}) -- source1
pos2 = vector_add(pos, {x = meta:get_int("x2"), y = meta:get_int("y2"), z = meta:get_int("z2")}) -- target
end
else
if meta:get_int("dim") < 1 then
meta:set_string("infotext", S("MOVER: Must reconfigure sources position.")); return
end
x1, y1, z1 = meta:get_int("x1") - x0 + 1, meta:get_int("y1") - y0 + 1, meta:get_int("z1") - z0 + 1 -- get dimensions
local x0, y0, z0 = meta:get_int("x0"), meta:get_int("y0"), meta:get_int("z0") -- source1
local x1, y1 = meta:get_int("x1") - x0 + 1, meta:get_int("y1") - y0 + 1 -- get dimensions
local pc = meta:get_int("pc"); pc = (pc + 1) % meta:get_int("dim"); meta:set_int("pc", pc) -- cycle position
-- pc = z * a * b + x * b + y, from x, y, z to pc
-- set current input position
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)
local yc = y0 + (pc % y1); pc = (pc - (pc % y1)) / y1
local xc = x0 + (pc % x1); pc = (pc - (pc % x1)) / x1
local zc = z0 + pc
pos1 = vector_add(pos, {x = xc, y = yc, z = zc})
local markerN = machines.markerN[owner]
if markerN and T < temp_15P then
local lua_entity = markerN:get_luaentity()
if lua_entity and vector.equals(pos, lua_entity._origin or {}) then
markerN:set_pos(pos1) -- mark current position
end
end
local x2, y2, z2 = meta:get_int("x2"), meta:get_int("y2"), meta:get_int("z2") -- target
transport = mode == "transport"
-- 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
else
pos2 = vector_add(pos, {x = x2, y = y2, z = z2})
end
if mreverse ~= 0 and mreverse ~= 2 then -- reverse pos1, pos2
local xt, yt, zt = pos1.x, pos1.y, pos1.z
pos1 = {x = pos2.x, y = pos2.y, z = pos2.z}
pos2 = {x = xt, y = yt, z = zt}
end
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
end
if mreverse ~= 0 and mreverse ~= 2 then -- reverse pos1, pos2
local post = {x = pos1.x, y = pos1.y, z = pos1.z}
pos1 = {x = pos2.x, y = pos2.y, z = pos2.z}
pos2 = {x = post.x, y = post.y, z = post.z}
end
local owner = meta:get_string("owner")
-- PROTECTION CHECK
local text = S("Mover block. Protection fail.")
if minetest.is_protected(pos1, owner) or minetest.is_protected(pos2, owner) then
meta:set_string("infotext", text); return
elseif meta:get_string("infotext") == text then
meta:set_string("infotext", "")
meta:set_string("infotext", S("Mover block. Protection fail.")); return
end
local node1 = minetest.get_node(pos1)
local node1_name = node1.name
local inventory = mode == "inventory"
local prefer = meta:get_string("prefer")
local node1, node1_name, source_chest, msg
local inventory = mode == "inventory" -- inventory mode
local source_chest = mover.chests[node1_name] or false
-- FUEL COST: calculate
-- FUEL
local upgrade = meta:get_int("upgrade")
local fuel_cost
local fuel = meta:get_float("fuel")
if upgrade == -1 then
fuel_cost = 0 -- free operation for admin
if not object then
node1 = minetest.get_node(pos1); node1_name = node1.name
if not inventory then
source_chest = mover.chests[node1_name] or false
end
end
fuel_cost = 0 -- free operations for admin
else
if inventory or source_chest and node1_name ~= "default:chest" then -- taking items from chests/inventory move
fuel_cost = mover.hardness[prefer] or 1
elseif object and meta:get_int("elevator") == 1 then -- check if elevator mode
-- FUEL COST: calculate
if object and meta:get_int("elevator") == 1 then -- check if elevator mode
local requirement = math.floor((abs(pos2.x - pos.x) + abs(pos2.y - pos.y) + abs(pos2.z - pos.z)) / 100) + 1
if upgrade - 1 < requirement and
meta:get_inventory():get_stack("upgrade", 1):get_name() ~= "default:diamondblock"
if (upgrade - 1) >= requirement and (meta:get_int("upgradetype") == 2 or
meta:get_inventory():get_stack("upgrade", 1):get_name() == "default:diamondblock") -- for compatibility
then
fuel_cost = 0
else
meta:set_string("infotext",
S("MOVER: Elevator error. Need at least @1 diamond block(s) in upgrade (1 for every 100 distance).",
requirement)); return
end
fuel_cost = 0
else
local hardness = mover.hardness[node1_name]
if hardness == 0 and object then hardness = 1 end -- no free teleport from machine blocks
fuel_cost = hardness or 1
node1 = minetest.get_node(pos1); node1_name = node1.name
if inventory then -- taking items from chests/inventory move
fuel_cost = mover.hardness[prefer] or 1
else
source_chest = mover.chests[node1_name] or false
if source_chest and node1_name ~= "default:chest" then
fuel_cost = mover.hardness[prefer] or 1
else
local hardness = mover.hardness[node1_name]
if hardness == 0 and object then hardness = 1 end -- no free teleport from machine blocks
fuel_cost = hardness or 1
end
end
end
if fuel_cost > 0 then
@ -646,53 +721,75 @@ minetest.register_node("basic_machines:mover", {
fuel_cost = fuel_cost * 0.1
end
if meta:get_inventory():get_stack("upgrade", 1):get_name() ~= "default:mese" then
upgrade = 1
if temp_80P then
if T > temp_80P then
fuel_cost = fuel_cost + (0.2 / mover_max_temp) * T * fuel_cost
elseif T < temp_15P then
fuel_cost = fuel_cost * 0.97
end
end
fuel_cost = fuel_cost / upgrade -- upgrade decreases fuel cost
end
end
-- FUEL OPERATIONS
if fuel < fuel_cost then -- needs fuel to operate, find nearby battery
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
elseif supply < 0 then -- no battery at target location, try to find it!
if not basic_machines.find_and_connect_battery(pos) then
meta:set_string("infotext", S("Can not find nearby battery to connect to!"))
minetest.sound_play("default_cool_lava", {pos = pos, gain = 1, max_hear_distance = 8}, true)
return
if meta:get_int("upgradetype") == 1 or
meta:get_inventory():get_stack("upgrade", 1):get_name() == "default:mese" -- for compatibility
then
fuel_cost = fuel_cost / upgrade -- upgrade decreases fuel cost
end
end
if found_fuel then
fuel = fuel + found_fuel; meta:set_float("fuel", fuel)
end
-- FUEL OPERATIONS
if fuel < fuel_cost then -- needs fuel to operate, find nearby battery
local power_draw = fuel_cost; local supply
if power_draw < 1 then power_draw = 1 end -- at least 10 one block operations with 1 refuel
if power_draw == 1 then
local bpos = {x = meta:get_int("batx"), y = meta:get_int("baty"), z = meta:get_int("batz")} -- battery pos
supply = basic_machines.check_power(bpos, power_draw * 3) -- try to store energy to reduce refuel
if supply <= 0 then
supply = basic_machines.check_power(bpos, power_draw)
end
else
supply = basic_machines.check_power(
{x = meta:get_int("batx"), y = meta:get_int("baty"), z = meta:get_int("batz")}, power_draw)
end
if fuel < fuel_cost then
meta:set_string("infotext", S("Mover block. Energy @1, needed energy @2. Put nonempty battery next to mover.",
fuel, fuel_cost)); return
else
meta:set_string("infotext", S("Mover block refueled. Fuel status @1.", fuel))
local found_fuel
if supply > 0 then
found_fuel = supply
elseif supply < 0 then -- no battery at target location, try to find it!
if not basic_machines.find_and_connect_battery(pos) then
meta:set_string("infotext", S("Can not find nearby battery to connect to!"))
minetest.sound_play("default_cool_lava", {pos = pos, gain = 1, max_hear_distance = 8}, true)
return
end
end
if found_fuel then
fuel = fuel + found_fuel; meta:set_float("fuel", fuel)
end
if fuel < fuel_cost then
meta:set_string("infotext", S("Mover block. Energy @1, needed energy @2. Put nonempty battery next to mover.",
fuel, fuel_cost)); return
else
msg = S("Mover block refueled. Fuel status @1.", twodigits_float(fuel))
end
end
end
local node2 = minetest.get_node(pos2).name
local target_chest = mover.chests[node2] or false
-- OBJECT MODE
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)
if meta:get_int("elevator") == 1 and radius == 0 then radius = 1 end -- for compatibility
local x1, y1, z1
if mreverse == 1 then
x1, y1, z1 = meta:get_int("x0"), meta:get_int("y0"), meta:get_int("z0") -- source1
else
x1, y1, z1 = meta:get_int("x1"), meta:get_int("y1"), meta:get_int("z1") -- source2
end
local radius = math.min(vector.distance(pos1, vector_add(pos, {x = x1, y = y1, z = z1})), max_range) -- distance source1-source2
local elevator = meta:get_int("elevator"); if elevator == 1 and radius == 0 then radius = 1 end -- for compatibility
local teleport_any = false
if target_chest then -- put objects in target chest
if mover.chests[minetest.get_node(pos2).name] and elevator == 0 then -- put objects in target chest
local inv = minetest.get_meta(pos2):get_inventory()
local mucca
@ -707,7 +804,6 @@ minetest.register_node("basic_machines:mover", {
local stack = ItemStack(lua_entity.itemstring)
if not stack:is_empty() and inv:room_for_item("main", stack) then
inv:add_item("main", stack); teleport_any = true
-- obj:set_pos({x = 0, y = 0, z = 0})
end
obj:remove()
end
@ -746,8 +842,6 @@ minetest.register_node("basic_machines:mover", {
end
end
-- minetest.chat_send_all("times " .. times .. " v " .. minetest.pos_to_string(velocityv))
-- move objects to another location
for _, obj in ipairs(minetest.get_objects_inside_radius(pos1, radius)) do
if obj:is_player() then
@ -771,7 +865,7 @@ minetest.register_node("basic_machines:mover", {
elseif name == "carts:cart" then -- just accelerate cart
obj:set_velocity(velocityv) -- move objects with set velocity in target direction
fuel = fuel - fuel_cost; meta:set_float("fuel", fuel)
meta:set_string("infotext", S("Mover block. Fuel status @1.", fuel))
meta:set_string("infotext", S("Mover block. Temperature: @1, Fuel: @2.", T, twodigits_float(fuel)))
return
else -- don't move objects like balls to destination after delay
minetest.after(times, function()
@ -788,34 +882,32 @@ minetest.register_node("basic_machines:mover", {
if teleport_any then
fuel = fuel - fuel_cost; meta:set_float("fuel", fuel)
meta:set_string("infotext", S("Mover block. Fuel status @1.", fuel))
meta:set_string("infotext", S("Mover block. Temperature: @1, Fuel: @2.", T, twodigits_float(fuel)))
minetest.sound_play("basic_machines_tng_transporter1", {pos = pos2, gain = 1, max_hear_distance = 8}, true)
elseif msg then
meta:set_string("infotext", msg)
end
return
end
if node1_name == "air" then return end -- nothing to move
if node1_name == "air" then if msg then meta:set_string("infotext", msg) end; return end -- nothing to move
-- decide what to do if target is chest: do nothing if target nonempty and not chest
if not target_chest and not inventory and node2 ~= "air" and not mover.bonemeal_table[prefer] or
target_chest and transport
then
return
end
if inventory then -- inventory mode
local invName1, invName2 = meta:get_string("inv1"), meta:get_string("inv2")
-- INVENTORY MODE
if inventory then
local invName1, invName2
if mreverse == 1 then -- reverse inventory names too
local invNamet = invName1; invName1 = invName2; invName2 = invNamet
invName1, invName2 = meta:get_string("inv2"), meta:get_string("inv1")
else
invName1, invName2 = meta:get_string("inv1"), meta:get_string("inv2")
end
-- forbidden nodes to take from in inventory mode - to prevent abuses:
local limit_inventory = mover.limit_inventory_table[node1_name]
if limit_inventory then
if limit_inventory == true or limit_inventory[invName1] then -- forbidden to take from this inventory
return
if msg then meta:set_string("infotext", msg) end; return
end
end
@ -825,13 +917,15 @@ minetest.register_node("basic_machines:mover", {
stack = ItemStack(prefer)
else -- just pick one item from chest to transfer
inv1 = minetest.get_meta(pos1):get_inventory()
if inv1:is_empty(invName1) then return end -- nothing to move
if inv1:is_empty(invName1) then -- nothing to move
if msg then meta:set_string("infotext", msg) end; return
end
local i, found = 1, false
while i <= inv1:get_size(invName1) do -- find item to move in inventory
stack = inv1:get_stack(invName1, i)
if stack:is_empty() then i = i + 1 else found = true; break end
end
if not found then return end
if not found then if msg then meta:set_string("infotext", msg) end; return end
end
-- can we move the items to target inventory ?
@ -842,73 +936,93 @@ minetest.register_node("basic_machines:mover", {
if inv1:contains_item(invName1, stack) then
inv2:add_item(invName2, stack)
inv1:remove_item(invName1, stack)
elseif upgrade == -1 and minetest.registered_items[stack:get_name()] then -- admin is owner.. just add stuff
inv2:add_item(invName2, stack)
else
if upgrade == -1 and minetest.registered_items[stack:get_name()] then -- admin is owner.. just add stuff
inv2:add_item(invName2, stack)
else
return -- item not found in chest
end
if msg then meta:set_string("infotext", msg) end; return -- item not found in chest
end
else
return
if msg then meta:set_string("infotext", msg) end; return
end
local count = meta:get_int("activation_count")
if count < 15 then
if count < 16 then
minetest.sound_play("basic_machines_chest_inventory_move", {pos = pos2, gain = 1, max_hear_distance = 8}, true)
end
local t0, t1 = meta:get_int("t"), minetest.get_gametime()
if t0 >= t1 - machines_minstep then
if t0 > tn then
meta:set_int("activation_count", count + 1)
elseif count > 1 and t0 < t1 - machines_minstep then
elseif count > 0 then
meta:set_int("activation_count", 0)
end
meta:set_int("t", t1)
fuel = fuel - fuel_cost; meta:set_float("fuel", fuel)
meta:set_string("infotext", S("Mover block. Fuel status @1.", fuel))
meta:set_string("infotext", S("Mover block. Temperature: @1, Fuel: @2.", T, twodigits_float(fuel)))
return
end
local bonemeal = false
local drop = mode == "drop" -- drops node instead of placing it
local dig = mode == "dig" -- digs at target location
-- filtering
if prefer ~= "" then -- prefered node set
if prefer ~= node1_name and not source_chest then return end -- only take prefered node
local inv_stack = meta:get_inventory():get_stack("filter", 1)
local inv_stack_count = inv_stack:get_count() > 0
if inv_stack_count and not source_chest then
local inv_palette_index = tonumber(inv_stack:get_meta():get("palette_index"))
if inv_palette_index then
local def = inv_stack:get_definition()
local palette_index = minetest.strip_param2_color(node1.param2, def and def.paramtype2)
if inv_palette_index ~= palette_index then return end
-- NORMAL, DIG, DROP, TRANSPORT MODES
if prefer ~= "" then -- filter check
if not source_chest then
if prefer ~= node1_name then -- only take preferred node
if msg then meta:set_string("infotext", msg) end; return
else
local inv_stack = meta:get_inventory():get_stack("filter", 1)
if inv_stack:get_count() > 0 then
local inv_palette_index = tonumber(inv_stack:get_meta():get("palette_index"))
if inv_palette_index then
local def = inv_stack:get_definition()
local palette_index = minetest.strip_param2_color(node1.param2, def and def.paramtype2)
if inv_palette_index ~= palette_index then
if msg then meta:set_string("infotext", msg) end; return
end
end
end
end
end
elseif source_chest then -- prefer == "", doesn't know what to take out of chest/inventory
if msg then meta:set_string("infotext", msg) end; return
end
local normal = mode == "normal"
local node2_name = minetest.get_node(pos2).name
local target_chest = mover.chests[node2_name] or false
local bonemeal = mover.bonemeal_table[prefer]
if drop or mreverse == 1 and mover.plants_table[prefer] or
(normal or dig or transport) and minetest.registered_nodes[prefer] or
normal and target_chest
then
-- do nothing if target non-empty and not chest and not bonemeal or transport mode and target chest
if not target_chest and node2_name ~= "air" and not bonemeal or transport and target_chest then
if msg then meta:set_string("infotext", msg) end; return
end
local drop, dig = mode == "drop", mode == "dig"
-- filtering
if prefer ~= "" then -- preferred node set
local normal = mode == "normal"; local def
if drop or normal and target_chest then
node1.name, node1_name = prefer, prefer
elseif mreverse == 1 and mover.plants_table[prefer] or
normal or dig or transport
then
def = minetest.registered_nodes[prefer]
if def then
node1.name, node1_name = prefer, prefer
else
minetest.chat_send_player(owner, S("MOVER: Filter defined with unknown node (@1) at @2,@3,@4.",
prefer, pos.x, pos.y, pos.z)); return
end
else
minetest.chat_send_player(owner, S("MOVER: Wrong filter (@1) at @2,@3,@4.",
prefer, pos.x, pos.y, pos.z)); return
end
if source_chest then -- take stuff from chest
if source_chest and not transport then -- take stuff from chest
local inv_stack = meta:get_inventory():get_stack("filter", 1)
local stack, match_meta = ItemStack(prefer), false
local inv = minetest.get_meta(pos1):get_inventory()
local stack = ItemStack(prefer)
local match_meta = false
if inv_stack_count then
if inv_stack:get_count() > 0 then
local palette_index = tonumber(inv_stack:get_meta():get("palette_index"))
if palette_index then
stack:get_meta():set_int("palette_index", palette_index)
@ -918,18 +1032,20 @@ minetest.register_node("basic_machines:mover", {
if inv:contains_item("main", stack, match_meta) then
if mreverse == 1 and not match_meta then
if mover.plants_table[prefer] then -- planting mode: check if transform seed -> plant is needed
prefer = mover.plants_table[prefer]
if prefer then
node1 = {name = prefer, param1 = nil,
param2 = minetest.registered_nodes[prefer].place_param2}
node1_name = prefer
else
return
if normal or dig then
if mover.plants_table[prefer] then -- planting mode: check if transform seed -> plant is needed
prefer = mover.plants_table[prefer]
if prefer then
node1 = {name = prefer, param1 = nil,
param2 = def.place_param2}
node1_name = prefer
else
if msg then meta:set_string("infotext", msg) end; return
end
elseif def and def.paramtype2 ~= "facedir" then
node1.param2 = nil
end
elseif (normal or dig) and minetest.registered_nodes[prefer].paramtype2 ~= "facedir" then
node1.param2 = nil
elseif drop and mover.bonemeal_table[prefer] then -- bonemeal check
elseif drop and bonemeal then -- bonemeal check
local on_use = (minetest.registered_items[prefer] or {}).on_use
if on_use then
vplayer[owner] = vplayer[owner] or create_virtual_player(owner)
@ -938,7 +1054,7 @@ minetest.register_node("basic_machines:mover", {
bonemeal = itemstack and itemstack:get_count() == 1 or
basic_machines.creative(owner)
else
return
if msg then meta:set_string("infotext", msg) end; return
end
end
elseif not match_meta then
@ -946,17 +1062,14 @@ minetest.register_node("basic_machines:mover", {
end
inv:remove_item("main", stack)
else
return
if msg then meta:set_string("infotext", msg) end; return
end
end
elseif source_chest then -- doesn't know what to take out of chest/inventory
return
end
local not_special = true -- mode for special items: trees, liquids using bucket, mese crystals
local not_special = true -- mode for special items: trees, liquids using bucket, mese crystals ore
-- if target chest put in chest
if target_chest then
if target_chest and not transport then -- if target chest put in chest
local inv = minetest.get_meta(pos2):get_inventory()
if dig then
if not source_chest then
@ -1029,7 +1142,7 @@ minetest.register_node("basic_machines:mover", {
inv:add_item("main", item)
minetest.set_node(pos1, {name = harvest_node1[1]})
else
return
if msg then meta:set_string("infotext", msg) end; return
end
end
end
@ -1076,44 +1189,41 @@ minetest.register_node("basic_machines:mover", {
end
local count = meta:get_int("activation_count")
if count < 15 then
if count < 16 then
minetest.sound_play("basic_machines_transporter", {pos = pos2, gain = 1, max_hear_distance = 8}, true)
end
local t0, t1 = meta:get_int("t"), minetest.get_gametime()
if t0 >= t1 - machines_minstep then
if t0 > tn then
meta:set_int("activation_count", count + 1)
elseif count > 1 and t0 < t1 - machines_minstep then
elseif count > 0 then
meta:set_int("activation_count", 0)
end
meta:set_int("t", t1)
if target_chest and source_chest then -- chest to chest transport has lower cost, * 0.1
fuel_cost = fuel_cost * 0.1
end
fuel = fuel - fuel_cost; meta:set_float("fuel", fuel)
meta:set_string("infotext", S("Mover block. Fuel status @1.", fuel))
meta:set_string("infotext", S("Mover block. Temperature: @1, Fuel: @2.", T, twodigits_float(fuel)))
if transport then -- transport nodes parallel as defined by source1 and target, clone with complete metadata
local meta1 = minetest.get_meta(pos1):to_table()
minetest.set_node(pos2, node1); minetest.get_meta(pos2):from_table(meta1)
minetest.set_node(pos1, {name = "air"}); minetest.get_meta(pos1):from_table(nil)
return
end
-- REMOVE NODE DUG
if not target_chest and not bonemeal then
if drop then -- drops node instead of placing it
minetest.add_item(pos2, item_to_stack(node1)) -- drops it
else
minetest.set_node(pos2, node1)
else
-- REMOVE NODE DUG
if not target_chest and not bonemeal then
if drop then -- drops node instead of placing it
minetest.add_item(pos2, item_to_stack(node1)) -- drops it
else
minetest.set_node(pos2, node1)
end
end
end
if not source_chest and not_special then
minetest.set_node(pos1, {name = "air"})
if dig then check_for_falling(pos1) end -- pre 5.0.0 nodeupdate(pos1)
if not source_chest and not_special then
minetest.set_node(pos1, {name = "air"})
if dig then check_for_falling(pos1) end -- pre 5.0.0 nodeupdate(pos1)
end
end
end,

View File

@ -6,6 +6,7 @@
local F, S = basic_machines.F, basic_machines.S
local machines_minstep = basic_machines.properties.machines_minstep
local twodigits_float = basic_machines.twodigits_float
local no_recycle_list = { -- prevent unrealistic recycling
["default:bronze_ingot"] = 1, ["default:gold_ingot"] = 1,
["default:copper_ingot"] = 1, ["default:steel_ingot"] = 1,
@ -37,49 +38,46 @@ end
local function recycler_process(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory(); local msg
-- FUEL CHECK
local fuel = meta:get_float("fuel"); local fuel_req
local fuel_req; local fuel = meta:get_float("fuel")
if meta:get_int("admin") == 1 then
fuel_req = 0
else
fuel_req = 1
end
local inv = meta:get_inventory()
local msg
if fuel < fuel_req then -- we need new fuel
local fuellist = inv:get_list("fuel"); if not fuellist then return end
local fueladd, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
if fuel < fuel_req then -- we need new fuel
local fuellist = inv:get_list("fuel"); if not fuellist then return end
local fueladd, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
if fueladd.time == 0 then -- no fuel inserted, try look for outlet
local supply = basic_machines.check_power({x = pos.x, y = pos.y - 1, z = pos.z}, fuel_req)
if supply > 0 then
fueladd.time = 40 * supply -- same as 10 coal
if fueladd.time == 0 then -- no fuel inserted, try look for outlet
local supply = basic_machines.check_power({x = pos.x, y = pos.y - 1, z = pos.z}, fuel_req)
if supply > 0 then
fueladd.time = 40 * supply -- same as 10 coal
else
meta:set_string("infotext", S("Please insert fuel")); return
end
else
meta:set_string("infotext", S("Please insert fuel")); return
inv:set_stack("fuel", 1, afterfuel.items[1])
fueladd.time = fueladd.time * 0.1 -- thats 4 for coal
end
else
inv:set_stack("fuel", 1, afterfuel.items[1])
fueladd.time = fueladd.time * 0.1 -- thats 4 for coal
end
if fueladd.time > 0 then
fuel = fuel + fueladd.time; meta:set_float("fuel", fuel)
-- meta:set_string("infotext", S("Added fuel furnace burn time @1, fuel status @2", fueladd.time, fuel))
msg = S("Added fuel furnace burn time @1, fuel status @2", fueladd.time, fuel)
end
if fueladd.time > 0 then
fuel = fuel + fueladd.time; meta:set_float("fuel", fuel)
msg = S("Added fuel furnace burn time @1, fuel status @2", fueladd.time, twodigits_float(fuel))
end
if fuel < fuel_req then return end
if fuel < fuel_req then return end
end
end
-- RECYCLING: check out inserted items
local stack = inv:get_stack("src", 1)
if stack:is_empty() then if msg then meta:set_string("infotext", msg) end; return end -- nothing to do
local src_item = stack:get_name() -- stack:to_string()
local src_item = stack:get_name()
-- take first word to determine what item was
-- local p = src_item:find(" "); if p then src_item = src_item:sub(1, p - 1) end
local itemlist; local reqcount = 1; local description -- needed count of materials for recycle to work
if src_item == meta:get_string("node") then -- did we already handle this ? if yes read from cache
@ -146,23 +144,23 @@ local function recycler_process(pos)
stack = stack:take_item(reqcount); inv:remove_item("src", stack)
local count = meta:get_int("activation_count")
if count < 15 then
if count < 16 then
minetest.sound_play("basic_machines_recycler", {pos = pos, gain = 0.5, max_hear_distance = 16}, true)
end
local t0, t1 = meta:get_int("t"), minetest.get_gametime()
if t0 >= t1 - machines_minstep then
if t0 > t1 - machines_minstep then
meta:set_int("activation_count", count + 1)
elseif count > 1 and t0 < t1 - machines_minstep then
elseif count > 0 then
meta:set_int("activation_count", 0)
end
meta:set_int("t", t1)
fuel = fuel - fuel_req; meta:set_float("fuel", fuel) -- burn fuel on successful operation
if inv:is_empty("src") then
meta:set_string("infotext", S("Fuel status @1", fuel))
meta:set_string("infotext", S("Fuel status @1", twodigits_float(fuel)))
else
meta:set_string("infotext", S("Fuel status @1, recycling '@2' (@3)", fuel, description, src_item))
meta:set_string("infotext", S("Fuel status @1, recycling '@2' (@3)", twodigits_float(fuel), description, src_item))
end
end
@ -185,7 +183,7 @@ minetest.register_node("basic_machines:recycler", {
meta:set_int("recipe", 1)
meta:set_float("fuel", 0)
meta:set_int("activation_count", 0); meta:set_int("t", 0)
meta:set_int("t", 0); meta:set_int("activation_count", 0)
local inv = meta:get_inventory()
inv:set_size("src", 1)
@ -204,7 +202,9 @@ minetest.register_node("basic_machines:recycler", {
end,
on_receive_fields = function(pos, formname, fields, sender)
if fields.OK and not minetest.is_protected(pos, sender:get_player_name()) then
if fields.OK then
if minetest.is_protected(pos, sender:get_player_name()) then return end
local meta = minetest.get_meta(pos)
if fields.recipe ~= meta:get_string("recipe") then
@ -239,7 +239,7 @@ minetest.register_node("basic_machines:recycler", {
if listname == "src" then
local meta = minetest.get_meta(pos)
if meta:get_inventory():is_empty("src") then
meta:set_string("infotext", S("Fuel status @1", meta:get_float("fuel")))
meta:set_string("infotext", S("Fuel status @1", twodigits_float(meta:get_float("fuel"))))
end
end
end,

View File

@ -74,14 +74,14 @@ local function battery_recharge(pos)
meta:set_string("infotext", S("(R) Energy: @1 / @2", math.ceil(energy * 10) / 10, capacity))
local count = meta:get_int("activation_count")
if count < 15 then
if count < 16 then
minetest.sound_play("basic_machines_electric_zap", {pos = pos, gain = 0.05, max_hear_distance = 8}, true)
end
local t0, t1 = meta:get_int("t"), minetest.get_gametime()
if t0 >= t1 - machines_minstep then
if t0 > t1 - machines_minstep then
meta:set_int("activation_count", count + 1)
elseif count > 1 and t0 < t1 - machines_minstep then
elseif count > 0 then
meta:set_int("activation_count", 0)
end
meta:set_int("t", t1)
@ -109,7 +109,7 @@ basic_machines.check_power = function(pos, power_draw)
if power_draw > maxpower then
meta:set_string("infotext", S("Power draw required: @1, maximum power output @2. Please upgrade battery.",
power_draw, maxpower)); return 0
basic_machines.twodigits_float(power_draw), maxpower)); return 0
elseif power_draw > energy then
not_R = false; energy = battery_recharge(pos) -- try recharge battery and continue operation immediately
end
@ -185,7 +185,7 @@ minetest.register_node("basic_machines:battery_0", {
meta:set_float("maxpower", 1)
meta:set_float("energy", 0)
meta:set_int("upgrade", 0) -- upgrade level determines max energy output
meta:set_int("activation_count", 0); meta:set_int("t", 0)
meta:set_int("t", 0); meta:set_int("activation_count", 0)
local inv = meta:get_inventory()
inv:set_size("fuel", 1) -- place to put crystals
@ -334,9 +334,7 @@ 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
local upgrade = basic_machines.twodigits_float(meta:get_float("upgrade"))
meta:set_string("formspec", ([[
size[8,6.5]

BIN
textures/machines_pos.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 B