mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 10:03:45 +01:00
Item entities: Enable item collision detection for sudden movement
This commit is contained in:
parent
179476d833
commit
ce832eb421
@ -33,7 +33,7 @@ core.register_entity(":__builtin:item", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
itemstring = "",
|
itemstring = "",
|
||||||
physical_state = true,
|
moving_state = true,
|
||||||
slippery_state = false,
|
slippery_state = false,
|
||||||
age = 0,
|
age = 0,
|
||||||
|
|
||||||
@ -148,16 +148,14 @@ core.register_entity(":__builtin:item", {
|
|||||||
local vel = self.object:getvelocity()
|
local vel = self.object:getvelocity()
|
||||||
local def = node and core.registered_nodes[node.name]
|
local def = node and core.registered_nodes[node.name]
|
||||||
-- Ignore is nil -> stop until the block loaded
|
-- Ignore is nil -> stop until the block loaded
|
||||||
local is_physical = (def and not def.walkable) or vel.y ~= 0
|
local is_moving = (def and not def.walkable) or
|
||||||
|
vel.x ~= 0 or vel.y ~= 0 or vel.z ~= 0
|
||||||
local is_slippery = false
|
local is_slippery = false
|
||||||
|
|
||||||
if def and def.walkable and
|
if def and def.walkable then
|
||||||
(math.abs(vel.x) > 0.2 or math.abs(vel.z) > 0.2) then
|
|
||||||
local slippery = core.get_item_group(node.name, "slippery")
|
local slippery = core.get_item_group(node.name, "slippery")
|
||||||
is_slippery = slippery ~= 0
|
is_slippery = slippery ~= 0
|
||||||
if is_slippery then
|
if is_slippery and (math.abs(vel.x) > 0.2 or math.abs(vel.z) > 0.2) then
|
||||||
is_physical = true
|
|
||||||
|
|
||||||
-- Horizontal deceleration
|
-- Horizontal deceleration
|
||||||
local slip_factor = 4.0 / (slippery + 4)
|
local slip_factor = 4.0 / (slippery + 4)
|
||||||
self.object:set_acceleration({
|
self.object:set_acceleration({
|
||||||
@ -165,32 +163,31 @@ core.register_entity(":__builtin:item", {
|
|||||||
y = 0,
|
y = 0,
|
||||||
z = -vel.z * slip_factor
|
z = -vel.z * slip_factor
|
||||||
})
|
})
|
||||||
|
elseif vel.y == 0 then
|
||||||
|
is_moving = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.physical_state == is_physical and
|
if self.moving_state == is_moving and
|
||||||
self.slippery_state == is_slippery then
|
self.slippery_state == is_slippery then
|
||||||
-- Do not update anything until the physical state changes
|
-- Do not update anything until the moving state changes
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
self.physical_state = is_physical
|
self.moving_state = is_moving
|
||||||
self.slippery_state = is_slippery
|
self.slippery_state = is_slippery
|
||||||
self.object:set_properties({
|
|
||||||
physical = is_physical
|
|
||||||
})
|
|
||||||
|
|
||||||
if is_slippery then
|
if is_moving then
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if is_physical then
|
|
||||||
self.object:set_acceleration({x = 0, y = -gravity, z = 0})
|
self.object:set_acceleration({x = 0, y = -gravity, z = 0})
|
||||||
else
|
else
|
||||||
self.object:set_acceleration({x = 0, y = 0, z = 0})
|
self.object:set_acceleration({x = 0, y = 0, z = 0})
|
||||||
self.object:set_velocity({x = 0, y = 0, z = 0})
|
self.object:set_velocity({x = 0, y = 0, z = 0})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--Only collect items if not moving
|
||||||
|
if is_moving then
|
||||||
|
return
|
||||||
|
end
|
||||||
-- Collect the items around to merge with
|
-- Collect the items around to merge with
|
||||||
local own_stack = ItemStack(self.itemstring)
|
local own_stack = ItemStack(self.itemstring)
|
||||||
if own_stack:get_free_space() == 0 then
|
if own_stack:get_free_space() == 0 then
|
||||||
|
Loading…
Reference in New Issue
Block a user