-
Notifications
You must be signed in to change notification settings - Fork 0
/
heater.lua
136 lines (105 loc) · 2.89 KB
/
heater.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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
minetest.register_craftitem("bitumen:heat", {
description = "Heat",
stack_max = 100,
inventory_image = "bitumen_heat.png",
groups = {flammable = 3},
})
minetest.register_craft({
type = "fuel",
recipe = "bitumen:heat",
burntime = 10,
})
minetest.register_node("bitumen:heater", {
description = "Heater",
tiles = {
"default_bronze_block.png", "default_bronze_block.png",
"default_bronze_block.png", "default_bronze_block.png",
"default_bronze_block.png", "default_furnace_front.png",
},
paramtype2 = "facedir",
groups = {cracky=2, petroleum_fixture=1},
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
on_punch = function(pos)
swap_node(pos, "bitumen:heater_on")
end,
})
minetest.register_node("bitumen:heater_on", {
description = "Heater (Active)",
tiles = {
"default_tin_block.png", "default_bronze_block.png",
"default_bronze_block.png", "default_tin_block.png",
"default_tin_block.png",
{
image = "default_furnace_front_active.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 1.5
},
}
},
paramtype2 = "facedir",
groups = {cracky=2, petroleum_fixture=1, not_in_creative_inventory=1},
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
on_punch = function(pos)
swap_node(pos, "bitumen:heater")
end,
})
minetest.register_abm({
nodenames = {"bitumen:heater_on"},
interval = 1,
chance = 1,
action = function(pos)
local apos = {x=pos.x, y=pos.y + 1, z=pos.z}
local anode = minetest.get_node(apos)
if anode.name == "air" then
-- print("air above")
return
end
local ameta = minetest.get_meta(apos)
local ainv = ameta:get_inventory()
if ainv:get_size("fuel") <= 0 then
-- print("no fuel inv")
return
end
if ainv:contains_item("fuel", "bitumen:heat 2") then
-- print("fuel full")
return -- still full
end
local node = minetest.get_node(pos)
local back_dir = minetest.facedir_to_dir(node.param2)
local backpos = vector.add(pos, back_dir)
local backnet = bitumen.pipes.get_net(backpos)
if backnet == nil then
-- print("no network")
return
end
local max_amount = 1
local taken, fluid = bitumen.pipes.take_fluid(backpos, max_amount)
-- print("taken " .. fluid .. " " .. taken)
local heat = bitumen.fluid_to_heat(fluid, taken)
ainv:add_item("fuel", "bitumen:heat ".. math.floor(heat+.5))
-- print("")
-- print("added heat ".. heat)
end
})
minetest.register_craft({
output = "bitumen:heater",
recipe = {
{"default:tin_ingot", "default:furnace", "default:tin_ingot"},
{"default:tin_ingot", "default:tin_ingot", "default:tin_ingot"},
{"default:tin_ingot", "default:tin_ingot", "default:tin_ingot"},
}
})