2019-03-19 00:40:17 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
|
|
|
Copyright (C) 2019 Joachim Stolberg
|
|
|
|
|
2019-08-22 21:49:47 +03:00
|
|
|
GPL v3
|
2019-03-19 00:40:17 +03:00
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
Coalburner as heater for the Meltingpot
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
2019-07-02 22:33:12 +03:00
|
|
|
local S = techage.S
|
2019-03-19 00:40:17 +03:00
|
|
|
|
2019-05-04 14:16:16 +03:00
|
|
|
local COAL_BURN_TIME = 1200
|
2019-05-03 23:30:06 +03:00
|
|
|
local CYCLE_TIME = 5
|
|
|
|
|
2019-09-14 20:49:33 +03:00
|
|
|
local function get_node_lvm(pos)
|
|
|
|
local node = minetest.get_node_or_nil(pos)
|
|
|
|
if node then
|
|
|
|
return node
|
|
|
|
end
|
|
|
|
local vm = minetest.get_voxel_manip()
|
|
|
|
local MinEdge, MaxEdge = vm:read_from_map(pos, pos)
|
|
|
|
local data = vm:get_data()
|
|
|
|
local param2_data = vm:get_param2_data()
|
|
|
|
local area = VoxelArea:new({MinEdge = MinEdge, MaxEdge = MaxEdge})
|
|
|
|
local idx = area:indexp(pos)
|
|
|
|
node = {
|
|
|
|
name = minetest.get_name_from_content_id(data[idx]),
|
|
|
|
param2 = param2_data[idx]
|
|
|
|
}
|
|
|
|
return node
|
|
|
|
end
|
2019-05-03 23:30:06 +03:00
|
|
|
|
2019-03-19 00:40:17 +03:00
|
|
|
local function num_coal(pos)
|
|
|
|
local pos1 = {x=pos.x, y=pos.y+1, z=pos.z}
|
|
|
|
local pos2 = {x=pos.x, y=pos.y+32, z=pos.z}
|
|
|
|
local nodes = minetest.find_nodes_in_area(pos1, pos2, {"techage:charcoal", "techage:charcoal_burn"})
|
|
|
|
return #nodes
|
|
|
|
end
|
|
|
|
|
|
|
|
local function num_cobble(pos, height)
|
|
|
|
local pos1 = {x=pos.x-1, y=pos.y+1, z=pos.z-1}
|
|
|
|
local pos2 = {x=pos.x+1, y=pos.y+height, z=pos.z+1}
|
|
|
|
local nodes = minetest.find_nodes_in_area(pos1, pos2, {"default:cobble", "default:desert_cobble"})
|
|
|
|
return #nodes
|
|
|
|
end
|
|
|
|
|
2019-05-03 23:30:06 +03:00
|
|
|
local function num_air(pos)
|
|
|
|
local pos1 = {x=pos.x-1, y=pos.y, z=pos.z-1}
|
|
|
|
local pos2 = {x=pos.x+1, y=pos.y, z=pos.z+1}
|
|
|
|
local nodes = minetest.find_nodes_in_area(pos1, pos2, {"air"})
|
|
|
|
return #nodes
|
|
|
|
end
|
|
|
|
|
2019-03-19 00:40:17 +03:00
|
|
|
local function start_burner(pos, height)
|
|
|
|
local pos1 = {x=pos.x-1, y=pos.y+1, z=pos.z-1}
|
|
|
|
local pos2 = {x=pos.x+1, y=pos.y+height, z=pos.z+1}
|
2019-05-03 23:30:06 +03:00
|
|
|
for _,p in ipairs(minetest.find_nodes_in_area(pos1, pos2, "techage:charcoal")) do
|
2019-05-04 14:16:16 +03:00
|
|
|
minetest.swap_node(p, {name = "techage:charcoal_burn"})
|
2019-05-03 23:30:06 +03:00
|
|
|
end
|
2019-03-19 00:40:17 +03:00
|
|
|
end
|
|
|
|
|
2019-05-04 23:31:53 +03:00
|
|
|
local function remove_coal(pos, height)
|
|
|
|
local pos1 = {x=pos.x-1, y=pos.y+1, z=pos.z-1}
|
|
|
|
local pos2 = {x=pos.x+1, y=pos.y+height, z=pos.z+1}
|
|
|
|
for _,p in ipairs(minetest.find_nodes_in_area(pos1, pos2, "techage:charcoal_burn")) do
|
|
|
|
minetest.remove_node(p)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-19 00:40:17 +03:00
|
|
|
local function remove_flame(pos, height)
|
|
|
|
local idx
|
|
|
|
pos = {x=pos.x, y=pos.y+height, z=pos.z}
|
|
|
|
for idx=height,1,-1 do
|
|
|
|
pos = {x=pos.x, y=pos.y+1, z=pos.z}
|
2019-09-14 20:49:33 +03:00
|
|
|
local node = get_node_lvm(pos)
|
2019-03-19 00:40:17 +03:00
|
|
|
if string.find(node.name, "techage:flame") then
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
elseif node.name == "techage:meltingpot" then
|
|
|
|
techage.update_heat(pos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-11 02:21:03 +03:00
|
|
|
local function calc_num_coal(height, burn_time)
|
|
|
|
local num = height
|
|
|
|
if burn_time < 0 then
|
|
|
|
local x = (COAL_BURN_TIME * 0.2) / height
|
|
|
|
num = math.max(height + math.floor(burn_time/x), 0)
|
2019-05-03 23:30:06 +03:00
|
|
|
end
|
|
|
|
return num
|
|
|
|
end
|
|
|
|
|
2019-03-19 00:40:17 +03:00
|
|
|
local function flame(pos, height, heat, first_time)
|
|
|
|
local idx
|
|
|
|
pos = {x=pos.x, y=pos.y+height, z=pos.z}
|
|
|
|
for idx=heat,1,-1 do
|
|
|
|
pos = {x=pos.x, y=pos.y+1, z=pos.z}
|
|
|
|
idx = math.min(idx, 12)
|
2019-09-14 20:49:33 +03:00
|
|
|
local node = get_node_lvm(pos)
|
2019-08-16 12:13:30 +03:00
|
|
|
if node.name == "techage:meltingpot_active" or node.name == "ignore" then
|
2019-03-19 00:40:17 +03:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if node.name == "techage:meltingpot" then
|
|
|
|
if first_time then
|
|
|
|
techage.switch_to_active(pos)
|
|
|
|
else
|
|
|
|
techage.update_heat(pos)
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
minetest.add_node(pos, {name = "techage:flame"..math.min(idx,7)})
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_int("heat", idx)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-05-03 23:30:06 +03:00
|
|
|
local lRatio = {120, 110, 95, 75, 55, 28, 0}
|
|
|
|
local lColor = {"000080", "400040", "800000", "800000", "800000", "800000", "800000"}
|
|
|
|
|
2019-03-19 00:40:17 +03:00
|
|
|
for idx,ratio in ipairs(lRatio) do
|
|
|
|
local color = "techage_flame_animated.png^[colorize:#"..lColor[idx].."B0:"..ratio
|
|
|
|
minetest.register_node("techage:flame"..idx, {
|
|
|
|
tiles = {
|
|
|
|
{
|
|
|
|
name = color,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 16,
|
|
|
|
aspect_h = 16,
|
|
|
|
length = 1
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
after_destruct = function(pos, oldnode)
|
|
|
|
pos.y = pos.y + 1
|
2019-09-14 20:49:33 +03:00
|
|
|
local node = get_node_lvm(pos)
|
2019-03-19 00:40:17 +03:00
|
|
|
if minetest.get_item_group(node.name, "techage_flame") > 0 then
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
2019-08-16 12:13:30 +03:00
|
|
|
drawtype = "glasslike",
|
2019-03-19 00:40:17 +03:00
|
|
|
use_texture_alpha = true,
|
|
|
|
inventory_image = "techage_flame.png",
|
|
|
|
paramtype = "light",
|
|
|
|
light_source = 13,
|
|
|
|
walkable = false,
|
|
|
|
buildable_to = true,
|
|
|
|
floodable = true,
|
|
|
|
sunlight_propagates = true,
|
|
|
|
damage_per_second = 4 + idx,
|
|
|
|
groups = {igniter = 2, dig_immediate = 3, techage_flame=1, not_in_creative_inventory=1},
|
|
|
|
drop = "",
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("techage:ash", {
|
|
|
|
description = S("Ash"),
|
|
|
|
tiles = {"techage_ash.png"},
|
|
|
|
drawtype = "nodebox",
|
2019-11-10 23:08:37 +03:00
|
|
|
paramtype = "light",
|
2019-03-19 00:40:17 +03:00
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{-4/8, -4/8, -4/8, 4/8, -3/8, 4/8},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
is_ground_content = false,
|
|
|
|
groups = {crumbly = 3, not_in_creative_inventory=1},
|
|
|
|
drop = "",
|
|
|
|
sounds = default.node_sound_defaults(),
|
|
|
|
})
|
|
|
|
|
|
|
|
function techage.start_burner(pos, playername)
|
|
|
|
local height = num_coal(pos)
|
|
|
|
if minetest.is_protected(
|
|
|
|
{x=pos.x, y=pos.y+height, z=pos.z},
|
|
|
|
playername) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if num_cobble(pos, height) == height * 8 then
|
|
|
|
local meta = minetest.get_meta(pos)
|
2019-05-11 02:21:03 +03:00
|
|
|
--meta:set_int("ignite", minetest.get_gametime())
|
|
|
|
meta:set_int("burn_time", COAL_BURN_TIME)
|
2019-03-19 00:40:17 +03:00
|
|
|
meta:set_int("height", height)
|
|
|
|
start_burner(pos, height)
|
|
|
|
flame(pos, height, height, true)
|
2019-04-27 18:42:27 +03:00
|
|
|
local handle = minetest.sound_play("techage_gasflare", {
|
2019-03-19 00:40:17 +03:00
|
|
|
pos = {x=pos.x, y=pos.y+height, z=pos.z},
|
|
|
|
max_hear_distance = 20,
|
2019-04-27 18:42:27 +03:00
|
|
|
gain = height/12.0,
|
2019-03-19 00:40:17 +03:00
|
|
|
loop = true})
|
|
|
|
meta:set_int("handle", handle)
|
2019-05-03 23:30:06 +03:00
|
|
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
2019-03-19 00:40:17 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function techage.keep_running_burner(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local height = meta:get_int("height")
|
|
|
|
remove_flame(pos, height)
|
|
|
|
local handle = meta:get_int("handle")
|
|
|
|
if handle then
|
|
|
|
minetest.sound_stop(handle)
|
|
|
|
meta:set_int("handle", 0)
|
|
|
|
end
|
2019-05-11 02:21:03 +03:00
|
|
|
local burn_time = meta:get_int("burn_time")
|
|
|
|
-- burner hole is open
|
|
|
|
if num_air(pos) == 1 then
|
|
|
|
meta:set_int("burn_time", burn_time - CYCLE_TIME)
|
|
|
|
-- tower intact
|
|
|
|
if num_cobble(pos, height) == height * 8 then
|
|
|
|
local num_coal = calc_num_coal(height, burn_time)
|
|
|
|
if num_coal > 0 then
|
|
|
|
if meta:get_int("paused") == 1 then
|
|
|
|
flame(pos, height, num_coal, true)
|
|
|
|
meta:set_int("paused", 0)
|
|
|
|
else
|
|
|
|
flame(pos, height, num_coal, false)
|
|
|
|
end
|
|
|
|
handle = minetest.sound_play("techage_gasflare", {
|
|
|
|
pos = {x=pos.x, y=pos.y+height, z=pos.z},
|
|
|
|
max_hear_distance = 32,
|
|
|
|
gain = num_coal/12.0,
|
|
|
|
loop = true})
|
|
|
|
meta:set_int("handle", handle)
|
2019-05-04 23:31:53 +03:00
|
|
|
else
|
2019-05-11 02:21:03 +03:00
|
|
|
minetest.swap_node(pos, {name="techage:ash"})
|
|
|
|
remove_coal(pos, height)
|
|
|
|
return false
|
2019-05-04 23:31:53 +03:00
|
|
|
end
|
2019-03-19 00:40:17 +03:00
|
|
|
else
|
|
|
|
minetest.swap_node(pos, {name="techage:ash"})
|
2019-05-04 23:31:53 +03:00
|
|
|
remove_coal(pos, height)
|
2019-03-19 00:40:17 +03:00
|
|
|
return false
|
|
|
|
end
|
2019-05-11 02:21:03 +03:00
|
|
|
else
|
|
|
|
meta:set_int("paused", 1)
|
2019-03-19 00:40:17 +03:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function techage.stop_burner(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local height = meta:get_int("height")
|
|
|
|
remove_flame(pos, height)
|
2019-05-04 23:31:53 +03:00
|
|
|
remove_coal(pos, height)
|
2019-03-19 00:40:17 +03:00
|
|
|
local handle = meta:get_int("handle")
|
|
|
|
minetest.sound_stop(handle)
|
2019-05-11 02:21:03 +03:00
|
|
|
meta:set_int("burn_time", 0)
|
2019-03-19 00:40:17 +03:00
|
|
|
end
|
2019-05-01 00:58:42 +03:00
|
|
|
|
|
|
|
|