Compare commits

..
4 Commits
Author SHA1 Message Date
Cubicake d8d81c4662 Coded 2025-02-12 21:36:04 +10:30
Cubicake b338dc2175 Update README.md 2025-02-05 20:45:10 +10:30
Cubicake 3ab250e4ef Update README.md 2025-02-05 20:41:43 +10:30
Cubicake 231d2bc7d1 Update README.md 2025-02-05 20:40:05 +10:30
7 changed files with 98 additions and 25 deletions

No files matched your search

+24 -11
View File
@@ -1,4 +1,8 @@
This is a simple server-side plugin for PaperMC (May also work with Spigot, this is untested) that hides entities from players if they do not have line-of-sight. All raycasts are run async to reduce performance impact.
Latest version: v1.2.2
The latest version can currently only be found on Modrinth https://modrinth.com/plugin/raycasted-entity-occlusion/
This is a simple server-side plugin for PaperMC (May also work with Spigot, this is untested) that hides/culls entities from players if they do not have line-of-sight. All raycasts are run async to reduce performance impact.
Use cases:
- To prevent mob nametags from being visible through walls
@@ -9,18 +13,27 @@ Use cases:
- Reduce client lag
- In servers with large megabases full of item frames, armour stands and other entities, RaycastedEntityOcclusion will prevent these entities from lagging the client unless they are within line-of-sight
Config info:
Default Config:
The config has three settings:
AlwaysShowRadius: 4
RaycastRadius: 64
SearchRadius: 72
- AlwaysShowRadius: 8
- RaycastRadius: 48
- SearchRadius: 52
- MoreChecks: false
- OccludePlayers: false
- RecheckInterval: 20
Entities inside the AlwaysShowRadius are always shown, even if occluded. This is to prevent nasty surprises when turning a corner quickly.
The SearchRadius is a misnomer, it's actually a cubic bounding box around the player within which entities will be checked. If an entity is within the SearchRadius but not the RaycastRadius, it will be automatically hidden.
The RaycastRadius is the radius where entities will be checked. If an entity is currently hidden it will run a raycast every tick. This is to quickly detect when the entity becomes visible. If the entity is currently visible, it will only ruun the raycast every 10 ticks to reduce performance impact.
The SearchRadius is a cubic bounding box around the player within which entities will be checked. If an entity is within the SearchRadius but not the RaycastRadius, it will be automatically hidden.
The RaycastRadius is the radius where entities will be checked. If an entity is currently hidden it will run a raycast every tick. This is to quickly detect when the entity becomes visible. If the entity is currently visible, it will only run the raycast every {RecheckInterval} ticks to reduce performance impact.
MoreChecks toggles between two raycasting modes. By default (MoreChecks = false) the plugin runs one raycast from the center of each mob to the player. This means that if the center of the mob is hidden but some parts should be visible, the player won't be able to see the mob at all. Enabling MoreChecks runs a raycast from the top, bottom, left and right of the entity to the player.
OccludePlayers toggles whether players will be checked. Enabling this prevents ESP mods from revealing players.
Known issues:
- Players are also occluded. This itself is not an issue, however hiding players also removes them from the tab list and command autocomplete.
- Due to the nature of the plugin, there will be a short delay once an entity should be visible before it appears, causing it to appear like it "popped" into view
- Due to the nature of the plugin, there will be a short delay once an entity should be visible before it appears, causing it to appear like it "popped" into view. This issue is partially resolved by turning MoreChecks on
- If OccludePlayers is set to true any occluded players will be removed from tablist
- When updating the plugin to a version with more config versions, no checks are performed to detect this and add the new configs to config.yml. This means that the config file will be missing several options. (This is an issue when updating to v1.1.0 or v1.2.0). To fix, just copy the new config options from the Default Config section above.
+1 -1
View File
@@ -3,7 +3,7 @@ plugins {
}
group = 'games.cubi'
version = '1.2.0'
version = '1.3.0-dev'
repositories {
mavenCentral()
@@ -54,6 +54,15 @@ public class CheckEntityVisibility {
}.runTaskTimer(plugin, 0L, 1L);
}
public void updateConfigValues() {
this.alwaysShowRadius = plugin.alwaysShowRadius;
this.raycastRadius = plugin.raycastRadius;
this.searchRadius = plugin.searchRadius;
this.moreChecks = plugin.moreChecks;
this.occludePlayers = plugin.occludePlayers;
this.recheckInterval = plugin.recheckInterval;
}
public void runVisibilityCheck(Player player) {
World world = player.getWorld();
List<Entity> nearbyEntities = player.getNearbyEntities(searchRadius, searchRadius, searchRadius);
@@ -76,7 +85,10 @@ public class CheckEntityVisibility {
addEntityToHide(player, entity);
continue;
}
if (!player.canSee(entity) || plugin.tickCounter % recheckInterval == 0) {
Boolean canSee = player.canSee(entity);
int check = tickCounter % recheckInterval;
//plugin.getLogger().info("check: " + check + " cansee " + canSee);
if (!canSee || check == 0) {
//check whether to run intensive or light checks
Double height = entity.getHeight();
if (moreChecks) {
@@ -137,13 +149,19 @@ public class CheckEntityVisibility {
for (Map.Entry<Player, Set<Entity>> entry : entitiesToShow.entrySet()) {
Player player = entry.getKey();
for (Entity entity : entry.getValue()) {
player.showEntity(plugin, entity);
if (entity instanceof Player p) {
player.showPlayer(plugin, p);
}
else player.showEntity(plugin, entity);
}
}
for (Map.Entry<Player, Set<Entity>> entry : entitiesToHide.entrySet()) {
Player player = entry.getKey();
for (Entity entity : entry.getValue()) {
player.hideEntity(plugin, entity);
if (entity instanceof Player p) {
player.hidePlayer(plugin, p);
}
else player.hideEntity(plugin, entity);
}
}
}
@@ -14,8 +14,19 @@ public class CommandHandler implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length != 0 && args[0].equalsIgnoreCase("reload")) {
plugin.loadConfig();
plugin.getCheckEntityVisibility().updateConfigValues();
sender.sendMessage("RaycastedEntityOcclusion config reloaded.");
return true;
}
sender.sendMessage("RaycastedEntityOcclusion v" + plugin.getDescription().getVersion());
return false;
sender.sendMessage("AlwaysShowRadius: " + plugin.alwaysShowRadius);
sender.sendMessage("RaycastRadius: " + plugin.raycastRadius);
sender.sendMessage("SearchRadius: " + plugin.searchRadius);
sender.sendMessage("MoreChecks: " + plugin.moreChecks);
sender.sendMessage("OccludePlayers: " + plugin.occludePlayers);
sender.sendMessage("RecheckInterval: " + plugin.recheckInterval);
return true;
}
}
@@ -44,4 +44,29 @@ public class Raycast {
private static boolean isOccluding(Material material) {
return material.isOccluding();
}
public static boolean syncRaycast(Location start, Location end, RaycastedEntityOcclusion plugin) {
Vector direction = end.toVector().subtract(start.toVector()).normalize();
double distance = start.distance(end);
// Perform the ray trace
RayTraceResult result = start.getWorld().rayTraceBlocks(start, direction, distance,
FluidCollisionMode.NEVER, // Ignore fluids
true, // Pass through transparent blocks
// Check if the block is occluding
(block) -> isOccluding(block.getType())
);
// Check if the ray hit a solid block or reached the player
if (result == null || result.getHitBlock() == null) {
// No solid block was hit, so the ray reached the player
return true;
} else {
// A solid block was hit
return false;
//plugin.getLogger().info("Raycast hit a solid block: " + result.getHitBlock().getType() + " at " + result.getHitBlock().getLocation());
}
}
}
@@ -1,5 +1,6 @@
package games.cubi.raycastedEntityOcclusion;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
public final class RaycastedEntityOcclusion extends JavaPlugin {
@@ -32,15 +33,17 @@ public final class RaycastedEntityOcclusion extends JavaPlugin {
}
private void loadConfig() {
public void loadConfig() {
saveDefaultConfig();
reloadConfig();
FileConfiguration config = getConfig();
alwaysShowRadius = getConfig().getInt("AlwaysShowRadius", 4);
raycastRadius = getConfig().getInt("RaycastRadius", 64);
searchRadius = getConfig().getInt("SearchRadius", 72);
moreChecks = getConfig().getBoolean("MoreChecks", false);
occludePlayers = getConfig().getBoolean("OccludePlayers", false);
recheckInterval = getConfig().getInt("RecheckInterval", 10);
alwaysShowRadius = config.getInt("AlwaysShowRadius", 4);
raycastRadius = config.getInt("RaycastRadius", 64);
searchRadius = config.getInt("SearchRadius", 72);
moreChecks = config.getBoolean("MoreChecks", false);
occludePlayers = config.getBoolean("OccludePlayers", false);
recheckInterval = config.getInt("RecheckInterval", 10);
getLogger().info("AlwaysShowRadius: " + alwaysShowRadius);
@@ -50,4 +53,7 @@ public final class RaycastedEntityOcclusion extends JavaPlugin {
getLogger().info("OccludePlayers: " + occludePlayers);
getLogger().info("RecheckInterval: " + recheckInterval);
}
public CheckEntityVisibility getCheckEntityVisibility() {
return checkEntityVisibility;
}
}
+1 -1
View File
@@ -2,5 +2,5 @@ AlwaysShowRadius: 8
RaycastRadius: 48
SearchRadius: 52
MoreChecks: false #This will enable more raycasts per mob, increasing performance hit but showing partially visible mobs
OccludePlayers: false #This will disable occlusion checks for players. Setting this to true is the interim fix for players being removed from tab list
OccludePlayers: false #Enabling this will make the plugin cull hidden players alongside entities
RecheckInterval: 20 #Time in ticks between rechecking visible mobs