Code cleanup. Add tar and more stone types.

This commit is contained in:
Calinou 2014-06-27 20:14:08 +02:00
parent 2b6eb1ff84
commit e2f4cc369b
14 changed files with 107 additions and 119 deletions

View File

@ -1,4 +1,3 @@
local S = moreblocks.gettext
circular_saw = {}
@ -10,10 +9,10 @@ circular_saw.known_stairs = setmetatable({}, {
end,
})
-- This is populated by stairsplus:register_all
-- This is populated by stairsplus:register_all:
circular_saw.known_nodes = {}
-- How many microblocks does this shape at the output inventory cost?
-- How many microblocks does this shape at the output inventory cost:
circular_saw.cost_in_microblocks = {
1, 1, 1, 1, 1, 1, 1, 2,
2, 3, 2, 4, 2, 4, 5, 6,
@ -67,15 +66,15 @@ function circular_saw:get_output_inv(modname, material, amount, max)
end
local list = {}
-- If there is nothing inside display empty inventory
-- If there is nothing inside, display empty inventory:
if amount < 1 then
return list
end
for i, t in ipairs(circular_saw.names) do
local cost = circular_saw.cost_in_microblocks[i]
table.insert(list, modname..":"..t[1].."_"..material..t[2]
.." "..math.min(math.floor(amount/cost), max))
table.insert(list, modname .. ":" .. t[1] .. "_" .. material .. t[2]
.. " " .. math.min(math.floor(amount/cost), max))
end
return list
end
@ -83,7 +82,7 @@ end
-- Reset empty circular_saw after last full block has been taken out
-- (or the circular_saw has been placed the first time)
-- note: max_offered is not reset
-- Note: max_offered is not reset:
function circular_saw:reset(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
@ -100,7 +99,7 @@ end
-- Player has taken something out of the box or placed something inside
-- that amounts to count microblocks
-- that amounts to count microblocks:
function circular_saw:update_inventory(pos, amount)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
@ -129,28 +128,27 @@ function circular_saw:update_inventory(pos, amount)
local modname = name_parts[1]
local material = name_parts[2]
-- Display as many full blocks as possible
inv:set_list("input", {
inv:set_list("input", { -- Display as many full blocks as possible:
node_name.." ".. math.floor(amount / 8)
})
-- The stairnodes made of default nodes use moreblocks namespace, other mods keep own.
-- The stairnodes made of default nodes use moreblocks namespace, other mods keep own:
if modname == "default" then
modname = "moreblocks"
end
--print("circular_saw set to " ..modname.. " : "
-- ..material.. " with "..(amount).." microblocks.")
-- print("circular_saw set to " .. modname .. " : "
-- .. material .. " with " .. (amount) .. " microblocks.")
-- 0-7 microblocks may remain left-over.
-- 0-7 microblocks may remain left-over:
inv:set_list("micro", {
modname..":micro_"..material.."_bottom "..(amount % 8)
modname .. ":micro_" .. material .. "_bottom " .. (amount % 8)
})
-- Display
-- Display:
inv:set_list("output",
self:get_output_inv(modname, material, amount,
meta:get_int("max_offered")))
-- Store how many microblocks are available
meta:set_int("anz", amount)
-- Store how many microblocks are available:
meta:set_int("anz", amount)
meta:set_string("infotext",
S("Circular Saw is working on %s (owned by %s)")
@ -158,31 +156,31 @@ function circular_saw:update_inventory(pos, amount)
end
-- The amount of items offered per shape can be configured
-- The amount of items offered per shape can be configured:
function circular_saw.on_receive_fields(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
local max = tonumber(fields.max_offered)
if max and max > 0 then
meta:set_string("max_offered", max)
-- update to show the correct number of items
-- Update to show the correct number of items:
circular_saw:update_inventory(pos, 0)
end
end
-- Moving the inventory of the circular_saw around is not allowed because it
-- is a fictional inventory. Moving inventory around would be rather
-- impractical and make things more difficult to calculate.
-- is a fictional inventory. Moving inventory around would be rather
-- impractical and make things more difficult to calculate:
function circular_saw.allow_metadata_inventory_move(
pos, from_list, from_index, to_list, to_index, count, player)
return 0
end
-- Only input- and recycle-slot are intended as input slots
-- Only input- and recycle-slot are intended as input slots:
function circular_saw.allow_metadata_inventory_put(
pos, listname, index, stack, player)
-- The player is not allowed to put something in there
-- The player is not allowed to put something in there:
if listname == "output" or listname == "micro" then
return 0
end
@ -192,7 +190,7 @@ function circular_saw.allow_metadata_inventory_put(
local stackname = stack:get_name()
local count = stack:get_count()
-- Only alow those items that are offered in the output inventory to be recycled
-- Only alow those items that are offered in the output inventory to be recycled:
if listname == "recycle" then
if not inv:contains_item("output", stackname) then
return 0
@ -210,7 +208,7 @@ function circular_saw.allow_metadata_inventory_put(
return count
end
-- Only accept certain blocks as input which are known to be craftable into stairs
-- Only accept certain blocks as input which are known to be craftable into stairs:
if listname == "input" then
if not inv:is_empty("input") and
inv:get_stack("input", index):get_name() ~= stackname then
@ -225,25 +223,25 @@ function circular_saw.allow_metadata_inventory_put(
end
end
-- Taking is allowed from all slots (even the internal microblock slot)
-- Taking is allowed from all slots (even the internal microblock slot).
-- Putting something in is slightly more complicated than taking anything
-- because we have to make sure it is of a suitable material
-- because we have to make sure it is of a suitable material:
function circular_saw.on_metadata_inventory_put(
pos, listname, index, stack, player)
-- We need to find out if the circular_saw is already set to a
-- specific material or not
-- specific material or not:
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stackname = stack:get_name()
local count = stack:get_count()
-- Putting something into the input slot is only possible if that had
-- been empty before or did contain something of the same material
-- been empty before or did contain something of the same material:
if listname == "input" then
-- Each new block is worth 8 microblocks
-- Each new block is worth 8 microblocks:
circular_saw:update_inventory(pos, 8 * count)
elseif listname == "recycle" then
-- Lets look which shape this represents
-- Lets look which shape this represents:
local cost = circular_saw:get_cost(inv, stackname)
circular_saw:update_inventory(pos, cost * count)
end
@ -252,27 +250,28 @@ end
function circular_saw.on_metadata_inventory_take(
pos, listname, index, stack, player)
-- If it is one of the offered stairs: find out how many
-- microblocks have to be substracted
-- microblocks have to be substracted:
if listname == "output" then
-- We do know how much each block at each position costs
-- We do know how much each block at each position costs:
local cost = circular_saw.cost_in_microblocks[index]
* stack:get_count()
circular_saw:update_inventory(pos, -cost)
elseif listname == "micro" then
-- Each microblock costs 1 microblock
-- Each microblock costs 1 microblock:
circular_saw:update_inventory(pos, -stack:get_count())
elseif listname == "input" then
-- Each normal (= full) block taken costs 8 microblocks
-- Each normal (= full) block taken costs 8 microblocks:
circular_saw:update_inventory(pos, 8 * -stack:get_count())
end
-- The recycle field plays no role here since it is processed immediately.
end
gui_slots = "listcolors[#606060AA;#808080;#101010;#202020;#FFF]"
function circular_saw.on_construct(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", "size[11,9]"..
meta:set_string("formspec", "size[11,9]"..gui_slots..
"label[0,0;"..S("Input\nmaterial").."]"..
"list[current_name;input;1.5,0;1,1;]"..
"label[0,1;"..S("Left-over").."]"..
@ -289,8 +288,8 @@ function circular_saw.on_construct(pos)
meta:set_string("infotext", S("Circular Saw is empty"))
local inv = meta:get_inventory()
inv:set_size("input", 1) -- Input slot for full blocks of material x.
inv:set_size("micro", 1) -- Storage for 1-7 surplus microblocks.
inv:set_size("input", 1) -- Input slot for full blocks of material x.
inv:set_size("micro", 1) -- Storage for 1-7 surplus microblocks.
inv:set_size("recycle", 1) -- Surplus partial blocks can be placed here.
inv:set_size("output", 4*8) -- 4x8 versions of stair-parts of material x.
@ -306,8 +305,7 @@ function circular_saw.can_dig(pos,player)
not inv:is_empty("recycle") then
return false
end
-- Can be dug by anyone when empty ,not only by the owner.
-- Can be dug by anyone when empty, not only by the owner:
return true
end
@ -347,14 +345,13 @@ minetest.register_node("moreblocks:circular_saw", {
:format(owner))
end,
-- The amount of items offered per shape can be configured.
-- The amount of items offered per shape can be configured:
on_receive_fields = circular_saw.on_receive_fields,
allow_metadata_inventory_move = circular_saw.allow_metadata_inventory_move,
-- Only input- and recycle-slot are intended as input slots.
-- Only input- and recycle-slot are intended as input slots:
allow_metadata_inventory_put = circular_saw.allow_metadata_inventory_put,
-- Taking is allowed from all slots (even the internal microblock slot). Moving is forbidden.
-- Putting something in is slightly more complicated than taking anything because we have to make sure it is of a suitable material.
-- Putting something in is slightly more complicated than taking anything because we have to make sure it is of a suitable material:
on_metadata_inventory_put = circular_saw.on_metadata_inventory_put,
on_metadata_inventory_take = circular_saw.on_metadata_inventory_take,
})

View File

@ -18,8 +18,8 @@ local function setting(settingtype, name, default)
end
end
-- Whether to direct wood based on player posititon when placing the block (true or false).
-- Whether to direct wood based on player posititon when placing the block (true or false):
setting("bool", "wood_facedir", true)
-- Show stairs/slabs/panels/microblocks in creative inventory (true or false).
setting("bool", "show_stairsplus_creative_inv", false)
-- Show stairs/slabs/panels/microblocks in creative inventory (true or false):
setting("bool", "stairsplus_in_creative_inventory", false)

View File

@ -179,6 +179,25 @@ minetest.register_craft({
}
})
minetest.register_craft({
output = "moreblocks:split_stone_tile_alt",
recipe = {
{"moreblocks:split_stone_tile"},
}
})
minetest.register_craft({
output = "moreblocks:grey_bricks",
type = "shapeless",
recipe = {"default:stone", "default:brick"},
})
minetest.register_craft({
output = "moreblocks:grey_bricks",
type = "shapeless",
recipe = {"default:stonebrick", "default:brick"},
})
minetest.register_craft({
output = "moreblocks:empty_bookshelf",
type = "shapeless",
@ -413,6 +432,10 @@ minetest.register_craft({
}
})
minetest.register_craft({
type = "cooking", output = "moreblocks:tar", recipe = "default:gravel",
})
minetest.register_craft({
output = "moreblocks:circular_saw",
recipe = {
@ -421,4 +444,3 @@ minetest.register_craft({
{ "group:wood", "", "group:wood"},
}
})

View File

@ -1,15 +1,15 @@
--[[
-- More Blocks (moreblocks) by Calinou
-- Licensed under the zlib license for code and CC BY-SA 3.0 for textures, see LICENSE.txt for info.
-- Licensed under the zlib/ license for code and CC BY-SA 3.0 for textures, see LICENSE.txt for info.
--]]
moreblocks = {}
-- Load translation library if intllib is installed
local S = nil
local S -- Load translation library if intllib is installed:
if intllib then
S = intllib.Getter()
S = intllib.Getter(minetest.get_current_modname())
else
S = function(s) return s end
end

View File

@ -14,7 +14,6 @@ local nodes = {
["wood_tile"] = {
description = S("Wooden Tile"),
groups = {snappy = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
paramtype2 = "facedir",
tiles = {"default_wood.png^moreblocks_wood_tile.png",
"default_wood.png^moreblocks_wood_tile.png",
"default_wood.png^moreblocks_wood_tile.png",
@ -26,7 +25,6 @@ local nodes = {
["wood_tile_flipped"] = {
description = S("Wooden Tile"),
groups = {snappy = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
paramtype2 = "facedir",
tiles = {"default_wood.png^moreblocks_wood_tile.png^[transformR90",
"default_wood.png^moreblocks_wood_tile.png^[transformR90",
"default_wood.png^moreblocks_wood_tile.png^[transformR90",
@ -39,21 +37,18 @@ local nodes = {
["wood_tile_center"] = {
description = S("Centered Wooden Tile"),
groups = {snappy = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
paramtype2 = "facedir",
tiles = {"default_wood.png^moreblocks_wood_tile_center.png"},
sounds = sound_wood,
},
["wood_tile_full"] = {
description = S("Full Wooden Tile"),
groups = {snappy = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
paramtype2 = "facedir",
tiles = tile_tiles("wood_tile_full"),
sounds = sound_wood,
},
["wood_tile_up"] = {
description = S("Upwards Wooden Tile"),
groups = {snappy = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
paramtype2 = "facedir",
tiles = {"default_wood.png^moreblocks_wood_tile_up.png"},
sounds = sound_wood,
no_stairs = true,
@ -61,7 +56,6 @@ local nodes = {
["wood_tile_down"] = {
description = S("Downwards Wooden Tile"),
groups = {snappy = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
paramtype2 = "facedir",
tiles = {"default_wood.png^[transformR180^moreblocks_wood_tile_up.png^[transformR180"},
sounds = sound_wood,
no_stairs = true,
@ -69,7 +63,6 @@ local nodes = {
["wood_tile_left"] = {
description = S("Leftwards Wooden Tile"),
groups = {snappy = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
paramtype2 = "facedir",
tiles = {"default_wood.png^[transformR270^moreblocks_wood_tile_up.png^[transformR270"},
sounds = sound_wood,
no_stairs = true,
@ -77,7 +70,6 @@ local nodes = {
["wood_tile_right"] = {
description = S("Rightwards Wooden Tile"),
groups = {snappy = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
paramtype2 = "facedir",
tiles = {"default_wood.png^[transformR90^moreblocks_wood_tile_up.png^[transformR90"},
sounds = sound_wood,
no_stairs = true,
@ -87,6 +79,11 @@ local nodes = {
groups = {cracky = 3},
sounds = sound_stone,
},
["grey_bricks"] = {
description = S("Stone Bricks"),
groups = {cracky = 3},
sounds = sound_stone,
},
["coal_stone_bricks"] = {
description = S("Coal Stone Bricks"),
groups = {cracky = 3},
@ -109,6 +106,18 @@ local nodes = {
groups = {cracky = 3},
sounds = sound_stone,
},
["split_stone_tile_alt"] = {
description = S("Split Stone Tile"),
tiles = {"moreblocks_split_stone_tile_alt_top.png",
"moreblocks_split_stone_tile_alt.png"},
groups = {cracky = 3},
sounds = sound_stone,
},
["tar"] = {
description = S("Tar"),
groups = {cracky = 2},
sounds = sound_stone,
},
["plankstone"] = {
description = S("Plankstone"),
groups = {cracky = 3},
@ -147,7 +156,6 @@ local nodes = {
["cactus_checker"] = {
description = S("Cactus Checker"),
groups = {cracky = 3},
paramtype2 = "facedir",
tiles = {"default_stone.png^moreblocks_cactus_checker.png",
"default_stone.png^moreblocks_cactus_checker.png",
"default_stone.png^moreblocks_cactus_checker.png",
@ -182,7 +190,6 @@ local nodes = {
"default_stone.png^moreblocks_coal_checker.png",
"default_stone.png^moreblocks_coal_checker.png^[transformR90",
"default_stone.png^moreblocks_coal_checker.png^[transformR90"},
paramtype2 = "facedir",
groups = {cracky = 3},
sounds = sound_stone,
},
@ -194,7 +201,6 @@ local nodes = {
"default_stone.png^moreblocks_iron_checker.png",
"default_stone.png^moreblocks_iron_checker.png^[transformR90",
"default_stone.png^moreblocks_iron_checker.png^[transformR90"},
paramtype2 = "facedir",
groups = {cracky = 3},
sounds = sound_stone,
},

View File

@ -10,7 +10,7 @@ minetest.register_craft({
})
minetest.register_craft({
output = "default:ladder 3",
output = "default:ladder 4",
recipe = {
{"default:stick", "", "default:stick"},
{"default:stick", "default:stick", "default:stick"},
@ -19,7 +19,7 @@ minetest.register_craft({
})
minetest.register_craft({
output = "default:paper 3",
output = "default:paper 4",
recipe = {
{"default:papyrus", "default:papyrus", "default:papyrus"},
}
@ -68,23 +68,7 @@ minetest.register_craft({
-- Redefinitions of some default nodes:
-- Don't bother overriding nodes if minetest.override_item isn't available.
if minetest.override_item then
if moreblocks.config.wood_facedir then
minetest.override_item("default:wood", {paramtype2 = "facedir",})
minetest.override_item("default:junglewood", {paramtype2 = "facedir",})
minetest.override_item("default:brick", {paramtype2 = "facedir",})
minetest.override_item("default:stonebrick", {paramtype2 = "facedir",})
minetest.override_item("default:desert_stonebrick", {paramtype2 = "facedir",})
minetest.override_item("default:sandstonebrick", {paramtype2 = "facedir",})
minetest.override_item("moreblocks:cactus_brick", {paramtype2 = "facedir",})
minetest.override_item("moreblocks:coal_stone_bricks", {paramtype2 = "facedir",})
minetest.override_item("moreblocks:iron_stone_bricks", {paramtype2 = "facedir",})
end
-- Make glass and obsidian glass framed, like the More Blocks glasses:
minetest.override_item("default:glass", {
drawtype = "glasslike_framed",
})
@ -94,7 +78,6 @@ minetest.override_item("default:obsidian_glass", {
})
-- Let there be light. This makes some nodes let light pass through:
minetest.override_item("default:ladder", {
paramtype = "light",
sunlight_propagates = true,
@ -143,5 +126,3 @@ for i = 2, 5 do
sunlight_propagates = true,
})
end
end -- End "if minetest.override_item".

View File

@ -1,11 +1,11 @@
API documentation for StairsPlus
API documentation for Stairs+
================================
- - - - - - - - - - - - - - - -
* `stairsplus:register_all(modname, subname, recipeitem, fields)`
Registers a stair, slab, panel, microblock, and any other types of
microblocks to be added in the future.
Also registers the node with the circular saw.
nodes to be added in the future.
This also registers the node with the circular saw.
Example:
```lua
stairsplus:register_all("moreblocks", "wood", "defaut:wood", {
@ -16,7 +16,7 @@ API documentation for StairsPlus
})
```
The following register only a particular type of microblock.
You will probably never want to use them directly.
You will probably never want to use them directly:
* `stairsplus:register_stair(modname, subname, recipeitem, fields)`
* `stairsplus:register_slab(modname, subname, recipeitem, fields)`

View File

@ -60,4 +60,3 @@ register_stairsplus_alias("moreblocks", "splitstonesquare", "split_stone_tile")
register_stairsplus_alias("moreblocks", "woodtile", "wood_tile")
register_stairsplus_alias("moreblocks", "woodtile_centered", "wood_tile_centered")
register_stairsplus_alias("moreblocks", "woodtile_full", "wood_tile_full")

View File

@ -1,4 +1,3 @@
-- Nodes will be called <modname>:{stair,slab,panel,micro}_<subname>
local modpath = minetest.get_modpath("moreblocks").."/stairsplus"
@ -6,8 +5,8 @@ local modpath = minetest.get_modpath("moreblocks").."/stairsplus"
stairsplus = {}
stairsplus.expect_infinite_stacks = false
if not minetest.get_modpath("unified_inventory") and
minetest.setting_getbool("creative_mode") then
if not minetest.get_modpath("unified_inventory")
and minetest.setting_getbool("creative_mode") then
stairsplus.expect_infinite_stacks = true
end
@ -21,7 +20,7 @@ function stairsplus:register_all(modname, subname, recipeitem, fields)
self:register_slab (modname, subname, recipeitem, fields)
self:register_panel(modname, subname, recipeitem, fields)
self:register_micro(modname, subname, recipeitem, fields)
-- self:register_6dfacedir_conversion(modname, subname)
-- self:register_6dfacedir_conversion(modname, subname) -- Not needed as of Q3 2013, uncomment to fix old maps.
circular_saw.known_nodes[recipeitem] = {modname, subname}
end
@ -35,12 +34,10 @@ function register_stair_slab_panel_micro(modname, subname, recipeitem, groups, i
})
end
-- dofile(modpath.."/aliases.lua")
-- dofile(modpath.."/conversion.lua")
-- dofile(modpath.."/aliases.lua") -- Not needed as of Q2 2013, uncomment to fix old maps.
-- dofile(modpath.."/conversion.lua") -- Not needed as of Q2 2013, uncomment to fix old maps.
dofile(modpath.."/stairs.lua")
dofile(modpath.."/slabs.lua")
dofile(modpath.."/panels.lua")
dofile(modpath.."/microblocks.lua")
dofile(modpath.."/registrations.lua")

View File

@ -1,6 +1,4 @@
-- Load translation library if intllib is installed
local S
local S -- Load translation library if intllib is installed:
if intllib then
S = intllib.Getter(minetest.get_current_modname())
else
@ -110,4 +108,3 @@ function stairsplus:register_micro(modname, subname, recipeitem, fields)
recipe = {"moreblocks:micro_" .. subname, "moreblocks:micro_" .. subname, "moreblocks:micro_" .. subname, "moreblocks:micro_" .. subname, "moreblocks:micro_" .. subname, "moreblocks:micro_" .. subname, "moreblocks:micro_" .. subname, "moreblocks:micro_" .. subname},
})
end

View File

@ -1,6 +1,4 @@
-- Load translation library if intllib is installed
local S
local S -- Load translation library if intllib is installed:
if intllib then
S = intllib.Getter(minetest.get_current_modname())
else
@ -111,4 +109,3 @@ function stairsplus:register_panel(modname, subname, recipeitem, fields)
recipe = {"moreblocks:panel_" .. subname, "moreblocks:panel_" .. subname, "moreblocks:panel_" .. subname, "moreblocks:panel_" .. subname},
})
end

View File

@ -1,6 +1,4 @@
-- Default stairs/slabs/panels/microblocks.
local default_nodes = {
local default_nodes = { -- Default stairs/slabs/panels/microblocks:
"stone",
"cobble",
"mossycobble",
@ -12,7 +10,7 @@ local default_nodes = {
"bronzeblock",
"diamondblock",
"desert_stone",
-- "desert_cobble", -- Does not work in minetest_game.
-- "desert_cobble",
"glass",
"tree",
"wood",
@ -26,11 +24,11 @@ local default_nodes = {
}
for _, name in pairs(default_nodes) do
local nodename = "default:"..name
local nodename = "default:" .. name
local ndef = minetest.registered_nodes[nodename]
local groups = {}
for k, v in pairs(ndef.groups)
-- Ignore wood and stone groups to not make them usable in crafting.
-- Ignore wood and stone groups to not make them usable in crafting:
do if k ~= "wood" and k ~= "stone" then
groups[k] = v
end

View File

@ -1,6 +1,4 @@
-- Load translation library if intllib is installed
local S
local S -- Load translation library if intllib is installed:
if intllib then
S = intllib.Getter(minetest.get_current_modname())
else
@ -101,4 +99,3 @@ function stairsplus:register_slab(modname, subname, recipeitem, fields)
recipe = {"moreblocks:panel_" .. subname, "moreblocks:panel_" .. subname},
})
end

View File

@ -1,6 +1,4 @@
-- Load translation library if intllib is installed
local S
local S -- Load translation library if intllib is installed:
if intllib then
S = intllib.Getter(minetest.get_current_modname())
else
@ -192,4 +190,3 @@ function stairsplus:register_stair(modname, subname, recipeitem, fields)
recipe = {"moreblocks:panel_" .. subname, "moreblocks:panel_" .. subname, "moreblocks:panel_" .. subname},
})
end