forked from nalc/homedecor_modpack
Merge pull request #338 from FozLand/desk_fan_fix
Avoid crashes due to missing desk_fan entity.
This commit is contained in:
commit
bb06cfd6f6
|
@ -24,6 +24,22 @@ minetest.register_entity("homedecor:mesh_desk_fan", {
|
||||||
visual_size = {x=10, y=10},
|
visual_size = {x=10, y=10},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local add_mesh_desk_fan_entity = function(pos)
|
||||||
|
print("in add_mesh_desk_fan_entity()")
|
||||||
|
local param2 = minetest.get_node(pos).param2
|
||||||
|
local entity = minetest.add_entity(pos, "homedecor:mesh_desk_fan")
|
||||||
|
if param2 == 0 then
|
||||||
|
entity:setyaw(3.142) -- 180 degrees
|
||||||
|
elseif minetest.get_node(pos).param2 == 1 then
|
||||||
|
entity:setyaw(3.142/2) -- 90 degrees
|
||||||
|
elseif minetest.get_node(pos).param2 == 3 then
|
||||||
|
entity:setyaw((-3.142/2)) -- 270 degrees
|
||||||
|
else
|
||||||
|
entity:setyaw(0)
|
||||||
|
end
|
||||||
|
return entity
|
||||||
|
end
|
||||||
|
|
||||||
homedecor.register("desk_fan", {
|
homedecor.register("desk_fan", {
|
||||||
description = "Desk Fan",
|
description = "Desk Fan",
|
||||||
groups = {oddly_breakable_by_hand=2},
|
groups = {oddly_breakable_by_hand=2},
|
||||||
|
@ -39,54 +55,25 @@ homedecor.register("desk_fan", {
|
||||||
selection_box = { type = "regular" },
|
selection_box = { type = "regular" },
|
||||||
on_rotate = screwdriver.disallow,
|
on_rotate = screwdriver.disallow,
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local entity_remove = minetest.get_objects_inside_radius(pos, 0.1)
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("active", "no")
|
meta:set_string("active", "no")
|
||||||
if entity_remove[1] == nil then
|
add_mesh_desk_fan_entity(pos)
|
||||||
minetest.add_entity({x=pos.x, y=pos.y, z=pos.z}, "homedecor:mesh_desk_fan") --+(0.0625*10)
|
|
||||||
entity_remove = minetest.get_objects_inside_radius(pos, 0.1)
|
|
||||||
if minetest.get_node(pos).param2 == 0 then --list of rad to 90 degree: 3.142/2 = 90; 3.142 = 180; 3*3.142 = 270
|
|
||||||
entity_remove[1]:setyaw(3.142)
|
|
||||||
elseif minetest.get_node(pos).param2 == 1 then
|
|
||||||
entity_remove[1]:setyaw(3.142/2)
|
|
||||||
elseif minetest.get_node(pos).param2 == 3 then
|
|
||||||
entity_remove[1]:setyaw((-3.142/2))
|
|
||||||
else
|
|
||||||
entity_remove[1]:setyaw(0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
on_punch = function(pos)
|
on_punch = function(pos)
|
||||||
local entity_anim = minetest.get_objects_inside_radius(pos, 0.1)
|
local meta = minetest.get_meta(pos)
|
||||||
local speedy_meta = minetest.get_meta(pos)
|
local entities = minetest.get_objects_inside_radius(pos, 0.1)
|
||||||
if speedy_meta:get_string("active") == "no" then
|
local entity = entities[1] or add_mesh_desk_fan_entity(pos)
|
||||||
speedy_meta:set_string("active", "yes")
|
if meta:get_string("active") == "no" then
|
||||||
elseif speedy_meta:get_string("active") == "yes" then
|
meta:set_string("active", "yes")
|
||||||
speedy_meta:set_string("active", "no")
|
entity:set_animation({x=0,y=96}, 24, 0)
|
||||||
end
|
|
||||||
|
|
||||||
if entity_anim[1] == nil then
|
|
||||||
minetest.add_entity({x=pos.x, y=pos.y, z=pos.z}, "homedecor:mesh_desk_fan") --+(0.0625*10)
|
|
||||||
local entity_remove = minetest.get_objects_inside_radius(pos, 0.1)
|
|
||||||
if minetest.get_node(pos).param2 == 0 then --list of rad to 90 degree: 3.142/2 = 90; 3.142 = 180; 3*3.142 = 270
|
|
||||||
entity_remove[1]:setyaw(3.142)
|
|
||||||
elseif minetest.get_node(pos).param2 == 1 then
|
|
||||||
entity_remove[1]:setyaw(3.142/2)
|
|
||||||
elseif minetest.get_node(pos).param2 == 3 then
|
|
||||||
entity_remove[1]:setyaw((-3.142/2))
|
|
||||||
else
|
else
|
||||||
entity_remove[1]:setyaw(0)
|
meta:set_string("active", "no")
|
||||||
end
|
entity:set_animation({x=0,y=0}, 1, 0)
|
||||||
end
|
|
||||||
if minetest.get_meta(pos):get_string("active") == "no" then
|
|
||||||
entity_anim[1]:set_animation({x=0,y=0}, 1, 0)
|
|
||||||
elseif minetest.get_meta(pos):get_string("active") == "yes" then
|
|
||||||
entity_anim[1]:set_animation({x=0,y=96}, 24, 0)
|
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
after_dig_node = function(pos)
|
after_dig_node = function(pos)
|
||||||
local entity_remove = minetest.get_objects_inside_radius(pos, 0.1)
|
local entities = minetest.get_objects_inside_radius(pos, 0.1)
|
||||||
entity_remove[1]:remove()
|
if entities[1] then entities[1]:remove() end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user