-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
103 lines (101 loc) · 3.1 KB
/
init.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
local modpath = core.get_modpath(core.get_current_modname())
better_anvil = {
registered_repairs = {}
}
dofile(modpath.."/api.lua")
core.register_node("better_anvil:anvil", {
description = "Anvil",
tiles = {
"better_anvil_top.png",
"better_anvil_top.png",
"better_anvil_side1.png",
"better_anvil_side1.png",
"better_anvil_side2.png",
"better_anvil_side2.png"
},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
node_box = {
type = "fixed",
fixed = {
{-0.3125, 0.0625, -0.4375, 0.375, 0.5, 0.4375},
{-0.1875, -0.4375, -0.25, 0.25, 0.4375, 0.25},
{-0.375, -0.5, -0.4375, 0.4375, -0.1875, 0.4375},
}
},
groups = {cracky = 1, falling_node = 1, level = 1},
sounds = default.node_sound_metal_defaults(),
on_construct = function(pos)
local meta = core.get_meta(pos)
if meta == nil then
return
end
meta:set_string("formspec", better_anvil.get_formspec(true))
local inv = meta:get_inventory()
inv:set_size("input", 1)
inv:set_size("modifier", 1)
inv:set_size("output", 1)
end,
on_metadata_inventory_take = function(pos, list_name, i, stack, player)
local meta = core.get_meta(pos)
local inv = meta:get_inventory()
local mdstack = inv:get_stack("modifier", 1)
if list_name == "output" then
inv:set_stack("input", 1, "")
if not mdstack:is_empty() then
inv:set_stack("modifier", 1, "")
end
meta:set_string("formspec", better_anvil.get_formspec(true))
elseif list_name == "modifier" then
meta:set_string("formspec", better_anvil.get_formspec(true))
inv:set_stack("output", 1, "")
end
end,
allow_metadata_inventory_put = function(pos, list_name, index, itemstack, player)
local meta = core.get_meta(pos)
local inv = meta:get_inventory()
if list_name == "input" then
local name = itemstack:get_name()
meta:set_string("formspec", better_anvil.get_formspec(false))
return 1
elseif list_name == "modifier" then
local istack = inv:get_stack("input", 1)
local name = itemstack:get_name()
if istack then
local craft = core.get_craft_recipe(name)
core.chat_send_all(dump(craft))
if istack:get_name() == name then
if (istack:get_wear() < itemstack:get_wear()) or (istack:get_wear() == itemstack:get_wear()) then
return 1
else
return 0
end
elseif itemstack:get_definition().groups.dye == 1 then
return 1
else
return 1
end
else
meta:set_string("formspec", better_anvil.get_formspec(true))
return 1
end
elseif list_name == "output" then
meta:set_string("formspec", better_anvil.get_formspec(true))
return 0
end
end,
on_receive_fields = function(pos, formname, fields, sender)
better_anvil.update(pos, fields)
end,
})
core.register_alias("anvil", "better_anvil:anvil")
core.register_alias("better_anvil", "better_anvil:anvil")
core.register_craft({
output = "better_anvil:anvil",
recipe = {
{"default:steelblock", "default:steelblock", "default:steelblock"},
{"", "default:steel_ingot", ""},
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
}
})