allow CNC to work without technic

minetest.conf technic_cnc_use_technic = false disables
use of power, returns items instantly, uses only default
stuff in craft recipe

(defaults to enabled if technic is installed)
This commit is contained in:
Vanessa Dannenberg 2018-11-25 08:13:56 -05:00 committed by Nathanaël Courant
parent dc0689018d
commit d40946fa38
5 changed files with 193 additions and 114 deletions

View File

@ -7,10 +7,15 @@
-- I could imagine some form of API allowing modders to come with their own node -- 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. -- box definitions and easily stuff it in the this machine for production.
local technic_modpath = minetest.get_modpath("technic") local S = technic_cnc.getter
local S = technic.getter local allow_metadata_inventory_put
local allow_metadata_inventory_take
local allow_metadata_inventory_move
local can_dig
local voltage = ""
if technic_cnc.use_technic then
minetest.register_craft({ minetest.register_craft({
output = 'technic:cnc', output = 'technic:cnc',
recipe = { recipe = {
@ -20,6 +25,53 @@ minetest.register_craft({
}, },
}) })
allow_metadata_inventory_put = technic.machine_inventory_put
allow_metadata_inventory_take = technic.machine_inventory_take
allow_metadata_inventory_move = technic.machine_inventory_move
can_dig = technic.machine_can_dig
voltage = "LV "
else
minetest.register_craft({
output = 'technic:cnc',
recipe = {
{'default:glass', 'default:diamond', 'default:glass'},
{'basic_materials:ic', 'default:steelblock', 'basic_materials:motor'},
{'default:steel_ingot', 'default:mese', 'default:steel_ingot'},
},
})
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return stack:get_count()
end
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return stack:get_count()
end
allow_metadata_inventory_move = function(pos, from_list, from_index,
to_list, to_index, count, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return stack:get_count()
end
can_dig = function(pos, player)
if player and minetest.is_protected(pos, player:get_player_name()) then return false end
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("dst")
and inv:is_empty("src")
and default.can_interact_with_node(player, pos)
end
end
local shape = {} local shape = {}
local onesize_products = { local onesize_products = {
@ -140,7 +192,19 @@ local function form_handler(pos, formname, fields, sender)
break break
end end
end end
return
if not technic_cnc.use_technic then
local result = meta:get_string("cnc_product")
if not inv:is_empty("src")
and minetest.registered_nodes[result]
and inv:room_for_item("dst", result) then
local srcstack = inv:get_stack("src", 1)
srcstack:take_item()
inv:set_stack("src", 1, srcstack)
inv:add_item("dst", result.." "..meta:get_int("cnc_multiplier"))
end
end
end end
-- Action code performing the transformation -- Action code performing the transformation
@ -148,7 +212,7 @@ local run = function(pos, node)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local eu_input = meta:get_int("LV_EU_input") local eu_input = meta:get_int("LV_EU_input")
local machine_name = S("%s CNC Machine"):format("LV") local machine_name = S("%sCNC Machine"):format(voltage)
local machine_node = "technic:cnc" local machine_node = "technic:cnc"
local demand = 450 local demand = 450
@ -183,7 +247,7 @@ end
-- The actual block inactive state -- The actual block inactive state
minetest.register_node(":technic:cnc", { minetest.register_node(":technic:cnc", {
description = S("%s CNC Machine"):format("LV"), description = S("%sCNC Machine"):format(voltage),
tiles = {"technic_cnc_top.png", "technic_cnc_bottom.png", "technic_cnc_side.png", tiles = {"technic_cnc_top.png", "technic_cnc_bottom.png", "technic_cnc_side.png",
"technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front.png"}, "technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front.png"},
groups = {cracky=2, technic_machine=1, technic_lv=1}, groups = {cracky=2, technic_machine=1, technic_lv=1},
@ -192,24 +256,26 @@ minetest.register_node(":technic:cnc", {
legacy_facedir_simple = true, legacy_facedir_simple = true,
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("infotext", S("%s CNC Machine"):format("LV")) meta:set_string("infotext", S("%sCNC Machine"):format(voltage))
meta:set_float("technic_power_machine", 1) meta:set_float("technic_power_machine", 1)
meta:set_string("formspec", cnc_formspec) meta:set_string("formspec", cnc_formspec)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("src", 1) inv:set_size("src", 1)
inv:set_size("dst", 4) inv:set_size("dst", 4)
end, end,
can_dig = technic.machine_can_dig, can_dig = can_dig,
allow_metadata_inventory_put = technic.machine_inventory_put, allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = technic.machine_inventory_take, allow_metadata_inventory_take = allow_metadata_inventory_take,
allow_metadata_inventory_move = technic.machine_inventory_move, allow_metadata_inventory_move = allow_metadata_inventory_move,
on_receive_fields = form_handler, on_receive_fields = form_handler,
technic_run = run, technic_run = technic_cnc.use_technic and run,
}) })
-- Active state block -- Active state block
if technic_cnc.use_technic then
minetest.register_node(":technic:cnc_active", { minetest.register_node(":technic:cnc_active", {
description = S("%s CNC Machine"):format("LV"), description = S("%sCNC Machine"):format(voltage),
tiles = {"technic_cnc_top_active.png", "technic_cnc_bottom.png", "technic_cnc_side.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"}, "technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front_active.png"},
groups = {cracky=2, technic_machine=1, technic_lv=1, not_in_creative_inventory=1}, groups = {cracky=2, technic_machine=1, technic_lv=1, not_in_creative_inventory=1},
@ -217,10 +283,10 @@ minetest.register_node(":technic:cnc_active", {
paramtype2 = "facedir", paramtype2 = "facedir",
drop = "technic:cnc", drop = "technic:cnc",
legacy_facedir_simple = true, legacy_facedir_simple = true,
can_dig = technic.machine_can_dig, can_dig = can_dig,
allow_metadata_inventory_put = technic.machine_inventory_put, allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = technic.machine_inventory_take, allow_metadata_inventory_take = allow_metadata_inventory_take,
allow_metadata_inventory_move = technic.machine_inventory_move, allow_metadata_inventory_move = allow_metadata_inventory_move,
on_receive_fields = form_handler, on_receive_fields = form_handler,
technic_run = run, technic_run = run,
technic_disabled_machine_name = "technic:cnc", technic_disabled_machine_name = "technic:cnc",
@ -228,4 +294,6 @@ minetest.register_node(":technic:cnc_active", {
technic.register_machine("LV", "technic:cnc", technic.receiver) technic.register_machine("LV", "technic:cnc", technic.receiver)
technic.register_machine("LV", "technic:cnc_active", technic.receiver) technic.register_machine("LV", "technic:cnc_active", technic.receiver)
else
minetest.register_alias("technic:cnc_active", "technic:cnc")
end

View File

@ -1,16 +1,14 @@
-- API for the technic CNC machine -- API for the technic CNC machine
-- Again code is adapted from the NonCubic Blocks MOD v1.4 by yves_de_beck -- Again code is adapted from the NonCubic Blocks MOD v1.4 by yves_de_beck
local S = technic.getter local S = technic_cnc.getter
technic.cnc = {}
-- REGISTER NONCUBIC FORMS, CREATE MODELS AND RECIPES: -- REGISTER NONCUBIC FORMS, CREATE MODELS AND RECIPES:
------------------------------------------------------ ------------------------------------------------------
-- Define slope boxes for the various nodes -- Define slope boxes for the various nodes
------------------------------------------- -------------------------------------------
technic.cnc.programs = { technic_cnc.programs = {
{ suffix = "technic_cnc_stick", { suffix = "technic_cnc_stick",
model = {-0.15, -0.5, -0.15, 0.15, 0.5, 0.15}, model = {-0.15, -0.5, -0.15, 0.15, 0.5, 0.15},
desc = S("Stick") desc = S("Stick")
@ -263,7 +261,7 @@ technic.cnc.programs = {
} }
-- Allow disabling certain programs for some node. Default is allowing all types for all nodes -- Allow disabling certain programs for some node. Default is allowing all types for all nodes
technic.cnc.programs_disable = { technic_cnc.programs_disable = {
-- ["default:brick"] = {"technic_cnc_stick"}, -- Example: Disallow the stick for brick -- ["default:brick"] = {"technic_cnc_stick"}, -- Example: Disallow the stick for brick
-- ... -- ...
["default:dirt"] = {"technic_cnc_oblate_spheroid", "technic_cnc_slope_upsdown", "technic_cnc_edge", ["default:dirt"] = {"technic_cnc_oblate_spheroid", "technic_cnc_slope_upsdown", "technic_cnc_edge",
@ -273,7 +271,7 @@ technic.cnc.programs_disable = {
} }
-- Generic function for registering all the different node types -- Generic function for registering all the different node types
function technic.cnc.register_program(recipeitem, suffix, model, groups, images, description, cbox, sbox) function technic_cnc.register_program(recipeitem, suffix, model, groups, images, description, cbox, sbox)
local dtype local dtype
local nodeboxdef local nodeboxdef
@ -308,12 +306,12 @@ function technic.cnc.register_program(recipeitem, suffix, model, groups, images,
end end
-- function to iterate over all the programs the CNC machine knows -- function to iterate over all the programs the CNC machine knows
function technic.cnc.register_all(recipeitem, groups, images, description) function technic_cnc.register_all(recipeitem, groups, images, description)
for _, data in ipairs(technic.cnc.programs) do for _, data in ipairs(technic_cnc.programs) do
-- Disable node creation for disabled node types for some material -- Disable node creation for disabled node types for some material
local do_register = true local do_register = true
if technic.cnc.programs_disable[recipeitem] ~= nil then if technic_cnc.programs_disable[recipeitem] ~= nil then
for __, disable in ipairs(technic.cnc.programs_disable[recipeitem]) do for __, disable in ipairs(technic_cnc.programs_disable[recipeitem]) do
if disable == data.suffix then if disable == data.suffix then
do_register = false do_register = false
end end
@ -321,49 +319,49 @@ function technic.cnc.register_all(recipeitem, groups, images, description)
end end
-- Create the node if it passes the test -- Create the node if it passes the test
if do_register then if do_register then
technic.cnc.register_program(recipeitem, data.suffix, data.model, technic_cnc.register_program(recipeitem, data.suffix, data.model,
groups, images, description.." "..data.desc, data.cbox, data.sbox) groups, images, description.." "..data.desc, data.cbox, data.sbox)
end end
end end
end end
-- REGISTER NEW TECHNIC_CNC_API's PART 2: technic.cnc..register_element_end(subname, recipeitem, groups, images, desc_element_xyz) -- REGISTER NEW TECHNIC_CNC_API's PART 2: technic_cnc..register_element_end(subname, recipeitem, groups, images, desc_element_xyz)
----------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------
function technic.cnc.register_slope_edge_etc(recipeitem, groups, images, desc_slope, desc_slope_lying, desc_slope_upsdown, desc_slope_edge, desc_slope_inner_edge, desc_slope_upsdwn_edge, desc_slope_upsdwn_inner_edge, desc_pyramid, desc_spike, desc_onecurvededge, desc_twocurvededge, desc_cylinder, desc_cylinder_horizontal, desc_spheroid, desc_element_straight, desc_element_edge, desc_element_t, desc_element_cross, desc_element_end) function technic_cnc.register_slope_edge_etc(recipeitem, groups, images, desc_slope, desc_slope_lying, desc_slope_upsdown, desc_slope_edge, desc_slope_inner_edge, desc_slope_upsdwn_edge, desc_slope_upsdwn_inner_edge, desc_pyramid, desc_spike, desc_onecurvededge, desc_twocurvededge, desc_cylinder, desc_cylinder_horizontal, desc_spheroid, desc_element_straight, desc_element_edge, desc_element_t, desc_element_cross, desc_element_end)
technic.cnc.register_slope(recipeitem, groups, images, desc_slope) technic_cnc.register_slope(recipeitem, groups, images, desc_slope)
technic.cnc.register_slope_lying(recipeitem, groups, images, desc_slope_lying) technic_cnc.register_slope_lying(recipeitem, groups, images, desc_slope_lying)
technic.cnc.register_slope_upsdown(recipeitem, groups, images, desc_slope_upsdown) technic_cnc.register_slope_upsdown(recipeitem, groups, images, desc_slope_upsdown)
technic.cnc.register_slope_edge(recipeitem, groups, images, desc_slope_edge) technic_cnc.register_slope_edge(recipeitem, groups, images, desc_slope_edge)
technic.cnc.register_slope_inner_edge(recipeitem, groups, images, desc_slope_inner_edge) technic_cnc.register_slope_inner_edge(recipeitem, groups, images, desc_slope_inner_edge)
technic.cnc.register_slope_edge_upsdown(recipeitem, groups, images, desc_slope_upsdwn_edge) technic_cnc.register_slope_edge_upsdown(recipeitem, groups, images, desc_slope_upsdwn_edge)
technic.cnc.register_slope_inner_edge_upsdown(recipeitem, groups, images, desc_slope_upsdwn_inner_edge) technic_cnc.register_slope_inner_edge_upsdown(recipeitem, groups, images, desc_slope_upsdwn_inner_edge)
technic.cnc.register_pyramid(recipeitem, groups, images, desc_pyramid) technic_cnc.register_pyramid(recipeitem, groups, images, desc_pyramid)
technic.cnc.register_spike(recipeitem, groups, images, desc_spike) technic_cnc.register_spike(recipeitem, groups, images, desc_spike)
technic.cnc.register_onecurvededge(recipeitem, groups, images, desc_onecurvededge) technic_cnc.register_onecurvededge(recipeitem, groups, images, desc_onecurvededge)
technic.cnc.register_twocurvededge(recipeitem, groups, images, desc_twocurvededge) technic_cnc.register_twocurvededge(recipeitem, groups, images, desc_twocurvededge)
technic.cnc.register_cylinder(recipeitem, groups, images, desc_cylinder) technic_cnc.register_cylinder(recipeitem, groups, images, desc_cylinder)
technic.cnc.register_cylinder_horizontal(recipeitem, groups, images, desc_cylinder_horizontal) technic_cnc.register_cylinder_horizontal(recipeitem, groups, images, desc_cylinder_horizontal)
technic.cnc.register_spheroid(recipeitem, groups, images, desc_spheroid) technic_cnc.register_spheroid(recipeitem, groups, images, desc_spheroid)
technic.cnc.register_element_straight(recipeitem, groups, images, desc_element_straight) technic_cnc.register_element_straight(recipeitem, groups, images, desc_element_straight)
technic.cnc.register_element_edge(recipeitem, groups, images, desc_element_edge) technic_cnc.register_element_edge(recipeitem, groups, images, desc_element_edge)
technic.cnc.register_element_t(recipeitem, groups, images, desc_element_t) technic_cnc.register_element_t(recipeitem, groups, images, desc_element_t)
technic.cnc.register_element_cross(recipeitem, groups, images, desc_element_cross) technic_cnc.register_element_cross(recipeitem, groups, images, desc_element_cross)
technic.cnc.register_element_end(recipeitem, groups, images, desc_element_end) technic_cnc.register_element_end(recipeitem, groups, images, desc_element_end)
end end
-- REGISTER STICKS: noncubic.register_xyz(recipeitem, groups, images, desc_element_xyz) -- REGISTER STICKS: noncubic.register_xyz(recipeitem, groups, images, desc_element_xyz)
------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------
function technic.cnc.register_stick_etc(recipeitem, groups, images, desc_stick) function technic_cnc.register_stick_etc(recipeitem, groups, images, desc_stick)
technic.cnc.register_stick(recipeitem, groups, images, desc_stick) technic_cnc.register_stick(recipeitem, groups, images, desc_stick)
end end
function technic.cnc.register_elements(recipeitem, groups, images, desc_element_straight_double, desc_element_edge_double, desc_element_t_double, desc_element_cross_double, desc_element_end_double) function technic_cnc.register_elements(recipeitem, groups, images, desc_element_straight_double, desc_element_edge_double, desc_element_t_double, desc_element_cross_double, desc_element_end_double)
technic.cnc.register_element_straight_double(recipeitem, groups, images, desc_element_straight_double) technic_cnc.register_element_straight_double(recipeitem, groups, images, desc_element_straight_double)
technic.cnc.register_element_edge_double(recipeitem, groups, images, desc_element_edge_double) technic_cnc.register_element_edge_double(recipeitem, groups, images, desc_element_edge_double)
technic.cnc.register_element_t_double(recipeitem, groups, images, desc_element_t_double) technic_cnc.register_element_t_double(recipeitem, groups, images, desc_element_t_double)
technic.cnc.register_element_cross_double(recipeitem, groups, images, desc_element_cross_double) technic_cnc.register_element_cross_double(recipeitem, groups, images, desc_element_cross_double)
technic.cnc.register_element_end_double(recipeitem, groups, images, desc_element_end_double) technic_cnc.register_element_end_double(recipeitem, groups, images, desc_element_end_double)
end end

View File

@ -1,91 +1,99 @@
-- REGISTER MATERIALS AND PROPERTIES FOR NONCUBIC ELEMENTS: -- REGISTER MATERIALS AND PROPERTIES FOR NONCUBIC ELEMENTS:
----------------------------------------------------------- -----------------------------------------------------------
local S = technic.getter local S = technic_cnc.getter
-- DIRT -- DIRT
------- -------
technic.cnc.register_all("default:dirt", technic_cnc.register_all("default:dirt",
{snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1}, {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1},
{"default_grass.png", "default_dirt.png", "default_grass.png"}, {"default_grass.png", "default_dirt.png", "default_grass.png"},
S("Dirt")) S("Dirt"))
-- WOOD -- WOOD
------- -------
technic.cnc.register_all("default:wood", technic_cnc.register_all("default:wood",
{snappy=2, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1}, {snappy=2, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1},
{"default_wood.png"}, {"default_wood.png"},
S("Wooden")) S("Wooden"))
-- STONE -- STONE
-------- --------
technic.cnc.register_all("default:stone", technic_cnc.register_all("default:stone",
{cracky=3, not_in_creative_inventory=1}, {cracky=3, not_in_creative_inventory=1},
{"default_stone.png"}, {"default_stone.png"},
S("Stone")) S("Stone"))
-- COBBLE -- COBBLE
--------- ---------
technic.cnc.register_all("default:cobble", technic_cnc.register_all("default:cobble",
{cracky=3, not_in_creative_inventory=1}, {cracky=3, not_in_creative_inventory=1},
{"default_cobble.png"}, {"default_cobble.png"},
S("Cobble")) S("Cobble"))
-- BRICK -- BRICK
-------- --------
technic.cnc.register_all("default:brick", technic_cnc.register_all("default:brick",
{cracky=3, not_in_creative_inventory=1}, {cracky=3, not_in_creative_inventory=1},
{"default_brick.png"}, {"default_brick.png"},
S("Brick")) S("Brick"))
-- SANDSTONE -- SANDSTONE
------------ ------------
technic.cnc.register_all("default:sandstone", technic_cnc.register_all("default:sandstone",
{crumbly=2, cracky=3, not_in_creative_inventory=1}, {crumbly=2, cracky=3, not_in_creative_inventory=1},
{"default_sandstone.png"}, {"default_sandstone.png"},
S("Sandstone")) S("Sandstone"))
-- LEAVES -- LEAVES
--------- ---------
technic.cnc.register_all("default:leaves", technic_cnc.register_all("default:leaves",
{snappy=2, choppy=2, oddly_breakable_by_hand=3, not_in_creative_inventory=1}, {snappy=2, choppy=2, oddly_breakable_by_hand=3, not_in_creative_inventory=1},
{"default_leaves.png"}, {"default_leaves.png"},
S("Leaves")) S("Leaves"))
-- TREE -- TREE
------- -------
technic.cnc.register_all("default:tree", technic_cnc.register_all("default:tree",
{snappy=1, choppy=2, oddly_breakable_by_hand=2, flammable=3, wood=1, not_in_creative_inventory=1}, {snappy=1, choppy=2, oddly_breakable_by_hand=2, flammable=3, wood=1, not_in_creative_inventory=1},
{"default_tree.png"}, {"default_tree.png"},
S("Tree")) S("Tree"))
-- WROUGHT IRON
---------------
technic.cnc.register_all("default:steelblock",
{cracky=1, level=2, not_in_creative_inventory=1},
{"technic_wrought_iron_block.png"},
S("Wrought Iron"))
-- Bronze -- Bronze
-------- --------
technic.cnc.register_all("default:bronzeblock", technic_cnc.register_all("default:bronzeblock",
{cracky=1, level=2, not_in_creative_inventory=1}, {cracky=1, level=2, not_in_creative_inventory=1},
{"default_bronze_block.png"}, {"default_bronze_block.png"},
S("Bronze")) S("Bronze"))
local steeltex = "default_steel_block.png"
local steelname = "Steel"
if technic_cnc.technic_modpath then
steeltex = "technic_wrought_iron_block.png"
steelname = "Wrought Iron"
-- Stainless Steel -- Stainless Steel
-------- --------
technic.cnc.register_all("technic:stainless_steel_block", technic_cnc.register_all("technic:stainless_steel_block",
{cracky=1, level=2, not_in_creative_inventory=1}, {cracky=1, level=2, not_in_creative_inventory=1},
{"technic_stainless_steel_block.png"}, {"technic_stainless_steel_block.png"},
S("Stainless Steel")) S("Stainless Steel"))
-- Marble -- Marble
------------ ------------
technic.cnc.register_all("technic:marble", technic_cnc.register_all("technic:marble",
{cracky=3, not_in_creative_inventory=1}, {cracky=3, not_in_creative_inventory=1},
{"technic_marble.png"}, {"technic_marble.png"},
S("Marble")) S("Marble"))
-- Granite -- Granite
------------ ------------
technic.cnc.register_all("technic:granite", technic_cnc.register_all("technic:granite",
{cracky=1, not_in_creative_inventory=1}, {cracky=1, not_in_creative_inventory=1},
{"technic_granite.png"}, {"technic_granite.png"},
S("Granite")) S("Granite"))
end
-- STEEL
---------------
technic_cnc.register_all("default:steelblock",
{cracky=1, level=2, not_in_creative_inventory=1},
{steeltex},
S(steelname))

View File

@ -1,2 +1,2 @@
default default
technic technic?

View File

@ -2,6 +2,11 @@ local modpath = minetest.get_modpath("technic_cnc")
technic_cnc = {} technic_cnc = {}
technic_cnc.technic_modpath = minetest.get_modpath("technic")
technic_cnc.use_technic = technic_cnc.technic_modpath
and minetest.settings:get_bool("technic_cnc_use_technic") ~= false
if rawget(_G, "intllib") then if rawget(_G, "intllib") then
technic_cnc.getter = intllib.Getter() technic_cnc.getter = intllib.Getter()
else else