mirror of
https://github.com/minetest-mods/technic.git
synced 2024-11-11 13:00:29 +01:00
Handle CONTENT_IGNORE when checking windmill conditions.
Windmills always span more than one mapblock, so even with a switching station next to the generators, they will stop working if unloaded due to the windmill check failing to handle CONTENT_IGNORE of the frames at the foot of the windmill, unless a second switching station would be placed there. The commit assumes, that a user has to load a block to modify it, and thus unloaded blocks to have the same windmill frame state as before. This also makes technic_run for windmills a little faster by being able to skip some unnecessary node lookups and generally avoiding creation of 20 tables per windmill per step.
This commit is contained in:
parent
1475ee6e40
commit
d39797aad8
|
@ -33,8 +33,15 @@ local function check_wind_mill(pos)
|
||||||
if pos.y < 30 then
|
if pos.y < 30 then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
pos = {x=pos.x, y=pos.y, z=pos.z}
|
||||||
for i = 1, 20 do
|
for i = 1, 20 do
|
||||||
local node = minetest.get_node({x=pos.x, y=pos.y-i, z=pos.z})
|
pos.y = pos.y - 1
|
||||||
|
local node = minetest.get_node_or_nil(pos)
|
||||||
|
if not node then
|
||||||
|
-- we reached CONTENT_IGNORE, we can assume, that nothing changed
|
||||||
|
-- as the user will have to load the block to change it
|
||||||
|
return
|
||||||
|
end
|
||||||
if node.name ~= "technic:wind_mill_frame" then
|
if node.name ~= "technic:wind_mill_frame" then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@ -45,17 +52,17 @@ end
|
||||||
local run = function(pos, node)
|
local run = function(pos, node)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local machine_name = S("Wind %s Generator"):format("MV")
|
local machine_name = S("Wind %s Generator"):format("MV")
|
||||||
local power = math.min(pos.y * 100, 5000)
|
|
||||||
|
|
||||||
if not check_wind_mill(pos) then
|
local check = check_wind_mill(pos)
|
||||||
|
if check == false then
|
||||||
meta:set_int("MV_EU_supply", 0)
|
meta:set_int("MV_EU_supply", 0)
|
||||||
meta:set_string("infotext", S("%s Improperly Placed"):format(machine_name))
|
meta:set_string("infotext", S("%s Improperly Placed"):format(machine_name))
|
||||||
return
|
elseif check == true then
|
||||||
else
|
local power = math.min(pos.y * 100, 5000)
|
||||||
meta:set_int("MV_EU_supply", power)
|
meta:set_int("MV_EU_supply", power)
|
||||||
end
|
|
||||||
|
|
||||||
meta:set_string("infotext", S("@1 (@2 EU)", machine_name, technic.pretty_num(power)))
|
meta:set_string("infotext", S("@1 (@2 EU)", machine_name, technic.pretty_num(power)))
|
||||||
|
end
|
||||||
|
-- check == nil: assume nothing has changed
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node("technic:wind_mill", {
|
minetest.register_node("technic:wind_mill", {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user