diff --git a/default.lua b/default.lua new file mode 100644 index 0000000..1260aca --- /dev/null +++ b/default.lua @@ -0,0 +1,40 @@ +--Register tree bark +minetest.register_craftitem(":default:tree_bark", { + description = "Tree bark", + inventory_image = "tree_bark.png", + groups = {not_in_creative_inventory = 1, wood = 1} +}) +--register bark as fuel +minetest.register_craft({ + type = "fuel", + recipe = "default:tree_bark", + burntime = 15, +}) + + +--Register stripped trees +local mod_name = "default" +local trunk_names = { + "tree", + "jungletree", + "aspen_tree", + "acacia_tree", + "pine_tree", +} + +chisel_tree.register_trunk(mod_name,trunk_names) + + +--Register axes +local axe_types = { +"axe_wood", +"axe_stone", +"axe_bronze", +"axe_steel", +"axe_mese", +"axe_diamond", +} + +chisel_tree.trunk_names(trunk_names) +chisel_tree.register_axes(mod_name,axe_types) + diff --git a/functions.lua b/functions.lua new file mode 100644 index 0000000..80e86e4 --- /dev/null +++ b/functions.lua @@ -0,0 +1,76 @@ +chisel_tree = {} + +--function to register nodes +function chisel_tree.register_trunk(mod_name,trunk_names) + for _, name in ipairs(trunk_names) do + minetest.register_node(":"..mod_name..":stripped_" .. name, { + description = "Stripped "..name, + tiles = { + "stripped_"..mod_name.."_"..name.."_top.png", + "stripped_"..mod_name.."_"..name.."_top.png", + "stripped_"..mod_name.."_"..name..".png" + }, + groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory = 1}, + sounds = default.node_sound_wood_defaults(), + paramtype2 = "facedir", + on_place = minetest.rotate_node, + }) + end +end + +function chisel_tree.trunk_names(trunk_list) + trunk_names = trunk_list +end + +--function to override axes +function chisel_tree.register_axes(mod_name,axe_types) + for _, axe_name in ipairs(axe_types) do + minetest.override_item(mod_name..":" .. axe_name, { + on_place = function(itemstack, user, pointed_thing) + + if pointed_thing.type ~= "node" then + return + end + + local pos = pointed_thing.under + local pname = user:get_player_name() + + if minetest.is_protected(pos, pname) then + minetest.record_protection_violation(pos, pname) + return + end + + local node = minetest.get_node(pos).name + + for _, n in ipairs(trunk_names) do + + local tree = mod_name..":"..n + if tree==node then + local old_node = minetest.get_node(pos) + minetest.swap_node(pos, {name = mod_name..":".."stripped_"..n, param2 = old_node.param2}) + itemstack:add_wear(65535 / 299) -- 300 uses + + if not creative_mode then + local inv = user:get_inventory() + --check for room in inv, if not, drop item + if inv:room_for_item("main", "default:tree_bark") then + inv:add_item("main", {name="default:tree_bark"}) + else + minetest.add_item(pos, "default:tree_bark") + end + end + + return itemstack + end + end + + end, + }) + end +end +--register alias to support old tool +minetest.register_alias("chisel_tree:chisel", "default:axe_steel") + + + + diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..edbd437 --- /dev/null +++ b/init.lua @@ -0,0 +1,20 @@ +-- get modpath +local mpath = minetest.get_modpath("chisel_tree") + +-- load functions +dofile(mpath .. "/functions.lua") + +--load default +dofile(mpath .. "/default.lua") + +--load optional dependencies +if minetest.get_modpath("moretrees") then + dofile(mpath .. "/moretrees.lua") +end +--[[ +if minetest.get_modpath("ethereal") then + dofile(mpath .. "/ethereal.lua") +end]]-- + + + diff --git a/moretrees.lua b/moretrees.lua new file mode 100644 index 0000000..b9ebdce --- /dev/null +++ b/moretrees.lua @@ -0,0 +1,22 @@ +--Register stripped trees +local mod_name = "moretrees" +local trunk_names = { + "beech_trunk", + "apple_tree_trunk", + "oak_trunk", + "sequoia_trunk", + "birch_trunk", + "palm_trunk", + "date_palm_trunk", + "spruce_trunk", + "cedar_trunk", + "poplar_trunk", + "willow_trunk", + "rubber_tree_trunk", + "fir_trunk", + "jungletree_trunk", + +} + +chisel_tree.register_trunk(mod_name,trunk_names) +