Item Frame : some code cleaning
This commit is contained in:
parent
f8b6cfe365
commit
55ed70b08c
128
itemframe.lua
128
itemframe.lua
@ -1,4 +1,4 @@
|
||||
local tmp = {}
|
||||
local itemframe, tmp = {}, {}
|
||||
screwdriver = screwdriver or {}
|
||||
|
||||
local function remove_item(pos, node)
|
||||
@ -49,6 +49,75 @@ local function drop_item(pos, node)
|
||||
timer:stop()
|
||||
end
|
||||
|
||||
function itemframe.after_place(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
|
||||
|
||||
function itemframe.timer(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local num = #minetest.get_objects_inside_radius(pos, 0.5)
|
||||
|
||||
if num == 0 and meta:get_string("item") ~= "" then
|
||||
update_item(pos, node)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function itemframe.rightclick(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
|
||||
|
||||
drop_item(pos, node)
|
||||
local itemstring = itemstack:take_item():get_name()
|
||||
meta:set_string("item", itemstring)
|
||||
update_item(pos, node)
|
||||
|
||||
return itemstack
|
||||
end
|
||||
|
||||
function itemframe.punch(pos, node, puncher)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local player = puncher:get_player_name()
|
||||
local owner = meta:get_string("owner")
|
||||
|
||||
if player ~= owner then return end
|
||||
drop_item(pos, node)
|
||||
end
|
||||
|
||||
function itemframe.dig(pos, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local pname = player:get_player_name()
|
||||
local owner = meta:get_string("owner")
|
||||
|
||||
return player and pname == owner
|
||||
end
|
||||
|
||||
minetest.register_alias("xdecor:frame", "xdecor:itemframe")
|
||||
|
||||
xdecor.register("itemframe", {
|
||||
description = "Item Frame",
|
||||
groups = {choppy=3, oddly_breakable_by_hand=2, flammable=3},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_rotate = screwdriver.disallow,
|
||||
sunlight_propagates = true,
|
||||
inventory_image = "xdecor_itemframe.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_itemframe.png"},
|
||||
after_place_node = itemframe.after_place,
|
||||
on_timer = itemframe.timer,
|
||||
on_rightclick = itemframe.rightclick,
|
||||
on_punch = itemframe.punch,
|
||||
can_dig = itemframe.dig,
|
||||
after_destruct = remove_item
|
||||
})
|
||||
|
||||
minetest.register_entity("xdecor:f_item", {
|
||||
visual = "wielditem",
|
||||
visual_size = {x=0.33, y=0.33},
|
||||
@ -80,60 +149,3 @@ minetest.register_entity("xdecor:f_item", {
|
||||
end
|
||||
})
|
||||
|
||||
xdecor.register("frame", {
|
||||
description = "Item Frame",
|
||||
groups = {choppy=2},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_rotate = screwdriver.disallow,
|
||||
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"},
|
||||
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_timer = function(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local num = #minetest.get_objects_inside_radius(pos, 0.5)
|
||||
|
||||
if num == 0 and meta:get_string("item") ~= "" then
|
||||
update_item(pos, node)
|
||||
end
|
||||
return true
|
||||
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
|
||||
|
||||
drop_item(pos, node)
|
||||
local itemstring = itemstack:take_item():get_name()
|
||||
meta:set_string("item", itemstring)
|
||||
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 ~= owner then return end
|
||||
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")
|
||||
|
||||
return player and pname == owner
|
||||
end,
|
||||
after_destruct = remove_item
|
||||
})
|
||||
|
||||
|
@ -436,6 +436,7 @@ xdecor.register_hard_node("moonbrick", "Moon Brick", {})
|
||||
xdecor.register_hard_node("stone_tile", "Stone Tile", {})
|
||||
xdecor.register_hard_node("stone_rune", "Runestone", {})
|
||||
xdecor.register_hard_node("packed_ice", "Packed Ice", {
|
||||
groups = {cracky=1, puts_out_fire=1},
|
||||
sounds = default.node_sound_glass_defaults()
|
||||
})
|
||||
xdecor.register_hard_node("wood_tile", "Wooden Tile", {
|
||||
|
@ -146,7 +146,7 @@ minetest.register_craft({
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "xdecor:frame",
|
||||
output = "xdecor:itemframe",
|
||||
recipe = {
|
||||
{"group:stick", "group:stick", "group:stick"},
|
||||
{"group:stick", "default:paper", "group:stick"},
|
||||
|
Before Width: | Height: | Size: 224 B After Width: | Height: | Size: 224 B |
Loading…
Reference in New Issue
Block a user