forked from VoxeLibre/VoxeLibre
Compare commits
2 Commits
master
...
item_frame
Author | SHA1 | Date |
---|---|---|
Henry Behrendt | c2dbcedbd3 | |
Henry Behrendt | afe1206f3d |
|
@ -89,6 +89,26 @@ local remove_item_entity = function(pos, node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function setRotation(pos, node, meta, rotate)
|
||||||
|
if node.name == "mcl_itemframes:item_frame" then
|
||||||
|
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do
|
||||||
|
local entity = obj:get_luaentity()
|
||||||
|
if entity and (entity.name == "mcl_itemframes:item" or entity.name == "mcl_itemframes:map") then
|
||||||
|
local rotation = meta:get_int("rotation") or 0
|
||||||
|
if rotate then
|
||||||
|
rotation = (rotation +1) % 8
|
||||||
|
meta:set_int("rotation", rotation)
|
||||||
|
end
|
||||||
|
local r = obj:get_rotation()
|
||||||
|
--* `get_rotation()`: returns the rotation, a vector (radians)
|
||||||
|
r.z = math.pi / ((entity.name == "mcl_itemframes:item") and 4 or 2) * rotation
|
||||||
|
obj:set_rotation(r)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local update_item_entity = function(pos, node, param2)
|
local update_item_entity = function(pos, node, param2)
|
||||||
remove_item_entity(pos, node)
|
remove_item_entity(pos, node)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
@ -122,10 +142,12 @@ local update_item_entity = function(pos, node, param2)
|
||||||
lua:_update_texture()
|
lua:_update_texture()
|
||||||
if node.name == "mcl_itemframes:item_frame" then
|
if node.name == "mcl_itemframes:item_frame" then
|
||||||
e:set_yaw(yaw)
|
e:set_yaw(yaw)
|
||||||
|
setRotation(pos, node, meta)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local e = minetest.add_entity(pos, "mcl_itemframes:map", map_id)
|
local e = minetest.add_entity(pos, "mcl_itemframes:map", map_id)
|
||||||
e:set_yaw(yaw)
|
e:set_yaw(yaw)
|
||||||
|
setRotation(pos, node, meta)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -135,15 +157,18 @@ local drop_item = function(pos, node, meta, clicker)
|
||||||
if clicker and clicker:is_player() then
|
if clicker and clicker:is_player() then
|
||||||
cname = clicker:get_player_name()
|
cname = clicker:get_player_name()
|
||||||
end
|
end
|
||||||
|
local res = false
|
||||||
if node.name == "mcl_itemframes:item_frame" and not minetest.is_creative_enabled(cname) then
|
if node.name == "mcl_itemframes:item_frame" and not minetest.is_creative_enabled(cname) then
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local item = inv:get_stack("main", 1)
|
local item = inv:get_stack("main", 1)
|
||||||
if not item:is_empty() then
|
if not item:is_empty() then
|
||||||
minetest.add_item(pos, item)
|
minetest.add_item(pos, item)
|
||||||
|
res = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
meta:set_string("infotext", "")
|
meta:set_string("infotext", "")
|
||||||
remove_item_entity(pos, node)
|
remove_item_entity(pos, node)
|
||||||
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node("mcl_itemframes:item_frame",{
|
minetest.register_node("mcl_itemframes:item_frame",{
|
||||||
|
@ -210,36 +235,33 @@ minetest.register_node("mcl_itemframes:item_frame",{
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
drop_item(pos, node, meta, clicker)
|
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
if itemstack:is_empty() then
|
if inv:is_empty("main") then
|
||||||
remove_item_entity(pos, node)
|
if itemstack:is_empty() then return itemstack end --nothing to do
|
||||||
meta:set_string("infotext", "")
|
local put_itemstack = ItemStack(itemstack)
|
||||||
inv:set_stack("main", 1, "")
|
put_itemstack:set_count(1)
|
||||||
|
local itemname = put_itemstack:get_name()
|
||||||
|
if minetest.get_item_group(itemname, "compass") > 0 then
|
||||||
|
put_itemstack:set_name("mcl_compass:" .. mcl_compass.get_compass_image(pos, minetest.dir_to_yaw(minetest.facedir_to_dir(node.param2))))
|
||||||
|
end
|
||||||
|
if minetest.get_item_group(itemname, "clock") > 0 then
|
||||||
|
minetest.get_node_timer(pos):start(1.0)
|
||||||
|
end
|
||||||
|
inv:set_stack("main", 1, put_itemstack)
|
||||||
|
update_item_entity(pos, node)
|
||||||
|
-- Add node infotext when item has been named
|
||||||
|
local imeta = itemstack:get_meta()
|
||||||
|
local iname = imeta:get_string("name")
|
||||||
|
if iname then
|
||||||
|
meta:set_string("infotext", iname)
|
||||||
|
end
|
||||||
|
if not minetest.is_creative_enabled(clicker:get_player_name()) then
|
||||||
|
itemstack:take_item()
|
||||||
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
|
else
|
||||||
|
setRotation(pos, node, meta, true)
|
||||||
end
|
end
|
||||||
local put_itemstack = ItemStack(itemstack)
|
|
||||||
put_itemstack:set_count(1)
|
|
||||||
local itemname = put_itemstack:get_name()
|
|
||||||
if minetest.get_item_group(itemname, "compass") > 0 then
|
|
||||||
put_itemstack:set_name("mcl_compass:" .. mcl_compass.get_compass_image(pos, minetest.dir_to_yaw(minetest.facedir_to_dir(node.param2))))
|
|
||||||
end
|
|
||||||
if minetest.get_item_group(itemname, "clock") > 0 then
|
|
||||||
minetest.get_node_timer(pos):start(1.0)
|
|
||||||
end
|
|
||||||
inv:set_stack("main", 1, put_itemstack)
|
|
||||||
update_item_entity(pos, node)
|
|
||||||
-- Add node infotext when item has been named
|
|
||||||
local imeta = itemstack:get_meta()
|
|
||||||
local iname = imeta:get_string("name")
|
|
||||||
if iname then
|
|
||||||
meta:set_string("infotext", iname)
|
|
||||||
end
|
|
||||||
|
|
||||||
if not minetest.is_creative_enabled(clicker:get_player_name()) then
|
|
||||||
itemstack:take_item()
|
|
||||||
end
|
|
||||||
return itemstack
|
|
||||||
end,
|
end,
|
||||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
|
@ -268,6 +290,17 @@ minetest.register_node("mcl_itemframes:item_frame",{
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
can_dig = function(pos, clicker)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
if drop_item(pos, node, meta, clicker) then
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
meta:set_string("infotext", "")
|
||||||
|
inv:set_stack("main", 1, "")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end,
|
||||||
on_destruct = function(pos)
|
on_destruct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
|
|
Loading…
Reference in New Issue