Style cleaning + better repairable tools checking

This commit is contained in:
Jean-Patrick Guerrero 2016-02-15 19:32:49 +01:00
parent 231caefc5a
commit c7e77cbf06
7 changed files with 137 additions and 181 deletions

View File

@ -24,17 +24,15 @@ minetest.register_craftitem("xdecor:bowl_soup", {
minetest.register_tool("xdecor:flint_steel", {
description = "Flint & Steel",
inventory_image = "xdecor_flint_steel.png",
tool_capabilities = {
groupcaps = { igniter = {uses=10, maxlevel=1} }
},
on_use = function(itemstack, user, pointed_thing)
local player = user:get_player_name()
if pointed_thing.type == "node" and
minetest.get_node(pointed_thing.above).name == "air" then
if not minetest.is_protected(pointed_thing.above, player) then
minetest.set_node(pointed_thing.above, {name="xdecor:fire"})
local pt = pointed_thing
if pt.type == "node" and minetest.get_node(pt.above).name == "air" then
if not minetest.is_protected(pt.above, player) then
minetest.set_node(pt.above, {name="xdecor:fire"})
else
minetest.chat_send_player(player, "This area is protected.")
minetest.chat_send_player(player, "[!] This area is protected")
end
end

View File

@ -132,11 +132,9 @@ end
xdecor.register("enchantment_table", {
description = "Enchantment Table",
tiles = {
"xdecor_enchantment_top.png", "xdecor_enchantment_bottom.png",
"xdecor_enchantment_side.png", "xdecor_enchantment_side.png",
"xdecor_enchantment_side.png", "xdecor_enchantment_side.png"
},
tiles = {"xdecor_enchantment_top.png", "xdecor_enchantment_bottom.png",
"xdecor_enchantment_side.png", "xdecor_enchantment_side.png",
"xdecor_enchantment_side.png", "xdecor_enchantment_side.png"},
groups = {cracky=1, oddly_breakable_by_hand=1, level=1},
sounds = default.node_sound_stone_defaults(),
on_rotate = screwdriver.rotate_simple,

View File

@ -1,6 +1,51 @@
local tmp = {}
local tmp, itemframe = {}, {}
screwdriver = screwdriver or {}
function itemframe:remove_item(pos, node)
local objs = minetest.get_objects_inside_radius(pos, 0.5)
if not objs then return end
for _, obj in pairs(objs) do
if obj and obj:get_luaentity() and
obj:get_luaentity().name == "xdecor:f_item" then
obj:remove()
end
end
end
local facedir = {
[0] = {x=0, y=0, z=1}, {x=1, y=0, z=0},
{x=0, y=0, z=-1},{x=-1, y=0, z=0}
}
function itemframe:update_item(pos, node)
self:remove_item(pos, node)
local meta = minetest.get_meta(pos)
local itemstring = meta:get_string("item")
local posad = facedir[node.param2]
if not posad or itemstring == "" then return end
pos.x = pos.x + posad.x * 6.5/16
pos.y = pos.y + posad.y * 6.5/16
pos.z = pos.z + posad.z * 6.5/16
tmp.nodename = node.name
tmp.texture = ItemStack(itemstring):get_name()
local entity = minetest.add_entity(pos, "xdecor:f_item")
local yaw = math.pi*2 - node.param2 * math.pi/2
entity:setyaw(yaw)
end
function itemframe:drop_item(pos, node)
local meta = minetest.get_meta(pos)
local item = meta:get_string("item")
if item == "" then return end
minetest.add_item(pos, item)
meta:set_string("item", "")
self:remove_item(pos, node)
end
minetest.register_entity("xdecor:f_item", {
hp_max = 1,
visual = "wielditem",
@ -33,51 +78,6 @@ minetest.register_entity("xdecor:f_item", {
end
})
local remove_item = function(pos, node)
local objs = minetest.get_objects_inside_radius(pos, 0.5)
if not objs then return end
for _, obj in pairs(objs) do
if obj and obj:get_luaentity() and
obj:get_luaentity().name == "xdecor:f_item" then
obj:remove()
end
end
end
local facedir = {}
facedir[0] = {x=0, y=0, z=1}
facedir[1] = {x=1, y=0, z=0}
facedir[2] = {x=0, y=0, z=-1}
facedir[3] = {x=-1, y=0, z=0}
local update_item = function(pos, node)
remove_item(pos, node)
local meta = minetest.get_meta(pos)
local itemstring = meta:get_string("item")
local posad = facedir[node.param2]
if not posad or itemstring == "" then return end
pos.x = pos.x + posad.x * 6.5/16
pos.y = pos.y + posad.y * 6.5/16
pos.z = pos.z + posad.z * 6.5/16
tmp.nodename = node.name
tmp.texture = ItemStack(itemstring):get_name()
local entity = minetest.add_entity(pos, "xdecor:f_item")
local yaw = math.pi*2 - node.param2 * math.pi/2
entity:setyaw(yaw)
end
local drop_item = function(pos, node)
local meta = minetest.get_meta(pos)
if meta:get_string("item") == "" then return end
minetest.add_item(pos, meta:get_string("item"))
meta:set_string("item", "")
remove_item(pos, node)
end
xdecor.register("frame", {
description = "Item Frame",
groups = {choppy=3, oddly_breakable_by_hand=2},
@ -86,50 +86,43 @@ xdecor.register("frame", {
sunlight_propagates = true,
inventory_image = "xdecor_frame.png",
node_box = xdecor.nodebox.slab_z(0.9375),
tiles = {
"xdecor_wood.png", "xdecor_wood.png", "xdecor_wood.png",
"xdecor_wood.png", "xdecor_wood.png", "xdecor_frame.png"
},
tiles = {"xdecor_wood.png", "xdecor_wood.png", "xdecor_wood.png",
"xdecor_wood.png", "xdecor_wood.png", "xdecor_frame.png"},
after_place_node = function(pos, placer, itemstack)
local meta = minetest.get_meta(pos)
local name = placer:get_player_name()
meta:set_string("owner", name)
meta:set_string("infotext", "Item Frame (owned by "..name..")")
end,
on_rightclick = function(pos, node, clicker, itemstack)
local meta = minetest.get_meta(pos)
local player = clicker:get_player_name()
local owner = meta:get_string("owner")
if player ~= owner or not itemstack then return end
if player ~= meta:get_string("owner") or not itemstack then
return
end
drop_item(pos, node)
itemframe:drop_item(pos, node)
local itemstring = itemstack:take_item():to_string()
meta:set_string("item", itemstring)
update_item(pos, node)
itemframe:update_item(pos, node)
return itemstack
end,
on_punch = function(pos, node, puncher)
local meta = minetest.get_meta(pos)
local player = puncher:get_player_name()
local owner = meta:get_string("owner")
if player ~= meta:get_string("owner") then return end
drop_item(pos, node)
if player ~= owner then return end
itemframe:drop_item(pos, node)
end,
can_dig = function(pos, player)
local meta = minetest.get_meta(pos)
local pname = player:get_player_name()
local owner = meta:get_string("owner")
if not player or player:get_player_name() ~= owner then
return false
end
return true
return player and pname == owner
end,
after_destruct = remove_item
after_destruct = itemframe:remove_item(pos, node)
})
minetest.register_abm({
@ -138,6 +131,6 @@ minetest.register_abm({
action = function(pos, node)
local num = #minetest.get_objects_inside_radius(pos, 0.5)
if num > 0 then return end
update_item(pos, node)
itemframe:update_item(pos, node)
end
})

View File

@ -114,11 +114,9 @@ end
xdecor.register("mailbox", {
description = "Mailbox",
tiles = {
"xdecor_mailbox_top.png", "xdecor_mailbox_bottom.png",
"xdecor_mailbox_side.png", "xdecor_mailbox_side.png",
"xdecor_mailbox.png", "xdecor_mailbox.png",
},
tiles = {"xdecor_mailbox_top.png", "xdecor_mailbox_bottom.png",
"xdecor_mailbox_side.png", "xdecor_mailbox_side.png",
"xdecor_mailbox.png", "xdecor_mailbox.png"},
groups = {cracky=3, oddly_breakable_by_hand=1},
on_rotate = screwdriver.rotate_simple,
can_dig = mailbox.dig,

124
nodes.lua
View File

@ -9,11 +9,9 @@ xpanes.register_pane("bamboo_frame", {
inventory_image = "xdecor_bamboo_frame.png",
wield_image = "xdecor_bamboo_frame.png",
groups = {choppy=3, oddly_breakable_by_hand=2, pane=1, flammable=2},
recipe = {
{"default:papyrus", "default:papyrus", "default:papyrus"},
{"default:papyrus", "farming:cotton", "default:papyrus"},
{"default:papyrus", "default:papyrus", "default:papyrus"}
}
recipe = { {"default:papyrus", "default:papyrus", "default:papyrus"},
{"default:papyrus", "farming:cotton", "default:papyrus"},
{"default:papyrus", "default:papyrus", "default:papyrus"} }
})
xdecor.register("baricade", {
@ -43,11 +41,9 @@ xdecor.register("cabinet", {
groups = {choppy=2, oddly_breakable_by_hand=1, flammable=3},
sounds = default.node_sound_wood_defaults(),
on_rotate = screwdriver.rotate_simple,
tiles = {
"xdecor_cabinet_sides.png", "xdecor_cabinet_sides.png",
"xdecor_cabinet_sides.png", "xdecor_cabinet_sides.png",
"xdecor_cabinet_sides.png", "xdecor_cabinet_front.png"
}
tiles = {"xdecor_cabinet_sides.png", "xdecor_cabinet_sides.png",
"xdecor_cabinet_sides.png", "xdecor_cabinet_sides.png",
"xdecor_cabinet_sides.png", "xdecor_cabinet_front.png"}
})
xdecor.register("cabinet_half", {
@ -57,11 +53,9 @@ xdecor.register("cabinet_half", {
groups = {choppy=3, oddly_breakable_by_hand=2, flammable=3},
sounds = default.node_sound_wood_defaults(),
node_box = xdecor.nodebox.slab_y(0.5, 0.5),
tiles = {
"xdecor_cabinet_sides.png", "xdecor_cabinet_sides.png",
"xdecor_half_cabinet_sides.png", "xdecor_half_cabinet_sides.png",
"xdecor_half_cabinet_sides.png", "xdecor_half_cabinet_front.png"
}
tiles = {"xdecor_cabinet_sides.png", "xdecor_cabinet_sides.png",
"xdecor_half_cabinet_sides.png", "xdecor_half_cabinet_sides.png",
"xdecor_half_cabinet_sides.png", "xdecor_half_cabinet_front.png"}
})
xdecor.register("candle", {
@ -74,13 +68,12 @@ xdecor.register("candle", {
legacy_wallmounted = true,
walkable = false,
groups = {dig_immediate=3, attached_node=1},
tiles = {
{ name = "xdecor_candle_floor.png",
animation = {type="vertical_frames", length=1.5} },
{ name = "xdecor_candle_ceiling.png",
animation = {type="vertical_frames", length=1.5} },
{ name = "xdecor_candle_wall.png",
animation = {type="vertical_frames", length=1.5} }
tiles = {{name = "xdecor_candle_floor.png",
animation = {type="vertical_frames", length=1.5}},
{name = "xdecor_candle_ceiling.png",
animation = {type="vertical_frames", length=1.5}},
{name = "xdecor_candle_wall.png",
animation = {type="vertical_frames", length=1.5}}
},
selection_box = {
type = "wallmounted",
@ -120,11 +113,9 @@ xpanes.register_pane("chainlink", {
inventory_image = "xdecor_chainlink.png",
wield_image = "xdecor_chainlink.png",
groups = {cracky=3, oddly_breakable_by_hand=2, pane=1},
recipe = {
{"default:steel_ingot", "", "default:steel_ingot"},
{"", "default:steel_ingot", ""},
{"default:steel_ingot", "", "default:steel_ingot"}
}
recipe = { {"default:steel_ingot", "", "default:steel_ingot"},
{"", "default:steel_ingot", ""},
{"default:steel_ingot", "", "default:steel_ingot"} }
})
-- The following nodedef is licensed under WTFPL for granting a possible re-use
@ -177,10 +168,8 @@ for _, c in pairs({"red"}) do -- Add more curtains colors simply here.
minetest.register_craft({
output = "xdecor:curtain_"..c.." 4",
recipe = {
{"", "wool:"..c, ""},
{"", "wool:"..c, ""}
}
recipe = { {"", "wool:"..c, ""},
{"", "wool:"..c, ""} }
})
end
@ -216,8 +205,7 @@ xdecor.register("cushion", {
xdecor.register("cushion_block", {
tiles = {"xdecor_cushion.png"},
groups = {snappy=3, flammable=3, fall_damage_add_percent=-75, not_in_creative_inventory=1},
drop = "xdecor:cushion 2"
groups = {snappy=3, flammable=3, fall_damage_add_percent=-75, not_in_creative_inventory=1}
})
local function door_access(door) return door:find("prison") end
@ -250,11 +238,9 @@ xdecor.register("empty_shelf", {
xdecor.register("enderchest", {
description = "Ender Chest",
tiles = {
"xdecor_enderchest_top.png", "xdecor_enderchest_top.png",
"xdecor_enderchest_side.png", "xdecor_enderchest_side.png",
"xdecor_enderchest_side.png", "xdecor_enderchest_front.png"
},
tiles = {"xdecor_enderchest_top.png", "xdecor_enderchest_top.png",
"xdecor_enderchest_side.png", "xdecor_enderchest_side.png",
"xdecor_enderchest_side.png", "xdecor_enderchest_front.png"},
groups = {cracky=1, choppy=1, oddly_breakable_by_hand=1},
sounds = default.node_sound_stone_defaults(),
on_rotate = screwdriver.rotate_simple,
@ -280,15 +266,11 @@ xdecor.register("fire", {
drawtype = "plantlike",
light_source = 14,
walkable = false,
tiles = {
{ name = "xdecor_fire_anim.png",
animation = {type="vertical_frames", length=1.5} }
},
tiles = {{ name = "xdecor_fire_anim.png",
animation = {type="vertical_frames", length=1.5 }}},
damage_per_second = 4,
drop = "",
selection_box = {
type = "fixed", fixed = {-0.3, -0.5, -0.3, 0.3, -0.3, 0.3}
},
selection_box = xdecor.pixelbox(16, {{4, 0, 4, 8, 3, 8}}),
groups = {dig_immediate=3, hot=3, not_in_creative_inventory=1}
})
@ -317,8 +299,7 @@ xdecor.register("lantern", {
legacy_wallmounted = true,
walkable = false,
groups = {dig_immediate=3, attached_node=1},
tiles = {"xdecor_lantern_floor.png", "xdecor_lantern_ceiling.png",
"xdecor_lantern.png"},
tiles = {"xdecor_lantern_floor.png", "xdecor_lantern_ceiling.png", "xdecor_lantern.png"},
selection_box = {
type = "wallmounted",
wall_top = {-0.25, -0.4, -0.25, 0.25, 0.5, 0.25},
@ -347,10 +328,8 @@ xdecor.register("packed_ice", {
sounds = default.node_sound_glass_defaults()
})
local flowers = {"dandelion_white", "dandelion_yellow", "geranium", "rose",
"tulip", "viola"}
for _, f in pairs(flowers) do
for _, f in pairs({"dandelion_white", "dandelion_yellow", "geranium",
"rose", "tulip", "viola"}) do
xdecor.register("potted_"..f, {
description = string.gsub("Potted Flowers ("..f..")", "_", " "),
walkable = false,
@ -364,10 +343,8 @@ for _, f in pairs(flowers) do
minetest.register_craft({
output = "xdecor:potted_"..f,
recipe = {
{"default:clay_brick", "flowers:"..f, "default:clay_brick"},
{"", "default:clay_brick", ""}
}
recipe = { {"default:clay_brick", "flowers:"..f, "default:clay_brick"},
{"", "default:clay_brick", ""} }
})
end
@ -450,12 +427,11 @@ xpanes.register_pane("rusty_bar", {
inventory_image = "xdecor_rusty_bars.png",
wield_image = "xdecor_rusty_bars.png",
groups = {cracky=3, oddly_breakable_by_hand=2, pane=1},
recipe = {
{"", "default:dirt", ""},
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
}
recipe = { {"", "default:dirt", ""},
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"} }
})
minetest.register_alias("xpanes:rust_bar", "xpanes:rusty_bar")
for i = 1, 15 do
minetest.register_alias("xpanes:rust_bar_"..i, "xpanes:rusty_bar_"..i)
@ -477,10 +453,8 @@ xdecor.register("stonepath", {
selection_box = xdecor.nodebox.slab_y(0.05)
})
local stonish = {"desertstone_tile", "stone_tile", "stone_rune",
"coalstone_tile", "hard_clay"}
for _, t in pairs(stonish) do
for _, t in pairs({"desertstone_tile", "stone_tile", "stone_rune",
"coalstone_tile", "hard_clay"}) do
xdecor.register(t, {
drawtype = "normal",
description = string.gsub(" "..t, "%W%l", string.upper):sub(2):gsub("_", " "),
@ -513,14 +487,12 @@ xdecor.register("tv", {
light_source = 11,
groups = {snappy=3},
on_rotate = screwdriver.rotate_simple,
tiles = {
"xdecor_television_left.png^[transformR270",
"xdecor_television_left.png^[transformR90",
"xdecor_television_left.png^[transformFX",
"xdecor_television_left.png", "xdecor_television_back.png",
{ name = "xdecor_television_front_animated.png",
animation = {type="vertical_frames", length=80.0} }
}
tiles = { "xdecor_television_left.png^[transformR270",
"xdecor_television_left.png^[transformR90",
"xdecor_television_left.png^[transformFX",
"xdecor_television_left.png", "xdecor_television_back.png",
{name = "xdecor_television_front_animated.png",
animation = {type="vertical_frames", length=80.0}} }
})
xpanes.register_pane("wood_frame", {
@ -533,11 +505,9 @@ xpanes.register_pane("wood_frame", {
wield_image = "xdecor_wood_frame.png",
groups = {choppy=3, oddly_breakable_by_hand=2, pane=1, flammable=3},
sounds = default.node_sound_wood_defaults(),
recipe = {
{"group:wood", "group:stick", "group:wood"},
{"group:stick", "group:stick", "group:stick"},
{"group:wood", "group:stick", "group:wood"}
}
recipe = { {"group:wood", "group:stick", "group:wood"},
{"group:stick", "group:stick", "group:stick"},
{"group:wood", "group:stick", "group:wood"} }
})
xdecor.register("woodframed_glass", {

View File

@ -3,7 +3,7 @@ local rope = {}
-- Code by Mirko K. (modified by Temperest, Wulfsdad and kilbith) (License: GPL).
minetest.register_on_punchnode(function(pos, oldnode, digger)
if oldnode.name == "xdecor:rope" then
rope.remove(pos, oldnode, digger, "xdecor:rope")
rope:remove(pos, oldnode, digger, "xdecor:rope")
end
end)
@ -26,7 +26,7 @@ function rope.place(itemstack, _, pointed_thing)
return itemstack
end
function rope.remove(pos, oldnode, digger, rope_name)
function rope:remove(pos, oldnode, digger, rope_name)
local num = 0
local below = {x=pos.x, y=pos.y, z=pos.z}
local digger_inv = digger:get_inventory()
@ -50,9 +50,6 @@ xdecor.register("rope", {
tiles = {"xdecor_rope.png"},
inventory_image = "xdecor_rope_inv.png",
wield_image = "xdecor_rope_inv.png",
selection_box = {
type = "fixed",
fixed = {-0.15, -0.5, -0.15, 0.15, 0.5, 0.15}
},
selection_box = xdecor.pixelbox(8, {{3, 0, 3, 2, 8, 2}}),
on_place = rope.place
})

View File

@ -38,9 +38,12 @@ workbench.defs = {
}
-- Tools allowed to be repaired.
function workbench:repairable_tools(stack)
local tools = [[ pick, axe, shovel, sword, hoe, armor, shield ]]
return tools:find(stack:match(":(%w+)"))
function workbench:repairable(stack)
local tools = {"pick", "axe", "shovel", "sword", "hoe", "armor", "shield"}
for _, t in pairs(tools) do
if stack:find(t) then return true end
end
return false
end
function workbench:get_output(inv, input, name)
@ -136,16 +139,15 @@ function workbench.timer(pos)
inv:set_stack("tool", 1, tool)
inv:set_stack("hammer", 1, hammer)
return true
end
function workbench.put(_, listname, _, stack)
local stackname = stack:get_name()
if (listname == "tool" and stack:get_wear() > 0 and workbench:repairable_tools(stackname)) or
(listname == "input" and minetest.registered_nodes[stackname.."_cube"]) or
(listname == "hammer" and stackname == "xdecor:hammer") or
listname == "storage" then
if (listname == "tool" and stack:get_wear() > 0 and workbench:repairable(stackname)) or
(listname == "input" and minetest.registered_nodes[stackname.."_cube"]) or
(listname == "hammer" and stackname == "xdecor:hammer") or
listname == "storage" then
return stack:get_count()
end
return 0
@ -183,7 +185,9 @@ function workbench.on_take(pos, listname, index, stack)
if listname == "input" then
if stack:get_name() == input:get_name() then
workbench:get_output(inv, input, stack:get_name())
else inv:set_list("forms", {}) end
else
inv:set_list("forms", {})
end
elseif listname == "forms" then
input:take_item(math.ceil(stack:get_count() / workbench.defs[index][2]))
inv:set_stack("input", 1, input)
@ -195,11 +199,9 @@ xdecor.register("workbench", {
description = "Work Bench",
groups = {cracky=2, choppy=2, oddly_breakable_by_hand=1},
sounds = default.node_sound_wood_defaults(),
tiles = {
"xdecor_workbench_top.png", "xdecor_workbench_top.png",
"xdecor_workbench_sides.png", "xdecor_workbench_sides.png",
"xdecor_workbench_front.png", "xdecor_workbench_front.png"
},
tiles = {"xdecor_workbench_top.png", "xdecor_workbench_top.png",
"xdecor_workbench_sides.png", "xdecor_workbench_sides.png",
"xdecor_workbench_front.png", "xdecor_workbench_front.png"},
on_rotate = screwdriver.rotate_simple,
can_dig = workbench.dig,
on_timer = workbench.timer,