mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2025-01-26 09:41:20 +01:00
Limit hologram view range with small view distance setting
This commit is contained in:
parent
39f3f49504
commit
d76739d332
@ -9,6 +9,7 @@ import me.filoghost.fcommons.logging.Log;
|
||||
import me.filoghost.holographicdisplays.core.tracking.LineTrackerManager;
|
||||
import me.filoghost.holographicdisplays.core.listener.LineClickListener;
|
||||
import me.filoghost.holographicdisplays.core.placeholder.tracking.ActivePlaceholderTracker;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -73,8 +74,11 @@ public class TickingTask implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
// Holograms need to disappear before chunks (code taken from Bukkit)
|
||||
int maxViewRange = (Bukkit.getViewDistance() - 1) * 16;
|
||||
|
||||
try {
|
||||
lineTrackerManager.update(onlinePlayers, movedPlayers);
|
||||
lineTrackerManager.update(onlinePlayers, movedPlayers, maxViewRange);
|
||||
} catch (Throwable t) {
|
||||
// Catch all types of Throwable because we're using NMS code
|
||||
if (tickClock.getCurrentTick() - lastErrorLogTick >= 20) {
|
||||
|
@ -43,8 +43,8 @@ public class ItemLineTracker extends ClickableLineTracker<Viewer> {
|
||||
|
||||
@MustBeInvokedByOverriders
|
||||
@Override
|
||||
protected void update(List<CachedPlayer> onlinePlayers, List<CachedPlayer> movedPlayers) {
|
||||
super.update(onlinePlayers, movedPlayers);
|
||||
protected void update(List<CachedPlayer> onlinePlayers, List<CachedPlayer> movedPlayers, int maxViewRange) {
|
||||
super.update(onlinePlayers, movedPlayers, maxViewRange);
|
||||
|
||||
if (spawnItemEntity && hasViewers() && line.hasPickupCallback()) {
|
||||
for (Viewer viewer : getViewers()) {
|
||||
|
@ -54,7 +54,7 @@ public abstract class LineTracker<T extends Viewer> {
|
||||
}
|
||||
|
||||
@MustBeInvokedByOverriders
|
||||
protected void update(List<CachedPlayer> onlinePlayers, List<CachedPlayer> movedPlayers) {
|
||||
protected void update(List<CachedPlayer> onlinePlayers, List<CachedPlayer> movedPlayers, int maxViewRange) {
|
||||
boolean sendChangesPackets = false;
|
||||
|
||||
// First, detect the changes if the flag is on and set it off
|
||||
@ -77,7 +77,7 @@ public abstract class LineTracker<T extends Viewer> {
|
||||
}
|
||||
|
||||
// Finally, add/remove viewers sending them the full spawn/destroy packets
|
||||
modifyViewersAndSendPackets(onlinePlayers, movedPlayers);
|
||||
modifyViewersAndSendPackets(onlinePlayers, movedPlayers, maxViewRange);
|
||||
|
||||
if (sendChangesPackets) {
|
||||
clearDetectedChanges();
|
||||
@ -86,7 +86,7 @@ public abstract class LineTracker<T extends Viewer> {
|
||||
|
||||
protected abstract boolean updatePlaceholders();
|
||||
|
||||
private void modifyViewersAndSendPackets(List<CachedPlayer> onlinePlayers, List<CachedPlayer> movedPlayers) {
|
||||
private void modifyViewersAndSendPackets(List<CachedPlayer> onlinePlayers, List<CachedPlayer> movedPlayers, int maxViewRange) {
|
||||
if (!getLine().isInLoadedChunk()) {
|
||||
resetViewersAndSendDestroyPackets();
|
||||
return;
|
||||
@ -120,7 +120,7 @@ public abstract class LineTracker<T extends Viewer> {
|
||||
for (int i = 0; i < size; i++) {
|
||||
CachedPlayer player = playersToCheck.get(i);
|
||||
Player bukkitPlayer = player.getBukkitPlayer();
|
||||
if (shouldTrackPlayer(player)) {
|
||||
if (shouldTrackPlayer(player, maxViewRange)) {
|
||||
if (!viewers.containsKey(bukkitPlayer)) {
|
||||
T viewer = createViewer(player);
|
||||
viewers.put(bukkitPlayer, viewer);
|
||||
@ -148,17 +148,22 @@ public abstract class LineTracker<T extends Viewer> {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldTrackPlayer(CachedPlayer player) {
|
||||
private boolean shouldTrackPlayer(CachedPlayer player, int maxViewRange) {
|
||||
Location playerLocation = player.getLocation();
|
||||
if (playerLocation.getWorld() != getLine().getWorldIfLoaded()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
double viewRange = getViewRange();
|
||||
if (viewRange > maxViewRange) {
|
||||
viewRange = maxViewRange;
|
||||
}
|
||||
|
||||
double diffX = Math.abs(playerLocation.getX() - positionCoordinates.getX());
|
||||
double diffZ = Math.abs(playerLocation.getZ() - positionCoordinates.getZ());
|
||||
|
||||
return diffX <= getViewRange()
|
||||
&& diffZ <= getViewRange()
|
||||
return diffX <= viewRange
|
||||
&& diffZ <= viewRange
|
||||
&& getLine().isVisibleTo(player.getBukkitPlayer());
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ public class LineTrackerManager {
|
||||
return tracker;
|
||||
}
|
||||
|
||||
public void update(List<CachedPlayer> onlinePlayers, List<CachedPlayer> movedPlayers) {
|
||||
public void update(List<CachedPlayer> onlinePlayers, List<CachedPlayer> movedPlayers, int maxViewRange) {
|
||||
Iterator<LineTracker<?>> iterator = lineTrackers.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
LineTracker<?> lineTracker = iterator.next();
|
||||
@ -59,7 +59,7 @@ public class LineTrackerManager {
|
||||
continue;
|
||||
}
|
||||
|
||||
lineTracker.update(onlinePlayers, movedPlayers);
|
||||
lineTracker.update(onlinePlayers, movedPlayers, maxViewRange);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user