3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-10-08 10:50:11 +02:00

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.
Dieser Commit ist enthalten in:
Camotoy 2022-05-15 13:52:18 -04:00
Ursprung b33cc512b4
Commit b885e22fa3
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
2 geänderte Dateien mit 25 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -69,7 +69,10 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import com.nukkitx.protocol.bedrock.packet.*; import com.nukkitx.protocol.bedrock.packet.*;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.EventLoop; 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.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; 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.ItemFrameEntity;
import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.entity.type.Tickable;
import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; 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.Inventory;
import org.geysermc.geyser.inventory.PlayerInventory; import org.geysermc.geyser.inventory.PlayerInventory;
import org.geysermc.geyser.inventory.recipe.GeyserRecipe; import org.geysermc.geyser.inventory.recipe.GeyserRecipe;
@ -1092,15 +1094,17 @@ public class GeyserSession implements GeyserConnection, CommandSender {
worldBorder.resize(); worldBorder.resize();
} }
if (!worldBorder.isWithinWarningBoundaries()) { boolean shouldShowFog = !worldBorder.isWithinWarningBoundaries();
if (shouldShowFog || worldBorder.isCloseToBorderBoundaries()) {
// Show particles representing where the world border is // Show particles representing where the world border is
worldBorder.drawWall(); worldBorder.drawWall();
// Set the mood // Set the mood
if (!isInWorldBorderWarningArea) { if (shouldShowFog && !isInWorldBorderWarningArea) {
isInWorldBorderWarningArea = true; isInWorldBorderWarningArea = true;
sendFog("minecraft:fog_crimson_forest"); sendFog("minecraft:fog_crimson_forest");
} }
} else if (isInWorldBorderWarningArea) { }
if (!shouldShowFog && isInWorldBorderWarningArea) {
// Clear fog as we are outside the world border now // Clear fog as we are outside the world border now
removeFog("minecraft:fog_crimson_forest"); removeFog("minecraft:fog_crimson_forest");
isInWorldBorderWarningArea = false; isInWorldBorderWarningArea = false;

Datei anzeigen

@ -139,6 +139,18 @@ public class WorldBorder {
return position.getX() > minX && position.getX() < maxX && position.getZ() > minZ && position.getZ() < maxZ; 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. * 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. * 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 particlePosY = entityPosition.getY();
float particlePosZ = entityPosition.getZ(); 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); 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); 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); 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); drawWall(Vector3f.from(particlePosX, particlePosY, minZ), false);
} }
} }