Add recipe on_done callback. Fix some bugs. Update of punch powered setting.

This commit is contained in:
SFENCE 2021-12-16 20:36:23 +01:00
parent 506807981a
commit ef44a002ce
3 changed files with 21 additions and 11 deletions

View File

@ -1,4 +1,6 @@
appliances.all_sides = {"right", "left", "front", "back", "top", "bottom"}
appliances.appliance = {};
local appliance = appliances.appliance;
@ -154,7 +156,7 @@ appliance.have_control = false;
function appliance:recipe_register_input(input_name, input_def)
if (not self.have_input) then
minetest.log("error", "Input is disabled. Registration of input recipe cannot be finished.");
minetest.log("error", "[Appliances]: Input is disabled. Registration of input recipe cannot be finished.");
return;
end
if (self.input_stack_size <= 1) then
@ -163,7 +165,7 @@ function appliance:recipe_register_input(input_name, input_def)
local register = true;
for index, value in pairs(input_def.inputs) do
if ((index < 1) or ( index > self.input_stack_size)) then
minetest.log("error", "Input definition is not compatible with size of input stack: "..dump(input_def));
minetest.log("error", "[Appliances]: Input definition is not compatible with size of input stack: "..dump(input_def));
register = false;
break;
end
@ -407,7 +409,7 @@ function appliance:recipe_inventory_can_take(pos, listname, index, stack, player
count = count-input.inputs;
if (count<0) then count = 0; end
else
minetest.log("error", "Input item missing in recipes list.")
minetest.log("error", "[Appliances]: Input item missing in recipes list.")
end
end
elseif (listname==self.use_stack) then
@ -701,13 +703,13 @@ end
function appliance:interrupt_production(timer_step)
if (self.stoppable_production==false) then
if (production_time>0) then
if (timer_step.production_time>0) then
if timer_step.use_input then
if timer_step.use_input.losts then
local output = self:recipe_select_output(timer_step, timer_step.use_input.losts);
self:recipe_output_to_stack_or_drop(timer_step.pos, timer_step.inv, output);
end
self:recipe_input_from_stack(inv, timer_step.use_input);
self:recipe_input_from_stack(timer_step.inv, timer_step.use_input);
end
timer_step.meta:set_int("production_time", 0);
timer_step.production_time = 0;
@ -784,11 +786,15 @@ function appliance:remove_used_item(timer_step)
self:waiting(timer_step.pos, timer_step.meta);
return true;
end
self:recipe_output_to_stack(timer_step.inv, output);
if timer_step.use_usage.on_done then
output = timer_step.use_usage.on_done(self, timer_step, output)
end
self:recipe_output_to_stack_or_drop(timer_step.pos, timer_step.inv, output);
self:recipe_usage_from_stack(timer_step.inv, timer_step.use_usage);
timer_step.consumption_time = 0;
timer_step.meta:set_int("consumption_time", 0);
end
return false
end
function appliance:production_done(timer_step)
@ -798,11 +804,15 @@ function appliance:production_done(timer_step)
self:waiting(timer_step.pos, timer_step.meta);
return true;
end
self:recipe_output_to_stack(timer_step.inv, output);
if timer_step.use_input.on_done then
output = timer_step.use_input.on_done(self, timer_step, output)
end
self:recipe_output_to_stack_or_drop(timer_step.pos, timer_step.inv, output);
self:recipe_input_from_stack(timer_step.inv, timer_step.use_input);
timer_step.production_time = 0;
timer_step.meta:set_int("production_time", 0);
end
return false
end
function appliance:update_meta_formspec(timer_step)

View File

@ -94,7 +94,7 @@ if appliances.have_pipeworks then
end
local item_supply =
{
update_node_def = function (self, power_data, node_def)
update_node_def = function (self, supply_data, node_def)
node_def.groups.tubedevice = 1;
node_def.groups.tubedevice_receiver = 1;
node_def.tube =

View File

@ -38,8 +38,8 @@ if true then
{
is_powered = function (self, power_supply, pos, meta)
local is_powered = meta:get_int("is_powered");
if (is_powered~=0) then
meta:set_int("is_powered", 0);
if (is_powered>0) then
meta:set_int("is_powered", is_powered-1);
return power_supply.run_speed;
end
return 0;
@ -52,7 +52,7 @@ if true then
end,
on_punch = function (self, power_supply, pos, node, puncher, pointed_thing)
local meta = minetest.get_meta(pos);
meta:set_int("is_powered", 1);
meta:set_int("is_powered", power_supply.punch_power or 1);
end,
};