Vanessa Ezekowitz
2015-01-17 d6b0deb989e649e2800932d4a587c3ba9e3e24c7
commit | author | age
ee0765 1 -- API for the technic CNC machine
S 2 -- Again code is adapted from the NonCubic Blocks MOD v1.4 by yves_de_beck
3
be2f30 4 local S = technic.getter
S 5
6 technic.cnc = {}
ee0765 7
S 8 -- REGISTER NONCUBIC FORMS, CREATE MODELS AND RECIPES:
9 ------------------------------------------------------
10
11 -- Define slope boxes for the various nodes
12 -------------------------------------------
13 technic.cnc.programs = {
14     {suffix  = "technic_cnc_stick",
80cb6a 15     model = {-0.15, -0.5, -0.15, 0.15, 0.5, 0.15},
be2f30 16     desc    = S("Stick")},
ee0765 17
S 18     {suffix  = "technic_cnc_element_end_double",
80cb6a 19     model = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.5},
be2f30 20     desc    = S("Element End Double")},
ee0765 21
S 22     {suffix  = "technic_cnc_element_cross_double",
80cb6a 23     model = {
ee0765 24         {0.3, -0.5, -0.3, 0.5, 0.5, 0.3},
S 25         {-0.3, -0.5, -0.5, 0.3, 0.5, 0.5},
26         {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}},
be2f30 27     desc    = S("Element Cross Double")},
ee0765 28
S 29     {suffix  = "technic_cnc_element_t_double",
80cb6a 30     model = {
ee0765 31         {-0.3, -0.5, -0.5, 0.3, 0.5, 0.3},
S 32         {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3},
33         {0.3, -0.5, -0.3, 0.5, 0.5, 0.3}},
be2f30 34     desc    = S("Element T Double")},
ee0765 35
S 36     {suffix  = "technic_cnc_element_edge_double",
80cb6a 37     model = {
ee0765 38         {-0.3, -0.5, -0.5, 0.3, 0.5, 0.3},
S 39         {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}},
be2f30 40     desc    = S("Element Edge Double")},
ee0765 41
S 42     {suffix  = "technic_cnc_element_straight_double",
80cb6a 43     model = {-0.3, -0.5, -0.5, 0.3, 0.5, 0.5},
be2f30 44     desc    = S("Element Straight Double")},
ee0765 45
S 46     {suffix  = "technic_cnc_element_end",
80cb6a 47     model = {-0.3, -0.5, -0.3, 0.3, 0, 0.5},
be2f30 48     desc    = S("Element End")},
ee0765 49
S 50     {suffix  = "technic_cnc_element_cross",
80cb6a 51     model = {
ee0765 52         {0.3, -0.5, -0.3, 0.5, 0, 0.3},
S 53         {-0.3, -0.5, -0.5, 0.3, 0, 0.5},
54         {-0.5, -0.5, -0.3, -0.3, 0, 0.3}},
be2f30 55     desc    = S("Element Cross")},
ee0765 56
S 57     {suffix  = "technic_cnc_element_t",
80cb6a 58     model = {
ee0765 59         {-0.3, -0.5, -0.5, 0.3, 0, 0.3},
S 60         {-0.5, -0.5, -0.3, -0.3, 0, 0.3},
61         {0.3, -0.5, -0.3, 0.5, 0, 0.3}},
be2f30 62     desc    = S("Element T")},
ee0765 63
S 64     {suffix  = "technic_cnc_element_edge",
80cb6a 65     model = {
ee0765 66         {-0.3, -0.5, -0.5, 0.3, 0, 0.3},
S 67         {-0.5, -0.5, -0.3, -0.3, 0, 0.3}},
be2f30 68     desc    = S("Element Edge")},
ee0765 69
S 70     {suffix  = "technic_cnc_element_straight",
80cb6a 71     model = {-0.3, -0.5, -0.5, 0.3, 0, 0.5},
be2f30 72     desc    = S("Element Straight")},
ee0765 73
S 74     {suffix  = "technic_cnc_sphere",
80cb6a 75     model = "technic_oblatesphere.obj",
VE 76     desc    = S("Oblate Sphere")},
ee0765 77
S 78     {suffix  = "technic_cnc_cylinder_horizontal",
80cb6a 79     model = "technic_cylinder_horizontal.obj",
be2f30 80     desc    = S("Horizontal Cylinder")},
ee0765 81
S 82     {suffix  = "technic_cnc_cylinder",
80cb6a 83     model = "technic_cylinder.obj",
be2f30 84     desc    = S("Cylinder")},
ee0765 85
S 86     {suffix  = "technic_cnc_twocurvededge",
80cb6a 87     model = "technic_two_curved_edge.obj",
VE 88     desc    = S("Two Curved Edge/Corner Block")},
ee0765 89
S 90     {suffix  = "technic_cnc_onecurvededge",
80cb6a 91     model = "technic_one_curved_edge.obj",
be2f30 92     desc    = S("One Curved Edge Block")},
ee0765 93
S 94     {suffix  = "technic_cnc_spike",
80cb6a 95     model = "technic_pyramid_spike.obj",
be2f30 96     desc    = S("Spike")},
ee0765 97
S 98     {suffix  = "technic_cnc_pyramid",
80cb6a 99     model = "technic_pyramid.obj",
be2f30 100     desc    = S("Pyramid")},
ee0765 101
S 102     {suffix  = "technic_cnc_slope_inner_edge_upsdown",
80cb6a 103     model = "technic_innercorner_upsdown.obj",
VE 104     desc    = S("Slope Upside Down Inner Edge/Corner")},
ee0765 105
S 106     {suffix  = "technic_cnc_slope_edge_upsdown",
80cb6a 107     model = "technic_outercorner_upsdown.obj",
VE 108     desc    = S("Slope Upside Down Outer Edge/Corner")},
ee0765 109
S 110     {suffix  = "technic_cnc_slope_inner_edge",
80cb6a 111     model = "technic_innercorner.obj",
VE 112     desc    = S("Slope Inner Edge/Corner")},
ee0765 113
S 114     {suffix  = "technic_cnc_slope_edge",
80cb6a 115     model = "technic_outercorner.obj",
VE 116     desc    = S("Slope Outer Edge/Corner")},
ee0765 117
S 118     {suffix  = "technic_cnc_slope_upsdown",
80cb6a 119     model = "technic_slope_upsdown.obj",
be2f30 120     desc    = S("Slope Upside Down")},
ee0765 121
S 122     {suffix  = "technic_cnc_slope_lying",
80cb6a 123     model = "technic_slope_horizontal.obj",
be2f30 124     desc    = S("Slope Lying")},
ee0765 125
S 126     {suffix  = "technic_cnc_slope",
80cb6a 127     model = "technic_slope.obj",
be2f30 128     desc    = S("Slope")},
ee0765 129 }
S 130
131 -- Allow disabling certain programs for some node. Default is allowing all types for all nodes
132 technic.cnc.programs_disable = {
133     -- ["default:brick"] = {"technic_cnc_stick"}, -- Example: Disallow the stick for brick
134     -- ...
135     ["default:dirt"] = {"technic_cnc_sphere", "technic_cnc_slope_upsdown", "technic_cnc_edge",
136                         "technic_cnc_inner_edge", "technic_cnc_slope_edge_upsdown",
137                         "technic_cnc_slope_inner_edge_upsdown", "technic_cnc_stick",
138                         "technic_cnc_cylinder_horizontal"}
139 }
140
141 -- Generic function for registering all the different node types
80cb6a 142 function technic.cnc.register_program(recipeitem, suffix, model, groups, images, description)
VE 143
144     local dtype
145     local nodeboxdef
146     local meshdef
147
148     if type(model) ~= "string" then -- assume a nodebox if it's a table or function call
149         dtype = "nodebox"
150         nodeboxdef = {
151             type  = "fixed",
152             fixed = model
153         }
154     else
155         dtype = "mesh"
156         meshdef = model
157     end
158
ee0765 159     minetest.register_node(":"..recipeitem.."_"..suffix, {
S 160         description   = description,
80cb6a 161         drawtype      = dtype,
VE 162         node_box      = nodeboxdef,
163         mesh          = meshdef,
ee0765 164         tiles         = images,
S 165         paramtype     = "light",
166         paramtype2    = "facedir",
167         walkable      = true,
168         groups        = groups,
169     })
170 end
171
172 -- function to iterate over all the programs the CNC machine knows
173 function technic.cnc.register_all(recipeitem, groups, images, description)
174     for _, data in ipairs(technic.cnc.programs) do
175         -- Disable node creation for disabled node types for some material
176         local do_register = true
177         if technic.cnc.programs_disable[recipeitem] ~= nil then
178             for __, disable in ipairs(technic.cnc.programs_disable[recipeitem]) do
179                 if disable == data.suffix then
180                     do_register = false
181                 end
182             end
183         end
184         -- Create the node if it passes the test
185         if do_register then
80cb6a 186             technic.cnc.register_program(recipeitem, data.suffix, data.model, groups, images, description.." "..data.desc)
ee0765 187         end
S 188     end
189 end
190
191
192 -- REGISTER NEW TECHNIC_CNC_API's PART 2: technic.cnc..register_element_end(subname, recipeitem, groups, images, desc_element_xyz)
193 -----------------------------------------------------------------------------------------------------------------------
194 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_sphere, desc_element_straight, desc_element_edge, desc_element_t, desc_element_cross, desc_element_end)
195
196          technic.cnc.register_slope(recipeitem, groups, images, desc_slope)
197          technic.cnc.register_slope_lying(recipeitem, groups, images, desc_slope_lying)
198          technic.cnc.register_slope_upsdown(recipeitem, groups, images, desc_slope_upsdown)
199          technic.cnc.register_slope_edge(recipeitem, groups, images, desc_slope_edge)
200          technic.cnc.register_slope_inner_edge(recipeitem, groups, images, desc_slope_inner_edge)
201          technic.cnc.register_slope_edge_upsdown(recipeitem, groups, images, desc_slope_upsdwn_edge)
202          technic.cnc.register_slope_inner_edge_upsdown(recipeitem, groups, images, desc_slope_upsdwn_inner_edge)
203          technic.cnc.register_pyramid(recipeitem, groups, images, desc_pyramid)
204          technic.cnc.register_spike(recipeitem, groups, images, desc_spike)
205          technic.cnc.register_onecurvededge(recipeitem, groups, images, desc_onecurvededge)
206          technic.cnc.register_twocurvededge(recipeitem, groups, images, desc_twocurvededge)
207          technic.cnc.register_cylinder(recipeitem, groups, images, desc_cylinder)
208          technic.cnc.register_cylinder_horizontal(recipeitem, groups, images, desc_cylinder_horizontal)
209          technic.cnc.register_sphere(recipeitem, groups, images, desc_sphere)
210          technic.cnc.register_element_straight(recipeitem, groups, images, desc_element_straight)
211          technic.cnc.register_element_edge(recipeitem, groups, images, desc_element_edge)
212          technic.cnc.register_element_t(recipeitem, groups, images, desc_element_t)
213          technic.cnc.register_element_cross(recipeitem, groups, images, desc_element_cross)
214          technic.cnc.register_element_end(recipeitem, groups, images, desc_element_end)
215 end
216
217 -- REGISTER STICKS: noncubic.register_xyz(recipeitem, groups, images, desc_element_xyz)
218 ------------------------------------------------------------------------------------------------------------
219 function technic.cnc.register_stick_etc(recipeitem, groups, images, desc_stick)
220          technic.cnc.register_stick(recipeitem, groups, images, desc_stick)
221 end
222
223 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)
224          technic.cnc.register_element_straight_double(recipeitem, groups, images, desc_element_straight_double)
225          technic.cnc.register_element_edge_double(recipeitem, groups, images, desc_element_edge_double)
226          technic.cnc.register_element_t_double(recipeitem, groups, images, desc_element_t_double)
227          technic.cnc.register_element_cross_double(recipeitem, groups, images, desc_element_cross_double)
228          technic.cnc.register_element_end_double(recipeitem, groups, images, desc_element_end_double)
229 end
230