1
0
Fork 0
TheDarkProject/mods/ENTITIES/vl_held_item/init.lua

41 lines
1.2 KiB
Lua
Raw Normal View History

2024-05-04 11:37:30 +02:00
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
2024-05-05 20:25:19 +02:00
vl_held_item = {}
local mod = vl_held_item
2024-05-04 11:37:30 +02:00
2024-05-05 20:25:19 +02:00
local held_item_entity = {
2024-05-04 11:37:30 +02:00
initial_properties = {
hp_max = 1,
physical = true,
pointable = false,
collide_with_objects = true,
2024-05-05 20:25:19 +02:00
static_save = false, -- TODO remove/change later when needed to persist
-- WARNING persisting held items not recommended, mob can recreate it after_activate
2024-05-04 11:37:30 +02:00
collision_box = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
},
visual = "wielditem",
textures = { "mcl_core:dirt_with_grass" },
}
2024-05-05 20:25:19 +02:00
function held_item_entity:on_activate(staticdata, dtime_unloaded)
2024-05-04 11:37:30 +02:00
local staticdata = minetest.deserialize(staticdata)
self._staticdata = staticdata
local props = {
visual = "wielditem",
2024-05-05 20:25:19 +02:00
textures = { staticdata.itemname },
2024-05-04 11:37:30 +02:00
}
self.object:set_properties(props)
end
2024-05-05 20:25:19 +02:00
function held_item_entity:get_staticdata()
2024-05-04 11:37:30 +02:00
return minetest.serialize(self._staticdata)
end
2024-05-05 20:25:19 +02:00
minetest.register_entity("vl_held_item:held_item_entity", held_item_entity)
2024-05-04 11:37:30 +02:00
2024-05-05 20:25:19 +02:00
function mod.create_item_entity(pos, itemname)
2024-05-04 11:37:30 +02:00
local staticdata = {
2024-05-05 20:25:19 +02:00
itemname = itemname
2024-05-04 11:37:30 +02:00
}
2024-05-05 20:25:19 +02:00
return minetest.add_entity(pos, "vl_held_item:held_item_entity", minetest.serialize(staticdata))
2024-05-04 11:37:30 +02:00
end