Add dump button to metal tank

This commit is contained in:
Evert Prants 2018-04-05 09:21:15 +03:00
parent b3297c2fa4
commit ac4c2e95d5
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 55 additions and 6 deletions

View File

@ -82,6 +82,7 @@ function metal_caster.get_metal_caster_formspec(data)
"list[context;bucket_out;4.75,1.4;2,2;]".. "list[context;bucket_out;4.75,1.4;2,2;]"..
"image[5.75,0.2;1,1;gui_furnace_arrow_bg.png^[transformR270]".. "image[5.75,0.2;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
"image[5.75,1.4;1,1;gui_furnace_arrow_bg.png^[transformR90]".. "image[5.75,1.4;1,1;gui_furnace_arrow_bg.png^[transformR90]"..
"button[6.68,2.48;1.33,1;dump;Dump]"..
"list[current_player;main;0,4.25;8,1;]".. "list[current_player;main;0,4.25;8,1;]"..
"list[current_player;main;0,5.5;8,3;8]".. "list[current_player;main;0,5.5;8,3;8]"..
"listring[context;coolant]".. "listring[context;coolant]"..
@ -204,8 +205,6 @@ local function get_cast_for(item)
end end
end end
print(typename, cast)
return typename, cast return typename, cast
end end
@ -254,6 +253,14 @@ local function caster_node_timer(pos, elapsed)
local metal = meta:get_string("metal") local metal = meta:get_string("metal")
local metal_type = "" local metal_type = ""
local dumping = meta:get_int("dump")
if dumping and dumping == 1 then
metal_count = 0
metal = ""
refresh = true
meta:set_int("dump", 0)
end
-- Insert water bucket into tank, return empty bucket -- Insert water bucket into tank, return empty bucket
if inv:get_stack("coolant", 1):get_name() == "bucket:bucket_water" then if inv:get_stack("coolant", 1):get_name() == "bucket:bucket_water" then
if coolant_count + 1000 <= metal_caster.max_coolant then if coolant_count + 1000 <= metal_caster.max_coolant then
@ -423,6 +430,18 @@ function metal_caster.register_cast(name, data)
metal_melter.register_melt(castname, "gold", "cast") metal_melter.register_melt(castname, "gold", "cast")
end end
local function on_receive_fields(pos, formname, fields, sender)
if sender and minetest.is_protected(pos, sender:get_player_name()) then
return 0
end
local meta = minetest.get_meta(pos)
if fields["dump"] then
meta:set_int('dump', 1)
minetest.get_node_timer(pos):start(1.0)
end
end
-- Register the caster -- Register the caster
minetest.register_node("metal_melter:metal_caster", { minetest.register_node("metal_melter:metal_caster", {
description = "Metal Caster", description = "Metal Caster",
@ -449,6 +468,7 @@ minetest.register_node("metal_melter:metal_caster", {
on_metadata_inventory_take = function(pos) on_metadata_inventory_take = function(pos)
minetest.get_node_timer(pos):start(1.0) minetest.get_node_timer(pos):start(1.0)
end, end,
on_receive_fields = on_receive_fields,
on_blast = function(pos) on_blast = function(pos)
local drops = {} local drops = {}
default.get_inventory_drops(pos, "cast", drops) default.get_inventory_drops(pos, "cast", drops)

View File

@ -106,6 +106,7 @@ function metal_melter.get_metal_melter_formspec(data)
"list[context;bucket_out;4.75,1.4;1,1;]".. "list[context;bucket_out;4.75,1.4;1,1;]"..
"image[5.75,0.2;1,1;gui_furnace_arrow_bg.png^[transformR270]".. "image[5.75,0.2;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
"image[5.75,1.4;1,1;gui_furnace_arrow_bg.png^[transformR90]".. "image[5.75,1.4;1,1;gui_furnace_arrow_bg.png^[transformR90]"..
"button[6.68,2.48;1.33,1;dump;Dump]"..
"list[current_player;main;0,4.25;8,1;]".. "list[current_player;main;0,4.25;8,1;]"..
"list[current_player;main;0,5.5;8,3;8]".. "list[current_player;main;0,5.5;8,3;8]"..
"listring[context;heat]".. "listring[context;heat]"..
@ -189,6 +190,14 @@ local function melter_node_timer(pos, elapsed)
-- Current metal used -- Current metal used
local metal = meta:get_string("metal") local metal = meta:get_string("metal")
local dumping = meta:get_int("dump")
if dumping and dumping == 1 then
metal_count = 0
metal = ""
refresh = true
meta:set_int("dump", 0)
end
-- Insert lava bucket into tank, return empty bucket -- Insert lava bucket into tank, return empty bucket
if inv:get_stack("heat", 1):get_name() == "bucket:bucket_lava" then if inv:get_stack("heat", 1):get_name() == "bucket:bucket_lava" then
if heat_count + 1000 <= metal_melter.max_fuel then if heat_count + 1000 <= metal_melter.max_fuel then
@ -324,6 +333,18 @@ local function can_dig(pos, player)
return inv:is_empty("input") and inv:is_empty("heat") and inv:is_empty("bucket_in") and inv:is_empty("bucket_out") return inv:is_empty("input") and inv:is_empty("heat") and inv:is_empty("bucket_in") and inv:is_empty("bucket_out")
end end
local function on_receive_fields(pos, formname, fields, sender)
if sender and minetest.is_protected(pos, sender:get_player_name()) then
return 0
end
local meta = minetest.get_meta(pos)
if fields["dump"] then
meta:set_int('dump', 1)
minetest.get_node_timer(pos):start(1.0)
end
end
minetest.register_node("metal_melter:metal_melter", { minetest.register_node("metal_melter:metal_melter", {
description = "Metal Melter", description = "Metal Melter",
tiles = { tiles = {
@ -356,6 +377,7 @@ minetest.register_node("metal_melter:metal_melter", {
minetest.remove_node(pos) minetest.remove_node(pos)
return drops return drops
end, end,
on_receive_fields = on_receive_fields,
allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move, allow_metadata_inventory_move = allow_metadata_inventory_move,
@ -386,6 +408,7 @@ minetest.register_node("metal_melter:metal_melter_filled", {
on_metadata_inventory_put = function(pos) on_metadata_inventory_put = function(pos)
minetest.get_node_timer(pos):start(1.0) minetest.get_node_timer(pos):start(1.0)
end, end,
on_receive_fields = on_receive_fields,
allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move, allow_metadata_inventory_move = allow_metadata_inventory_move,

View File

@ -325,6 +325,12 @@ local function compare_components_required(tool_spec, materials)
end end
end end
for i, v in pairs(materials) do
if not tool_spec[i] then
all_match = false
end
end
return all_match return all_match
end end
@ -334,15 +340,15 @@ function tinkering.create_tool(tool_type, materials, want_tool, custom_name, ove
-- TODO: Add texture as metadata (https://github.com/minetest/minetest/issues/5686) -- TODO: Add texture as metadata (https://github.com/minetest/minetest/issues/5686)
-- Not a valid tool type -- Not a valid tool type
if not tinkering.tools[tool_type] then return false end if not tinkering.tools[tool_type] then return nil end
local tool_data = tinkering.tools[tool_type] local tool_data = tinkering.tools[tool_type]
-- Check if the components are correct -- Check if the components are correct
if not compare_components_required(tool_data.components, materials) then return false end if not compare_components_required(tool_data.components, materials) then return nil end
-- Get tool definition and other metadata -- Get tool definition and other metadata
local tool_def, mat_names, tags = tinkering.tool_definition(tool_type, materials) local tool_def, mat_names, tags = tinkering.tool_definition(tool_type, materials)
if not tool_def then return false end if not tool_def then return nil end
local mod_name = tool_data.mod or "tinkering" local mod_name = tool_data.mod or "tinkering"
@ -366,7 +372,7 @@ function tinkering.create_tool(tool_type, materials, want_tool, custom_name, ove
minetest.register_tool(internal_name, tool_def) minetest.register_tool(internal_name, tool_def)
end end
if not want_tool then return true end if not want_tool then return nil end
-- Create a new tool instance and apply metadata -- Create a new tool instance and apply metadata
local tool = ItemStack(internal_name) local tool = ItemStack(internal_name)