New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Builtin item: Tidy up the code #4370
Conversation
4582607
to
a09e3eb
Compare
If you already change assumed gravity, then you should probably get the value from That won't account for realm specific overrides on players, but at least then it's consistent with server wide settings. |
59e2231
to
b45cad9
Compare
I need more opinions how the behaviour of the builtin item should be. From my side it looks okay. |
c626eeb
to
faca89f
Compare
I would adjust merge radius to 1.0, but everything else works a-ok that I'm using changes on Xanadu server. |
e12dab4
to
4908238
Compare
Comments for the last commit: I'm glad to see that everything runs fine on Xanadu, this means there were no problems found with these changes. |
4908238
to
7662d8f
Compare
0d2b423
to
1e3eb19
Compare
Rebased. |
1e3eb19
to
881f736
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haven't tested
builtin/game/item_entity.lua
Outdated
local count = math.min(stack:get_count(), max_count) | ||
local size = 0.2 + 0.1 * (count / max_count) | ||
|
||
if not core.registered_items[itemname] then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
odd how the old code didn't take aliases into account
builtin/game/item_entity.lua
Outdated
|
||
local stack = ItemStack(entity.itemstring) | ||
local name = stack:get_name() | ||
if own_stack:get_name() ~= name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with use breaks after binary operators
builtin/game/item_entity.lua
Outdated
return false | ||
-- Merge the remote stack into this one | ||
|
||
local pos = object:getpos() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_pos
builtin/game/item_entity.lua
Outdated
|
||
local pos = object:getpos() | ||
pos.y = pos.y + ((total_count - count) / max_count) * 0.15 | ||
self.object:moveto(pos) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move_to
builtin/game/item_entity.lua
Outdated
-- Don't infinetly fall into unloaded map | ||
self.object:setvelocity({x = 0, y = 0, z = 0}) | ||
|
||
local pos = self.object:getpos() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_pos()
builtin/game/item_entity.lua
Outdated
self.object:setvelocity({x = 0, y = 0, z = 0}) | ||
|
||
local pos = self.object:getpos() | ||
local node = minetest.get_node({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
core
as in builtin
builtin/game/item_entity.lua
Outdated
return | ||
end | ||
|
||
self.object:setvelocity({x=0, y=0, z=0}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set_velocity
builtin/game/item_entity.lua
Outdated
}) | ||
|
||
if is_falling then | ||
self.object:setacceleration({x = 0, y = -gravity, z = 0}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set_acceleration
builtin/game/item_entity.lua
Outdated
|
||
if is_falling then | ||
self.object:setacceleration({x = 0, y = -gravity, z = 0}) | ||
else | ||
self.object:setacceleration({x = 0, y = 0, z = 0}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set_acceleration
881f736
to
882b541
Compare
Thanks for the review. Does it look right now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 needs testing however
builtin/game/item_entity.lua
Outdated
self.object:set_acceleration({x = 0, y = 0, z = 0}) | ||
end | ||
|
||
-- Collect the items around to merge with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, merging is only attempted if the item has 'physical_state' true (in motion). The merging function is intensive so should not run for stationary ('physical_state' false) items, which are the majority of items present in a world.
Although i'm not too sure, this new code looks like it can run merging for stationary items?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not an issue, as this code part is only executed when the physical state changes. For stationary items this code part will not be executed at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
I'm ok with the changes to 'try merge with'. My fixing of items on ice (which may be added to this PR) means your changes to 'on step' cannot be done in the same way. So, 'on step' needs to be copied from #6300 and then possibly developed from that code. |
Use setting movement_gravity Reset age on merge Set merge radius to 1.0m
882b541
to
9be31c4
Compare
local slip_factor = 4.0 / (slippery + 4) | ||
self.object:set_acceleration({ | ||
x = -vel.x * slip_factor, | ||
y = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible that a walkable node is detected below before the item has hit it, so detecting a walkable node below should not set always set acceleration to zero. This will be difficult to notice visually but is incorrect physics.
The item is physical when it is in motion so that it uses it's collisionbox to stop moving vertically, then when vertical velocity becomes zero (we need to detect this, as in the previous code) we know it has hit a node and is supported by it and we can then set vertical motion to zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeting motion to zero when a walkable node below is detected may result in the item floating above or slightly buried in the node.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I'm using the collisionbox height now to detect the node below to ensure that the item is correctly lying on the node.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok good.
local slippery = core.get_item_group(node.name, "slippery") | ||
is_slippery = slippery ~= 0 | ||
if is_slippery then | ||
is_physical = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible that a walkable node is detected below before the item has hit it, because we don't know the size and offset of the item's collisionbox (and these vary). If the node is not slippery then this code sets physical to false (no motion), which is wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Abrupt stops of the item when a non-slippery node was detected is fixed now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will retest. |
Ok seems to work now so 👍 |
New code structure Use setting movement_gravity Reset age on merge Set merge radius to 1.0m
New code structure Use setting movement_gravity Reset age on merge Set merge radius to 1.0m
This commit changes the behaviour of
try_merge_with
:self
collects all similar items around instead of splitting (and deleting)