mirror of
https://github.com/minefaco/stripped_tree.git
synced 2024-10-04 00:33:10 +02:00
Added chiseling machine
This commit is contained in:
parent
31df09522a
commit
b78f2d5664
95
chiseling_machine.lua
Normal file
95
chiseling_machine.lua
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
local max_stack = tonumber(minetest.settings:get("default_stack_max"))
|
||||||
|
--*************************************************************************
|
||||||
|
minetest.register_node("stripped_tree:chiseling_machine", {
|
||||||
|
description = "Rightclick me!",
|
||||||
|
tiles = {"chiseling_machine.png", "chiseling_machine.png", "chiseling_machine_side.png", "chiseling_machine_side.png","chiseling_machine_side.png", "chiseling_machine_side.png"},
|
||||||
|
groups = {cracky = 1},
|
||||||
|
after_place_node = function(pos, placer)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("formspec",
|
||||||
|
"size[8,9]"..
|
||||||
|
"label[0,0;Chiseling Machine]"..
|
||||||
|
"image[2,2;1,1;chisel.png]"..
|
||||||
|
"list[current_name;src;2,1;1,1;]"..
|
||||||
|
"list[current_name;dst;5,1;2,2;]"..
|
||||||
|
"list[current_player;main;0,5;8,4;]"..
|
||||||
|
"listring[current_name;dst]"..
|
||||||
|
"listring[current_player;main]"..
|
||||||
|
"listring[current_name;src]"..
|
||||||
|
"listring[current_player;main]"
|
||||||
|
)
|
||||||
|
end,
|
||||||
|
on_construct = function(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("formspec", formspec)
|
||||||
|
meta:set_string("infotext", machine_name)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
inv:set_size("src", 1)
|
||||||
|
inv:set_size("dst", 2)
|
||||||
|
meta:set_int("elapsed", 0)
|
||||||
|
meta:set_int("cook_time", 0)
|
||||||
|
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_put = function(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
-- start timer function, it will sort out whether furnace can burn or not.
|
||||||
|
minetest.get_node_timer(pos):start(1.0)
|
||||||
|
local stack = inv:get_stack("src", 1)
|
||||||
|
local nodename = stack:get_name()
|
||||||
|
local count = stack:get_count()
|
||||||
|
local mod_name, node_name = unpack(nodename:split(":"))
|
||||||
|
local has_stripped = minetest.registered_nodes[mod_name..":".."stripped_"..node_name]
|
||||||
|
local dstcount = inv:get_stack("dst",1):get_count()
|
||||||
|
if has_stripped and dstcount < max_stack then
|
||||||
|
minetest.chat_send_all(dstcount)
|
||||||
|
local stripped =mod_name..":".."stripped_"..node_name
|
||||||
|
inv:add_item("dst", stripped.." "..count)
|
||||||
|
inv:add_item("dst", "default:tree_bark "..count.."")
|
||||||
|
inv:remove_item("src", stack)
|
||||||
|
end
|
||||||
|
|
||||||
|
end,
|
||||||
|
|
||||||
|
on_receive_fields = function(pos, formname, fields, player)
|
||||||
|
if fields.quit then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
print(fields.x)
|
||||||
|
end,
|
||||||
|
|
||||||
|
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
|
if pos then
|
||||||
|
return count
|
||||||
|
end
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
--[[
|
||||||
|
minetest.register_node("stripped_tree:chiseling_machine", {
|
||||||
|
description = "Chiseling machine for trees",
|
||||||
|
tiles = {
|
||||||
|
"chiseling_machine.png"
|
||||||
|
},
|
||||||
|
groups = {choppy = 2, oddly_breakable_by_hand = 1},
|
||||||
|
sounds = default.node_sound_wood_defaults(),
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
on_rightclick = function(pos,node,clicker,itemstack)
|
||||||
|
minetest.chat_send_all("todo correcto")
|
||||||
|
formspec(pos)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
]]--
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "stripped_tree:chiseling_machine",
|
||||||
|
recipe = {
|
||||||
|
{"group:wood","default:diamond","group:wood"},
|
||||||
|
{"group:wood","stripped_tree:chisel","group:wood"},
|
||||||
|
{"group:wood", "group:wood","group:wood"},
|
||||||
|
},
|
||||||
|
})
|
86
functions.lua
Normal file
86
functions.lua
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
stripped_tree = {}
|
||||||
|
--Select between chisel tool or axes.
|
||||||
|
stripped_tree.ENABLE_CHISEL = true
|
||||||
|
local creative_mode = minetest.settings:get_bool("creative_mode")
|
||||||
|
|
||||||
|
--Function to verify that stripped tree trunk exists
|
||||||
|
stripped_tree.has_stripped = function(pos)
|
||||||
|
local node = minetest.get_node(pos).name or pos
|
||||||
|
local mod_name, node_name = unpack(node:split(":"))
|
||||||
|
local has_stripped = minetest.registered_nodes[mod_name..":".."stripped_"..node_name]
|
||||||
|
return has_stripped
|
||||||
|
end
|
||||||
|
|
||||||
|
--Function to swap nodes
|
||||||
|
stripped_tree.swap_node = function(pos,user,creative_mode)
|
||||||
|
local old_node = minetest.get_node(pos)
|
||||||
|
local stripped =mod_name..":".."stripped_"..node_name
|
||||||
|
minetest.swap_node(pos,{name=stripped,param2=old_node.param2})
|
||||||
|
--itemstack:add_wear(65535 / 299) this is not useful at moment.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
--function to register nodes
|
||||||
|
function stripped_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,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = mod_name..":"..name,
|
||||||
|
recipe = {{"","default:tree_bark",""},
|
||||||
|
{"default:tree_bark",mod_name..":stripped_" .. name,"default:tree_bark"},
|
||||||
|
{"","default:tree_bark",""}}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--function to override axes
|
||||||
|
if stripped_tree.ENABLE_CHISEL ~= true then
|
||||||
|
function stripped_tree.register_axes(mod_n,axe_types)
|
||||||
|
for _, axe_name in ipairs(axe_types) do
|
||||||
|
minetest.override_item(mod_n..":" .. 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
|
||||||
|
|
||||||
|
if stripped_tree.has_stripped(pos) then
|
||||||
|
stripped_tree.swap_node(pos,user,creative_mode)
|
||||||
|
end
|
||||||
|
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
80
init.lua
Normal file
80
init.lua
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- get modpath
|
||||||
|
local mpath = minetest.get_modpath("stripped_tree")
|
||||||
|
|
||||||
|
-- load functions
|
||||||
|
dofile(mpath .. "/functions.lua")
|
||||||
|
|
||||||
|
--load default
|
||||||
|
dofile(mpath .. "/default.lua")
|
||||||
|
dofile(mpath .. "/chiseling_machine.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
|
||||||
|
|
||||||
|
if minetest.get_modpath("moreores") then
|
||||||
|
dofile(mpath .. "/moreores.lua")
|
||||||
|
end
|
||||||
|
|
||||||
|
if stripped_tree.ENABLE_CHISEL then
|
||||||
|
|
||||||
|
minetest.register_tool("stripped_tree:chisel", {
|
||||||
|
description = "Chisel for tree trunks",
|
||||||
|
inventory_image = "chisel.png",
|
||||||
|
wield_image = "chisel.png",
|
||||||
|
sound = {breaks = "default_tool_breaks"},
|
||||||
|
stack_max = 1,
|
||||||
|
on_use = 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
|
||||||
|
local mod_name, node_name = unpack(node:split(":"))
|
||||||
|
local has_stripped = minetest.registered_nodes[mod_name..":".."stripped_"..node_name]
|
||||||
|
|
||||||
|
if has_stripped then
|
||||||
|
local stripped = mod_name..":".."stripped_"..node_name
|
||||||
|
minetest.swap_node(pos,{name=stripped})
|
||||||
|
|
||||||
|
if not minetest.settings:get_bool("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
|
||||||
|
itemstack:add_wear(65535 / 299) -- 300 uses
|
||||||
|
end
|
||||||
|
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "stripped_tree:chisel",
|
||||||
|
recipe = {{"","default:steel_ingot",""},
|
||||||
|
{"","screwdriver:screwdriver",""},
|
||||||
|
{"","",""}}
|
||||||
|
})
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user