Use absolute value for bouncy in collision (#11969)

* use abs(bouncy) in collision
* test case for negative bouncy
* send abs(bouncy) to old clients
This commit is contained in:
pecksin 2022-02-16 17:06:00 -05:00 committed by GitHub
parent 258ae99491
commit 5d0b18a0d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 4 deletions

@ -252,9 +252,9 @@ for i=-100, 100, 25 do
end end
-- Bouncy nodes (various bounce levels) -- Bouncy nodes (various bounce levels)
for i=20, 180, 20 do for i=-140, 180, 20 do
local val = math.floor(((i-20)/200)*255) local val = math.floor(((i-20)/200)*255)
minetest.register_node("testnodes:bouncy"..i, { minetest.register_node(("testnodes:bouncy"..i):gsub("-","NEG"), {
description = S("Bouncy Node (@1%)", i), description = S("Bouncy Node (@1%)", i),
groups = {bouncy=i, dig_immediate=3}, groups = {bouncy=i, dig_immediate=3},

@ -303,7 +303,8 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
if (!f.walkable) if (!f.walkable)
continue; continue;
int n_bouncy_value = itemgroup_get(f.groups, "bouncy"); // Negative bouncy may have a meaning, but we need +value here.
int n_bouncy_value = abs(itemgroup_get(f.groups, "bouncy"));
int neighbors = 0; int neighbors = 0;
if (f.drawtype == NDT_NODEBOX && if (f.drawtype == NDT_NODEBOX &&

@ -452,8 +452,13 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const
writeU16(os, groups.size()); writeU16(os, groups.size());
for (const auto &group : groups) { for (const auto &group : groups) {
os << serializeString16(group.first); os << serializeString16(group.first);
if (protocol_version < 41 && group.first.compare("bouncy") == 0) {
// Old clients may choke on negative bouncy value
writeS16(os, abs(group.second));
} else {
writeS16(os, group.second); writeS16(os, group.second);
} }
}
writeU8(os, param_type); writeU8(os, param_type);
writeU8(os, param_type_2); writeU8(os, param_type_2);