-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2171a57
commit 5902fec
Showing
5 changed files
with
90 additions
and
11 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/main/java/ac/grim/grimac/checks/impl/breaking/PositionBreak.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package ac.grim.grimac.checks.impl.breaking; | ||
|
||
import ac.grim.grimac.checks.Check; | ||
import ac.grim.grimac.checks.CheckData; | ||
import ac.grim.grimac.checks.type.BlockBreakCheck; | ||
import ac.grim.grimac.player.GrimPlayer; | ||
import ac.grim.grimac.utils.anticheat.update.BlockBreak; | ||
import ac.grim.grimac.utils.collisions.datatypes.SimpleCollisionBox; | ||
|
||
@CheckData(name = "PositionBreak") | ||
public class PositionBreak extends Check implements BlockBreakCheck { | ||
public PositionBreak(GrimPlayer player) { | ||
super(player); | ||
} | ||
|
||
@Override | ||
public void onBlockBreak(BlockBreak blockBreak) { | ||
SimpleCollisionBox combined = blockBreak.getCombinedBox(); | ||
|
||
final double[] possibleEyeHeights = player.getPossibleEyeHeights(); | ||
double minEyeHeight = Double.MAX_VALUE; | ||
double maxEyeHeight = Double.MIN_VALUE; | ||
for (double height : possibleEyeHeights) { | ||
minEyeHeight = Math.min(minEyeHeight, height); | ||
maxEyeHeight = Math.max(maxEyeHeight, height); | ||
} | ||
|
||
SimpleCollisionBox eyePositions = new SimpleCollisionBox(player.x, player.y + minEyeHeight, player.z, player.x, player.y + maxEyeHeight, player.z); | ||
if (!player.packetStateData.didLastMovementIncludePosition || player.canSkipTicks()) { | ||
eyePositions.expand(player.getMovementThreshold()); | ||
} | ||
|
||
// If the player is inside a block, then they can ray trace through the block and hit the other side of the block | ||
if (eyePositions.isIntersected(combined)) { | ||
return; | ||
} | ||
|
||
// So now we have the player's possible eye positions | ||
// So then look at the face that the player has clicked | ||
boolean flag = switch (blockBreak.face) { | ||
case NORTH -> eyePositions.minZ > combined.minZ; // Z- face | ||
case SOUTH -> eyePositions.maxZ < combined.maxZ; // Z+ face | ||
case EAST -> eyePositions.maxX < combined.maxX; // X+ face | ||
case WEST -> eyePositions.minX > combined.minX; // X- face | ||
case UP -> eyePositions.maxY < combined.maxY; // Y+ face | ||
case DOWN -> eyePositions.minY > combined.minY; // Y- face | ||
default -> false; | ||
}; | ||
|
||
if (flag && flagAndAlert("action=" + blockBreak.action + ", face=" + blockBreak.face) && shouldModifyPackets()) { | ||
blockBreak.cancel(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters