summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkpoppel <poulsen.kim@gmail.com>2013-05-07 22:51:03 +0200
committerkpoppel <poulsen.kim@gmail.com>2013-05-07 22:51:03 +0200
commitfef948c5ac919082fa30d441ec62d6d1d0d2c98b (patch)
treeecd589794119492774df7c0e3f0e3735811886ae
parent7f2be244f2f7f2497cba33ba1e2bd5a599f23bfb (diff)
CNC can now change programs while it is working.
-rw-r--r--technic/battery_box.lua4
-rw-r--r--technic/cnc.lua116
2 files changed, 66 insertions, 54 deletions
diff --git a/technic/battery_box.lua b/technic/battery_box.lua
index 0e08d74..9c91821 100644
--- a/technic/battery_box.lua
+++ b/technic/battery_box.lua
@@ -218,7 +218,7 @@ minetest.register_abm({
end
end
--- dischargin registered power tools
+-- discharging registered power tools
if inv:is_empty("dst") == false then
srcstack = inv:get_stack("dst", 1)
src_item=srcstack:to_table()
@@ -297,7 +297,7 @@ table_index=1
local pos1={}
i=1
repeat
- if PR_nodes[i]==nil then break end -- gettin power from all connected producers
+ if PR_nodes[i]==nil then break end -- getting power from all connected producers
pos1.x=PR_nodes[i].x
pos1.y=PR_nodes[i].y
pos1.z=PR_nodes[i].z
diff --git a/technic/cnc.lua b/technic/cnc.lua
index 71b78b0..4976502 100644
--- a/technic/cnc.lua
+++ b/technic/cnc.lua
@@ -1,5 +1,11 @@
-- 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,
@@ -89,6 +95,57 @@ local cnc_power_formspec=
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",
@@ -117,7 +174,7 @@ minetest.register_node("technic:cnc", {
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)
@@ -127,9 +184,6 @@ minetest.register_node("technic:cnc", {
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)
@@ -142,58 +196,14 @@ minetest.register_node("technic:cnc", {
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,
@@ -206,8 +216,10 @@ minetest.register_node("technic:cnc_active", {
end
return true
end,
+ on_receive_fields = form_handler,
})
+-- Action code performing the transformation
minetest.register_abm(
{
nodenames = {"technic:cnc","technic:cnc_active"},