forked from MineClone5/MineClone5
Attempt to get clock and map working in glowing itemframes
This commit is contained in:
parent
9c19395dd7
commit
8ccf1ae3a9
|
@ -46,7 +46,7 @@ minetest.register_entity("extra_mobs:glow_item_frame_item",{
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if self._texture ~= nil then
|
if self._texture then
|
||||||
self.object:set_properties({
|
self.object:set_properties({
|
||||||
textures={self._texture},
|
textures={self._texture},
|
||||||
visual_size={x=VISUAL_SIZE/self._scale, y=VISUAL_SIZE/self._scale},
|
visual_size={x=VISUAL_SIZE/self._scale, y=VISUAL_SIZE/self._scale},
|
||||||
|
@ -55,9 +55,9 @@ minetest.register_entity("extra_mobs:glow_item_frame_item",{
|
||||||
end,
|
end,
|
||||||
get_staticdata = function(self)
|
get_staticdata = function(self)
|
||||||
if not self then return end
|
if not self then return end
|
||||||
if self._nodename ~= nil and self._texture ~= nil then
|
if self._nodename and self._texture then
|
||||||
local ret = self._nodename .. ';' .. self._texture
|
local ret = self._nodename .. ';' .. self._texture
|
||||||
if self._scale ~= nil then
|
if self._scale then
|
||||||
ret = ret .. ';' .. tostring(self._scale)
|
ret = ret .. ';' .. tostring(self._scale)
|
||||||
end
|
end
|
||||||
return ret
|
return ret
|
||||||
|
@ -66,7 +66,7 @@ minetest.register_entity("extra_mobs:glow_item_frame_item",{
|
||||||
end,
|
end,
|
||||||
|
|
||||||
_update_texture = function(self)
|
_update_texture = function(self)
|
||||||
if self._texture ~= nil then
|
if self._texture then
|
||||||
self.object:set_properties({
|
self.object:set_properties({
|
||||||
textures={self._texture},
|
textures={self._texture},
|
||||||
visual_size={x=VISUAL_SIZE/self._scale, y=VISUAL_SIZE/self._scale},
|
visual_size={x=VISUAL_SIZE/self._scale, y=VISUAL_SIZE/self._scale},
|
||||||
|
@ -75,6 +75,23 @@ minetest.register_entity("extra_mobs:glow_item_frame_item",{
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_entity("extra_mobs:glow_item_frame_map", {
|
||||||
|
initial_properties = {
|
||||||
|
visual = "upright_sprite",
|
||||||
|
visual_size = {x = 1, y = 1},
|
||||||
|
pointable = false,
|
||||||
|
physical = false,
|
||||||
|
collide_with_objects = false,
|
||||||
|
textures = {"blank.png"},
|
||||||
|
},
|
||||||
|
on_activate = function(self, staticdata)
|
||||||
|
self.id = staticdata
|
||||||
|
self.object:set_properties({textures = {mcl_maps.load_map(self.id)}})
|
||||||
|
end,
|
||||||
|
get_staticdata = function(self)
|
||||||
|
return self.id
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
local facedir = {}
|
local facedir = {}
|
||||||
facedir[0] = {x=0,y=0,z=1}
|
facedir[0] = {x=0,y=0,z=1}
|
||||||
|
@ -83,19 +100,17 @@ facedir[2] = {x=0,y=0,z=-1}
|
||||||
facedir[3] = {x=-1,y=0,z=0}
|
facedir[3] = {x=-1,y=0,z=0}
|
||||||
|
|
||||||
local remove_item_entity = function(pos, node)
|
local remove_item_entity = function(pos, node)
|
||||||
local objs = nil
|
|
||||||
if node.name == "extra_mobs:glow_item_frame" then
|
if node.name == "extra_mobs:glow_item_frame" then
|
||||||
objs = minetest.get_objects_inside_radius(pos, .5)
|
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do
|
||||||
end
|
local entity = obj:get_luaentity()
|
||||||
if objs then
|
if entity and (entity.name == "extra_mobs:glow_item_frame_item" or entity.name == "extra_mobs:glow_item_frame_map") then
|
||||||
for _, obj in ipairs(objs) do
|
|
||||||
if obj and obj:get_luaentity() and obj:get_luaentity().name == "extra_mobs:glow_item_frame_item" then
|
|
||||||
obj:remove()
|
obj:remove()
|
||||||
end
|
end
|
||||||
end
|
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)
|
remove_item_entity(pos, node)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
@ -111,27 +126,29 @@ local update_item_entity = function(pos, node, param2)
|
||||||
pos.y = pos.y + posad.y*6.5/16
|
pos.y = pos.y + posad.y*6.5/16
|
||||||
pos.z = pos.z + posad.z*6.5/16
|
pos.z = pos.z + posad.z*6.5/16
|
||||||
end
|
end
|
||||||
local e = minetest.add_entity(pos, "extra_mobs:glow_item_frame_item")
|
local yaw = math.pi*2 - param2 * math.pi/2
|
||||||
local lua = e:get_luaentity()
|
local map_id = item:get_meta():get_string("mcl_maps:id")
|
||||||
lua._nodename = node.name
|
if map_id == "" then
|
||||||
local itemname = item:get_name()
|
local e = minetest.add_entity(pos, "extra_mobs:glow_item_frame_item")
|
||||||
if itemname == "" or itemname == nil then
|
local lua = e:get_luaentity()
|
||||||
lua._texture = "blank.png"
|
lua._nodename = node.name
|
||||||
lua._scale = 1
|
local itemname = item:get_name()
|
||||||
else
|
if itemname == "" or itemname == nil then
|
||||||
lua._texture = itemname
|
lua._texture = "blank.png"
|
||||||
local def = minetest.registered_items[itemname]
|
lua._scale = 1
|
||||||
if def and def.wield_scale then
|
else
|
||||||
lua._scale = def.wield_scale.x
|
lua._texture = itemname
|
||||||
else
|
local def = minetest.registered_items[itemname]
|
||||||
lua._scale = 1
|
lua._scale = def and def.wield_scale and def.wield_scale.x or 1
|
||||||
end
|
end
|
||||||
end
|
lua:_update_texture()
|
||||||
lua:_update_texture()
|
if node.name == "extra_mobs:glow_item_frame" then
|
||||||
if node.name == "extra_mobs:glow_item_frame" then
|
e:set_yaw(yaw)
|
||||||
local yaw = math.pi*2 - param2 * math.pi/2
|
end
|
||||||
e:set_yaw(yaw)
|
else
|
||||||
end
|
local e = minetest.add_entity(pos, "extra_mobs:glow_item_frame_map", map_id)
|
||||||
|
e:set_yaw(yaw)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -174,6 +191,21 @@ minetest.register_node("extra_mobs:glow_item_frame",{
|
||||||
groups = { dig_immediate=3,deco_block=1,dig_by_piston=1,container=7,attached_node_facedir=1 },
|
groups = { dig_immediate=3,deco_block=1,dig_by_piston=1,container=7,attached_node_facedir=1 },
|
||||||
sounds = mcl_sounds.node_sound_defaults(),
|
sounds = mcl_sounds.node_sound_defaults(),
|
||||||
node_placement_prediction = "",
|
node_placement_prediction = "",
|
||||||
|
on_timer = function(pos)
|
||||||
|
local inv = minetest.get_meta(pos):get_inventory()
|
||||||
|
local stack = inv:get_stack("main", 1)
|
||||||
|
local itemname = stack:get_name()
|
||||||
|
if minetest.get_item_group(itemname, "clock") > 0 then
|
||||||
|
local new_name = "mcl_clock:clock_" .. (mcl_worlds.clock_works(pos) and mcl_clock.old_time or mcl_clock.random_frame)
|
||||||
|
if itemname ~= new_name then
|
||||||
|
stack:set_name(new_name)
|
||||||
|
inv:set_stack("main", 1, stack)
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
update_item_entity(pos, node, node.param2)
|
||||||
|
end
|
||||||
|
minetest.get_node_timer(pos):start(1.0)
|
||||||
|
end
|
||||||
|
end,
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
if pointed_thing.type ~= "node" then
|
if pointed_thing.type ~= "node" then
|
||||||
return itemstack
|
return itemstack
|
||||||
|
@ -214,6 +246,12 @@ minetest.register_node("extra_mobs:glow_item_frame",{
|
||||||
end
|
end
|
||||||
local put_itemstack = ItemStack(itemstack)
|
local put_itemstack = ItemStack(itemstack)
|
||||||
put_itemstack:set_count(1)
|
put_itemstack:set_count(1)
|
||||||
|
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)
|
inv:set_stack("main", 1, put_itemstack)
|
||||||
update_item_entity(pos, node)
|
update_item_entity(pos, node)
|
||||||
-- Add node infotext when item has been named
|
-- Add node infotext when item has been named
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
name = extra_mobs
|
name = extra_mobs
|
||||||
depends = mcl_mobs, mobs_mc
|
depends = mcl_mobs, mobs_mc, mcl_compass, mcl_core, mcl_maps
|
||||||
optional_depends = mc_warped_fungus_stick, mc_sweet_berry
|
optional_depends = mc_warped_fungus_stick, mc_sweet_berry
|
||||||
|
|
Loading…
Reference in New Issue