mirror of
https://github.com/Cubicake/RaycastedAntiESP.git
synced 2026-11-26 01:49:42 -05:00
Compare commits
121
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9951b5d7a1 | ||
|
|
e99c3b9de2 | ||
|
|
0500f4bd5f | ||
|
|
9a841308ff | ||
|
|
c4bf1cbf0b | ||
|
|
db22c675db | ||
|
|
5a42fd74ad | ||
|
|
85b788742c | ||
|
|
20f660b8a3 | ||
|
|
4d17483a5a | ||
|
|
274b081c78 | ||
|
|
45e14637e0 | ||
|
|
b007735636 | ||
|
|
bb7275a618 | ||
|
|
853fa1531a | ||
|
|
396382bcc2 | ||
|
|
aae6bdb53c | ||
|
|
2f8f698069 | ||
|
|
fc3badb90a | ||
|
|
7aab3b60e8 | ||
|
|
2ab157bd4a | ||
|
|
3227c63e2e | ||
|
|
1dc77b3e6f | ||
|
|
cb044f789d | ||
|
|
c110aab634 | ||
|
|
5d407afbdf | ||
|
|
a8f12c9a24 | ||
|
|
0e4c251c6c | ||
|
|
e2b598a361 | ||
|
|
8c140cf8b6 | ||
|
|
4fe9ab02ef | ||
|
|
a21102d04f | ||
|
|
22488e9e71 | ||
|
|
bc40438cb3 | ||
|
|
3f633710e7 | ||
|
|
8de5d53198 | ||
|
|
53650f9b63 | ||
|
|
ba812bce3a | ||
|
|
42932abaa5 | ||
|
|
290749dde8 | ||
|
|
e19808fb4b | ||
|
|
691d429652 | ||
|
|
1575091d12 | ||
|
|
4919383c73 | ||
|
|
5293db6c86 | ||
|
|
c5f17a7b12 | ||
|
|
ddafbd0c25 | ||
|
|
8d9a354154 | ||
|
|
64bfcccde5 | ||
|
|
e91dc4647d | ||
|
|
96601efed5 | ||
|
|
c63a194ea9 | ||
|
|
71cde26cb9 | ||
|
|
33ab1cd234 | ||
|
|
e1c96d87ff | ||
|
|
3d8686e1ae | ||
|
|
971a648ad8 | ||
|
|
b0f05eaf4f | ||
|
|
bc9fcd6d7a | ||
|
|
a631c57465 | ||
|
|
9f9fb7f021 | ||
|
|
903e7c84bc | ||
|
|
ae75c37d90 | ||
|
|
17f5040c49 | ||
|
|
c04cf7558e | ||
|
|
11358badac | ||
|
|
008e62eee2 | ||
|
|
409261000e | ||
|
|
4854b1f88b | ||
|
|
e384ea0775 | ||
|
|
61df3f4f2d | ||
|
|
9f3eec6f09 | ||
|
|
4361276070 | ||
|
|
5d852cd6d3 | ||
|
|
2b2c7b9108 | ||
|
|
93949b7906 | ||
|
|
cee4d4b6f9 | ||
|
|
9fed35527d | ||
|
|
d101ba9b99 | ||
|
|
4527a9dd02 | ||
|
|
8aefd39d65 | ||
|
|
ccbed56a99 | ||
|
|
5e4692c753 | ||
|
|
5d05ac00b7 | ||
|
|
7d611ffdcb | ||
|
|
f3ff087874 | ||
|
|
a11711e06f | ||
|
|
30286928b2 | ||
|
|
5fdf26f624 | ||
|
|
f72da61436 | ||
|
|
980cc33e7b | ||
|
|
d873c7b1ff | ||
|
|
f67b0b2ae7 | ||
|
|
c047ed08e1 | ||
|
|
e886efa823 | ||
|
|
740974f17c | ||
|
|
f38bda6993 | ||
|
|
61e7cac35f | ||
|
|
8f61e203f8 | ||
|
|
751398eaaa | ||
|
|
736ccab3e0 | ||
|
|
32a8d92df4 | ||
|
|
af0d887e14 | ||
|
|
f32c8ec9fa | ||
|
|
858c4d4340 | ||
|
|
274d437525 | ||
|
|
c610bc42a6 | ||
|
|
ae8905ed46 | ||
|
|
dcaed38f4d | ||
|
|
512a4db255 | ||
|
|
4fd8954fea | ||
|
|
1b5db5edca | ||
|
|
a08a477176 | ||
|
|
f4f3ca4d63 | ||
|
|
ab537e777b | ||
|
|
02938e3b57 | ||
|
|
e4b488eb69 | ||
|
|
e55b685ce2 | ||
|
|
6fd6d9bc04 | ||
|
|
d1244be5d1 | ||
|
|
dd9db4211d |
No files matched your search
@@ -3,6 +3,7 @@
|
||||
|
||||
README.md
|
||||
*.md
|
||||
*.toml
|
||||
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
## Contributions
|
||||
Contributions via pull requests are welcome. Please join our [discord](https://discord.cubi.games) or make an `issue` to discuss any contributions beforehand to make sure they will not conflict with or hinder existing plans.
|
||||
|
||||
A good place to start with contributions is to look for `issue`s flagged with the label `help wanted`.
|
||||
A good place to start with contributions is to look for `issue`s flagged with the label `Outside Help Welcome`. These have been deemed as uninvasive changes, typically not requiring a complete understanding of the project. You are welcome to send a PR resolving these issues without first discussing changes with a maintainer.
|
||||
|
||||
You must hold the rights to any code you contribute, and must agree to licence it under the same licence as the rest of the project in perpetuity, explicitly including any and all changes to the project's licence by project maintainers in the future. The project's licence can always be found at [LICENSE](LICENSE).
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
RaycastedAntiESP is a packet-based plugin for Paper, Folia, and its forks that hides entities (including players) and tile entities (blocks such as chests, banners, signs, etc) from players if they would not be visible to a legitimate player.
|
||||
This limits the usefulness of unfair advantages such as cheat clients, freecam, xray, or pie-ray.
|
||||
RaycastedAntiESP is a packet-based plugin for Paper, Folia, and its forks that hides entities (including players) and tile entities (blocks such as chests, banners, signs, etc) from players if they would not be visible to a legitimate player. It is **unbypassable** by design, as packets sent by the server are blocked from reaching the client unless the block/entity has been confirmed to be visible.
|
||||
This limits the usefulness of unfair advantages such as cheat clients, freecam, and x-ray, and completely blocks pie-ray.
|
||||
|
||||
### Supported Versions
|
||||
While the current "stable" plugin version is v1.6.5, it is strongly recommended that you use the [alpha-channel builds](https://modrinth.com/plugin/raycasted-anti-esp/versions?c=alpha) instead. Since v1.6.5, RaycastedAntiESP has been:
|
||||
@@ -11,19 +11,27 @@ The supported minecraft versions are 1.21.4+. Only Paper and derivative software
|
||||
## Use cases:
|
||||
|
||||
- Prevent cheating (anti-esp hacks)
|
||||
- Block usage of pie-ray to locate underground bases
|
||||
- Prevent mods such as mini-maps or cheat clients from displaying the locations of hidden entities
|
||||
- This is the plugin's primary purpose.
|
||||
- Block usage of pie-ray to locate underground bases or farms.
|
||||
- Prevent mods such as mini-maps or cheat clients from displaying the locations of hidden entities.
|
||||
- Increase client-side performance for low-end devices
|
||||
- Massive megabases containing hundreds of armour stands, item frames, banners etc can cause performance issues on low-end devices unable to process so many entities. Raycasted AntiESP will cull those entities for the client, reducing the number of entities to process.
|
||||
- Reduce network load by limiting packets
|
||||
- With `keep-client-entity-when-hidden` set to true, running RaycastedAntiESP will significantly reduce the number of entity packets sent to the client.
|
||||
- While entity packets are only a small portion of network bandwidth, this will still have a measurable impact and may be useful on extremely bandwidth-limited servers.
|
||||
- Unless you are extremely limited by bandwidth, this will probably be unnoticeable.
|
||||
- Hide nametags behind walls
|
||||
- Yes, this plugin is a bit overkill for doing that, yes you can do it anyways.
|
||||
- Yes, this plugin is overkill for doing that, yes you can do it anyways.
|
||||
|
||||
## Configuration
|
||||
RaycastedAntiESP has many configuration options. A full list with explanations can be found at https://raycastedantiesp.cubi.games/config/.
|
||||
|
||||
## Dependencies:
|
||||
- Packetevents
|
||||
- Required for all features, as packets are intercepted and rewritten to make sure that clients never learn about anything they should not be able to see.
|
||||
|
||||
## Known issues:
|
||||
- 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.
|
||||
- There will be a short delay once an entity should be visible before it appears, causing it to appear like it "popped" into view. Various config options exist to partially address this issue, though all such options necessarily weaken the plugin's ability to block cheaters.
|
||||
|
||||
## Versioning:
|
||||
Note that the following versioning information only applies to v2 and beyond, and alpha versions of v2 start with a major version number of 0 rather than 2.
|
||||
|
||||
@@ -38,7 +38,7 @@ dependencies {
|
||||
testImplementation("it.unimi.dsi:fastutil:8.5.18")
|
||||
}
|
||||
|
||||
val coreVersion = "0.6.0-SNAPSHOT"
|
||||
val coreVersion = "0.7.1-SNAPSHOT"
|
||||
|
||||
val isRelease = gradle.startParameter.taskNames.any {
|
||||
it.contains("buildRelease")
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core;
|
||||
|
||||
import games.cubi.logs.PlatformLogger;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core;
|
||||
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
/**
|
||||
* Implementations should increment (starting from 0) once a tick, and should call AsyncEngine's tick method each time the tick increments.
|
||||
*/
|
||||
public interface Ticker extends IntSupplier {
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.blocks.BlockChunkDataBuilder;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
public final class ChunkData {
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.chunks.ChunkData.LOCAL_MASK;
|
||||
|
||||
public interface ChunkOcclusionView {
|
||||
/**
|
||||
* The parameters here are local coordinates within the chunk section, so they must be in the range [0, 15].
|
||||
@@ -9,4 +19,12 @@ public interface ChunkOcclusionView {
|
||||
* @return true if the block at the given local coordinates is occluding, false otherwise.
|
||||
*/
|
||||
boolean isOccludingLocal(@Range(from = 0, to = 15) int x, @Range(from = 0, to = 15) int y, @Range(from = 0, to = 15) int z);
|
||||
|
||||
default boolean isOccludingGlobal(int x, int y, int z) {
|
||||
return isOccludingLocal(x & LOCAL_MASK, y & LOCAL_MASK, z & LOCAL_MASK);
|
||||
}
|
||||
|
||||
default boolean isSolid() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
import org.jetbrains.annotations.Range;
|
||||
@@ -45,5 +53,10 @@ public sealed interface OccludingChunkData extends ChunkOcclusionView permits Oc
|
||||
public OccludingChunkData setOccluding(int x, int y, int z, boolean occluding) {
|
||||
return filled().setOccluding(x, y, z, occluding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.ChunkSectionConfig;
|
||||
@@ -19,7 +27,7 @@ public record ChecksConfig(PlayerConfig playerConfig, EntityConfig entityConfig,
|
||||
);
|
||||
}
|
||||
|
||||
public boolean hasRestartOnlyChanges(ChecksConfig startup) {
|
||||
public boolean hasEnabledStatusChanges(ChecksConfig startup) {
|
||||
return playerConfig.enabled() != startup.playerConfig.enabled()
|
||||
|| entityConfig.enabled() != startup.entityConfig.enabled()
|
||||
|| chunkSectionConfig.enabled() != startup.chunkSectionConfig.enabled();
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
public interface Config {
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
public class ConfigLoadException extends RuntimeException {
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
import games.cubi.raycastedantiesp.core.config.engine.EngineConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.ChunkSectionConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.EntityConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.PlayerConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.SoundEffectsConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.TileEntityConfig;
|
||||
import games.cubi.raycastedantiesp.core.utils.VarHandler;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
@@ -168,11 +178,23 @@ public class ConfigManager {
|
||||
return activeConfig().checksConfig().tileEntityConfig();
|
||||
}
|
||||
|
||||
public SoundEffectsConfig getSoundEffectsConfig() {
|
||||
return activeConfig().checksConfig().soundEffectsConfig();
|
||||
}
|
||||
|
||||
public ChunkSectionConfig getChunkSectionConfig() {
|
||||
return activeConfig().checksConfig().chunkSectionConfig();
|
||||
}
|
||||
|
||||
public DebugConfig getDebugConfig() {
|
||||
RootConfig current = activeConfig();
|
||||
return current == null ? null : current.debugConfig();
|
||||
}
|
||||
|
||||
public UpdateConfig getUpdateConfig() {
|
||||
return activeConfig().updateConfig();
|
||||
}
|
||||
|
||||
public EngineConfig getEngineConfig() {
|
||||
return activeConfig().engineConfig();
|
||||
}
|
||||
@@ -209,6 +231,7 @@ public class ConfigManager {
|
||||
EngineConfig engineConfig = EngineConfig.load(loaded);
|
||||
BlockProcessorConfig blockProcessorConfig = BlockProcessorConfig.load(loaded);
|
||||
DebugConfig debugConfig = DebugConfig.load(loaded);
|
||||
UpdateConfig updateConfig = UpdateConfig.load(loaded);
|
||||
Map<Class<? extends Config>, Config> extensionConfigs = new LinkedHashMap<>();
|
||||
for (ConfigExtension<? extends Config> extension : extensions) {
|
||||
extensionConfigs.put(extension.type(), extension.load(loaded, blockProcessorConfig));
|
||||
@@ -218,7 +241,7 @@ public class ConfigManager {
|
||||
throw new ConfigLoadException("checks.chunk-section.enabled must be false when block-processor.track-all-blocks is false");
|
||||
}
|
||||
|
||||
return new RootConfig(version, checksConfig, engineConfig, blockProcessorConfig, debugConfig, Map.copyOf(extensionConfigs));
|
||||
return new RootConfig(version, checksConfig, engineConfig, blockProcessorConfig, debugConfig, updateConfig, Map.copyOf(extensionConfigs));
|
||||
}
|
||||
|
||||
private void validateReload(RootConfig next) {
|
||||
@@ -226,13 +249,16 @@ public class ConfigManager {
|
||||
return;
|
||||
}
|
||||
if (next.engineConfig().mode() != startupConfig.engineConfig().mode()) {
|
||||
throw new RestartRequiredException("engine.mode cannot be changed without a restart");
|
||||
throw new RestartRequiredException("engine.mode cannot be changed without a restart.");
|
||||
}
|
||||
if (!next.blockProcessorConfig().equals(startupConfig.blockProcessorConfig())) {
|
||||
throw new RestartRequiredException("block-processor cannot be changed without a restart");
|
||||
throw new RestartRequiredException("block-processor cannot be changed without a restart.");
|
||||
}
|
||||
if (next.checksConfig().hasRestartOnlyChanges(startupConfig.checksConfig())) {
|
||||
throw new RestartRequiredException("checks cannot be enabled or disabled without a restart");
|
||||
if (!next.checksConfig().entityConfig().excludedTypes().equals(startupConfig.checksConfig().entityConfig().excludedTypes())) {
|
||||
throw new RestartRequiredException("excluded entity types cannot be changed without a restart.");
|
||||
}
|
||||
if (next.checksConfig().hasEnabledStatusChanges(startupConfig.checksConfig())) {
|
||||
throw new RestartRequiredException("player and entity checks cannot be enabled or disabled without a restart.");
|
||||
}
|
||||
for (ConfigExtension<? extends Config> extension : extensions) {
|
||||
validateExtensionReload(extension, next);
|
||||
@@ -280,11 +306,28 @@ public class ConfigManager {
|
||||
Files.createFile(configPath);
|
||||
}
|
||||
}
|
||||
prependConfigDocumentationHeaderIfMissing();
|
||||
} catch (IOException e) {
|
||||
throw new ConfigLoadException("Failed to create config.yml", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void prependConfigDocumentationHeaderIfMissing() {
|
||||
try {
|
||||
String content = Files.readString(configPath);
|
||||
|
||||
if (content.startsWith("#")) {
|
||||
Logger.debug("Config starts with comment");
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.debug("no starting comment");
|
||||
Files.writeString(configPath, "# An explanation of this configuration file and what all the options do can be found at https://raycastedantiesp.cubi.games/config/" + System.lineSeparator() + content);
|
||||
} catch (Exception e) {
|
||||
Logger.warning(e,3, ConfigManager.class);
|
||||
}
|
||||
}
|
||||
|
||||
private ConfigurationNode loadConfigNode() {
|
||||
try {
|
||||
return loader.load();
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.engine.EngineConfig;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public record RootConfig(String configVersion, ChecksConfig checksConfig, EngineConfig engineConfig, BlockProcessorConfig blockProcessorConfig, DebugConfig debugConfig, Map<Class<? extends Config>, Config> extensionConfigs) implements Config {
|
||||
public record RootConfig(String configVersion, ChecksConfig checksConfig, EngineConfig engineConfig, BlockProcessorConfig blockProcessorConfig, DebugConfig debugConfig, UpdateConfig updateConfig, Map<Class<? extends Config>, Config> extensionConfigs) implements Config {
|
||||
public <T extends Config> T extensionConfig(Class<T> type) {
|
||||
Config config = extensionConfigs.get(type);
|
||||
return type.cast(config);
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public record UpdateConfig(boolean checkRelease, boolean checkBeta, boolean checkAlpha, boolean notifyInGame) implements Config {
|
||||
|
||||
public static UpdateConfig load(ConfigurationNode root) {
|
||||
ConfigurationNode node = ConfigReader.node(root, "updates");
|
||||
return new UpdateConfig(
|
||||
ConfigReader.bool(ConfigReader.node(node, "check-release"), "updates.check-release"),
|
||||
ConfigReader.bool(ConfigReader.node(node, "check-beta"), "updates.check-beta"),
|
||||
ConfigReader.bool(ConfigReader.node(node, "check-alpha"), "updates.check-alpha"),
|
||||
ConfigReader.bool(ConfigReader.node(node, "notify-in-game"), "updates.notify-in-game")
|
||||
);
|
||||
}
|
||||
|
||||
public boolean anyChannelEnabled() {
|
||||
return checkRelease || checkBeta || checkAlpha;
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.engine;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.Config;
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigLoadException;
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigReader;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public record AsyncEngineConfig(int asyncProcessingThreads) implements Config {
|
||||
public static AsyncEngineConfig load(ConfigurationNode node) {
|
||||
int threads = ConfigReader.integer(ConfigReader.node(node, "processing-threads"), "engine.async.processing-threads");
|
||||
if (threads < 1) {
|
||||
throw new ConfigLoadException("engine.async.processing-threads must be at least 1");
|
||||
}
|
||||
return new AsyncEngineConfig(threads);
|
||||
}
|
||||
}
|
||||
+10
-2
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.engine;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.Config;
|
||||
@@ -5,7 +13,7 @@ import games.cubi.raycastedantiesp.core.config.ConfigLoadException;
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigReader;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public record EngineConfig(EngineMode mode, SimpleEngineConfig simpleConfig) implements Config {
|
||||
public record EngineConfig(EngineMode mode, AsyncEngineConfig asyncConfig) implements Config {
|
||||
public static EngineConfig load(ConfigurationNode root) {
|
||||
ConfigurationNode node = ConfigReader.node(root, "engine");
|
||||
String modeName = ConfigReader.string(ConfigReader.node(node, "mode"), "engine.mode");
|
||||
@@ -13,7 +21,7 @@ public record EngineConfig(EngineMode mode, SimpleEngineConfig simpleConfig) imp
|
||||
if (mode == null) {
|
||||
throw new ConfigLoadException("engine.mode has unsupported value '" + modeName + "'");
|
||||
}
|
||||
return new EngineConfig(mode, SimpleEngineConfig.load(ConfigReader.node(node, "simple")));
|
||||
return new EngineConfig(mode, AsyncEngineConfig.load(ConfigReader.node(node, "async")));
|
||||
}
|
||||
|
||||
public EngineMode getMode() {
|
||||
|
||||
@@ -1,16 +1,32 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.engine;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigEnum;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum EngineMode implements ConfigEnum {
|
||||
SIMPLE("simple"),
|
||||
ASYNC("async", "simple"),
|
||||
NETTY("netty");
|
||||
|
||||
private final String configName;
|
||||
private final @Nullable String aliasName;
|
||||
|
||||
EngineMode(String configName) {
|
||||
this.configName = configName;
|
||||
aliasName = null;
|
||||
}
|
||||
|
||||
EngineMode(String configName, @NotNull String aliasName) {
|
||||
this.configName = configName;
|
||||
this.aliasName = aliasName;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -19,7 +35,7 @@ public enum EngineMode implements ConfigEnum {
|
||||
|
||||
public static @Nullable EngineMode fromString(String name) {
|
||||
for (EngineMode mode : values()) {
|
||||
if (mode.configName.equalsIgnoreCase(name)) {
|
||||
if (mode.configName.equalsIgnoreCase(name) || name.equalsIgnoreCase(mode.aliasName)) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
@@ -28,6 +44,6 @@ public enum EngineMode implements ConfigEnum {
|
||||
|
||||
@Override
|
||||
public String[] getValues() {
|
||||
return new String[] {"simple", "netty"};
|
||||
return new String[] {NETTY.configName, ASYNC.configName};
|
||||
}
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
package games.cubi.raycastedantiesp.core.config.engine;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.Config;
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigLoadException;
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigReader;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public record SimpleEngineConfig(int asyncProcessingThreads) implements Config {
|
||||
public static SimpleEngineConfig load(ConfigurationNode node) {
|
||||
int threads = ConfigReader.integer(ConfigReader.node(node, "async-processing-threads"), "engine.simple.async-processing-threads");
|
||||
if (threads < 1) {
|
||||
throw new ConfigLoadException("engine.simple.async-processing-threads must be at least 1");
|
||||
}
|
||||
return new SimpleEngineConfig(threads);
|
||||
}
|
||||
}
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.Config;
|
||||
|
||||
+23
-2
@@ -1,15 +1,36 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigReader;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class EntityConfig extends RaycastConfig {
|
||||
private EntityConfig(RaycastConfig config) {
|
||||
private final Set<String> excludedTypes;
|
||||
|
||||
private EntityConfig(RaycastConfig config, List<String> excludedTypes) {
|
||||
super(config.enabled(), config.hideSoundsWhenHidden(), config.getMaxOccludingCount(), config.getAlwaysShowRadius(),
|
||||
config.getRaycastRadius(), config.hideOnSpawnDistance(), config.getVisibleRecheckIntervalTicks(),
|
||||
config.keepClientEntityWhenHidden());
|
||||
this.excludedTypes = Set.copyOf(excludedTypes);
|
||||
}
|
||||
|
||||
public static EntityConfig load(ConfigurationNode node, String path) {
|
||||
return new EntityConfig(RaycastConfig.load(node, path, true, true));
|
||||
RaycastConfig config = RaycastConfig.load(node, path, true, true);
|
||||
List<String> excludedTypes = ConfigReader.stringList(ConfigReader.node(node, "excluded-types"), path + ".excluded-types");
|
||||
return new EntityConfig(config, excludedTypes);
|
||||
}
|
||||
|
||||
public Set<String> excludedTypes() {
|
||||
return excludedTypes;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSets;
|
||||
|
||||
/**
|
||||
* Immutable entity-type exclusion policy resolved during plugin startup.
|
||||
*/
|
||||
public final class EntityTypeExclusions {
|
||||
public static volatile IntSet volatileExclusionSet = null;
|
||||
|
||||
// Is this sort of an insane approach? Yes. But it works.
|
||||
static class FakeLazyConstant {
|
||||
private static final IntSet finalEntityTypeExclusions = init();
|
||||
|
||||
private static IntSet init() {
|
||||
IntSet set = volatileExclusionSet;
|
||||
if (set == null) {
|
||||
Logger.error(new RuntimeException("Exclusion set was not initialised before being read"), 4, EntityTypeExclusions.class);
|
||||
return IntSets.emptySet();
|
||||
}
|
||||
return set;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean excludes(int entityType) {
|
||||
return FakeLazyConstant.finalEntityTypeExclusions.contains(entityType);
|
||||
}
|
||||
|
||||
public static int size() {
|
||||
return FakeLazyConstant.finalEntityTypeExclusions.size();
|
||||
}
|
||||
}
|
||||
+21
-2
@@ -1,15 +1,34 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigReader;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public class PlayerConfig extends RaycastConfig {
|
||||
private PlayerConfig(RaycastConfig config) {
|
||||
private final boolean onlyCheckSneaking;
|
||||
|
||||
private PlayerConfig(RaycastConfig config, boolean onlyCheckSneaking) {
|
||||
super(config.enabled(), config.hideSoundsWhenHidden(), config.getMaxOccludingCount(), config.getAlwaysShowRadius(),
|
||||
config.getRaycastRadius(), config.hideOnSpawnDistance(), config.getVisibleRecheckIntervalTicks(),
|
||||
config.keepClientEntityWhenHidden());
|
||||
this.onlyCheckSneaking = onlyCheckSneaking;
|
||||
}
|
||||
|
||||
public static PlayerConfig load(ConfigurationNode node, String path) {
|
||||
return new PlayerConfig(RaycastConfig.load(node, path, true, true));
|
||||
return new PlayerConfig(
|
||||
RaycastConfig.load(node, path, true, true),
|
||||
ConfigReader.bool(ConfigReader.node(node, "only-check-sneaking"), path + ".only-check-sneaking")
|
||||
);
|
||||
}
|
||||
|
||||
public boolean onlyCheckSneaking() {
|
||||
return onlyCheckSneaking;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.Config;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
+55
-50
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
import games.cubi.locatables.api.ImmutableSpatial;
|
||||
@@ -8,6 +16,7 @@ import games.cubi.raycastedantiesp.core.config.DebugConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.EntityConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.PlayerConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.TileEntityConfig;
|
||||
import games.cubi.raycastedantiesp.core.entity.EntityBypassRegistry;
|
||||
import games.cubi.raycastedantiesp.core.tracked.NettyEntity;
|
||||
import games.cubi.raycastedantiesp.core.players.PlayerData;
|
||||
import games.cubi.raycastedantiesp.core.players.PlayerRegistry;
|
||||
@@ -24,7 +33,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
public abstract class SimpleEngine implements Engine {
|
||||
public abstract class AsyncEngine implements Engine {
|
||||
private static final long SLOW_TICK_NANOS = 40 * 1_000_000L;
|
||||
//Literally just magic numbers I made by keyboard mashing
|
||||
private static final int TICK_IDLE = 1872;
|
||||
@@ -41,7 +50,7 @@ public abstract class SimpleEngine implements Engine {
|
||||
private final AsyncRunner asyncRunner;
|
||||
private final TimingStatsSelector timingStatsSelector = new TimingStatsSelector();
|
||||
|
||||
public SimpleEngine(ConfigManager config, ParticleSpawner particleSpawner, IntSupplier currentTickSupplier, AsyncRunner asyncRunner) {
|
||||
public AsyncEngine(ConfigManager config, ParticleSpawner particleSpawner, IntSupplier currentTickSupplier, AsyncRunner asyncRunner) {
|
||||
this.config = config;
|
||||
this.particleSpawner = particleSpawner;
|
||||
this.currentTickSupplier = currentTickSupplier;
|
||||
@@ -68,7 +77,7 @@ public abstract class SimpleEngine implements Engine {
|
||||
*/
|
||||
public void cancelPendingTickReservation() {
|
||||
if (!tickState.compareAndSet(TICK_PENDING, TICK_IDLE)) {
|
||||
Logger.warning("Attempted to cancel a pending tick reservation, but the tick was no longer pending.", 5, SimpleEngine.class);
|
||||
Logger.warning("Attempted to cancel a pending tick reservation, but the tick was no longer pending.", 5, AsyncEngine.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +111,7 @@ public abstract class SimpleEngine implements Engine {
|
||||
|
||||
if (tickState.get() == TICK_RUNNING) {
|
||||
// This means that there is already a tick running, so we should exit
|
||||
Logger.info("Tick finished behind but another thread had already begun ticking the next tick.", 5, SimpleEngine.class);
|
||||
Logger.info("Tick finished behind but another thread had already begun ticking the next tick.", 5, AsyncEngine.class);
|
||||
return;
|
||||
}
|
||||
expectPending = false; //Next call to startTickState should not expect to see status set to pending
|
||||
@@ -118,7 +127,7 @@ public abstract class SimpleEngine implements Engine {
|
||||
* lifecycle; false if this attempt was skipped or cleaned up during setup.
|
||||
*/
|
||||
private boolean dispatchTick(int scheduledTick, int startTick, long scheduledNanos) {
|
||||
int threads = config.getEngineConfig().simpleConfig().asyncProcessingThreads();
|
||||
int threads = config.getEngineConfig().asyncConfig().asyncProcessingThreads();
|
||||
if (threads < 1) threads = 1;
|
||||
|
||||
DebugConfig debugConfig = config.getDebugConfig();
|
||||
@@ -134,7 +143,7 @@ public abstract class SimpleEngine implements Engine {
|
||||
Logger.info("RaycastedAntiESP is already processing this tick; skipping duplicate same-tick attempt."
|
||||
+ " scheduledTick=" + scheduledTick
|
||||
+ " currentServerTick=" + startTick
|
||||
+ " currentRunningTick=" + tickAlreadyRunning, 6, SimpleEngine.class);
|
||||
+ " currentRunningTick=" + tickAlreadyRunning, 6, AsyncEngine.class);
|
||||
finishTickState();
|
||||
return false;
|
||||
}
|
||||
@@ -148,7 +157,7 @@ public abstract class SimpleEngine implements Engine {
|
||||
+ " currentServerTick=" + currentTickSupplier.getAsInt()
|
||||
+ " currentRunningTick=" + tickAlreadyRunning
|
||||
+ " runningThreads=" + runningThreads
|
||||
+ " timeSpentInQueue=" + TickTimingFormatter.formatMillis(queueNanos) + "ms", 5, SimpleEngine.class);
|
||||
+ " timeSpentInQueue=" + TickTimingFormatter.formatMillis(queueNanos) + "ms", 5, AsyncEngine.class);
|
||||
logAggregateReport(tickTimingStats.recordSkipped(threads, startNanos));
|
||||
finishTickState();
|
||||
return false;
|
||||
@@ -224,7 +233,7 @@ public abstract class SimpleEngine implements Engine {
|
||||
} else {
|
||||
finishTickState();
|
||||
}
|
||||
Logger.error("An error occurred during tick scheduling before handing off to sub-tick processing. Resetting tickThreadsRunning to 0 to avoid deadlock. Current tick: " + currentTickSupplier.getAsInt(), 2, SimpleEngine.class);
|
||||
Logger.error("An error occurred during tick scheduling before handing off to sub-tick processing. Resetting tickThreadsRunning to 0 to avoid deadlock. Current tick: " + currentTickSupplier.getAsInt(), 2, AsyncEngine.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,7 +256,7 @@ public abstract class SimpleEngine implements Engine {
|
||||
}
|
||||
int threadsRemaining = tickThreadsRunning.decrementAndGet();
|
||||
if (threadsRemaining < 0) {
|
||||
Logger.error("tickThreadsRunning went below 0! This should never happen. Resetting to 0 to avoid further issues.", 2, SimpleEngine.class);
|
||||
Logger.error("tickThreadsRunning went below 0! This should never happen. Resetting to 0 to avoid further issues.", 2, AsyncEngine.class);
|
||||
tickThreadsRunning.set(0);
|
||||
finaliseTick(currentTick);
|
||||
}
|
||||
@@ -258,13 +267,13 @@ public abstract class SimpleEngine implements Engine {
|
||||
TickTimingSnapshot snapshot = timings.snapshot(currentTickSupplier.getAsInt(), completionNanos);
|
||||
String aggregateReport = timingStats.recordCompleted(snapshot, completionNanos);
|
||||
if (snapshot.wallNanos() > SLOW_TICK_NANOS) {
|
||||
Logger.warning(snapshot.toSlowTickMessage(), 5, SimpleEngine.class);
|
||||
Logger.warning(snapshot.toSlowTickMessage(), 5, AsyncEngine.class);
|
||||
}
|
||||
logAggregateReport(aggregateReport);
|
||||
} else {
|
||||
long elapsedNanos = completionNanos - tickNanos.get();
|
||||
if (elapsedNanos > SLOW_TICK_NANOS) {
|
||||
Logger.warning("Tick completed in " + (elapsedNanos / 1_000_000.0) + " ms. If you see this warning frequently, consider reducing the raycasting load by adjusting the configuration.", 5, SimpleEngine.class);
|
||||
Logger.warning("Tick completed in " + (elapsedNanos / 1_000_000.0) + " ms. If you see this warning frequently, consider reducing the raycasting load by adjusting the configuration.", 5, AsyncEngine.class);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
@@ -288,7 +297,7 @@ public abstract class SimpleEngine implements Engine {
|
||||
}
|
||||
if (tickState.compareAndSet(TICK_IDLE, TICK_RUNNING)) {
|
||||
// This means that this tick was dispatched but not marked as such, or was unmarked at some point.
|
||||
Logger.warning("Tick " + scheduledTick + " was dispatched but not marked as pending. This suggests a race condition. Please report this on our GitHub or Discord.", 5, SimpleEngine.class);
|
||||
Logger.warning("Tick " + scheduledTick + " was dispatched but not marked as pending. This suggests a race condition. Please report this on our GitHub or Discord.", 5, AsyncEngine.class);
|
||||
return true;
|
||||
}
|
||||
} else if (tickState.compareAndSet(TICK_IDLE, TICK_RUNNING)) {
|
||||
@@ -297,7 +306,7 @@ public abstract class SimpleEngine implements Engine {
|
||||
|
||||
// This means there is already a tick pending or running, so we should exit.
|
||||
recordSkippedTick(-1, System.nanoTime());
|
||||
Logger.info("Tick " + scheduledTick + " is pending but another tick is already pending or running. Exiting now.", 6, SimpleEngine.class);
|
||||
Logger.info("Tick " + scheduledTick + " is pending but another tick is already pending or running. Exiting now.", 6, AsyncEngine.class);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -316,7 +325,7 @@ public abstract class SimpleEngine implements Engine {
|
||||
private void finishTickState() {
|
||||
if (!tickState.compareAndSet(TICK_RUNNING, TICK_IDLE)) {
|
||||
// This should never happen as it means the tick was marked as completed before processing was completed
|
||||
Logger.warning("tickState was not running when completing tick! This should never happen. Please report this on our GitHub or Discord.", 5, SimpleEngine.class);
|
||||
Logger.warning("tickState was not running when completing tick! This should never happen. Please report this on our GitHub or Discord.", 5, AsyncEngine.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,20 +356,26 @@ public abstract class SimpleEngine implements Engine {
|
||||
}
|
||||
timings.incrementProcessedPlayers();
|
||||
|
||||
if (entityConfig.enabled()) {
|
||||
long sectionStartNanos = timings.startEntitySection();
|
||||
checkEntities(playerData, playerLocation, entityConfig, debugParticles, blockView, currentTick, worldEpoch, timings);
|
||||
timings.finishEntitySection(sectionStartNanos);
|
||||
}
|
||||
if (playerConfig.enabled()) {
|
||||
long sectionStartNanos = timings.startPlayerSection();
|
||||
checkPlayers(playerData, playerLocation, playerConfig, debugParticles, blockView, currentTick, worldEpoch, timings);
|
||||
timings.finishPlayerSection(sectionStartNanos);
|
||||
}
|
||||
if (tileEntityConfig.enabled()) {
|
||||
long sectionStartNanos = timings.startTileSection();
|
||||
checkTileEntities(playerData, playerLocation, tileEntityConfig, debugParticles, blockView, currentTick, worldEpoch, timings);
|
||||
timings.finishTileSection(sectionStartNanos);
|
||||
try {
|
||||
if (entityConfig.enabled()) {
|
||||
long sectionStartNanos = timings.startEntitySection();
|
||||
checkEntities(playerData, playerLocation, entityConfig, debugParticles, blockView, currentTick, worldEpoch, timings);
|
||||
timings.finishEntitySection(sectionStartNanos);
|
||||
}
|
||||
if (playerConfig.enabled()) {
|
||||
long sectionStartNanos = timings.startPlayerSection();
|
||||
checkPlayers(playerData, playerLocation, playerConfig, debugParticles, blockView, currentTick, worldEpoch, timings);
|
||||
timings.finishPlayerSection(sectionStartNanos);
|
||||
}
|
||||
if (tileEntityConfig.enabled()) {
|
||||
long sectionStartNanos = timings.startTileSection();
|
||||
checkTileEntities(playerData, playerLocation, tileEntityConfig, debugParticles, blockView, currentTick, worldEpoch, timings);
|
||||
timings.finishTileSection(sectionStartNanos);
|
||||
}
|
||||
} finally {
|
||||
playerData.entityView().flushPendingTransitions();
|
||||
playerData.playerView().flushPendingTransitions();
|
||||
blockView.flushPendingTransitions();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -369,21 +384,16 @@ public abstract class SimpleEngine implements Engine {
|
||||
EntityView<?> entityView = player.entityView();
|
||||
|
||||
int checked = entityView.forEachNeedingRecheckEntity(entityConfig.getVisibleRecheckIntervalTicks(), currentTick, !(timings instanceof TickTimingBatchNoOp), worldEpoch, entity -> {
|
||||
boolean wasVisible = entity.visible();
|
||||
if (attachedToSelf(player, entityView, entity, currentTick, worldEpoch)) {
|
||||
if (entity.glowing()) {
|
||||
entityView.setVisibility(entity, true, currentTick, worldEpoch);
|
||||
return;
|
||||
}
|
||||
ImmutableSpatial entityLocation = entity.getOffsetPosition();
|
||||
if (entityLocation == null) {
|
||||
timings.incrementEntityNullTargets();
|
||||
Logger.debug("SimpleEngine.checkEntities skipped-null-location viewer=" + player.getPlayerUUID()
|
||||
+ " target=" + entity.entityUUID()
|
||||
+ " wasVisible=" + wasVisible
|
||||
+ " tick=" + currentTick);
|
||||
if (attachedToAlwaysVisibleEntityOrSelf(player, entityView, entity, currentTick, worldEpoch)) {
|
||||
return;
|
||||
}
|
||||
|
||||
timings.incrementEntityRaycasts();
|
||||
boolean canSee = RaycastUtil.raycast(playerLocation, entityLocation, entityConfig.getMaxOccludingCount(), entityConfig.getAlwaysShowRadius(), entityConfig.getRaycastRadius(), debugParticles, blockView, 1, particleSpawner);
|
||||
boolean canSee = RaycastUtil.raycast(playerLocation, entity, entityConfig.getMaxOccludingCount(), entityConfig.getAlwaysShowRadius(), entityConfig.getRaycastRadius(), debugParticles, blockView, entity.getYOffset(), 1, particleSpawner);
|
||||
entityView.setVisibility(entity, canSee, currentTick, worldEpoch);
|
||||
});
|
||||
timings.addEntityChecked(checked);
|
||||
@@ -393,30 +403,25 @@ public abstract class SimpleEngine implements Engine {
|
||||
EntityView<?> playerView = player.playerView();
|
||||
|
||||
int checked = playerView.forEachNeedingRecheckEntity(playerConfig.getVisibleRecheckIntervalTicks(), currentTick, !(timings instanceof TickTimingBatchNoOp), worldEpoch, otherPlayer -> {
|
||||
boolean wasVisible = otherPlayer.visible();
|
||||
if (attachedToSelf(player, playerView, otherPlayer, currentTick, worldEpoch)) {
|
||||
if (otherPlayer.glowing() || (playerConfig.onlyCheckSneaking() && !otherPlayer.sneaking())) {
|
||||
playerView.setVisibility(otherPlayer, true, currentTick, worldEpoch);
|
||||
return;
|
||||
}
|
||||
ImmutableSpatial otherPlayerLocation = otherPlayer.getOffsetPosition();
|
||||
if (otherPlayerLocation == null) {
|
||||
timings.incrementPlayerNullTargets();
|
||||
Logger.debug("SimpleEngine.checkPlayers skipped-null-location viewer=" + player.getPlayerUUID()
|
||||
+ " target=" + otherPlayer.entityUUID()
|
||||
+ " wasVisible=" + wasVisible
|
||||
+ " tick=" + currentTick);
|
||||
if (attachedToAlwaysVisibleEntityOrSelf(player, playerView, otherPlayer, currentTick, worldEpoch)) {
|
||||
return;
|
||||
}
|
||||
timings.incrementPlayerRaycasts();
|
||||
boolean canSee = RaycastUtil.raycast(playerLocation, otherPlayerLocation, playerConfig.getMaxOccludingCount(), playerConfig.getAlwaysShowRadius(), playerConfig.getRaycastRadius(), debugParticles, blockView, 1, particleSpawner);
|
||||
boolean canSee = RaycastUtil.raycast(playerLocation, otherPlayer, playerConfig.getMaxOccludingCount(), playerConfig.getAlwaysShowRadius(), playerConfig.getRaycastRadius(), debugParticles, blockView, 1.5f, 1, particleSpawner);
|
||||
playerView.setVisibility(otherPlayer, canSee, currentTick, worldEpoch);
|
||||
});
|
||||
timings.addPlayerChecked(checked);
|
||||
}
|
||||
|
||||
private boolean attachedToSelf(PlayerData player, EntityView<?> view, NettyEntity<?,?> entity, int currentTick, int worldEpoch) {
|
||||
private boolean attachedToAlwaysVisibleEntityOrSelf(PlayerData player, EntityView<?> view, NettyEntity<?> entity, int currentTick, int worldEpoch) {
|
||||
int selfEntityID = player.nettyData().getSelfEntityID();
|
||||
if (!player.nettyData().isSelfEntityID(entity.leashingEntity())
|
||||
&& !player.nettyData().isSelfEntityID(entity.vehicleID())
|
||||
&& !EntityBypassRegistry.isBypassed(entity.vehicleID())
|
||||
&& !PrimitiveIntArrayList.contains(entity.passengerIDs(), selfEntityID)) {
|
||||
return false;
|
||||
}
|
||||
@@ -441,7 +446,7 @@ public abstract class SimpleEngine implements Engine {
|
||||
|
||||
private static void logAggregateReport(String aggregateReport) {
|
||||
if (aggregateReport != null) {
|
||||
Logger.info(aggregateReport, 4, SimpleEngine.class);
|
||||
Logger.info(aggregateReport, 4, AsyncEngine.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
public interface AsyncRunner {
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
public interface Engine {
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
public class TickTimingBatch {
|
||||
@@ -72,10 +80,6 @@ public class TickTimingBatch {
|
||||
entityChecked += count;
|
||||
}
|
||||
|
||||
public void incrementEntityNullTargets() {
|
||||
entityNullTargets++;
|
||||
}
|
||||
|
||||
public void incrementEntityRaycasts() {
|
||||
entityRaycasts++;
|
||||
}
|
||||
@@ -84,10 +88,6 @@ public class TickTimingBatch {
|
||||
playerChecked += count;
|
||||
}
|
||||
|
||||
public void incrementPlayerNullTargets() {
|
||||
playerNullTargets++;
|
||||
}
|
||||
|
||||
public void incrementPlayerRaycasts() {
|
||||
playerRaycasts++;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
public class TickTimingBatchNoOp extends TickTimingBatch {
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
record TickTimingSnapshot(
|
||||
@@ -17,10 +25,8 @@ record TickTimingSnapshot(
|
||||
int nullLocationSkippedPlayers,
|
||||
int entityChecked,
|
||||
int entityRaycasts,
|
||||
int entityNullTargets,
|
||||
int playerChecked,
|
||||
int playerRaycasts,
|
||||
int playerNullTargets,
|
||||
int tileChecked,
|
||||
int tileRaycasts,
|
||||
int tileWorldSkipped,
|
||||
@@ -44,10 +50,8 @@ record TickTimingSnapshot(
|
||||
+ " nullLocationSkippedPlayers=" + nullLocationSkippedPlayers
|
||||
+ " entityRecheckCandidates=" + entityChecked
|
||||
+ " entityRaycasts=" + entityRaycasts
|
||||
+ " entityNullTargets=" + entityNullTargets
|
||||
+ " playerRecheckCandidates=" + playerChecked
|
||||
+ " playerRaycasts=" + playerRaycasts
|
||||
+ " playerNullTargets=" + playerNullTargets
|
||||
+ " tileRecheckCandidates=" + tileChecked
|
||||
+ " tileRaycasts=" + tileRaycasts
|
||||
+ " tileWorldSkipped=" + tileWorldSkipped
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
final class TickTimings {
|
||||
@@ -19,11 +27,9 @@ final class TickTimings {
|
||||
|
||||
private int entityChecked;
|
||||
private int entityRaycasts;
|
||||
private int entityNullTargets;
|
||||
|
||||
private int playerChecked;
|
||||
private int playerRaycasts;
|
||||
private int playerNullTargets;
|
||||
|
||||
private int tileChecked;
|
||||
private int tileRaycasts;
|
||||
@@ -52,11 +58,9 @@ final class TickTimings {
|
||||
|
||||
entityChecked += batch.entityChecked;
|
||||
entityRaycasts += batch.entityRaycasts;
|
||||
entityNullTargets += batch.entityNullTargets;
|
||||
|
||||
playerChecked += batch.playerChecked;
|
||||
playerRaycasts += batch.playerRaycasts;
|
||||
playerNullTargets += batch.playerNullTargets;
|
||||
|
||||
tileChecked += batch.tileChecked;
|
||||
tileRaycasts += batch.tileRaycasts;
|
||||
@@ -82,10 +86,8 @@ final class TickTimings {
|
||||
nullLocationSkippedPlayers,
|
||||
entityChecked,
|
||||
entityRaycasts,
|
||||
entityNullTargets,
|
||||
playerChecked,
|
||||
playerRaycasts,
|
||||
playerNullTargets,
|
||||
tileChecked,
|
||||
tileRaycasts,
|
||||
tileWorldSkipped,
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
public class TimingStatsNoOp extends TimingStats {
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.entity;
|
||||
|
||||
import games.cubi.utils.sets.CopyOnWriteMTIntSet;
|
||||
|
||||
/**
|
||||
* Global registry of entity IDs which RaycastedAntiESP must ignore.
|
||||
*/
|
||||
public final class EntityBypassRegistry {
|
||||
private static final CopyOnWriteMTIntSet BYPASSED_ENTITY_IDS = CopyOnWriteMTIntSet.get();
|
||||
// Technically, (26.2+) Minecraft only guarantees that an entity ID corresponds to one-and-only-one entity within a single world, and entities in different worlds can have the same ID.
|
||||
// (26.1.2-) Minecraft does not guarantee that an entity ID is unique.
|
||||
// However, this requires the int id counter to overflow from Integer.MAX_VALUE all the way back to 0. This is unlikely to occur, and even if it does occur, it is unlikely that the original entities are still alive.
|
||||
private EntityBypassRegistry() {
|
||||
}
|
||||
|
||||
public static void addEntity(int entityID) {
|
||||
BYPASSED_ENTITY_IDS.add(entityID);
|
||||
}
|
||||
|
||||
/**
|
||||
* For use when an entity is despawned/killed, or in other words completely gone from the server.
|
||||
*/
|
||||
public static boolean markEntityDespawned(int entityID) {
|
||||
return BYPASSED_ENTITY_IDS.remove(entityID);
|
||||
}
|
||||
|
||||
public static boolean isBypassed(int entityID) {
|
||||
return BYPASSED_ENTITY_IDS.contains(entityID);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import games.cubi.logs.Logger;
|
||||
import games.cubi.raycastedantiesp.core.tracked.NettyEntity;
|
||||
import games.cubi.raycastedantiesp.core.utils.*;
|
||||
import games.cubi.raycastedantiesp.core.utils.Packet.Packets;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntArrayMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
@@ -20,6 +21,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.invoke.VarHandle;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.tracked.NettyEntity.NO_LEASHER;
|
||||
import static games.cubi.raycastedantiesp.core.tracked.NettyEntity.NO_VEHICLE;
|
||||
|
||||
/**
|
||||
@@ -32,8 +34,13 @@ public class NettyData implements Clearable {
|
||||
// START Leash tracking:
|
||||
//
|
||||
private final Int2ObjectArrayMap<int[]> unresolvedLeashedEntityIDsByHolderID = new Int2ObjectArrayMap<>(DEFAULT_MAP_SIZE);
|
||||
private final Int2IntArrayMap unresolvedHolderIDsByLeashedEntityID = new Int2IntArrayMap(DEFAULT_MAP_SIZE);
|
||||
|
||||
public void addUnresolvedLeash(int holderEntityID, int leashedEntityID) {
|
||||
int previousHolderEntityID = unresolvedHolderIDsByLeashedEntityID.put(leashedEntityID, holderEntityID);
|
||||
if (previousHolderEntityID != NO_LEASHER && previousHolderEntityID != holderEntityID) {
|
||||
removeLeashedEntityFromUnresolvedHolder(previousHolderEntityID, leashedEntityID);
|
||||
}
|
||||
unresolvedLeashedEntityIDsByHolderID.compute(holderEntityID, (ignored, existing) -> {
|
||||
if (PrimitiveIntArrayList.contains(existing, leashedEntityID)) {
|
||||
return existing;
|
||||
@@ -43,37 +50,49 @@ public class NettyData implements Clearable {
|
||||
}
|
||||
|
||||
public boolean removeUnresolvedLeash(int holderEntityID, int leashedEntityID) {
|
||||
final boolean[] removed = new boolean[1];
|
||||
unresolvedLeashedEntityIDsByHolderID.computeIfPresent(holderEntityID, (ignored, existing) -> {
|
||||
if (!PrimitiveIntArrayList.contains(existing, leashedEntityID)) {
|
||||
return existing;
|
||||
}
|
||||
removed[0] = true;
|
||||
int[] updated = PrimitiveIntArrayList.remove(existing, leashedEntityID);
|
||||
return PrimitiveIntArrayList.isEmpty(updated) ? null : updated;
|
||||
});
|
||||
return removed[0];
|
||||
if (unresolvedHolderIDsByLeashedEntityID.get(leashedEntityID) != holderEntityID) {
|
||||
return false;
|
||||
}
|
||||
unresolvedHolderIDsByLeashedEntityID.remove(leashedEntityID);
|
||||
removeLeashedEntityFromUnresolvedHolder(holderEntityID, leashedEntityID);
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getUnresolvedHolderForLeashedEntity(int leashedEntityID) {
|
||||
return unresolvedHolderIDsByLeashedEntityID.get(leashedEntityID);
|
||||
}
|
||||
|
||||
public int[] getUnresolvedLeashes(int holderEntityID) {
|
||||
return PrimitiveIntArrayList.getCopyOrNull(unresolvedLeashedEntityIDsByHolderID.get(holderEntityID));
|
||||
}
|
||||
|
||||
public int[] consumeUnresolvedLeashes(int holderEntityID) {
|
||||
return unresolvedLeashedEntityIDsByHolderID.remove(holderEntityID);
|
||||
int[] existing = unresolvedLeashedEntityIDsByHolderID.remove(holderEntityID);
|
||||
if (PrimitiveIntArrayList.isEmpty(existing)) {
|
||||
return existing;
|
||||
}
|
||||
for (int leashedEntityID : existing) {
|
||||
if (unresolvedHolderIDsByLeashedEntityID.get(leashedEntityID) == holderEntityID) {
|
||||
unresolvedHolderIDsByLeashedEntityID.remove(leashedEntityID);
|
||||
}
|
||||
}
|
||||
return existing;
|
||||
}
|
||||
|
||||
public void removeUnresolvedLeashedEntityFromAll(int leashedEntityID) {
|
||||
ObjectIterator<Int2ObjectMap.Entry<int @IntArrayListMarker []>> iterator = unresolvedLeashedEntityIDsByHolderID.int2ObjectEntrySet().fastIterator();
|
||||
while (iterator.hasNext()) {
|
||||
Int2ObjectMap.Entry<int @IntArrayListMarker []> entry = iterator.next();
|
||||
int[] existing = entry.getValue();
|
||||
if (!PrimitiveIntArrayList.contains(existing, leashedEntityID)) {
|
||||
continue;
|
||||
}
|
||||
int[] updated = PrimitiveIntArrayList.remove(existing, leashedEntityID);
|
||||
if (PrimitiveIntArrayList.isEmpty(updated)) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
entry.setValue(updated);
|
||||
public int consumeUnresolvedHolderForLeashedEntity(int leashedEntityID) {
|
||||
int holderEntityID = unresolvedHolderIDsByLeashedEntityID.remove(leashedEntityID);
|
||||
if (holderEntityID == NO_LEASHER) {
|
||||
return NO_LEASHER;
|
||||
}
|
||||
removeLeashedEntityFromUnresolvedHolder(holderEntityID, leashedEntityID);
|
||||
return holderEntityID;
|
||||
}
|
||||
|
||||
private void removeLeashedEntityFromUnresolvedHolder(int holderEntityID, int leashedEntityID) {
|
||||
unresolvedLeashedEntityIDsByHolderID.computeIfPresent(holderEntityID, (ignored, existing) -> {
|
||||
int[] updated = PrimitiveIntArrayList.remove(existing, leashedEntityID);
|
||||
return PrimitiveIntArrayList.isEmpty(updated) ? null : updated;
|
||||
});
|
||||
}
|
||||
//
|
||||
// END Leash tracking.
|
||||
@@ -85,18 +104,21 @@ public class NettyData implements Clearable {
|
||||
// START Passenger tracking:
|
||||
//
|
||||
/**
|
||||
* Latest unresolved full passenger list for a vehicle.
|
||||
* This is only needed while at least one referenced passenger or the vehicle-side reconciliation has still not been spawned in for the client. The actual client deals with this somehow but we need the entity to have been spawned in before we can register the passenger relationship.
|
||||
* Latest full passenger list for a vehicle that is not represented by a tracked entity.
|
||||
* Normally this is temporary reconciliation state while a vehicle or passenger is waiting to spawn.
|
||||
* Bypassed vehicles remain untracked, so their authoritative passenger list stays here until it is
|
||||
* replaced by another passenger packet or cleared by the vehicle's destroy packet.
|
||||
*/
|
||||
private final Int2ObjectArrayMap<int[]> unresolvedPassengerIDsByVehicleID = new Int2ObjectArrayMap<>(DEFAULT_MAP_SIZE);
|
||||
/**
|
||||
* Reverse lookup for unresolved passenger relationships.
|
||||
* Lets a later passenger spawn discover which vehicle most recently claimed it as a passenger.
|
||||
* Reverse lookup for passenger relationships stored above.
|
||||
* Lets a later passenger spawn discover which untracked vehicle most recently claimed it as a passenger.
|
||||
* This may grow larger than {@link #unresolvedPassengerIDsByVehicleID} if vehicles have several passengers, so it's an open hash map.
|
||||
*/
|
||||
private final Int2IntOpenHashMap unresolvedVehicleIDsByPassengerID = new Int2IntOpenHashMap(DEFAULT_MAP_SIZE);
|
||||
|
||||
{
|
||||
unresolvedHolderIDsByLeashedEntityID.defaultReturnValue(NO_LEASHER);
|
||||
unresolvedVehicleIDsByPassengerID.defaultReturnValue(NO_VEHICLE);
|
||||
}
|
||||
|
||||
@@ -241,15 +263,15 @@ public class NettyData implements Clearable {
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// START Self entity tracking:
|
||||
//
|
||||
private final NettyEntity<?, ?> selfEntity;
|
||||
private final NettyEntity<?> selfEntity;
|
||||
private final int selfEntityID;
|
||||
|
||||
public NettyData(NettyEntity<?, ?> selfEntity) {
|
||||
public NettyData(NettyEntity<?> selfEntity) {
|
||||
this.selfEntity = selfEntity;
|
||||
this.selfEntityID = selfEntity.entityID();
|
||||
}
|
||||
|
||||
public NettyEntity<?, ?> getSelfEntity() {
|
||||
public NettyEntity<?> getSelfEntity() {
|
||||
return selfEntity;
|
||||
}
|
||||
|
||||
@@ -334,6 +356,7 @@ public class NettyData implements Clearable {
|
||||
|
||||
public void clearPendingReconciliationState() {
|
||||
unresolvedLeashedEntityIDsByHolderID.clear();
|
||||
unresolvedHolderIDsByLeashedEntityID.clear();
|
||||
unresolvedPassengerIDsByVehicleID.clear();
|
||||
unresolvedVehicleIDsByPassengerID.clear();
|
||||
pendingPostEntitySpawnTasksByEntityID.clear();
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.players;
|
||||
|
||||
import games.cubi.locatables.api.Locatable;
|
||||
@@ -9,6 +17,7 @@ import games.cubi.raycastedantiesp.core.view.BlockView;
|
||||
import games.cubi.raycastedantiesp.core.view.EntityView;
|
||||
import games.cubi.raycastedantiesp.core.view.ViewRegistry;
|
||||
import games.cubi.raycastedantiesp.core.view.controller.PacketEntityViewController;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.util.Objects;
|
||||
@@ -43,7 +52,7 @@ public class PlayerData {
|
||||
entityView = ViewRegistry.createEntityView(worldEpochSupplier);
|
||||
playerView = ViewRegistry.createPlayerEntityView(worldEpochSupplier);
|
||||
ownLocation = new ThreadSafeLocatable(null, 0, 0, 0);
|
||||
NettyEntity<?, ?> selfEntity = Logger.requireNonNull(
|
||||
NettyEntity<?> selfEntity = Logger.requireNonNull(
|
||||
selfEntityCreator.createSelfEntity(this, selfEntityID, player),
|
||||
"Self entity creator returned null",
|
||||
3,
|
||||
@@ -165,7 +174,7 @@ public class PlayerData {
|
||||
return null;
|
||||
}
|
||||
|
||||
public NettyEntity<?,?> entityFromID(int entityID) {
|
||||
public @Nullable NettyEntity<?> entityFromID(int entityID) {
|
||||
if (nettyData.isSelfEntityID(entityID)) {
|
||||
return nettyData.getSelfEntity();
|
||||
}
|
||||
@@ -173,7 +182,7 @@ public class PlayerData {
|
||||
if (entityView == null) {
|
||||
return null;
|
||||
}
|
||||
return (NettyEntity<?, ?>) entityView.getEntity(entityID);
|
||||
return (NettyEntity<?>) entityView.getEntity(entityID);
|
||||
}
|
||||
|
||||
public void setBypassPermission(boolean hasBypassPermission) {
|
||||
|
||||
@@ -0,0 +1,355 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.players;
|
||||
|
||||
import games.cubi.locatables.api.FloatingLocatableEquality;
|
||||
import games.cubi.locatables.api.Locatable;
|
||||
import games.cubi.locatables.api.MutableFloatingLocatable;
|
||||
import games.cubi.locatables.api.Spatial;
|
||||
import games.cubi.raycastedantiesp.core.utils.VarHandler;
|
||||
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A mutable, thread-safe location and view state for a player.
|
||||
*
|
||||
* <p>Mutations are serialized because platform and packet lifecycle callbacks
|
||||
* may write from different threads. World and scalar reads use relaxed
|
||||
* per-field access: a read may combine values from adjacent updates.</p>
|
||||
* <p></p>
|
||||
* Reads of several fields are not coherently published. This is acceptable
|
||||
* since players typically move in small increments, so an old x and new z
|
||||
* still closely approximate the player's actual position. In less-frequent
|
||||
* cases such as teleports or dimension switches, raycasts may use the incorrect
|
||||
* position briefly. This does not matter, as incorrect state will be fixed by next tick's raycast.
|
||||
*/
|
||||
public final class PlayerLocatable implements MutableFloatingLocatable, FloatingLocatableEquality {
|
||||
private final Object writerMonitor = new Object();
|
||||
|
||||
private volatile UUID world; private static final VarHandle WORLD = VarHandler.get(PlayerLocatable.class, "world", UUID.class);
|
||||
private volatile double x; private static final VarHandle X = VarHandler.get(PlayerLocatable.class, "x", double.class);
|
||||
private volatile double y; private static final VarHandle Y = VarHandler.get(PlayerLocatable.class, "y", double.class);
|
||||
private volatile double z; private static final VarHandle Z = VarHandler.get(PlayerLocatable.class, "z", double.class);
|
||||
private volatile float yaw; private static final VarHandle YAW = VarHandler.get(PlayerLocatable.class, "yaw", float.class);
|
||||
private volatile float pitch; private static final VarHandle PITCH = VarHandler.get(PlayerLocatable.class, "pitch", float.class);
|
||||
private volatile PlayerPose pose; private static final VarHandle POSE = VarHandler.get(PlayerLocatable.class, "pose", PlayerPose.class);
|
||||
|
||||
public PlayerLocatable() {
|
||||
}
|
||||
|
||||
/** Initialises or replaces the complete valid player state. */
|
||||
public void initialise(UUID world, double footX, double footY, double footZ, float yaw, float pitch, PlayerPose pose) {
|
||||
validateFullState(world, footX, footY, footZ, yaw, pitch, pose);
|
||||
synchronized (writerMonitor) {
|
||||
writeFullState(world, footX, footY, footZ, yaw, pitch, pose);
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates the complete state for a world change. */
|
||||
public void worldChange(UUID world, double footX, double footY, double footZ, float yaw, float pitch, PlayerPose pose) {
|
||||
validateFullState(world, footX, footY, footZ, yaw, pitch, pose);
|
||||
synchronized (writerMonitor) {
|
||||
writeFullState(world, footX, footY, footZ, yaw, pitch, pose);
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates the player's foot position while retaining rotation and pose. */
|
||||
public void updateFoot(double footX, double footY, double footZ) {
|
||||
validateFinite(footX, footY, footZ);
|
||||
synchronized (writerMonitor) {
|
||||
X.setOpaque(this, footX);
|
||||
Y.setOpaque(this, footY);
|
||||
Z.setOpaque(this, footZ);
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates the player's rotation while retaining position and pose. */
|
||||
public void updateRotation(float yaw, float pitch) {
|
||||
validateRotation(yaw, pitch);
|
||||
synchronized (writerMonitor) {
|
||||
YAW.setOpaque(this, yaw);
|
||||
PITCH.setOpaque(this, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates the player's pose while retaining position and rotation. */
|
||||
public void updatePose(PlayerPose pose) {
|
||||
Objects.requireNonNull(pose, "pose");
|
||||
synchronized (writerMonitor) {
|
||||
POSE.setOpaque(this, pose);
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates position and rotation in one logical operation. */
|
||||
public void updateFootAndRotation(double footX, double footY, double footZ, float yaw, float pitch) {
|
||||
validateFinite(footX, footY, footZ);
|
||||
validateRotation(yaw, pitch);
|
||||
synchronized (writerMonitor) {
|
||||
X.setOpaque(this, footX);
|
||||
Y.setOpaque(this, footY);
|
||||
Z.setOpaque(this, footZ);
|
||||
YAW.setOpaque(this, yaw);
|
||||
PITCH.setOpaque(this, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
/** Invalidates and clears the complete player state. */
|
||||
public void invalidate() {
|
||||
synchronized (writerMonitor) {
|
||||
WORLD.setOpaque(this, null);
|
||||
X.setOpaque(this, 0.0);
|
||||
Y.setOpaque(this, 0.0);
|
||||
Z.setOpaque(this, 0.0);
|
||||
YAW.setOpaque(this, 0.0f);
|
||||
PITCH.setOpaque(this, 0.0f);
|
||||
POSE.setOpaque(this, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID world() {
|
||||
return (UUID) WORLD.getOpaque(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double x() {
|
||||
return (double) X.getOpaque(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double y() {
|
||||
return (double) Y.getOpaque(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double z() {
|
||||
return (double) Z.getOpaque(this);
|
||||
}
|
||||
|
||||
public float yaw() {
|
||||
return (float) YAW.getOpaque(this);
|
||||
}
|
||||
|
||||
public float pitch() {
|
||||
return (float) PITCH.getOpaque(this);
|
||||
}
|
||||
|
||||
public PlayerPose pose() {
|
||||
return (PlayerPose) POSE.getOpaque(this);
|
||||
}
|
||||
|
||||
public float cameraYOffset() {
|
||||
PlayerPose currentPose = (PlayerPose) POSE.getOpaque(this);
|
||||
return currentPose == null ? 0.0f : currentPose.cameraYOffset();
|
||||
}
|
||||
|
||||
public double cameraX() {
|
||||
return (double) X.getOpaque(this);
|
||||
}
|
||||
|
||||
public double cameraY() {
|
||||
double currentY = (double) Y.getOpaque(this);
|
||||
PlayerPose currentPose = (PlayerPose) POSE.getOpaque(this);
|
||||
return currentY + (currentPose == null ? 0.0 : (double) currentPose.cameraYOffset());
|
||||
}
|
||||
|
||||
public double cameraZ() {
|
||||
return (double) Z.getOpaque(this);
|
||||
}
|
||||
|
||||
public double cameraDistanceSquared(Spatial spatial) {
|
||||
Objects.requireNonNull(spatial, "spatial");
|
||||
double targetX = spatial.x();
|
||||
double targetY = spatial.y();
|
||||
double targetZ = spatial.z();
|
||||
double currentX = (double) X.getOpaque(this);
|
||||
double currentY = (double) Y.getOpaque(this);
|
||||
double currentZ = (double) Z.getOpaque(this);
|
||||
PlayerPose currentPose = (PlayerPose) POSE.getOpaque(this);
|
||||
double dx = currentX - targetX;
|
||||
double dy = currentY + (currentPose == null ? 0.0 : (double) currentPose.cameraYOffset()) - targetY;
|
||||
double dz = currentZ - targetZ;
|
||||
return dx * dx + dy * dy + dz * dz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setX(double x) {
|
||||
validateFinite(x);
|
||||
synchronized (writerMonitor) {
|
||||
X.setOpaque(this, x);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setY(double y) {
|
||||
validateFinite(y);
|
||||
synchronized (writerMonitor) {
|
||||
Y.setOpaque(this, y);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setZ(double z) {
|
||||
validateFinite(z);
|
||||
synchronized (writerMonitor) {
|
||||
Z.setOpaque(this, z);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setPosition(double x, double y, double z) {
|
||||
validateFinite(x, y, z);
|
||||
synchronized (writerMonitor) {
|
||||
X.setOpaque(this, x);
|
||||
Y.setOpaque(this, y);
|
||||
Z.setOpaque(this, z);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setPosition(Spatial spatial) {
|
||||
Objects.requireNonNull(spatial, "spatial");
|
||||
return setPosition(spatial.x(), spatial.y(), spatial.z());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setWorld(UUID world) {
|
||||
if (world == null) {
|
||||
invalidate();
|
||||
return this;
|
||||
}
|
||||
synchronized (writerMonitor) {
|
||||
WORLD.setOpaque(this, world);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setLocation(Locatable locatable) {
|
||||
Objects.requireNonNull(locatable, "locatable");
|
||||
return setLocation(locatable.world(), locatable.x(), locatable.y(), locatable.z());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setLocation(UUID world, double x, double y, double z) {
|
||||
validateFinite(x, y, z);
|
||||
if (world == null) {
|
||||
invalidate();
|
||||
return this;
|
||||
}
|
||||
synchronized (writerMonitor) {
|
||||
X.setOpaque(this, x);
|
||||
Y.setOpaque(this, y);
|
||||
Z.setOpaque(this, z);
|
||||
WORLD.setOpaque(this, world);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable set(Locatable locatable) {
|
||||
return setLocation(locatable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable set(double x, double y, double z) {
|
||||
return setPosition(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable set(int x, int y, int z) {
|
||||
return setPosition(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable set(double x, double y, double z, UUID world) {
|
||||
return setLocation(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocatableType getType() {
|
||||
return LocatableType.ThreadSafe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return isEqualTo(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return makeHash();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean strictlyEquals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof PlayerLocatable that)) {
|
||||
return false;
|
||||
}
|
||||
UUID thisWorld = world();
|
||||
double thisX = x();
|
||||
double thisY = y();
|
||||
double thisZ = z();
|
||||
return Objects.equals(thisWorld, that.world())
|
||||
&& Double.doubleToLongBits(thisX) == Double.doubleToLongBits(that.x())
|
||||
&& Double.doubleToLongBits(thisY) == Double.doubleToLongBits(that.y())
|
||||
&& Double.doubleToLongBits(thisZ) == Double.doubleToLongBits(that.z());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toStringForm();
|
||||
}
|
||||
|
||||
/** This method must only be called while holding {@link #writerMonitor}. */
|
||||
private void writeFullState(UUID world, double footX, double footY, double footZ, float yaw, float pitch, PlayerPose pose) {
|
||||
WORLD.setOpaque(this, null);
|
||||
X.setOpaque(this, footX);
|
||||
Y.setOpaque(this, footY);
|
||||
Z.setOpaque(this, footZ);
|
||||
YAW.setOpaque(this, yaw);
|
||||
PITCH.setOpaque(this, pitch);
|
||||
POSE.setOpaque(this, pose);
|
||||
WORLD.setOpaque(this, world);
|
||||
}
|
||||
|
||||
private static void validateFullState(UUID world, double footX, double footY, double footZ, float yaw, float pitch, PlayerPose pose) {
|
||||
Objects.requireNonNull(world, "world");
|
||||
Objects.requireNonNull(pose, "pose");
|
||||
validateFinite(footX, footY, footZ);
|
||||
validateRotation(yaw, pitch);
|
||||
}
|
||||
|
||||
private static void validateFinite(double x, double y, double z) {
|
||||
if (!Double.isFinite(x) || !Double.isFinite(y) || !Double.isFinite(z)) {
|
||||
throw new IllegalArgumentException("Coordinates must be finite");
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateFinite(double value) {
|
||||
if (!Double.isFinite(value)) {
|
||||
throw new IllegalArgumentException("Coordinate must be finite");
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateRotation(float yaw, float pitch) {
|
||||
if (!Float.isFinite(yaw) || !Float.isFinite(pitch) || pitch < -90.0f || pitch > 90.0f) {
|
||||
throw new IllegalArgumentException("Rotation must be finite and pitch must be between -90 and 90 degrees");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.players;
|
||||
|
||||
/** Player body poses and the corresponding camera height above the feet. */
|
||||
public enum PlayerPose {
|
||||
UNKNOWN(1.62f),
|
||||
STANDING(1.62f),
|
||||
SNEAKING(1.27f),
|
||||
SWIMMING(0.40f),
|
||||
FALL_FLYING(0.40f),
|
||||
SPIN_ATTACK(0.40f),
|
||||
SLEEPING(0.20f),
|
||||
DYING(0.20f);
|
||||
|
||||
private final float cameraYOffset;
|
||||
|
||||
PlayerPose(float cameraYOffset) {
|
||||
this.cameraYOffset = cameraYOffset;
|
||||
}
|
||||
|
||||
public float cameraYOffset() {
|
||||
return cameraYOffset;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.players;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.tracked.NettyEntity;
|
||||
@@ -10,17 +18,14 @@ public class PlayerRegistry {
|
||||
|
||||
@FunctionalInterface
|
||||
public interface SelfEntityCreator {
|
||||
NettyEntity<?, ?> createSelfEntity(PlayerData playerData, int selfEntityID, UUID playerUUID);
|
||||
NettyEntity<?> createSelfEntity(PlayerData playerData, int selfEntityID, UUID playerUUID);
|
||||
}
|
||||
|
||||
private static PlayerRegistry instance;
|
||||
private static final PlayerRegistry instance = new PlayerRegistry();
|
||||
|
||||
private PlayerRegistry() {}
|
||||
|
||||
public static PlayerRegistry getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new PlayerRegistry();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.raycast;
|
||||
|
||||
import games.cubi.locatables.api.Locatable;
|
||||
|
||||
@@ -1,18 +1,38 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.raycast;
|
||||
|
||||
import games.cubi.locatables.api.Locatable;
|
||||
import games.cubi.locatables.api.MutableFloatingSpatial;
|
||||
import games.cubi.locatables.api.Spatial;
|
||||
import games.cubi.locatables.api.*;
|
||||
import games.cubi.locatables.implementations.MutableChunkSection;
|
||||
import games.cubi.locatables.implementations.MutableSpatialImpl;
|
||||
import games.cubi.logs.Logger;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkOcclusionView;
|
||||
import games.cubi.raycastedantiesp.core.view.BlockView;
|
||||
|
||||
public class RaycastUtil {
|
||||
|
||||
//True: Has line-of-sight
|
||||
public static boolean raycast(Locatable start, Spatial end, int maxOccluding, int alwaysShowRadius, int maxRaycastRadius, boolean debug, BlockView snap, int stepSize, ParticleSpawner particleSpawner) {
|
||||
MutableFloatingSpatial clonedEnd = end.cloneAndIfBlockThenCentre();
|
||||
double total = start.distance(clonedEnd) - stepSize; //benchmarking shows that calling distance() is faster than distanceSquared() then checking distanceSquared < stepSize*stepSize every time despite the latter replacing a square root with multiplication
|
||||
//True: Has line-of-sight
|
||||
//This is deliberately a ray-stepping algorithm rather than DDA as it is much faster (2x in benchmarking)
|
||||
//Missing blocks is acceptable, as it will be assumed the player can see past those corners.
|
||||
//While this uses objects, JHM and in-game profiling have both shown that all objects used here are consistently scalarised by the JVM.
|
||||
public static boolean raycast(Locatable start, Spatial end, int maxOccluding, int alwaysShowRadius, int maxRaycastRadius, boolean debug, BlockView snap, float stepSize, ParticleSpawner particleSpawner) {
|
||||
//return raycastCubiNoAllocUnrolledLongBitsAccumulated(maxOccluding, alwaysShowRadius, maxRaycastRadius, debug, 1, snap, start.x(), start.y(), start.z(), end.x(), end.y(), end.z());
|
||||
|
||||
//return raycastUnrolledAccumulated(maxOccluding, alwaysShowRadius, maxRaycastRadius, debug, 1, snap, start, end);
|
||||
return raycast(start, end, maxOccluding, alwaysShowRadius, maxRaycastRadius, debug, snap, 0f, stepSize, particleSpawner);
|
||||
}
|
||||
|
||||
public static boolean raycast(Locatable start, Spatial end, int maxOccluding, int alwaysShowRadius, int maxRaycastRadius, boolean debug, BlockView snap, float yOffsetEnd, float stepSize, ParticleSpawner particleSpawner) {
|
||||
double endOffset = end instanceof BlockSpatial ? 0.5 : 0.0;
|
||||
MutableFloatingSpatial clonedEnd = new MutableSpatialImpl(end.x() + endOffset, end.y() + endOffset + yOffsetEnd, end.z() + endOffset);
|
||||
//Equivalent to end.cloneAndIfBlockThenCentre(); but not used since the JVM was not reliably scalarising that method (probably due to the polymorphic overriding?). This causes 0 object allocations.
|
||||
float total = (float) (start.distance(clonedEnd) - stepSize); //benchmarking shows that calling distance() is faster than distanceSquared() then checking distanceSquared < stepSize*stepSize every time despite the latter replacing a square root with multiplication
|
||||
if (total <= alwaysShowRadius) return true;
|
||||
if (total > maxRaycastRadius) return false;
|
||||
if (debug && particleSpawner == null) {
|
||||
@@ -22,11 +42,17 @@ public class RaycastUtil {
|
||||
Spatial dir = clonedEnd.subtract(start).normalise().scalarMultiply(stepSize);
|
||||
|
||||
MutableFloatingSpatial current = new MutableSpatialImpl(start.x(),start.y(),start.z());
|
||||
MutableChunkSection currentChunk = new MutableChunkSection().updateFrom(current);
|
||||
ChunkOcclusionView currentOcclusionView = snap.getChunkOcclusionView(currentChunk);
|
||||
|
||||
for (double traveled = 0; traveled < total; traveled += stepSize) { //benchmarking shows that for loop is marginally faster than while loop initially (after running for a while they are equal
|
||||
for (float traveled = 0; traveled < total; traveled += stepSize) {
|
||||
current.add(dir);
|
||||
if (!ChunkSectionEquality.equals(currentChunk, current)) {
|
||||
currentChunk.updateFrom(current);
|
||||
currentOcclusionView = snap.getChunkOcclusionView(currentChunk);
|
||||
}
|
||||
|
||||
if (snap.isBlockOccluding(current.blockX(), current.blockY(), current.blockZ())) {
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(current.blockX(), current.blockY(), current.blockZ())) {
|
||||
maxOccluding--;
|
||||
if (debug) particleSpawner.spawnParticleAt(start.world(), current, ParticleSpawner.Colour.RED);
|
||||
if (maxOccluding < 1) return false;
|
||||
@@ -37,4 +63,275 @@ public class RaycastUtil {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
public static boolean raycastCubiNoAllocUnrolledLongBitsAccumulated(int maxOccluding, final int alwaysShowRadius, final int maxRaycastRadius, boolean debug, final int stepSize, BlockView snap,
|
||||
final double startX, final double startY, final double startZ, final double endX, final double endY, final double endZ) {
|
||||
if (maxOccluding <= 0) return false;
|
||||
|
||||
double total = Math.sqrt(((endX - startX) * (endX - startX)) + ((endY - startY) * (endY - startY)) + ((endZ - startZ) * (endZ - startZ)));
|
||||
if (total <= alwaysShowRadius) return true;
|
||||
if (total > maxRaycastRadius) return false;
|
||||
double finalDist = total - stepSize;
|
||||
|
||||
final double dirX = (endX - startX) / total * stepSize;
|
||||
final double dirY = (endY - startY) / total * stepSize;
|
||||
final double dirZ = (endZ - startZ) / total * stepSize;
|
||||
|
||||
double currentX = startX;
|
||||
double currentY = startY;
|
||||
double currentZ = startZ;
|
||||
|
||||
int chunkX = ((int) currentX) >> 4;
|
||||
int chunkY = ((int) currentY) >> 4;
|
||||
int chunkZ = ((int) currentZ) >> 4;
|
||||
ChunkOcclusionView currentOcclusionView = snap.getChunkOcclusionView(chunkX, chunkY, chunkZ);
|
||||
|
||||
int occluded = 0;
|
||||
|
||||
double traveled = 0;
|
||||
final double fourSteps = stepSize * 4.0;
|
||||
while (traveled + fourSteps <= finalDist) {
|
||||
currentX += dirX;
|
||||
currentY += dirY;
|
||||
currentZ += dirZ;
|
||||
|
||||
int blockX = (int) Math.floor(currentX);
|
||||
int blockY = (int) Math.floor(currentY);
|
||||
int blockZ = (int) Math.floor(currentZ);
|
||||
if (blockX >> 4 != chunkX || blockY >> 4 != chunkY || blockZ >> 4 != chunkZ) {
|
||||
chunkX = blockX >> 4;
|
||||
chunkY = blockY >> 4;
|
||||
chunkZ = blockZ >> 4;
|
||||
currentOcclusionView = snap.getChunkOcclusionView(chunkX, chunkY, chunkZ);
|
||||
}
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded ++;
|
||||
|
||||
currentX += dirX;
|
||||
currentY += dirY;
|
||||
currentZ += dirZ;
|
||||
|
||||
blockX = (int) Math.floor(currentX);
|
||||
blockY = (int) Math.floor(currentY);
|
||||
blockZ = (int) Math.floor(currentZ);
|
||||
if (blockX >> 4 != chunkX || blockY >> 4 != chunkY || blockZ >> 4 != chunkZ) {
|
||||
chunkX = blockX >> 4;
|
||||
chunkY = blockY >> 4;
|
||||
chunkZ = blockZ >> 4;
|
||||
currentOcclusionView = snap.getChunkOcclusionView(chunkX, chunkY, chunkZ);
|
||||
}
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded ++;
|
||||
|
||||
currentX += dirX;
|
||||
currentY += dirY;
|
||||
currentZ += dirZ;
|
||||
|
||||
blockX = (int) Math.floor(currentX);
|
||||
blockY = (int) Math.floor(currentY);
|
||||
blockZ = (int) Math.floor(currentZ);
|
||||
if (blockX >> 4 != chunkX || blockY >> 4 != chunkY || blockZ >> 4 != chunkZ) {
|
||||
chunkX = blockX >> 4;
|
||||
chunkY = blockY >> 4;
|
||||
chunkZ = blockZ >> 4;
|
||||
currentOcclusionView = snap.getChunkOcclusionView(chunkX, chunkY, chunkZ);
|
||||
}
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded ++;
|
||||
|
||||
currentX += dirX;
|
||||
currentY += dirY;
|
||||
currentZ += dirZ;
|
||||
|
||||
blockX = (int) Math.floor(currentX);
|
||||
blockY = (int) Math.floor(currentY);
|
||||
blockZ = (int) Math.floor(currentZ);
|
||||
if (blockX >> 4 != chunkX || blockY >> 4 != chunkY || blockZ >> 4 != chunkZ) {
|
||||
chunkX = blockX >> 4;
|
||||
chunkY = blockY >> 4;
|
||||
chunkZ = blockZ >> 4;
|
||||
currentOcclusionView = snap.getChunkOcclusionView(chunkX, chunkY, chunkZ);
|
||||
}
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded ++;
|
||||
|
||||
if (occluded >= maxOccluding) return false;
|
||||
|
||||
traveled += fourSteps;
|
||||
}
|
||||
|
||||
for (; traveled < finalDist; traveled += stepSize) {
|
||||
currentX += dirX;
|
||||
currentY += dirY;
|
||||
currentZ += dirZ;
|
||||
|
||||
int blockX = (int) Math.floor(currentX);
|
||||
int blockY = (int) Math.floor(currentY);
|
||||
int blockZ = (int) Math.floor(currentZ);
|
||||
if (blockX >> 4 != chunkX || blockY >> 4 != chunkY || blockZ >> 4 != chunkZ) {
|
||||
chunkX = blockX >> 4;
|
||||
chunkY = blockY >> 4;
|
||||
chunkZ = blockZ >> 4;
|
||||
currentOcclusionView = snap.getChunkOcclusionView(chunkX, chunkY, chunkZ);
|
||||
}
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded ++;
|
||||
}
|
||||
|
||||
return occluded < maxOccluding;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* The local spatial and chunk-section objects do not escape this method, so the JVM
|
||||
* should be able to scalarise them while keeping the ray-stepping code easier to follow.
|
||||
*/
|
||||
public static boolean raycastUnrolledAccumulated(int maxOccluding, final int alwaysShowRadius, final int maxRaycastRadius, boolean debug,
|
||||
final float stepSize, final BlockView snap, final Spatial start, final Spatial end) {
|
||||
RayPosition current = RayPosition.from(start);
|
||||
RayDirection direction = RayDirection.from(end, current);
|
||||
double total = direction.getLengthAndNormalise(stepSize);
|
||||
if (total <= alwaysShowRadius) return true;
|
||||
if (total > maxRaycastRadius) return false;
|
||||
float finalDist = (float) (total - stepSize);
|
||||
|
||||
RayChunkSection currentChunk = new RayChunkSection().updateFrom(current);
|
||||
ChunkOcclusionView currentOcclusionView = snap.getChunkOcclusionView(currentChunk.chunkX, currentChunk.chunkY, currentChunk.chunkZ);
|
||||
|
||||
int occluded = 0;
|
||||
|
||||
float traveled = 0;
|
||||
final float fourSteps = stepSize * 4.0f;
|
||||
while (traveled + fourSteps <= finalDist) {
|
||||
current.advance(direction);
|
||||
int blockX = current.blockX();
|
||||
int blockY = current.blockY();
|
||||
int blockZ = current.blockZ();
|
||||
if (blockX >> 4 != currentChunk.chunkX || blockY >> 4 != currentChunk.chunkY || blockZ >> 4 != currentChunk.chunkZ) {
|
||||
currentChunk.updateFrom(current);
|
||||
currentOcclusionView = snap.getChunkOcclusionView(currentChunk.chunkX, currentChunk.chunkY, currentChunk.chunkZ);
|
||||
}
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded++;
|
||||
|
||||
current.advance(direction);
|
||||
blockX = current.blockX();
|
||||
blockY = current.blockY();
|
||||
blockZ = current.blockZ();
|
||||
if (blockX >> 4 != currentChunk.chunkX || blockY >> 4 != currentChunk.chunkY || blockZ >> 4 != currentChunk.chunkZ) {
|
||||
currentChunk.updateFrom(current);
|
||||
currentOcclusionView = snap.getChunkOcclusionView(currentChunk.chunkX, currentChunk.chunkY, currentChunk.chunkZ);
|
||||
}
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded++;
|
||||
|
||||
current.advance(direction);
|
||||
blockX = current.blockX();
|
||||
blockY = current.blockY();
|
||||
blockZ = current.blockZ();
|
||||
if (blockX >> 4 != currentChunk.chunkX || blockY >> 4 != currentChunk.chunkY || blockZ >> 4 != currentChunk.chunkZ) {
|
||||
currentChunk.updateFrom(current);
|
||||
currentOcclusionView = snap.getChunkOcclusionView(currentChunk.chunkX, currentChunk.chunkY, currentChunk.chunkZ);
|
||||
}
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded++;
|
||||
|
||||
current.advance(direction);
|
||||
blockX = current.blockX();
|
||||
blockY = current.blockY();
|
||||
blockZ = current.blockZ();
|
||||
if (blockX >> 4 != currentChunk.chunkX || blockY >> 4 != currentChunk.chunkY || blockZ >> 4 != currentChunk.chunkZ) {
|
||||
currentChunk.updateFrom(current);
|
||||
currentOcclusionView = snap.getChunkOcclusionView(currentChunk.chunkX, currentChunk.chunkY, currentChunk.chunkZ);
|
||||
}
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded++;
|
||||
|
||||
if (occluded >= maxOccluding) return false;
|
||||
|
||||
traveled += fourSteps;
|
||||
}
|
||||
|
||||
for (; traveled < finalDist; traveled += stepSize) {
|
||||
current.advance(direction);
|
||||
int blockX = current.blockX();
|
||||
int blockY = current.blockY();
|
||||
int blockZ = current.blockZ();
|
||||
if (blockX >> 4 != currentChunk.chunkX || blockY >> 4 != currentChunk.chunkY || blockZ >> 4 != currentChunk.chunkZ) {
|
||||
currentChunk.updateFrom(current);
|
||||
currentOcclusionView = snap.getChunkOcclusionView(currentChunk.chunkX, currentChunk.chunkY, currentChunk.chunkZ);
|
||||
}
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded++;
|
||||
}
|
||||
|
||||
return occluded < maxOccluding;
|
||||
}
|
||||
|
||||
private static final class RayPosition {
|
||||
private double x, y, z;
|
||||
|
||||
private void advance(RayDirection direction) {
|
||||
x += direction.x;
|
||||
y += direction.y;
|
||||
z += direction.z;
|
||||
}
|
||||
|
||||
private int blockX() {
|
||||
return (int) Math.floor(x);
|
||||
}
|
||||
|
||||
private int blockY() {
|
||||
return (int) Math.floor(y);
|
||||
}
|
||||
|
||||
private int blockZ() {
|
||||
return (int) Math.floor(z);
|
||||
}
|
||||
|
||||
private int chunkX() {
|
||||
return blockX() >> 4;
|
||||
}
|
||||
|
||||
private int chunkY() {
|
||||
return blockY() >> 4;
|
||||
}
|
||||
|
||||
private int chunkZ() {
|
||||
return blockZ() >> 4;
|
||||
}
|
||||
|
||||
private RayPosition(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
private static RayPosition from(Spatial spatial) {
|
||||
return new RayPosition(spatial.x(), spatial.y(), spatial.z());
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RayDirection {
|
||||
private double x, y, z;
|
||||
|
||||
private RayDirection(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
private static RayDirection from(Spatial end, RayPosition start) {
|
||||
return new RayDirection(end.x() - start.x, end.y() - start.y, end.z() - start.z);
|
||||
}
|
||||
|
||||
private double getLengthAndNormalise(float stepSize) {
|
||||
double len = Math.sqrt(x * x + y * y + z * z);
|
||||
x = (x / len) * stepSize;
|
||||
y = (y / len) * stepSize;
|
||||
z = (z / len) * stepSize;
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RayChunkSection {
|
||||
private int chunkX, chunkY, chunkZ;
|
||||
|
||||
private RayChunkSection updateFrom(RayPosition other) {
|
||||
this.chunkX = other.chunkX();
|
||||
this.chunkY = other.chunkY();
|
||||
this.chunkZ = other.chunkZ();
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,14 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.tracked;
|
||||
|
||||
import games.cubi.locatables.api.ImmutableSpatial;
|
||||
import games.cubi.locatables.api.MutableFloatingSpatial;
|
||||
import games.cubi.locatables.implementations.ImmutableSpatialImpl;
|
||||
import games.cubi.raycastedantiesp.core.players.PlayerData;
|
||||
import games.cubi.raycastedantiesp.core.utils.Clearable;
|
||||
import games.cubi.raycastedantiesp.core.utils.PrimitiveIntArrayList;
|
||||
@@ -17,12 +23,12 @@ import java.util.UUID;
|
||||
* Designed for use with netty-based systems, where entity data updates only ever come from one thread, but reads may come from multiple threads. This is however not enforced, and must be kept in mind when using this class.
|
||||
* A representation of an entity for a specific player.
|
||||
*/
|
||||
public abstract class NettyEntity<EntityType, PacketReplayData extends Clearable> implements TrackedEntity<EntityType, PacketReplayData> {
|
||||
public abstract class NettyEntity<PacketReplayData extends Clearable> implements TrackedEntity<PacketReplayData> {
|
||||
// immutable fields
|
||||
private final int entityID;
|
||||
private final int entityID; // Note that, while rare, entity ids will be negative once the entity id counter overflows.
|
||||
private final UUID entityUUID;
|
||||
private final boolean isSelfEntity;
|
||||
private final EntityType entityType;
|
||||
private final int entityType;
|
||||
private final PlayerData owningPlayer;
|
||||
|
||||
// Netty mutatable fields. Should NEVER be mutated from the engine thread, but reads are fine.
|
||||
@@ -30,6 +36,11 @@ public abstract class NettyEntity<EntityType, PacketReplayData extends Clearable
|
||||
private volatile double y; private static final VarHandle Y = VarHandler.get(NettyEntity.class, "y", double.class);
|
||||
private volatile double z; private static final VarHandle Z = VarHandler.get(NettyEntity.class, "z", double.class);
|
||||
|
||||
// Packet-derived state shared with the engine.
|
||||
private static final byte FLAG_SNEAKING = 1;
|
||||
private static final byte FLAG_GLOWING = 1 << 1;
|
||||
private volatile byte trackedFlags; private static final VarHandle TRACKED_FLAGS = VarHandler.get(NettyEntity.class, "trackedFlags", byte.class);
|
||||
|
||||
// Packet-thread-only replay and client state.
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
@@ -56,7 +67,13 @@ public abstract class NettyEntity<EntityType, PacketReplayData extends Clearable
|
||||
// engine thread mutable, reads from netty and engine.
|
||||
private volatile boolean visible;
|
||||
|
||||
public NettyEntity(PlayerData owningPlayer, double x, double y, double z, int entityID, UUID entityUUID, boolean isSelfEntity, EntityType entityType, boolean visible) {
|
||||
// Constants
|
||||
public static final int NEVER_CHECKED = Integer.MIN_VALUE;
|
||||
public static final int NO_VEHICLE = -1;
|
||||
public static final int NO_LEASHER = -2;
|
||||
public static final int SELF_ENTITY_TYPE = -29;
|
||||
|
||||
public NettyEntity(PlayerData owningPlayer, double x, double y, double z, int entityID, UUID entityUUID, boolean isSelfEntity, int entityType, boolean visible) {
|
||||
X.set(this, x); Y.set(this, y); Z.set(this, z);
|
||||
|
||||
this.entityID = entityID;
|
||||
@@ -75,8 +92,7 @@ public abstract class NettyEntity<EntityType, PacketReplayData extends Clearable
|
||||
entityUUID = ownUUID;
|
||||
owningPlayer = selfData;
|
||||
isSelfEntity = true;
|
||||
entityType = null;
|
||||
clientVisible = true;
|
||||
entityType = SELF_ENTITY_TYPE;
|
||||
visible = true;
|
||||
}
|
||||
|
||||
@@ -99,18 +115,50 @@ public abstract class NettyEntity<EntityType, PacketReplayData extends Clearable
|
||||
* Wherever possible, effort should be made to only call this from the engine thread, for thread safety reasons.
|
||||
*/
|
||||
@Override
|
||||
public TrackedEntity<?, ?> setVisible(boolean visible) {
|
||||
public TrackedEntity<?> setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean glowing() {
|
||||
return (((byte) TRACKED_FLAGS.getOpaque(this)) & FLAG_GLOWING) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sneaking() {
|
||||
return (((byte) TRACKED_FLAGS.getOpaque(this)) & FLAG_SNEAKING) != 0;
|
||||
}
|
||||
|
||||
public boolean setGlowing(boolean glowing) {
|
||||
return setTrackedFlag(FLAG_GLOWING, glowing);
|
||||
}
|
||||
|
||||
public boolean setSneaking(boolean sneaking) {
|
||||
return setTrackedFlag(FLAG_SNEAKING, sneaking);
|
||||
}
|
||||
|
||||
private boolean setTrackedFlag(byte mask, boolean enabled) {
|
||||
byte previous = enabled
|
||||
? (byte) TRACKED_FLAGS.getAndBitwiseOrRelease(this, mask)
|
||||
: (byte) TRACKED_FLAGS.getAndBitwiseAndRelease(this, (byte) ~mask);
|
||||
boolean changed = (previous & mask) != (enabled ? mask : 0);
|
||||
if (changed) {
|
||||
// A concurrent engine check may overwrite this marker. Hidden entities retry next tick; visible entities
|
||||
// may wait for their configured recheck or remain visible if rechecks are disabled.
|
||||
// This is acceptable and not considered an issue.
|
||||
LAST_CHECKED.setOpaque(this, NEVER_CHECKED);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastChecked() {
|
||||
return (int) LAST_CHECKED.getOpaque(this);
|
||||
}
|
||||
// todo it may be that this is only ever set by the engine thread? If so, just volatile annotation may be safe enough, as no two engine threads should update a single player at the same time (add guard lock for this)
|
||||
|
||||
@Override
|
||||
public TrackedEntity<?, ?> setLastChecked(int lastChecked) {
|
||||
public TrackedEntity<?> setLastChecked(int lastChecked) {
|
||||
LAST_CHECKED.setOpaque(this, lastChecked);
|
||||
return this;
|
||||
}
|
||||
@@ -121,7 +169,7 @@ public abstract class NettyEntity<EntityType, PacketReplayData extends Clearable
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEntity<?, ?> setClientVisible(boolean clientVisible) {
|
||||
public TrackedEntity<?> setClientVisible(boolean clientVisible) {
|
||||
this.clientVisible = clientVisible;
|
||||
return this;
|
||||
}
|
||||
@@ -140,7 +188,7 @@ public abstract class NettyEntity<EntityType, PacketReplayData extends Clearable
|
||||
* THIS METHOD IS ONLY SAFE TO CALL FROM THE PLAYER's NETTY THREAD
|
||||
*/
|
||||
@Override
|
||||
public TrackedEntity<?, ?> setYaw(float yaw) {
|
||||
public TrackedEntity<?> setYaw(float yaw) {
|
||||
this.yaw = yaw;
|
||||
return this;
|
||||
}
|
||||
@@ -154,7 +202,7 @@ public abstract class NettyEntity<EntityType, PacketReplayData extends Clearable
|
||||
* THIS METHOD IS ONLY SAFE TO CALL FROM THE PLAYER's NETTY THREAD
|
||||
*/
|
||||
@Override
|
||||
public TrackedEntity<?, ?> setPitch(float pitch) {
|
||||
public TrackedEntity<?> setPitch(float pitch) {
|
||||
this.pitch = pitch;
|
||||
return this;
|
||||
}
|
||||
@@ -168,7 +216,7 @@ public abstract class NettyEntity<EntityType, PacketReplayData extends Clearable
|
||||
* THIS METHOD IS ONLY SAFE TO CALL FROM THE PLAYER's NETTY THREAD
|
||||
*/
|
||||
@Override
|
||||
public TrackedEntity<?, ?> setHeadYaw(float headYaw) {
|
||||
public TrackedEntity<?> setHeadYaw(float headYaw) {
|
||||
this.headYaw = headYaw;
|
||||
return this;
|
||||
}
|
||||
@@ -192,7 +240,7 @@ public abstract class NettyEntity<EntityType, PacketReplayData extends Clearable
|
||||
* THIS METHOD IS ONLY SAFE TO CALL FROM THE PLAYER's NETTY THREAD
|
||||
*/
|
||||
@Override
|
||||
public TrackedEntity<?, ?> setVelocity(double velocityX, double velocityY, double velocityZ) {
|
||||
public TrackedEntity<?> setVelocity(double velocityX, double velocityY, double velocityZ) {
|
||||
this.velocityX = velocityX;
|
||||
this.velocityY = velocityY;
|
||||
this.velocityZ = velocityZ;
|
||||
@@ -208,13 +256,12 @@ public abstract class NettyEntity<EntityType, PacketReplayData extends Clearable
|
||||
* THIS METHOD IS ONLY SAFE TO CALL FROM THE PLAYER's NETTY THREAD
|
||||
*/
|
||||
@Override
|
||||
public TrackedEntity<?, ?> setOnGround(boolean onGround) {
|
||||
public TrackedEntity<?> setOnGround(boolean onGround) {
|
||||
this.onGround = onGround;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType entityType() {
|
||||
public int entityType() {
|
||||
return entityType;
|
||||
}
|
||||
|
||||
@@ -224,7 +271,7 @@ public abstract class NettyEntity<EntityType, PacketReplayData extends Clearable
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEntity<?, ?> setEntityData(int entityData) {
|
||||
public TrackedEntity<?> setEntityData(int entityData) {
|
||||
this.entityData = entityData;
|
||||
return this;
|
||||
}
|
||||
@@ -236,7 +283,7 @@ public abstract class NettyEntity<EntityType, PacketReplayData extends Clearable
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEntity<?, ?> setPassengerIDs(int[] passengerIDs) {
|
||||
public TrackedEntity<?> setPassengerIDs(int[] passengerIDs) {
|
||||
PASSENGER_IDS.setRelease(this, passengerIDs == null ? new int[0] : passengerIDs.clone());
|
||||
return this;
|
||||
}
|
||||
@@ -253,6 +300,9 @@ public abstract class NettyEntity<EntityType, PacketReplayData extends Clearable
|
||||
|
||||
@Override
|
||||
public void addLeashedEntity(int leashedEntityID) {
|
||||
if (PrimitiveIntArrayList.contains(leashedIDs, leashedEntityID)) {
|
||||
return;
|
||||
}
|
||||
leashedIDs = PrimitiveIntArrayList.add(leashedIDs, leashedEntityID);
|
||||
}
|
||||
|
||||
@@ -265,9 +315,6 @@ public abstract class NettyEntity<EntityType, PacketReplayData extends Clearable
|
||||
return PrimitiveIntArrayList.getCopyOrNull(leashedIDs);
|
||||
}
|
||||
|
||||
public static final int NO_VEHICLE = -1;
|
||||
public static final int NO_LEASHER = -2;
|
||||
|
||||
@Override
|
||||
public int leashingEntity() {
|
||||
return (int) LEASHER_ID.getOpaque(this);
|
||||
@@ -284,14 +331,14 @@ public abstract class NettyEntity<EntityType, PacketReplayData extends Clearable
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEntity<?, ?> setPacketReplayData(PacketReplayData packetReplayData) {
|
||||
public TrackedEntity<?> setPacketReplayData(PacketReplayData packetReplayData) {
|
||||
this.packetReplayData = packetReplayData;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableSpatial getOffsetPosition() {
|
||||
return new ImmutableSpatialImpl(x(), y() + 0.5, z()); //todo: move away from hardcoded offset
|
||||
public float getYOffset() {
|
||||
return 0.5f; //todo: move away from hardcoded offset
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -353,7 +400,7 @@ public abstract class NettyEntity<EntityType, PacketReplayData extends Clearable
|
||||
double currentY = y();
|
||||
double currentZ = z();
|
||||
for (int passengerID : currentPassengerIDs) {
|
||||
NettyEntity<?, ?> passenger = owningPlayer.entityFromID(passengerID);
|
||||
NettyEntity<?> passenger = owningPlayer.entityFromID(passengerID);
|
||||
if (passenger != null) {
|
||||
passenger.setVehicleID(entityID);
|
||||
passenger.setX(currentX);
|
||||
@@ -369,6 +416,7 @@ public abstract class NettyEntity<EntityType, PacketReplayData extends Clearable
|
||||
if (packetReplayData != null) packetReplayData.clear();
|
||||
packetReplayData = null;
|
||||
|
||||
TRACKED_FLAGS.setOpaque(this, (byte) 0);
|
||||
VEHICLE_ID.setOpaque(this, NO_VEHICLE);
|
||||
PASSENGER_IDS.setRelease(this, null);
|
||||
leashedIDs = null;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.tracked;
|
||||
|
||||
import games.cubi.locatables.api.BlockSpatial;
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.tracked;
|
||||
|
||||
import games.cubi.locatables.api.ImmutableSpatial;
|
||||
import games.cubi.locatables.api.MutableFloatingSpatial;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -9,54 +16,56 @@ import java.util.UUID;
|
||||
/**
|
||||
* Per-player platform-independent representation of an entity
|
||||
*/
|
||||
public interface TrackedEntity<EntityType, PacketReplayData> extends MutableFloatingSpatial {
|
||||
public interface TrackedEntity<PacketReplayData> extends MutableFloatingSpatial {
|
||||
|
||||
int entityID();
|
||||
|
||||
UUID entityUUID();
|
||||
|
||||
boolean visible();
|
||||
TrackedEntity<?, ?> setVisible(boolean visible);
|
||||
TrackedEntity<?> setVisible(boolean visible);
|
||||
|
||||
boolean glowing();
|
||||
|
||||
boolean sneaking();
|
||||
|
||||
int lastChecked();
|
||||
TrackedEntity<?, ?> setLastChecked(int lastChecked);
|
||||
TrackedEntity<?> setLastChecked(int lastChecked);
|
||||
|
||||
/** Packet-thread-only client state. */
|
||||
boolean clientVisible();
|
||||
TrackedEntity<?, ?> setClientVisible(boolean clientVisible);
|
||||
TrackedEntity<?> setClientVisible(boolean clientVisible);
|
||||
|
||||
boolean isSelfEntity();
|
||||
|
||||
/** Packet-thread-only replay state. */
|
||||
float yaw();
|
||||
TrackedEntity<?, ?> setYaw(float yaw);
|
||||
TrackedEntity<?> setYaw(float yaw);
|
||||
|
||||
/** Packet-thread-only replay state. */
|
||||
float pitch();
|
||||
TrackedEntity<?, ?> setPitch(float pitch);
|
||||
TrackedEntity<?> setPitch(float pitch);
|
||||
|
||||
/** Packet-thread-only replay state. */
|
||||
float headYaw();
|
||||
TrackedEntity<?, ?> setHeadYaw(float headYaw);
|
||||
TrackedEntity<?> setHeadYaw(float headYaw);
|
||||
|
||||
/** Packet-thread-only replay state. */
|
||||
double velocityX();
|
||||
double velocityY();
|
||||
double velocityZ();
|
||||
TrackedEntity<?, ?> setVelocity(double velocityX, double velocityY, double velocityZ);
|
||||
TrackedEntity<?> setVelocity(double velocityX, double velocityY, double velocityZ);
|
||||
|
||||
/** Packet-thread-only replay state. */
|
||||
boolean onGround();
|
||||
TrackedEntity<?, ?> setOnGround(boolean onGround);
|
||||
|
||||
EntityType entityType();
|
||||
TrackedEntity<?> setOnGround(boolean onGround);
|
||||
|
||||
/** Packet-thread-only replay state. */
|
||||
int entityData();
|
||||
TrackedEntity<?, ?> setEntityData(int entityData);
|
||||
TrackedEntity<?> setEntityData(int entityData);
|
||||
|
||||
int[] passengerIDs();
|
||||
TrackedEntity<?, ?> setPassengerIDs(int[] passengerIDs);
|
||||
TrackedEntity<?> setPassengerIDs(int[] passengerIDs);
|
||||
|
||||
void setVehicleID(int vehicleID);
|
||||
int vehicleID();
|
||||
@@ -70,9 +79,9 @@ public interface TrackedEntity<EntityType, PacketReplayData> extends MutableFloa
|
||||
|
||||
/** Packet-thread-only cached packet state. */
|
||||
PacketReplayData packetReplayData();
|
||||
TrackedEntity<?, ?> setPacketReplayData(PacketReplayData packetReplayData);
|
||||
TrackedEntity<?> setPacketReplayData(PacketReplayData packetReplayData);
|
||||
|
||||
ImmutableSpatial getOffsetPosition();
|
||||
float getYOffset();
|
||||
|
||||
/**
|
||||
* For use when the player disconnects, clears all data.
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.tracked;
|
||||
|
||||
import games.cubi.locatables.api.ImmutableBlockSpatial;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
public interface Clearable {
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import java.lang.annotation.*; /**
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import it.unimi.dsi.fastutil.Hash;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
public class ThreadGuard {
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import ca.spottedleaf.concurrentutil.util.ConcurrentUtil;
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import ca.spottedleaf.concurrentutil.collection.MultiThreadedQueue;
|
||||
import ca.spottedleaf.concurrentutil.map.SWMRInt2ObjectHashTable;
|
||||
import games.cubi.locatables.api.BlockLocatable;
|
||||
import games.cubi.locatables.api.BlockSpatial;
|
||||
import games.cubi.logs.Logger;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockInfoResolver;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkOcclusionView;
|
||||
import games.cubi.raycastedantiesp.core.chunks.OccludingChunkData;
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedTileEntity;
|
||||
import games.cubi.raycastedantiesp.core.tracked.NettyTileEntity;
|
||||
@@ -40,7 +48,7 @@ public abstract class AbstractBlockView<R extends Clearable, T extends NettyTile
|
||||
* <p> Since direct access to this object outside {@link AbstractBlockView} is impossible, a marker head object is skipped, and head removal is handled separately.
|
||||
* **/
|
||||
private final SWMRInt2ObjectHashTable<NettyTileEntity<R>> knownTileEntitiesByColumnBucket = new SWMRInt2ObjectHashTable<>();
|
||||
private final MultiThreadedQueue<BlockViewTransition> transitions = new MultiThreadedQueue<>();
|
||||
private final PackedBlockTransitionQueue transitions = new PackedBlockTransitionQueue();
|
||||
private final IntSupplier worldEpochSupplier;
|
||||
private volatile UUID trackedWorld;
|
||||
// Bit 0 is enabled; higher bits are a generation. The generation prevents enabled -> disabled -> enabled ABA from
|
||||
@@ -59,6 +67,10 @@ public abstract class AbstractBlockView<R extends Clearable, T extends NettyTile
|
||||
|
||||
protected abstract T createTrackedTileEntity(BlockSpatial position, char blockID, boolean visible);
|
||||
|
||||
@Override
|
||||
public ChunkOcclusionView getChunkOcclusionView(int chunkX, int chunkY, int chunkZ) {
|
||||
return chunks.getSection(chunkX, chunkY, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockOccluding(int x, int y, int z) {
|
||||
@@ -135,15 +147,6 @@ public abstract class AbstractBlockView<R extends Clearable, T extends NettyTile
|
||||
return state == null || state.visible();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTileEntityVisibilityDecision(TrackedTileEntity<?> tileEntity, boolean visible, int currentTick, long modeToken, int expectedWorldEpoch) {
|
||||
if (!(tileEntity instanceof NettyTileEntity<?> nettyTileEntity)) {
|
||||
return;
|
||||
}
|
||||
@SuppressWarnings("unchecked") T typed = (T) nettyTileEntity;
|
||||
commitTileEntityVisibilityDecision(typed, typed.visible(), visible, currentTick, modeToken, expectedWorldEpoch);
|
||||
}
|
||||
|
||||
private void commitTileEntityVisibilityDecision(T tileEntity, boolean currentVisibility, boolean shouldBeVisible, int currentTick, long modeToken, int expectedWorldEpoch) {
|
||||
if (!isCurrentWorldEpoch(expectedWorldEpoch) || tileEntityCheckModeTokenAcquire() != modeToken) {
|
||||
return;
|
||||
@@ -155,12 +158,8 @@ public abstract class AbstractBlockView<R extends Clearable, T extends NettyTile
|
||||
tileEntity.setVisible(shouldBeVisible);
|
||||
tileEntity.setLastChecked(currentTick);
|
||||
if (visibilityChanged) {
|
||||
transitions.add(new BlockViewTransition(
|
||||
shouldBeVisible ? BlockViewTransition.Type.SHOW : BlockViewTransition.Type.HIDE,
|
||||
tileEntity,
|
||||
modeToken,
|
||||
expectedWorldEpoch
|
||||
));
|
||||
BlockViewTransition.Type type = shouldBeVisible ? BlockViewTransition.Type.SHOW : BlockViewTransition.Type.HIDE;
|
||||
transitions.add(type, tileEntity, modeToken, expectedWorldEpoch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +173,7 @@ public abstract class AbstractBlockView<R extends Clearable, T extends NettyTile
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTileEntityCheckMode(boolean enabled, int currentTick) {
|
||||
public void applyTileEntityCheckMode(boolean enabled, int currentTick, Consumer<TrackedTileEntity<?>> visibilityRepairConsumer) {
|
||||
long current = tileEntityCheckModeTokenAcquire();
|
||||
if (modeEnabled(current) == enabled) {
|
||||
return;
|
||||
@@ -188,12 +187,11 @@ public abstract class AbstractBlockView<R extends Clearable, T extends NettyTile
|
||||
}
|
||||
|
||||
TILE_ENTITY_CHECK_MODE_TOKEN.setRelease(this, next);
|
||||
int worldEpoch = worldEpochSupplier.getAsInt();
|
||||
forEachTileEntity(tileEntity -> {
|
||||
boolean visible = tileEntity.visible();
|
||||
if (!visible) {
|
||||
@SuppressWarnings("unchecked") T typed = (T) tileEntity;
|
||||
commitTileEntityVisibilityDecision(typed, false, true, currentTick, next, worldEpoch);
|
||||
if (!tileEntity.visible()) {
|
||||
tileEntity.setVisible(true);
|
||||
tileEntity.setLastChecked(currentTick);
|
||||
visibilityRepairConsumer.accept(tileEntity);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -257,17 +255,17 @@ public abstract class AbstractBlockView<R extends Clearable, T extends NettyTile
|
||||
|
||||
@Override
|
||||
public boolean hasPendingTransitions() {
|
||||
return !transitions.isEmpty();
|
||||
return transitions.hasPendingTransitions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockViewTransition> drainTransitions() {
|
||||
List<BlockViewTransition> drained = new ArrayList<>();
|
||||
BlockViewTransition transition;
|
||||
while ((transition = transitions.poll()) != null) {
|
||||
drained.add(transition);
|
||||
}
|
||||
return drained;
|
||||
public void flushPendingTransitions() {
|
||||
transitions.flushPendingTransitions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drainTransitions(BlockView.TransitionConsumer consumer) {
|
||||
transitions.drainTransitions(consumer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -374,7 +372,7 @@ public abstract class AbstractBlockView<R extends Clearable, T extends NettyTile
|
||||
chunks.clear();
|
||||
forEachTileEntity(NettyTileEntity::markRemoved);
|
||||
knownTileEntitiesByColumnBucket.clear();
|
||||
transitions.clear();
|
||||
transitions.clearPublishedTransitions();
|
||||
}
|
||||
|
||||
private void removeTileEntitiesInChunk(int chunkX, int chunkZ) {
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.locatables.api.BlockLocatable;
|
||||
import games.cubi.locatables.api.BlockSpatial;
|
||||
import games.cubi.locatables.api.SpatialChunkSection;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkOcclusionView;
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedTileEntity;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.OccludingChunkData;
|
||||
import games.cubi.raycastedantiesp.core.utils.Clearable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.IntSupplier;
|
||||
@@ -21,6 +29,15 @@ import java.util.function.IntSupplier;
|
||||
* decisions; visibility fields and the transition queue are safe for that Netty/engine overlap.</p>
|
||||
*/
|
||||
public interface BlockView extends Clearable {
|
||||
/**
|
||||
* Parameters are chunk coordinates
|
||||
*/
|
||||
ChunkOcclusionView getChunkOcclusionView(int chunkX, int chunkY, int chunkZ);
|
||||
|
||||
default ChunkOcclusionView getChunkOcclusionView(SpatialChunkSection chunkSection) {
|
||||
return getChunkOcclusionView(chunkSection.chunkX(), chunkSection.chunkY(), chunkSection.chunkZ());
|
||||
}
|
||||
|
||||
boolean isBlockOccluding(BlockLocatable location);
|
||||
|
||||
boolean isBlockOccluding(int x, int y, int z);
|
||||
@@ -40,9 +57,6 @@ public interface BlockView extends Clearable {
|
||||
|
||||
boolean isVisible(UUID world, BlockSpatial position, int currentTick);
|
||||
|
||||
/** Applies a checked visibility decision and queues any required client transition. */
|
||||
void applyTileEntityVisibilityDecision(TrackedTileEntity<?> tileEntity, boolean visible, int currentTick, long modeToken, int expectedWorldEpoch);
|
||||
|
||||
/**
|
||||
* Records visibility established by the current outbound packet without queuing another packet. This also resets
|
||||
* the check timestamp because the transmitted state supersedes the result of any previous visibility check. The
|
||||
@@ -50,8 +64,14 @@ public interface BlockView extends Clearable {
|
||||
*/
|
||||
void recordOutboundTileEntityVisibility(TrackedTileEntity<?> tileEntity, boolean visible);
|
||||
|
||||
/** Applies a mode change from the structural writer. */
|
||||
void applyTileEntityCheckMode(boolean enabled, int currentTick);
|
||||
/**
|
||||
* Applies a mode change from the structural writer.
|
||||
*
|
||||
* Invokes {@code visibilityRepairConsumer} for each tile entity made visible when checks are disabled. The
|
||||
* structural writer must send their current state directly rather than publishing them to the engine transition
|
||||
* queue.
|
||||
*/
|
||||
void applyTileEntityCheckMode(boolean enabled, int currentTick, Consumer<TrackedTileEntity<?>> visibilityRepairConsumer);
|
||||
|
||||
/** Returns an opaque enabled-state/generation snapshot for rejecting results that cross a mode change. */
|
||||
long tileEntityCheckModeToken();
|
||||
@@ -86,7 +106,15 @@ public interface BlockView extends Clearable {
|
||||
|
||||
boolean hasPendingTransitions();
|
||||
|
||||
List<BlockViewTransition> drainTransitions();
|
||||
/** Publishes the partial transition batch owned by the current engine producer. */
|
||||
void flushPendingTransitions();
|
||||
|
||||
@FunctionalInterface
|
||||
interface TransitionConsumer {
|
||||
void accept(BlockViewTransition.Type type, TrackedTileEntity<?> tileEntity, long modeToken, int worldEpoch);
|
||||
}
|
||||
|
||||
void drainTransitions(TransitionConsumer consumer);
|
||||
|
||||
/** Structural-writer operation. */
|
||||
void upsertBlock(UUID world, int x, int y, int z, int blockID);
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedTileEntity;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedEntity;
|
||||
@@ -6,12 +14,11 @@ import games.cubi.raycastedantiesp.core.tracked.NettyEntity;
|
||||
import games.cubi.raycastedantiesp.core.utils.Clearable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
public interface EntityView<T extends TrackedEntity<?, ?>> extends Clearable {
|
||||
public interface EntityView<T extends TrackedEntity<?>> extends Clearable {
|
||||
void insertEntity(UUID world, T entity);
|
||||
|
||||
void removeEntity(int entityID, int currentTick);
|
||||
@@ -32,6 +39,12 @@ public interface EntityView<T extends TrackedEntity<?, ?>> extends Clearable {
|
||||
|
||||
boolean exists(int entityID);
|
||||
|
||||
/**
|
||||
* Returns a weakly consistent count of the entities currently tracked by this view.
|
||||
* This operation is safe to call from threads other than the structural writer.
|
||||
*/
|
||||
int size();
|
||||
|
||||
@Deprecated
|
||||
boolean isVisible(UUID entityUUID, int currentTick);
|
||||
|
||||
@@ -39,7 +52,14 @@ public interface EntityView<T extends TrackedEntity<?, ?>> extends Clearable {
|
||||
|
||||
boolean isVisible(int entityID);
|
||||
|
||||
void setVisibility(NettyEntity<?,?> entity, boolean visible, int currentTick, int expectedWorldEpoch);
|
||||
void setVisibility(NettyEntity<?> entity, boolean visible, int currentTick, int expectedWorldEpoch);
|
||||
|
||||
/**
|
||||
* Applies visibility from the Netty structural writer without publishing an engine transition.
|
||||
*
|
||||
* @return whether the entity and epoch were current and the visibility was applied
|
||||
*/
|
||||
boolean recordDirectVisibility(NettyEntity<?> entity, boolean visible, int currentTick, int expectedWorldEpoch);
|
||||
|
||||
Collection<UUID> getKnownEntities();
|
||||
|
||||
@@ -50,18 +70,26 @@ public interface EntityView<T extends TrackedEntity<?, ?>> extends Clearable {
|
||||
*
|
||||
* @return number of entities passed to {@code action}.
|
||||
*/
|
||||
int forEachNeedingRecheck(int recheckTicks, int currentTick, Consumer<UUID> action);
|
||||
int forEachNeedingRecheck(int visibleRecheckTicks, int currentTick, Consumer<UUID> action);
|
||||
|
||||
/**
|
||||
* Iterates currently tracked entities that should be visibility-checked.
|
||||
*
|
||||
* @return number of entities passed to {@code action}, or 0 if {@code countingActuallyNeeded} is false.
|
||||
*/
|
||||
int forEachNeedingRecheckEntity(int recheckTicks, int currentTick, boolean countingActuallyNeeded, int expectedWorldEpoch, Consumer<NettyEntity<?,?>> action);
|
||||
int forEachNeedingRecheckEntity(int visibleRecheckTicks, int currentTick, boolean countingActuallyNeeded, int expectedWorldEpoch, Consumer<NettyEntity<?>> action);
|
||||
|
||||
boolean hasPendingTransitions();
|
||||
|
||||
List<EntityViewTransition> drainTransitions();
|
||||
/** Publishes the partial transition batch owned by the current engine producer. */
|
||||
void flushPendingTransitions();
|
||||
|
||||
@FunctionalInterface
|
||||
interface TransitionConsumer {
|
||||
void accept(EntityViewTransition.Type type, TrackedEntity<?> entity, int worldEpoch);
|
||||
}
|
||||
|
||||
void drainTransitions(TransitionConsumer consumer);
|
||||
|
||||
boolean isPlayerView();
|
||||
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedEntity;
|
||||
|
||||
// Used to cache visibility changes until the player's netty thread next processes
|
||||
public record EntityViewTransition(Type type, TrackedEntity<?, ?> entity, int worldEpoch) {
|
||||
public record EntityViewTransition(Type type, TrackedEntity<?> entity, int worldEpoch) {
|
||||
public enum Type {
|
||||
SHOW,
|
||||
HIDE,
|
||||
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.utils.Clearable;
|
||||
import games.cubi.utils.IntrusiveSPSCQueue;
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedTileEntity;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Queues tile-entity visibility transitions without allocating a record for every transition.
|
||||
*
|
||||
* <p>Exactly one engine thread at a time owns the pending batch and publishes it to the intrusive SPSC queue. The
|
||||
* producer role may migrate between engine threads, while the player's Netty thread exclusively drains published
|
||||
* entries. Producer and consumer methods must not be called from the opposite role.</p>
|
||||
*/
|
||||
public final class PackedBlockTransitionQueue {
|
||||
private static final int BATCH_MIN_SIZE = 3;
|
||||
private static final int BATCH_SIZE = 8;
|
||||
|
||||
private final IntrusiveSPSCQueue<QueueEntry> publishedEntries = new IntrusiveSPSCQueue<>();
|
||||
private final PendingBatch pending = new PendingBatch();
|
||||
|
||||
public void add(BlockViewTransition.Type type, TrackedTileEntity<?> tileEntity, long modeToken, int worldEpoch) {
|
||||
Objects.requireNonNull(type, "type");
|
||||
Objects.requireNonNull(tileEntity, "tileEntity");
|
||||
|
||||
if (pending.count != 0 && (pending.modeToken != modeToken || pending.worldEpoch != worldEpoch)) {
|
||||
flushPending();
|
||||
}
|
||||
if (pending.count == 0) {
|
||||
pending.modeToken = modeToken;
|
||||
pending.worldEpoch = worldEpoch;
|
||||
}
|
||||
pending.add(type, tileEntity);
|
||||
if (pending.count == BATCH_SIZE) {
|
||||
flushPending();
|
||||
}
|
||||
}
|
||||
|
||||
/** Publishes the producer-owned partial batch. Only the engine producer may call this method. */
|
||||
public void flushPendingTransitions() {
|
||||
flushPending();
|
||||
}
|
||||
|
||||
public boolean hasPendingTransitions() {
|
||||
return !publishedEntries.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Drains published entries in FIFO order. A claimed queue entry is consumed at most once if a callback throws while
|
||||
* processing it, and any unvisited transitions packed into that entry are discarded.
|
||||
*/
|
||||
public void drainTransitions(BlockView.TransitionConsumer consumer) {
|
||||
Objects.requireNonNull(consumer, "consumer");
|
||||
QueueEntry entry;
|
||||
while ((entry = publishedEntries.poll()) != null) {
|
||||
entry.drain(consumer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discards transitions already published to the consumer. The producer-owned pending batch is intentionally left
|
||||
* untouched: a structural clear can race an engine flush, and that in-flight batch must retain its old epoch and
|
||||
* mode token so the consumer can reject it normally after it is published.
|
||||
*/
|
||||
public void clearPublishedTransitions() {
|
||||
publishedEntries.clear();
|
||||
}
|
||||
|
||||
private void flushPending() {
|
||||
switch (pending.count) {
|
||||
case 0 -> {
|
||||
return;
|
||||
}
|
||||
case 1 -> publishedEntries.offer(new SingleEntry(pending.t1, pending.e1, pending.modeToken, pending.worldEpoch));
|
||||
case 2 -> {
|
||||
publishedEntries.offer(new SingleEntry(pending.t1, pending.e1, pending.modeToken, pending.worldEpoch));
|
||||
publishedEntries.offer(new SingleEntry(pending.t2, pending.e2, pending.modeToken, pending.worldEpoch));
|
||||
}
|
||||
case BATCH_MIN_SIZE, 4, 5, 6, 7, BATCH_SIZE -> publishedEntries.offer(new BatchEntry(pending));
|
||||
default -> throw new IllegalStateException("Tile transition batch exceeded eight entries");
|
||||
}
|
||||
pending.clear();
|
||||
}
|
||||
|
||||
private abstract static class QueueEntry extends IntrusiveSPSCQueue.Node {
|
||||
abstract void drain(BlockView.TransitionConsumer consumer);
|
||||
}
|
||||
|
||||
private static final class SingleEntry extends QueueEntry {
|
||||
private final BlockViewTransition.Type type;
|
||||
private final TrackedTileEntity<?> tileEntity;
|
||||
private final long modeToken;
|
||||
private final int worldEpoch;
|
||||
|
||||
private SingleEntry(BlockViewTransition.Type type, TrackedTileEntity<?> tileEntity, long modeToken, int worldEpoch) {
|
||||
this.type = type;
|
||||
this.tileEntity = tileEntity;
|
||||
this.modeToken = modeToken;
|
||||
this.worldEpoch = worldEpoch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drain(BlockView.TransitionConsumer consumer) {
|
||||
consumer.accept(type, tileEntity, modeToken, worldEpoch);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class PendingBatch implements Clearable {
|
||||
private BlockViewTransition.Type t1, t2, t3, t4, t5, t6, t7, t8;
|
||||
private TrackedTileEntity<?> e1, e2, e3, e4, e5, e6, e7, e8;
|
||||
private long modeToken;
|
||||
private int worldEpoch;
|
||||
private int count;
|
||||
|
||||
private void add(BlockViewTransition.Type type, TrackedTileEntity<?> tileEntity) {
|
||||
switch (++count) {
|
||||
case 1 -> { t1 = type; e1 = tileEntity; }
|
||||
case 2 -> { t2 = type; e2 = tileEntity; }
|
||||
case 3 -> { t3 = type; e3 = tileEntity; }
|
||||
case 4 -> { t4 = type; e4 = tileEntity; }
|
||||
case 5 -> { t5 = type; e5 = tileEntity; }
|
||||
case 6 -> { t6 = type; e6 = tileEntity; }
|
||||
case 7 -> { t7 = type; e7 = tileEntity; }
|
||||
case 8 -> { t8 = type; e8 = tileEntity; }
|
||||
default -> throw new IllegalStateException("Tile transition batch exceeded eight entries");
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
t1 = null;
|
||||
t2 = null;
|
||||
t3 = null;
|
||||
t4 = null;
|
||||
t5 = null;
|
||||
t6 = null;
|
||||
t7 = null;
|
||||
t8 = null;
|
||||
e1 = null;
|
||||
e2 = null;
|
||||
e3 = null;
|
||||
e4 = null;
|
||||
e5 = null;
|
||||
e6 = null;
|
||||
e7 = null;
|
||||
e8 = null;
|
||||
modeToken = 0L;
|
||||
worldEpoch = 0;
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class BatchEntry extends QueueEntry {
|
||||
private final BlockViewTransition.Type t1, t2, t3, t4, t5, t6, t7, t8;
|
||||
private final TrackedTileEntity<?> e1, e2, e3, e4, e5, e6, e7, e8;
|
||||
private final long modeToken;
|
||||
private final int worldEpoch;
|
||||
private final int count;
|
||||
|
||||
private BatchEntry(PendingBatch pending) {
|
||||
t1 = pending.t1;
|
||||
t2 = pending.t2;
|
||||
t3 = pending.t3;
|
||||
t4 = pending.t4;
|
||||
t5 = pending.t5;
|
||||
t6 = pending.t6;
|
||||
t7 = pending.t7;
|
||||
t8 = pending.t8;
|
||||
e1 = pending.e1;
|
||||
e2 = pending.e2;
|
||||
e3 = pending.e3;
|
||||
e4 = pending.e4;
|
||||
e5 = pending.e5;
|
||||
e6 = pending.e6;
|
||||
e7 = pending.e7;
|
||||
e8 = pending.e8;
|
||||
modeToken = pending.modeToken;
|
||||
worldEpoch = pending.worldEpoch;
|
||||
count = pending.count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drain(BlockView.TransitionConsumer consumer) {
|
||||
consumer.accept(t1, e1, modeToken, worldEpoch);
|
||||
if (count >= 2) consumer.accept(t2, e2, modeToken, worldEpoch);
|
||||
if (count >= 3) consumer.accept(t3, e3, modeToken, worldEpoch);
|
||||
if (count >= 4) consumer.accept(t4, e4, modeToken, worldEpoch);
|
||||
if (count >= 5) consumer.accept(t5, e5, modeToken, worldEpoch);
|
||||
if (count >= 6) consumer.accept(t6, e6, modeToken, worldEpoch);
|
||||
if (count >= 7) consumer.accept(t7, e7, modeToken, worldEpoch);
|
||||
if (count >= 8) consumer.accept(t8, e8, modeToken, worldEpoch);
|
||||
}
|
||||
}
|
||||
}
|
||||
+223
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.utils.Clearable;
|
||||
import games.cubi.utils.IntrusiveSPSCQueue;
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedEntity;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Queues entity visibility transitions without allocating a record for every transition.
|
||||
*
|
||||
* <p>Exactly one engine thread at a time owns the pending batch and publishes it to the intrusive SPSC queue. The
|
||||
* producer role may migrate between engine threads, while the player's Netty thread exclusively drains published
|
||||
* entries. Producer and consumer methods must not be called from the opposite role.</p>
|
||||
*/
|
||||
public final class PackedEntityTransitionQueue { //todo: potentially merge this with PackedBlockTransitionQueue, and add a mode token to entities
|
||||
private static final int BATCH_MIN_SIZE = 3;
|
||||
private static final int BATCH_SIZE = 8;
|
||||
|
||||
private final IntrusiveSPSCQueue<QueueEntry> publishedEntries = new IntrusiveSPSCQueue<>();
|
||||
private final PendingBatch pending = new PendingBatch();
|
||||
|
||||
public void add(EntityViewTransition.Type type, TrackedEntity<?> entity, int worldEpoch) {
|
||||
Objects.requireNonNull(type, "type");
|
||||
Objects.requireNonNull(entity, "entity");
|
||||
|
||||
if (pending.count != 0 && pending.worldEpoch != worldEpoch) {
|
||||
flushPending();
|
||||
}
|
||||
if (pending.count == 0) {
|
||||
pending.worldEpoch = worldEpoch;
|
||||
}
|
||||
pending.add(type, entity);
|
||||
if (pending.count == BATCH_SIZE) {
|
||||
flushPending();
|
||||
}
|
||||
}
|
||||
|
||||
/** Publishes the producer-owned partial batch. Only the engine producer may call this method. */
|
||||
public void flushPendingTransitions() {
|
||||
flushPending();
|
||||
}
|
||||
|
||||
public boolean hasPendingTransitions() {
|
||||
return !publishedEntries.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Drains published entries in FIFO order. A claimed queue entry is consumed at most once if a callback throws while
|
||||
* processing it, and any unvisited transitions packed into that entry are discarded.
|
||||
*/
|
||||
public void drainTransitions(EntityView.TransitionConsumer consumer) {
|
||||
Objects.requireNonNull(consumer, "consumer");
|
||||
QueueEntry entry;
|
||||
while ((entry = publishedEntries.poll()) != null) {
|
||||
entry.drain(consumer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discards transitions already published to the consumer. The producer-owned pending batch is intentionally left
|
||||
* untouched: a structural clear can race an engine flush, and that in-flight batch must retain its old epoch so
|
||||
* the consumer can reject it normally after it is published.
|
||||
*/
|
||||
public void clearPublishedTransitions() {
|
||||
publishedEntries.clear();
|
||||
}
|
||||
|
||||
private void flushPending() {
|
||||
switch (pending.count) {
|
||||
case 0 -> {
|
||||
return;
|
||||
}
|
||||
case 1 -> publishedEntries.offer(new SingleEntry(pending.t1, pending.e1, pending.worldEpoch));
|
||||
case 2 -> {
|
||||
publishedEntries.offer(new SingleEntry(pending.t1, pending.e1, pending.worldEpoch));
|
||||
publishedEntries.offer(new SingleEntry(pending.t2, pending.e2, pending.worldEpoch));
|
||||
}
|
||||
case BATCH_MIN_SIZE, 4, 5, 6, 7, BATCH_SIZE -> publishedEntries.offer(new BatchEntry(pending));
|
||||
default -> throw new IllegalStateException("Entity transition batch exceeded eight entries");
|
||||
}
|
||||
pending.clear();
|
||||
}
|
||||
|
||||
private abstract static class QueueEntry extends IntrusiveSPSCQueue.Node {
|
||||
abstract void drain(EntityView.TransitionConsumer consumer);
|
||||
}
|
||||
|
||||
private static final class SingleEntry extends QueueEntry {
|
||||
private final EntityViewTransition.Type type;
|
||||
private final TrackedEntity<?> entity;
|
||||
private final int worldEpoch;
|
||||
|
||||
private SingleEntry(EntityViewTransition.Type type, TrackedEntity<?> entity, int worldEpoch) {
|
||||
this.type = type;
|
||||
this.entity = entity;
|
||||
this.worldEpoch = worldEpoch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drain(EntityView.TransitionConsumer consumer) {
|
||||
consumer.accept(type, entity, worldEpoch);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class PendingBatch implements Clearable {
|
||||
private EntityViewTransition.Type t1;
|
||||
private EntityViewTransition.Type t2;
|
||||
private EntityViewTransition.Type t3;
|
||||
private EntityViewTransition.Type t4;
|
||||
private EntityViewTransition.Type t5;
|
||||
private EntityViewTransition.Type t6;
|
||||
private EntityViewTransition.Type t7;
|
||||
private EntityViewTransition.Type t8;
|
||||
private TrackedEntity<?> e1;
|
||||
private TrackedEntity<?> e2;
|
||||
private TrackedEntity<?> e3;
|
||||
private TrackedEntity<?> e4;
|
||||
private TrackedEntity<?> e5;
|
||||
private TrackedEntity<?> e6;
|
||||
private TrackedEntity<?> e7;
|
||||
private TrackedEntity<?> e8;
|
||||
private int worldEpoch;
|
||||
private int count;
|
||||
|
||||
private void add(EntityViewTransition.Type type, TrackedEntity<?> entity) {
|
||||
switch (++count) {
|
||||
case 1 -> { t1 = type; e1 = entity; }
|
||||
case 2 -> { t2 = type; e2 = entity; }
|
||||
case 3 -> { t3 = type; e3 = entity; }
|
||||
case 4 -> { t4 = type; e4 = entity; }
|
||||
case 5 -> { t5 = type; e5 = entity; }
|
||||
case 6 -> { t6 = type; e6 = entity; }
|
||||
case 7 -> { t7 = type; e7 = entity; }
|
||||
case 8 -> { t8 = type; e8 = entity; }
|
||||
default -> throw new IllegalStateException("Entity transition batch exceeded eight entries");
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
t1 = null;
|
||||
t2 = null;
|
||||
t3 = null;
|
||||
t4 = null;
|
||||
t5 = null;
|
||||
t6 = null;
|
||||
t7 = null;
|
||||
t8 = null;
|
||||
e1 = null;
|
||||
e2 = null;
|
||||
e3 = null;
|
||||
e4 = null;
|
||||
e5 = null;
|
||||
e6 = null;
|
||||
e7 = null;
|
||||
e8 = null;
|
||||
worldEpoch = 0;
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class BatchEntry extends QueueEntry {
|
||||
private final EntityViewTransition.Type t1;
|
||||
private final EntityViewTransition.Type t2;
|
||||
private final EntityViewTransition.Type t3;
|
||||
private final EntityViewTransition.Type t4;
|
||||
private final EntityViewTransition.Type t5;
|
||||
private final EntityViewTransition.Type t6;
|
||||
private final EntityViewTransition.Type t7;
|
||||
private final EntityViewTransition.Type t8;
|
||||
private final TrackedEntity<?> e1;
|
||||
private final TrackedEntity<?> e2;
|
||||
private final TrackedEntity<?> e3;
|
||||
private final TrackedEntity<?> e4;
|
||||
private final TrackedEntity<?> e5;
|
||||
private final TrackedEntity<?> e6;
|
||||
private final TrackedEntity<?> e7;
|
||||
private final TrackedEntity<?> e8;
|
||||
private final int worldEpoch;
|
||||
private final int count;
|
||||
|
||||
private BatchEntry(PendingBatch pending) {
|
||||
t1 = pending.t1;
|
||||
t2 = pending.t2;
|
||||
t3 = pending.t3;
|
||||
t4 = pending.t4;
|
||||
t5 = pending.t5;
|
||||
t6 = pending.t6;
|
||||
t7 = pending.t7;
|
||||
t8 = pending.t8;
|
||||
e1 = pending.e1;
|
||||
e2 = pending.e2;
|
||||
e3 = pending.e3;
|
||||
e4 = pending.e4;
|
||||
e5 = pending.e5;
|
||||
e6 = pending.e6;
|
||||
e7 = pending.e7;
|
||||
e8 = pending.e8;
|
||||
worldEpoch = pending.worldEpoch;
|
||||
count = pending.count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drain(EntityView.TransitionConsumer consumer) {
|
||||
consumer.accept(t1, e1, worldEpoch);
|
||||
if (count >= 2) consumer.accept(t2, e2, worldEpoch);
|
||||
if (count >= 3) consumer.accept(t3, e3, worldEpoch);
|
||||
if (count >= 4) consumer.accept(t4, e4, worldEpoch);
|
||||
if (count >= 5) consumer.accept(t5, e5, worldEpoch);
|
||||
if (count >= 6) consumer.accept(t6, e6, worldEpoch);
|
||||
if (count >= 7) consumer.accept(t7, e7, worldEpoch);
|
||||
if (count >= 8) consumer.accept(t8, e8, worldEpoch);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
|
||||
+15
@@ -1,9 +1,18 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view.chunks;
|
||||
|
||||
import ca.spottedleaf.concurrentutil.map.SWMRLong2ObjectHashTable;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockInfoResolver;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkOcclusionView;
|
||||
import games.cubi.raycastedantiesp.core.chunks.blocks.TwoBlockChunkData;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.view.chunks.ChunkSectionStore.packChunkCoords;
|
||||
@@ -16,6 +25,12 @@ public final class BlockChunkSectionStore extends SWMRLong2ObjectHashTable<Block
|
||||
this.blockInfoResolver = blockInfoResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkOcclusionView getSection(int chunkX, int chunkY, int chunkZ) {
|
||||
long key = packChunkCoords(chunkX, chunkY, chunkZ);
|
||||
return get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOccluding(int x, int y, int z) {
|
||||
long key = packGlobalCoords(x, y, z);
|
||||
|
||||
+14
@@ -1,9 +1,23 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view.chunks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkOcclusionView;
|
||||
import games.cubi.raycastedantiesp.core.chunks.OccludingChunkData;
|
||||
|
||||
public interface ChunkSectionStore {
|
||||
/**
|
||||
* Coordinates are chunk coordinates
|
||||
*/
|
||||
ChunkOcclusionView getSection(int chunkX, int chunkY, int chunkZ);
|
||||
|
||||
boolean isOccluding(int x, int y, int z);
|
||||
|
||||
void setBlockID(int x, int y, int z, int blockID);
|
||||
|
||||
+15
-4
@@ -1,10 +1,15 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view.chunks;
|
||||
|
||||
import ca.spottedleaf.concurrentutil.map.SWMRLong2ObjectHashTable;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockInfoResolver;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.OccludingChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.*;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.view.chunks.ChunkSectionStore.packChunkCoords;
|
||||
import static games.cubi.raycastedantiesp.core.view.chunks.ChunkSectionStore.packGlobalCoords;
|
||||
@@ -16,6 +21,12 @@ public final class OccludingChunkSectionStore extends SWMRLong2ObjectHashTable<O
|
||||
this.blockInfoResolver = blockInfoResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkOcclusionView getSection(int chunkX, int chunkY, int chunkZ) {
|
||||
long key = packChunkCoords(chunkX, chunkY, chunkZ);
|
||||
return get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOccluding(int x, int y, int z) {
|
||||
long key = packGlobalCoords(x, y, z);
|
||||
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
package games.cubi.raycastedantiesp.core.view.controller;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
import games.cubi.raycastedantiesp.core.tracked.NettyEntity;
|
||||
import games.cubi.raycastedantiesp.core.players.PlayerData;
|
||||
import games.cubi.raycastedantiesp.core.utils.BaseEntitySpawnTask;
|
||||
|
||||
final class LeashReconciliationTask extends BaseEntitySpawnTask {
|
||||
private final PlayerData playerData;
|
||||
private final int leashedEntityID;
|
||||
private final int leashingEntityID;
|
||||
|
||||
LeashReconciliationTask(PlayerData playerData, int leashedEntityID, int leashingEntityID, int submittedTick) {
|
||||
super(submittedTick);
|
||||
this.playerData = playerData;
|
||||
this.leashedEntityID = leashedEntityID;
|
||||
this.leashingEntityID = leashingEntityID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
NettyEntity<?,?> leashed = playerData.entityFromID(leashedEntityID);
|
||||
if (leashed == null) {
|
||||
Logger.error("Reconciliation fail: Attempted to reconcile leash for unknown leashed entity, leashedEntityId=" + leashedEntityID, 3, this.getClass());
|
||||
return;
|
||||
}
|
||||
PacketEntityViewController.get().handleLeashEntityNow(leashed, leashingEntityID, playerData, submittedTick); //submittedTick isn't the right tick to use here, but it's for a rare error case and as long as the tick is in the past it should be fine.
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LeashReconciliationTask{" +
|
||||
"submittedTick=" + submittedTick +
|
||||
", leashedEntityId=" + leashedEntityID +
|
||||
", leashingEntityId=" + leashingEntityID +
|
||||
", playerUUID=" + playerData.getPlayerUUID() +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
+248
-98
@@ -13,6 +13,7 @@ import games.cubi.logs.Logger;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.EntityConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.PlayerConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.RaycastConfig;
|
||||
import games.cubi.raycastedantiesp.core.entity.EntityBypassRegistry;
|
||||
import games.cubi.raycastedantiesp.core.tracked.NettyEntity;
|
||||
import games.cubi.raycastedantiesp.core.players.NettyData;
|
||||
import games.cubi.raycastedantiesp.core.players.PlayerData;
|
||||
@@ -93,7 +94,10 @@ public abstract class PacketEntityViewController<P> {
|
||||
return PlayerRegistry.getInstance().registerAndGetPlayer(playerUUID, currentTick, entityID, this::createSelfEntity);
|
||||
}
|
||||
|
||||
protected abstract NettyEntity<?,?> createSelfEntity(PlayerData ownData, int entityID, UUID playerUUID);
|
||||
protected abstract NettyEntity<?> createSelfEntity(PlayerData ownData, int entityID, UUID playerUUID);
|
||||
|
||||
/** Applies a SHOW transition immediately on the Netty thread without publishing it to the engine SPSC queue. */
|
||||
protected abstract void processDirectEntityShow(PlayerData playerData, EntityView<?> view, NettyEntity<?> entity, int worldEpoch);
|
||||
|
||||
protected void handlePlayerDisconnect(UUID player) {
|
||||
if (player == null) {
|
||||
@@ -117,7 +121,7 @@ public abstract class PacketEntityViewController<P> {
|
||||
return false;
|
||||
}
|
||||
|
||||
NettyEntity<?,?> entity = Logger.requireNonNull(processEntitySpawn(playerData, packet, world, currentTick), "processEntitySpawn returned null", 3, PacketEntityViewController.class);
|
||||
NettyEntity<?> entity = Logger.requireNonNull(processEntitySpawn(playerData, packet, world, currentTick), "processEntitySpawn returned null", 3, PacketEntityViewController.class);
|
||||
|
||||
if ((!isPlayer && entityConfig.enabled()) || isPlayer && playerConfig.enabled()) {
|
||||
Locatable ownLocation = playerData.ownLocation();
|
||||
@@ -205,6 +209,10 @@ public abstract class PacketEntityViewController<P> {
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
protected boolean handleEntityMetadata(P packet, int entityID, PlayerData playerData, int currentTick) {
|
||||
NettyEntity<?> entity = playerData.entityFromID(entityID);
|
||||
if (entity != null) {
|
||||
processTrackedMetadata(packet, entity);
|
||||
}
|
||||
cachePacket(packet, entityID, playerData, currentTick);
|
||||
return cancelIfEnabledAndHidden(entityID, playerData);
|
||||
}
|
||||
@@ -243,7 +251,8 @@ public abstract class PacketEntityViewController<P> {
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
protected boolean handleEntityPassengers(int entityID, int[] passengers, PlayerData playerData, int currentTick) {
|
||||
NettyEntity<?,?> vehicle = playerData.entityFromID(entityID);
|
||||
boolean bypassedVehicle = EntityBypassRegistry.isBypassed(entityID);
|
||||
NettyEntity<?> vehicle = bypassedVehicle ? null : playerData.entityFromID(entityID);
|
||||
int[] previousPassengers = getPreviousPassengerState(entityID, vehicle, playerData);
|
||||
playerData.nettyData().consumeUnresolvedPassengers(entityID); // throw away any unresolved passengers as this new packet will have the correct passenger list
|
||||
// "Stale" passengers are passengers that the previous authoritative state said were mounted,
|
||||
@@ -251,19 +260,29 @@ public abstract class PacketEntityViewController<P> {
|
||||
clearStalePassengerReferences(entityID, previousPassengers, passengers, playerData);
|
||||
if (vehicle == null) {
|
||||
playerData.nettyData().setUnresolvedPassengers(entityID, passengers);
|
||||
if (bypassedVehicle) {
|
||||
for (int passengerID : passengers) {
|
||||
NettyEntity<?> passenger = playerData.entityFromID(passengerID);
|
||||
if (passenger == null) {
|
||||
continue;
|
||||
}
|
||||
passenger.setVehicleID(entityID);
|
||||
forceVisibleBecauseAttached(passenger, playerData, currentTick, "bypassed vehicle passenger");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return handleEntityPassengersNow(vehicle, passengers, playerData, currentTick);
|
||||
}
|
||||
|
||||
//This (and leash handling) leaks some info to the client, as it will receive the passenger packet even if the passengers are auto-hidden once parsed, but as the packet doesn't include any location or type info, this shouldn't be too incriminating.
|
||||
boolean handleEntityPassengersNow(NettyEntity<?,?> entity, int[] passengers, PlayerData playerData, int currentTick) {
|
||||
boolean handleEntityPassengersNow(NettyEntity<?> entity, int[] passengers, PlayerData playerData, int currentTick) {
|
||||
int entityID = entity.entityID();
|
||||
entity.setPassengerIDs(passengers);
|
||||
int[] unresolvedPassengers = null;
|
||||
boolean selfIsPassenger = false;
|
||||
for (int passengerID : passengers) {
|
||||
NettyEntity<?,?> passenger = playerData.entityFromID(passengerID);
|
||||
NettyEntity<?> passenger = playerData.entityFromID(passengerID);
|
||||
if (passenger == null) {
|
||||
unresolvedPassengers = PrimitiveIntArrayList.add(unresolvedPassengers, passengerID);
|
||||
continue;
|
||||
@@ -275,7 +294,7 @@ public abstract class PacketEntityViewController<P> {
|
||||
}
|
||||
playerData.nettyData().setUnresolvedPassengers(entityID, unresolvedPassengers);
|
||||
checkVehicle(entity, playerData);
|
||||
boolean cancelForForcedVehicleShow = selfIsPassenger && forceVisibleBecauseAttachedToSelf(entity, playerData, currentTick, "self-passenger vehicle");
|
||||
boolean cancelForForcedVehicleShow = selfIsPassenger && forceVisibleBecauseAttached(entity, playerData, currentTick, "self-passenger vehicle");
|
||||
if (cancelForForcedVehicleShow) {
|
||||
return true;
|
||||
}
|
||||
@@ -283,21 +302,29 @@ public abstract class PacketEntityViewController<P> {
|
||||
boolean passengersNotVisible = false;
|
||||
IntArrayList visiblePassengers = new IntArrayList(passengers.length);
|
||||
for (int passengerID : passengers) {
|
||||
NettyEntity<?,?> passenger = playerData.entityFromID(passengerID);
|
||||
if (passenger == null) {
|
||||
if (EntityBypassRegistry.isBypassed(passengerID)) {
|
||||
visiblePassengers.add(passengerID);
|
||||
}
|
||||
else if (entity.isSelfEntity() && forceVisibleBecauseAttachedToSelf(passenger, playerData, currentTick, "self-vehicle passenger")) {
|
||||
passengersNotVisible = true;
|
||||
}
|
||||
else if (entity.isSelfEntity() || passenger.isSelfEntity()) {
|
||||
visiblePassengers.add(passengerID);
|
||||
}
|
||||
else if (cancelIfEnabledAndHidden(passenger, playerData)) {
|
||||
passengersNotVisible = true;
|
||||
}
|
||||
else {
|
||||
visiblePassengers.add(passengerID);
|
||||
NettyEntity<?> passenger = playerData.entityFromID(passengerID);
|
||||
if (passenger == null) {
|
||||
visiblePassengers.add(passengerID);
|
||||
}
|
||||
else if (entity.isSelfEntity() && forceVisibleBecauseAttached(passenger, playerData, currentTick, "self-vehicle passenger")) {
|
||||
passengersNotVisible = true;
|
||||
// The direct SHOW path already makes this passenger client-visible. Keep it in the
|
||||
// replacement relationship packet so the packet does not undo the newly established mount.
|
||||
visiblePassengers.add(passengerID);
|
||||
}
|
||||
else if (entity.isSelfEntity() || passenger.isSelfEntity()) {
|
||||
visiblePassengers.add(passengerID);
|
||||
}
|
||||
else if (cancelIfEnabledAndHidden(passenger, playerData)) {
|
||||
passengersNotVisible = true;
|
||||
}
|
||||
else {
|
||||
visiblePassengers.add(passengerID);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (passengersNotVisible) {
|
||||
@@ -307,7 +334,7 @@ public abstract class PacketEntityViewController<P> {
|
||||
return passengersNotVisible;
|
||||
}
|
||||
|
||||
private int[] getPreviousPassengerState(int vehicleID, NettyEntity<?,?> vehicle, PlayerData playerData) {
|
||||
private int[] getPreviousPassengerState(int vehicleID, NettyEntity<?> vehicle, PlayerData playerData) {
|
||||
if (vehicle != null) {
|
||||
int[] previousPassengerIDs = vehicle.passengerIDs();
|
||||
if (!PrimitiveIntArrayList.isEmpty(previousPassengerIDs)) {
|
||||
@@ -329,19 +356,19 @@ public abstract class PacketEntityViewController<P> {
|
||||
if (PrimitiveIntArrayList.contains(newPassengers, previousPassengerID)) {
|
||||
continue;
|
||||
}
|
||||
NettyEntity<?,?> previousPassenger = playerData.entityFromID(previousPassengerID);
|
||||
NettyEntity<?> previousPassenger = playerData.entityFromID(previousPassengerID);
|
||||
if (previousPassenger != null && previousPassenger.vehicleID() == vehicleID) {
|
||||
previousPassenger.setVehicleID(NO_VEHICLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkVehicle(NettyEntity<?,?> entity, PlayerData playerData) {
|
||||
private void checkVehicle(NettyEntity<?> entity, PlayerData playerData) {
|
||||
int vehicleID = entity.vehicleID();
|
||||
if (vehicleID < 0) {
|
||||
if (vehicleID == NO_VEHICLE) {
|
||||
return;
|
||||
}
|
||||
NettyEntity<?,?> vehicle = playerData.entityFromID(vehicleID);
|
||||
NettyEntity<?> vehicle = playerData.entityFromID(vehicleID);
|
||||
if (vehicle == null) {
|
||||
return;
|
||||
}
|
||||
@@ -357,8 +384,7 @@ public abstract class PacketEntityViewController<P> {
|
||||
continue;
|
||||
}
|
||||
clearPassengerReferencesForDestroyedEntity(entityID, playerData);
|
||||
clearPendingHolderReference(entityID, playerData);
|
||||
playerData.nettyData().removeUnresolvedLeashedEntityFromAll(entityID);
|
||||
clearLeashReferencesForDestroyedEntity(entityID, playerData);
|
||||
playerData.nettyData().clearPendingPostSpawnTasksForEntity(entityID);
|
||||
EntityView<?> view = playerData.viewFromEntityID(entityID);
|
||||
if (view == null) continue;
|
||||
@@ -382,7 +408,7 @@ public abstract class PacketEntityViewController<P> {
|
||||
int[] unresolvedPassengers = playerData.nettyData().consumeUnresolvedPassengers(entityID);
|
||||
if (!PrimitiveIntArrayList.isEmpty(unresolvedPassengers)) {
|
||||
for (int passengerID : unresolvedPassengers) {
|
||||
NettyEntity<?,?> passenger = playerData.entityFromID(passengerID);
|
||||
NettyEntity<?> passenger = playerData.entityFromID(passengerID);
|
||||
if (passenger != null && passenger.vehicleID() == entityID) {
|
||||
passenger.setVehicleID(NO_VEHICLE);
|
||||
}
|
||||
@@ -391,14 +417,14 @@ public abstract class PacketEntityViewController<P> {
|
||||
|
||||
int unresolvedVehicleID = playerData.nettyData().consumeUnresolvedVehicleForPassenger(entityID);
|
||||
if (unresolvedVehicleID != NO_VEHICLE) {
|
||||
NettyEntity<?,?> unresolvedVehicle = playerData.entityFromID(unresolvedVehicleID);
|
||||
NettyEntity<?> unresolvedVehicle = playerData.entityFromID(unresolvedVehicleID);
|
||||
if (unresolvedVehicle != null) {
|
||||
// this can occur if the vehicle existed at the time of the passenger packet but not the passenger, and somehow the passenger never got resolved to the vehicle (missing spawn packets etc). In reality this should never happen.
|
||||
unresolvedVehicle.setPassengerIDs(PrimitiveIntArrayList.remove(unresolvedVehicle.passengerIDs(), entityID));
|
||||
}
|
||||
}
|
||||
|
||||
NettyEntity<?,?> entity = playerData.entityFromID(entityID);
|
||||
NettyEntity<?> entity = playerData.entityFromID(entityID);
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
@@ -406,7 +432,7 @@ public abstract class PacketEntityViewController<P> {
|
||||
int[] currentPassengerIDs = entity.passengerIDs();
|
||||
if (!PrimitiveIntArrayList.isEmpty(currentPassengerIDs)) {
|
||||
for (int passengerID : currentPassengerIDs) {
|
||||
NettyEntity<?,?> passenger = playerData.entityFromID(passengerID);
|
||||
NettyEntity<?> passenger = playerData.entityFromID(passengerID);
|
||||
if (passenger != null && passenger.vehicleID() == entityID) {
|
||||
passenger.setVehicleID(NO_VEHICLE);
|
||||
}
|
||||
@@ -417,24 +443,61 @@ public abstract class PacketEntityViewController<P> {
|
||||
if (vehicleID == NO_VEHICLE) {
|
||||
return;
|
||||
}
|
||||
NettyEntity<?,?> vehicle = playerData.entityFromID(vehicleID);
|
||||
NettyEntity<?> vehicle = playerData.entityFromID(vehicleID);
|
||||
if (vehicle != null) {
|
||||
vehicle.setPassengerIDs(PrimitiveIntArrayList.remove(vehicle.passengerIDs(), entityID));
|
||||
}
|
||||
entity.setVehicleID(NO_VEHICLE);
|
||||
}
|
||||
|
||||
private void clearPendingHolderReference(int holderEntityID, PlayerData playerData) {
|
||||
int[] pendingLeashedEntityIDs = playerData.nettyData().consumeUnresolvedLeashes(holderEntityID);
|
||||
if (PrimitiveIntArrayList.isEmpty(pendingLeashedEntityIDs)) {
|
||||
/**
|
||||
* Clears both sides of resolved and unresolved leash relationships so a reused entity ID
|
||||
* cannot inherit relationships belonging to the destroyed entity.
|
||||
*/
|
||||
private void clearLeashReferencesForDestroyedEntity(int entityID, PlayerData playerData) {
|
||||
// Deferred relationships are indexed by both endpoints, so clear the cases where this ID
|
||||
// was the holder and where it was the leashed entity.
|
||||
int[] pendingLeashedEntityIDs = playerData.nettyData().consumeUnresolvedLeashes(entityID);
|
||||
if (!PrimitiveIntArrayList.isEmpty(pendingLeashedEntityIDs)) {
|
||||
for (int leashedEntityID : pendingLeashedEntityIDs) {
|
||||
NettyEntity<?> leashedEntity = playerData.entityFromID(leashedEntityID);
|
||||
if (leashedEntity != null && leashedEntity.leashingEntity() == entityID) {
|
||||
leashedEntity.setLeashingEntity(NO_LEASHER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int pendingHolderEntityID = playerData.nettyData().consumeUnresolvedHolderForLeashedEntity(entityID);
|
||||
if (pendingHolderEntityID != NO_LEASHER) {
|
||||
NettyEntity<?> pendingHolder = playerData.entityFromID(pendingHolderEntityID);
|
||||
if (pendingHolder != null) {
|
||||
pendingHolder.removeLeashedEntity(entityID);
|
||||
}
|
||||
}
|
||||
|
||||
NettyEntity<?> entity = playerData.entityFromID(entityID);
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
for (int leashedEntityID : pendingLeashedEntityIDs) {
|
||||
NettyEntity<?,?> leashedEntity = playerData.entityFromID(leashedEntityID);
|
||||
if (leashedEntity != null && leashedEntity.leashingEntity() == holderEntityID) {
|
||||
leashedEntity.setLeashingEntity(NO_LEASHER);
|
||||
|
||||
// A tracked entity owns the same two relationship directions in its resolved state.
|
||||
int[] currentLeashedEntityIDs = entity.leashedEntityIDsOrNull();
|
||||
if (!PrimitiveIntArrayList.isEmpty(currentLeashedEntityIDs)) {
|
||||
for (int leashedEntityID : currentLeashedEntityIDs) {
|
||||
NettyEntity<?> leashedEntity = playerData.entityFromID(leashedEntityID);
|
||||
if (leashedEntity != null && leashedEntity.leashingEntity() == entityID) {
|
||||
leashedEntity.setLeashingEntity(NO_LEASHER);
|
||||
}
|
||||
}
|
||||
}
|
||||
int holderEntityID = entity.leashingEntity();
|
||||
if (holderEntityID != NO_LEASHER) {
|
||||
NettyEntity<?> holder = playerData.entityFromID(holderEntityID);
|
||||
if (holder != null) {
|
||||
holder.removeLeashedEntity(entityID);
|
||||
}
|
||||
entity.setLeashingEntity(NO_LEASHER);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -449,74 +512,73 @@ public abstract class PacketEntityViewController<P> {
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
@Packet(Packet.Packets.LEASH_ENTITY)
|
||||
protected boolean handleLeashEntity(int leashedEntity, int leashingEntity, PlayerData playerData, int currentTick) {
|
||||
if (playerData.nettyData().isSelfEntityID(leashedEntity) && playerData.nettyData().isSelfEntityID(leashingEntity)) {
|
||||
protected boolean handleLeashEntity(int leashedEntityID, int holderEntityID, PlayerData playerData, int currentTick) {
|
||||
if (playerData.nettyData().isSelfEntityID(leashedEntityID) && playerData.nettyData().isSelfEntityID(holderEntityID)) {
|
||||
return false;
|
||||
}
|
||||
NettyEntity<?,?> leashed = playerData.entityFromID(leashedEntity);
|
||||
if (leashed == null) {
|
||||
playerData.nettyData().addPostEntitySpawnTask(leashedEntity, new LeashReconciliationTask(playerData, leashedEntity, leashingEntity, currentTick));
|
||||
return false;
|
||||
NettyEntity<?> leashedEntity = playerData.entityFromID(leashedEntityID);
|
||||
removeExistingLeashReference(leashedEntityID, leashedEntity, playerData);
|
||||
|
||||
if (holderEntityID == NO_LEASHER) {
|
||||
return leashedEntity != null && cancelIfEnabledAndHidden(leashedEntity, playerData);
|
||||
}
|
||||
return handleLeashEntityNow(leashed, leashingEntity, playerData, currentTick);
|
||||
|
||||
NettyEntity<?> holderEntity = playerData.entityFromID(holderEntityID);
|
||||
if (leashedEntity != null) {
|
||||
leashedEntity.setLeashingEntity(holderEntityID);
|
||||
}
|
||||
if (holderEntity != null) {
|
||||
holderEntity.addLeashedEntity(leashedEntityID);
|
||||
}
|
||||
if (leashedEntity == null || holderEntity == null) {
|
||||
playerData.nettyData().addUnresolvedLeash(holderEntityID, leashedEntityID);
|
||||
}
|
||||
|
||||
if (holderEntity != null && holderEntity.isSelfEntity() && leashedEntity != null
|
||||
&& forceVisibleBecauseAttached(leashedEntity, playerData, currentTick, "self-held leash")) {
|
||||
return true; // The visibility update repairs leash state, so suppress the packet to avoid sending it twice and before the client is aware of the entity.
|
||||
}
|
||||
return leashedEntity != null && cancelIfEnabledAndHidden(leashedEntity, playerData)
|
||||
|| holderEntity != null && cancelIfEnabledAndHidden(holderEntity, playerData);
|
||||
}
|
||||
|
||||
boolean handleLeashEntityNow(NettyEntity<?,?> leashedEntity, int leashingEntity, PlayerData playerData, int currentTick) {
|
||||
//Note, leashing entity ID will be -1 to unleash. From testing it sometimes seems to be 0?
|
||||
removeExistingLeashReference(leashedEntity.entityID(), leashedEntity, playerData);
|
||||
if (leashingEntity == -1 || leashingEntity == 0) {
|
||||
if (leashedEntity.leashingEntity() == NO_LEASHER) {
|
||||
Logger.warning("Entity was already unleashing when handling leash entity packet, leashedEntityID=" + leashedEntity + " for player: " + playerData.getPlayerUUID(), 4, PacketEntityViewController.class);
|
||||
return false;
|
||||
}
|
||||
leashedEntity.setLeashingEntity(NO_LEASHER);
|
||||
return cancelIfEnabledAndHidden(leashedEntity, playerData);
|
||||
}
|
||||
else {
|
||||
leashedEntity.setLeashingEntity(leashingEntity);
|
||||
NettyEntity<?,?> leashing = playerData.entityFromID(leashingEntity);
|
||||
if (leashing == null) {
|
||||
playerData.nettyData().addUnresolvedLeash(leashingEntity, leashedEntity.entityID());
|
||||
return cancelIfEnabledAndHidden(leashedEntity, playerData);
|
||||
}
|
||||
else {
|
||||
leashing.addLeashedEntity(leashedEntity.entityID());
|
||||
if (leashing.isSelfEntity()) {
|
||||
return forceVisibleBecauseAttachedToSelf(leashedEntity, playerData, currentTick, "self-held leash"); // This schedules a visibility update, which repairs leash state, so suppressing the packet avoids sending it twice (and before the client is aware of the entity)
|
||||
}
|
||||
return cancelIfEnabledAndHidden(leashedEntity, playerData) || cancelIfEnabledAndHidden(leashingEntity, playerData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean forceVisibleBecauseAttachedToSelf(NettyEntity<?,?> entity, PlayerData self, int currentTick, String reason) {
|
||||
private boolean forceVisibleBecauseAttached(NettyEntity<?> entity, PlayerData self, int currentTick, String reason) {
|
||||
if (entity.isSelfEntity()) {
|
||||
return false;
|
||||
}
|
||||
boolean wasClientVisible = entity.clientVisible();
|
||||
EntityView<?> view = self.viewFromEntityID(entity.entityID());
|
||||
if (view == null) {
|
||||
Logger.warning("Could not find owning view while forcing self-attached entity visible, id=" + entity.entityID() + " player=" + self.getPlayerUUID() + " reason=" + reason, 4, PacketEntityViewController.class);
|
||||
Logger.warning("Could not find owning view while forcing attached entity visible, id=" + entity.entityID() + " player=" + self.getPlayerUUID() + " reason=" + reason, 6, PacketEntityViewController.class);
|
||||
// Note that this path can fire when a vehicle is bypassed, so its log level must be higher than default.
|
||||
return false;
|
||||
}
|
||||
view.setVisibility(entity, true, currentTick, self.acquireWorldEpoch());
|
||||
boolean wasVisible = entity.visible();
|
||||
int worldEpoch = self.acquireWorldEpoch();
|
||||
if (!view.recordDirectVisibility(entity, true, currentTick, worldEpoch)) {
|
||||
return false;
|
||||
}
|
||||
if (!wasVisible || !wasClientVisible) {
|
||||
processDirectEntityShow(self, view, entity, worldEpoch);
|
||||
}
|
||||
return !wasClientVisible;
|
||||
}
|
||||
|
||||
private void removeExistingLeashReference(int leashedEntityID, NettyEntity<?,?> leashed, PlayerData playerData) {
|
||||
int previousLeashingEntityID = leashed.leashingEntity();
|
||||
private void removeExistingLeashReference(int leashedEntityID, NettyEntity<?> leashedEntity, PlayerData playerData) {
|
||||
int previousLeashingEntityID = leashedEntity == null
|
||||
? playerData.nettyData().getUnresolvedHolderForLeashedEntity(leashedEntityID)
|
||||
: leashedEntity.leashingEntity();
|
||||
if (previousLeashingEntityID == NO_LEASHER) {
|
||||
return;
|
||||
}
|
||||
if (playerData.nettyData().removeUnresolvedLeash(previousLeashingEntityID, leashedEntityID)) {
|
||||
return;
|
||||
playerData.nettyData().removeUnresolvedLeash(previousLeashingEntityID, leashedEntityID);
|
||||
NettyEntity<?> previousHolder = playerData.entityFromID(previousLeashingEntityID);
|
||||
if (previousHolder != null) {
|
||||
previousHolder.removeLeashedEntity(leashedEntityID);
|
||||
}
|
||||
NettyEntity<?,?> previouslyLeashing = playerData.entityFromID(previousLeashingEntityID);
|
||||
if (previouslyLeashing == null) {
|
||||
Logger.warning("Found null previously leashing entity when handling leash entity packet, previouslyLeashingEntityID=" + previousLeashingEntityID + " for player: " + playerData.getPlayerUUID(), 5, PacketEntityViewController.class);
|
||||
return;
|
||||
if (leashedEntity != null) {
|
||||
leashedEntity.setLeashingEntity(NO_LEASHER);
|
||||
}
|
||||
previouslyLeashing.removeLeashedEntity(leashedEntityID);
|
||||
}
|
||||
|
||||
protected RaycastConfig getCorrectConfig(EntityView<?> entityView) {
|
||||
@@ -551,7 +613,7 @@ public abstract class PacketEntityViewController<P> {
|
||||
/**
|
||||
* @return True if the packet should be suppressed
|
||||
*/
|
||||
protected boolean cancelIfEnabledAndHidden(NettyEntity<?,?> entity, PlayerData playerData) {
|
||||
protected boolean cancelIfEnabledAndHidden(NettyEntity<?> entity, PlayerData playerData) {
|
||||
if (entity.isSelfEntity()) {
|
||||
return false;
|
||||
}
|
||||
@@ -567,31 +629,113 @@ public abstract class PacketEntityViewController<P> {
|
||||
* 1. this entity is the vehicle and one or more passengers were missing, or
|
||||
* 2. this entity is the passenger and the vehicle was already known.
|
||||
*/
|
||||
protected void reconcileUnresolvedPassengers(NettyEntity<?,?> insertedEntity, PlayerData playerData) {
|
||||
protected void reconcileUnresolvedPassengers(NettyEntity<?> insertedEntity, PlayerData playerData) {
|
||||
int[] pendingPassengers = playerData.nettyData().getUnresolvedPassengers(insertedEntity.entityID());
|
||||
if (!PrimitiveIntArrayList.isEmpty(pendingPassengers)) {
|
||||
playerData.nettyData().consumeUnresolvedPassengers(insertedEntity.entityID());
|
||||
handleEntityPassengersNow(insertedEntity, pendingPassengers, playerData, insertedEntity.lastChecked());
|
||||
resendPassengerStateIfClientVisible(insertedEntity, playerData);
|
||||
}
|
||||
|
||||
int unresolvedVehicleID = playerData.nettyData().getUnresolvedVehicleForPassenger(insertedEntity.entityID());
|
||||
if (unresolvedVehicleID == NO_VEHICLE) {
|
||||
return;
|
||||
}
|
||||
NettyEntity<?,?> vehicle = playerData.entityFromID(unresolvedVehicleID);
|
||||
if (EntityBypassRegistry.isBypassed(unresolvedVehicleID)) {
|
||||
insertedEntity.setVehicleID(unresolvedVehicleID);
|
||||
forceVisibleBecauseAttached(insertedEntity, playerData, insertedEntity.lastChecked(), "bypassed vehicle unresolved passenger");
|
||||
return;
|
||||
}
|
||||
NettyEntity<?> vehicle = playerData.entityFromID(unresolvedVehicleID);
|
||||
if (vehicle == null) {
|
||||
return;
|
||||
}
|
||||
insertedEntity.setVehicleID(unresolvedVehicleID);
|
||||
playerData.nettyData().removeUnresolvedPassengerLink(insertedEntity.entityID(), unresolvedVehicleID);
|
||||
if (vehicle.isSelfEntity() && forceVisibleBecauseAttachedToSelf(insertedEntity, playerData, insertedEntity.lastChecked(), "self-vehicle unresolved passenger")) {
|
||||
if (vehicle.isSelfEntity() && forceVisibleBecauseAttached(insertedEntity, playerData, insertedEntity.lastChecked(), "self-vehicle unresolved passenger")) {
|
||||
return;
|
||||
}
|
||||
resendPassengerStateIfClientVisible(vehicle, playerData);
|
||||
}
|
||||
|
||||
private boolean keepingClientEntityWhenHidden(NettyEntity<?,?> entity, PlayerData data) {
|
||||
/**
|
||||
* Reconciles relationship state which arrived before this entity was identified as bypassed.
|
||||
* The pending records are retained because a bypassed entity will never have a tracked entity
|
||||
* to own the authoritative relationship state.
|
||||
*/
|
||||
protected void handleBypassedEntitySpawn(int entityID, PlayerData playerData, int currentTick) {
|
||||
// Vanilla may send entity state before its spawn packet, and those packets were already
|
||||
// forwarded to the client. Discard deferred tracking work rather than replaying duplicates.
|
||||
playerData.nettyData().clearPendingPostSpawnTasksForEntity(entityID);
|
||||
int[] pendingPassengers = playerData.nettyData().getUnresolvedPassengers(entityID);
|
||||
if (!PrimitiveIntArrayList.isEmpty(pendingPassengers)) {
|
||||
for (int passengerID : pendingPassengers) {
|
||||
NettyEntity<?> passenger = playerData.entityFromID(passengerID);
|
||||
if (passenger == null) {
|
||||
continue;
|
||||
}
|
||||
passenger.setVehicleID(entityID);
|
||||
forceVisibleBecauseAttached(passenger, playerData, currentTick, "bypassed vehicle passenger");
|
||||
}
|
||||
}
|
||||
|
||||
int holderEntityID = playerData.nettyData().getUnresolvedHolderForLeashedEntity(entityID);
|
||||
if (holderEntityID != NO_LEASHER) {
|
||||
NettyEntity<?> holder = playerData.entityFromID(holderEntityID);
|
||||
if (holder != null) {
|
||||
holder.addLeashedEntity(entityID);
|
||||
}
|
||||
}
|
||||
int[] pendingLeashedEntityIDs = playerData.nettyData().getUnresolvedLeashes(entityID);
|
||||
if (!PrimitiveIntArrayList.isEmpty(pendingLeashedEntityIDs)) {
|
||||
for (int leashedEntityID : pendingLeashedEntityIDs) {
|
||||
NettyEntity<?> leashedEntity = playerData.entityFromID(leashedEntityID);
|
||||
if (leashedEntity != null) {
|
||||
leashedEntity.setLeashingEntity(entityID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves deferred leash state into a newly tracked entity while retaining relationships whose
|
||||
* other endpoint is still untracked or permanently bypassed.
|
||||
*/
|
||||
protected void reconcileUnresolvedLeashes(NettyEntity<?> insertedEntity, PlayerData playerData) {
|
||||
int entityID = insertedEntity.entityID();
|
||||
int pendingHolderEntityID = playerData.nettyData().getUnresolvedHolderForLeashedEntity(entityID);
|
||||
if (pendingHolderEntityID != NO_LEASHER) {
|
||||
insertedEntity.setLeashingEntity(pendingHolderEntityID);
|
||||
NettyEntity<?> holder = playerData.entityFromID(pendingHolderEntityID);
|
||||
if (holder != null) {
|
||||
holder.addLeashedEntity(entityID);
|
||||
playerData.nettyData().removeUnresolvedLeash(pendingHolderEntityID, entityID);
|
||||
if (holder.isSelfEntity()) {
|
||||
forceVisibleBecauseAttached(insertedEntity, playerData, insertedEntity.lastChecked(), "self-held unresolved leash");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int[] pendingLeashedEntityIDs = playerData.nettyData().getUnresolvedLeashes(entityID);
|
||||
if (PrimitiveIntArrayList.isEmpty(pendingLeashedEntityIDs)) {
|
||||
return;
|
||||
}
|
||||
for (int leashedEntityID : pendingLeashedEntityIDs) {
|
||||
NettyEntity<?> leashedEntity = playerData.entityFromID(leashedEntityID);
|
||||
if (leashedEntity == null) {
|
||||
if (EntityBypassRegistry.isBypassed(leashedEntityID)) {
|
||||
insertedEntity.addLeashedEntity(leashedEntityID);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
leashedEntity.setLeashingEntity(entityID);
|
||||
insertedEntity.addLeashedEntity(leashedEntityID);
|
||||
playerData.nettyData().removeUnresolvedLeash(entityID, leashedEntityID);
|
||||
if (insertedEntity.isSelfEntity()) {
|
||||
forceVisibleBecauseAttached(leashedEntity, playerData, leashedEntity.lastChecked(), "self-held unresolved leash");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean keepingClientEntityWhenHidden(NettyEntity<?> entity, PlayerData data) {
|
||||
if (entityConfig.keepClientEntityWhenHidden() == playerConfig.keepClientEntityWhenHidden()) {
|
||||
return entityConfig.keepClientEntityWhenHidden();
|
||||
}
|
||||
@@ -599,7 +743,7 @@ public abstract class PacketEntityViewController<P> {
|
||||
return getCorrectConfig(view).keepClientEntityWhenHidden();
|
||||
}
|
||||
|
||||
protected void resendPassengerStateIfClientVisible(NettyEntity<?,?> vehicle, PlayerData playerData) {
|
||||
protected void resendPassengerStateIfClientVisible(NettyEntity<?> vehicle, PlayerData playerData) {
|
||||
if (!vehicle.clientVisible() || (keepingClientEntityWhenHidden(vehicle, playerData) && !vehicle.visible())) {
|
||||
return;
|
||||
}
|
||||
@@ -607,8 +751,8 @@ public abstract class PacketEntityViewController<P> {
|
||||
}
|
||||
|
||||
protected IntArrayList collectClientVisiblePassengers(int[] passengerIDs, PlayerData playerData) {
|
||||
// Integer.MIN_VALUE cannot be a valid tracked entity ID, so this disables the exception.
|
||||
return collectClientVisiblePassengers(passengerIDs, playerData, Integer.MIN_VALUE);
|
||||
// HackyEntityIDGuard reserves -1, so it cannot accidentally match an entity being shown.
|
||||
return collectClientVisiblePassengers(passengerIDs, playerData, -1);
|
||||
}
|
||||
|
||||
protected IntArrayList collectClientVisiblePassengers(int[] passengerIDs, PlayerData playerData, int entityBeingShownID) {
|
||||
@@ -618,7 +762,11 @@ public abstract class PacketEntityViewController<P> {
|
||||
return visiblePassengers;
|
||||
}
|
||||
for (int passengerID : passengerIDs) {
|
||||
NettyEntity<?,?> passenger = playerData.entityFromID(passengerID);
|
||||
if (EntityBypassRegistry.isBypassed(passengerID)) {
|
||||
visiblePassengers.add(passengerID);
|
||||
continue;
|
||||
}
|
||||
NettyEntity<?> passenger = playerData.entityFromID(passengerID);
|
||||
if (passenger != null && ((passenger.clientVisible() && (!keepingClientEntityWhenHidden(passenger, playerData) || passenger.visible())) || passenger.entityID() == entityBeingShownID)) {
|
||||
visiblePassengers.add(passengerID);
|
||||
}
|
||||
@@ -629,7 +777,7 @@ public abstract class PacketEntityViewController<P> {
|
||||
/**
|
||||
* @return The created entity, with a default visibility of <code>true</code>. Must not return null. Does not insert the entity into any views, that is the responsibility of the caller.
|
||||
*/
|
||||
protected abstract NettyEntity<?,?> processEntitySpawn(PlayerData playerData, P packet, UUID world, int currentTick);
|
||||
protected abstract NettyEntity<?> processEntitySpawn(PlayerData playerData, P packet, UUID world, int currentTick);
|
||||
|
||||
/** @return The entity ID of the entity */
|
||||
protected abstract int processRelativeMovePacket(P packet, PlayerData playerData, int currentTick);
|
||||
@@ -643,6 +791,8 @@ public abstract class PacketEntityViewController<P> {
|
||||
/** @return The entity ID of the entity */
|
||||
protected abstract int processPositionSyncPacket(P packet, PlayerData playerData, int currentTick);
|
||||
|
||||
protected abstract void processTrackedMetadata(P packet, NettyEntity<?> entity);
|
||||
|
||||
protected abstract void cachePacket(P packet, int entityID, PlayerData playerData, int currentTick);
|
||||
/** @return The entity ID of the entity */
|
||||
protected abstract int processRotationPacket(P packet, PlayerData playerData, int currentTick);
|
||||
@@ -656,7 +806,7 @@ public abstract class PacketEntityViewController<P> {
|
||||
/**Silently sends the provided array of entities as passengers for the required vehicle.*/
|
||||
protected abstract void sendEntityPassengerPacket(int vehicle, IntArrayList passengers, PlayerData playerData);
|
||||
|
||||
protected abstract void insertEntityToPlayerView(NettyEntity<?,?> entity, PlayerData playerData, UUID world);
|
||||
protected abstract void insertEntityToPlayerView(NettyEntity<?> entity, PlayerData playerData, UUID world);
|
||||
|
||||
protected abstract void insertEntityToEntityView(NettyEntity<?,?> entity, PlayerData playerData, UUID world);
|
||||
protected abstract void insertEntityToEntityView(NettyEntity<?> entity, PlayerData playerData, UUID world);
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.blocks.ByteArrayBlockChunkData;
|
||||
|
||||
+20
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -15,9 +23,20 @@ class RaycastConfigTest {
|
||||
EntityConfig entityConfig = EntityConfig.load(entityNode(false), "checks.entity");
|
||||
|
||||
assertTrue(playerConfig.keepClientEntityWhenHidden());
|
||||
assertFalse(playerConfig.onlyCheckSneaking());
|
||||
assertFalse(entityConfig.keepClientEntityWhenHidden());
|
||||
}
|
||||
|
||||
@Test
|
||||
void playerSneakingOnlySettingLoadsIndependently() throws SerializationException {
|
||||
ConfigurationNode node = entityNode(true);
|
||||
node.node("only-check-sneaking").set(true);
|
||||
|
||||
PlayerConfig playerConfig = PlayerConfig.load(node, "checks.player");
|
||||
|
||||
assertTrue(playerConfig.onlyCheckSneaking());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tileEntityConfigDoesNotRequireOrEnableClientRetention() throws SerializationException {
|
||||
TileEntityConfig config = TileEntityConfig.load(baseNode(), "checks.tile-entity");
|
||||
@@ -38,6 +57,7 @@ class RaycastConfigTest {
|
||||
ConfigurationNode node = baseNode();
|
||||
node.node("hide-sounds-when-hidden").set(true);
|
||||
node.node("keep-client-entity-when-hidden").set(keepClientEntityWhenHidden);
|
||||
node.node("only-check-sneaking").set(false);
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.players;
|
||||
|
||||
import games.cubi.locatables.implementations.ImmutableLocatableImpl;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class PlayerLocatableConcurrencyTest {
|
||||
private static final UUID WORLD = UUID.fromString("00000000-0000-0000-0000-000000000001");
|
||||
private static final UUID OTHER_WORLD = UUID.fromString("00000000-0000-0000-0000-000000000002");
|
||||
|
||||
@Test
|
||||
void concurrentReadersAndWritersObserveFiniteSamples() throws Exception {
|
||||
PlayerLocatable location = new PlayerLocatable();
|
||||
location.initialise(WORLD, 0.0, 1.0, 2.0, 0.0f, 0.0f, PlayerPose.STANDING);
|
||||
ImmutableLocatableImpl target = new ImmutableLocatableImpl(WORLD, 10.0, 11.0, 12.0);
|
||||
|
||||
AtomicBoolean running = new AtomicBoolean(true);
|
||||
AtomicReference<Throwable> failure = new AtomicReference<>();
|
||||
CountDownLatch readersStarted = new CountDownLatch(4);
|
||||
ExecutorService executor = Executors.newFixedThreadPool(6);
|
||||
List<Future<?>> readers = new ArrayList<>();
|
||||
|
||||
try {
|
||||
Future<?> lifecycleWriter = executor.submit(() -> runLifecycleWriter(location));
|
||||
Future<?> partialWriter = executor.submit(() -> runPartialWriter(location));
|
||||
for (int i = 0; i < 4; i++) {
|
||||
readers.add(executor.submit(() -> runReader(location, target, running, readersStarted, failure)));
|
||||
}
|
||||
|
||||
assertTrue(readersStarted.await(5, TimeUnit.SECONDS));
|
||||
lifecycleWriter.get(10, TimeUnit.SECONDS);
|
||||
partialWriter.get(10, TimeUnit.SECONDS);
|
||||
running.set(false);
|
||||
for (Future<?> reader : readers) {
|
||||
reader.get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
assertNull(failure.get(), () -> "Concurrent reader failed: " + failure.get());
|
||||
} finally {
|
||||
running.set(false);
|
||||
executor.shutdownNow();
|
||||
assertTrue(executor.awaitTermination(10, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
private static void runLifecycleWriter(PlayerLocatable location) {
|
||||
for (int i = 0; i < 20_000; i++) {
|
||||
UUID world = (i & 1) == 0 ? WORLD : OTHER_WORLD;
|
||||
location.worldChange(world, i, i + 1.0, i + 2.0, i % 360.0f, (i % 180.0f) - 90.0f, poseFor(i));
|
||||
if ((i & 255) == 0) {
|
||||
location.invalidate();
|
||||
location.initialise(world, i, i + 1.0, i + 2.0, 0.0f, 0.0f, PlayerPose.UNKNOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void runPartialWriter(PlayerLocatable location) {
|
||||
for (int i = 0; i < 20_000; i++) {
|
||||
try {
|
||||
location.updateFoot(i + 0.25, i + 1.25, i + 2.25);
|
||||
location.updateRotation(i % 360.0f, (i % 180.0f) - 90.0f);
|
||||
location.updatePose(poseFor(i + 1));
|
||||
} catch (IllegalStateException ignored) {
|
||||
// The lifecycle writer is allowed to invalidate between partial updates.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void runReader(PlayerLocatable location, ImmutableLocatableImpl target, AtomicBoolean running,
|
||||
CountDownLatch readersStarted, AtomicReference<Throwable> failure) {
|
||||
readersStarted.countDown();
|
||||
try {
|
||||
while (running.get()) {
|
||||
location.world();
|
||||
double x = location.x();
|
||||
double y = location.y();
|
||||
double z = location.z();
|
||||
float yaw = location.yaw();
|
||||
float pitch = location.pitch();
|
||||
location.pose();
|
||||
float cameraYOffset = location.cameraYOffset();
|
||||
double cameraX = location.cameraX();
|
||||
double cameraY = location.cameraY();
|
||||
double cameraZ = location.cameraZ();
|
||||
double distanceSquared = location.cameraDistanceSquared(target);
|
||||
|
||||
if (!Double.isFinite(x) || !Double.isFinite(y) || !Double.isFinite(z)
|
||||
|| !Float.isFinite(yaw) || !Float.isFinite(pitch)
|
||||
|| !Float.isFinite(cameraYOffset)
|
||||
|| !Double.isFinite(cameraX) || !Double.isFinite(cameraY) || !Double.isFinite(cameraZ)
|
||||
|| !Double.isFinite(distanceSquared)) {
|
||||
throw new AssertionError("Observed a non-finite player sample");
|
||||
}
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
failure.compareAndSet(null, throwable);
|
||||
}
|
||||
}
|
||||
|
||||
private static PlayerPose poseFor(int value) {
|
||||
return switch (Math.floorMod(value, 4)) {
|
||||
case 0 -> PlayerPose.STANDING;
|
||||
case 1 -> PlayerPose.SNEAKING;
|
||||
case 2 -> PlayerPose.SWIMMING;
|
||||
default -> PlayerPose.SLEEPING;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.players;
|
||||
|
||||
import games.cubi.locatables.implementations.ImmutableLocatableImpl;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class PlayerLocatableTest {
|
||||
private static final UUID WORLD = UUID.fromString("00000000-0000-0000-0000-000000000001");
|
||||
private static final UUID OTHER_WORLD = UUID.fromString("00000000-0000-0000-0000-000000000002");
|
||||
|
||||
@Test
|
||||
void poseCameraOffsetsAreExposed() {
|
||||
assertEquals(1.62f, PlayerPose.UNKNOWN.cameraYOffset());
|
||||
assertEquals(1.62f, PlayerPose.STANDING.cameraYOffset());
|
||||
assertEquals(1.27f, PlayerPose.SNEAKING.cameraYOffset());
|
||||
assertEquals(0.40f, PlayerPose.SWIMMING.cameraYOffset());
|
||||
assertEquals(0.40f, PlayerPose.FALL_FLYING.cameraYOffset());
|
||||
assertEquals(0.40f, PlayerPose.SPIN_ATTACK.cameraYOffset());
|
||||
assertEquals(0.20f, PlayerPose.SLEEPING.cameraYOffset());
|
||||
assertEquals(0.20f, PlayerPose.DYING.cameraYOffset());
|
||||
}
|
||||
|
||||
@Test
|
||||
void startsInvalidAndInitializesCompleteCameraState() {
|
||||
PlayerLocatable location = new PlayerLocatable();
|
||||
|
||||
assertNull(location.world());
|
||||
assertNull(location.pose());
|
||||
assertEquals(0.0f, location.cameraYOffset());
|
||||
|
||||
location.initialise(WORLD, 10.0, 20.0, 30.0, 90.0f, -25.0f, PlayerPose.SNEAKING);
|
||||
|
||||
assertEquals(WORLD, location.world());
|
||||
assertEquals(10.0, location.x());
|
||||
assertEquals(20.0, location.y());
|
||||
assertEquals(30.0, location.z());
|
||||
assertEquals(90.0f, location.yaw());
|
||||
assertEquals(-25.0f, location.pitch());
|
||||
assertEquals(PlayerPose.SNEAKING, location.pose());
|
||||
assertEquals(1.27f, location.cameraYOffset());
|
||||
assertEquals(10.0, location.cameraX());
|
||||
assertEquals(21.27, location.cameraY(), 1.0e-6);
|
||||
assertEquals(30.0, location.cameraZ());
|
||||
assertEquals(1.27 * 1.27, location.cameraDistanceSquared(new ImmutableLocatableImpl(WORLD, 10.0, 20.0, 30.0)), 1.0e-6);
|
||||
}
|
||||
|
||||
@Test
|
||||
void partialUpdatesPreserveOmittedStateAndRequireInitialization() {
|
||||
PlayerLocatable location = new PlayerLocatable();
|
||||
assertThrows(IllegalStateException.class, () -> location.updateFoot(1.0, 2.0, 3.0));
|
||||
assertThrows(IllegalStateException.class, () -> location.updateRotation(1.0f, 2.0f));
|
||||
assertThrows(IllegalStateException.class, () -> location.updatePose(PlayerPose.STANDING));
|
||||
|
||||
location.initialise(WORLD, 1.0, 2.0, 3.0, 4.0f, 5.0f, PlayerPose.STANDING);
|
||||
location.updateFoot(6.0, 7.0, 8.0);
|
||||
location.updateRotation(9.0f, 10.0f);
|
||||
location.updatePose(PlayerPose.SNEAKING);
|
||||
|
||||
assertEquals(6.0, location.x());
|
||||
assertEquals(7.0, location.y());
|
||||
assertEquals(8.0, location.z());
|
||||
assertEquals(9.0f, location.yaw());
|
||||
assertEquals(10.0f, location.pitch());
|
||||
assertEquals(PlayerPose.SNEAKING, location.pose());
|
||||
}
|
||||
|
||||
@Test
|
||||
void locatableMutationsPreserveViewStateAndSetWorldNullInvalidates() {
|
||||
PlayerLocatable location = new PlayerLocatable();
|
||||
location.initialise(WORLD, 1.0, 2.0, 3.0, 4.0f, 5.0f, PlayerPose.SLEEPING);
|
||||
|
||||
assertSame(location, location.setPosition(6.0, 7.0, 8.0));
|
||||
assertSame(location, location.setLocation(OTHER_WORLD, 9.0, 10.0, 11.0));
|
||||
assertEquals(4.0f, location.yaw());
|
||||
assertEquals(5.0f, location.pitch());
|
||||
assertEquals(PlayerPose.SLEEPING, location.pose());
|
||||
assertEquals(OTHER_WORLD, location.world());
|
||||
assertEquals(9.0, location.x());
|
||||
assertEquals(10.0, location.y());
|
||||
assertEquals(11.0, location.z());
|
||||
|
||||
location.setWorld(null);
|
||||
|
||||
assertNull(location.world());
|
||||
assertNull(location.pose());
|
||||
assertEquals(0.0, location.x());
|
||||
assertEquals(0.0, location.y());
|
||||
assertEquals(0.0, location.z());
|
||||
assertThrows(IllegalStateException.class, () -> location.setWorld(WORLD));
|
||||
}
|
||||
|
||||
@Test
|
||||
void equalityUsesWorldAndFootCoordinatesOnly() {
|
||||
PlayerLocatable first = new PlayerLocatable();
|
||||
PlayerLocatable second = new PlayerLocatable();
|
||||
first.initialise(WORLD, 1.0, 2.0, 3.0, 4.0f, 5.0f, PlayerPose.STANDING);
|
||||
second.initialise(WORLD, 1.0, 2.0, 3.0, 90.0f, -5.0f, PlayerPose.SLEEPING);
|
||||
|
||||
assertEquals(first, second);
|
||||
assertEquals(first.hashCode(), second.hashCode());
|
||||
assertTrue(first.strictlyEquals(second));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fullStateRejectsInvalidValues() {
|
||||
PlayerLocatable location = new PlayerLocatable();
|
||||
|
||||
assertThrows(NullPointerException.class, () -> location.initialise(null, 0.0, 0.0, 0.0, 0.0f, 0.0f, PlayerPose.STANDING));
|
||||
assertThrows(NullPointerException.class, () -> location.initialise(WORLD, 0.0, 0.0, 0.0, 0.0f, 0.0f, null));
|
||||
assertThrows(IllegalArgumentException.class, () -> location.initialise(WORLD, Double.NaN, 0.0, 0.0, 0.0f, 0.0f, PlayerPose.STANDING));
|
||||
assertThrows(IllegalArgumentException.class, () -> location.initialise(WORLD, 0.0, 0.0, 0.0, Float.NaN, 0.0f, PlayerPose.STANDING));
|
||||
assertThrows(IllegalArgumentException.class, () -> location.initialise(WORLD, 0.0, 0.0, 0.0, 0.0f, 91.0f, PlayerPose.STANDING));
|
||||
assertNull(location.world());
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.raycast;
|
||||
|
||||
import games.cubi.locatables.api.Locatable;
|
||||
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.tracked;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.utils.Clearable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Phaser;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class NettyEntityTrackedStateTest {
|
||||
@Test
|
||||
void trackedFlagsUpdateIndependentlyAndReportChanges() {
|
||||
TestEntity entity = new TestEntity();
|
||||
|
||||
assertTrue(entity.setSneaking(true));
|
||||
assertTrue(entity.sneaking());
|
||||
assertFalse(entity.glowing());
|
||||
assertEquals(NettyEntity.NEVER_CHECKED, entity.lastChecked());
|
||||
|
||||
entity.setLastChecked(10);
|
||||
assertFalse(entity.setSneaking(true));
|
||||
assertEquals(10, entity.lastChecked());
|
||||
|
||||
assertTrue(entity.setGlowing(true));
|
||||
assertTrue(entity.sneaking());
|
||||
assertTrue(entity.glowing());
|
||||
assertEquals(NettyEntity.NEVER_CHECKED, entity.lastChecked());
|
||||
|
||||
entity.clear();
|
||||
|
||||
assertFalse(entity.sneaking());
|
||||
assertFalse(entity.glowing());
|
||||
}
|
||||
|
||||
@Test
|
||||
void concurrentUpdatesToDifferentFlagsDoNotOverwriteEachOther() {
|
||||
assertTimeoutPreemptively(Duration.ofSeconds(10), () -> {
|
||||
TestEntity entity = new TestEntity();
|
||||
int iterations = 2_000;
|
||||
Phaser phases = new Phaser(3);
|
||||
AtomicBoolean lostUpdate = new AtomicBoolean();
|
||||
|
||||
try (var executor = Executors.newFixedThreadPool(2)) {
|
||||
var sneakingTask = executor.submit(() -> {
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
phases.arriveAndAwaitAdvance();
|
||||
entity.setSneaking(true);
|
||||
phases.arriveAndAwaitAdvance();
|
||||
}
|
||||
});
|
||||
var glowingTask = executor.submit(() -> {
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
phases.arriveAndAwaitAdvance();
|
||||
entity.setGlowing(true);
|
||||
phases.arriveAndAwaitAdvance();
|
||||
}
|
||||
});
|
||||
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
entity.clear();
|
||||
phases.arriveAndAwaitAdvance();
|
||||
phases.arriveAndAwaitAdvance();
|
||||
if (!entity.sneaking() || !entity.glowing()) {
|
||||
lostUpdate.set(true);
|
||||
}
|
||||
}
|
||||
sneakingTask.get();
|
||||
glowingTask.get();
|
||||
}
|
||||
|
||||
assertFalse(lostUpdate.get());
|
||||
});
|
||||
}
|
||||
|
||||
private static final class TestEntity extends NettyEntity<Clearable> {
|
||||
private TestEntity() {
|
||||
super(null, 0, 0, 0, 1, UUID.randomUUID(), false, 0, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import games.cubi.utils.sets.CopyOnWriteMTIntSet;
|
||||
import games.cubi.utils.sets.SortedStripedMTIntSet;
|
||||
import org.junit.jupiter.api.DynamicContainer;
|
||||
import org.junit.jupiter.api.TestFactory;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.DynamicContainer.dynamicContainer;
|
||||
import static org.junit.jupiter.api.DynamicTest.dynamicTest;
|
||||
|
||||
class CopyOnWriteMTIntSetTest {
|
||||
private static final List<Implementation> IMPLEMENTATIONS = List.of(
|
||||
new Implementation("sorted stripes", SortedStripedMTIntSet::new)
|
||||
);
|
||||
|
||||
@TestFactory
|
||||
Stream<DynamicContainer> implementationsMeetContract() {
|
||||
return IMPLEMENTATIONS.stream().map(implementation -> dynamicContainer(
|
||||
implementation.name(),
|
||||
Stream.of(
|
||||
dynamicTest("adds, finds, and removes all int values", () -> basicOperations(implementation.create())),
|
||||
dynamicTest("removes beginning, middle, and end values", () -> removalPositions(implementation.create())),
|
||||
dynamicTest("traverses one coherent snapshot", () -> snapshotTraversal(implementation.create())),
|
||||
dynamicTest("supports concurrent readers and writers", () -> concurrentReadersAndWriters(implementation.create()))
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
private static void basicOperations(CopyOnWriteMTIntSet set) {
|
||||
int[] values = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
|
||||
for (int value : values) {
|
||||
assertFalse(set.contains(value));
|
||||
set.add(value);
|
||||
set.add(value);
|
||||
assertTrue(set.contains(value));
|
||||
}
|
||||
for (int value : values) {
|
||||
assertTrue(set.remove(value));
|
||||
assertFalse(set.contains(value));
|
||||
assertFalse(set.remove(value));
|
||||
}
|
||||
}
|
||||
|
||||
private static void removalPositions(CopyOnWriteMTIntSet set) {
|
||||
for (int value = 1; value <= 5; value++) {
|
||||
set.add(value);
|
||||
}
|
||||
|
||||
assertTrue(set.remove(1));
|
||||
assertTrue(set.remove(3));
|
||||
assertTrue(set.remove(5));
|
||||
|
||||
assertFalse(set.contains(1));
|
||||
assertTrue(set.contains(2));
|
||||
assertFalse(set.contains(3));
|
||||
assertTrue(set.contains(4));
|
||||
assertFalse(set.contains(5));
|
||||
}
|
||||
|
||||
private static void snapshotTraversal(CopyOnWriteMTIntSet set) {
|
||||
set.add(1);
|
||||
set.add(2);
|
||||
set.add(3);
|
||||
|
||||
Set<Integer> observed = new HashSet<>();
|
||||
set.forEach(value -> {
|
||||
assertTrue(observed.add(value));
|
||||
if (value == 1) {
|
||||
assertTrue(set.remove(2));
|
||||
set.add(4);
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue(observed.containsAll(Set.of(1, 2, 3)));
|
||||
assertTrue(observed.size() == 3);
|
||||
assertFalse(set.contains(2));
|
||||
assertTrue(set.contains(4));
|
||||
|
||||
set.remove(1);
|
||||
set.remove(3);
|
||||
set.remove(4);
|
||||
set.forEach(value -> assertTrue(false, "An empty set must not be traversed: " + value));
|
||||
}
|
||||
|
||||
private static void concurrentReadersAndWriters(CopyOnWriteMTIntSet set) {
|
||||
assertTimeoutPreemptively(Duration.ofSeconds(20), () -> {
|
||||
int transientCount = 512;
|
||||
int transientBase = 100_000;
|
||||
for (int value = 0; value < transientCount; value++) {
|
||||
set.add(transientBase + value);
|
||||
}
|
||||
|
||||
int valueCount = 2_048;
|
||||
ExecutorService executor = Executors.newFixedThreadPool(8);
|
||||
CountDownLatch start = new CountDownLatch(1);
|
||||
List<Future<?>> futures = new ArrayList<>();
|
||||
try {
|
||||
for (int worker = 0; worker < 2; worker++) {
|
||||
int workerIndex = worker;
|
||||
futures.add(executor.submit(() -> {
|
||||
await(start);
|
||||
if (workerIndex == 0) {
|
||||
for (int value = 0; value < valueCount; value++) {
|
||||
addFinalValues(set, value);
|
||||
}
|
||||
} else {
|
||||
for (int value = valueCount - 1; value >= 0; value--) {
|
||||
addFinalValues(set, value);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
for (int remover = 0; remover < 2; remover++) {
|
||||
futures.add(executor.submit(() -> {
|
||||
await(start);
|
||||
for (int value = 0; value < transientCount; value++) {
|
||||
set.remove(transientBase + value);
|
||||
}
|
||||
}));
|
||||
}
|
||||
for (int reader = 0; reader < 3; reader++) {
|
||||
futures.add(executor.submit(() -> {
|
||||
await(start);
|
||||
for (int iteration = 0; iteration < 10_000; iteration++) {
|
||||
int value = iteration % valueCount;
|
||||
set.contains(value);
|
||||
set.contains(-value - 1);
|
||||
set.contains(Integer.MIN_VALUE);
|
||||
set.contains(Integer.MAX_VALUE);
|
||||
if (iteration % 100 == 0) {
|
||||
Set<Integer> snapshot = new HashSet<>();
|
||||
set.forEach(snapshotValue -> assertTrue(snapshot.add(snapshotValue), "Duplicate value in traversal snapshot: " + snapshotValue));
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
start.countDown();
|
||||
for (Future<?> future : futures) {
|
||||
future.get(5, TimeUnit.SECONDS);
|
||||
}
|
||||
} finally {
|
||||
executor.shutdownNow();
|
||||
executor.awaitTermination(5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
Set<Integer> expected = new HashSet<>();
|
||||
for (int value = 0; value < valueCount; value++) {
|
||||
expected.add(value);
|
||||
expected.add(-value - 1);
|
||||
}
|
||||
expected.add(Integer.MIN_VALUE);
|
||||
expected.add(Integer.MAX_VALUE);
|
||||
|
||||
Set<Integer> actual = new HashSet<>();
|
||||
set.forEach(value -> assertTrue(actual.add(value), "Duplicate value in final snapshot: " + value));
|
||||
assertEquals(expected, actual);
|
||||
for (int value = 0; value < transientCount; value++) {
|
||||
assertFalse(set.contains(transientBase + value));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void addFinalValues(CopyOnWriteMTIntSet set, int value) {
|
||||
set.add(value);
|
||||
set.add(-value - 1);
|
||||
set.add(value);
|
||||
set.add(-value - 1);
|
||||
if (value == 0) {
|
||||
set.add(Integer.MIN_VALUE);
|
||||
set.add(Integer.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
private static void await(CountDownLatch latch) {
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException exception) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new AssertionError("Interrupted while awaiting concurrent test start", exception);
|
||||
}
|
||||
}
|
||||
|
||||
private record Implementation(String name, Supplier<CopyOnWriteMTIntSet> factory) {
|
||||
private CopyOnWriteMTIntSet create() {
|
||||
return factory.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loaded 100 of 163 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user