diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index 5f264329e..0daa43da8 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -69,7 +69,10 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.packet.*; import io.netty.channel.Channel; import io.netty.channel.EventLoop; -import it.unimi.dsi.fastutil.ints.*; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; @@ -94,7 +97,6 @@ import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.ItemFrameEntity; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; -import org.geysermc.geyser.entity.type.player.SkullPlayerEntity; import org.geysermc.geyser.inventory.Inventory; import org.geysermc.geyser.inventory.PlayerInventory; import org.geysermc.geyser.inventory.recipe.GeyserRecipe; @@ -1092,15 +1094,17 @@ public class GeyserSession implements GeyserConnection, CommandSender { worldBorder.resize(); } - if (!worldBorder.isWithinWarningBoundaries()) { + boolean shouldShowFog = !worldBorder.isWithinWarningBoundaries(); + if (shouldShowFog || worldBorder.isCloseToBorderBoundaries()) { // Show particles representing where the world border is worldBorder.drawWall(); // Set the mood - if (!isInWorldBorderWarningArea) { + if (shouldShowFog && !isInWorldBorderWarningArea) { isInWorldBorderWarningArea = true; sendFog("minecraft:fog_crimson_forest"); } - } else if (isInWorldBorderWarningArea) { + } + if (!shouldShowFog && isInWorldBorderWarningArea) { // Clear fog as we are outside the world border now removeFog("minecraft:fog_crimson_forest"); isInWorldBorderWarningArea = false; diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java b/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java index 66922ff0b..09e7e9234 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java @@ -139,6 +139,18 @@ public class WorldBorder { return position.getX() > minX && position.getX() < maxX && position.getZ() > minZ && position.getZ() < maxZ; } + private static final int CLOSE_TO_BORDER = 5; + + /** + * @return if the player is close to the border boundaries. Used to always indicate a border even if there is no + * warning blocks set. + */ + public boolean isCloseToBorderBoundaries() { + Vector3f position = session.getPlayerEntity().getPosition(); + return !(position.getX() > minX + CLOSE_TO_BORDER && position.getX() < maxX - CLOSE_TO_BORDER + && position.getZ() > minZ + CLOSE_TO_BORDER && position.getZ() < maxZ - CLOSE_TO_BORDER); + } + /** * Confirms that the entity is within world border boundaries when they move. * Otherwise, if {@code adjustPosition} is true, this function will push the player back. @@ -246,16 +258,16 @@ public class WorldBorder { float particlePosY = entityPosition.getY(); float particlePosZ = entityPosition.getZ(); - if (entityPosition.getX() > warningMaxX) { + if (entityPosition.getX() > Math.min(warningMaxX, maxX - CLOSE_TO_BORDER)) { drawWall(Vector3f.from(maxX, particlePosY, particlePosZ), true); } - if (entityPosition.getX() < warningMinX) { + if (entityPosition.getX() < Math.max(warningMinX, minX + CLOSE_TO_BORDER)) { drawWall(Vector3f.from(minX, particlePosY, particlePosZ), true); } - if (entityPosition.getZ() > warningMaxZ) { + if (entityPosition.getZ() > Math.min(warningMaxZ, maxZ - CLOSE_TO_BORDER)) { drawWall(Vector3f.from(particlePosX, particlePosY, maxZ), false); } - if (entityPosition.getZ() < warningMinZ) { + if (entityPosition.getZ() < Math.max(warningMinZ, minZ + CLOSE_TO_BORDER)) { drawWall(Vector3f.from(particlePosX, particlePosY, minZ), false); } }