From a9c2b29ab3df9b69e5a7aaf888762292028ead16 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Wed, 14 Jun 2017 22:48:03 +0200 Subject: [PATCH] recipe added --- hammer.lua | 18 ++-- init.lua | 263 ++++++++++++++++++++++++++++------------------------- 2 files changed, 148 insertions(+), 133 deletions(-) diff --git a/hammer.lua b/hammer.lua index f438419..c6564d0 100644 --- a/hammer.lua +++ b/hammer.lua @@ -4,11 +4,11 @@ ================ v0.01 by JoSt - Derived from the work of RealBadAngel, Maciej Kasatkin (screwdriver) + Derived from the work of RealBadAngel, Maciej Kasatkin (screwdriver) Copyright (C) 2017 Joachim Stolberg - Copyright (C) 2013-2016 RealBadAngel, Maciej Kasatkin - Copyright (C) 2013-2016 Various Minetest developers and contributors + Copyright (C) 2013-2016 RealBadAngel, Maciej Kasatkin + Copyright (C) 2013-2016 Various Minetest developers and contributors LGPLv2.1+ See LICENSE.txt for more information @@ -35,12 +35,12 @@ gravelsieve.handler = function(itemstack, user, pointed_thing) local node = minetest.get_node(pos) if node.name == "default:cobble" then node.name = "default:gravel" - minetest.swap_node(pos, node) - minetest.sound_play({ - name="default_dig_crumbly"},{ - gain=1, - max_hear_distance=20, - loop=false}) + minetest.swap_node(pos, node) + minetest.sound_play({ + name="default_dig_crumbly"},{ + gain=1, + max_hear_distance=20, + loop=false}) end return itemstack diff --git a/init.lua b/init.lua index a9988f2..36349bd 100644 --- a/init.lua +++ b/init.lua @@ -4,11 +4,11 @@ ================ v0.01 by JoSt - Derived from the work of celeron55, Perttu Ahola (furnace) + Derived from the work of celeron55, Perttu Ahola (furnace) Copyright (C) 2017 Joachim Stolberg - Copyright (C) 2011-2016 celeron55, Perttu Ahola - Copyright (C) 2011-2016 Various Minetest developers and contributors + Copyright (C) 2011-2016 celeron55, Perttu Ahola + Copyright (C) 2011-2016 Various Minetest developers and contributors LGPLv2.1+ See LICENSE.txt for more information @@ -19,7 +19,7 @@ ]]-- gravelsieve = { - rand = PseudoRandom(1234) + rand = PseudoRandom(1234) } dofile(minetest.get_modpath("gravelsieve") .. "/hammer.lua") @@ -27,21 +27,21 @@ dofile(minetest.get_modpath("gravelsieve") .. "/hammer.lua") -- Ore probability table (1/n) local sieve_table = { - iron_lump = 15, - copper_lump = 15, - tin_lump = 15, - gold_lump = 25, - mese_crystal = 25, - diamond = 50, + iron_lump = 15, + copper_lump = 15, + tin_lump = 15, + gold_lump = 25, + mese_crystal = 25, + diamond = 50, } local sieve_formspec = - "size[8,8]".. - "list[context;src;1,1;1,1;]".. - "image[3,1;1,1;gui_furnace_arrow_bg.png^[transformR270]".. - "list[context;dst;4,0;4,3;]".. - "list[current_player;main;0,4;8,4;]" + "size[8,8]".. + "list[context;src;1,1;1,1;]".. + "image[3,1;1,1;gui_furnace_arrow_bg.png^[transformR270]".. + "list[context;dst;4,0;4,3;]".. + "list[current_player;main;0,4;8,4;]" local function can_dig(pos, player) local meta = minetest.get_meta(pos); @@ -79,139 +79,142 @@ end local function swap_node(pos, meta) local node = minetest.get_node(pos) - local idx = meta:get_int("idx") - idx = (idx + 1) % 4 - meta:set_int("idx", idx) - node.name = "gravelsieve:sieve"..idx + local idx = meta:get_int("idx") + idx = (idx + 1) % 4 + meta:set_int("idx", idx) + node.name = "gravelsieve:sieve"..idx minetest.swap_node(pos, node) - return idx == 3 + return idx == 3 end local function random_ore(inv, src) - local num - local result = false - for ore, probability in pairs(sieve_table) do - if src:get_name() == "gravelsieve:gravel1" then - probability = probability * 2 - elseif src:get_name() == "gravelsieve:gravel2" then - probability = probability * 4 - elseif src:get_name() == "gravelsieve:gravel3" then - probability = probability * 8 - end - num = gravelsieve.rand:next(0, probability) - if num == probability then - item = ItemStack("default:"..ore) - if inv:room_for_item("dst", item) then - inv:add_item("dst", item) - return true - end - end - end - return result + local num + local result = false + for ore, probability in pairs(sieve_table) do + if src:get_name() == "gravelsieve:gravel1" then + probability = probability * 2 + elseif src:get_name() == "gravelsieve:gravel2" then + probability = probability * 4 + elseif src:get_name() == "gravelsieve:gravel3" then + probability = probability * 8 + end + num = gravelsieve.rand:next(0, probability) + if num == probability then + item = ItemStack("default:"..ore) + if inv:room_for_item("dst", item) then + inv:add_item("dst", item) + return true + end + end + end + return result end - + local function move_src2dst(meta, pos, inv, src, dst) - if inv:room_for_item("dst", dst) and inv:contains_item("src", src) then - local res = swap_node(pos, meta) - if res then - if not random_ore(inv, src) then - inv:add_item("dst", dst) - end - inv:remove_item("src", src) - end - return true - end - return false + if inv:room_for_item("dst", dst) and inv:contains_item("src", src) then + local res = swap_node(pos, meta) + if res then + if not random_ore(inv, src) then + inv:add_item("dst", dst) + end + inv:remove_item("src", src) + end + return true + end + return false end local function sieve_node_timer(pos, elapsed) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - local gravel = ItemStack("default:gravel") - local gravel1 = ItemStack("gravelsieve:gravel1") - local gravel2 = ItemStack("gravelsieve:gravel2") - local gravel3 = ItemStack("gravelsieve:gravel3") + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local gravel = ItemStack("default:gravel") + local gravel1 = ItemStack("gravelsieve:gravel1") + local gravel2 = ItemStack("gravelsieve:gravel2") + local gravel3 = ItemStack("gravelsieve:gravel3") - if move_src2dst(meta, pos, inv, gravel, gravel1) then - return true - elseif move_src2dst(meta, pos, inv, gravel1, gravel2) then - return true - elseif move_src2dst(meta, pos, inv, gravel2, gravel3) then - return true - else - minetest.get_node_timer(pos):stop() - return false - end + if move_src2dst(meta, pos, inv, gravel, gravel1) then + return true + elseif move_src2dst(meta, pos, inv, gravel1, gravel2) then + return true + elseif move_src2dst(meta, pos, inv, gravel2, gravel3) then + return true + else + minetest.get_node_timer(pos):stop() + return false + end end for idx = 0,4 do - local nodebox_data = { - { -8/16, -8/16, -8/16, 8/16, 4/16, -6/16 }, - { -8/16, -8/16, 6/16, 8/16, 4/16, 8/16 }, - { -8/16, -8/16, -8/16, -6/16, 4/16, 8/16 }, - { 6/16, -8/16, -8/16, 8/16, 4/16, 8/16 }, - { -6/16, -2/16, -6/16, 6/16, 8/16, 6/16 }, - } - nodebox_data[5][5] = (8 - 2*idx) / 16 + local nodebox_data = { + { -8/16, -8/16, -8/16, 8/16, 4/16, -6/16 }, + { -8/16, -8/16, 6/16, 8/16, 4/16, 8/16 }, + { -8/16, -8/16, -8/16, -6/16, 4/16, 8/16 }, + { 6/16, -8/16, -8/16, 8/16, 4/16, 8/16 }, + { -6/16, -2/16, -6/16, 6/16, 8/16, 6/16 }, + } + nodebox_data[5][5] = (8 - 2*idx) / 16 - local tiles_data = { - -- up, down, right, left, back, front - "gravelsieve_gravel.png", - "gravelsieve_gravel.png", - "gravelsieve_sieve.png", - "gravelsieve_sieve.png", - "gravelsieve_sieve.png", - "gravelsieve_sieve.png", - } - if idx == 3 then - tiles_data[1] = "gravelsieve_top.png" - end - - minetest.register_node("gravelsieve:sieve"..idx, { - description = "Gravel Sieve "..idx, - tiles = tiles_data, - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = nodebox_data, - }, + local tiles_data = { + -- up, down, right, left, back, front + "gravelsieve_gravel.png", + "gravelsieve_gravel.png", + "gravelsieve_sieve.png", + "gravelsieve_sieve.png", + "gravelsieve_sieve.png", + "gravelsieve_sieve.png", + } + if idx == 3 then + tiles_data[1] = "gravelsieve_top.png" + not_in_creative_inventory = 0 + else + not_in_creative_inventory = 1 + end + + minetest.register_node("gravelsieve:sieve"..idx, { + description = "Gravel Sieve", + tiles = tiles_data, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = nodebox_data, + }, - can_dig = can_dig, - on_timer = sieve_node_timer, + can_dig = can_dig, + on_timer = sieve_node_timer, - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_int("idx", idx) - meta:set_string("formspec", sieve_formspec) - local inv = meta:get_inventory() - inv:set_size('src', 1) - inv:set_size('dst', 12) - end, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_int("idx", idx) + meta:set_string("formspec", sieve_formspec) + local inv = meta:get_inventory() + inv:set_size('src', 1) + inv:set_size('dst', 12) + end, - on_metadata_inventory_move = function(pos) - minetest.get_node_timer(pos):start(1.0) - end, + on_metadata_inventory_move = function(pos) + minetest.get_node_timer(pos):start(1.0) + end, - on_metadata_inventory_take = function(pos) - minetest.get_node_timer(pos):start(1.0) - end, + on_metadata_inventory_take = function(pos) + minetest.get_node_timer(pos):start(1.0) + end, - on_metadata_inventory_put = function(pos) - minetest.get_node_timer(pos):start(1.0) - end, + on_metadata_inventory_put = function(pos) + minetest.get_node_timer(pos):start(1.0) + end, - allow_metadata_inventory_put = allow_metadata_inventory_put, - allow_metadata_inventory_move = allow_metadata_inventory_move, - allow_metadata_inventory_take = allow_metadata_inventory_take, + allow_metadata_inventory_put = allow_metadata_inventory_put, + allow_metadata_inventory_move = allow_metadata_inventory_move, + allow_metadata_inventory_take = allow_metadata_inventory_take, - paramtype2 = "facedir", - sunlight_propagates = true, - is_ground_content = false, - groups = {cracky=3, stone=1, uber=1}, - }) + paramtype2 = "facedir", + sunlight_propagates = true, + is_ground_content = false, + groups = {cracky=3, stone=1, uber=1, not_in_creative_inventory=not_in_creative_inventory}, + }) end minetest.register_node("gravelsieve:gravel1", { @@ -255,3 +258,15 @@ minetest.register_node("gravelsieve:gravel3", { } } }) + +minetest.register_craft({ + output = "gravelsieve:sieve", + recipe = { + {"group:wood", "", "group:wood"}, + {"group:wood", "default:steel_ingot", "group:wood"}, + {"group:wood", "", "group:wood"}, + }, +}) + +minetest.register_alias("gravelsieve:sieve", "gravelsieve:sieve3") +