kpoppel
2013-07-02 053fa59739f4b772174bf0a090969b3395ab3f98
commit | author | age
ee5c6c 1 technic.grinder_recipes ={}
82cba9 2
ee5c6c 3 technic.register_grinder_recipe = function(src, dst)
K 4                    technic.grinder_recipes[src] = dst
5                    if unified_inventory then
6                       unified_inventory.register_craft(
7                      {
8                         type = "grinding",
9                         output = dst,
10                         items = {src},
11                         width = 0,
12                      })
13                    end
14                 end
82cba9 15
ee5c6c 16 -- Receive an ItemStack of result by an ItemStack input
K 17 technic.get_grinder_recipe = function(itemstack)
18                 local src_item  = itemstack:to_table()
19                 if src_item == nil then
20                    return nil
21                 end
22                 local item_name = src_item["name"]
23                 if technic.grinder_recipes[item_name] then
24                    return ItemStack(technic.grinder_recipes[item_name])
25                 else
26                    return nil
27                 end
28                  end
82cba9 29
ee5c6c 30
K 31 technic.register_grinder_recipe("default:stone","default:sand")
32 technic.register_grinder_recipe("default:cobble","default:gravel")
33 technic.register_grinder_recipe("default:gravel","default:dirt")
34 technic.register_grinder_recipe("default:desert_stone","default:desert_sand")
35 technic.register_grinder_recipe("default:iron_lump","technic:iron_dust 2")
36 technic.register_grinder_recipe("default:steel_ingot","technic:iron_dust 1")
37 technic.register_grinder_recipe("default:coal_lump","technic:coal_dust 2")
38 technic.register_grinder_recipe("default:copper_lump","technic:copper_dust 2")
39 technic.register_grinder_recipe("default:copper_ingot","technic:copper_dust 1")
40 technic.register_grinder_recipe("default:gold_lump","technic:gold_dust 2")
41 technic.register_grinder_recipe("default:gold_ingot","technic:gold_dust 1")
42 --technic.register_grinder_recipe("default:bronze_ingot","technic:bronze_dust 1")  -- Dust does not exist yet
43 --technic.register_grinder_recipe("home_decor:brass_ingot","technic:brass_dust 1") -- needs check for the mod
44 technic.register_grinder_recipe("moreores:tin_lump","technic:tin_dust 2")
45 technic.register_grinder_recipe("moreores:tin_ingot","technic:tin_dust 1")
46 technic.register_grinder_recipe("moreores:silver_lump","technic:silver_dust 2")
47 technic.register_grinder_recipe("moreores:silver_ingot","technic:silver_dust 1")
48 technic.register_grinder_recipe("moreores:mithril_lump","technic:mithril_dust 2")
49 technic.register_grinder_recipe("moreores:mithril_ingot","technic:mithril_dust 1")
50 technic.register_grinder_recipe("technic:chromium_lump","technic:chromium_dust 2")
51 technic.register_grinder_recipe("technic:chromium_ingot","technic:chromium_dust 1")
52 technic.register_grinder_recipe("technic:stainless_steel_ingot","stainless_steel_dust 1")
53 technic.register_grinder_recipe("technic:brass_ingot","technic:brass_dust 1")
54 technic.register_grinder_recipe("technic:zinc_lump","technic:zinc_dust 2")
55 technic.register_grinder_recipe("technic:zinc_ingot","technic:zinc_dust 1")
56 technic.register_grinder_recipe("technic:coal_dust","dye:black 2")
57 technic.register_grinder_recipe("default:cactus","dye:green 2")
58 technic.register_grinder_recipe("default:dry_shrub","dye:brown 2")
59 technic.register_grinder_recipe("flowers:flower_geranium","dye:blue 2")
60 technic.register_grinder_recipe("flowers:flower_dandelion_white","dye:white 2")
61 technic.register_grinder_recipe("flowers:flower_dandelion_yellow","dye:yellow 2")
62 technic.register_grinder_recipe("flowers:flower_tulip","dye:orange 2")
63 technic.register_grinder_recipe("flowers:flower_rose","dye:red 2")
64 technic.register_grinder_recipe("flowers:flower_viola","dye:violet 2")
82cba9 65
R 66 minetest.register_craftitem( "technic:coal_dust", {
ee5c6c 67                 description = "Coal Dust",
K 68                 inventory_image = "technic_coal_dust.png",
69                 on_place_on_ground = minetest.craftitem_place_item,
70                  })
82cba9 71
R 72 minetest.register_craftitem( "technic:iron_dust", {
ee5c6c 73                 description = "Iron Dust",
K 74                 inventory_image = "technic_iron_dust.png",
75                 on_place_on_ground = minetest.craftitem_place_item,
76                  })
82cba9 77
R 78 minetest.register_craft({
ee5c6c 79                type = "cooking",
K 80                output = "default:steel_ingot",
81                recipe = "technic:iron_dust",
82             })
82cba9 83
R 84 minetest.register_craftitem( "technic:copper_dust", {
ee5c6c 85                 description = "Copper Dust",
K 86                 inventory_image = "technic_copper_dust.png",
87                 on_place_on_ground = minetest.craftitem_place_item,
88                  })
82cba9 89 minetest.register_craft({
ee5c6c 90                type = "cooking",
K 91                output = "moreores:copper_ingot",
92                recipe = "technic:copper_dust",
93             })
82cba9 94
R 95 minetest.register_craftitem( "technic:tin_dust", {
ee5c6c 96                 description = "Tin Dust",
K 97                 inventory_image = "technic_tin_dust.png",
98                 on_place_on_ground = minetest.craftitem_place_item,
99                  })
82cba9 100 minetest.register_craft({
ee5c6c 101                type = "cooking",
K 102                output = "moreores:tin_ingot",
103                recipe = "technic:tin_dust",
104             })
82cba9 105
R 106 minetest.register_craftitem( "technic:silver_dust", {
ee5c6c 107                 description = "Silver Dust",
K 108                 inventory_image = "technic_silver_dust.png",
109                 on_place_on_ground = minetest.craftitem_place_item,
110                  })
82cba9 111 minetest.register_craft({
ee5c6c 112                type = "cooking",
K 113                output = "moreores:silver_ingot",
114                recipe = "technic:silver_dust",
115             })
82cba9 116
R 117 minetest.register_craftitem( "technic:gold_dust", {
ee5c6c 118                 description = "Gold Dust",
K 119                 inventory_image = "technic_gold_dust.png",
120                 on_place_on_ground = minetest.craftitem_place_item,
121                  })
82cba9 122 minetest.register_craft({
ee5c6c 123                type = "cooking",
K 124                output = "moreores:gold_ingot",
125                recipe = "technic:gold_dust",
126             })
82cba9 127
R 128 minetest.register_craftitem( "technic:mithril_dust", {
ee5c6c 129                 description = "Mithril Dust",
K 130                 inventory_image = "technic_mithril_dust.png",
131                 on_place_on_ground = minetest.craftitem_place_item,
132                  })
82cba9 133 minetest.register_craft({
ee5c6c 134                type = "cooking",
K 135                output = "moreores:mithril_ingot",
136                recipe = "technic:mithril_dust",
137             })
82cba9 138
R 139 minetest.register_craftitem( "technic:chromium_dust", {
ee5c6c 140                 description = "Chromium Dust",
K 141                 inventory_image = "technic_chromium_dust.png",
142                 on_place_on_ground = minetest.craftitem_place_item,
143                  })
82cba9 144 minetest.register_craft({
ee5c6c 145                type = "cooking",
K 146                output = "technic:chromium_ingot",
147                recipe = "technic:chromium_dust",
148             })
82cba9 149
R 150 minetest.register_craftitem( "technic:bronze_dust", {
ee5c6c 151                 description = "Bronze Dust",
K 152                 inventory_image = "technic_bronze_dust.png",
153                 on_place_on_ground = minetest.craftitem_place_item,
154                  })
82cba9 155 minetest.register_craft({
ee5c6c 156                type = "cooking",
K 157                output = "moreores:bronze_ingot",
158                recipe = "technic:bronze_dust",
159             })
82cba9 160
R 161 minetest.register_craftitem( "technic:brass_dust", {
ee5c6c 162                 description = "Brass Dust",
K 163                 inventory_image = "technic_brass_dust.png",
164                 on_place_on_ground = minetest.craftitem_place_item,
165                  })
82cba9 166 minetest.register_craft({
ee5c6c 167                type = "cooking",
K 168                output = "technic:brass_ingot",
169                recipe = "technic:brass_dust",
170             })
82cba9 171
R 172 minetest.register_craftitem( "technic:stainless_steel_dust", {
ee5c6c 173                 description = "Stainless Steel Dust",
K 174                 inventory_image = "technic_stainless_steel_dust.png",
175                  })
82cba9 176
R 177 minetest.register_craft({
ee5c6c 178                type = "cooking",
K 179                output = "technic:stainless_steel_ingot",
180                recipe = "technic:stainless_steel_dust",
181             })
82cba9 182
R 183 minetest.register_craftitem( "technic:zinc_dust", {
ee5c6c 184                 description = "Zinc Dust",
K 185                 inventory_image = "technic_zinc_dust.png",
186                  })
82cba9 187
R 188 minetest.register_craft({
ee5c6c 189                type = "cooking",
K 190                output = "technic:zinc_ingot",
191                recipe = "technic:zinc_dust",
192             })
82cba9 193
R 194 minetest.register_alias("grinder", "technic:grinder")
195 minetest.register_craft({
ee5c6c 196                output = 'technic:grinder',
K 197                recipe = {
198                   {'default:desert_stone', 'default:desert_stone', 'default:desert_stone'},
199                   {'default:desert_stone', 'default:diamond', 'default:desert_stone'},
200                   {'default:stone', 'moreores:copper_ingot', 'default:stone'},
201                }
202             })
82cba9 203
R 204 minetest.register_craftitem("technic:grinder", {
ee5c6c 205                    description = "Grinder",
K 206                    stack_max = 99,
207                 })
82cba9 208
ee5c6c 209 local grinder_formspec =
K 210    "invsize[8,9;]"..
211    "label[0,0;Grinder]"..
212    "list[current_name;src;3,1;1,1;]"..
213    "list[current_name;dst;5,1;2,2;]"..
214    "list[current_player;main;0,5;8,4;]"
612349 215
ee5c6c 216 minetest.register_node(
K 217    "technic:grinder",
218    {
219       description = "Grinder",
220       tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", "technic_lv_grinder_side.png",
221            "technic_lv_grinder_side.png", "technic_lv_grinder_side.png", "technic_lv_grinder_front.png"},
222       paramtype2 = "facedir",
223       groups = {cracky=2},
224       legacy_facedir_simple = true,
225       sounds = default.node_sound_wood_defaults(),
226       on_construct = function(pos)
227             local meta = minetest.env:get_meta(pos)
228             meta:set_string("infotext", "Grinder")
229             meta:set_float("technic_power_machine", 1)
230             meta:set_string("formspec", grinder_formspec)
231             local inv = meta:get_inventory()
232             inv:set_size("src", 1)
233             inv:set_size("dst", 4)
234              end,
235       can_dig = function(pos,player)
236            local meta = minetest.env:get_meta(pos);
237            local inv = meta:get_inventory()
238            if not inv:is_empty("src") or not inv:is_empty("dst") then
239               minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
240               return false
241            else
242               return true
243            end
612349 244         end,
ee5c6c 245    })
K 246
247 minetest.register_node(
248    "technic:grinder_active",
249    {
250       description = "Grinder",
251       tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", "technic_lv_grinder_side.png",
252            "technic_lv_grinder_side.png", "technic_lv_grinder_side.png", "technic_lv_grinder_front_active.png"},
253       paramtype2 = "facedir",
254       groups = {cracky=2,not_in_creative_inventory=1},
255       legacy_facedir_simple = true,
256       sounds = default.node_sound_wood_defaults(),
257       can_dig = function(pos,player)
258            local meta = minetest.env:get_meta(pos);
259            local inv = meta:get_inventory()
260            if not inv:is_empty("src") or not inv:is_empty("dst") then
261               minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
262               return false
263            else
264               return true
265            end
82cba9 266         end,
ee5c6c 267    })
82cba9 268
ee5c6c 269 minetest.register_abm(
K 270    { nodenames = {"technic:grinder","technic:grinder_active"},
271      interval = 1,
272      chance   = 1,
273      action = function(pos, node, active_object_count, active_object_count_wider)
274          -- Run a machine through its states. Takes the same arguments as the ABM action
275          -- and adds the machine's states and any extra data which is needed by the machine.
276          -- A machine is characterized by running through a set number of states (usually 2:
277          -- Idle and active) in some order. A state decides when to move to the next one
278          -- and the machine only changes state if it is powered correctly.
279          -- The machine will automatically shut down if disconnected from power in some fashion.
280          local meta         = minetest.env:get_meta(pos)
281          local eu_input     = meta:get_int("LV_EU_input")
282          local state        = meta:get_int("state")
283          local next_state   = state
82cba9 284
ee5c6c 285          -- Machine information
K 286          local machine_name         = "Grinder"
287          local machine_node         = "technic:grinder"
288          local machine_state_demand = { 50, 300 }
289              
290          -- Setup meta data if it does not exist. state is used as an indicator of this
291          if state == 0 then
292             meta:set_int("state", 1)
293             meta:set_int("LV_EU_demand", machine_state_demand[1])
294             meta:set_int("LV_EU_input", 0)
295             return
296          end
297              
298          -- Power off automatically if no longer connected to a switching station
299          technic.switching_station_timeout_count(pos, "LV")
300              
301          -- State machine
302          if eu_input == 0 then
303             -- unpowered - go idle
304             hacky_swap_node(pos, machine_node)
305             meta:set_string("infotext", machine_name.." Unpowered")
306             next_state = 1
307          elseif eu_input == machine_state_demand[state] then
308             -- Powered - do the state specific actions
309                 
310             local inv    = meta:get_inventory()
311             local empty  = inv:is_empty("src")
82cba9 312
ee5c6c 313             if state == 1 then
K 314                hacky_swap_node(pos, machine_node)
315                meta:set_string("infotext", machine_name.." Idle")
82cba9 316
ee5c6c 317                local result = technic.get_grinder_recipe(inv:get_stack("src", 1))
K 318                if not empty and result and inv:room_for_item("dst",result) then
319               meta:set_int("src_time", 0)
320               next_state = 2
321                end
612349 322
ee5c6c 323             elseif state == 2 then
K 324                hacky_swap_node(pos, machine_node.."_active")
325                meta:set_string("infotext", machine_name.." Active")
612349 326
ee5c6c 327                if empty then
K 328               next_state = 1
329                else
330               meta:set_int("src_time", meta:get_int("src_time") + 1)
331               if meta:get_int("src_time") == 4 then -- 4 ticks per output
332                  -- check if there's room for output in "dst" list
333                  local result = technic.get_grinder_recipe(inv:get_stack("src", 1))
82cba9 334
ee5c6c 335                  meta:set_int("src_time", 0)
K 336                  if inv:room_for_item("dst",result) then
337                 -- take stuff from "src" list
338                 srcstack = inv:get_stack("src", 1)
339                 srcstack:take_item()
340                 inv:set_stack("src", 1, srcstack)
341                 -- Put result in "dst" list
342                 inv:add_item("dst", result)
343                  else
344                 -- all full: go idle
345                 next_state = 1
346                  end
347               end
348                end
349             end
350          end
351          -- Change state?
352          if next_state ~= state then
353             meta:set_int("LV_EU_demand", machine_state_demand[next_state])
354             meta:set_int("state", next_state)
355          end
356           end
357   })
82cba9 358
ee5c6c 359 technic.register_LV_machine ("technic:grinder","RE")
K 360 technic.register_LV_machine ("technic:grinder_active","RE")