2021-04-04 02:39:08 +02:00
|
|
|
|
--these are lua locals, used for higher performance
|
2021-05-29 16:12:33 +02:00
|
|
|
|
local minetest, math, vector, ipairs, pairs = minetest, math, vector, ipairs, pairs
|
2021-04-04 02:39:08 +02:00
|
|
|
|
|
|
|
|
|
--this is used for the player pool in the sound buffer
|
|
|
|
|
local pool = {}
|
|
|
|
|
|
|
|
|
|
local tick = false
|
|
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
2021-04-04 03:05:31 +02:00
|
|
|
|
local name
|
2021-04-04 02:39:08 +02:00
|
|
|
|
name = player:get_player_name()
|
|
|
|
|
pool[name] = 0
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
2021-04-04 03:05:31 +02:00
|
|
|
|
local name
|
2021-04-04 02:39:08 +02:00
|
|
|
|
name = player:get_player_name()
|
|
|
|
|
pool[name] = nil
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
2021-03-28 08:13:24 +02:00
|
|
|
|
local has_awards = minetest.get_modpath("awards")
|
|
|
|
|
|
2021-04-02 05:48:00 +02:00
|
|
|
|
local mcl_item_entity = {}
|
2021-03-28 08:13:24 +02:00
|
|
|
|
|
2017-02-16 00:57:35 +01:00
|
|
|
|
--basic settings
|
2017-02-17 02:44:33 +01:00
|
|
|
|
local item_drop_settings = {} --settings table
|
2021-04-03 06:42:20 +02:00
|
|
|
|
item_drop_settings.dug_buffer = 0.65 -- the warm up period before a dug item can be collected
|
2017-06-03 17:03:22 +02:00
|
|
|
|
item_drop_settings.age = 1.0 --how old a dropped item (_insta_collect==false) has to be before collecting
|
|
|
|
|
item_drop_settings.radius_magnet = 2.0 --radius of item magnet. MUST BE LARGER THAN radius_collect!
|
2021-01-08 14:55:02 +01:00
|
|
|
|
item_drop_settings.xp_radius_magnet = 7.25 --radius of xp magnet. MUST BE LARGER THAN radius_collect!
|
2017-06-03 17:27:58 +02:00
|
|
|
|
item_drop_settings.radius_collect = 0.2 --radius of collection
|
2021-04-03 03:57:38 +02:00
|
|
|
|
item_drop_settings.player_collect_height = 0.8 --added to their pos y value
|
2017-02-16 00:57:35 +01:00
|
|
|
|
item_drop_settings.collection_safety = false --do this to prevent items from flying away on laggy servers
|
|
|
|
|
item_drop_settings.random_item_velocity = true --this sets random item velocity if velocity is 0
|
2017-02-18 21:59:24 +01:00
|
|
|
|
item_drop_settings.drop_single_item = false --if true, the drop control drops 1 item instead of the entire stack, and sneak+drop drops the stack
|
|
|
|
|
-- drop_single_item is disabled by default because it is annoying to throw away items from the intentory screen
|
2017-02-16 00:57:35 +01:00
|
|
|
|
|
2017-05-29 17:39:01 +02:00
|
|
|
|
item_drop_settings.magnet_time = 0.75 -- how many seconds an item follows the player before giving up
|
2017-05-27 15:17:03 +02:00
|
|
|
|
|
2021-05-25 12:52:25 +02:00
|
|
|
|
local function get_gravity()
|
2017-08-09 16:17:00 +02:00
|
|
|
|
return tonumber(minetest.settings:get("movement_gravity")) or 9.81
|
2017-05-27 15:22:28 +02:00
|
|
|
|
end
|
|
|
|
|
|
2021-03-28 08:13:24 +02:00
|
|
|
|
local registered_pickup_achievement = {}
|
|
|
|
|
|
|
|
|
|
--TODO: remove limitation of 1 award per itemname
|
|
|
|
|
function mcl_item_entity.register_pickup_achievement(itemname, award)
|
|
|
|
|
if not has_awards then
|
|
|
|
|
minetest.log("warning", "[mcl_item_entity] Trying to register pickup achievement ["..award.."] for ["..itemname.."] while awards missing")
|
|
|
|
|
elseif registered_pickup_achievement[itemname] then
|
|
|
|
|
minetest.log("error", "[mcl_item_entity] Trying to register already existing pickup achievement ["..award.."] for ["..itemname.."]")
|
|
|
|
|
else
|
|
|
|
|
registered_pickup_achievement[itemname] = award
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
mcl_item_entity.register_pickup_achievement("tree", "mcl:mineWood")
|
|
|
|
|
mcl_item_entity.register_pickup_achievement("mcl_mobitems:blaze_rod", "mcl:blazeRod")
|
|
|
|
|
mcl_item_entity.register_pickup_achievement("mcl_mobitems:leather", "mcl:killCow")
|
|
|
|
|
mcl_item_entity.register_pickup_achievement("mcl_core:diamond", "mcl:diamonds")
|
2022-07-01 20:39:10 +02:00
|
|
|
|
mcl_item_entity.register_pickup_achievement("mcl_core:crying_obsidian", "mcl:whosCuttingOnions")
|
2022-07-01 20:41:01 +02:00
|
|
|
|
mcl_item_entity.register_pickup_achievement("mcl_nether:ancient_debris", "mcl:hiddenInTheDepths")
|
2021-03-28 08:13:24 +02:00
|
|
|
|
|
2021-05-25 12:52:25 +02:00
|
|
|
|
local function check_pickup_achievements(object, player)
|
2021-03-28 08:13:24 +02:00
|
|
|
|
if has_awards then
|
|
|
|
|
local itemname = ItemStack(object:get_luaentity().itemstring):get_name()
|
|
|
|
|
local playername = player:get_player_name()
|
|
|
|
|
for name,award in pairs(registered_pickup_achievement) do
|
|
|
|
|
if itemname == name or minetest.get_item_group(itemname, name) ~= 0 then
|
|
|
|
|
awards.unlock(playername, award)
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-03-05 22:33:09 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2017-02-16 00:57:35 +01:00
|
|
|
|
|
2021-05-25 12:52:25 +02:00
|
|
|
|
local function enable_physics(object, luaentity, ignore_check)
|
2017-06-10 20:56:53 +02:00
|
|
|
|
if luaentity.physical_state == false or ignore_check == true then
|
2017-06-10 20:37:17 +02:00
|
|
|
|
luaentity.physical_state = true
|
|
|
|
|
object:set_properties({
|
|
|
|
|
physical = true
|
|
|
|
|
})
|
|
|
|
|
object:set_acceleration({x=0,y=-get_gravity(),z=0})
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-05-25 12:52:25 +02:00
|
|
|
|
local function disable_physics(object, luaentity, ignore_check, reset_movement)
|
2017-06-10 20:56:53 +02:00
|
|
|
|
if luaentity.physical_state == true or ignore_check == true then
|
2017-06-10 20:37:17 +02:00
|
|
|
|
luaentity.physical_state = false
|
|
|
|
|
object:set_properties({
|
|
|
|
|
physical = false
|
|
|
|
|
})
|
|
|
|
|
if reset_movement ~= false then
|
|
|
|
|
object:set_velocity({x=0,y=0,z=0})
|
|
|
|
|
object:set_acceleration({x=0,y=0,z=0})
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-06-10 21:39:26 +02:00
|
|
|
|
|
2021-04-02 05:48:00 +02:00
|
|
|
|
minetest.register_globalstep(function(dtime)
|
2021-04-04 02:39:08 +02:00
|
|
|
|
tick = not tick
|
|
|
|
|
|
2021-04-03 06:42:20 +02:00
|
|
|
|
for _,player in pairs(minetest.get_connected_players()) do
|
|
|
|
|
if player:get_hp() > 0 or not minetest.settings:get_bool("enable_damage") then
|
2021-04-04 02:39:08 +02:00
|
|
|
|
|
|
|
|
|
local name = player:get_player_name()
|
2021-05-04 09:16:42 +02:00
|
|
|
|
|
2021-04-04 03:09:43 +02:00
|
|
|
|
local pos = player:get_pos()
|
2021-04-04 02:39:08 +02:00
|
|
|
|
|
|
|
|
|
if tick == true and pool[name] > 0 then
|
|
|
|
|
minetest.sound_play("item_drop_pickup", {
|
|
|
|
|
pos = pos,
|
2022-03-13 14:58:01 +01:00
|
|
|
|
gain = 0.3,
|
2021-04-04 02:39:08 +02:00
|
|
|
|
max_hear_distance = 16,
|
2021-04-04 02:53:34 +02:00
|
|
|
|
pitch = math.random(70,110)/100
|
2021-04-04 02:39:08 +02:00
|
|
|
|
})
|
|
|
|
|
if pool[name] > 6 then
|
|
|
|
|
pool[name] = 6
|
|
|
|
|
else
|
|
|
|
|
pool[name] = pool[name] - 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2021-05-04 09:16:42 +02:00
|
|
|
|
|
2021-04-03 06:42:20 +02:00
|
|
|
|
local inv = player:get_inventory()
|
|
|
|
|
local checkpos = {x=pos.x,y=pos.y + item_drop_settings.player_collect_height,z=pos.z}
|
|
|
|
|
|
|
|
|
|
--magnet and collection
|
|
|
|
|
for _,object in pairs(minetest.get_objects_inside_radius(checkpos, item_drop_settings.xp_radius_magnet)) do
|
|
|
|
|
if not object:is_player() and vector.distance(checkpos, object:get_pos()) < item_drop_settings.radius_magnet and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" and object:get_luaentity()._magnet_timer and (object:get_luaentity()._insta_collect or (object:get_luaentity().age > item_drop_settings.age)) then
|
|
|
|
|
|
|
|
|
|
if object:get_luaentity()._magnet_timer >= 0 and object:get_luaentity()._magnet_timer < item_drop_settings.magnet_time and inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
|
|
|
|
|
|
|
|
|
|
-- Collection
|
|
|
|
|
if not object:get_luaentity()._removed then
|
|
|
|
|
-- Ignore if itemstring is not set yet
|
|
|
|
|
if object:get_luaentity().itemstring ~= "" then
|
|
|
|
|
inv:add_item("main", ItemStack(object:get_luaentity().itemstring))
|
2021-04-04 02:39:08 +02:00
|
|
|
|
|
2021-04-03 06:42:20 +02:00
|
|
|
|
check_pickup_achievements(object, player)
|
|
|
|
|
|
|
|
|
|
-- Destroy entity
|
|
|
|
|
-- This just prevents this section to be run again because object:remove() doesn't remove the item immediately.
|
2021-04-03 03:40:04 +02:00
|
|
|
|
object:get_luaentity().target = checkpos
|
2021-04-03 06:42:20 +02:00
|
|
|
|
object:get_luaentity()._removed = true
|
2021-04-03 03:40:04 +02:00
|
|
|
|
|
2021-04-03 03:50:47 +02:00
|
|
|
|
object:set_velocity({x=0,y=0,z=0})
|
|
|
|
|
object:set_acceleration({x=0,y=0,z=0})
|
2021-04-03 04:02:19 +02:00
|
|
|
|
|
|
|
|
|
object:move_to(checkpos)
|
|
|
|
|
|
2021-04-04 02:39:08 +02:00
|
|
|
|
pool[name] = pool[name] + 1
|
|
|
|
|
|
2021-04-03 04:02:19 +02:00
|
|
|
|
minetest.after(0.25, function()
|
|
|
|
|
--safety check
|
|
|
|
|
if object and object:get_luaentity() then
|
|
|
|
|
object:remove()
|
|
|
|
|
end
|
|
|
|
|
end)
|
2021-04-02 05:48:00 +02:00
|
|
|
|
end
|
2019-04-01 10:59:36 +02:00
|
|
|
|
end
|
2021-04-03 06:42:20 +02:00
|
|
|
|
end
|
2019-04-01 10:59:36 +02:00
|
|
|
|
|
2021-04-03 06:42:20 +02:00
|
|
|
|
elseif not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "mcl_experience:orb" then
|
|
|
|
|
local entity = object:get_luaentity()
|
|
|
|
|
entity.collector = player:get_player_name()
|
|
|
|
|
entity.collected = true
|
2020-10-19 14:38:21 +02:00
|
|
|
|
|
2017-02-16 00:57:35 +01:00
|
|
|
|
end
|
2021-04-02 05:48:00 +02:00
|
|
|
|
end
|
2021-04-03 06:42:20 +02:00
|
|
|
|
|
2017-02-16 00:57:35 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2015-06-29 19:55:56 +02:00
|
|
|
|
end)
|
|
|
|
|
|
2020-11-06 13:46:52 +01:00
|
|
|
|
-- Stupid workaround to get drops from a drop table:
|
|
|
|
|
-- Create a temporary table in minetest.registered_nodes that contains the proper drops,
|
|
|
|
|
-- because unfortunately minetest.get_node_drops needs the drop table to be inside a registered node definition
|
|
|
|
|
-- (very ugly)
|
|
|
|
|
|
|
|
|
|
local tmp_id = 0
|
|
|
|
|
|
|
|
|
|
local function get_drops(drop, toolname, param2, paramtype2)
|
|
|
|
|
tmp_id = tmp_id + 1
|
|
|
|
|
local tmp_node_name = "mcl_item_entity:" .. tmp_id
|
|
|
|
|
minetest.registered_nodes[tmp_node_name] = {
|
|
|
|
|
name = tmp_node_name,
|
|
|
|
|
drop = drop,
|
|
|
|
|
paramtype2 = paramtype2
|
|
|
|
|
}
|
|
|
|
|
local drops = minetest.get_node_drops({name = tmp_node_name, param2 = param2}, toolname)
|
|
|
|
|
minetest.registered_nodes[tmp_node_name] = nil
|
|
|
|
|
return drops
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function discrete_uniform_distribution(drops, min_count, max_count, cap)
|
|
|
|
|
local new_drops = table.copy(drops)
|
|
|
|
|
for i, item in ipairs(drops) do
|
|
|
|
|
local new_item = ItemStack(item)
|
|
|
|
|
local multiplier = math.random(min_count, max_count)
|
|
|
|
|
if cap then
|
|
|
|
|
multiplier = math.min(cap, multiplier)
|
|
|
|
|
end
|
|
|
|
|
new_item:set_count(multiplier * new_item:get_count())
|
|
|
|
|
new_drops[i] = new_item
|
|
|
|
|
end
|
|
|
|
|
return new_drops
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function get_fortune_drops(fortune_drops, fortune_level)
|
|
|
|
|
local drop
|
|
|
|
|
local i = fortune_level
|
|
|
|
|
repeat
|
|
|
|
|
drop = fortune_drops[i]
|
|
|
|
|
i = i - 1
|
|
|
|
|
until drop or i < 1
|
|
|
|
|
return drop or {}
|
|
|
|
|
end
|
|
|
|
|
|
2021-04-02 05:48:00 +02:00
|
|
|
|
local doTileDrops = minetest.settings:get_bool("mcl_doTileDrops", true)
|
|
|
|
|
|
2015-06-29 19:55:56 +02:00
|
|
|
|
function minetest.handle_node_drops(pos, drops, digger)
|
2018-03-05 13:35:14 +01:00
|
|
|
|
-- NOTE: This function override allows digger to be nil.
|
|
|
|
|
-- This means there is no digger. This is a special case which allows this function to be called
|
|
|
|
|
-- by hand. Creative Mode is intentionally ignored in this case.
|
|
|
|
|
|
2021-01-05 18:05:20 +01:00
|
|
|
|
if (digger and digger:is_player() and minetest.is_creative_enabled(digger:get_player_name())) or doTileDrops == false then
|
2017-05-23 19:32:20 +02:00
|
|
|
|
return
|
2015-06-29 19:55:56 +02:00
|
|
|
|
end
|
2017-08-03 01:01:44 +02:00
|
|
|
|
|
|
|
|
|
-- Check if node will yield its useful drop by the digger's tool
|
|
|
|
|
local dug_node = minetest.get_node(pos)
|
2021-03-15 21:55:59 +01:00
|
|
|
|
local tooldef
|
2020-11-02 19:09:23 +01:00
|
|
|
|
local tool
|
2021-05-29 16:12:33 +02:00
|
|
|
|
if digger then
|
2020-11-02 19:09:23 +01:00
|
|
|
|
tool = digger:get_wielded_item()
|
2021-03-15 21:55:59 +01:00
|
|
|
|
tooldef = minetest.registered_tools[tool:get_name()]
|
2017-08-03 01:01:44 +02:00
|
|
|
|
|
2021-03-15 21:55:59 +01:00
|
|
|
|
if not mcl_autogroup.can_harvest(dug_node.name, tool:get_name()) then
|
2018-03-05 12:53:16 +01:00
|
|
|
|
return
|
|
|
|
|
end
|
2017-08-03 01:01:44 +02:00
|
|
|
|
end
|
|
|
|
|
|
2021-03-16 20:36:38 +01:00
|
|
|
|
local diggroups = tooldef and tooldef._mcl_diggroups
|
2021-03-15 21:55:59 +01:00
|
|
|
|
local shearsy_level = diggroups and diggroups.shearsy and diggroups.shearsy.level
|
|
|
|
|
|
2020-11-02 19:09:23 +01:00
|
|
|
|
--[[ Special node drops when dug by shears by reading _mcl_shears_drop or with a silk touch tool reading _mcl_silk_touch_drop
|
2017-08-03 02:27:55 +02:00
|
|
|
|
from the node definition.
|
2020-11-02 19:09:23 +01:00
|
|
|
|
Definition of _mcl_shears_drop / _mcl_silk_touch_drop:
|
|
|
|
|
* true: Drop itself when dug by shears / silk touch tool
|
|
|
|
|
* table: Drop every itemstring in this table when dug by shears _mcl_silk_touch_drop
|
2017-08-03 02:27:55 +02:00
|
|
|
|
]]
|
2021-01-04 10:15:28 +01:00
|
|
|
|
|
2020-11-06 13:46:52 +01:00
|
|
|
|
local enchantments = tool and mcl_enchanting.get_enchantments(tool, "silk_touch")
|
2021-01-04 10:15:28 +01:00
|
|
|
|
|
2020-11-02 19:09:23 +01:00
|
|
|
|
local silk_touch_drop = false
|
2017-08-03 02:27:55 +02:00
|
|
|
|
local nodedef = minetest.registered_nodes[dug_node.name]
|
2022-03-09 04:00:48 +01:00
|
|
|
|
if not nodedef then return end
|
|
|
|
|
|
2021-03-15 21:55:59 +01:00
|
|
|
|
if shearsy_level and shearsy_level > 0 and nodedef._mcl_shears_drop then
|
2017-08-03 02:27:55 +02:00
|
|
|
|
if nodedef._mcl_shears_drop == true then
|
|
|
|
|
drops = { dug_node.name }
|
|
|
|
|
else
|
|
|
|
|
drops = nodedef._mcl_shears_drop
|
|
|
|
|
end
|
2020-11-06 13:46:52 +01:00
|
|
|
|
elseif tool and enchantments.silk_touch and nodedef._mcl_silk_touch_drop then
|
2020-11-02 19:09:23 +01:00
|
|
|
|
silk_touch_drop = true
|
|
|
|
|
if nodedef._mcl_silk_touch_drop == true then
|
|
|
|
|
drops = { dug_node.name }
|
|
|
|
|
else
|
|
|
|
|
drops = nodedef._mcl_silk_touch_drop
|
|
|
|
|
end
|
2017-08-03 02:27:55 +02:00
|
|
|
|
end
|
2021-01-04 10:15:28 +01:00
|
|
|
|
|
2020-11-06 13:46:52 +01:00
|
|
|
|
if tool and nodedef._mcl_fortune_drop and enchantments.fortune then
|
|
|
|
|
local fortune_level = enchantments.fortune
|
|
|
|
|
local fortune_drop = nodedef._mcl_fortune_drop
|
|
|
|
|
if fortune_drop.discrete_uniform_distribution then
|
|
|
|
|
local min_count = fortune_drop.min_count
|
|
|
|
|
local max_count = fortune_drop.max_count + fortune_level * (fortune_drop.factor or 1)
|
|
|
|
|
local chance = fortune_drop.chance or fortune_drop.get_chance and fortune_drop.get_chance(fortune_level)
|
|
|
|
|
if not chance or math.random() < chance then
|
|
|
|
|
drops = discrete_uniform_distribution(fortune_drop.multiply and drops or fortune_drop.items, min_count, max_count, fortune_drop.cap)
|
|
|
|
|
elseif fortune_drop.override then
|
|
|
|
|
drops = {}
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
-- Fixed Behavior
|
2021-01-04 10:15:28 +01:00
|
|
|
|
local drop = get_fortune_drops(fortune_drop, fortune_level)
|
2020-11-06 13:46:52 +01:00
|
|
|
|
drops = get_drops(drop, tool:get_name(), dug_node.param2, nodedef.paramtype2)
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-08-03 02:27:55 +02:00
|
|
|
|
|
2021-11-03 19:36:57 +01:00
|
|
|
|
if digger and mcl_experience.throw_xp and not silk_touch_drop then
|
2020-11-02 19:09:23 +01:00
|
|
|
|
local experience_amount = minetest.get_item_group(dug_node.name,"xp")
|
|
|
|
|
if experience_amount > 0 then
|
2021-11-03 19:36:57 +01:00
|
|
|
|
mcl_experience.throw_xp(pos, experience_amount)
|
2020-11-02 19:09:23 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2021-01-04 10:15:28 +01:00
|
|
|
|
|
2015-06-29 19:55:56 +02:00
|
|
|
|
for _,item in ipairs(drops) do
|
2019-03-01 17:30:21 +01:00
|
|
|
|
local count
|
2015-06-29 19:55:56 +02:00
|
|
|
|
if type(item) == "string" then
|
2019-03-01 17:30:21 +01:00
|
|
|
|
count = ItemStack(item):get_count()
|
2015-06-29 19:55:56 +02:00
|
|
|
|
else
|
|
|
|
|
count = item:get_count()
|
|
|
|
|
end
|
2019-03-01 17:30:21 +01:00
|
|
|
|
local drop_item = ItemStack(item)
|
|
|
|
|
drop_item:set_count(1)
|
2017-05-23 19:32:20 +02:00
|
|
|
|
for i=1,count do
|
2019-12-18 03:10:49 +01:00
|
|
|
|
local dpos = table.copy(pos)
|
|
|
|
|
-- Apply offset for plantlike_rooted nodes because of their special shape
|
|
|
|
|
if nodedef and nodedef.drawtype == "plantlike_rooted" and nodedef.walkable then
|
|
|
|
|
dpos.y = dpos.y + 1
|
|
|
|
|
end
|
|
|
|
|
-- Spawn item and apply random speed
|
2020-01-06 13:02:30 +01:00
|
|
|
|
local obj = minetest.add_item(dpos, drop_item)
|
2021-05-29 16:12:33 +02:00
|
|
|
|
if obj then
|
2017-05-23 19:32:20 +02:00
|
|
|
|
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
|
2015-06-29 19:55:56 +02:00
|
|
|
|
end
|
2019-03-06 04:38:57 +01:00
|
|
|
|
obj:set_velocity({x=1/x, y=obj:get_velocity().y, z=1/z})
|
2021-04-03 06:42:20 +02:00
|
|
|
|
|
|
|
|
|
obj:get_luaentity().age = item_drop_settings.dug_buffer
|
|
|
|
|
|
|
|
|
|
obj:get_luaentity()._insta_collect = false
|
2015-06-29 19:55:56 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-05-29 17:13:58 +02:00
|
|
|
|
-- Drop single items by default
|
|
|
|
|
function minetest.item_drop(itemstack, dropper, pos)
|
|
|
|
|
if dropper and dropper:is_player() then
|
|
|
|
|
local v = dropper:get_look_dir()
|
|
|
|
|
local p = {x=pos.x, y=pos.y+1.2, z=pos.z}
|
|
|
|
|
local cs = itemstack:get_count()
|
|
|
|
|
if dropper:get_player_control().sneak then
|
|
|
|
|
cs = 1
|
|
|
|
|
end
|
|
|
|
|
local item = itemstack:take_item(cs)
|
2020-01-06 13:02:30 +01:00
|
|
|
|
local obj = minetest.add_item(p, item)
|
2017-05-29 17:13:58 +02:00
|
|
|
|
if obj then
|
|
|
|
|
v.x = v.x*4
|
|
|
|
|
v.y = v.y*4 + 2
|
|
|
|
|
v.z = v.z*4
|
2019-03-06 04:38:57 +01:00
|
|
|
|
obj:set_velocity(v)
|
2017-05-30 18:16:36 +02:00
|
|
|
|
-- Force collection delay
|
|
|
|
|
obj:get_luaentity()._insta_collect = false
|
2017-05-29 17:13:58 +02:00
|
|
|
|
return itemstack
|
2017-02-16 00:57:35 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--modify builtin:item
|
|
|
|
|
|
2018-06-20 19:02:52 +02:00
|
|
|
|
local time_to_live = tonumber(minetest.settings:get("item_entity_ttl"))
|
2017-02-16 00:57:35 +01:00
|
|
|
|
if not time_to_live then
|
2017-05-29 17:18:43 +02:00
|
|
|
|
time_to_live = 300
|
2017-02-16 00:57:35 +01:00
|
|
|
|
end
|
|
|
|
|
|
2021-05-28 00:07:06 +02:00
|
|
|
|
local function cxcz(o, cw, one, zero)
|
|
|
|
|
if cw < 0 then
|
|
|
|
|
table.insert(o, { [one]=1, y=0, [zero]=0 })
|
|
|
|
|
table.insert(o, { [one]=-1, y=0, [zero]=0 })
|
|
|
|
|
else
|
|
|
|
|
table.insert(o, { [one]=-1, y=0, [zero]=0 })
|
|
|
|
|
table.insert(o, { [one]=1, y=0, [zero]=0 })
|
|
|
|
|
end
|
|
|
|
|
return o
|
|
|
|
|
end
|
|
|
|
|
|
2020-01-06 13:02:30 +01:00
|
|
|
|
minetest.register_entity(":__builtin:item", {
|
2017-02-16 00:57:35 +01:00
|
|
|
|
initial_properties = {
|
|
|
|
|
hp_max = 1,
|
|
|
|
|
physical = true,
|
|
|
|
|
collide_with_objects = false,
|
|
|
|
|
collisionbox = {-0.3, -0.3, -0.3, 0.3, 0.3, 0.3},
|
2019-03-07 03:53:06 +01:00
|
|
|
|
pointable = false,
|
2017-02-16 00:57:35 +01:00
|
|
|
|
visual = "wielditem",
|
|
|
|
|
visual_size = {x = 0.4, y = 0.4},
|
|
|
|
|
textures = {""},
|
|
|
|
|
spritediv = {x = 1, y = 1},
|
|
|
|
|
initial_sprite_basepos = {x = 0, y = 0},
|
|
|
|
|
is_visible = false,
|
|
|
|
|
infotext = "",
|
|
|
|
|
},
|
|
|
|
|
|
2017-12-01 18:50:15 +01:00
|
|
|
|
-- Itemstring of dropped item. The empty string is used when the item is not yet initialized yet.
|
|
|
|
|
-- The itemstring MUST be set immediately to a non-empty string after creating the entity.
|
|
|
|
|
-- The hand is NOT permitted as dropped item. ;-)
|
|
|
|
|
-- Item entities will be deleted if they still have an empty itemstring on their first on_step tick.
|
2021-05-29 16:12:33 +02:00
|
|
|
|
itemstring = "",
|
2017-12-01 18:50:15 +01:00
|
|
|
|
|
|
|
|
|
-- If true, item will fall
|
2017-02-16 00:57:35 +01:00
|
|
|
|
physical_state = true,
|
2017-12-01 18:50:15 +01:00
|
|
|
|
|
|
|
|
|
-- If item entity is currently flowing in water
|
|
|
|
|
_flowing = false,
|
|
|
|
|
|
|
|
|
|
-- Number of seconds this item entity has existed so far
|
2017-02-16 00:57:35 +01:00
|
|
|
|
age = 0,
|
|
|
|
|
|
2021-04-02 05:48:00 +02:00
|
|
|
|
-- How old it has become in the collection animation
|
|
|
|
|
collection_age = 0,
|
|
|
|
|
|
2017-02-16 00:57:35 +01:00
|
|
|
|
set_item = function(self, itemstring)
|
|
|
|
|
self.itemstring = itemstring
|
2017-12-01 18:50:15 +01:00
|
|
|
|
if self.itemstring == "" then
|
|
|
|
|
-- item not yet known
|
|
|
|
|
return
|
|
|
|
|
end
|
2017-02-16 00:57:35 +01:00
|
|
|
|
local stack = ItemStack(itemstring)
|
2021-05-04 10:24:08 +02:00
|
|
|
|
if minetest.get_item_group(stack:get_name(), "compass") > 0 then
|
2022-05-12 20:57:54 +02:00
|
|
|
|
if string.find(stack:get_name(), "_lodestone") then
|
|
|
|
|
stack:set_name("mcl_compass:18_lodestone")
|
|
|
|
|
else
|
|
|
|
|
stack:set_name("mcl_compass:18")
|
|
|
|
|
end
|
2021-05-04 10:24:08 +02:00
|
|
|
|
itemstring = stack:to_string()
|
|
|
|
|
self.itemstring = itemstring
|
|
|
|
|
end
|
|
|
|
|
if minetest.get_item_group(stack:get_name(), "clock") > 0 then
|
|
|
|
|
self.is_clock = true
|
|
|
|
|
end
|
2017-02-16 00:57:35 +01:00
|
|
|
|
local count = stack:get_count()
|
|
|
|
|
local max_count = stack:get_stack_max()
|
|
|
|
|
if count > max_count then
|
|
|
|
|
count = max_count
|
|
|
|
|
self.itemstring = stack:get_name().." "..max_count
|
|
|
|
|
end
|
|
|
|
|
local itemtable = stack:to_table()
|
|
|
|
|
local itemname = nil
|
|
|
|
|
local description = ""
|
|
|
|
|
if itemtable then
|
|
|
|
|
itemname = stack:to_table().name
|
|
|
|
|
end
|
2019-12-14 17:40:16 +01:00
|
|
|
|
local glow
|
2020-04-08 04:07:16 +02:00
|
|
|
|
local def = minetest.registered_items[itemname]
|
|
|
|
|
if def then
|
|
|
|
|
description = def.description
|
|
|
|
|
glow = def.light_source
|
2019-12-14 17:40:16 +01:00
|
|
|
|
end
|
2020-04-08 04:07:16 +02:00
|
|
|
|
local s = 0.2 + 0.1 * (count / max_count)
|
|
|
|
|
local wield_scale = (def and def.wield_scale and def.wield_scale.x) or 1
|
|
|
|
|
local c = s
|
|
|
|
|
s = s / wield_scale
|
2017-02-16 00:57:35 +01:00
|
|
|
|
local prop = {
|
|
|
|
|
is_visible = true,
|
|
|
|
|
visual = "wielditem",
|
|
|
|
|
textures = {itemname},
|
|
|
|
|
visual_size = {x = s, y = s},
|
|
|
|
|
collisionbox = {-c, -c, -c, c, c, c},
|
|
|
|
|
automatic_rotate = math.pi * 0.5,
|
|
|
|
|
infotext = description,
|
2019-12-14 17:40:16 +01:00
|
|
|
|
glow = glow,
|
2017-02-16 00:57:35 +01:00
|
|
|
|
}
|
|
|
|
|
self.object:set_properties(prop)
|
|
|
|
|
if item_drop_settings.random_item_velocity == true then
|
2017-05-27 15:17:03 +02:00
|
|
|
|
minetest.after(0, function(self)
|
|
|
|
|
if not self or not self.object or not self.object:get_luaentity() then
|
|
|
|
|
return
|
|
|
|
|
end
|
2019-03-06 04:38:57 +01:00
|
|
|
|
local vel = self.object:get_velocity()
|
2017-02-18 02:06:21 +01:00
|
|
|
|
if vel and vel.x == 0 and vel.z == 0 then
|
2017-02-16 00:57:35 +01:00
|
|
|
|
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
|
|
|
|
|
local y = math.random(2,4)
|
2019-03-06 04:38:57 +01:00
|
|
|
|
self.object:set_velocity({x=1/x, y=y, z=1/z})
|
2017-02-16 00:57:35 +01:00
|
|
|
|
end
|
2017-05-27 15:17:03 +02:00
|
|
|
|
end, self)
|
2017-02-16 00:57:35 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end,
|
|
|
|
|
|
|
|
|
|
get_staticdata = function(self)
|
2021-07-28 20:44:48 +02:00
|
|
|
|
local data = minetest.serialize({
|
2017-02-16 00:57:35 +01:00
|
|
|
|
itemstring = self.itemstring,
|
|
|
|
|
always_collect = self.always_collect,
|
|
|
|
|
age = self.age,
|
2017-05-29 23:31:41 +02:00
|
|
|
|
_insta_collect = self._insta_collect,
|
2017-06-10 20:47:12 +02:00
|
|
|
|
_flowing = self._flowing,
|
2017-09-05 17:25:15 +02:00
|
|
|
|
_removed = self._removed,
|
2017-02-16 00:57:35 +01:00
|
|
|
|
})
|
2021-07-28 20:44:48 +02:00
|
|
|
|
-- sfan5 guessed that the biggest serializable item
|
|
|
|
|
-- entity would have a size of 65530 bytes. This has
|
|
|
|
|
-- been experimentally verified to be still too large.
|
|
|
|
|
--
|
|
|
|
|
-- anon5 has calculated that the biggest serializable
|
|
|
|
|
-- item entity has a size of exactly 65487 bytes:
|
|
|
|
|
--
|
|
|
|
|
-- 1. serializeString16 can handle max. 65535 bytes.
|
|
|
|
|
-- 2. The following engine metadata is always saved:
|
|
|
|
|
-- • 1 byte (version)
|
|
|
|
|
-- • 2 byte (length prefix)
|
|
|
|
|
-- • 14 byte “__builtin:item”
|
|
|
|
|
-- • 4 byte (length prefix)
|
|
|
|
|
-- • 2 byte (health)
|
|
|
|
|
-- • 3 × 4 byte = 12 byte (position)
|
|
|
|
|
-- • 4 byte (yaw)
|
|
|
|
|
-- • 1 byte (version 2)
|
|
|
|
|
-- • 2 × 4 byte = 8 byte (pitch and roll)
|
|
|
|
|
-- 3. This leaves 65487 bytes for the serialization.
|
|
|
|
|
if #data > 65487 then -- would crash the engine
|
|
|
|
|
local stack = ItemStack(self.itemstring)
|
|
|
|
|
stack:get_meta():from_table(nil)
|
|
|
|
|
self.itemstring = stack:to_string()
|
2021-07-29 15:46:50 +02:00
|
|
|
|
minetest.log(
|
|
|
|
|
"warning",
|
|
|
|
|
"Overlong item entity metadata removed: “" ..
|
|
|
|
|
self.itemstring ..
|
|
|
|
|
"” had serialized length of " ..
|
|
|
|
|
#data
|
|
|
|
|
)
|
2021-07-28 20:44:48 +02:00
|
|
|
|
return self:get_staticdata()
|
|
|
|
|
end
|
|
|
|
|
return data
|
2017-02-16 00:57:35 +01:00
|
|
|
|
end,
|
|
|
|
|
|
|
|
|
|
on_activate = function(self, staticdata, dtime_s)
|
|
|
|
|
if string.sub(staticdata, 1, string.len("return")) == "return" then
|
2020-01-06 13:02:30 +01:00
|
|
|
|
local data = minetest.deserialize(staticdata)
|
2017-02-16 00:57:35 +01:00
|
|
|
|
if data and type(data) == "table" then
|
|
|
|
|
self.itemstring = data.itemstring
|
|
|
|
|
self.always_collect = data.always_collect
|
|
|
|
|
if data.age then
|
2022-07-03 11:28:43 +02:00
|
|
|
|
self.age = data.age
|
2017-02-16 00:57:35 +01:00
|
|
|
|
else
|
2022-07-03 11:28:43 +02:00
|
|
|
|
self.age = self.age
|
2017-02-16 00:57:35 +01:00
|
|
|
|
end
|
|
|
|
|
--remember collection data
|
2017-05-30 00:58:14 +02:00
|
|
|
|
-- If true, can collect item without delay
|
|
|
|
|
self._insta_collect = data._insta_collect
|
2017-06-10 20:47:12 +02:00
|
|
|
|
self._flowing = data._flowing
|
2017-09-05 17:25:15 +02:00
|
|
|
|
self._removed = data._removed
|
2017-02-16 00:57:35 +01:00
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
self.itemstring = staticdata
|
|
|
|
|
end
|
2017-09-05 17:25:15 +02:00
|
|
|
|
if self._removed then
|
|
|
|
|
self._removed = true
|
|
|
|
|
self.object:remove()
|
|
|
|
|
return
|
|
|
|
|
end
|
2017-05-30 18:16:36 +02:00
|
|
|
|
if self._insta_collect == nil then
|
|
|
|
|
-- Intentionally default, since delayed collection is rare
|
|
|
|
|
self._insta_collect = true
|
|
|
|
|
end
|
2017-06-10 20:47:12 +02:00
|
|
|
|
if self._flowing == nil then
|
|
|
|
|
self._flowing = false
|
|
|
|
|
end
|
2017-05-27 17:02:17 +02:00
|
|
|
|
self._magnet_timer = 0
|
2017-05-27 17:53:36 +02:00
|
|
|
|
self._magnet_active = false
|
|
|
|
|
-- How long ago the last possible collector was detected. nil = none in this session
|
|
|
|
|
self._collector_timer = nil
|
2017-05-30 00:58:14 +02:00
|
|
|
|
-- Used to apply additional force
|
|
|
|
|
self._force = nil
|
|
|
|
|
self._forcestart = nil
|
|
|
|
|
self._forcetimer = 0
|
|
|
|
|
|
2017-02-16 00:57:35 +01:00
|
|
|
|
self.object:set_armor_groups({immortal = 1})
|
2019-03-06 04:38:57 +01:00
|
|
|
|
self.object:set_velocity({x = 0, y = 2, z = 0})
|
|
|
|
|
self.object:set_acceleration({x = 0, y = -get_gravity(), z = 0})
|
2017-02-16 00:57:35 +01:00
|
|
|
|
self:set_item(self.itemstring)
|
|
|
|
|
end,
|
|
|
|
|
|
2017-09-05 19:17:40 +02:00
|
|
|
|
try_merge_with = function(self, own_stack, object, entity)
|
|
|
|
|
if self.age == entity.age or entity._removed then
|
|
|
|
|
-- Can not merge with itself and remove entity
|
|
|
|
|
return false
|
2017-02-16 00:57:35 +01:00
|
|
|
|
end
|
2017-09-05 19:17:40 +02:00
|
|
|
|
|
|
|
|
|
local stack = ItemStack(entity.itemstring)
|
|
|
|
|
local name = stack:get_name()
|
|
|
|
|
if own_stack:get_name() ~= name or
|
|
|
|
|
own_stack:get_meta() ~= stack:get_meta() or
|
|
|
|
|
own_stack:get_wear() ~= stack:get_wear() or
|
|
|
|
|
own_stack:get_free_space() == 0 then
|
|
|
|
|
-- Can not merge different or full stack
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local count = own_stack:get_count()
|
|
|
|
|
local total_count = stack:get_count() + count
|
|
|
|
|
local max_count = stack:get_stack_max()
|
|
|
|
|
|
|
|
|
|
if total_count > max_count then
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
-- Merge the remote stack into this one
|
|
|
|
|
|
|
|
|
|
local pos = object:get_pos()
|
|
|
|
|
pos.y = pos.y + ((total_count - count) / max_count) * 0.15
|
|
|
|
|
self.object:move_to(pos)
|
|
|
|
|
|
|
|
|
|
self.age = 0 -- Handle as new entity
|
|
|
|
|
own_stack:set_count(total_count)
|
|
|
|
|
self:set_item(own_stack:to_string())
|
|
|
|
|
|
|
|
|
|
entity._removed = true
|
|
|
|
|
object:remove()
|
|
|
|
|
return true
|
2017-02-16 00:57:35 +01:00
|
|
|
|
end,
|
|
|
|
|
|
2021-09-06 16:34:25 +02:00
|
|
|
|
on_step = function(self, dtime, moveresult)
|
2017-09-05 17:25:15 +02:00
|
|
|
|
if self._removed then
|
2021-04-03 03:40:04 +02:00
|
|
|
|
self.object:set_properties({
|
|
|
|
|
physical = false
|
|
|
|
|
})
|
2021-04-03 03:50:47 +02:00
|
|
|
|
self.object:set_velocity({x=0,y=0,z=0})
|
|
|
|
|
self.object:set_acceleration({x=0,y=0,z=0})
|
2017-09-05 17:25:15 +02:00
|
|
|
|
return
|
|
|
|
|
end
|
2017-02-16 00:57:35 +01:00
|
|
|
|
self.age = self.age + dtime
|
2021-05-29 16:12:33 +02:00
|
|
|
|
if self._collector_timer then
|
2017-05-27 17:53:36 +02:00
|
|
|
|
self._collector_timer = self._collector_timer + dtime
|
|
|
|
|
end
|
2017-02-16 00:57:35 +01:00
|
|
|
|
if time_to_live > 0 and self.age > time_to_live then
|
2017-09-05 17:25:15 +02:00
|
|
|
|
self._removed = true
|
2017-02-16 00:57:35 +01:00
|
|
|
|
self.object:remove()
|
|
|
|
|
return
|
|
|
|
|
end
|
2017-12-01 18:50:15 +01:00
|
|
|
|
-- Delete corrupted item entities. The itemstring MUST be non-empty on its first step,
|
|
|
|
|
-- otherwise there might have some data corruption.
|
|
|
|
|
if self.itemstring == "" then
|
2019-02-01 06:33:07 +01:00
|
|
|
|
minetest.log("warning", "Item entity with empty itemstring found at "..minetest.pos_to_string(self.object:get_pos()).. "! Deleting it now.")
|
2017-12-01 18:50:15 +01:00
|
|
|
|
self._removed = true
|
|
|
|
|
self.object:remove()
|
2020-08-29 10:57:33 +02:00
|
|
|
|
return
|
2017-09-02 18:43:02 +02:00
|
|
|
|
end
|
|
|
|
|
|
2019-02-01 06:33:07 +01:00
|
|
|
|
local p = self.object:get_pos()
|
2020-01-06 13:02:30 +01:00
|
|
|
|
local node = minetest.get_node_or_nil(p)
|
2017-02-16 00:57:35 +01:00
|
|
|
|
local in_unloaded = (node == nil)
|
2017-05-27 17:53:36 +02:00
|
|
|
|
|
2021-05-04 09:16:42 +02:00
|
|
|
|
if self.is_clock then
|
|
|
|
|
self.object:set_properties({
|
|
|
|
|
textures = {"mcl_clock:clock_" .. (mcl_worlds.clock_works(p) and mcl_clock.old_time or mcl_clock.random_frame)}
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
2017-05-27 17:53:36 +02:00
|
|
|
|
-- If no collector was found for a long enough time, declare the magnet as disabled
|
|
|
|
|
if self._magnet_active and (self._collector_timer == nil or (self._collector_timer > item_drop_settings.magnet_time)) then
|
|
|
|
|
self._magnet_active = false
|
2017-06-10 20:37:17 +02:00
|
|
|
|
enable_physics(self.object, self)
|
2017-05-30 06:00:26 +02:00
|
|
|
|
return
|
2017-05-27 17:53:36 +02:00
|
|
|
|
end
|
2017-05-30 13:59:26 +02:00
|
|
|
|
if in_unloaded then
|
2017-06-10 20:37:17 +02:00
|
|
|
|
-- Don't infinetly fall into unloaded map
|
|
|
|
|
disable_physics(self.object, self)
|
2017-02-16 00:57:35 +01:00
|
|
|
|
return
|
|
|
|
|
end
|
2017-02-16 18:26:38 +01:00
|
|
|
|
|
2019-02-01 08:31:17 +01:00
|
|
|
|
-- Destroy item in lava, fire or special nodes
|
2017-02-16 00:57:35 +01:00
|
|
|
|
local nn = node.name
|
2022-07-22 07:34:58 +02:00
|
|
|
|
local is_in_water = (minetest.get_item_group(nn, "water") ~= 0)
|
2017-02-16 19:32:42 +01:00
|
|
|
|
local def = minetest.registered_nodes[nn]
|
2019-02-01 08:31:17 +01:00
|
|
|
|
local lg = minetest.get_item_group(nn, "lava")
|
|
|
|
|
local fg = minetest.get_item_group(nn, "fire")
|
|
|
|
|
local dg = minetest.get_item_group(nn, "destroys_items")
|
|
|
|
|
if (def and (lg ~= 0 or fg ~= 0 or dg == 1)) then
|
2020-12-22 15:29:24 +01:00
|
|
|
|
--Wait 2 seconds to allow mob drops to be cooked, & picked up instead of instantly destroyed.
|
|
|
|
|
if self.age > 2 then
|
|
|
|
|
if dg ~= 2 then
|
|
|
|
|
minetest.sound_play("builtin_item_lava", {pos = self.object:get_pos(), gain = 0.5})
|
|
|
|
|
end
|
|
|
|
|
self._removed = true
|
|
|
|
|
self.object:remove()
|
|
|
|
|
return
|
2017-02-16 19:32:42 +01:00
|
|
|
|
end
|
2017-02-16 18:26:38 +01:00
|
|
|
|
end
|
|
|
|
|
|
2021-09-06 16:34:25 +02:00
|
|
|
|
-- Destroy item when it collides with a cactus
|
|
|
|
|
if moveresult and moveresult.collides then
|
|
|
|
|
for _, collision in pairs(moveresult.collisions) do
|
|
|
|
|
local pos = collision.node_pos
|
|
|
|
|
if collision.type == "node" and minetest.get_node(pos).name == "mcl_core:cactus" then
|
|
|
|
|
self._removed = true
|
|
|
|
|
self.object:remove()
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-05-29 22:51:13 +02:00
|
|
|
|
-- Push item out when stuck inside solid opaque node
|
2022-07-22 07:34:58 +02:00
|
|
|
|
if not is_in_water and def and def.walkable and def.groups and def.groups.opaque == 1 then
|
2017-05-29 22:51:13 +02:00
|
|
|
|
local shootdir
|
2019-08-27 13:08:54 +02:00
|
|
|
|
local cx = (p.x % 1) - 0.5
|
|
|
|
|
local cz = (p.z % 1) - 0.5
|
2017-05-29 22:51:13 +02:00
|
|
|
|
local order = {}
|
|
|
|
|
|
|
|
|
|
-- First prepare the order in which the 4 sides are to be checked.
|
|
|
|
|
-- 1st: closest
|
|
|
|
|
-- 2nd: other direction
|
|
|
|
|
-- 3rd and 4th: other axis
|
2019-08-27 13:08:54 +02:00
|
|
|
|
if math.abs(cx) < math.abs(cz) then
|
2017-05-29 22:51:13 +02:00
|
|
|
|
order = cxcz(order, cx, "x", "z")
|
|
|
|
|
order = cxcz(order, cz, "z", "x")
|
|
|
|
|
else
|
|
|
|
|
order = cxcz(order, cz, "z", "x")
|
|
|
|
|
order = cxcz(order, cx, "x", "z")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Check which one of the 4 sides is free
|
|
|
|
|
for o=1, #order do
|
|
|
|
|
local nn = minetest.get_node(vector.add(p, order[o])).name
|
|
|
|
|
local def = minetest.registered_nodes[nn]
|
|
|
|
|
if def and def.walkable == false and nn ~= "ignore" then
|
|
|
|
|
shootdir = order[o]
|
2017-05-29 22:56:53 +02:00
|
|
|
|
break
|
2017-05-29 22:51:13 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
-- If none of the 4 sides is free, shoot upwards
|
|
|
|
|
if shootdir == nil then
|
|
|
|
|
shootdir = { x=0, y=1, z=0 }
|
|
|
|
|
local nn = minetest.get_node(vector.add(p, shootdir)).name
|
|
|
|
|
if nn == "ignore" then
|
|
|
|
|
-- Do not push into ignore
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Set new item moving speed accordingly
|
|
|
|
|
local newv = vector.multiply(shootdir, 3)
|
2019-03-06 04:38:57 +01:00
|
|
|
|
self.object:set_acceleration({x = 0, y = 0, z = 0})
|
|
|
|
|
self.object:set_velocity(newv)
|
2017-05-29 22:51:13 +02:00
|
|
|
|
|
2017-06-10 20:56:53 +02:00
|
|
|
|
disable_physics(self.object, self, false, false)
|
2017-05-30 00:58:14 +02:00
|
|
|
|
|
|
|
|
|
if shootdir.y == 0 then
|
|
|
|
|
self._force = newv
|
|
|
|
|
p.x = math.floor(p.x)
|
|
|
|
|
p.y = math.floor(p.y)
|
|
|
|
|
p.z = math.floor(p.z)
|
|
|
|
|
self._forcestart = p
|
|
|
|
|
self._forcetimer = 1
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- This code is run after the entity got a push from above “push away” code.
|
|
|
|
|
-- It is responsible for making sure the entity is entirely outside the solid node
|
|
|
|
|
-- (with its full collision box), not just its center.
|
|
|
|
|
if self._forcetimer > 0 then
|
|
|
|
|
local cbox = self.object:get_properties().collisionbox
|
|
|
|
|
local ok = false
|
|
|
|
|
if self._force.x > 0 and (p.x > (self._forcestart.x + 0.5 + (cbox[4] - cbox[1])/2)) then ok = true
|
|
|
|
|
elseif self._force.x < 0 and (p.x < (self._forcestart.x + 0.5 - (cbox[4] - cbox[1])/2)) then ok = true
|
|
|
|
|
elseif self._force.z > 0 and (p.z > (self._forcestart.z + 0.5 + (cbox[6] - cbox[3])/2)) then ok = true
|
|
|
|
|
elseif self._force.z < 0 and (p.z < (self._forcestart.z + 0.5 - (cbox[6] - cbox[3])/2)) then ok = true end
|
|
|
|
|
-- Item was successfully forced out. No more pushing
|
|
|
|
|
if ok then
|
|
|
|
|
self._forcetimer = -1
|
|
|
|
|
self._force = nil
|
2017-06-10 20:37:17 +02:00
|
|
|
|
enable_physics(self.object, self)
|
2017-05-30 00:58:14 +02:00
|
|
|
|
else
|
|
|
|
|
self._forcetimer = self._forcetimer - dtime
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
|
elseif self._force then
|
|
|
|
|
self._force = nil
|
2017-06-10 20:37:17 +02:00
|
|
|
|
enable_physics(self.object, self)
|
2017-05-29 22:51:13 +02:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2022-07-22 07:34:58 +02:00
|
|
|
|
local is_floating_on_water = false
|
2022-06-02 08:50:51 +02:00
|
|
|
|
-- Move item around on flowing liquids; add 'source' check to allow items to continue flowing a bit in the source block of flowing water.
|
2022-07-22 07:34:58 +02:00
|
|
|
|
if def and (def.liquidtype == "flowing" or def.liquidtype == "source") then
|
|
|
|
|
self._flowing = true
|
2017-02-16 18:26:38 +01:00
|
|
|
|
|
2017-02-19 23:41:46 +01:00
|
|
|
|
--[[ Get flowing direction (function call from flowlib), if there's a liquid.
|
|
|
|
|
NOTE: According to Qwertymine, flowlib.quickflow is only reliable for liquids with a flowing distance of 7.
|
|
|
|
|
Luckily, this is exactly what we need if we only care about water, which has this flowing distance. ]]
|
2017-05-29 21:42:24 +02:00
|
|
|
|
local vec = flowlib.quick_flow(p, node)
|
2017-02-19 23:41:46 +01:00
|
|
|
|
-- Just to make sure we don't manipulate the speed for no reason
|
|
|
|
|
if vec.x ~= 0 or vec.y ~= 0 or vec.z ~= 0 then
|
2017-02-16 18:26:38 +01:00
|
|
|
|
-- Minecraft Wiki: Flowing speed is "about 1.39 meters per second"
|
2022-06-03 12:46:27 +02:00
|
|
|
|
local f = 1.2
|
2017-02-19 23:41:46 +01:00
|
|
|
|
-- Set new item moving speed into the direciton of the liquid
|
|
|
|
|
local newv = vector.multiply(vec, f)
|
2022-06-03 12:46:27 +02:00
|
|
|
|
-- Swap to acceleration instead of a static speed to better mimic MC mechanics.
|
|
|
|
|
self.object:set_acceleration({x = newv.x, y = -0.22, z = newv.z})
|
2017-02-16 18:26:38 +01:00
|
|
|
|
|
|
|
|
|
self.physical_state = true
|
2017-06-10 20:47:12 +02:00
|
|
|
|
self._flowing = true
|
2017-02-16 18:26:38 +01:00
|
|
|
|
self.object:set_properties({
|
|
|
|
|
physical = true
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
end
|
2022-07-22 07:34:58 +02:00
|
|
|
|
if is_in_water and def.liquidtype == "source" then
|
|
|
|
|
local cur_vec = self.object:get_velocity()
|
|
|
|
|
-- apply some acceleration in the opposite direction so it doesn't slide forever
|
|
|
|
|
local vec = {
|
|
|
|
|
x = 0 -cur_vec.x*0.9,
|
|
|
|
|
y = 3 -cur_vec.y*0.9,
|
|
|
|
|
z = 0 -cur_vec.z*0.9}
|
|
|
|
|
self.object:set_acceleration(vec)
|
|
|
|
|
if self.physical_state ~= false or self._flowing ~= true then
|
|
|
|
|
self.physical_state = true
|
|
|
|
|
self._flowing = true
|
|
|
|
|
self.object:set_properties({
|
|
|
|
|
physical = true
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
elseif self._flowing == true and not is_in_water then
|
2017-06-10 20:47:12 +02:00
|
|
|
|
-- Disable flowing physics if not on/in flowing liquid
|
|
|
|
|
self._flowing = false
|
2022-07-22 07:34:58 +02:00
|
|
|
|
local pos = self.object:get_pos()
|
|
|
|
|
disable_physics(self.object, self, false, false)
|
2017-06-10 20:47:12 +02:00
|
|
|
|
return
|
2017-02-16 18:26:38 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-02-16 00:57:35 +01:00
|
|
|
|
-- If node is not registered or node is walkably solid and resting on nodebox
|
2017-05-29 20:10:51 +02:00
|
|
|
|
local nn = minetest.get_node({x=p.x, y=p.y-0.5, z=p.z}).name
|
2019-03-06 04:38:57 +01:00
|
|
|
|
local v = self.object:get_velocity()
|
2017-02-16 18:26:38 +01:00
|
|
|
|
|
2022-06-02 08:50:51 +02:00
|
|
|
|
if not minetest.registered_nodes[nn] or minetest.registered_nodes[nn].walkable and not minetest.registered_nodes[nn].groups.slippery and v.y == 0 then
|
2017-02-16 00:57:35 +01:00
|
|
|
|
if self.physical_state then
|
|
|
|
|
local own_stack = ItemStack(self.object:get_luaentity().itemstring)
|
|
|
|
|
-- Merge with close entities of the same item
|
2021-03-16 17:43:32 +01:00
|
|
|
|
for _, object in pairs(minetest.get_objects_inside_radius(p, 0.8)) do
|
2017-02-16 00:57:35 +01:00
|
|
|
|
local obj = object:get_luaentity()
|
|
|
|
|
if obj and obj.name == "__builtin:item"
|
|
|
|
|
and obj.physical_state == false then
|
|
|
|
|
if self:try_merge_with(own_stack, object, obj) then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-07-22 07:34:58 +02:00
|
|
|
|
if not is_in_water then
|
|
|
|
|
disable_physics(self.object, self)
|
|
|
|
|
end
|
2017-02-16 00:57:35 +01:00
|
|
|
|
end
|
|
|
|
|
else
|
2017-06-10 20:37:17 +02:00
|
|
|
|
if self._magnet_active == false then
|
|
|
|
|
enable_physics(self.object, self)
|
2017-02-16 00:57:35 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
|
2017-02-17 02:47:29 +01:00
|
|
|
|
-- Note: on_punch intentionally left out. The player should *not* be able to collect items by punching
|
2017-02-16 00:57:35 +01:00
|
|
|
|
})
|