0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/spigot.git synced 2024-11-24 15:16:26 +00:00
spigot/CraftBukkit-Patches/0007-View-Distance.patch
2024-10-23 02:15:00 +11:00

90 lines
5.2 KiB
Diff

From 9226af3ca85df5e5903f4e02094f705c0beb07f0 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Sat, 23 Mar 2013 09:52:41 +1100
Subject: [PATCH] View Distance
This commit allows the user to select per world view distances.
diff --git a/src/main/java/net/minecraft/server/level/WorldServer.java b/src/main/java/net/minecraft/server/level/WorldServer.java
index 0166025d16..8aeb3a5683 100644
--- a/src/main/java/net/minecraft/server/level/WorldServer.java
+++ b/src/main/java/net/minecraft/server/level/WorldServer.java
@@ -277,8 +277,8 @@ public class WorldServer extends World implements ServerEntityGetter, GeneratorA
this.entityManager = new PersistentEntitySectionManager<>(Entity.class, new WorldServer.a(), entitypersistentstorage);
StructureTemplateManager structuretemplatemanager = minecraftserver.getStructureManager();
- int j = minecraftserver.getPlayerList().getViewDistance();
- int k = minecraftserver.getPlayerList().getSimulationDistance();
+ int j = this.spigotConfig.viewDistance; // Spigot
+ int k = this.spigotConfig.simulationDistance; // Spigot
PersistentEntitySectionManager persistententitysectionmanager = this.entityManager;
Objects.requireNonNull(this.entityManager);
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 5f117e0aaf..8fc11b1383 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -237,7 +237,8 @@ public abstract class PlayerList {
boolean flag1 = gamerules.getBoolean(GameRules.RULE_REDUCEDDEBUGINFO);
boolean flag2 = gamerules.getBoolean(GameRules.RULE_LIMITED_CRAFTING);
- playerconnection.send(new PacketPlayOutLogin(entityplayer.getId(), worlddata.isHardcore(), this.server.levelKeys(), this.getMaxPlayers(), this.viewDistance, this.simulationDistance, flag1, !flag, flag2, entityplayer.createCommonSpawnInfo(worldserver1), this.server.enforceSecureProfile()));
+ // Spigot - view distance
+ playerconnection.send(new PacketPlayOutLogin(entityplayer.getId(), worlddata.isHardcore(), this.server.levelKeys(), this.getMaxPlayers(), worldserver1.spigotConfig.viewDistance, worldserver1.spigotConfig.simulationDistance, flag1, !flag, flag2, entityplayer.createCommonSpawnInfo(worldserver1), this.server.enforceSecureProfile()));
entityplayer.getBukkitEntity().sendSupportedChannels(); // CraftBukkit
playerconnection.send(new PacketPlayOutServerDifficulty(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
playerconnection.send(new PacketPlayOutAbilities(entityplayer.getAbilities()));
@@ -689,6 +690,8 @@ public abstract class PlayerList {
WorldData worlddata = worldserver1.getLevelData();
entityplayer1.connection.send(new PacketPlayOutRespawn(entityplayer1.createCommonSpawnInfo(worldserver1), (byte) i));
+ entityplayer1.connection.send(new PacketPlayOutViewDistance(worldserver1.spigotConfig.viewDistance)); // Spigot
+ entityplayer1.connection.send(new ClientboundSetSimulationDistancePacket(worldserver1.spigotConfig.simulationDistance)); // Spigot
entityplayer1.connection.teleport(CraftLocation.toBukkit(entityplayer1.position(), worldserver1.getWorld(), entityplayer1.getYRot(), entityplayer1.getXRot())); // CraftBukkit
entityplayer1.connection.send(new PacketPlayOutSpawnPosition(worldserver.getSharedSpawnPos(), worldserver.getSharedSpawnAngle()));
entityplayer1.connection.send(new PacketPlayOutServerDifficulty(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
index 5ff085b9e6..acaf903011 100644
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
@@ -148,4 +148,36 @@ public class SpigotWorldConfig
expMerge = getDouble("merge-radius.exp", 3.0 );
log( "Experience Merge Radius: " + expMerge );
}
+
+ public int viewDistance;
+ private void viewDistance()
+ {
+ if ( SpigotConfig.version < 12 )
+ {
+ set( "view-distance", null );
+ }
+
+ Object viewDistanceObject = get( "view-distance", "default" );
+ viewDistance = ( viewDistanceObject ) instanceof Number ? ( (Number) viewDistanceObject ).intValue() : -1;
+ if ( viewDistance <= 0 )
+ {
+ viewDistance = Bukkit.getViewDistance();
+ }
+
+ viewDistance = Math.max( Math.min( viewDistance, 32 ), 3 );
+ log( "View Distance: " + viewDistance );
+ }
+
+ public int simulationDistance;
+ private void simulationDistance()
+ {
+ Object simulationDistanceObject = get( "simulation-distance", "default" );
+ simulationDistance = ( simulationDistanceObject ) instanceof Number ? ( (Number) simulationDistanceObject ).intValue() : -1;
+ if ( simulationDistance <= 0 )
+ {
+ simulationDistance = Bukkit.getSimulationDistance();
+ }
+
+ log( "Simulation Distance: " + simulationDistance );
+ }
}
--
2.47.0