techage/steam_engine/gearbox.lua

127 lines
3.0 KiB
Lua
Raw Normal View History

2019-03-02 14:24:48 +03:00
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
GPL v3
2019-03-02 14:24:48 +03:00
See LICENSE.txt for more information
TA2 Gearbox
]]--
-- for lazy programmers
local P = minetest.string_to_pos
local M = minetest.get_meta
local S = techage.S
2019-03-02 14:24:48 +03:00
2019-06-16 22:06:16 +03:00
local PWR_NEEDED = 1
local CYCLE_TIME = 4
2019-03-02 14:24:48 +03:00
2019-03-09 00:08:39 +03:00
local Axle = techage.Axle
2019-08-17 00:44:11 +03:00
local power = techage.power
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-08-17 00:44:11 +03:00
local function on_power(pos, mem)
swap_node(pos, "techage:gearbox_on")
techage.switch_axles(pos, true)
end
2019-08-17 00:44:11 +03:00
local function on_nopower(pos, mem)
swap_node(pos, "techage:gearbox")
techage.switch_axles(pos, false)
end
2019-06-16 22:06:16 +03:00
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
2019-08-17 00:44:11 +03:00
power.consumer_alive(pos, mem)
2019-06-16 22:06:16 +03:00
return true
end
2019-08-17 00:44:11 +03:00
-- to be able to restart the node after server crashes
2019-06-16 22:06:16 +03:00
local function on_rightclick(pos, node, clicker)
2019-08-17 00:44:11 +03:00
local mem = tubelib2.get_mem(pos)
2019-06-16 22:06:16 +03:00
minetest.get_node_timer(pos):start(CYCLE_TIME)
2019-08-17 00:44:11 +03:00
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED)
2019-06-16 22:06:16 +03:00
end
local function after_place_node(pos, placer, itemstack, pointed_thing)
local mem = tubelib2.init_mem(pos)
2019-06-16 22:06:16 +03:00
minetest.get_node_timer(pos):start(CYCLE_TIME)
2019-08-17 00:44:11 +03:00
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED)
end
local function after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
techage.switch_axles(pos, node.name == "techage:gearbox_on")
2019-03-02 14:24:48 +03:00
end
minetest.register_node("techage:gearbox", {
description = S("TA2 Gearbox"),
2019-03-02 14:24:48 +03:00
tiles = {"techage_filling_ta2.png^techage_axle_gearbox.png^techage_frame_ta2.png"},
2019-05-21 01:05:53 +03:00
on_construct = tubelib2.init_mem,
2019-06-16 22:06:16 +03:00
after_place_node = after_place_node,
on_rightclick = on_rightclick,
2019-08-17 00:44:11 +03:00
after_tube_update = after_tube_update,
2019-06-16 22:06:16 +03:00
on_timer = node_timer,
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:gearbox_on", {
tiles = {
-- up, down, right, left, back, front
{
image = "techage_filling4_ta2.png^techage_axle_gearbox4.png^techage_frame4_ta2.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 0.6,
},
},
},
2019-06-16 22:06:16 +03:00
after_place_node = after_place_node,
on_rightclick = on_rightclick,
on_timer = node_timer,
2019-08-17 00:44:11 +03:00
after_tube_update = after_tube_update,
2019-03-02 14:24:48 +03:00
paramtype2 = "facedir",
groups = {not_in_creative_inventory=1},
diggable = false,
2019-06-16 22:06:16 +03:00
drop = "",
2019-03-02 14:24:48 +03:00
on_rotate = screwdriver.disallow,
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
2019-05-21 01:05:53 +03:00
techage.power.register_node({"techage:gearbox", "techage:gearbox_on"}, {
power_network = Axle,
on_power = on_power,
2019-08-17 00:44:11 +03:00
on_nopower = on_nopower,
2019-05-21 01:05:53 +03:00
})
2019-04-28 17:04:45 +03:00
minetest.register_craft({
output = "techage:gearbox 2",
recipe = {
{"default:junglewood", "techage:axle", "default:wood"},
{"techage:axle", "techage:iron_ingot", "techage:axle"},
{"default:wood", "techage:axle", "default:junglewood"},
},
})