Add a manual grindstone

This commit is contained in:
Evert Prants 2018-06-24 16:45:21 +03:00
parent e14838deeb
commit 96591d3bde
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
7 changed files with 178 additions and 2 deletions

View File

@ -227,6 +227,10 @@ minetest.register_craft({
"elepower_dynamics:viridisium_dust",
"elepower_dynamics:viridisium_dust",
"elepower_dynamics:viridisium_dust",
"elepower_dynamics:copper_dust",
"elepower_dynamics:copper_dust",
"elepower_dynamics:copper_dust",
"elepower_dynamics:copper_dust",
"farming:seed_wheat",
}
})

View File

@ -86,9 +86,13 @@ end
function elefluid.transfer_timer_tick(pos, elapsed)
local refresh = true
local node = minetest.get_node_or_nil(pos)
if not node then
return false
end
local meta = minetest.get_meta(pos)
local node = minetest.get_node(pos)
local meta1 = nil
local targets = {}
-- Only allow the node directly behind to be a start of a network

View File

@ -123,6 +123,19 @@ minetest.register_craft({
}
})
-- Grindstone
minetest.register_craft({
output = "elepower_machines:grindstone",
recipe = {
{"group:stone", "group:stone", "group:stone"},
{"default:flint", "default:flint", "default:flint"},
{"group:cobble", "group:cobble", "group:cobble"},
},
replacements = {
{"bucket:bucket_lava", "bucket:bucket_empty"}
}
})
-- Machine block
minetest.register_craft({
output = "elepower_machines:machine_block",

View File

@ -88,3 +88,21 @@ function elepm.get_coal_alloy_furnace_formspec(fuel_percent, item_percent)
"listring[current_player;main]"..
default.get_hotbar_bg(0, 4.25)
end
function elepm.get_grindstone_formspec(item_percent)
return "size[8,8.5]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[context;src;1.6,1;1,1;]"..
"image[3.5,1;1,1;gui_furnace_arrow_bg.png^[lowpart:"..
(item_percent)..":gui_furnace_arrow_fg.png^[transformR270]"..
"list[context;dst;4.5,1;2,1;]"..
"list[current_player;main;0,4.25;8,1;]"..
"list[current_player;main;0,5.5;8,3;8]"..
"listring[context;dst]"..
"listring[current_player;main]"..
"listring[context;src]"..
"listring[current_player;main]"..
default.get_hotbar_bg(0, 4.25)
end

View File

@ -0,0 +1,136 @@
local function can_dig(pos, player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("dst") and inv:is_empty("src")
end
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) or listname == "dst" then
return 0
end
return stack:get_count()
end
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stack = inv:get_stack(from_list, from_index)
return allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
end
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return stack:get_count()
end
local function metadata_inventory_changed(pos)
local t = minetest.get_node_timer(pos)
if not t:is_started() then
t:start(0.2)
end
end
local function grindstone_timer(pos, elapsed)
local refresh = false
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local recipe = elepm.get_recipe("grind", inv:get_list("src"))
if not recipe or recipe.time == 0 then
meta:set_int("src_time", 0)
meta:set_int("src_time_max", 0)
meta:set_string("formspec", elepm.get_grindstone_formspec(0))
meta:set_string("infotext", "No recipe")
return
end
local target_time = ele.helpers.round(recipe.time * 18)
local time = meta:get_int("src_time")
if time >= target_time then
local output = recipe.output
if type(output) ~= "table" then output = { output } end
local output_stacks = {}
for _, o in ipairs(output) do
table.insert(output_stacks, ItemStack(o))
end
local room_for_output = true
inv:set_size("dst_tmp", inv:get_size("dst"))
inv:set_list("dst_tmp", inv:get_list("dst"))
for _, o in ipairs(output_stacks) do
if not inv:room_for_item("dst_tmp", o) then
room_for_output = false
break
end
inv:add_item("dst_tmp", o)
end
if not room_for_output then
time = target_time - 1
else
inv:set_list("src", recipe.new_input)
inv:set_list("dst", inv:get_list("dst_tmp"))
time = 0
end
refresh = true
end
local percentile = math.floor(100 * time / target_time)
meta:set_string("formspec", elepm.get_grindstone_formspec(percentile))
meta:set_int("src_time", time)
meta:set_int("src_time_max", target_time)
meta:set_string("infotext", "Grindstone: ".. percentile .. "%")
return refresh
end
ele.register_base_device("elepower_machines:grindstone", {
description = "Grindstone\nA medieval pulverizer",
tiles = {
"elepower_cfalloy_top.png", "elepower_cfalloy_bottom.png", "elepower_grinder_side.png",
"elepower_grinder_side.png", "elepower_grinder_side.png", "elepower_grinder_side.png"
},
on_construct = function (pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size("src", 1)
inv:set_size("dst", 2)
meta:set_string("formspec", elepm.get_grindstone_formspec(0))
end,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = allow_metadata_inventory_take,
allow_metadata_inventory_move = allow_metadata_inventory_move,
on_metadata_inventory_move = metadata_inventory_changed,
on_metadata_inventory_take = metadata_inventory_changed,
on_metadata_inventory_put = metadata_inventory_changed,
can_dig = can_dig,
on_timer = grindstone_timer,
groups = {
tubedevice = 1,
cracky = 2,
},
on_punch = function (pos, node, puncher, pointed_thing)
local meta = minetest.get_meta(pos)
local stime = meta:get_int("src_time")
local sttm = meta:get_int("src_time_max")
if sttm > 0 then
meta:set_int("src_time", stime + 1)
minetest.get_node_timer(pos):start(0.2)
end
minetest.node_punch(pos, node, puncher, pointed_thing)
end
})

View File

@ -5,6 +5,7 @@ dofile(elepm.modpath.."/machines/furnace.lua")
dofile(elepm.modpath.."/machines/alloy_furnace.lua")
dofile(elepm.modpath.."/machines/coal_alloy_furnace.lua")
dofile(elepm.modpath.."/machines/pulverizer.lua")
dofile(elepm.modpath.."/machines/grindstone.lua")
dofile(elepm.modpath.."/machines/sawmill.lua")
dofile(elepm.modpath.."/machines/generator.lua")
dofile(elepm.modpath.."/machines/storage.lua")

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB