forked from MineClone5/MineClone5
Update Fork #9
|
@ -2,7 +2,13 @@ local S = minetest.get_translator(minetest.get_current_modname())
|
|||
|
||||
local VISUAL_SIZE = 0.3
|
||||
|
||||
minetest.register_entity("mcl_itemframes:item",{
|
||||
local vari = {{ "mcl_itemframes:item", "mcl_itemframes:map", "mcl_itemframes:item_frame", S("Item Frame"), S("Can hold an item"), S("Item frames are decorative blocks in which items can be placed."), "mcl_itemframes_itemframe1facedir.obj", "mcl_itemframes_itemframe_background.png", "default_wood.png", "mcl_itemframes_item_frame.png", "mcl_itemframes_item_frame.png", {"itemframes:frame"}},
|
||||
{ "mcl_itemframes:glow_item", "mcl_itemframes:glow_map", "mcl_itemframes:glow_item_frame", S("Glow Item Frame"), S("Can hold an item and glows"), S("Glow Item frames are decorative blocks in which items can be placed."), "extra_mobs_glow_item_frame.obj", "extra_mobs_glow_item_frame_border.png", "extra_mobs_glow_item_frame_border.png", "extra_mobs_glow_item_frame_item.png", "extra_mobs_glow_item_frame.png", {"extra_mobs:glow_frame", "extra_mobs:glow_item_frame"}},
|
||||
}
|
||||
|
||||
for v=1, #vari do
|
||||
local var = vari[v]
|
||||
minetest.register_entity(var[1],{
|
||||
hp_max = 1,
|
||||
visual = "wielditem",
|
||||
visual_size = {x=VISUAL_SIZE, y=VISUAL_SIZE},
|
||||
|
@ -11,6 +17,7 @@ minetest.register_entity("mcl_itemframes:item",{
|
|||
textures = { "blank.png" },
|
||||
_texture = "blank.png",
|
||||
_scale = 1,
|
||||
glow = (v-1)*minetest.LIGHT_MAX,
|
||||
|
||||
on_activate = function(self, staticdata)
|
||||
if staticdata and staticdata ~= "" then
|
||||
|
@ -52,9 +59,9 @@ minetest.register_entity("mcl_itemframes:item",{
|
|||
})
|
||||
end
|
||||
end,
|
||||
})
|
||||
})
|
||||
|
||||
minetest.register_entity("mcl_itemframes:map", {
|
||||
minetest.register_entity(var[2], {
|
||||
initial_properties = {
|
||||
visual = "upright_sprite",
|
||||
visual_size = {x = 1, y = 1},
|
||||
|
@ -73,27 +80,27 @@ minetest.register_entity("mcl_itemframes:map", {
|
|||
get_staticdata = function(self)
|
||||
return self.id
|
||||
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 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 remove_item_entity = function(pos, node)
|
||||
if node.name == "mcl_itemframes:item_frame" then
|
||||
local remove_item_entity = function(pos, node)
|
||||
if node.name == var[3] 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
|
||||
if entity and (entity.name == var[1] or entity.name == var[2]) then
|
||||
obj:remove()
|
||||
end
|
||||
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)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
|
@ -102,7 +109,7 @@ local update_item_entity = function(pos, node, param2)
|
|||
if not param2 then
|
||||
param2 = node.param2
|
||||
end
|
||||
if node.name == "mcl_itemframes:item_frame" then
|
||||
if node.name == var[3] then
|
||||
local posad = facedir[param2]
|
||||
pos.x = pos.x + posad.x*6.5/16
|
||||
pos.y = pos.y + posad.y*6.5/16
|
||||
|
@ -111,7 +118,7 @@ local update_item_entity = function(pos, node, param2)
|
|||
local yaw = math.pi*2 - param2 * math.pi/2
|
||||
local map_id = item:get_meta():get_string("mcl_maps:id")
|
||||
if map_id == "" then
|
||||
local e = minetest.add_entity(pos, "mcl_itemframes:item")
|
||||
local e = minetest.add_entity(pos, var[1])
|
||||
local lua = e:get_luaentity()
|
||||
lua._nodename = node.name
|
||||
local itemname = item:get_name()
|
||||
|
@ -124,22 +131,22 @@ local update_item_entity = function(pos, node, param2)
|
|||
lua._scale = def and def.wield_scale and def.wield_scale.x or 1
|
||||
end
|
||||
lua:_update_texture()
|
||||
if node.name == "mcl_itemframes:item_frame" then
|
||||
if node.name == var[3] then
|
||||
e:set_yaw(yaw)
|
||||
end
|
||||
else
|
||||
local e = minetest.add_entity(pos, "mcl_itemframes:map", map_id)
|
||||
local e = minetest.add_entity(pos, var[2], map_id)
|
||||
e:set_yaw(yaw)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local drop_item = function(pos, node, meta, clicker)
|
||||
local drop_item = function(pos, node, meta, clicker)
|
||||
local cname = ""
|
||||
if clicker and clicker:is_player() then
|
||||
cname = clicker:get_player_name()
|
||||
end
|
||||
if node.name == "mcl_itemframes:item_frame" and not minetest.is_creative_enabled(cname) then
|
||||
if node.name == var[3] and not minetest.is_creative_enabled(cname) then
|
||||
local inv = meta:get_inventory()
|
||||
local item = inv:get_stack("main", 1)
|
||||
if not item:is_empty() then
|
||||
|
@ -148,23 +155,27 @@ local drop_item = function(pos, node, meta, clicker)
|
|||
end
|
||||
meta:set_string("infotext", "")
|
||||
remove_item_entity(pos, node)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("mcl_itemframes:item_frame",{
|
||||
description = S("Item Frame"),
|
||||
_tt_help = S("Can hold an item"),
|
||||
_doc_items_longdesc = S("Item frames are decorative blocks in which items can be placed."),
|
||||
minetest.register_node(var[3],{
|
||||
description = var[4],
|
||||
_tt_help = var[5],
|
||||
_doc_items_longdesc = var[6],
|
||||
_doc_items_usagehelp = S("Just place any item on the item frame. Use the item frame again to retrieve the item."),
|
||||
drawtype = "mesh",
|
||||
is_ground_content = false,
|
||||
mesh = "mcl_itemframes_itemframe1facedir.obj",
|
||||
mesh = var[7],
|
||||
selection_box = { type = "fixed", fixed = {-6/16, -6/16, 7/16, 6/16, 6/16, 0.5} },
|
||||
collision_box = { type = "fixed", fixed = {-6/16, -6/16, 7/16, 6/16, 6/16, 0.5} },
|
||||
tiles = {"mcl_itemframes_itemframe_background.png", "mcl_itemframes_itemframe_background.png", "mcl_itemframes_itemframe_background.png", "mcl_itemframes_itemframe_background.png", "default_wood.png", "mcl_itemframes_itemframe_background.png"},
|
||||
inventory_image = "mcl_itemframes_item_frame.png",
|
||||
wield_image = "mcl_itemframes_item_frame.png",
|
||||
tiles = {var[8], var[8], var[8], var[8], var[9], var[8]},
|
||||
inventory_image = var[10],
|
||||
wield_image = var[11],
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
|
||||
--FIXME: should only be glowing, no light source. How is that possible with a node?
|
||||
light_source = 1,
|
||||
|
||||
sunlight_propagates = true,
|
||||
groups = { dig_immediate=3,deco_block=1,dig_by_piston=1,container=7,attached_node_facedir=1 },
|
||||
sounds = mcl_sounds.node_sound_defaults(),
|
||||
|
@ -284,12 +295,12 @@ minetest.register_node("mcl_itemframes:item_frame",{
|
|||
local node = minetest.get_node(pos)
|
||||
|
||||
local objs = nil
|
||||
if node.name == "mcl_itemframes:item_frame" then
|
||||
if node.name == var[3] then
|
||||
objs = minetest.get_objects_inside_radius(pos, 0.5)
|
||||
end
|
||||
if objs then
|
||||
for _, obj in ipairs(objs) do
|
||||
if obj and obj:get_luaentity() and obj:get_luaentity().name == "mcl_itemframes:item" then
|
||||
if obj and obj:get_luaentity() and obj:get_luaentity().name == var[1] then
|
||||
update_item_entity(pos, node, (node.param2+1) % 4)
|
||||
break
|
||||
end
|
||||
|
@ -300,24 +311,15 @@ minetest.register_node("mcl_itemframes:item_frame",{
|
|||
return false
|
||||
end
|
||||
end,
|
||||
})
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "mcl_itemframes:item_frame",
|
||||
recipe = {
|
||||
{"mcl_core:stick", "mcl_core:stick", "mcl_core:stick"},
|
||||
{"mcl_core:stick", "mcl_mobitems:leather", "mcl_core:stick"},
|
||||
{"mcl_core:stick", "mcl_core:stick", "mcl_core:stick"},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_lbm({
|
||||
minetest.register_lbm({
|
||||
label = "Update legacy item frames",
|
||||
name = "mcl_itemframes:update_legacy_item_frames",
|
||||
nodenames = {"itemframes:frame"},
|
||||
nodenames = var[12],
|
||||
action = function(pos, node)
|
||||
-- Swap legacy node, then respawn entity
|
||||
node.name = "mcl_itemframes:item_frame"
|
||||
node.name = var[3]
|
||||
local meta = minetest.get_meta(pos)
|
||||
local item = meta:get_string("item")
|
||||
minetest.swap_node(pos, node)
|
||||
|
@ -331,17 +333,36 @@ minetest.register_lbm({
|
|||
end
|
||||
update_item_entity(pos, node)
|
||||
end,
|
||||
})
|
||||
})
|
||||
|
||||
-- FIXME: Item entities can get destroyed by /clearobjects
|
||||
minetest.register_lbm({
|
||||
-- FIXME: Item entities can get destroyed by /clearobjects
|
||||
minetest.register_lbm({
|
||||
label = "Respawn item frame item entities",
|
||||
name = "mcl_itemframes:respawn_entities",
|
||||
nodenames = {"mcl_itemframes:item_frame"},
|
||||
nodenames = {var[3]},
|
||||
run_at_every_load = true,
|
||||
action = function(pos, node)
|
||||
update_item_entity(pos, node)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
minetest.register_craft({
|
||||
output = "mcl_itemframes:item_frame",
|
||||
recipe = {
|
||||
{"mcl_core:stick", "mcl_core:stick", "mcl_core:stick"},
|
||||
{"mcl_core:stick", "mcl_mobitems:leather", "mcl_core:stick"},
|
||||
{"mcl_core:stick", "mcl_core:stick", "mcl_core:stick"},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = 'mcl_itemframes:glow_item_frame',
|
||||
recipe = {'mcl_itemframes:item_frame', 'extra_mobs:glow_ink_sac'},
|
||||
})
|
||||
|
||||
minetest.register_alias("itemframes:frame", "mcl_itemframes:item_frame")
|
||||
minetest.register_alias("extra_mobs:glow_item_frame","mcl_itemframes:glow_item_frame")
|
||||
minetest.register_alias("extra_mobs:glow_frame","mcl_itemframes:glow_item_frame")
|
||||
minetest.register_alias("extra_mobs:glow_item_frame_item","mcl_itemframes:glow_item")
|
||||
|
|
Loading…
Reference in New Issue