Skip to content

Commit

Permalink
feat: add onlyCheckCenter option to ray cast check (#372)
Browse files Browse the repository at this point in the history
* feat: Ray cast check only check block center option

* Delete misc.xml

* Update OrebfuscatorProximityConfig.java

* Update ProximityConfig.java

* Update OrebfuscatorProximityConfig.java

* Update ProximityConfig.java
  • Loading branch information
LoliColleen committed May 23, 2024
1 parent 6030993 commit 5e82c2d
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public interface ProximityConfig extends WorldConfig {

Matrix4f frustumCullingProjectionMatrix();

boolean useRayCastCheck();
boolean rayCastCheckEnabled();

boolean rayCastCheckOnlyCheckCenter();

Iterable<Map.Entry<BlockProperties, Integer>> hiddenBlocks();
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public boolean usesFrustumCulling() {

public boolean usesRayCastCheck() {
for (ProximityConfig config : this.proximityConfigs) {
if (config.useRayCastCheck()) {
if (config.rayCastCheckEnabled()) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public class OrebfuscatorProximityConfig extends AbstractWorldConfig implements
private float frustumCullingMinDistanceSquared = 9;
private Matrix4f frustumCullingProjectionMatrix;

private boolean useRayCastCheck = false;
private boolean rayCastCheckEnabled = false;
private boolean rayCastCheckOnlyCheckCenter = false;
private int defaultBlockFlags = (ProximityHeightCondition.MATCH_ALL | BlockFlags.FLAG_USE_BLOCK_BELOW);

private boolean usesBlockSpecificConfigs = false;
Expand Down Expand Up @@ -66,8 +67,10 @@ public class OrebfuscatorProximityConfig extends AbstractWorldConfig implements
this.frustumCullingProjectionMatrix = new Matrix4f() // create projection matrix with aspect 16:9
.perspective(frustumCullingFov, 16f / 9f, 0.01f, 2 * distance);

this.useRayCastCheck = section.getBoolean("useRayCastCheck",
section.getBoolean("useFastGazeCheck", false));
this.rayCastCheckEnabled = section.getBoolean("rayCastCheck.enabled",
section.getBoolean("useRayCastCheck",
section.getBoolean("useFastGazeCheck", false)));
this.rayCastCheckOnlyCheckCenter = section.getBoolean("rayCastCheck.onlyCheckCenter", false);

this.defaultBlockFlags = ProximityHeightCondition.create(minY, maxY);
if (section.getBoolean("useBlockBelow", true)) {
Expand All @@ -92,7 +95,8 @@ protected void serialize(ConfigurationSection section) {
section.set("frustumCulling.minDistance", frustumCullingMinDistance);
section.set("frustumCulling.fov", frustumCullingFov);

section.set("useRayCastCheck", this.useRayCastCheck);
section.set("rayCastCheck.enabled", this.rayCastCheckEnabled);
section.set("rayCastCheck.onlyCheckCenter", this.rayCastCheckOnlyCheckCenter);
section.set("useBlockBelow", BlockFlags.isUseBlockBelowBitSet(this.defaultBlockFlags));

this.serializeHiddenBlocks(section, "hiddenBlocks");
Expand Down Expand Up @@ -199,8 +203,13 @@ public Matrix4f frustumCullingProjectionMatrix() {
}

@Override
public boolean useRayCastCheck() {
return this.useRayCastCheck;
public boolean rayCastCheckEnabled() {
return this.rayCastCheckEnabled;
}

@Override
public boolean rayCastCheckOnlyCheckCenter() {
return this.rayCastCheckOnlyCheckCenter;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void process(Player player) {
}

// frustum culling and ray casting both need rotation changes
boolean needsRotation = proximityConfig.frustumCullingEnabled() || proximityConfig.useRayCastCheck();
boolean needsRotation = proximityConfig.frustumCullingEnabled() || proximityConfig.rayCastCheckEnabled();

// check if player changed location since last time
OrebfuscatorPlayer orebfuscatorPlayer = this.playerMap.get(player);
Expand Down Expand Up @@ -132,7 +132,7 @@ private void process(Player player) {
}

// do ray cast check
if (proximityConfig.useRayCastCheck() && !FastGazeUtil.doFastCheck(blockPos, eyeLocation, world)) {
if (proximityConfig.rayCastCheckEnabled() && !FastGazeUtil.doFastCheck(blockPos, eyeLocation, world, proximityConfig.rayCastCheckOnlyCheckCenter())) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,40 @@ public class FastGazeUtil {
* Basic idea here is to take some rays from the considered block to the
* player's eyes, and decide if any of those rays can reach the eyes unimpeded.
*
* @param block the starting block
* @param eyes the destination eyes
* @param player the player world we are testing for
* @param pos the starting block position
* @param eyes the destination eyes
* @param player the player world we are testing for
* @param onlyCheckCenter only check block center if true
* @return true if unimpeded path, false otherwise
*/
public static boolean doFastCheck(BlockPos pos, Location eyes, World player) {
public static boolean doFastCheck(BlockPos pos, Location eyes, World player, boolean onlyCheckCenter) {
double ex = eyes.getX();
double ey = eyes.getY();
double ez = eyes.getZ();
double x = pos.x;
double y = pos.y;
double z = pos.z;
return // midfaces
FastGazeUtil.fastAABBRayCheck(x, y, z, x, y + 0.5, z + 0.5, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x + 0.5, y, z + 0.5, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x + 0.5, y + 0.5, z, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x + 0.5, y + 1.0, z + 0.5, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x + 0.5, y + 0.5, z + 1.0, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x + 1.0, y + 0.5, z + 0.5, ex, ey, ez, player) ||
// corners
FastGazeUtil.fastAABBRayCheck(x, y, z, x, y, z, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x + 1, y, z, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x, y + 1, z, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x + 1, y + 1, z, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x, y, z + 1, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x + 1, y, z + 1, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x, y + 1, z + 1, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x + 1, y + 1, z + 1, ex, ey, ez, player);
if (onlyCheckCenter) {
return // center
FastGazeUtil.fastAABBRayCheck(x, y, z, x + 0.5, y + 0.5, z + 0.5, ex, ey, ez, player);
} else {
return // midfaces
FastGazeUtil.fastAABBRayCheck(x, y, z, x, y + 0.5, z + 0.5, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x + 0.5, y, z + 0.5, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x + 0.5, y + 0.5, z, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x + 0.5, y + 1.0, z + 0.5, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x + 0.5, y + 0.5, z + 1.0, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x + 1.0, y + 0.5, z + 0.5, ex, ey, ez, player) ||
// corners
FastGazeUtil.fastAABBRayCheck(x, y, z, x, y, z, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x + 1, y, z, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x, y + 1, z, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x + 1, y + 1, z, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x, y, z + 1, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x + 1, y, z + 1, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x, y + 1, z + 1, ex, ey, ez, player)
|| FastGazeUtil.fastAABBRayCheck(x, y, z, x + 1, y + 1, z + 1, ex, ey, ez, player);
}
}

public static boolean fastAABBRayCheck(double bx, double by, double bz, double x, double y, double z, double ex,
Expand Down
12 changes: 9 additions & 3 deletions orebfuscator-plugin/src/main/resources/config/config-1.10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:mossy_cobblestone: {}
Expand Down Expand Up @@ -169,7 +171,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:chest: {}
Expand Down Expand Up @@ -199,7 +203,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:chest: {}
Expand Down
12 changes: 9 additions & 3 deletions orebfuscator-plugin/src/main/resources/config/config-1.11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:mossy_cobblestone: {}
Expand Down Expand Up @@ -233,7 +235,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:chest: {}
Expand Down Expand Up @@ -279,7 +283,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:chest: {}
Expand Down
12 changes: 9 additions & 3 deletions orebfuscator-plugin/src/main/resources/config/config-1.12.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:mossy_cobblestone: {}
Expand Down Expand Up @@ -233,7 +235,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:chest: {}
Expand Down Expand Up @@ -279,7 +283,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:chest: {}
Expand Down
10 changes: 7 additions & 3 deletions orebfuscator-plugin/src/main/resources/config/config-1.13.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
useBlockBelow: true
hiddenBlocks:
minecraft:mossy_cobblestone: {}
Expand Down Expand Up @@ -237,7 +238,8 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
useBlockBelow: true
hiddenBlocks:
minecraft:chest: {}
Expand Down Expand Up @@ -284,7 +286,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:chest: {}
Expand Down
12 changes: 9 additions & 3 deletions orebfuscator-plugin/src/main/resources/config/config-1.14.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:mossy_cobblestone: {}
Expand Down Expand Up @@ -247,7 +249,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:chest: {}
Expand Down Expand Up @@ -304,7 +308,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:chest: {}
Expand Down
12 changes: 9 additions & 3 deletions orebfuscator-plugin/src/main/resources/config/config-1.15.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:mossy_cobblestone: {}
Expand Down Expand Up @@ -249,7 +251,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:chest: {}
Expand Down Expand Up @@ -308,7 +312,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:chest: {}
Expand Down
12 changes: 9 additions & 3 deletions orebfuscator-plugin/src/main/resources/config/config-1.16.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:mossy_cobblestone: {}
Expand Down Expand Up @@ -256,7 +258,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:chest: {}
Expand Down Expand Up @@ -318,7 +322,9 @@ proximity:
enabled: true
minDistance: 3
fov: 80
useRayCastCheck: false
rayCastCheck:
enabled: false
onlyCheckCenter: false
useBlockBelow: true
hiddenBlocks:
minecraft:chest: {}
Expand Down
Loading

0 comments on commit 5e82c2d

Please sign in to comment.