-- Technic CNC v1.0 by kpo
-- Based on the NonCubic Blocks MOD v1.4 by yves_de_beck
+
+-- Idea:
+-- Somehw have a tabbed/paged panel if the number of shapes should expand
+-- beyond what is available in the panel today.
+-- I could imagine some form of API allowing modders to come with their own node
+-- box definitions and easily stuff it in the this machine for production.
local shape = {}
local onesize_products = {
slope = 2,
local size = 1;
+-- The form handler is declared here because we need it in both the inactive and active modes
+-- in order to be able to change programs wile it is running.
+local form_handler = function(pos, formname, fields, sender)
+ -- REGISTER MILLING PROGRAMS AND OUTPUTS:
+ ------------------------------------------
+ -- Program for half/full size
+ if fields["full"] then
+ size = 1
+ return
+ end
+
+ if fields["half"] then
+ size = 2
+ return
+ end
+
+ -- Resolve the node name and the number of items to make
+ local meta = minetest.env:get_meta(pos)
+ local inv = meta:get_inventory()
+ local inputstack = inv:get_stack("src", 1)
+ local inputname = inputstack:get_name()
+ local multiplier = 0
+ for k, _ in pairs(fields) do
+ -- Set a multipier for the half/full size capable blocks
+ if twosize_products[k] ~= nil then
+ multiplier = size*twosize_products[k]
+ else
+ multiplier = onesize_products[k]
+ end
+
+ if onesize_products[k] ~= nil or twosize_products[k] ~= nil then
+ meta:set_float( "cnc_multiplier", multiplier)
+ meta:set_string("cnc_user", sender:get_player_name())
+ end
+
+ if onesize_products[k] ~= nil or (twosize_products[k] ~= nil and size==2) then
+ meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k)
+ print(inputname .. "_technic_cnc_" .. k)
+ break
+ end
+
+ if twosize_products[k] ~= nil and size==1 then
+ meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k .. "_double")
+ print(inputname .. "_technic_cnc_" .. k .. "_double")
+ break
+ end
+ end
+ return
+ end -- callback function
+
+-- The actual block inactive state
minetest.register_node("technic:cnc", {
description = "CNC Milling Machine",
tiles = {"technic_cnc_top.png", "technic_cnc_bottom.png", "technic_cnc_side.png",
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
- meta:set_string("infotext", "CNC machine")
+ meta:set_string("infotext", "CNC Machine Inactive")
meta:set_float("technic_power_machine", 1)
meta:set_float("internal_EU_buffer", 0)
meta:set_float("internal_EU_buffer_size", 5000)
local inv = meta:get_inventory()
inv:set_size("src", 1)
inv:set_size("dst", 4)
-
- meta:set_string("formspec", cnc_formspec)
- meta:set_string("infotext", "CNC Milling Machine")
end,
can_dig = function(pos,player)
return true
end,
-
- on_receive_fields = function(pos, formname, fields, sender)
- -- REGISTER MILLING PROGRAMS AND OUTPUTS:
- ------------------------------------------
- -- Program for half/full size
- if fields["full"] then
- size = 1
- return
- end
-
- if fields["half"] then
- size = 2
- return
- end
-
- -- Resolve the node name and the number of items to make
- local meta = minetest.env:get_meta(pos)
- local inv = meta:get_inventory()
- local inputstack = inv:get_stack("src", 1)
- local inputname = inputstack:get_name()
- local multiplier = 0
- for k, _ in pairs(fields) do
- -- Set a multipier for the half/full size capable blocks
- if twosize_products[k] ~= nil then
- multiplier = size*twosize_products[k]
- else
- multiplier = onesize_products[k]
- end
-
- if onesize_products[k] ~= nil or twosize_products[k] ~= nil then
- meta:set_float( "cnc_multiplier", multiplier)
- meta:set_string("cnc_user", sender:get_player_name())
- end
-
- if onesize_products[k] ~= nil or (twosize_products[k] ~= nil and size==2) then
- meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k)
- break
- end
-
- if twosize_products[k] ~= nil and size==1 then
- meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k .. "_double")
- break
- end
- end
- return
- end, -- callback function
+ on_receive_fields = form_handler,
})
+-- Active state block
minetest.register_node("technic:cnc_active", {
description = "CNC Machine",
- tiles = {"technic_cnc_top.png", "technic_cnc_bottom.png", "technic_cnc_side.png",
- "technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front_active.png"},
+ tiles = {"technic_cnc_top_active.png", "technic_cnc_bottom.png", "technic_cnc_side.png",
+ "technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front_active.png"},
paramtype2 = "facedir",
groups = {cracky=2,not_in_creative_inventory=1},
legacy_facedir_simple = true,
end
return true
end,
+ on_receive_fields = form_handler,
})
+-- Action code performing the transformation
minetest.register_abm(
{
nodenames = {"technic:cnc","technic:cnc_active"},