Always show the world border at least five blocks away

Previously, no indication that the world border exists would show if warning blocks was set to 0.
This commit is contained in:
Camotoy 2022-05-15 13:52:18 -04:00
parent b33cc512b4
commit b885e22fa3
No known key found for this signature in database
GPG Key ID: 7EEFB66FE798081F
2 changed files with 25 additions and 9 deletions

View File

@ -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;

View File

@ -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);
}
}