Fix incorrect border collision detection

The epsilon used was in the opposite direction, which would cause
the getCollisions method to incorrectly return it for when players
were exactly on the border but not colliding. To bring it in-line
with the rest of the collision code, the collision must be into
the border by +EPSILON.

Additionally, move the setReadTimeoutHook in the server list
ping patch to a client-side mixin so it does not load in the
dedicated server causing a crash.
This commit is contained in:
Spottedleaf
2023-12-14 19:05:40 -08:00
parent 14b42d3419
commit bb6d1f2aaa
4 changed files with 46 additions and 27 deletions

View File

@@ -0,0 +1,38 @@
package ca.spottedleaf.moonrise.mixin.serverlist;
import ca.spottedleaf.moonrise.patches.serverlist.ServerListConnection;
import io.netty.channel.ChannelFuture;
import io.netty.channel.SimpleChannelInboundHandler;
import net.minecraft.client.multiplayer.ServerStatusPinger;
import net.minecraft.network.Connection;
import net.minecraft.network.protocol.Packet;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.net.InetSocketAddress;
@Mixin(Connection.class)
public abstract class ClientConnectionMixin extends SimpleChannelInboundHandler<Packet<?>> implements ServerListConnection {
/**
* @reason Dirty hack to set the timeout before connecting for server ping list
* @author Spottedleaf
*/
@Redirect(
method = "connectToServer",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/network/Connection;connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/network/Connection;)Lio/netty/channel/ChannelFuture;"
)
)
private static ChannelFuture setReadTimeoutHook(final InetSocketAddress address, final boolean epoll,
final Connection connection) {
if (StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).walk((s -> s.filter(f -> f.getDeclaringClass() == ServerStatusPinger.class).findAny())).isPresent()) {
final int timeout = 5;
// reduce timeout to 5s so that non-responding servers release the thread allocation fast
((ServerListConnection)connection).moonrise$setReadTimeout(timeout);
}
return Connection.connect(address, epoll, connection);
}
}

View File

@@ -86,26 +86,4 @@ public abstract class ConnectionMixin extends SimpleChannelInboundHandler<Packet
pipeline.channel().config().setOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout * 1000);
}
}
/**
* @reason Dirty hack to set the timeout before connecting for server ping list
* @author Spottedleaf
*/
@Redirect(
method = "connectToServer",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/network/Connection;connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/network/Connection;)Lio/netty/channel/ChannelFuture;"
)
)
private static ChannelFuture setReadTimeoutHook(final InetSocketAddress address, final boolean epoll,
final Connection connection) {
if (StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).walk((s -> s.filter(f -> f.getDeclaringClass() == ServerStatusPinger.class).findAny())).isPresent()) {
final int timeout = 5;
// reduce timeout to 5s so that non-responding servers release the thread allocation fast
((ServerListConnection)connection).moonrise$setReadTimeout(timeout);
}
return Connection.connect(address, epoll, connection);
}
}

View File

@@ -1619,13 +1619,15 @@ public final class CollisionUtil {
public static boolean isCollidingWithBorderEdge(final WorldBorder worldborder, final double boxMinX, final double boxMaxX,
final double boxMinZ, final double boxMaxZ) {
final double borderMinX = worldborder.getMinX() + COLLISION_EPSILON; // -X
final double borderMaxX = worldborder.getMaxX() - COLLISION_EPSILON; // +X
final double borderMinX = worldborder.getMinX(); // -X
final double borderMaxX = worldborder.getMaxX(); // +X
final double borderMinZ = worldborder.getMinZ() + COLLISION_EPSILON; // -Z
final double borderMaxZ = worldborder.getMaxZ() - COLLISION_EPSILON; // +Z
final double borderMinZ = worldborder.getMinZ(); // -Z
final double borderMaxZ = worldborder.getMaxZ(); // +Z
return boxMinX < borderMinX || boxMaxX > borderMaxX || boxMinZ < borderMinZ || boxMaxZ > borderMaxZ;
// inverted check for world border enclosing the specified box expanded by -EPSILON
return (borderMinX - boxMinX) > CollisionUtil.COLLISION_EPSILON || (borderMaxX - boxMaxX) < -CollisionUtil.COLLISION_EPSILON ||
(borderMinZ - boxMinZ) > CollisionUtil.COLLISION_EPSILON || (borderMaxZ - boxMaxZ) < -CollisionUtil.COLLISION_EPSILON;
}
/* Math.max/min specify that any NaN argument results in a NaN return, unlike these functions */

View File

@@ -69,6 +69,7 @@
"collisions.ParticleMixin",
"profiler.MinecraftMixin",
"serverlist.ServerSelectionListMixin",
"serverlist.ClientConnectionMixin",
"starlight.multiplayer.ClientPacketListenerMixin",
"starlight.world.ClientLevelMixin"
],