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
..
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
...
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
|
local update_disassembler = function(pos)
local m = minetest.get_meta(pos)
local i = m:get_inventory()
local paper = i:get_stack('paper',1)
local item = i:get_stack('item',1)
local ink_count
for j=1,i:get_size('ink') do
local ink = i:get_stack('ink',j)
local c = ink:get_count()
if ink_count then
if c < ink_count then ink_count = c end
else ink_count = c end
end
ink_count = ink_count or 0
local maxrecs = math.min(ink_count, paper:get_count(), item:get_count())
if maxrecs > 0 and sorcery.cookbook.classes.craft.find(item:get_name()) then
local rec = ItemStack{name = 'sorcery:recipe', count = maxrecs}
sorcery.cookbook.setrecipe(rec, 'craft', item:get_name())
i:set_stack('output',1,rec)
else
i:set_stack('output',1,ItemStack())
end
end
local dsbox = {
type = 'fixed';
fixed = {
-0.5, -0.5, -0.5;
0.5, 0.0, 0.5;
};
................................................................................
};
after_dig_node = sorcery.lib.node.purge_container;
on_construct = function(pos)
local m = minetest.get_meta(pos)
local i = m:get_inventory()
i:set_size('item',1)
i:set_size('paper',1)
i:set_size('ink',3)
i:set_size('output',1)
m:set_string('infotext','Disassembly Kit')
m:set_string('formspec', [[
formspec_version[3]
size[10.25,7] real_coordinates[true]
list[current_player;main;0.25,2;8,4]
list[context;item;0.25,0.5;1,1;]
list[context;paper;2.25,0.5;1,1;]
list[context;ink;4.25,0.5;3,1;]
list[context;output;9,0.5;1,1;]
listring[context;output]
listring[current_player;main] listring[context;paper]
listring[current_player;main] listring[context;ink]
listring[current_player;main] listring[context;item]
listring[current_player;main]
]])
end;
on_metadata_inventory_put = update_disassembler;
on_metadata_inventory_take = function(pos,list,idx,stack,user)
local m = minetest.get_meta(pos)
local i = m:get_inventory()
local paper = i:get_stack('paper',1)
local item = i:get_stack('item',1)
if list == 'output' then
local count = stack:get_count()
local leftover = sorcery.data.infusion_leftovers[item:get_name()]
local lstack if leftover then
lstack = ItemStack(leftover)
lstack:set_count(lstack:get_count() * count)
-- this slightly idiosyncratic code is used to ensure that
-- itemstrings can be used in the infusion leftovers table
end
item:take_item(count)
if item:get_count() > 0 then
if leftover then
lstack = user:get_inventory():add_item(lstack)
if lstack:get_count() > 0 then minetest.add_item(pos,lstack) end
end
................................................................................
else
if leftover then
i:set_stack('item',1,lstack)
else
i:set_stack('item',1,ItemStack())
end
end
for j=1,i:get_size('ink') do
local ink = i:get_stack('ink',j)
ink:take_item(count)
i:set_stack('ink',j,ink)
end
end
update_disassembler(pos)
end;
allow_metadata_inventory_put = function(pos,list,idx,stack,user)
local name = stack:get_name()
if list == 'paper' then
if name == 'default:paper' then return stack:get_count() end
elseif list == 'ink' then
if minetest.get_item_group(name,'dye') > 0 then return stack:get_count() end
elseif list == 'item' then
return stack:get_count()
elseif list == 'output' then
return 0
end
return 0
end;
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
<
<
<
<
<
<
<
>
>
|
>
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
<
|
>
|
|
|
>
>
>
>
>
>
>
|
>
>
|
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
..
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
...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
local disassembler_formspec = function(pos)
local m = minetest.get_meta(pos)
local i = m:get_inventory()
local form = [[
formspec_version[3]
size[10.25,7] real_coordinates[true]
list[current_player;main;0.25,2;8,4]
]]
local slot = function(name,x,y,ghost)
local s = string.format('list[context;%s;%f,%f;1,1;]', name, x, y)
if ghost and i:is_empty(name) then
s = string.format('image[%f,%f;1,1;sorcery_ui_ghost_%s.png]',x,y,ghost) .. s
end
form = form .. s
end
slot('item',0.25,0.5)
slot('paper',2.25,0.5,'paper')
slot('ink',3.50,0.5,'ink_bottle')
slot('pen',4.75,0.5,'pen')
slot('output',9,0.5)
form = form .. [[
listring[context;output]
listring[current_player;main] listring[context;paper]
listring[current_player;main] listring[context;ink]
listring[current_player;main] listring[context;item]
listring[current_player;main]
]]
m:set_string('formspec',form)
end
local update_disassembler = function(pos)
local m = minetest.get_meta(pos)
local i = m:get_inventory()
local paper = i:get_stack('paper',1)
local item = i:get_stack('item',1)
local ink = i:get_stack('ink',1)
local pen = i:get_stack('pen',1)
local ink_count = ink:get_count()
local maxrecs = math.min(ink_count, paper:get_count(), item:get_count())
if pen:is_empty() then maxrecs = 0 end
if maxrecs > 0 and sorcery.cookbook.classes.craft.find(item:get_name()) then
local rec = ItemStack{name = 'sorcery:recipe', count = maxrecs}
sorcery.cookbook.setrecipe(rec, 'craft', item:get_name())
i:set_stack('output',1,rec)
else
i:set_stack('output',1,ItemStack())
end
disassembler_formspec(pos)
end
local dsbox = {
type = 'fixed';
fixed = {
-0.5, -0.5, -0.5;
0.5, 0.0, 0.5;
};
................................................................................
};
after_dig_node = sorcery.lib.node.purge_container;
on_construct = function(pos)
local m = minetest.get_meta(pos)
local i = m:get_inventory()
i:set_size('item',1)
i:set_size('paper',1)
i:set_size('ink',1)
i:set_size('pen',1)
i:set_size('output',1)
m:set_string('infotext','Disassembly Kit')
disassembler_formspec(pos)
end;
on_metadata_inventory_put = update_disassembler;
on_metadata_inventory_take = function(pos,list,idx,stack,user)
local m = minetest.get_meta(pos)
local i = m:get_inventory()
local paper = i:get_stack('paper',1)
local item = i:get_stack('item',1)
if list == 'output' then
local count = stack:get_count()
local leftover = sorcery.register.residue.db[item:get_name()]
local lstack if leftover then
lstack = ItemStack(leftover)
lstack:set_count(lstack:get_count() * count)
-- this slightly idiosyncratic code is used to ensure that
-- itemstrings can be used in the residue table
end
item:take_item(count)
if item:get_count() > 0 then
if leftover then
lstack = user:get_inventory():add_item(lstack)
if lstack:get_count() > 0 then minetest.add_item(pos,lstack) end
end
................................................................................
else
if leftover then
i:set_stack('item',1,lstack)
else
i:set_stack('item',1,ItemStack())
end
end
local ink = i:get_stack('ink',1)
local paper = i:get_stack('paper',1)
ink:take_item(count) paper:take_item(count)
i:set_stack('ink',1,ink) i:set_stack('paper',1,paper)
local penstack = i:get_stack('pen',1)
local pen = penstack:get_definition()._sorcery
local uses = pen.material.data.durability * 0.10
local dmg = 65535 / math.random(math.floor(uses*0.5),uses)
print('adding damage',dmg,penstack:get_wear())
penstack:add_wear(dmg)
print('wear now',penstack:get_wear())
i:set_stack('pen',1,penstack)
end
update_disassembler(pos)
end;
allow_metadata_inventory_put = function(pos,list,idx,stack,user)
local name = stack:get_name()
if list == 'paper' then
if name == 'default:paper' then return stack:get_count() end
elseif list == 'ink' then
if minetest.get_item_group(name,'ink') > 0 then return stack:get_count() end
elseif list == 'pen' then
if minetest.get_item_group(name,'sorcery_pen') > 0 then return stack:get_count() end
elseif list == 'item' then
return stack:get_count()
elseif list == 'output' then
return 0
end
return 0
end;
|