2015-09-01 17:15:24 +02:00
|
|
|
--
|
|
|
|
-- Builtin item mod
|
|
|
|
-- By PilzAdam
|
|
|
|
-- Tweaked by Kaadmy, for Pixture
|
|
|
|
--
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_entity(
|
2015-09-01 17:15:24 +02:00
|
|
|
":__builtin:item",
|
|
|
|
{
|
|
|
|
initial_properties = {
|
|
|
|
hp_max = 1,
|
|
|
|
physical = true,
|
|
|
|
collisionbox = {-0.125, -0.125, -0.125, 0.125, 0.125, 0.125},
|
|
|
|
collide_with_objects = false,
|
2019-08-31 17:42:49 +02:00
|
|
|
pointable = false,
|
2015-09-01 17:15:24 +02:00
|
|
|
visual = "sprite",
|
|
|
|
visual_size = {x=0.15, y=0.15},
|
|
|
|
textures = {""},
|
|
|
|
spritediv = {x=1, y=1},
|
|
|
|
initial_sprite_basepos = {x=0, y=0},
|
|
|
|
is_visible = false,
|
|
|
|
timer = 0,
|
|
|
|
},
|
|
|
|
|
|
|
|
itemstring = "",
|
|
|
|
physical_state = true,
|
2019-09-15 10:48:27 +02:00
|
|
|
item_magnet = false, -- set by other mod that implements item magnet
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
set_item = function(self, itemstring)
|
|
|
|
self.itemstring = itemstring
|
|
|
|
local stack = ItemStack(itemstring)
|
|
|
|
local itemtable = stack:to_table()
|
|
|
|
local itemname = nil
|
|
|
|
if itemtable then
|
|
|
|
itemname = stack:to_table().name
|
|
|
|
end
|
2016-02-02 22:26:04 +01:00
|
|
|
|
2019-09-14 09:52:07 +02:00
|
|
|
-- Hand and specially marked items are not allowed in entity form
|
|
|
|
if itemname ~= nil and ((itemname == "") or (minetest.get_item_group(itemname, "no_item_drop") == 1)) then
|
2016-02-02 22:26:04 +01:00
|
|
|
self.object:remove()
|
2019-09-14 09:52:07 +02:00
|
|
|
return
|
2016-02-02 22:26:04 +01:00
|
|
|
end
|
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
local item_texture = nil
|
|
|
|
local item_type = ""
|
2017-05-12 04:29:55 +02:00
|
|
|
if minetest.registered_items[itemname] then
|
|
|
|
item_texture = minetest.registered_items[itemname].inventory_image
|
|
|
|
item_type = minetest.registered_items[itemname].type
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
local prop = {
|
|
|
|
is_visible = true,
|
|
|
|
visual = "sprite",
|
|
|
|
textures = {"unknown_item.png"}
|
|
|
|
}
|
|
|
|
if item_texture and item_texture ~= "" then
|
|
|
|
prop.visual = "wielditem"
|
|
|
|
prop.textures = {itemname}
|
|
|
|
prop.visual_size = {x=0.15, y=0.15}
|
|
|
|
else
|
|
|
|
prop.visual = "wielditem"
|
|
|
|
prop.textures = {itemname}
|
|
|
|
prop.visual_size = {x=0.15, y=0.15}
|
|
|
|
prop.automatic_rotate = math.pi * 0.5
|
|
|
|
end
|
|
|
|
self.object:set_properties(prop)
|
|
|
|
end,
|
|
|
|
|
|
|
|
get_staticdata = function(self)
|
|
|
|
--return self.itemstring
|
2017-05-12 04:29:55 +02:00
|
|
|
return minetest.serialize(
|
2015-09-01 17:15:24 +02:00
|
|
|
{
|
|
|
|
itemstring = self.itemstring,
|
|
|
|
always_collect = self.always_collect,
|
|
|
|
timer = self.timer,
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_activate = function(self, staticdata, dtime_s)
|
|
|
|
if string.sub(staticdata, 1, string.len("return")) == "return" then
|
2017-05-12 04:29:55 +02:00
|
|
|
local data = minetest.deserialize(staticdata)
|
2015-09-01 17:15:24 +02:00
|
|
|
if data and type(data) == "table" then
|
|
|
|
self.itemstring = data.itemstring
|
|
|
|
self.always_collect = data.always_collect
|
|
|
|
self.timer = data.timer
|
|
|
|
if not self.timer then
|
|
|
|
self.timer = 0
|
|
|
|
end
|
|
|
|
self.timer = self.timer+dtime_s
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.itemstring = staticdata
|
|
|
|
end
|
|
|
|
self.object:set_armor_groups({immortal=1})
|
2019-03-20 15:04:20 +01:00
|
|
|
self.object:set_velocity({x=0, y=2, z=0})
|
|
|
|
self.object:set_acceleration({x=0, y=-10, z=0})
|
2015-09-01 17:15:24 +02:00
|
|
|
self:set_item(self.itemstring)
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_step = function(self, dtime)
|
2017-06-27 21:13:30 +02:00
|
|
|
local time = tonumber(minetest.settings:get("remove_items"))
|
2015-09-01 17:15:24 +02:00
|
|
|
if not time then time = 600 end
|
|
|
|
if not self.timer then self.timer = 0 end
|
|
|
|
|
|
|
|
self.timer = self.timer + dtime
|
|
|
|
if time ~= 0 and (self.timer > time) then
|
|
|
|
self.object:remove()
|
2019-09-14 09:52:07 +02:00
|
|
|
return
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
|
2019-03-20 15:04:20 +01:00
|
|
|
local p = self.object:get_pos()
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
local name = minetest.get_node(p).name
|
2019-09-14 09:52:07 +02:00
|
|
|
-- Destroy item in damaging node
|
|
|
|
if minetest.registered_nodes[name].damage_per_second > 0 then
|
2019-03-20 15:04:20 +01:00
|
|
|
minetest.sound_play("builtin_item_lava", {pos = self.object:get_pos(), gain = 0.45})
|
2015-09-01 17:15:24 +02:00
|
|
|
self.object:remove()
|
|
|
|
return
|
|
|
|
end
|
2019-09-15 10:48:27 +02:00
|
|
|
|
|
|
|
if self.item_magnet then
|
|
|
|
return
|
|
|
|
end
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
p.y = p.y - 0.3
|
2017-05-12 04:29:55 +02:00
|
|
|
local nn = minetest.get_node(p).name
|
2015-09-01 17:15:24 +02:00
|
|
|
-- If node is not registered or node is walkably solid:
|
2017-05-12 04:29:55 +02:00
|
|
|
if not minetest.registered_nodes[nn] or minetest.registered_nodes[nn].walkable then
|
2015-09-01 17:15:24 +02:00
|
|
|
if self.physical_state then
|
2019-03-20 15:04:20 +01:00
|
|
|
self.object:set_velocity({x=0,y=0,z=0})
|
|
|
|
self.object:set_acceleration({x=0, y=0, z=0})
|
2015-09-01 17:15:24 +02:00
|
|
|
self.physical_state = false
|
|
|
|
self.object:set_properties(
|
|
|
|
{
|
|
|
|
physical = false
|
|
|
|
})
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if not self.physical_state then
|
2019-03-20 15:04:20 +01:00
|
|
|
self.object:set_velocity({x=0,y=0,z=0})
|
|
|
|
self.object:set_acceleration({x=0, y=-10, z=0})
|
2015-09-01 17:15:24 +02:00
|
|
|
self.physical_state = true
|
|
|
|
self.object:set_properties(
|
|
|
|
{
|
|
|
|
physical = true
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2019-08-31 17:42:49 +02:00
|
|
|
default.log("mod:builtin_item", "loaded")
|