From a6b25376d7f1311579629e86888cedcf119a2e8a Mon Sep 17 00:00:00 2001 From: Dawson <30784509+funkemunky@users.noreply.github.com> Date: Tue, 20 Sep 2022 16:55:29 -0400 Subject: [PATCH] Adding collision accounting. dumb shit --- .../java/dev/brighten/ac/check/Check.java | 113 ++++---- .../check/impl/movement/speed/Horizontal.java | 272 ++++++++++++++++-- .../check/impl/movement/speed/Vertical.java | 13 + .../ac/data/info/BlockInformation.java | 19 +- .../java/dev/brighten/ac/utils/Helper.java | 25 ++ 5 files changed, 345 insertions(+), 97 deletions(-) create mode 100644 src/main/java/dev/brighten/ac/check/impl/movement/speed/Vertical.java diff --git a/src/main/java/dev/brighten/ac/check/Check.java b/src/main/java/dev/brighten/ac/check/Check.java index 00a51f0..16570c4 100644 --- a/src/main/java/dev/brighten/ac/check/Check.java +++ b/src/main/java/dev/brighten/ac/check/Check.java @@ -131,6 +131,10 @@ public class Check implements ECheck { } } + public Optional find(Class checkClass) { + return Optional.ofNullable((T) player.getCheckHandler().findCheck((Class) checkClass)); + } + static List devComponents = new ArrayList<>(), components = new ArrayList<>(); static { @@ -160,71 +164,68 @@ public class Check implements ECheck { if(System.currentTimeMillis() - lastFlagRun < 50L) return; lastFlagRun = System.currentTimeMillis(); - Anticheat.INSTANCE.getScheduler().execute(() -> { - if(Anticheat.INSTANCE.getTps() < 18) - vl = 0; + if(Anticheat.INSTANCE.getTps() < 18) + vl = 0; - final String info = String.format(information, variables); + final String info = String.format(information, variables); - FlagResult currentResult = FlagResult.builder().cancelled(false).build(); + FlagResult currentResult = FlagResult.builder().cancelled(false).build(); - for (AnticheatEvent event : AnticheatAPI.INSTANCE.getAllEvents()) { - currentResult = event.onFlag(player.getBukkitPlayer(), this, info, - currentResult.isCancelled()); + for (AnticheatEvent event : AnticheatAPI.INSTANCE.getAllEvents()) { + currentResult = event.onFlag(player.getBukkitPlayer(), this, info, + currentResult.isCancelled()); + } + + if(currentResult.isCancelled()) return; + + Anticheat.INSTANCE.getLogManager() + .insertLog(player, checkData, vl, System.currentTimeMillis(), info); + + if(alertCountReset.isPassed(20)) { + alertCount.set(0); + alertCountReset.reset(); + } + + if(alertCount.incrementAndGet() < 40) { + boolean dev = Anticheat.INSTANCE.getTps() < 18; + + //Sending Discord webhook alert + + List toSend = new ArrayList<>(); + + for (TextComponent tc : components) { + TextComponent ntc = new TextComponent(tc); + ntc.setText(formatAlert(tc.getText(), info)); + + ntc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Description:") + .color(ChatColor.YELLOW) + .append(formatAlert(" %desc%\n", info)).color(ChatColor.WHITE).append("Info:") + .color(ChatColor.YELLOW) + .append(formatAlert(" %info%\n", info)).color(ChatColor.WHITE) + .append("\n").append("Click to teleport to player") + .create())); + ntc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, + addPlaceHolders(CheckConfig.clickCommand))); + + toSend.add(ntc); } - if(currentResult.isCancelled()) return; - - Anticheat.INSTANCE.getLogManager() - .insertLog(player, checkData, vl, System.currentTimeMillis(), info); - - if(alertCountReset.isPassed(20)) { - alertCount.set(0); - alertCountReset.reset(); + for (UUID uuid : alertsEnabled) { + Anticheat.INSTANCE.getPlayerRegistry().getPlayer(uuid) + .ifPresent(apl -> apl.getBukkitPlayer().spigot().sendMessage(toSend + .toArray(new BaseComponent[0]))); } - - if(alertCount.incrementAndGet() < 40) { - boolean dev = Anticheat.INSTANCE.getTps() < 18; - - //Sending Discord webhook alert - - List toSend = new ArrayList<>(); - - for (TextComponent tc : components) { - TextComponent ntc = new TextComponent(tc); - ntc.setText(formatAlert(tc.getText(), info)); - - ntc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Description:") - .color(ChatColor.YELLOW) - .append(formatAlert(" %desc%\n", info)).color(ChatColor.WHITE).append("Info:") - .color(ChatColor.YELLOW) - .append(formatAlert(" %info%\n", info)).color(ChatColor.WHITE) - .append("\n").append("Click to teleport to player") - .create())); - ntc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, - addPlaceHolders(CheckConfig.clickCommand))); - - toSend.add(ntc); - } - - for (UUID uuid : alertsEnabled) { - Anticheat.INSTANCE.getPlayerRegistry().getPlayer(uuid) - .ifPresent(apl -> apl.getBukkitPlayer().spigot().sendMessage(toSend - .toArray(new BaseComponent[0]))); - } - alertCountReset.reset(); - } - if(punish && vl >= punishVl) { - punish(); - } - }); + alertCountReset.reset(); + } + if(punish && vl >= punishVl) { + punish(); + } } public void punish() { if(!punishable || lastPunish.isNotPassed(20)) return; lastPunish.reset(); - System.out.println("tried to punish"); List commands = CheckConfig.punishmentCommands.stream().map(this::addPlaceHolders) .collect(Collectors.toList()); @@ -235,12 +236,6 @@ public class Check implements ECheck { result = event.onPunish(player.getBukkitPlayer(),this, commands, result.isCancelled()); } PunishResult finalResult = result; - if(finalResult == null) { - System.out.println("Result is null"); - } else { - System.out.println("Is cancelled: " + finalResult.isCancelled()); - System.out.println("Commands: " + String.join(",", finalResult.getCommands())); - } if(finalResult != null && finalResult.getCommands() != null && !finalResult.isCancelled()) { RunUtils.task(() -> { for (String punishmentCommand : finalResult.getCommands()) { diff --git a/src/main/java/dev/brighten/ac/check/impl/movement/speed/Horizontal.java b/src/main/java/dev/brighten/ac/check/impl/movement/speed/Horizontal.java index ea9d44c..c292b8c 100644 --- a/src/main/java/dev/brighten/ac/check/impl/movement/speed/Horizontal.java +++ b/src/main/java/dev/brighten/ac/check/impl/movement/speed/Horizontal.java @@ -7,10 +7,7 @@ import dev.brighten.ac.check.WAction; import dev.brighten.ac.data.APlayer; import dev.brighten.ac.packet.ProtocolVersion; import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying; -import dev.brighten.ac.utils.Helper; -import dev.brighten.ac.utils.KLocation; -import dev.brighten.ac.utils.Materials; -import dev.brighten.ac.utils.MathHelper; +import dev.brighten.ac.utils.*; import dev.brighten.ac.utils.math.IntVector; import dev.brighten.ac.utils.world.types.SimpleCollisionBox; import dev.brighten.ac.utils.wrapper.Wrapper; @@ -27,10 +24,13 @@ import java.util.stream.Collectors; @CheckData(name = "Horizontal", checkId = "horizontala", type = CheckType.MOVEMENT) public class Horizontal extends Check { - private boolean lastLastClientGround; - private float buffer; + private boolean lastLastClientGround, lOnGround; + private float buffer, vbuffer; + private boolean maybeSetToZero; private Vector velocity; private int vTicks; + private double ldeltaX = 0, ldeltaY = 0, ldeltaZ = 0; + private KLocation previousFrom; private static final boolean[] TRUE_FALSE = new boolean[]{true, false}; @@ -41,7 +41,7 @@ public class Horizontal extends Check { } WAction flying = packet -> { - + boolean overrideSet = false; check: { @@ -55,13 +55,20 @@ public class Horizontal extends Check { break check; } - double smallestDelta = Double.MAX_VALUE; + double smallDelta = Double.MAX_VALUE, smallestDeltaXZ = Double.MAX_VALUE, smallestDeltaY = Double.MAX_VALUE; - double pmotionx = 0, pmotionz = 0; + double pmotionx = 0, pmotiony = 0, pmotionz = 0; boolean onGround = player.getMovement().getFrom().isOnGround(); + boolean didBlockCollisionsInfluence = false; List iterations = getIteration(); + String debug = ""; + + double xOverride = player.getMovement().getDeltaX(), + yOverride = player.getMovement().getDeltaY(), + zOverride = player.getMovement().getDeltaZ(); + for (Iteration it : iterations) { float forward = it.f, strafe = it.s; @@ -89,8 +96,17 @@ public class Horizontal extends Check { double aiMoveSpeed = player.getBukkitPlayer().getWalkSpeed() / 2; float drag = 0.91f; - double lmotionX = player.getMovement().getLDeltaX(), - lmotionZ = player.getMovement().getLDeltaZ(); + double lmotionX = ldeltaX, + lmotionY = ldeltaY, + lmotionZ = ldeltaZ; + + lmotionY-= 0.08; + lmotionY*= 0.98f; + + //Less than 0.05 + if(((lmotionX * lmotionX) + (lmotionZ * lmotionZ) + (lmotionY * lmotionY)) < 0.0025) { + break check; + } if(player.getBlockInfo().onSoulSand && player.getBlockInfo().collisionMaterialCount. @@ -128,11 +144,6 @@ public class Horizontal extends Check { lmotionZ = 0; } - //Less than 0.05 - if(((lmotionX * lmotionX) + (lmotionZ * lmotionZ)) < 0.0025 - && player.getMovement().getDeltaXZ() < 0.2) { - break check; - } // Attack slowdown if (it.attack) { lmotionX *= 0.6; @@ -199,12 +210,81 @@ public class Horizontal extends Check { } } - List collisionBoxes = Helper.toCollisionsDowncasted(Helper.blockCollisions - (player.getBlockInfo().blocks, player.getMovement().getFrom().getBox().copy() - .addCoord(lmotionX ,player.getMovement().getDeltaY(), lmotionZ), Materials.SOLID)); + if(it.jumped) lmotionY = MovementUtils.getJumpHeight(player); + + if(Math.abs(lmotionY) < (ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.V1_9) ? 0.005 : 0.003)) { + lmotionY = 0; + } + SimpleCollisionBox box = player.getMovement().getFrom().getBox().copy(); - box.offset(0, player.getMovement().getDeltaY(), 0); + double originalX = lmotionX, originalY = lmotionY, originalZ = lmotionZ; + if(it.sneaking && onGround) { + double d6; + + // 1.9+ changes from 0.05 to 0.03 + double protocolOffset = 0.05D; + + for (d6 = protocolOffset; lmotionX != 0.0D && Helper.getCollisions + (player.getBukkitPlayer().getWorld(), box.copy() + .offset(lmotionX, 0 ,0), Materials.SOLID).isEmpty(); originalX = lmotionX) { + if (lmotionX < d6 && lmotionX >= -d6) { + lmotionX = 0.0D; + } else if (lmotionX > 0.0D) { + lmotionX -= d6; + } else { + lmotionX += d6; + } + } + + for (; lmotionZ != 0.0D && Helper.getCollisions + (player.getBukkitPlayer().getWorld(), box.copy() + .offset(0, 0 ,lmotionZ), Materials.SOLID).isEmpty(); originalZ = lmotionZ) { + if (lmotionZ < d6 && lmotionZ >= -d6) { + lmotionZ = 0.0D; + } else if (lmotionZ > 0.0D) { + lmotionZ -= d6; + } else { + lmotionZ += d6; + } + } + + for (; lmotionX != 0.0D && lmotionZ != 0.0D && Helper.getCollisions + (player.getBukkitPlayer().getWorld(), box.copy() + .offset(lmotionX, -1.0 ,lmotionZ), Materials.SOLID).isEmpty(); + originalZ = lmotionZ) { + if (lmotionX < d6 && lmotionX >= -d6) { + lmotionX = 0.0D; + } else if (lmotionX > 0.0D) { + lmotionX -= d6; + } else { + lmotionX += d6; + } + + originalX = lmotionX; + + if (lmotionZ < d6 && lmotionZ >= -d6) { + lmotionZ = 0.0D; + } else if (lmotionZ > 0.0D) { + lmotionZ -= d6; + } else { + lmotionZ += d6; + } + } + } + + List collisionBoxes = Helper.getCollisions + (player.getBukkitPlayer().getWorld(), box.copy() + .addCoord(lmotionX ,lmotionY, lmotionZ), Materials.SOLID); + + for (SimpleCollisionBox blockBox : collisionBoxes) { + lmotionY = blockBox.calculateYOffset(box, lmotionY); + } + + box = box.offset(0, lmotionY, 0); + + boolean stepped = onGround && originalY != lmotionY && originalY < 0; + for (SimpleCollisionBox blockBox : collisionBoxes) { lmotionX = blockBox.calculateXOffset(box, lmotionX); } @@ -214,19 +294,130 @@ public class Horizontal extends Check { lmotionZ = blockBox.calculateZOffset(box, lmotionZ); } + box = box.offset(0, 0, lmotionZ); + + if(stepped && (lmotionX != originalX || lmotionZ != originalZ)) { + double d11 = lmotionX; + double d7 = lmotionY; + double d8 = lmotionZ; + SimpleCollisionBox axisalignedbb3 = box; + + box = player.getMovement().getFrom().getBox().copy(); + + lmotionY = 0.6; //Step height + List list = Helper + .getCollisions(player.getBukkitPlayer().getWorld(), + box.copy().addCoord(originalX, lmotionY, originalZ), + Materials.SOLID); + SimpleCollisionBox axisalignedbb4 = box; + SimpleCollisionBox axisalignedbb5 = axisalignedbb4.copy().addCoord(originalX, 0.0D, originalZ); + double d9 = lmotionY; + + for (SimpleCollisionBox axisalignedbb6 : list) { + d9 = axisalignedbb6.calculateYOffset(axisalignedbb5, d9); + } + + axisalignedbb4 = axisalignedbb4.copy().offset(0.0D, d9, 0.0D); + double d15 = originalX; + + for (SimpleCollisionBox axisalignedbb7 : list) { + d15 = axisalignedbb7.calculateXOffset(axisalignedbb4, d15); + } + + axisalignedbb4 = axisalignedbb4.offset(d15, 0.0D, 0.0D); + + double d16 = originalZ; + + for (SimpleCollisionBox axisalignedbb8 : list) { + d16 = axisalignedbb8.calculateZOffset(axisalignedbb4, d16); + } + + axisalignedbb4 = axisalignedbb4.offset(0.0D, 0.0D, d16); + SimpleCollisionBox axisalignedbb14 = box; + double d17 = lmotionY; + + for (SimpleCollisionBox axisalignedbb9 : list) { + d17 = axisalignedbb9.calculateYOffset(axisalignedbb14, d17); + } + + axisalignedbb14 = axisalignedbb14.copy().offset(0.0D, d17, 0.0D); + double d18 = originalX; + + for (SimpleCollisionBox axisalignedbb10 : list) { + d18 = axisalignedbb10.calculateXOffset(axisalignedbb14, d18); + } + + axisalignedbb14 = axisalignedbb14.copy().offset(d18, 0.0D, 0.0D); + double d19 = originalZ; + + for (SimpleCollisionBox axisalignedbb11 : list) { + d19 = axisalignedbb11.calculateZOffset(axisalignedbb14, d19); + } + + axisalignedbb14 = axisalignedbb14.copy().offset(0.0D, 0.0D, d19); + double d20 = d15 * d15 + d16 * d16; + double d10 = d18 * d18 + d19 * d19; + + if (d20 > d10) { + lmotionX = d15; + lmotionZ = d16; + lmotionY = -d9; + box = axisalignedbb4; + } else { + lmotionX = d18; + lmotionZ = d19; + lmotionY = -d17; + box = axisalignedbb14; + } + + for (SimpleCollisionBox axisalignedbb12 : list) { + lmotionY = axisalignedbb12.calculateYOffset(box, lmotionY); + } + + box = box.copy().offset(0.0D, lmotionY, 0.0D); + + if (d11 * d11 + d8 * d8 >= lmotionX * lmotionX + lmotionZ * lmotionZ) { + lmotionX = d11; + lmotionY = d7; + lmotionZ = d8; + box = axisalignedbb3; + } + } + + lmotionX = ((box.minX + box.maxX) / 2.0D) - player.getMovement().getFrom().getX(); + lmotionY = box.minY - player.getMovement().getFrom().getY(); + lmotionZ = ((box.minZ + box.maxZ) / 2.0D) - player.getMovement().getFrom().getZ(); + double diffX = player.getMovement().getDeltaX() - lmotionX, + diffY = player.getMovement().getDeltaY() - lmotionY, diffZ = player.getMovement().getDeltaZ() - lmotionZ; double delta = (diffX * diffX) + (diffZ * diffZ); + double deltaAll = delta + (diffY * diffY); + double deltaY = Math.abs(lmotionY - player.getMovement().getDeltaY()); - if (delta < smallestDelta) { - smallestDelta = delta; + if (deltaAll < smallDelta) { + smallDelta = deltaAll; + smallestDeltaXZ = delta; + smallestDeltaY = deltaY; pmotionx = lmotionX; pmotionz = lmotionZ; + pmotiony = lmotionY; - if (delta < 4E-17) { + if(stepped) { + overrideSet = true; + yOverride = 0; + xOverride = player.getMovement().getDeltaX(); + zOverride = player.getMovement().getDeltaZ(); + } else overrideSet = false; + + debug = "oY: " + originalY + ", ly:" + lmotionY + " stepped: " + stepped; + + if (deltaAll < 1E-16) { this.strafe = it.s * 0.98f; this.forward = it.f * 0.98f; + didBlockCollisionsInfluence = collisionBoxes.size() > 0; + if (player.getInfo().getLastCancel().isPassed(2)) player.getInfo() .setLastKnownGoodPosition(player @@ -236,26 +427,50 @@ public class Horizontal extends Check { } } } + + if(overrideSet) { + ldeltaX = xOverride; + ldeltaY = yOverride; + ldeltaZ = zOverride; + } + + debug(debug); iterations.clear(); double pmotion = Math.hypot(pmotionx, pmotionz); final double precision = getPrecision(); if (player.getMovement().getDeltaXZ() > pmotion - && smallestDelta > (precision) + && smallestDeltaXZ > (precision) && player.getMovement().getDeltaXZ() > 0.1) { - if ((buffer += smallestDelta > 58E-5 ? 1 : 0.5) > 1) { + if ((buffer += smallestDeltaXZ > 58E-5 ? 1 : 0.5) > 1) { buffer = Math.min(3.5f, buffer); //Ensuring we don't have a run-away buffer - flag("smallest=%s b=%.1f to=%s dxz=%.2f", smallestDelta, buffer, + flag("smallest=%s b=%.1f to=%s dxz=%.2f", smallestDeltaXZ, buffer, player.getMovement().getTo().getLoc(), player.getMovement().getDeltaXZ()); + cancel(); } else debug("bad movement"); } else if (buffer > 0) buffer -= 0.05f; - debug("smallest=%s sp=%s efcs=[%s] pm=%.5f dxz=%.5f b=%.1f", smallestDelta, + if(smallestDeltaY > 1E-10) { + double finalSmallestDeltaY = smallestDeltaY; + if(++vbuffer > 1) { + cancel(); + find(Vertical.class) + .ifPresent(vc -> vc.flag("dy=%.4f;sd=%s", player.getMovement().getDeltaY(), finalSmallestDeltaY)); + } + } else if(vbuffer > 0) vbuffer--; + + debug("sx=%s sy=%s py=%.5f dy=%.5f sp=%s efcs=[%s] pm=%.5f dxz=%.5f b=%.1f col=%s", smallestDeltaXZ, smallestDeltaY, + pmotiony, player.getMovement().getDeltaY(), player.getInfo().isSprinting(), player.getPotionHandler().potionEffects.stream() .map(pe -> pe.getType().getName() + ";" + pe.getAmplifier()) .collect(Collectors.joining(", ")), pmotion, - player.getMovement().getDeltaXZ(), buffer); + player.getMovement().getDeltaXZ(), buffer, didBlockCollisionsInfluence); + } + if(!overrideSet) { + ldeltaX = player.getMovement().getDeltaX(); + ldeltaY = player.getMovement().getDeltaY(); + ldeltaZ = player.getMovement().getDeltaZ(); } lastLastClientGround = player.getMovement().getFrom().isOnGround(); previousFrom = player.getMovement().getFrom().getLoc().clone(); @@ -329,6 +544,7 @@ public class Horizontal extends Check { private static boolean[] getJumpingIteration(boolean sprinting) { return sprinting ? new boolean[] {true, false} : new boolean[] {false}; } + private static final float[] SIN_TABLE_FAST = new float[4096], SIN_TABLE_FAST_NEW = new float[4096]; private static final float[] SIN_TABLE = new float[65536]; private static final float radToIndex = roundToFloat(651.8986469044033D); diff --git a/src/main/java/dev/brighten/ac/check/impl/movement/speed/Vertical.java b/src/main/java/dev/brighten/ac/check/impl/movement/speed/Vertical.java new file mode 100644 index 0000000..94b0c39 --- /dev/null +++ b/src/main/java/dev/brighten/ac/check/impl/movement/speed/Vertical.java @@ -0,0 +1,13 @@ +package dev.brighten.ac.check.impl.movement.speed; + +import dev.brighten.ac.api.check.CheckType; +import dev.brighten.ac.check.Check; +import dev.brighten.ac.check.CheckData; +import dev.brighten.ac.data.APlayer; + +@CheckData(name = "Vertical", checkId = "verticala", type = CheckType.MOVEMENT) +public class Vertical extends Check { + public Vertical(APlayer player) { + super(player); + } +} diff --git a/src/main/java/dev/brighten/ac/data/info/BlockInformation.java b/src/main/java/dev/brighten/ac/data/info/BlockInformation.java index fbe9647..4c33bdd 100644 --- a/src/main/java/dev/brighten/ac/data/info/BlockInformation.java +++ b/src/main/java/dev/brighten/ac/data/info/BlockInformation.java @@ -46,8 +46,8 @@ public class BlockInformation { if(!Anticheat.INSTANCE.isEnabled()) return; - double dy = player.getMovement().getDeltaY(); - double dh = player.getMovement().getDeltaXZ(); + double dy = Math.abs(player.getMovement().getDeltaY()) * 2; + double dh = player.getMovement().getDeltaXZ() * 2; blocks.clear(); @@ -61,15 +61,14 @@ public class BlockInformation { collisionMaterialCount.clear(); if(dy > 10) dy = 10; - else if(dy < -10) dy = -10; if(dh > 10) dh = 10; - int startX = Location.locToBlock(player.getMovement().getTo().getLoc().x - 0.6 - dh); - int endX = Location.locToBlock(player.getMovement().getTo().getLoc().x + 0.6 + dh); - int startY = Location.locToBlock(player.getMovement().getTo().getLoc().y - 0.6 + dy); - int endY = Location.locToBlock(player.getMovement().getTo().getLoc().y + 2.4 + dy); - int startZ = Location.locToBlock(player.getMovement().getTo().getLoc().z - 0.6 - dh); - int endZ = Location.locToBlock(player.getMovement().getTo().getLoc().z + 0.6 + dh); + int startX = Location.locToBlock(player.getMovement().getTo().getLoc().x - 1 - dh); + int endX = Location.locToBlock(player.getMovement().getTo().getLoc().x + 1 + dh); + int startY = Location.locToBlock(player.getMovement().getTo().getLoc().y - 1 - dy); + int endY = Location.locToBlock(player.getMovement().getTo().getLoc().y + 2.82 + dy); + int startZ = Location.locToBlock(player.getMovement().getTo().getLoc().z - 1 - dh); + int endZ = Location.locToBlock(player.getMovement().getTo().getLoc().z + 1 + dh); SimpleCollisionBox waterBox = player.getMovement().getTo().getBox().copy().expand(0, -.38, 0); @@ -104,7 +103,7 @@ public class BlockInformation { aboveCollisions.clear(); } final World world = player.getBukkitPlayer().getWorld(); - int it = 10 * 10; + int it = 12 * 12; int xstart = Math.min(startX, endX), xend = Math.max(startX, endX); int zstart = Math.min(startZ, endZ), zend = Math.max(startZ, endZ); diff --git a/src/main/java/dev/brighten/ac/utils/Helper.java b/src/main/java/dev/brighten/ac/utils/Helper.java index 9ee3e03..bdb2357 100644 --- a/src/main/java/dev/brighten/ac/utils/Helper.java +++ b/src/main/java/dev/brighten/ac/utils/Helper.java @@ -205,6 +205,31 @@ public class Helper { .collect(Collectors.toCollection(LinkedList::new)); } + public static List getCollisions(World world, SimpleCollisionBox collisionBox, int mask) { + int x1 = (int) Math.floor(collisionBox.minX); + int y1 = (int) Math.floor(collisionBox.minY); + int z1 = (int) Math.floor(collisionBox.minZ); + int x2 = (int) Math.floor(collisionBox.maxX + 1); + int y2 = (int) Math.floor(collisionBox.maxY + 1); + int z2 = (int) Math.floor(collisionBox.maxZ + 1); + List collisionBoxes = new ArrayList<>(); + Block block; + for (int x = x1; x < x2; x++) + for (int y = y1 - 1; y < y2; y++) + for (int z = z1; z < z2; z++) + if ((block = getBlockAt(world, x, y, z)) != null + && BlockUtils.getXMaterial(block.getType()) != XMaterial.AIR) + if (Materials.checkFlag(block.getType(),mask)) { + CollisionBox box = BlockData.getData(block.getType()) + .getBox(block, ProtocolVersion.getGameVersion()); + + if(box.isIntersected(collisionBox)) { + box.downCast(collisionBoxes); + } + } + return collisionBoxes; + } + public static List getBlocksNearby2(World world, SimpleCollisionBox collisionBox, int mask) { int x1 = (int) Math.floor(collisionBox.minX); int y1 = (int) Math.floor(collisionBox.minY);