Add item physics (based on builtin item WTFPL mod by PilzAdam)
Fixed item pick-up Renamed in-game name to Minetest The NeXt Game (not Minetest The NeXt Gameration) Added settings to minetest.conf.examplemaster
parent
9bd170ef46
commit
910641aaf1
|
@ -35,3 +35,11 @@
|
|||
# Whether players can skip night by sleeping
|
||||
# Default value is true
|
||||
#enable_bed_night_skip = true
|
||||
|
||||
# The to live in seconds for dropped items
|
||||
# Default value is 300
|
||||
#item_ttl = 300
|
||||
|
||||
# Drop items after digging a node and don't add them directly to the inventory
|
||||
# Default value is true
|
||||
#enable_item_drop = true
|
||||
|
|
|
@ -83,6 +83,7 @@ PilzAdam (WTFPL):
|
|||
default_obsidian_shard.png
|
||||
default_mineral_gold.png
|
||||
default_item_pickup.*.ogg
|
||||
default_item_lava.ogg
|
||||
|
||||
jojoa1997 (WTFPL):
|
||||
default_obsidian.png
|
||||
|
|
|
@ -53,3 +53,4 @@ dofile(luapath .. "aliases.lua")
|
|||
dofile(luapath .. "legacy.lua")
|
||||
dofile(luapath .. "chat_cmds.lua")
|
||||
dofile(luapath .. "item_pickup.lua")
|
||||
dofile(luapath .. "item_physics.lua")
|
||||
|
|
|
@ -0,0 +1,181 @@
|
|||
-- mods/default/lua/item_physics.lua
|
||||
|
||||
core.register_entity(":__builtin:item", {
|
||||
initial_properties = {
|
||||
hp_max = 1,
|
||||
physical = true,
|
||||
collisionbox = {-0.17, -0.17, -0.17, 0.17, 0.17, 0.17},
|
||||
visual = "sprite",
|
||||
visual_size = {x = 0.5, y = 0.5},
|
||||
textures = {""},
|
||||
spritediv = {x = 1, y = 1},
|
||||
initial_sprite_basepos = {x = 0, y = 0},
|
||||
is_visible = false,
|
||||
timer = 0,
|
||||
},
|
||||
|
||||
itemstring = "",
|
||||
physical_state = true,
|
||||
|
||||
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
|
||||
local item_texture = nil
|
||||
local item_type = ""
|
||||
if core.registered_items[itemname] then
|
||||
item_texture = core.registered_items[itemname].inventory_image
|
||||
item_type = core.registered_items[itemname].type
|
||||
end
|
||||
local prop = {
|
||||
is_visible = true,
|
||||
visual = "wielditem",
|
||||
textures = {itemname},
|
||||
visual_size = {x=0.20, y=0.20},
|
||||
automatic_rotate = math.pi * 0.25,
|
||||
}
|
||||
|
||||
self.object:set_properties(prop)
|
||||
end,
|
||||
|
||||
get_staticdata = function(self)
|
||||
--return self.itemstring
|
||||
return core.serialize({
|
||||
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
|
||||
local data = core.deserialize(staticdata)
|
||||
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})
|
||||
self.object:setvelocity({x=0, y=2, z=0})
|
||||
self.object:setacceleration({x=0, y=-10, z=0})
|
||||
self:set_item(self.itemstring)
|
||||
end,
|
||||
|
||||
on_step = function(self, dtime)
|
||||
local time = core.setting_get("item_ttl")
|
||||
if not time then
|
||||
time = 300
|
||||
end
|
||||
if not self.timer then
|
||||
self.timer = 0
|
||||
end
|
||||
self.timer = self.timer + dtime
|
||||
time = tonumber(time)
|
||||
if time ~= 0 and (self.timer > time) then
|
||||
self.object:remove()
|
||||
end
|
||||
|
||||
local p = self.object:getpos()
|
||||
|
||||
local name = core.get_node(p).name
|
||||
if name == "default:lava_flowing" or name == "default:lava_source" then
|
||||
core.sound_play("default_item_lava", {pos = self.object:getpos()})
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
|
||||
if core.registered_nodes[name].liquidtype == "flowing" then
|
||||
local get_flowing_dir = function(self)
|
||||
local pos = self.object:getpos()
|
||||
local param2 = core.get_node(pos).param2
|
||||
for i,d in ipairs({-1, 1, -1, 1}) do
|
||||
if i<3 then
|
||||
pos.x = pos.x+d
|
||||
else
|
||||
pos.z = pos.z+d
|
||||
end
|
||||
|
||||
local name = core.get_node(pos).name
|
||||
local par2 = core.get_node(pos).param2
|
||||
if name == "default:water_flowing" and par2 < param2 then
|
||||
return pos
|
||||
end
|
||||
|
||||
if i < 3 then
|
||||
pos.x = pos.x-d
|
||||
else
|
||||
pos.z = pos.z-d
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local vec = get_flowing_dir(self)
|
||||
if vec then
|
||||
local v = self.object:getvelocity()
|
||||
|
||||
if vec and vec.x-p.x > 0 then
|
||||
self.object:setvelocity({x=0.5,y=v.y,z=0})
|
||||
elseif vec and vec.x-p.x < 0 then
|
||||
self.object:setvelocity({x=-0.5,y=v.y,z=0})
|
||||
elseif vec and vec.z-p.z > 0 then
|
||||
self.object:setvelocity({x=0,y=v.y,z=0.5})
|
||||
elseif vec and vec.z-p.z < 0 then
|
||||
self.object:setvelocity({x=0,y=v.y,z=-0.5})
|
||||
end
|
||||
|
||||
self.object:setacceleration({x=0, y=-10, z=0})
|
||||
self.physical_state = true
|
||||
self.object:set_properties({
|
||||
physical = true
|
||||
})
|
||||
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
p.y = p.y - 0.3
|
||||
local nn = core.get_node(p).name
|
||||
-- If node is not registered or node is walkably solid
|
||||
if not core.registered_nodes[nn] or core.registered_nodes[nn].walkable then
|
||||
if self.physical_state then
|
||||
self.object:setvelocity({x=0,y=0,z=0})
|
||||
self.object:setacceleration({x=0, y=0, z=0})
|
||||
self.physical_state = false
|
||||
self.object:set_properties({
|
||||
physical = false
|
||||
})
|
||||
end
|
||||
else
|
||||
if not self.physical_state then
|
||||
self.object:setvelocity({x=0,y=0,z=0})
|
||||
self.object:setacceleration({x=0, y=-10, z=0})
|
||||
self.physical_state = true
|
||||
self.object:set_properties({
|
||||
physical = true
|
||||
})
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
on_punch = function(self, hitter)
|
||||
if self.itemstring ~= "" then
|
||||
local left = hitter:get_inventory():add_item("main", self.itemstring)
|
||||
if not left:is_empty() then
|
||||
self.itemstring = left:to_string()
|
||||
return
|
||||
end
|
||||
end
|
||||
self.object:remove()
|
||||
end,
|
||||
})
|
|
@ -14,7 +14,7 @@ core.register_globalstep(function(dtime)
|
|||
if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) and controls.aux1 then
|
||||
inv:add_item("main", ItemStack(object:get_luaentity().itemstring))
|
||||
if object:get_luaentity().itemstring ~= "" then
|
||||
core.sound_play("item_drop_pickup", {
|
||||
core.sound_play("default_item_pickup", {
|
||||
to_player = player:get_player_name(),
|
||||
gain = 0.4*(1/#objcts1 or 1),
|
||||
})
|
||||
|
@ -50,7 +50,7 @@ core.register_globalstep(function(dtime)
|
|||
if inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
|
||||
inv:add_item("main", ItemStack(object:get_luaentity().itemstring))
|
||||
if object:get_luaentity().itemstring ~= "" then
|
||||
core.sound_play("item_drop_pickup", {
|
||||
core.sound_play("default_item_pickup", {
|
||||
to_player = player:get_player_name(),
|
||||
gain = 0.4*(1/#objcts2 or 1),
|
||||
})
|
||||
|
@ -74,47 +74,46 @@ core.register_globalstep(function(dtime)
|
|||
end
|
||||
end)
|
||||
|
||||
function core.handle_node_drops(pos, drops, digger)
|
||||
local inv
|
||||
if core.setting_getbool("creative_mode") and digger and digger:is_player() then
|
||||
inv = digger:get_inventory()
|
||||
end
|
||||
for _,item in ipairs(drops) do
|
||||
local count, name
|
||||
if type(item) == "string" then
|
||||
count = 1
|
||||
name = item
|
||||
else
|
||||
count = item:get_count()
|
||||
name = item:get_name()
|
||||
local item_drop = core.setting_getbool("enable_item_drop") or true
|
||||
if item_drop then
|
||||
function core.handle_node_drops(pos, drops, digger)
|
||||
local inv
|
||||
if core.setting_getbool("creative_mode") and digger and digger:is_player() then
|
||||
inv = digger:get_inventory()
|
||||
end
|
||||
if not inv or not inv:contains_item("main", ItemStack(name)) then
|
||||
for i=1,count do
|
||||
local obj = core.add_item(pos, name)
|
||||
if obj ~= nil then
|
||||
obj:get_luaentity().collect = true
|
||||
local x = math.random(1, 5)
|
||||
if math.random(1,2) == 1 then
|
||||
x = -x
|
||||
end
|
||||
local z = math.random(1, 5)
|
||||
if math.random(1,2) == 1 then
|
||||
z = -z
|
||||
end
|
||||
obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z})
|
||||
|
||||
-- FIXME this doesnt work for deactiveted objects
|
||||
if core.setting_get("remove_items") and tonumber(core.setting_get("remove_items")) then
|
||||
core.after(tonumber(core.setting_get("remove_items")), function(obj)
|
||||
obj:remove()
|
||||
end, obj)
|
||||
for _,item in ipairs(drops) do
|
||||
local count, name
|
||||
if type(item) == "string" then
|
||||
count = 1
|
||||
name = item
|
||||
else
|
||||
count = item:get_count()
|
||||
name = item:get_name()
|
||||
end
|
||||
if not inv or not inv:contains_item("main", ItemStack(name)) then
|
||||
for i=1,count do
|
||||
local obj = core.add_item(pos, name)
|
||||
if obj ~= nil then
|
||||
obj:get_luaentity().collect = true
|
||||
local x = math.random(1, 5)
|
||||
if math.random(1,2) == 1 then
|
||||
x = -x
|
||||
end
|
||||
local z = math.random(1, 5)
|
||||
if math.random(1,2) == 1 then
|
||||
z = -z
|
||||
end
|
||||
obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z})
|
||||
|
||||
-- FIXME this doesnt work for deactiveted objects
|
||||
if core.setting_get("remove_items") and tonumber(core.setting_get("remove_items")) then
|
||||
core.after(tonumber(core.setting_get("remove_items")), function(obj)
|
||||
obj:remove()
|
||||
end, obj)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if core.setting_get("log_mods") then
|
||||
core.log("action", "item_drop loaded")
|
||||
end
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue