lamps, oil and oil explorer added

This commit is contained in:
Joachim Stolberg 2019-05-26 23:22:29 +02:00
parent fbe7508a0a
commit d342a3d669
33 changed files with 678 additions and 124 deletions

View File

@ -158,7 +158,6 @@ local function washing(pos, crd, mem, inv)
end end
local function keep_running(pos, elapsed) local function keep_running(pos, elapsed)
print("keep_running")
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
local crd = CRD(pos) local crd = CRD(pos)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()

View File

@ -125,7 +125,6 @@ local function swap_node(pos, name)
if node.name == name then if node.name == name then
return return
end end
print("swap_node", name)
node.name = name node.name = name
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
end end

View File

@ -66,7 +66,6 @@ local State = techage.NodeStates:new({
-- Pass1: Power balance calculation -- Pass1: Power balance calculation
local function on_power_pass1(pos, mem) local function on_power_pass1(pos, mem)
print("on_power_pass1", mem.charging)
if State:is_active(mem) and mem.capa > POWER_HYSTERESIS then if State:is_active(mem) and mem.capa > POWER_HYSTERESIS then
mem.correction = POWER_CONSUMPTION -- uncharging mem.correction = POWER_CONSUMPTION -- uncharging
else else
@ -77,7 +76,6 @@ end
-- Pass2: Power balance adjustment -- Pass2: Power balance adjustment
local function on_power_pass2(pos, mem, sum) local function on_power_pass2(pos, mem, sum)
print("on_power_pass2", mem.charging, sum)
if State:is_active(mem) then if State:is_active(mem) then
if sum > mem.correction + POWER_CONSUMPTION and if sum > mem.correction + POWER_CONSUMPTION and
mem.capa < POWER_MAX_LOAD - POWER_HYSTERESIS then mem.capa < POWER_MAX_LOAD - POWER_HYSTERESIS then
@ -100,14 +98,12 @@ end
-- Pass3: Power balance result -- Pass3: Power balance result
local function on_power_pass3(pos, mem, sum) local function on_power_pass3(pos, mem, sum)
print("on_power_pass3", mem.charging, sum)
mem.power_result = sum mem.power_result = sum
end end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
print("node_timer", mem.charging, mem.capa)
if State:is_active(mem) then if State:is_active(mem) then
mem.capa = mem.capa or 0 mem.capa = mem.capa or 0
if mem.charging == true then if mem.charging == true then

View File

@ -110,6 +110,12 @@ else
dofile(MP.."/lamps/lib.lua") dofile(MP.."/lamps/lib.lua")
dofile(MP.."/lamps/simplelamp.lua") dofile(MP.."/lamps/simplelamp.lua")
dofile(MP.."/lamps/streetlamp.lua") dofile(MP.."/lamps/streetlamp.lua")
dofile(MP.."/lamps/ceilinglamp.lua")
dofile(MP.."/lamps/industriallamp1.lua")
dofile(MP.."/lamps/industriallamp2.lua")
-- Oil
dofile(MP.."/oil/explore.lua")
--dofile(MP.."/test/generator.lua") --dofile(MP.."/test/generator.lua")

View File

@ -187,6 +187,7 @@ function techage.start_burner(pos, playername)
end end
function techage.keep_running_burner(pos) function techage.keep_running_burner(pos)
print("keep_running_burner")
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local height = meta:get_int("height") local height = meta:get_int("height")
remove_flame(pos, height) remove_flame(pos, height)

View File

@ -209,11 +209,22 @@ local function get_heat(pos)
pos.y = pos.y - 1 pos.y = pos.y - 1
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
pos.y = pos.y + 1 print("get_heat1", minetest.get_item_group(node.name, "techage_flame"))
if minetest.get_item_group(node.name, "techage_flame") > 0 then if minetest.get_item_group(node.name, "techage_flame") == 0 then
heat = meta:get_int("heat") pos.y = pos.y + 1
return 0
end end
return heat
pos.y = pos.y - 1
node = minetest.get_node(pos)
pos.y = pos.y + 2
print("get_heat2", node.name, minetest.get_item_group(node.name, "techage_flame"))
if minetest.get_item_group(node.name, "techage_flame") == 0 and
node.name ~= "techage:charcoal_burn" then
return 0
end
return meta:get_int("heat")
end end
-- Start melting if heat is ok AND source items available -- Start melting if heat is ok AND source items available

68
lamps/ceilinglamp.lua Normal file
View File

@ -0,0 +1,68 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
LGPLv2.1+
See LICENSE.txt for more information
TA3/TA4 Ceiling Lamp
]]--
-- Load support for intllib.
local MP = minetest.get_modpath("techage")
local I,_ = dofile(MP.."/intllib.lua")
techage.register_lamp("techage:ceilinglamp", {
description = "TA Ceiling Lamp",
tiles = {
-- up, down, right, left, back, front
'techage_ceilinglamp_top.png',
'techage_ceilinglamp_bottom.png',
'techage_ceilinglamp.png',
'techage_ceilinglamp.png',
'techage_ceilinglamp.png',
'techage_ceilinglamp.png',
'techage_ceilinglamp.png',
'techage_ceilinglamp.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-5/16, -7/16, -5/16, 5/16, -5/16, 5/16},
{-4/16, -8/16, -4/16, 4/16, -7/16, 4/16},
},
},
},{
description = "TA Ceiling Lamp",
tiles = {
-- up, down, right, left, back, front
'techage_ceilinglamp_top.png',
'techage_ceilinglamp_bottom.png',
'techage_ceilinglamp.png',
'techage_ceilinglamp.png',
'techage_ceilinglamp.png',
'techage_ceilinglamp.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-5/16, -7/16, -5/16, 5/16, -5/16, 5/16},
{-4/16, -8/16, -4/16, 4/16, -7/16, 4/16},
},
},
})
minetest.register_craft({
type = "shapeless",
output = "techage:ceilinglamp_off 3",
recipe = {"techage:simplelamp_off", "default:wood", "default:glass"},
})

68
lamps/industriallamp1.lua Normal file
View File

@ -0,0 +1,68 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
LGPLv2.1+
See LICENSE.txt for more information
TA3/TA4 Industrial Lamp 1
]]--
-- Load support for intllib.
local MP = minetest.get_modpath("techage")
local I,_ = dofile(MP.."/intllib.lua")
techage.register_lamp("techage:industriallamp1", {
description = "TA Industrial Lamp 1",
inventory_image = 'techage_industriallamp_inv1.png',
tiles = {
-- up, down, right, left, back, front
'techage_industriallamp1.png',
'techage_industriallamp1.png',
'techage_industriallamp1.png^[transformR180',
'techage_industriallamp1.png^[transformR180',
'techage_industriallamp1.png',
'techage_industriallamp1.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-8/16, -8/16, -3/32, -6/16, -9/32, 3/32},
{ 6/16, -8/16, -3/32, 8/16, -9/32, 3/32},
{-6/16, -7/16, -1/16, 6/16, -5/16, 1/16},
},
},
},{
tiles = {
-- up, down, right, left, back, front
'techage_industriallamp1_on.png',
'techage_industriallamp1_on.png',
'techage_industriallamp1_on.png^[transformR180',
'techage_industriallamp1_on.png^[transformR180',
'techage_industriallamp1_on.png',
'techage_industriallamp1_on.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-8/16, -8/16, -3/32, -6/16, -9/32, 3/32},
{ 6/16, -8/16, -3/32, 8/16, -9/32, 3/32},
{-6/16, -7/16, -1/16, 6/16, -5/16, 1/16},
},
},
})
minetest.register_craft({
output = "techage:industriallamp1_off 2",
recipe = {
{"", "", ""},
{"default:glass", "techage:simplelamp_off", "dye:grey"},
{"basic_materials:plastic_strip", "default:copper_ingot", "basic_materials:plastic_strip"},
},
})

70
lamps/industriallamp2.lua Normal file
View File

@ -0,0 +1,70 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
LGPLv2.1+
See LICENSE.txt for more information
TA3/TA4 Industrial Lamp 2
]]--
-- Load support for intllib.
local MP = minetest.get_modpath("techage")
local I,_ = dofile(MP.."/intllib.lua")
local size = {x = 8/32, y = 8/32, z = 5/32}
techage.register_lamp("techage:industriallamp2", {
description = "TA Industrial Lamp 2",
inventory_image = 'techage_industriallamp_inv2.png',
tiles = {
-- up, down, right, left, back, front
'techage_industriallamp2.png',
'techage_industriallamp2.png',
'techage_industriallamp2.png^[transformR180',
'techage_industriallamp2.png^[transformR180',
'techage_industriallamp2.png',
'techage_industriallamp2.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-8/32, -16/32, -4/32, 8/32, -9/32, 4/32},
{-7/32, -16/32, -5/32, 7/32, -9/32, 5/32},
{-7/32, -9/32, -4/32, 7/32, -8/32, 4/32},
},
},
},{
tiles = {
-- up, down, right, left, back, front
'techage_industriallamp2_on.png',
'techage_industriallamp2_on.png',
'techage_industriallamp2_on.png^[transformR180',
'techage_industriallamp2_on.png^[transformR180',
'techage_industriallamp2_on.png',
'techage_industriallamp2_on.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-8/32, -16/32, -4/32, 8/32, -9/32, 4/32},
{-7/32, -16/32, -5/32, 7/32, -9/32, 5/32},
{-7/32, -9/32, -4/32, 7/32, -8/32, 4/32},
},
},
})
minetest.register_craft({
output = "techage:industriallamp2_off 2",
recipe = {
{"default:glass", "default:glass", ""},
{"techage:simplelamp_off", "dye:black", ""},
{"basic_materials:steel_bar", "basic_materials:steel_bar", ""},
},
})

View File

@ -7,6 +7,27 @@ local POWER_CONSUMPTION = 1
local Power = techage.ElectricCable local Power = techage.ElectricCable
-- Input data to generate the Param2ToDir table
local Input = {
8,9,10,11, -- 1
16,17,18,19, -- 2
4,5,6,7, -- 3
12,13,14,15, -- 4
0,1,2,3, -- 5
20,21,22,23, -- 6
}
local Param2Dir = {}
for idx,val in ipairs(Input) do
Param2Dir[val] = math.floor((idx - 1) / 4) + 1
end
local function rotate(param2)
local offs = math.floor(param2 / 4) * 4
local rot = ((param2 % 4) + 1) % 4
return offs + rot
end
local function swap_node(pos, postfix) local function swap_node(pos, postfix)
local node = Power:get_node_lvm(pos) local node = Power:get_node_lvm(pos)
local parts = string.split(node.name, "_") local parts = string.split(node.name, "_")
@ -27,7 +48,6 @@ local function on_power_pass1(pos, mem)
end end
local function on_power_pass2(pos, mem, sum) local function on_power_pass2(pos, mem, sum)
local node = minetest
if sum > 0 and mem.running then if sum > 0 and mem.running then
swap_node(pos, "on") swap_node(pos, "on")
return 0 return 0
@ -50,12 +70,50 @@ local function lamp_on_rightclick(pos, node, clicker)
techage.power.power_distribution(pos) techage.power.power_distribution(pos)
end end
local function on_rotate(pos, node, user, mode, new_param2)
if minetest.is_protected(pos, user:get_player_name()) then
return false
end
node.param2 = rotate(node.param2)
minetest.swap_node(pos, node)
return true
end
local function on_place(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
return itemstack
end
return minetest.rotate_and_place(itemstack, placer, pointed_thing)
end
local function determine_power_side(pos, node)
return {tubelib2.Turn180Deg[Param2Dir[node.param2] or 1]}
end
function techage.register_lamp(basename, ndef_off, ndef_on) function techage.register_lamp(basename, ndef_off, ndef_on)
ndef_off.on_construct = tubelib2.init_mem ndef_off.on_construct = tubelib2.init_mem
ndef_off.on_rightclick = lamp_on_rightclick ndef_off.on_rightclick = lamp_on_rightclick
ndef_off.on_rotate = on_rotate
ndef_off.on_place = on_place
ndef_off.paramtype = "light"
ndef_off.light_source = 0
ndef_off.sunlight_propagates = true
ndef_off.paramtype2 = "facedir"
ndef_off.groups = {choppy=2, cracky=2, crumbly=2}
ndef_off.is_ground_content = false
ndef_off.sounds = default.node_sound_glass_defaults()
ndef_on.on_construct = tubelib2.init_mem ndef_on.on_construct = tubelib2.init_mem
ndef_on.on_rightclick = lamp_on_rightclick ndef_on.on_rightclick = lamp_on_rightclick
ndef_on.on_rotate = on_rotate
ndef_on.paramtype = "light"
ndef_on.light_source = minetest.LIGHT_MAX
ndef_on.sunlight_propagates = true
ndef_on.paramtype2 = "facedir"
ndef_on.diggable = false
ndef_on.groups = {not_in_creative_inventory=1}
ndef_on.is_ground_content = false
ndef_on.sounds = default.node_sound_glass_defaults()
minetest.register_node(basename.."_off", ndef_off) minetest.register_node(basename.."_off", ndef_off)
minetest.register_node(basename.."_on", ndef_on) minetest.register_node(basename.."_on", ndef_on)
@ -64,5 +122,6 @@ function techage.register_lamp(basename, ndef_off, ndef_on)
on_power_pass1 = on_power_pass1, on_power_pass1 = on_power_pass1,
on_power_pass2 = on_power_pass2, on_power_pass2 = on_power_pass2,
power_network = Power, power_network = Power,
conn_sides = determine_power_side, -- will be handled by clbk function
}) })
end end

View File

@ -39,13 +39,6 @@ techage.register_lamp("techage:streetlamp", {
type = "fixed", type = "fixed",
fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16}, fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16},
}, },
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_glass_defaults(),
},{ },{
description = "TA Street Lamp", description = "TA Street Lamp",
tiles = { tiles = {
@ -67,13 +60,6 @@ techage.register_lamp("techage:streetlamp", {
type = "fixed", type = "fixed",
fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16}, fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16},
}, },
paramtype = "light",
light_source = minetest.LIGHT_MAX,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {crumbly=0, not_in_creative_inventory=1},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
}) })
minetest.register_craft({ minetest.register_craft({

304
oil/explore.lua Normal file
View File

@ -0,0 +1,304 @@
-- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos
local M = minetest.get_meta
-- Load support for intllib.
local MP = minetest.get_modpath("techage")
local I,IS = dofile(MP.."/intllib.lua")
local PROBABILITY = 2
local OIL_MIN = 1000
local OIL_MAX = 20000
local DEPTH_MIN = (16 * 7) - 8
local DEPTH_MAX = (16 * 60) - 8
local seed = 1234
local function get_node_name(pos)
local node = minetest.get_node_or_nil(pos)
if node then
return node.name
end
local vm = minetest.get_voxel_manip()
local MinEdge, MaxEdge = vm:read_from_map(pos, pos)
local data = vm:get_data()
local area = VoxelArea:new({MinEdge = MinEdge, MaxEdge = MaxEdge})
local idx = area:index(pos.x, pos.y, pos.z)
return minetest.get_name_from_content_id(data[idx])
end
local function oil_amount(pos)
local block_key = seed +
math.floor((pos.z + 32768) / 16) * 4096 * 4096 +
math.floor((pos.y + 32768) / 16) * 4096 +
math.floor((pos.x + 32768) / 16)
math.randomseed(block_key)
math.random(); math.random(); math.random()
local has_oil = math.random(1,PROBABILITY) == 1
if has_oil then
local amount = math.random(OIL_MIN, OIL_MAX)
return amount
end
return 0
end
local function center(coord)
return (math.floor(coord/16) * 16) + 8
end
local Invalid = {
"air",
}
local function gen_oil_slice(pos1, posc, y, radius, data, id)
local y_offs = (y - pos1.y) * 16
for x = posc.x - radius, posc.x + radius do
for z = posc.z - radius, posc.z + radius do
local idx = x - pos1.x + y_offs + (z - pos1.z) * 16 * 16
data[idx] = id
end
end
return (radius * 2 + 1) * (radius * 2 + 1)
end
local function gen_oil_bubble(pos1, posC, amount, data)
local id = minetest.get_content_id("techage:oil_source")
local radius = math.floor(math.pow(amount, 1.0/3) / 2)
local sum = 0
for y = posC.y - radius, posC.y + radius do
sum = sum + gen_oil_slice(pos1, posC, y, radius + 1, data, id)
print(y, sum, amount)
if sum >= amount then break end
end
end
local function useable_stone_block(data)
local valid = {}
for _,id in ipairs(data) do
if not valid[id] then
local itemname = minetest.get_name_from_content_id(id)
local ndef = minetest.registered_nodes[itemname]
if not ndef or not ndef.is_ground_content or Invalid[itemname] then
return false
end
valid[id] = true
end
end
return true
end
local function explore_area(posS, depth, amount, player_name, pos1, pos2, posC)
if amount > 0 and M(posS):get_int("oil_amount") == 0 then
local vm = minetest.get_voxel_manip(pos1, pos2)
local data = vm:get_data()
if useable_stone_block(data) then
gen_oil_bubble(pos1, posC, amount/10, data)
vm:set_data(data)
vm:write_to_map()
vm:update_map()
print("explore_area", S(pos1), S(pos2))
else
amount = 0
end
end
M(posS):set_int("oil_amount", amount)
minetest.chat_send_player(player_name, "[TA Oil] depth: "..tostring(depth)..
", Oil: "..tostring(amount).." ")
end
local function get_next_depth(pos)
local meta = M(pos)
local name = get_node_name(pos)
local depth = DEPTH_MIN
if name == "techage:oilstorage" then
if meta:get_int("oil_amount") == 0 then
depth = M(pos):get_int("exploration_depth") + 32
else
depth = M(pos):get_int("exploration_depth")
end
else
minetest.set_node(pos, {name = "techage:oilstorage"})
end
M(pos):set_int("exploration_depth", depth)
return depth
end
local function emerge_area(pos, node, player_name)
node.name = "techage:oilexplorer_on"
minetest.swap_node(pos, node)
minetest.get_node_timer(pos):start(2.2)
-- used to store the depth/amount info
local store_pos = {x = center(pos.x), y = -100, z = center(pos.z)}
local depth = get_next_depth(store_pos)
minetest.sound_play("techage_explore", {
pos = pos,
max_hear_distance = 8})
local posC = {x = center(pos.x), y = center(pos.y-depth), z = center(pos.z)}
local amount = oil_amount(posC)
if amount > 0 then
local radius = 7
local pos1 = {x = posC.x - radius, y = posC.y - radius, z = posC.z - radius}
local pos2 = {x = posC.x + radius, y = posC.y + radius, z = posC.z + radius}
print("emerge_area", S(pos1), S(pos2), S(posC))
minetest.emerge_area(pos1, pos2)
minetest.after(2, explore_area, store_pos, depth, amount, player_name, pos1, pos2, posC)
else
minetest.after(2, explore_area, store_pos, depth, 0, player_name)
end
end
--local function test(pos)
-- local posC = {x = center(pos.x), y = center(pos.y+20), z = center(pos.z)}
-- local pos1 = {x = posC.x - 8, y = posC.y - 8, z = posC.z - 8}
-- local pos2 = {x = posC.x + 7, y = posC.y + 7, z = posC.z + 7}
-- bubble(pos1, pos2, posC, math.random(10, 200))
--end
-- Used as storage for already explored blocks
-- Will be places -100 in the middle if a block (8,8)
minetest.register_node("techage:oilstorage", {
description = "TA Oil Storage",
tiles = {"default_stone.png"},
groups = {not_in_creative_inventory=1},
diggable = false,
is_ground_content = false,
})
minetest.register_node("techage:oilexplorer", {
description = "Oil Explorer",
tiles = {
"techage_filling_ta3.png^techage_appl_oilexplorer_top.png^techage_frame_ta3_top.png",
"techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_oilexplorer.png",
},
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
emerge_area(pos, node, clicker:get_player_name())
end,
is_ground_content = false,
groups = {snappy=2,cracky=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("techage:oilexplorer_on", {
description = "Oil Explorer",
tiles = {
{
image = "techage_filling4_ta3.png^techage_appl_oilexplorer_top4.png^techage_frame4_ta3_top.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 1.0,
},
},
"techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_oilexplorer.png",
},
on_timer = function(pos,elapsed)
local node = minetest.get_node(pos)
node.name = "techage:oilexplorer"
minetest.swap_node(pos, node)
end,
is_ground_content = false,
groups = {snappy=2,cracky=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("techage:oil_source", {
description = "Oil Source",
drawtype = "liquid",
paramtype = "light",
inventory_image = "techage_oil_inv.png",
tiles = {
{
name = "techage_oil_animated.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 10
}
},
{
name = "techage_oil_animated.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 2.0
}
}
},
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
drowning = 1,
liquidtype = "source",
liquid_alternative_flowing = "techage:oil_flowing",
liquid_alternative_source = "techage:oil_source",
liquid_viscosity = 20,
liquid_range = 10,
post_effect_color = {a = 200, r = 1, g = 1, b = 1},
groups = {liquid = 5},
})
minetest.register_node("techage:oil_flowing", {
description = "Flowing Oil",
drawtype = "flowingliquid",
tiles = {"techage_oil.png"},
special_tiles = {
{
name = "techage_oil_animated.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 10,
},
},
{
name = "techage_oil_animated.png",
backface_culling = true,
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 10,
},
},
},
paramtype = "light",
paramtype2 = "flowingliquid",
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
is_ground_content = false,
drop = "",
drowning = 1,
liquidtype = "flowing",
liquid_alternative_flowing = "techage:oil_flowing",
liquid_alternative_source = "techage:oil_source",
liquid_viscosity = 20,
liquid_range = 10,
post_effect_color = {a = 200, r = 1, g = 1, b = 1},
groups = {liquid = 5, not_in_creative_inventory = 1},
})

68
oil/storage.lua Normal file
View File

@ -0,0 +1,68 @@
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local DAYS_VALID = (30 * 72) -- 30 real days
local storage = minetest.get_mod_storage()
local function data_maintenance()
minetest.log("info", "[MOD] minecart maintenance")
local day_count = minetest.get_day_count()
local tbl = storage:to_table()
for key,s in pairs(tbl.fields) do
local route = minetest.deserialize(s)
if not route.waypoints or not route.best_before or route.best_before < day_count then
storage:set_string(key, "")
else
minetest.log("info", "[minecart] Route: start="..key.." length="..#(route.waypoints))
end
end
end
minetest.after(1, data_maintenance)
-- Store data of running carts
minecart.CartsOnRail = {}
for key,val in pairs(minetest.deserialize(storage:get_string("CartsOnRail")) or {}) do
-- use invalid keys to force the cart spawning
minecart.CartsOnRail[-key] = val
end
minetest.register_on_shutdown(function()
data_maintenance()
storage:set_string("CartsOnRail", minetest.serialize(minecart.CartsOnRail))
end)
-- All positions as "pos_to_string" string
--Routes = {
-- start_pos = {
-- waypoints = {{spos, svel}, {spos, svel}, ...},
-- dest_pos = spos,
-- junctions = {
-- {spos = num},
-- {spos = num},
-- },
-- best_before = num
-- },
-- start_pos = {...},
--}
local Routes = {}
local NEW_ROUTE = {waypoints = {}, junctions = {}}
function minecart.store_route(key, route)
Routes[key] = table.copy(route)
Routes[key].best_before = minetest.get_day_count() + DAYS_VALID
storage:set_string(key, minetest.serialize(Routes[key]))
end
function minecart.get_route(key)
Routes[key] = Routes[key] or minetest.deserialize(storage:get_string(key)) or NEW_ROUTE
Routes[key].best_before = minetest.get_day_count() + DAYS_VALID
return Routes[key]
end
function minecart.del_route(key)
Routes[key] = nil -- remove from memory
storage:set_string(key, "") -- and from storage
end

View File

@ -55,8 +55,12 @@ end
local function set_conn_dirs(pos, sides) local function set_conn_dirs(pos, sides)
local tbl = {} local tbl = {}
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
for _,side in ipairs(sides) do if type(sides) == "function" then
tbl[#tbl+1] = tubelib2.Turn180Deg[side_to_dir(node.param2, side)] tbl = sides(pos, node)
else
for _,side in ipairs(sides) do
tbl[#tbl+1] = tubelib2.Turn180Deg[side_to_dir(node.param2, side)]
end
end end
M(pos):set_string("power_dirs", minetest.serialize(tbl)) M(pos):set_string("power_dirs", minetest.serialize(tbl))
end end
@ -125,7 +129,7 @@ local function power_distribution(pos)
Route = {} Route = {}
pos_already_reached(pos) pos_already_reached(pos)
sum = connection_walk(pos, "on_power_pass3", sum) sum = connection_walk(pos, "on_power_pass3", sum)
print("power sum = "..sum) --print("power sum = "..sum)
end end
local function register_lbm(name) local function register_lbm(name)

View File

@ -110,6 +110,7 @@ minetest.register_node("techage:powerswitch_on", {
switch_off(pos, node, clicker) switch_off(pos, node, clicker)
end, end,
drop = "techage:powerswitch",
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,

BIN
sounds/techage_explore.ogg Normal file

Binary file not shown.

View File

@ -272,7 +272,6 @@ minetest.register_node("techage:boiler2", {
end, end,
power_signal_heat = function(pos) power_signal_heat = function(pos)
print("power_signal_heat")
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
mem.fire_trigger = true mem.fire_trigger = true
if not minetest.get_node_timer(pos):is_started() then if not minetest.get_node_timer(pos):is_started() then

View File

@ -1,95 +1,10 @@
-- for lazy programmers local function bubble(pos1, pos2, posc, amount)
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end local radius = math.floor(math.pow(amount, 0.333))
local P = minetest.string_to_pos local xc = pos2.x - pos1.x
local M = minetest.get_meta for x = posc.x - radius, posc.x + radius do
for y = posc.y - radius, posc.y + radius do
local function determine_water_dir(pos) for z = posc.z - radius, posc.z + radius do
local pos1 = {x=pos.x+1, y=pos.y+1, z=pos.z} local idx = x - pos1.x +
local pos2 = {x=pos.x-1, y=pos.y+1, z=pos.z} (y - pos1.y) * 16 +
local pos3 = {x=pos.x, y=pos.y+1, z=pos.z+1} (z - pos1.z) * 16 * 16
local pos4 = {x=pos.x, y=pos.y+1, z=pos.z-1} print()
local node1 = minetest.get_node(pos1)
local node2 = minetest.get_node(pos2)
local node3 = minetest.get_node(pos3)
local node4 = minetest.get_node(pos4)
if node1.name == "default:water_flowing" and node2.name == "default:water_flowing" then
if node1.param2 > node2.param2 then
return 4
elseif node1.param2 < node2.param2 then
return 2
end
elseif node3.name == "default:water_flowing" and node4.name == "default:water_flowing" then
if node3.param2 > node4.param2 then
return 3
elseif node3.param2 < node4.param2 then
return 1
end
end
return 0
end
local function remove(obj)
obj:remove()
end
local function velocity(obj, dir)
obj:set_velocity(vector.multiply(tubelib2.Dir6dToVector[dir], 0.3))
minetest.after(10, remove, obj)
end
local function node_timer(pos, elapsed)
local node = minetest.get_node(techage.get_pos(pos, 'U'))
local obj = minetest.add_item({x=pos.x, y=pos.y+1, z=pos.z}, ItemStack("default:gold_lump"))
minetest.after(0.8, velocity, obj, M(pos):get_int("water_dir"))
return true
end
minetest.register_node("techage:rinser", {
description = "TechAge Rinser",
tiles = {
-- up, down, right, left, back, front
{
image = "techage_appl_sieve4_top.png^techage_frame4_ta2_top.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2.0,
},
},
'techage_electric_button.png',
},
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow,
is_ground_content = false,
after_place_node = function(pos, placer)
minetest.get_node_timer(pos):start(5)
local dir = determine_water_dir(pos)
M(pos):set_int("water_dir", dir)
end,
on_timer = node_timer,
})
local function remove_objects(pos)
for _, object in pairs(minetest.get_objects_inside_radius(pos, 1)) do
local lua_entity = object:get_luaentity()
if not object:is_player() and lua_entity and lua_entity.name == "__builtin:item" then
object:remove()
end
end
end
minetest.register_lbm({
label = "[techage] Rinser update",
name = "techage:update",
nodenames = {"techage:rinser"},
run_at_every_load = true,
action = function(pos, node)
remove_objects({x=pos.x, y=pos.y+1, z=pos.z})
end
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 551 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 591 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 268 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 429 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 657 B

BIN
textures/techage_oil.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B