Minor improvements

master
Vitalie Ciubotaru 2016-05-01 23:00:00 +09:00
parent c08847a063
commit 90fbd80f12
No known key found for this signature in database
GPG Key ID: 6B60758D4DF9A7EE
10 changed files with 307 additions and 135 deletions

View File

@ -1,7 +1,8 @@
License for Code
----------------
Copyright (C) 2016 cd2 (cdqwertz) <cdqwertz@gmail.com>
Original Work Copyright (C) 2016 cd2 (cdqwertz) <cdqwertz@gmail.com>
Modified Work Copyright (C) Vitalie Ciubotaru <vitalie at ciubotaru dot tk>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,10 +1,48 @@
#compost mod
With this mod, you are able to compost grass, leaves, flowers...
Compost Mod v0.0.1
==================
Compost bins turn organic matter like leaves, flowers, grass etc into soil. The
bin is operated by punching or right-clicking.
##License
Punching
--------
On punching (left-clicking) a compost bin, the pointed_thing is inserted into
the bin and dirt is transferred back. If pointed_thing is compostable and there
is a free slot for it, it disappears inside the bin. After that, if hand is
empty and there is soil in the bin, it appears in the hand.
Menu
----
Right-clicking the bin opens its menu. 8 (2 rows by 4 cols) slots for intputs,
one slot for output.
Once there are at least 8 pieces of acceptable inputs are inserted (stacks
OK), a timer starts. Every 30 seconds it adds 10% to the composting progress, so
it takes 5 minutes to create a block of soil.
Once 100% is reached, 8 pieces of input disappear and one block of soil is
added to output. The progress counter is reset to 0. Optionally, wear-out is
computed.
If there are not enough inputs, the timer (if it was set) is stopped (and it
works like a small chest).
Inputs
------
Acceptable inputs are group:flora (flowers and grasses) and group:leaves. Other
inputs are rejected. Food is rejected on esthetical grounds :-)
Nodebox
-------
If there is nothing in the bin, it looks empty when viewed from top (node
"compost:wood_barrel_empty"). If there's anything in it (inputs or soil), it
looks full of dirt (node "compost:wood_barrel").
License
-------
see LICENSE.txt
##Crafting
Crafting
--------
Wood barrel:
| W | | W |
@ -15,8 +53,11 @@ Wood barrel:
W : wood
S : wood slab
##Bugs
Bugs
----
Report bugs on the forum topic or open a issue on GitHub.
##created by
cd2 (cdqwertz) - cdqwertz.github.io
Authors
-------
* Original Work: cd2 (cdqwertz) - cdqwertz.github.io
* Modified Work: Vitalie Ciubotaru <vitalie at ciubotaru dot tk>

View File

@ -1 +1,2 @@
default
stairs

383
init.lua
View File

@ -1,42 +1,232 @@
compost = {}
compost.items = {}
--File name: init.lua
--Project name: compost, a Mod for Minetest
--License: General Public License, version 3 or later
--Original Work Copyright (C) 2016 cd2 (cdqwertz) <cdqwertz@gmail.com>
--Modified Work Copyright (C) Vitalie Ciubotaru <vitalie at ciubotaru dot tk>
function compost.register_item(name)
compost.items[name] = true
minetest.log('action', 'MOD: Compost loading...')
compost_version = '0.0.1'
local function formspec(pos)
local spos = pos.x..','..pos.y..','..pos.z
local formspec =
'size[8,8.5]'..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
'list[nodemeta:'..spos..';src;0,0;8,1;]'..
'list[nodemeta:'..spos..';dst;3.5,2;1,1;]'..
'list[current_player;main;0,4.25;8,1;]'..
'list[current_player;main;0,5.5;8,3;8]'..
'listring[nodemeta:'..spos ..';dst]'..
'listring[current_player;main]'..
'listring[nodemeta:'..spos ..';src]'..
'listring[current_player;main]'..
default.get_hotbar_bg(0, 4.25)
return formspec
end
-- grass
compost.register_item("default:grass_1")
compost.register_item("default:junglegrass")
local function is_compostable(input)
if minetest.get_item_group(input, 'flora') > 0 or minetest.get_item_group(input, 'leaves') > 0 then
return true
else
return false
end
end
-- leaves
compost.register_item("default:leaves")
compost.register_item("default:jungleleaves")
compost.register_item("default:pine_needles")
compost.register_item("default:acacia_leaves")
compost.register_item("default:aspen_leaves")
local function swap_node(pos, name)
local node = minetest.get_node(pos)
if node.name == name then
return
end
node.name = name
minetest.swap_node(pos, node)
end
-- dirt
compost.register_item("default:dirt")
compost.register_item("default:dirt_with_grass")
local function count_input(pos)
local q = 0
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stacks = inv:get_list('src')
for k, v in pairs(stacks) do
q = q + inv:get_stack('src', k):get_count()
end
return q
end
-- stick
compost.register_item("default:stick")
local function is_empty(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stacks = inv:get_list('src')
for k, v in pairs(stacks) do
if not inv:get_stack('src', k):is_empty() then
return false
end
end
if not inv:get_stack('dst', 1):is_empty() then
return false
end
return true
end
-- flowers
compost.register_item("flowers:geranium")
compost.register_item("flowers:tulip")
compost.register_item("flowers:rose")
compost.register_item("flowers:dandelion_yellow")
compost.register_item("flowers:dandelion_white")
local function update_nodebox(pos)
if is_empty(pos) then
swap_node(pos, "compost:wood_barrel_empty")
else
swap_node(pos, "compost:wood_barrel")
end
end
-- food
compost.register_item("farming:bread")
compost.register_item("farming:wheat")
local function update_timer(pos)
local timer = minetest.get_node_timer(pos)
local meta = minetest.get_meta(pos)
local count = count_input(pos)
if not timer:is_started() and count >= 8 then
timer:start(30)
meta:set_int('progress', 0)
meta:set_string('infotext', 'progress: 0%')
return
end
if timer:is_started() and count < 8 then
timer:stop()
meta:set_string('infotext', 'Empty composting bin.\nTo get compost, add some organic matter.')
meta:set_int('progress', 0)
end
end
minetest.register_node("compost:wood_barrel", {
description = "Wood Barrel",
tiles = {"default_wood.png"},
local function create_compost(pos)
local q = 8
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stacks = inv:get_list('src')
for k, v in pairs(stacks) do
local stack = inv:get_stack('src', k)
if not stack:is_empty() then
local count = stack:get_count()
if count <= q then
inv:set_stack('src', k, '')
q = q - count
else
inv:set_stack('src', k, stack:get_name() .. ' ' .. (count - q))
q = 0
break
end
end
end
local dirt_count = inv:get_stack('dst', 1):get_count()
inv:set_stack('dst', 1, 'default:dirt ' .. (dirt_count + 1))
end
local function on_timer(pos)
local timer = minetest.get_node_timer(pos)
local meta = minetest.get_meta(pos)
local progress = meta:get_int('progress') + 10
if progress >= 100 then
create_compost(pos)
meta:set_int('progress', 0)
else
meta:set_int('progress', progress)
end
if count_input(pos) >= 8 then
meta:set_string('infotext', 'progress: ' .. progress .. '%')
return true
else
timer:stop()
meta:set_string('infotext', 'Empty composting bin.\nTo get compost, add some organic matter.')
meta:set_int('progress', 0)
return false
end
end
local function on_construct(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size('src', 8)
inv:set_size('dst', 1)
meta:set_string('infotext','Empty composting bin.\nTo get compost, add some organic matter.')
meta:set_int('progress', 0)
end
local function on_rightclick(pos, node, clicker, itemstack)
minetest.show_formspec(
clicker:get_player_name(),
'compost:wood_barrel',
formspec(pos)
)
end
local function can_dig(pos,player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if inv:is_empty('src') and inv:is_empty('dst') then
return true
else
return false
end
end
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
if listname == 'src' and is_compostable(stack:get_name()) then
return stack:get_count()
else
return 0
end
end
local function on_metadata_inventory_put(pos, listname, index, stack, player)
update_timer(pos)
update_nodebox(pos)
minetest.log('action', player:get_player_name() .. ' moves stuff to compost bin at ' .. minetest.pos_to_string(pos))
return
end
local function on_metadata_inventory_take(pos, listname, index, stack, player)
update_timer(pos)
update_nodebox(pos)
minetest.log('action', player:get_player_name() .. ' takes stuff from compost bin at ' .. minetest.pos_to_string(pos))
return
end
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
local inv = minetest.get_meta(pos):get_inventory()
if from_list == to_list then
return inv:get_stack(from_list, from_index):get_count()
else
return 0
end
end
local function on_punch(pos, node, player, pointed_thing)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local wielded_item = player:get_wielded_item()
if not wielded_item:is_empty() then
local wielded_item_name = wielded_item:get_name()
local wielded_item_count = wielded_item:get_count()
if is_compostable(wielded_item_name) and inv:room_for_item('src', wielded_item_name) then
player:set_wielded_item('')
inv:add_item('src', wielded_item_name .. ' ' .. wielded_item_count)
minetest.log('action', player:get_player_name() .. ' moves stuff to compost bin at ' .. minetest.pos_to_string(pos))
update_nodebox(pos)
update_timer(pos)
end
end
local compost_count = inv:get_stack('dst', 1):get_count()
local wielded_item = player:get_wielded_item() --recheck
if compost_count > 0 and wielded_item:is_empty() then
inv:set_stack('dst', 1, '')
player:set_wielded_item('default:dirt ' .. compost_count)
minetest.log('action', player:get_player_name() .. ' takes stuff from compost bin at ' .. minetest.pos_to_string(pos))
update_nodebox(pos)
update_timer(pos)
end
end
minetest.register_node("compost:wood_barrel_empty", {
description = "Empty Compost Bin",
tiles = {
"default_wood.png",
},
drawtype = "nodebox",
node_box = {
type = "fixed",
@ -46,24 +236,31 @@ minetest.register_node("compost:wood_barrel", {
{-1/2, -1/2, -1/2, 1/2, 1/2, -3/8},
{-1/2, -1/2, 3/8, 1/2, 1/2, 1/2}},
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}
},
paramtype = "light",
is_ground_content = false,
groups = {choppy = 3},
sounds = default.node_sound_wood_defaults(),
on_punch = function(pos, node, puncher, pointed_thing)
local wielded_item = puncher:get_wielded_item():get_name()
if compost.items[wielded_item] then
minetest.set_node(pos, {name = "compost:wood_barrel_1"})
local w = puncher:get_wielded_item()
w:take_item(1)
puncher:set_wielded_item(w)
end
end
on_timer = on_timer,
on_construct = on_construct,
on_rightclick = on_rightclick,
can_dig = can_dig,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move,
on_metadata_inventory_put = on_metadata_inventory_put,
on_metadata_inventory_take = on_metadata_inventory_take,
on_punch = on_punch,
})
minetest.register_node("compost:wood_barrel_1", {
description = "Wood Barrel with compost",
tiles = {"default_wood.png^compost_compost_1.png", "default_wood.png"},
minetest.register_node("compost:wood_barrel", {
description = "Compost Bin",
tiles = {
"default_wood.png^compost_compost.png",
"default_wood.png",
},
drawtype = "nodebox",
node_box = {
type = "fixed",
@ -74,100 +271,32 @@ minetest.register_node("compost:wood_barrel_1", {
{-1/2, -1/2, 3/8, 1/2, 1/2, 1/2},
{-3/8, -1/2, -3/8, 3/8, 3/8, 3/8}},
},
paramtype = "light",
is_ground_content = false,
groups = {choppy = 3},
sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("compost:wood_barrel_2", {
description = "Wood Barrel with compost",
tiles = {"default_wood.png^compost_compost_2.png", "default_wood.png"},
drawtype = "nodebox",
node_box = {
selection_box = {
type = "fixed",
fixed = {{-1/2, -1/2, -1/2, 1/2, -3/8, 1/2},
{-1/2, -1/2, -1/2, -3/8, 1/2, 1/2},
{3/8, -1/2, -1/2, 1/2, 1/2, 1/2},
{-1/2, -1/2, -1/2, 1/2, 1/2, -3/8},
{-1/2, -1/2, 3/8, 1/2, 1/2, 1/2},
{-3/8, -1/2, -3/8, 3/8, 3/8, 3/8}},
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}
},
paramtype = "light",
is_ground_content = false,
groups = {choppy = 3},
groups = {choppy = 3, not_in_creative_inventory = 1},
sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("compost:wood_barrel_3", {
description = "Wood Barrel",
tiles = {"default_wood.png^compost_compost_3.png", "default_wood.png"},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {{-1/2, -1/2, -1/2, 1/2, -3/8, 1/2},
{-1/2, -1/2, -1/2, -3/8, 1/2, 1/2},
{3/8, -1/2, -1/2, 1/2, 1/2, 1/2},
{-1/2, -1/2, -1/2, 1/2, 1/2, -3/8},
{-1/2, -1/2, 3/8, 1/2, 1/2, 1/2},
{-3/8, -1/2, -3/8, 3/8, 3/8, 3/8}},
},
paramtype = "light",
is_ground_content = false,
groups = {choppy = 3},
sounds = default.node_sound_wood_defaults(),
on_punch = function(pos, node, player, pointed_thing)
local p = {x = pos.x + math.random(0, 5)/5 - 0.5, y = pos.y+1, z = pos.z + math.random(0, 5)/5 - 0.5}
minetest.add_item(p, {name = "compost:compost"})
minetest.set_node(pos, {name = "compost:wood_barrel"})
end
})
minetest.register_abm({
nodenames = {"compost:wood_barrel_1"},
interval = 5.0,
chance = 3,
action = function(pos, node, active_object_count, active_object_count_wider)
minetest.set_node(pos, {name = "compost:wood_barrel_2"})
end,
})
minetest.register_abm({
nodenames = {"compost:wood_barrel_2"},
interval = 5.0,
chance = 3,
action = function(pos, node, active_object_count, active_object_count_wider)
minetest.set_node(pos, {name = "compost:wood_barrel_3"})
end,
on_timer = on_timer,
on_construct = on_construct,
on_rightclick = on_rightclick,
can_dig = can_dig,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move,
on_metadata_inventory_put = on_metadata_inventory_put,
on_metadata_inventory_take = on_metadata_inventory_take,
on_punch = on_punch,
})
minetest.register_craft({
output = "compost:wood_barrel",
output = "compost:wood_barrel_empty",
recipe = {
{"default:wood", "", "default:wood"},
{"default:wood", "", "default:wood"},
{"default:wood", "stairs:slab_wood", "default:wood"}
}
})
minetest.register_node("compost:compost", {
description = "Compost",
tiles = {"compost_compost.png"},
groups = {crumbly = 3},
sounds = default.node_sound_dirt_defaults(),
})
minetest.register_node("compost:garden_soil", {
description = "Garden Soil",
tiles = {"compost_garden_soil.png"},
groups = {crumbly = 3, soil=3, grassland = 1, wet = 1},
sounds = default.node_sound_dirt_defaults(),
})
minetest.register_craft({
output = "compost:garden_soil",
recipe = {
{"compost:compost", "compost:compost"},
{"group:wood", "", "group:wood"},
{"group:wood", "", "group:wood"},
{"group:wood", "stairs:slab_wood", "group:wood"}
}
})
minetest.log('action', 'MOD: Compost version ' .. compost_version .. ' loaded.')

Binary file not shown.

Before

Width:  |  Height:  |  Size: 286 KiB

After

Width:  |  Height:  |  Size: 327 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 785 B

After

Width:  |  Height:  |  Size: 461 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 483 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 487 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 461 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 698 B