Compare commits

...
3 Commits
Author SHA1 Message Date
Cubicake 3fe9434856 Merge remote-tracking branch 'origin/main' 2025-01-23 22:09:53 +10:30
Cubicake 43dc579078 Added more config options: MoreChecks and OccludePlayers 2025-01-23 22:09:23 +10:30
Cubicake 4d290c2803 Create LICENSE 2025-01-19 18:40:00 +10:30
7 changed files with 91 additions and 13 deletions

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 Cubicake
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+1 -1
View File
@@ -3,7 +3,7 @@ plugins {
}
group = 'games.cubi'
version = '1.0-SNAPSHOT'
version = '1.1.0'
repositories {
mavenCentral()
@@ -31,7 +31,7 @@ public class Raycast {
} else {
// A solid block was hit
callback.onResult(false);
plugin.getLogger().info("Raycast hit a solid block: " + result.getHitBlock().getType() + " at " + result.getHitBlock().getLocation());
//plugin.getLogger().info("Raycast hit a solid block: " + result.getHitBlock().getType() + " at " + result.getHitBlock().getLocation());
}
}
@@ -4,8 +4,11 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.BoundingBox;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@@ -15,6 +18,8 @@ public final class RaycastedEntityOcclusion extends JavaPlugin {
public int alwaysShowRadius;
public int raycastRadius;
public int searchRadius;
public boolean moreChecks;
public boolean occludePlayers;
public int tickCounter = 0;
public RaycastedEntityOcclusion plugin = this;
@@ -51,10 +56,21 @@ public final class RaycastedEntityOcclusion extends JavaPlugin {
// Plugin shutdown logic
}
@EventHandler
public void entityTargetLivingEntityEvent(EntityTargetLivingEntityEvent event) {
if (event.getTarget() instanceof Player) {
Player player = (Player) event.getTarget();
addEntityToShow(player, event.getEntity());
}
}
private void checkEntityVisibility(Player player) {
List<Entity> nearbyEntities = player.getNearbyEntities(searchRadius, searchRadius, searchRadius);
for (Entity entity : nearbyEntities) {
if (entity instanceof Player && !occludePlayers) {
continue;
}
double distance = player.getLocation().distance(entity.getLocation());
if (distance <= alwaysShowRadius) {
// Always show entities within this radius
@@ -67,19 +83,51 @@ public final class RaycastedEntityOcclusion extends JavaPlugin {
continue;
}
if (!player.canSee(entity) || tickCounter % 10 == 0) {
// Perform raycast to check visibility
Location entityLocation = entity.getLocation().add(0, entity.getHeight() / 2, 0);
Raycast.asyncRaycast(player.getEyeLocation(), entityLocation, plugin, canSeePlayer -> {
if (canSeePlayer) {
addEntityToShow(player, entity);
} else {
addEntityToHide(player, entity);
}
});
//check whether to run intensive or light checks
Double height = entity.getHeight();
if (moreChecks) {
Double width = entity.getWidth();
Location checkOne = entity.getLocation().add(0, height - 0.01, 0);
Location checkTwo = entity.getLocation().add(0, 0.01, 0);
Location checkThree = entity.getLocation().add(width / 2, height / 2, 0);
Location checkFour = entity.getLocation().add(-width / 2, height / 2, 0);
Raycast.asyncRaycast(player.getEyeLocation(), checkOne, plugin, canSeePlayer -> {
if (canSeePlayer) {
addEntityToShow(player, entity);
} else {
Raycast.asyncRaycast(player.getEyeLocation(), checkTwo, plugin, canSeePlayer2 -> {
if (canSeePlayer2) addEntityToShow(player, entity);
else {
Raycast.asyncRaycast(player.getEyeLocation(), checkThree, plugin, canSeePlayer3 -> {
if (canSeePlayer3) addEntityToShow(player, entity);
else {
Raycast.asyncRaycast(player.getEyeLocation(), checkFour, plugin, canSeePlayer4 -> {
if (canSeePlayer4) addEntityToShow(player, entity);
else addEntityToHide(player, entity);
});
}
});
}
});
}
});
} else {
Location entityLocation = entity.getLocation().add(0, height / 2, 0);
Raycast.asyncRaycast(player.getEyeLocation(), entityLocation, plugin, canSeePlayer -> {
if (canSeePlayer) {
addEntityToShow(player, entity);
} else {
addEntityToHide(player, entity);
}
});
}
}
}
}
private void addEntityToShow(Player player, Entity entity) {
entitiesToShow.computeIfAbsent(player, k -> ConcurrentHashMap.newKeySet()).add(entity);
entitiesToHide.computeIfAbsent(player, k -> ConcurrentHashMap.newKeySet()).remove(entity);
@@ -90,6 +138,10 @@ public final class RaycastedEntityOcclusion extends JavaPlugin {
entitiesToShow.computeIfAbsent(player, k -> ConcurrentHashMap.newKeySet()).remove(entity);
}
private boolean entityPendingVisible(Player player, Entity entity) {
return entitiesToShow.get(player) != null && entitiesToShow.get(player).contains(entity);
}
private void applyVisibilityChanges() {
for (Map.Entry<Player, Set<Entity>> entry : entitiesToShow.entrySet()) {
Player player = entry.getKey();
@@ -111,6 +163,9 @@ public final class RaycastedEntityOcclusion extends JavaPlugin {
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);
getLogger().info("AlwaysShowRadius: " + alwaysShowRadius);
getLogger().info("RaycastRadius: " + raycastRadius);
+3 -1
View File
@@ -1,3 +1,5 @@
AlwaysShowRadius: 4
RaycastRadius: 64
SearchRadius: 72
SearchRadius: 72
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
+1 -1
View File
@@ -1,5 +1,5 @@
name: RaycastedEntityOcclusion
version: '1.0-SNAPSHOT'
version: ${version}
main: games.cubi.raycastedEntityOcclusion.RaycastedEntityOcclusion
api-version: '1.21'
prefix: EntityOcclusion