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
...
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
minetest.get_node_timer(pos):start(constants.mill_refresh)
end
local mill_fits_in_slot = function(slot,item)
if slot == 'grinder' then
if minetest.get_item_group(item:get_name(), 'sorcery_mill_grindhead')~=0
then return 1 end
elseif slot == 'input' then
local metal = sorcery.data.metallookup[item:get_name()]
local mat = sorcery.matreg.lookup[item:get_name()]
local comp = sorcery.data.compat.grindables[item:get_name()]
if metal or (mat and mat.metal) or comp then
return item:get_count()
else
mat = item:get_definition()._sorcery and
item:get_definition()._sorcery.material
if mat and mat.grindvalue then
return item:get_count()
end
end
end
return 0
end
local matprops = function(item)
local metal = sorcery.data.metallookup[item:get_name()]
if not metal then
-- allow grinding of armor and tools back to their
-- original components
local mat = sorcery.matreg.lookup[item:get_name()]
if mat and mat.metal then
metal = mat
end
end
local mp = (item:get_definition()._sorcery and
item:get_definition()._sorcery.material)
or sorcery.data.compat.grindables[item:get_name()]
or {}
if metal then mp = {
hardness = mp.hardness or metal.data.hardness;
grindvalue = ((mp.grindvalue or metal.value) or (metal and constants.metal_grindvalue));
powder = mp.powder or metal.data.parts.powder;
grindcost = mp.grindcost or constants.metal_grindcost; -- invariant for metal
} end
mp.torque = constants.grind_torque_factor * mp.hardness
mp.grindvalue = mp.grindvalue or constants.default_grindvalue
mp.grindcost = mp.grindcost or constants.default_grindcost
mp.hardness = mp.hardness or constants.default_hardness;
if item:get_wear() ~= 0 then
-- prevent cheating by recovering metal from items before they
-- are destroyed
local wearfac = (item:get_wear() / 65535)
mp.grindvalue = math.max(1,math.ceil(mp.grindvalue * wearfac))
mp.hardness = math.max(1,math.ceil(mp.grindcost * wearfac))
................................................................................
local speedboost = math.max(0.05,((grindpower - mp.hardness)/constants.grind_range) * grinders)
reqtime = mp.grindvalue * mp.hardness * constants.grind_factor * (1-speedboost)
if elapsed >= reqtime then
item:take_item(mp.grindcost)
inv:set_stack('input',1,item)
local pw = ItemStack{
name=mp.powder;
count=mp.grindvalue;
}
if inv:room_for_item('output',pw) then
inv:add_item('output',pw)
else
minetest.add_item(pos,pw)
end
elapsed = 0
|
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
<
<
>
>
<
|
|
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
135
136
137
138
...
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
minetest.get_node_timer(pos):start(constants.mill_refresh)
end
local mill_fits_in_slot = function(slot,item)
if slot == 'grinder' then
if minetest.get_item_group(item:get_name(), 'sorcery_mill_grindhead')~=0
then return 1 end
elseif slot == 'input' then
if sorcery.itemclass.get(item,'grindable') then
return item:get_count()
end
-- local metal = sorcery.data.metallookup[item:get_name()]
-- local mat = sorcery.matreg.lookup[item:get_name()]
-- local comp = sorcery.data.compat.grindables[item:get_name()]
-- if metal or (mat and mat.metal) or comp then
-- return item:get_count()
-- else
-- mat = item:get_definition()._sorcery and
-- item:get_definition()._sorcery.material
-- if mat and mat.metal or mat.powder then
-- return item:get_count()
-- end
-- end
end
return 0
end
local matprops = function(item)
local metal = sorcery.data.metallookup[item:get_name()]
local props = item:get_definition()._sorcery
if not metal then
-- allow grinding of armor and tools back to their
-- original components
local mat = sorcery.matreg.lookup[item:get_name()]
if mat and mat.metal then
metal = mat
elseif props and props.material and props.material.metal then
metal = props.material
end
end
local mp = (props and props.material)
or sorcery.data.compat.grindables[item:get_name()]
or {}
if metal then mp = {
hardness = mp.hardness or metal.data.hardness;
grindvalue = ((mp.grindvalue or metal.value) or (metal and constants.metal_grindvalue));
powder = mp.powder or metal.data.parts.powder;
grindcost = mp.grindcost or constants.metal_grindcost; -- invariant for metal
} end
mp.hardness = mp.hardness or constants.default_hardness;
mp.torque = constants.grind_torque_factor * mp.hardness
mp.grindvalue = mp.grindvalue or constants.default_grindvalue
mp.grindcost = mp.grindcost or constants.default_grindcost
if item:get_wear() ~= 0 then
-- prevent cheating by recovering metal from items before they
-- are destroyed
local wearfac = (item:get_wear() / 65535)
mp.grindvalue = math.max(1,math.ceil(mp.grindvalue * wearfac))
mp.hardness = math.max(1,math.ceil(mp.grindcost * wearfac))
................................................................................
local speedboost = math.max(0.05,((grindpower - mp.hardness)/constants.grind_range) * grinders)
reqtime = mp.grindvalue * mp.hardness * constants.grind_factor * (1-speedboost)
if elapsed >= reqtime then
item:take_item(mp.grindcost)
inv:set_stack('input',1,item)
local pw = ItemStack{
name=mp.powder;
count=math.floor(mp.grindvalue);
}
if inv:room_for_item('output',pw) then
inv:add_item('output',pw)
else
minetest.add_item(pos,pw)
end
elapsed = 0
|