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