2019-03-02 14:24:48 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
|
|
|
Copyright (C) 2019 Joachim Stolberg
|
|
|
|
|
|
|
|
LGPLv2.1+
|
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
TA2 Steam Engine Cylinder
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- 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
|
2019-03-05 23:20:44 +03:00
|
|
|
local TP = function(pos) return (minetest.registered_nodes[minetest.get_node(pos).name] or {}).techage end
|
|
|
|
local TN = function(node) return (minetest.registered_nodes[node.name] or {}).techage end
|
2019-03-02 14:24:48 +03:00
|
|
|
|
|
|
|
-- Load support for intllib.
|
|
|
|
local MP = minetest.get_modpath("tubelib2")
|
|
|
|
local I,_ = dofile(MP.."/intllib.lua")
|
|
|
|
|
2019-03-02 22:51:16 +03:00
|
|
|
local POWER_CONSUME = 8
|
2019-03-02 14:24:48 +03:00
|
|
|
|
|
|
|
local function swap_node(pos, name)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
if node.name == name then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
node.name = name
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
end
|
|
|
|
|
2019-03-08 01:12:07 +03:00
|
|
|
-- called from pipe network
|
2019-03-04 00:19:30 +03:00
|
|
|
local function valid_power_dir(pos, mem, in_dir)
|
|
|
|
return mem.power_dir == in_dir
|
|
|
|
end
|
|
|
|
|
2019-03-08 01:12:07 +03:00
|
|
|
-- called from pipe network
|
|
|
|
local function turn_power_on(pos, in_dir, on)
|
|
|
|
print("turn_power_on", in_dir, on)
|
|
|
|
local mem = tubelib2.get_mem(pos)
|
|
|
|
mem.power_supply = on
|
|
|
|
end
|
|
|
|
|
|
|
|
-- called from flywheel
|
|
|
|
local function start_cylinder(pos, on)
|
|
|
|
local mem = tubelib2.get_mem(pos)
|
|
|
|
if on and mem.power_supply then
|
|
|
|
mem.power_consume = POWER_CONSUME
|
2019-03-04 00:19:30 +03:00
|
|
|
swap_node(pos, "techage:cylinder_on")
|
2019-03-08 01:12:07 +03:00
|
|
|
return true
|
2019-03-04 00:19:30 +03:00
|
|
|
else
|
2019-03-08 01:12:07 +03:00
|
|
|
mem.power_consume = 0
|
2019-03-04 00:19:30 +03:00
|
|
|
swap_node(pos, "techage:cylinder")
|
|
|
|
end
|
2019-03-08 01:12:07 +03:00
|
|
|
return false
|
2019-03-02 22:51:16 +03:00
|
|
|
end
|
|
|
|
|
2019-03-02 14:24:48 +03:00
|
|
|
|
|
|
|
minetest.register_node("techage:cylinder", {
|
|
|
|
description = I("TA2 Cylinder"),
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_ta2.png^techage_frame_ta2.png",
|
|
|
|
"techage_filling_ta2.png^techage_frame_ta2.png",
|
2019-03-02 22:51:16 +03:00
|
|
|
"techage_filling_ta2.png^techage_appl_open.png^techage_frame_ta2.png",
|
|
|
|
"techage_filling_ta2.png^techage_frame_ta2.png^techage_steam_hole.png",
|
2019-03-02 14:24:48 +03:00
|
|
|
"techage_filling_ta2.png^techage_cylinder.png^techage_frame_ta2.png",
|
|
|
|
"techage_filling_ta2.png^techage_cylinder.png^techage_frame_ta2.png",
|
|
|
|
},
|
2019-03-02 22:51:16 +03:00
|
|
|
techage = {
|
2019-03-08 01:12:07 +03:00
|
|
|
turn_on = turn_power_on,
|
2019-03-02 22:51:16 +03:00
|
|
|
power_consumption = techage.consumer_power_consumption,
|
|
|
|
power_network = techage.SteamPipe,
|
|
|
|
power_side = 'L',
|
2019-03-04 00:19:30 +03:00
|
|
|
valid_power_dir = valid_power_dir,
|
2019-03-08 01:12:07 +03:00
|
|
|
start_cylinder = start_cylinder,
|
2019-03-02 22:51:16 +03:00
|
|
|
},
|
2019-03-02 14:24:48 +03:00
|
|
|
|
2019-03-08 01:12:07 +03:00
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local mem = techage.consumer_after_place_node(pos, placer)
|
|
|
|
mem.power_consume = 0 -- needed power to run
|
|
|
|
mem.power_supply = false -- power available?
|
|
|
|
end,
|
|
|
|
|
2019-03-02 22:51:16 +03:00
|
|
|
after_tube_update = techage.consumer_after_tube_update,
|
|
|
|
after_dig_node = techage.consumer_after_dig_node,
|
|
|
|
|
2019-03-02 14:24:48 +03:00
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {cracky=2, crumbly=2, choppy=2},
|
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("techage:cylinder_on", {
|
|
|
|
description = I("TA2 Cylinder"),
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_ta2.png^techage_frame_ta2.png",
|
|
|
|
"techage_filling_ta2.png^techage_frame_ta2.png",
|
2019-03-02 22:51:16 +03:00
|
|
|
"techage_filling_ta2.png^techage_appl_open.png^techage_frame_ta2.png",
|
|
|
|
"techage_filling_ta2.png^techage_frame_ta2.png^techage_steam_hole.png",
|
2019-03-02 14:24:48 +03:00
|
|
|
{
|
|
|
|
image = "techage_filling4_ta2.png^techage_cylinder4.png^techage_frame4_ta2.png",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 0.4,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
image = "techage_filling4_ta2.png^techage_cylinder4.png^techage_frame4_ta2.png",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 0.4,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-03-02 22:51:16 +03:00
|
|
|
techage = {
|
2019-03-08 01:12:07 +03:00
|
|
|
turn_on = turn_power_on,
|
2019-03-02 22:51:16 +03:00
|
|
|
power_consumption = techage.consumer_power_consumption,
|
|
|
|
power_network = techage.SteamPipe,
|
|
|
|
power_side = 'L',
|
2019-03-04 00:19:30 +03:00
|
|
|
valid_power_dir = valid_power_dir,
|
2019-03-08 01:12:07 +03:00
|
|
|
start_cylinder = start_cylinder,
|
2019-03-02 22:51:16 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
after_tube_update = techage.consumer_after_tube_update,
|
|
|
|
after_dig_node = techage.consumer_after_dig_node,
|
|
|
|
|
2019-03-02 14:24:48 +03:00
|
|
|
paramtype2 = "facedir",
|
2019-03-02 22:51:16 +03:00
|
|
|
groups = {not_in_creative_inventory=1},
|
|
|
|
diggable = false,
|
2019-03-02 14:24:48 +03:00
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
is_ground_content = false,
|
2019-03-02 22:51:16 +03:00
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2019-03-02 14:24:48 +03:00
|
|
|
})
|
|
|
|
|