mirror of
https://github.com/funkemunky/KauriV3.git
synced 2026-05-31 05:51:55 +00:00
Fixing world load fp in Fly A and accounting for collisions in Horizontal
This commit is contained in:
@@ -175,9 +175,8 @@ public class Check implements ECheck {
|
||||
|
||||
if(currentResult.isCancelled()) return;
|
||||
|
||||
Anticheat.INSTANCE.getScheduler()
|
||||
.execute(() -> Anticheat.INSTANCE.getLogManager()
|
||||
.insertLog(player, checkData, vl, System.currentTimeMillis(), info));
|
||||
Anticheat.INSTANCE.getLogManager()
|
||||
.insertLog(player, checkData, vl, System.currentTimeMillis(), info);
|
||||
|
||||
if(alertCountReset.isPassed(20)) {
|
||||
alertCount.set(0);
|
||||
@@ -186,7 +185,6 @@ public class Check implements ECheck {
|
||||
|
||||
if(alertCount.incrementAndGet() < 40) {
|
||||
boolean dev = Anticheat.INSTANCE.getTps() < 18;
|
||||
//if(vl > 0) Anticheat.INSTANCE.loggerManager.addLog(player, this, info);
|
||||
|
||||
//Sending Discord webhook alert
|
||||
|
||||
@@ -226,15 +224,23 @@ public class Check implements ECheck {
|
||||
if(!punishable || lastPunish.isNotPassed(20)) return;
|
||||
|
||||
lastPunish.reset();
|
||||
|
||||
PunishResult result = PunishResult.builder().cancelled(false).build();
|
||||
System.out.println("tried to punish");
|
||||
|
||||
List<String> commands = CheckConfig.punishmentCommands.stream().map(this::addPlaceHolders)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
PunishResult result = PunishResult.builder().cancelled(false).commands(commands).build();
|
||||
|
||||
for (AnticheatEvent event : AnticheatAPI.INSTANCE.getAllEvents()) {
|
||||
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()) {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package dev.brighten.ac.check.impl.combat;
|
||||
package dev.brighten.ac.check.impl.combat.aim;
|
||||
|
||||
import dev.brighten.ac.api.check.CheckType;
|
||||
import dev.brighten.ac.check.Check;
|
||||
@@ -61,8 +61,8 @@ public class KATrace extends Check {
|
||||
for (CollisionBox lookingAtBox : player.getMovement().getLookingAtBoxes()) {
|
||||
if((lookingAtBox instanceof SimpleCollisionBox)) {
|
||||
SimpleCollisionBox box = (SimpleCollisionBox) lookingAtBox;
|
||||
if(box.xMin % 1 != 0 || box.yMin % 1 != 0 || box.zMin % 1 != 0
|
||||
|| box.xMax % 1 != 0 || box.yMax % 1 != 0 || box.zMax % 1 != 0)
|
||||
if(box.minX % 1 != 0 || box.minY % 1 != 0 || box.minZ % 1 != 0
|
||||
|| box.maxX % 1 != 0 || box.maxY % 1 != 0 || box.maxZ % 1 != 0)
|
||||
continue;
|
||||
|
||||
Vector point = collision.collisionPoint(box.copy().shrink(0.005f, 0.005f, 0.005f));
|
||||
|
||||
@@ -77,6 +77,7 @@ public class FlyA extends Check {
|
||||
&& player.getInfo().getLastLiquid().isPassed(2)
|
||||
&& !player.getBlockInfo().fenceBelow
|
||||
&& !packet.isOnGround()
|
||||
&& player.getInfo().worldLoaded
|
||||
&& !player.getInfo().isServerGround()
|
||||
&& !player.getBlockInfo().onHalfBlock
|
||||
&& player.getInfo().getVelocity().isPassed(1)
|
||||
|
||||
@@ -7,16 +7,22 @@ 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.math.IntVector;
|
||||
import dev.brighten.ac.utils.world.types.SimpleCollisionBox;
|
||||
import dev.brighten.ac.utils.wrapper.Wrapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.val;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Deque;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CheckData(name = "Horizontal", checkId = "horizontala", type = CheckType.MOVEMENT)
|
||||
@@ -45,225 +51,198 @@ public class Horizontal extends Check {
|
||||
|| player.getInfo().getVelocity().isNotPassed(2)
|
||||
|| player.getInfo().isGeneralCancel()
|
||||
|| player.getBlockInfo().onClimbable
|
||||
|| player.getInfo().lastLiquid.isNotPassed(2)
|
||||
|| player.getBlockInfo().collidesHorizontally) {
|
||||
|| player.getInfo().lastLiquid.isNotPassed(2)) {
|
||||
break check;
|
||||
}
|
||||
|
||||
val underBlockLoc = previousFrom != null ? player.getMovement().getFrom().getLoc() : player.getMovement().getTo().getLoc();
|
||||
val lastUnderBlockLoc = previousFrom != null ? previousFrom : player.getMovement().getFrom().getLoc();
|
||||
|
||||
Deque<Material> frictionList = player.getBlockUpdateHandler()
|
||||
.getPossibleMaterials(new IntVector(MathHelper.floor_double(underBlockLoc.x),
|
||||
MathHelper.floor_double(underBlockLoc.y - 1), MathHelper.floor_double(underBlockLoc.z))),
|
||||
lfrictionList = player.getBlockUpdateHandler()
|
||||
.getPossibleMaterials(new IntVector(MathHelper.floor_double(lastUnderBlockLoc.x),
|
||||
MathHelper.floor_double(lastUnderBlockLoc.y - 1),
|
||||
MathHelper.floor_double(lastUnderBlockLoc.z)));
|
||||
|
||||
double smallestDelta = Double.MAX_VALUE;
|
||||
|
||||
double pmotionx = 0, pmotionz = 0;
|
||||
boolean onGround = player.getMovement().getFrom().isOnGround();
|
||||
|
||||
loop:
|
||||
{
|
||||
for (int f = -1; f < 2; f++) {
|
||||
for (Material underMaterial : frictionList) {
|
||||
for (Material lastUnderMaterial : lfrictionList) {
|
||||
for (int s = -1; s < 2; s++) {
|
||||
for (boolean sprinting : getSprintIteration(f)) {
|
||||
for (int fastMath = 0; fastMath <= 2; fastMath++) {
|
||||
for (boolean attack : TRUE_FALSE) {
|
||||
for (boolean motionModifiers : TRUE_FALSE) {
|
||||
for (boolean using : TRUE_FALSE) {
|
||||
for (boolean sneaking : getSneakingIteration(sprinting)) {
|
||||
for (boolean jumped : getJumpingIteration(sprinting)) {
|
||||
List<Iteration> iterations = getIteration();
|
||||
|
||||
float forward = f, strafe = s;
|
||||
for (Iteration it : iterations) {
|
||||
float forward = it.f, strafe = it.s;
|
||||
|
||||
if (sprinting && forward <= 0) {
|
||||
continue;
|
||||
}
|
||||
if (it.sprinting && forward <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sneaking) {
|
||||
forward *= 0.3;
|
||||
strafe *= 0.3;
|
||||
}
|
||||
if (it.sneaking) {
|
||||
forward *= 0.3;
|
||||
strafe *= 0.3;
|
||||
}
|
||||
|
||||
float friction = Wrapper.getInstance().getFriction(underMaterial);
|
||||
float lfriction = Wrapper.getInstance().getFriction(lastUnderMaterial);
|
||||
float friction = Wrapper.getInstance().getFriction(it.underMaterial);
|
||||
float lfriction = Wrapper.getInstance().getFriction(it.lastUnderMaterial);
|
||||
|
||||
if (using) {
|
||||
forward *= 0.2;
|
||||
strafe *= 0.2;
|
||||
}
|
||||
if (it.using) {
|
||||
forward *= 0.2;
|
||||
strafe *= 0.2;
|
||||
}
|
||||
|
||||
//Multiplying by 0.98 like in client
|
||||
forward *= 0.9800000190734863F;
|
||||
strafe *= 0.9800000190734863F;
|
||||
//Multiplying by 0.98 like in client
|
||||
forward *= 0.9800000190734863F;
|
||||
strafe *= 0.9800000190734863F;
|
||||
|
||||
double aiMoveSpeed = player.getBukkitPlayer().getWalkSpeed() / 2;
|
||||
double aiMoveSpeed = player.getBukkitPlayer().getWalkSpeed() / 2;
|
||||
|
||||
float drag = 0.91f;
|
||||
double lmotionX = player.getMovement().getLDeltaX(),
|
||||
lmotionZ = player.getMovement().getLDeltaZ();
|
||||
float drag = 0.91f;
|
||||
double lmotionX = player.getMovement().getLDeltaX(),
|
||||
lmotionZ = player.getMovement().getLDeltaZ();
|
||||
|
||||
if(motionModifiers) {
|
||||
if(player.getBlockInfo().onSoulSand
|
||||
&& player.getBlockInfo().collisionMaterialCount.
|
||||
containsKey(Material.SOUL_SAND)) {
|
||||
if(player.getBlockInfo().onSoulSand
|
||||
&& player.getBlockInfo().collisionMaterialCount.
|
||||
containsKey(Material.SOUL_SAND)) {
|
||||
|
||||
for(int i = 0
|
||||
; i < player.getBlockInfo()
|
||||
.collisionMaterialCount
|
||||
.get(Material.SOUL_SAND)
|
||||
; i++) {
|
||||
lmotionX*= 0.4;
|
||||
lmotionZ*= 0.4;
|
||||
}
|
||||
}
|
||||
for(int i = 0
|
||||
; i < player.getBlockInfo()
|
||||
.collisionMaterialCount
|
||||
.get(Material.SOUL_SAND)
|
||||
; i++) {
|
||||
lmotionX*= 0.4;
|
||||
lmotionZ*= 0.4;
|
||||
}
|
||||
}
|
||||
|
||||
/*if(!sneaking && player.getBlockInfo().onSlime
|
||||
&& player.getBlockInfo().collisionMaterialCount
|
||||
.containsKey(Material.SLIME_BLOCK)) {
|
||||
for(int i = 0 ; i < player.getBlockInfo()
|
||||
.collisionMaterialCount
|
||||
.get(Material.SLIME_BLOCK) ; i++) {
|
||||
lmotionX*=
|
||||
}
|
||||
}*/
|
||||
if(player.getBlockInfo().inWeb) {
|
||||
lmotionX*= 0.25;
|
||||
lmotionZ*= 0.25;
|
||||
}
|
||||
|
||||
if(player.getBlockInfo().inWeb) {
|
||||
lmotionX*= 0.25;
|
||||
lmotionZ*= 0.25;
|
||||
}
|
||||
}
|
||||
//The "1" will effectively remove lastFriction from the equation
|
||||
lmotionX *= (lastLastClientGround ? lfriction : 1) * 0.9100000262260437D;
|
||||
lmotionZ *= (lastLastClientGround ? lfriction : 1) * 0.9100000262260437D;
|
||||
|
||||
//The "1" will effectively remove lastFriction from the equation
|
||||
lmotionX *= (lastLastClientGround ? lfriction : 1) * 0.9100000262260437D;
|
||||
lmotionZ *= (lastLastClientGround ? lfriction : 1) * 0.9100000262260437D;
|
||||
//Running multiplication done after previous prediction
|
||||
if (player.getPlayerVersion().isOrAbove(ProtocolVersion.V1_9)) {
|
||||
if (Math.abs(lmotionX) < 0.003)
|
||||
lmotionX = 0;
|
||||
if (Math.abs(lmotionZ) < 0.003)
|
||||
lmotionZ = 0;
|
||||
} else {
|
||||
if (Math.abs(lmotionX) < 0.005)
|
||||
lmotionX = 0;
|
||||
if (Math.abs(lmotionZ) < 0.005)
|
||||
lmotionZ = 0;
|
||||
}
|
||||
|
||||
//Running multiplication done after previous prediction
|
||||
if (player.getPlayerVersion().isOrAbove(ProtocolVersion.V1_9)) {
|
||||
if (Math.abs(lmotionX) < 0.003)
|
||||
lmotionX = 0;
|
||||
if (Math.abs(lmotionZ) < 0.003)
|
||||
lmotionZ = 0;
|
||||
} else {
|
||||
if (Math.abs(lmotionX) < 0.005)
|
||||
lmotionX = 0;
|
||||
if (Math.abs(lmotionZ) < 0.005)
|
||||
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;
|
||||
lmotionZ *= 0.6;
|
||||
}
|
||||
|
||||
//Less than 0.05
|
||||
if(((lmotionX * lmotionX) + (lmotionZ * lmotionZ)) < 0.0025 && player.getMovement().getDeltaXZ() < 0.2) {
|
||||
break check;
|
||||
}
|
||||
// Attack slowdown
|
||||
if (attack) {
|
||||
lmotionX *= 0.6;
|
||||
lmotionZ *= 0.6;
|
||||
}
|
||||
if (it.sprinting)
|
||||
aiMoveSpeed += aiMoveSpeed * 0.30000001192092896D;
|
||||
|
||||
if (sprinting)
|
||||
aiMoveSpeed += aiMoveSpeed * 0.30000001192092896D;
|
||||
if (player.getPotionHandler().hasPotionEffect(PotionEffectType.SPEED))
|
||||
aiMoveSpeed += (player.getPotionHandler().getEffectByType(PotionEffectType.SPEED)
|
||||
.get()
|
||||
.getAmplifier() + 1) * (double) 0.20000000298023224D * aiMoveSpeed;
|
||||
if (player.getPotionHandler().hasPotionEffect(PotionEffectType.SLOW))
|
||||
aiMoveSpeed += (player.getPotionHandler().getEffectByType(PotionEffectType.SLOW)
|
||||
.get()
|
||||
.getAmplifier() + 1) * (double) -0.15000000596046448D * aiMoveSpeed;
|
||||
|
||||
if (player.getPotionHandler().hasPotionEffect(PotionEffectType.SPEED))
|
||||
aiMoveSpeed += (player.getPotionHandler().getEffectByType(PotionEffectType.SPEED)
|
||||
.get()
|
||||
.getAmplifier() + 1) * (double) 0.20000000298023224D * aiMoveSpeed;
|
||||
if (player.getPotionHandler().hasPotionEffect(PotionEffectType.SLOW))
|
||||
aiMoveSpeed += (player.getPotionHandler().getEffectByType(PotionEffectType.SLOW)
|
||||
.get()
|
||||
.getAmplifier() + 1) * (double) -0.15000000596046448D * aiMoveSpeed;
|
||||
float f5;
|
||||
if (onGround) {
|
||||
drag *= friction;
|
||||
|
||||
float f5;
|
||||
if (onGround) {
|
||||
drag *= friction;
|
||||
f5 = (float) (aiMoveSpeed * (0.16277136F / (drag * drag * drag)));
|
||||
|
||||
f5 = (float) (aiMoveSpeed * (0.16277136F / (drag * drag * drag)));
|
||||
if (it.sprinting && it.jumped) {
|
||||
float rot = player.getMovement().getTo().getLoc().yaw * 0.017453292F;
|
||||
lmotionX -= sin(it.fastMath, rot) * 0.2F;
|
||||
lmotionZ += cos(it.fastMath, rot) * 0.2F;
|
||||
}
|
||||
|
||||
if (sprinting && jumped) {
|
||||
float rot = player.getMovement().getTo().getLoc().yaw * 0.017453292F;
|
||||
lmotionX -= sin(fastMath, rot) * 0.2F;
|
||||
lmotionZ += cos(fastMath, rot) * 0.2F;
|
||||
}
|
||||
} else f5 = it.sprinting ? 0.025999999F : 0.02f;
|
||||
|
||||
} else f5 = sprinting ? 0.025999999F : 0.02f;
|
||||
if (player.getPlayerVersion().isOrAbove(ProtocolVersion.V1_9)) {
|
||||
double keyedMotion = forward * forward + strafe * strafe;
|
||||
|
||||
if (player.getPlayerVersion().isOrAbove(ProtocolVersion.V1_9)) {
|
||||
double keyedMotion = forward * forward + strafe * strafe;
|
||||
if (keyedMotion >= 1.0E-4F) {
|
||||
keyedMotion = f5 / Math.max(1.0, Math.sqrt(keyedMotion));
|
||||
forward *= keyedMotion;
|
||||
strafe *= keyedMotion;
|
||||
|
||||
if (keyedMotion >= 1.0E-4F) {
|
||||
keyedMotion = f5 / Math.max(1.0, Math.sqrt(keyedMotion));
|
||||
forward *= keyedMotion;
|
||||
strafe *= keyedMotion;
|
||||
final float yawSin = sin(it.fastMath,
|
||||
player.getMovement().getTo().getLoc().yaw * (float) Math.PI / 180.F),
|
||||
yawCos = cos(it.fastMath,
|
||||
player.getMovement().getTo().getLoc().yaw * (float) Math.PI / 180.F);
|
||||
|
||||
final float yawSin = sin(fastMath,
|
||||
player.getMovement().getTo().getLoc().yaw * (float) Math.PI / 180.F),
|
||||
yawCos = cos(fastMath,
|
||||
player.getMovement().getTo().getLoc().yaw * (float) Math.PI / 180.F);
|
||||
lmotionX += (strafe * yawCos - forward * yawSin);
|
||||
lmotionZ += (forward * yawCos + strafe * yawSin);
|
||||
}
|
||||
} else {
|
||||
float keyedMotion = forward * forward + strafe * strafe;
|
||||
|
||||
lmotionX += (strafe * yawCos - forward * yawSin);
|
||||
lmotionZ += (forward * yawCos + strafe * yawSin);
|
||||
}
|
||||
} else {
|
||||
float keyedMotion = forward * forward + strafe * strafe;
|
||||
if (keyedMotion >= 1.0E-4F) {
|
||||
keyedMotion = f5 / Math.max(1.0f, MathHelper.sqrt_float(keyedMotion));
|
||||
forward *= keyedMotion;
|
||||
strafe *= keyedMotion;
|
||||
|
||||
if (keyedMotion >= 1.0E-4F) {
|
||||
keyedMotion = f5 / Math.max(1.0f, MathHelper.sqrt_float(keyedMotion));
|
||||
forward *= keyedMotion;
|
||||
strafe *= keyedMotion;
|
||||
final float yawSin = sin(it.fastMath,
|
||||
player.getMovement().getTo().getLoc().yaw * (float) Math.PI / 180.F),
|
||||
yawCos = cos(it.fastMath,
|
||||
player.getMovement().getTo().getLoc().yaw * (float) Math.PI / 180.F);
|
||||
|
||||
final float yawSin = sin(fastMath,
|
||||
player.getMovement().getTo().getLoc().yaw * (float) Math.PI / 180.F),
|
||||
yawCos = cos(fastMath,
|
||||
player.getMovement().getTo().getLoc().yaw * (float) Math.PI / 180.F);
|
||||
lmotionX += (strafe * yawCos - forward * yawSin);
|
||||
lmotionZ += (forward * yawCos + strafe * yawSin);
|
||||
}
|
||||
}
|
||||
|
||||
lmotionX += (strafe * yawCos - forward * yawSin);
|
||||
lmotionZ += (forward * yawCos + strafe * yawSin);
|
||||
}
|
||||
}
|
||||
double diffX = player.getMovement().getDeltaX() - lmotionX,
|
||||
diffZ = player.getMovement().getDeltaZ() - lmotionZ;
|
||||
double delta = (diffX * diffX) + (diffZ * diffZ);
|
||||
List<SimpleCollisionBox> collisionBoxes = Helper.toCollisionsDowncasted(Helper.blockCollisions
|
||||
(player.getBlockInfo().blocks, player.getMovement().getFrom().getBox().copy()
|
||||
.addCoord(lmotionX ,player.getMovement().getDeltaY(), lmotionZ), Materials.SOLID));
|
||||
SimpleCollisionBox box = player.getMovement().getFrom().getBox().copy();
|
||||
|
||||
if (delta < smallestDelta) {
|
||||
smallestDelta = delta;
|
||||
pmotionx = lmotionX;
|
||||
pmotionz = lmotionZ;
|
||||
box.offset(0, player.getMovement().getDeltaY(), 0);
|
||||
for (SimpleCollisionBox blockBox : collisionBoxes) {
|
||||
lmotionX = blockBox.calculateXOffset(box, lmotionX);
|
||||
}
|
||||
|
||||
if (delta < 4E-17) {
|
||||
this.strafe = s * 0.98f;
|
||||
this.forward = f * 0.98f;
|
||||
box = box.offset(lmotionX,0,0);
|
||||
for (SimpleCollisionBox blockBox : collisionBoxes) {
|
||||
lmotionZ = blockBox.calculateZOffset(box, lmotionZ);
|
||||
}
|
||||
|
||||
if (player.getInfo().getLastCancel().isPassed(2))
|
||||
player.getInfo()
|
||||
.setLastKnownGoodPosition(player
|
||||
.getMovement().getFrom().getLoc()
|
||||
.clone());
|
||||
break loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
double diffX = player.getMovement().getDeltaX() - lmotionX,
|
||||
diffZ = player.getMovement().getDeltaZ() - lmotionZ;
|
||||
double delta = (diffX * diffX) + (diffZ * diffZ);
|
||||
|
||||
if (delta < smallestDelta) {
|
||||
smallestDelta = delta;
|
||||
pmotionx = lmotionX;
|
||||
pmotionz = lmotionZ;
|
||||
|
||||
if (delta < 4E-17) {
|
||||
this.strafe = it.s * 0.98f;
|
||||
this.forward = it.f * 0.98f;
|
||||
|
||||
if (player.getInfo().getLastCancel().isPassed(2))
|
||||
player.getInfo()
|
||||
.setLastKnownGoodPosition(player
|
||||
.getMovement().getFrom().getLoc()
|
||||
.clone());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
iterations.clear();
|
||||
|
||||
double pmotion = Math.hypot(pmotionx, pmotionz);
|
||||
final double precision = getPrecision();
|
||||
|
||||
if (player.getMovement().getDeltaXZ() > pmotion
|
||||
&& smallestDelta > (player.getBlockInfo().onSoulSand ? 0.01 : 5E-13)
|
||||
&& smallestDelta > (precision)
|
||||
&& player.getMovement().getDeltaXZ() > 0.1) {
|
||||
if ((buffer += smallestDelta > 58E-5 ? 1 : 0.5) > 1) {
|
||||
buffer = Math.min(3.5f, buffer); //Ensuring we don't have a run-away buffer
|
||||
@@ -282,6 +261,58 @@ public class Horizontal extends Check {
|
||||
previousFrom = player.getMovement().getFrom().getLoc().clone();
|
||||
};
|
||||
|
||||
private double getPrecision() {
|
||||
if(player.getBlockInfo().onSoulSand) {
|
||||
return 5E-4;
|
||||
}
|
||||
return 5E-13;
|
||||
}
|
||||
|
||||
private List<Iteration> getIteration() {
|
||||
List<Iteration> iterations = new ArrayList<>();
|
||||
val underBlockLoc = previousFrom != null ? player.getMovement().getFrom().getLoc() : player.getMovement().getTo().getLoc();
|
||||
val lastUnderBlockLoc = previousFrom != null ? previousFrom : player.getMovement().getFrom().getLoc();
|
||||
|
||||
Deque<Material> frictionList = player.getBlockUpdateHandler()
|
||||
.getPossibleMaterials(new IntVector(MathHelper.floor_double(underBlockLoc.x),
|
||||
MathHelper.floor_double(underBlockLoc.y - 1), MathHelper.floor_double(underBlockLoc.z))),
|
||||
lfrictionList = player.getBlockUpdateHandler()
|
||||
.getPossibleMaterials(new IntVector(MathHelper.floor_double(lastUnderBlockLoc.x),
|
||||
MathHelper.floor_double(lastUnderBlockLoc.y - 1),
|
||||
MathHelper.floor_double(lastUnderBlockLoc.z)));
|
||||
for (int f = -1; f < 2; f++) {
|
||||
for (Material underMaterial : frictionList) {
|
||||
for (Material lastUnderMaterial : lfrictionList) {
|
||||
for (int s = -1; s < 2; s++) {
|
||||
for (boolean sprinting : getSprintIteration(f)) {
|
||||
for (int fastMath = 0; fastMath <= 2; fastMath++) {
|
||||
for (boolean attack : TRUE_FALSE) {
|
||||
for (boolean using : TRUE_FALSE) {
|
||||
for (boolean sneaking : getSneakingIteration(sprinting)) {
|
||||
for (boolean jumped : getJumpingIteration(sprinting)) {
|
||||
iterations.add(new Iteration(underMaterial, lastUnderMaterial, f, s,
|
||||
fastMath, sprinting, attack, using, sneaking, jumped));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return iterations;
|
||||
}
|
||||
|
||||
|
||||
@AllArgsConstructor
|
||||
private static class Iteration {
|
||||
public Material underMaterial, lastUnderMaterial;
|
||||
public int f, s, fastMath;
|
||||
public boolean sprinting, attack, using, sneaking, jumped;
|
||||
}
|
||||
|
||||
private static boolean[] getSprintIteration(int f) {
|
||||
if(f > 0) {
|
||||
|
||||
@@ -49,13 +49,13 @@ public class BlockA extends Check {
|
||||
|
||||
final SimpleCollisionBox simpleBox = ((SimpleCollisionBox) box);
|
||||
|
||||
if(Math.abs(simpleBox.yMax - simpleBox.yMin) != 1.
|
||||
|| Math.abs(simpleBox.xMax - simpleBox.xMin) != 1.
|
||||
|| Math.abs(simpleBox.zMax - simpleBox.zMin) != 1.) {
|
||||
if(Math.abs(simpleBox.maxY - simpleBox.minY) != 1.
|
||||
|| Math.abs(simpleBox.maxX - simpleBox.minX) != 1.
|
||||
|| Math.abs(simpleBox.maxZ - simpleBox.minZ) != 1.) {
|
||||
debug("not full block: x=%.1f y=%.1f z=%.1f",
|
||||
Math.abs(simpleBox.xMax - simpleBox.xMin),
|
||||
Math.abs(simpleBox.yMax - simpleBox.yMin),
|
||||
Math.abs(simpleBox.zMax - simpleBox.zMin));
|
||||
Math.abs(simpleBox.maxX - simpleBox.minX),
|
||||
Math.abs(simpleBox.maxY - simpleBox.minY),
|
||||
Math.abs(simpleBox.maxZ - simpleBox.minZ));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import dev.brighten.ac.utils.world.BlockData;
|
||||
import dev.brighten.ac.utils.world.CollisionBox;
|
||||
import dev.brighten.ac.utils.world.EntityData;
|
||||
import dev.brighten.ac.utils.world.types.SimpleCollisionBox;
|
||||
import dev.brighten.ac.utils.wrapper.Wrapper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@@ -74,21 +73,21 @@ public class BlockInformation {
|
||||
|
||||
SimpleCollisionBox waterBox = player.getMovement().getTo().getBox().copy().expand(0, -.38, 0);
|
||||
|
||||
waterBox.xMin = MathHelper.floor_double(waterBox.xMin);
|
||||
waterBox.yMin = MathHelper.floor_double(waterBox.yMin);
|
||||
waterBox.zMin = MathHelper.floor_double(waterBox.zMin);
|
||||
waterBox.xMax = MathHelper.floor_double(waterBox.xMax + 1.);
|
||||
waterBox.yMax = MathHelper.floor_double(waterBox.yMax + 1.);
|
||||
waterBox.zMax = MathHelper.floor_double(waterBox.zMax + 1.);
|
||||
waterBox.minX = MathHelper.floor_double(waterBox.minX);
|
||||
waterBox.minY = MathHelper.floor_double(waterBox.minY);
|
||||
waterBox.minZ = MathHelper.floor_double(waterBox.minZ);
|
||||
waterBox.maxX = MathHelper.floor_double(waterBox.maxX + 1.);
|
||||
waterBox.maxY = MathHelper.floor_double(waterBox.maxY + 1.);
|
||||
waterBox.maxZ = MathHelper.floor_double(waterBox.maxZ + 1.);
|
||||
|
||||
SimpleCollisionBox lavaBox = player.getMovement().getTo().getBox().copy().expand(-.1f, -.4f, -.1f);
|
||||
|
||||
lavaBox.xMin = MathHelper.floor_double(waterBox.xMin);
|
||||
lavaBox.yMin = MathHelper.floor_double(waterBox.yMin);
|
||||
lavaBox.zMin = MathHelper.floor_double(waterBox.zMin);
|
||||
lavaBox.xMax = MathHelper.floor_double(waterBox.xMax + 1.);
|
||||
lavaBox.yMax = MathHelper.floor_double(waterBox.yMax + 1.);
|
||||
lavaBox.zMax = MathHelper.floor_double(waterBox.zMax + 1.);
|
||||
lavaBox.minX = MathHelper.floor_double(waterBox.minX);
|
||||
lavaBox.minY = MathHelper.floor_double(waterBox.minY);
|
||||
lavaBox.minZ = MathHelper.floor_double(waterBox.minZ);
|
||||
lavaBox.maxX = MathHelper.floor_double(waterBox.maxX + 1.);
|
||||
lavaBox.maxY = MathHelper.floor_double(waterBox.maxY + 1.);
|
||||
lavaBox.maxZ = MathHelper.floor_double(waterBox.maxZ + 1.);
|
||||
|
||||
SimpleCollisionBox normalBox = player.getMovement().getTo().getBox().copy();
|
||||
|
||||
@@ -107,26 +106,6 @@ public class BlockInformation {
|
||||
final World world = player.getBukkitPlayer().getWorld();
|
||||
int it = 10 * 10;
|
||||
|
||||
if(player.getMovement().getFrom().getBox() != null) {
|
||||
SimpleCollisionBox boundsForCollision = player.getMovement().getFrom().getBox().copy().shrink(0.001D, 0.001D, 0.001D);
|
||||
|
||||
IntVector min = new IntVector((int) boundsForCollision.xMin, (int) boundsForCollision.yMin, (int) boundsForCollision.zMin);
|
||||
IntVector max = new IntVector((int) boundsForCollision.xMax, (int) boundsForCollision.yMax, (int) boundsForCollision.zMax);
|
||||
|
||||
for(int x = min.getX() ; x <= max.getX() ; x++) {
|
||||
for(int y = min.getY() ; y <= max.getY() ; y++) {
|
||||
for(int z = min.getZ() ; z <= max.getZ() ; z++) {
|
||||
Material type = Wrapper.getInstance().getType(player.getBukkitPlayer().getWorld(), x, y, z);
|
||||
|
||||
collisionMaterialCount.compute(type, (key, count) -> {
|
||||
if(count == null) return 1;
|
||||
|
||||
return count + 1;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int xstart = Math.min(startX, endX), xend = Math.max(startX, endX);
|
||||
int zstart = Math.min(startZ, endZ), zend = Math.max(startZ, endZ);
|
||||
|
||||
@@ -136,8 +115,8 @@ public class BlockInformation {
|
||||
IntVector max;
|
||||
|
||||
if(boundsForCollision != null) {
|
||||
min = new IntVector((int) boundsForCollision.xMin, (int) boundsForCollision.yMin, (int) boundsForCollision.zMin);
|
||||
max = new IntVector((int) boundsForCollision.xMax, (int) boundsForCollision.yMax, (int) boundsForCollision.zMax);
|
||||
min = new IntVector((int) boundsForCollision.minX, (int) boundsForCollision.minY, (int) boundsForCollision.minZ);
|
||||
max = new IntVector((int) boundsForCollision.maxX, (int) boundsForCollision.maxY, (int) boundsForCollision.maxZ);
|
||||
} else {
|
||||
min = new IntVector(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
max = new IntVector(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
|
||||
|
||||
@@ -37,7 +37,6 @@ public class LoggerManager {
|
||||
WebSocket socket = new WebSocketFactory().createSocket("ws://port.funkemunky.cc/chat").connect();
|
||||
|
||||
System.out.println("Writing logs");
|
||||
Log log;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
|
||||
@@ -45,8 +44,12 @@ public class LoggerManager {
|
||||
oos.writeUTF(license());
|
||||
|
||||
int i = 0;
|
||||
while((log = logList.poll()) != null && i++ < 400) {
|
||||
oos.writeUTF(log.toJson());
|
||||
while(logList.size() > 0 && i++ < 400) {
|
||||
Log log = logList.poll();
|
||||
|
||||
if(log != null) {
|
||||
oos.writeUTF(log.toJson());
|
||||
}
|
||||
}
|
||||
|
||||
if(i == 0) {
|
||||
@@ -61,7 +64,7 @@ public class LoggerManager {
|
||||
|
||||
socket.disconnect();
|
||||
} catch (IOException | WebSocketException e) {
|
||||
throw new RuntimeException(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, 200, 200, TimeUnit.MILLISECONDS);
|
||||
|
||||
@@ -34,12 +34,12 @@ public class AxisAlignedBB {
|
||||
}
|
||||
|
||||
public AxisAlignedBB(SimpleCollisionBox box) {
|
||||
this.minX = box.xMin;
|
||||
this.minY = box.yMin;
|
||||
this.minZ = box.zMin;
|
||||
this.maxX = box.xMax;
|
||||
this.maxY = box.yMax;
|
||||
this.maxZ = box.zMax;
|
||||
this.minX = box.minX;
|
||||
this.minY = box.minY;
|
||||
this.minZ = box.minZ;
|
||||
this.maxX = box.maxX;
|
||||
this.maxY = box.maxY;
|
||||
this.maxZ = box.maxZ;
|
||||
}
|
||||
|
||||
public AxisAlignedBB(Location blockposition, Location blockposition1) {
|
||||
|
||||
@@ -60,9 +60,9 @@ public class Helper {
|
||||
|
||||
|
||||
public static void drawCuboid(SimpleCollisionBox box, EnumParticle particle, Collection<? extends Player> players) {
|
||||
Step.GenericStepper<Float> x = Step.step((float)box.xMin, 0.241F, (float)box.xMax);
|
||||
Step.GenericStepper<Float> y = Step.step((float)box.yMin, 0.241F, (float)box.yMax);
|
||||
Step.GenericStepper<Float> z = Step.step((float)box.zMin, 0.241F, (float)box.zMax);
|
||||
Step.GenericStepper<Float> x = Step.step((float)box.minX, 0.241F, (float)box.maxX);
|
||||
Step.GenericStepper<Float> y = Step.step((float)box.minY, 0.241F, (float)box.maxY);
|
||||
Step.GenericStepper<Float> z = Step.step((float)box.minZ, 0.241F, (float)box.maxZ);
|
||||
Iterator var6 = x.iterator();
|
||||
|
||||
while(var6.hasNext()) {
|
||||
@@ -151,12 +151,12 @@ public class Helper {
|
||||
}
|
||||
|
||||
public static SimpleCollisionBox wrap(SimpleCollisionBox a, SimpleCollisionBox b) {
|
||||
double minX = Math.min(a.xMin, b.xMin);
|
||||
double minY = Math.min(a.yMin, b.yMin);
|
||||
double minZ = Math.min(a.zMin, b.zMin);
|
||||
double maxX = Math.max(a.xMax, b.xMax);
|
||||
double maxY = Math.max(a.yMax, b.yMax);
|
||||
double maxZ = Math.max(a.zMax, b.zMax);
|
||||
double minX = Math.min(a.minX, b.minX);
|
||||
double minY = Math.min(a.minY, b.minY);
|
||||
double minZ = Math.min(a.minZ, b.minZ);
|
||||
double maxX = Math.max(a.maxX, b.maxX);
|
||||
double maxY = Math.max(a.maxY, b.maxY);
|
||||
double maxZ = Math.max(a.maxZ, b.maxZ);
|
||||
return new SimpleCollisionBox(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
@@ -165,12 +165,12 @@ public class Helper {
|
||||
SimpleCollisionBox wrap = box.get(0).copy();
|
||||
for (int i = 1; i < box.size(); i++) {
|
||||
SimpleCollisionBox a = box.get(i);
|
||||
if (wrap.xMin > a.xMin) wrap.xMin = a.xMin;
|
||||
if (wrap.yMin > a.yMin) wrap.yMin = a.yMin;
|
||||
if (wrap.zMin > a.zMin) wrap.zMin = a.zMin;
|
||||
if (wrap.xMax < a.xMax) wrap.xMax = a.xMax;
|
||||
if (wrap.yMax < a.yMax) wrap.yMax = a.yMax;
|
||||
if (wrap.zMax < a.zMax) wrap.zMax = a.zMax;
|
||||
if (wrap.minX > a.minX) wrap.minX = a.minX;
|
||||
if (wrap.minY > a.minY) wrap.minY = a.minY;
|
||||
if (wrap.minZ > a.minZ) wrap.minZ = a.minZ;
|
||||
if (wrap.maxX < a.maxX) wrap.maxX = a.maxX;
|
||||
if (wrap.maxY < a.maxY) wrap.maxY = a.maxY;
|
||||
if (wrap.maxZ < a.maxZ) wrap.maxZ = a.maxZ;
|
||||
}
|
||||
return wrap;
|
||||
}
|
||||
@@ -188,9 +188,9 @@ public class Helper {
|
||||
|
||||
other.downCast(downcasted);
|
||||
|
||||
return downcasted.stream().anyMatch(box -> box.xMax >= toCheck.xMin && box.xMin <= toCheck.xMax
|
||||
&& box.yMax >= toCheck.yMin && box.yMin <= toCheck.yMax && box.zMax >= toCheck.zMin
|
||||
&& box.zMin <= toCheck.zMax);
|
||||
return downcasted.stream().anyMatch(box -> box.maxX >= toCheck.minX && box.minX <= toCheck.maxX
|
||||
&& box.maxY >= toCheck.minY && box.minY <= toCheck.maxY && box.maxZ >= toCheck.minZ
|
||||
&& box.minZ <= toCheck.maxZ);
|
||||
}
|
||||
|
||||
public static List<Block> blockCollisions(List<Block> blocks, CollisionBox box, int material) {
|
||||
@@ -206,12 +206,12 @@ public class Helper {
|
||||
}
|
||||
|
||||
public static List<Block> getBlocksNearby2(World world, SimpleCollisionBox collisionBox, int mask) {
|
||||
int x1 = (int) Math.floor(collisionBox.xMin);
|
||||
int y1 = (int) Math.floor(collisionBox.yMin);
|
||||
int z1 = (int) Math.floor(collisionBox.zMin);
|
||||
int x2 = (int) Math.ceil(collisionBox.xMax);
|
||||
int y2 = (int) Math.ceil(collisionBox.yMax);
|
||||
int z2 = (int) Math.ceil(collisionBox.zMax);
|
||||
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.ceil(collisionBox.maxX);
|
||||
int y2 = (int) Math.ceil(collisionBox.maxY);
|
||||
int z2 = (int) Math.ceil(collisionBox.maxZ);
|
||||
List<Block> blocks = new LinkedList<>();
|
||||
Block block;
|
||||
for (int x = x1; x <= x2; x++)
|
||||
|
||||
@@ -49,12 +49,12 @@ public class MiscUtils {
|
||||
}
|
||||
}
|
||||
public static boolean isInMaterialBB(World world, SimpleCollisionBox entityBox, XMaterial xmaterial) {
|
||||
int startX = MathHelper.floor_double(entityBox.xMin);
|
||||
int startY = MathHelper.floor_double(entityBox.yMin);
|
||||
int startZ = MathHelper.floor_double(entityBox.zMin);
|
||||
int endX = MathHelper.floor_double(entityBox.xMax + 1D);
|
||||
int endY = MathHelper.floor_double(entityBox.yMax + 1D);
|
||||
int endZ = MathHelper.floor_double(entityBox.zMax + 1D);
|
||||
int startX = MathHelper.floor_double(entityBox.minX);
|
||||
int startY = MathHelper.floor_double(entityBox.minY);
|
||||
int startZ = MathHelper.floor_double(entityBox.minZ);
|
||||
int endX = MathHelper.floor_double(entityBox.maxX + 1D);
|
||||
int endY = MathHelper.floor_double(entityBox.maxY + 1D);
|
||||
int endZ = MathHelper.floor_double(entityBox.maxZ + 1D);
|
||||
|
||||
for(int x = startX ; x < endX ; x++) {
|
||||
for(int y = startY ; y < endY ; y++) {
|
||||
@@ -73,12 +73,12 @@ public class MiscUtils {
|
||||
}
|
||||
|
||||
public static boolean isInMaterialBB(World world, SimpleCollisionBox entityBox, int bitmask) {
|
||||
int startX = MathHelper.floor_double(entityBox.xMin);
|
||||
int startY = MathHelper.floor_double(entityBox.yMin);
|
||||
int startZ = MathHelper.floor_double(entityBox.zMin);
|
||||
int endX = MathHelper.floor_double(entityBox.xMax + 1D);
|
||||
int endY = MathHelper.floor_double(entityBox.yMax + 1D);
|
||||
int endZ = MathHelper.floor_double(entityBox.zMax + 1D);
|
||||
int startX = MathHelper.floor_double(entityBox.minX);
|
||||
int startY = MathHelper.floor_double(entityBox.minY);
|
||||
int startZ = MathHelper.floor_double(entityBox.minZ);
|
||||
int endX = MathHelper.floor_double(entityBox.maxX + 1D);
|
||||
int endY = MathHelper.floor_double(entityBox.maxY + 1D);
|
||||
int endZ = MathHelper.floor_double(entityBox.maxZ + 1D);
|
||||
|
||||
for(int x = startX ; x < endX ; x++) {
|
||||
for(int y = startY ; y < endY ; y++) {
|
||||
|
||||
@@ -37,7 +37,7 @@ public class MovementUtils {
|
||||
public static boolean isOnLadder(APlayer data) {
|
||||
try {
|
||||
int i = MathHelper.floor_double(data.getMovement().getTo().getLoc().x);
|
||||
int j = MathHelper.floor_double(data.getMovement().getTo().getBox().yMin);
|
||||
int j = MathHelper.floor_double(data.getMovement().getTo().getBox().minY);
|
||||
int k = MathHelper.floor_double(data.getMovement().getTo().getLoc().z);
|
||||
Block block = BlockUtils.getBlock(new Location(data.getBukkitPlayer().getWorld(), i, j, k));
|
||||
|
||||
@@ -111,13 +111,13 @@ public class MovementUtils {
|
||||
if(box instanceof SimpleCollisionBox) {
|
||||
SimpleCollisionBox sbox = (SimpleCollisionBox) box;
|
||||
|
||||
return new Location(block.get().getWorld(), x, sbox.yMax, z);
|
||||
return new Location(block.get().getWorld(), x, sbox.maxY, z);
|
||||
} else {
|
||||
List<SimpleCollisionBox> sboxes = new ArrayList<>();
|
||||
|
||||
box.downCast(sboxes);
|
||||
|
||||
double maxY = sboxes.stream().max(Comparator.comparing(sbox -> sbox.yMax)).map(s -> s.yMax)
|
||||
double maxY = sboxes.stream().max(Comparator.comparing(sbox -> sbox.maxY)).map(s -> s.maxY)
|
||||
.orElse(y + 1.);
|
||||
|
||||
return new Location(block.get().getWorld(), x, maxY, z);
|
||||
@@ -148,13 +148,13 @@ public class MovementUtils {
|
||||
if(box instanceof SimpleCollisionBox) {
|
||||
SimpleCollisionBox sbox = (SimpleCollisionBox) box;
|
||||
|
||||
return new Location(block.get().getWorld(), x, sbox.yMax, z);
|
||||
return new Location(block.get().getWorld(), x, sbox.maxY, z);
|
||||
} else {
|
||||
List<SimpleCollisionBox> sboxes = new ArrayList<>();
|
||||
|
||||
box.downCast(sboxes);
|
||||
|
||||
double maxY = sboxes.stream().max(Comparator.comparing(sbox -> sbox.yMax)).map(s -> s.yMax)
|
||||
double maxY = sboxes.stream().max(Comparator.comparing(sbox -> sbox.maxY)).map(s -> s.maxY)
|
||||
.orElse(y + 1.);
|
||||
|
||||
return new Location(block.get().getWorld(), x, maxY, z);
|
||||
|
||||
@@ -244,11 +244,11 @@ public class MinecraftReflection {
|
||||
if(ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.V1_8)) {
|
||||
return idioticOldStaticConstructorAABB
|
||||
.invoke(null,
|
||||
box.xMin, box.yMin, box.zMin,
|
||||
box.xMax, box.yMax, box.zMax);
|
||||
box.minX, box.minY, box.minZ,
|
||||
box.maxX, box.maxY, box.maxZ);
|
||||
} else return aabbConstructor
|
||||
.newInstance(box.xMin, box.yMin, box.zMin,
|
||||
box.xMax, box.yMax, box.zMax);
|
||||
.newInstance(box.minX, box.minY, box.minZ,
|
||||
box.maxX, box.maxY, box.maxZ);
|
||||
}
|
||||
|
||||
//Either bukkit or vanilla world object can be used.
|
||||
|
||||
@@ -246,32 +246,32 @@ public class RayCollision implements CollisionBox {
|
||||
double tFar;
|
||||
double tNear;
|
||||
if (invDirX >= 0.0D) {
|
||||
tNear = (aab.xMin - ray.originX) * invDirX;
|
||||
tFar = (aab.xMax - ray.originX) * invDirX;
|
||||
tNear = (aab.minX - ray.originX) * invDirX;
|
||||
tFar = (aab.maxX - ray.originX) * invDirX;
|
||||
} else {
|
||||
tNear = (aab.xMax - ray.originX) * invDirX;
|
||||
tFar = (aab.xMin - ray.originX) * invDirX;
|
||||
tNear = (aab.maxX - ray.originX) * invDirX;
|
||||
tFar = (aab.minX - ray.originX) * invDirX;
|
||||
}
|
||||
|
||||
double tymin;
|
||||
double tymax;
|
||||
if (invDirY >= 0.0D) {
|
||||
tymin = (aab.yMin - ray.originY) * invDirY;
|
||||
tymax = (aab.yMax - ray.originY) * invDirY;
|
||||
tymin = (aab.minY - ray.originY) * invDirY;
|
||||
tymax = (aab.maxY - ray.originY) * invDirY;
|
||||
} else {
|
||||
tymin = (aab.yMax - ray.originY) * invDirY;
|
||||
tymax = (aab.yMin - ray.originY) * invDirY;
|
||||
tymin = (aab.maxY - ray.originY) * invDirY;
|
||||
tymax = (aab.minY - ray.originY) * invDirY;
|
||||
}
|
||||
|
||||
if (tNear <= tymax && tymin <= tFar) {
|
||||
double tzmin;
|
||||
double tzmax;
|
||||
if (invDirZ >= 0.0D) {
|
||||
tzmin = (aab.zMin - ray.originZ) * invDirZ;
|
||||
tzmax = (aab.zMax - ray.originZ) * invDirZ;
|
||||
tzmin = (aab.minZ - ray.originZ) * invDirZ;
|
||||
tzmax = (aab.maxZ - ray.originZ) * invDirZ;
|
||||
} else {
|
||||
tzmin = (aab.zMax - ray.originZ) * invDirZ;
|
||||
tzmax = (aab.zMin - ray.originZ) * invDirZ;
|
||||
tzmin = (aab.maxZ - ray.originZ) * invDirZ;
|
||||
tzmax = (aab.minZ - ray.originZ) * invDirZ;
|
||||
}
|
||||
|
||||
if (tNear <= tzmax && tzmin <= tFar) {
|
||||
@@ -299,32 +299,32 @@ public class RayCollision implements CollisionBox {
|
||||
double tFar;
|
||||
double tNear;
|
||||
if (invDirX >= 0.0D) {
|
||||
tNear = (aab.xMin - ray.originX) * invDirX;
|
||||
tFar = (aab.xMax - ray.originX) * invDirX;
|
||||
tNear = (aab.minX - ray.originX) * invDirX;
|
||||
tFar = (aab.maxX - ray.originX) * invDirX;
|
||||
} else {
|
||||
tNear = (aab.xMax - ray.originX) * invDirX;
|
||||
tFar = (aab.xMin - ray.originX) * invDirX;
|
||||
tNear = (aab.maxX - ray.originX) * invDirX;
|
||||
tFar = (aab.minX - ray.originX) * invDirX;
|
||||
}
|
||||
|
||||
double tymin;
|
||||
double tymax;
|
||||
if (invDirY >= 0.0D) {
|
||||
tymin = (aab.yMin - ray.originY) * invDirY;
|
||||
tymax = (aab.yMax - ray.originY) * invDirY;
|
||||
tymin = (aab.minY - ray.originY) * invDirY;
|
||||
tymax = (aab.maxY - ray.originY) * invDirY;
|
||||
} else {
|
||||
tymin = (aab.yMax - ray.originY) * invDirY;
|
||||
tymax = (aab.yMin - ray.originY) * invDirY;
|
||||
tymin = (aab.maxY - ray.originY) * invDirY;
|
||||
tymax = (aab.minY - ray.originY) * invDirY;
|
||||
}
|
||||
|
||||
if (tNear <= tymax && tymin <= tFar) {
|
||||
double tzmin;
|
||||
double tzmax;
|
||||
if (invDirZ >= 0.0D) {
|
||||
tzmin = (aab.zMin - ray.originZ) * invDirZ;
|
||||
tzmax = (aab.zMax - ray.originZ) * invDirZ;
|
||||
tzmin = (aab.minZ - ray.originZ) * invDirZ;
|
||||
tzmax = (aab.maxZ - ray.originZ) * invDirZ;
|
||||
} else {
|
||||
tzmin = (aab.zMax - ray.originZ) * invDirZ;
|
||||
tzmax = (aab.zMin - ray.originZ) * invDirZ;
|
||||
tzmin = (aab.maxZ - ray.originZ) * invDirZ;
|
||||
tzmax = (aab.minZ - ray.originZ) * invDirZ;
|
||||
}
|
||||
|
||||
if (tNear <= tzmax && tzmin <= tFar) {
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class SimpleCollisionBox implements CollisionBox {
|
||||
public double xMin, yMin, zMin, xMax, yMax, zMax;
|
||||
public double minX, minY, minZ, maxX, maxY, maxZ;
|
||||
|
||||
public SimpleCollisionBox() {
|
||||
this(0, 0, 0, 0, 0, 0);
|
||||
@@ -23,35 +23,35 @@ public class SimpleCollisionBox implements CollisionBox {
|
||||
|
||||
public SimpleCollisionBox(double xMin, double yMin, double zMin, double xMax, double yMax, double zMax) {
|
||||
if (xMin < xMax) {
|
||||
this.xMin = xMin;
|
||||
this.xMax = xMax;
|
||||
this.minX = xMin;
|
||||
this.maxX = xMax;
|
||||
} else {
|
||||
this.xMin = xMax;
|
||||
this.xMax = xMin;
|
||||
this.minX = xMax;
|
||||
this.maxX = xMin;
|
||||
}
|
||||
if (yMin < yMax) {
|
||||
this.yMin = yMin;
|
||||
this.yMax = yMax;
|
||||
this.minY = yMin;
|
||||
this.maxY = yMax;
|
||||
} else {
|
||||
this.yMin = yMax;
|
||||
this.yMax = yMin;
|
||||
this.minY = yMax;
|
||||
this.maxY = yMin;
|
||||
}
|
||||
if (zMin < zMax) {
|
||||
this.zMin = zMin;
|
||||
this.zMax = zMax;
|
||||
this.minZ = zMin;
|
||||
this.maxZ = zMax;
|
||||
} else {
|
||||
this.zMin = zMax;
|
||||
this.zMax = zMin;
|
||||
this.minZ = zMax;
|
||||
this.maxZ = zMin;
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleCollisionBox(double width, double height) {
|
||||
xMin = -(width / 2);
|
||||
yMin = 0;
|
||||
zMin = -(width / 2);
|
||||
xMax = width / 2;
|
||||
yMax = height;
|
||||
zMax = width / 2;
|
||||
minX = -(width / 2);
|
||||
minY = 0;
|
||||
minZ = -(width / 2);
|
||||
maxX = width / 2;
|
||||
maxY = height;
|
||||
maxZ = width / 2;
|
||||
}
|
||||
|
||||
public SimpleCollisionBox(Vector min, Vector max) {
|
||||
@@ -70,7 +70,7 @@ public class SimpleCollisionBox implements CollisionBox {
|
||||
this(vec.getX(), vec.getY(), vec.getZ(), vec.getX(), vec.getY(), vec.getZ());
|
||||
|
||||
expand(width / 2, 0, width / 2);
|
||||
yMax+= height;
|
||||
maxY += height;
|
||||
}
|
||||
|
||||
public SimpleCollisionBox(BoundingBox box) {
|
||||
@@ -83,45 +83,45 @@ public class SimpleCollisionBox implements CollisionBox {
|
||||
|
||||
public void sort() {
|
||||
double temp = 0;
|
||||
if (xMin >= xMax) {
|
||||
temp = xMin;
|
||||
this.xMin = xMax;
|
||||
this.xMax = temp;
|
||||
if (minX >= maxX) {
|
||||
temp = minX;
|
||||
this.minX = maxX;
|
||||
this.maxX = temp;
|
||||
}
|
||||
if (yMin >= yMax) {
|
||||
temp = yMin;
|
||||
this.yMin = yMax;
|
||||
this.yMax = temp;
|
||||
if (minY >= maxY) {
|
||||
temp = minY;
|
||||
this.minY = maxY;
|
||||
this.maxY = temp;
|
||||
}
|
||||
if (zMin >= zMax) {
|
||||
temp = zMin;
|
||||
this.zMin = zMax;
|
||||
this.zMax = temp;
|
||||
if (minZ >= maxZ) {
|
||||
temp = minZ;
|
||||
this.minZ = maxZ;
|
||||
this.maxZ = temp;
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleCollisionBox copy() {
|
||||
return new SimpleCollisionBox(xMin, yMin, zMin, xMax, yMax, zMax);
|
||||
return new SimpleCollisionBox(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
public SimpleCollisionBox offset(double x, double y, double z) {
|
||||
this.xMin += x;
|
||||
this.yMin += y;
|
||||
this.zMin += z;
|
||||
this.xMax += x;
|
||||
this.yMax += y;
|
||||
this.zMax += z;
|
||||
this.minX += x;
|
||||
this.minY += y;
|
||||
this.minZ += z;
|
||||
this.maxX += x;
|
||||
this.maxY += y;
|
||||
this.maxZ += z;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimpleCollisionBox shrink(double x, double y, double z) {
|
||||
this.xMin += x;
|
||||
this.yMin += y;
|
||||
this.zMin += z;
|
||||
this.xMax -= x;
|
||||
this.yMax -= y;
|
||||
this.zMax -= z;
|
||||
this.minX += x;
|
||||
this.minY += y;
|
||||
this.minZ += z;
|
||||
this.maxX -= x;
|
||||
this.maxY -= y;
|
||||
this.maxZ -= z;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -137,26 +137,47 @@ public class SimpleCollisionBox implements CollisionBox {
|
||||
}
|
||||
|
||||
public SimpleCollisionBox expandMin(double x, double y, double z) {
|
||||
this.xMin += x;
|
||||
this.yMin += y;
|
||||
this.zMin += z;
|
||||
this.minX += x;
|
||||
this.minY += y;
|
||||
this.minZ += z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleCollisionBox expandMax(double x, double y, double z) {
|
||||
this.xMax += x;
|
||||
this.yMax += y;
|
||||
this.zMax += z;
|
||||
this.maxX += x;
|
||||
this.maxY += y;
|
||||
this.maxZ += z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleCollisionBox expand(double x, double y, double z) {
|
||||
this.xMin -= x;
|
||||
this.yMin -= y;
|
||||
this.zMin -= z;
|
||||
this.xMax += x;
|
||||
this.yMax += y;
|
||||
this.zMax += z;
|
||||
this.minX -= x;
|
||||
this.minY -= y;
|
||||
this.minZ -= z;
|
||||
this.maxX += x;
|
||||
this.maxY += y;
|
||||
this.maxZ += z;
|
||||
return this;
|
||||
}
|
||||
public SimpleCollisionBox addCoord(double x, double y, double z) {
|
||||
if (x < 0.0D) {
|
||||
minX += x;
|
||||
} else if (x > 0.0D) {
|
||||
maxX += x;
|
||||
}
|
||||
|
||||
if (y < 0.0D) {
|
||||
minY += y;
|
||||
} else if (y > 0.0D) {
|
||||
maxY += y;
|
||||
}
|
||||
|
||||
if (z < 0.0D) {
|
||||
minZ += z;
|
||||
} else if (z > 0.0D) {
|
||||
maxZ += z;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -166,64 +187,35 @@ public class SimpleCollisionBox implements CollisionBox {
|
||||
}
|
||||
|
||||
public SimpleCollisionBox expand(double value) {
|
||||
this.xMin -= value;
|
||||
this.yMin -= value;
|
||||
this.zMin -= value;
|
||||
this.xMax += value;
|
||||
this.yMax += value;
|
||||
this.zMax += value;
|
||||
this.minX -= value;
|
||||
this.minY -= value;
|
||||
this.minZ -= value;
|
||||
this.maxX += value;
|
||||
this.maxY += value;
|
||||
this.maxZ += value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector[] corners() {
|
||||
sort();
|
||||
Vector[] vectors = new Vector[8];
|
||||
vectors[0] = new Vector(xMin,yMin,zMin);
|
||||
vectors[1] = new Vector(xMin,yMin,zMax);
|
||||
vectors[2] = new Vector(xMax,yMin,zMin);
|
||||
vectors[3] = new Vector(xMax,yMin,zMax);
|
||||
vectors[4] = new Vector(xMin,yMax,zMin);
|
||||
vectors[5] = new Vector(xMin,yMax,zMax);
|
||||
vectors[6] = new Vector(xMax,yMax,zMin);
|
||||
vectors[7] = new Vector(xMax,yMax,zMax);
|
||||
vectors[0] = new Vector(minX, minY, minZ);
|
||||
vectors[1] = new Vector(minX, minY, maxZ);
|
||||
vectors[2] = new Vector(maxX, minY, minZ);
|
||||
vectors[3] = new Vector(maxX, minY, maxZ);
|
||||
vectors[4] = new Vector(minX, maxY, minZ);
|
||||
vectors[5] = new Vector(minX, maxY, maxZ);
|
||||
vectors[6] = new Vector(maxX, maxY, minZ);
|
||||
vectors[7] = new Vector(maxX, maxY, maxZ);
|
||||
return vectors;
|
||||
}
|
||||
|
||||
public Vector min() {
|
||||
return new Vector(xMin, yMin, zMin);
|
||||
return new Vector(minX, minY, minZ);
|
||||
}
|
||||
|
||||
public Vector max() {
|
||||
return new Vector(xMax, yMax, zMax);
|
||||
}
|
||||
|
||||
public SimpleCollisionBox addCoord(double x, double y, double z) {
|
||||
double d0 = this.xMin;
|
||||
double d1 = this.yMin;
|
||||
double d2 = this.zMin;
|
||||
double d3 = this.xMax;
|
||||
double d4 = this.yMax;
|
||||
double d5 = this.zMax;
|
||||
|
||||
if (x < 0.0D) {
|
||||
d0 += x;
|
||||
} else if (x > 0.0D) {
|
||||
d3 += x;
|
||||
}
|
||||
|
||||
if (y < 0.0D) {
|
||||
d1 += y;
|
||||
} else if (y > 0.0D) {
|
||||
d4 += y;
|
||||
}
|
||||
|
||||
if (z < 0.0D) {
|
||||
d2 += z;
|
||||
} else if (z > 0.0D) {
|
||||
d5 += z;
|
||||
}
|
||||
|
||||
return this;
|
||||
return new Vector(maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -232,9 +224,9 @@ public class SimpleCollisionBox implements CollisionBox {
|
||||
SimpleCollisionBox box = ((SimpleCollisionBox) other);
|
||||
box.sort();
|
||||
sort();
|
||||
return box.xMax >= this.xMin && box.xMin <= this.xMax
|
||||
&& box.yMax >= this.yMin && box.yMin <= this.yMax
|
||||
&& box.zMax >= this.zMin && box.zMin <= this.zMax;
|
||||
return box.maxX >= this.minX && box.minX <= this.maxX
|
||||
&& box.maxY >= this.minY && box.minY <= this.maxY
|
||||
&& box.maxZ >= this.minZ && box.minZ <= this.maxZ;
|
||||
} else {
|
||||
return other.isCollided(this);
|
||||
// throw new IllegalStateException("Attempted to check collision with " + other.getClass().getSimpleName());
|
||||
@@ -247,9 +239,9 @@ public class SimpleCollisionBox implements CollisionBox {
|
||||
SimpleCollisionBox box = (SimpleCollisionBox) other;
|
||||
box.sort();
|
||||
sort();
|
||||
return box.xMax > this.xMin && box.xMin < this.xMax
|
||||
&& box.yMax > this.yMin && box.yMin < this.yMax
|
||||
&& box.zMax > this.zMin && box.zMin < this.zMax;
|
||||
return box.maxX > this.minX && box.minX < this.maxX
|
||||
&& box.maxY > this.minY && box.minY < this.maxY
|
||||
&& box.maxZ > this.minZ && box.minZ < this.maxZ;
|
||||
} else {
|
||||
return other.isIntersected(this);
|
||||
}
|
||||
@@ -261,15 +253,15 @@ public class SimpleCollisionBox implements CollisionBox {
|
||||
* calculated offset. Otherwise return the calculated offset.
|
||||
*/
|
||||
public double calculateXOffset(SimpleCollisionBox other, double offsetX) {
|
||||
if (other.yMax > this.yMin && other.yMin < this.yMax && other.zMax > this.zMin && other.zMin < this.zMax) {
|
||||
if (offsetX > 0.0D && other.xMax <= this.xMin) {
|
||||
double d1 = this.xMin - other.xMax;
|
||||
if (other.maxY > this.minY && other.minY < this.maxY && other.maxZ > this.minZ && other.minZ < this.maxZ) {
|
||||
if (offsetX > 0.0D && other.maxX <= this.minX) {
|
||||
double d1 = this.minX - other.maxX;
|
||||
|
||||
if (d1 < offsetX) {
|
||||
offsetX = d1;
|
||||
}
|
||||
} else if (offsetX < 0.0D && other.xMin >= this.xMax) {
|
||||
double d0 = this.xMax - other.xMin;
|
||||
} else if (offsetX < 0.0D && other.minX >= this.maxX) {
|
||||
double d0 = this.maxX - other.minX;
|
||||
|
||||
if (d0 > offsetX) {
|
||||
offsetX = d0;
|
||||
@@ -288,15 +280,15 @@ public class SimpleCollisionBox implements CollisionBox {
|
||||
* calculated offset. Otherwise return the calculated offset.
|
||||
*/
|
||||
public double calculateYOffset(SimpleCollisionBox other, double offsetY) {
|
||||
if (other.xMax > this.xMin && other.xMin < this.xMax && other.zMax > this.zMin && other.zMin < this.zMax) {
|
||||
if (offsetY > 0.0D && other.yMax <= this.yMin) {
|
||||
double d1 = this.yMin - other.yMax;
|
||||
if (other.maxX > this.minX && other.minX < this.maxX && other.maxZ > this.minZ && other.minZ < this.maxZ) {
|
||||
if (offsetY > 0.0D && other.maxY <= this.minY) {
|
||||
double d1 = this.minY - other.maxY;
|
||||
|
||||
if (d1 < offsetY) {
|
||||
offsetY = d1;
|
||||
}
|
||||
} else if (offsetY < 0.0D && other.yMin >= this.yMax) {
|
||||
double d0 = this.yMax - other.yMin;
|
||||
} else if (offsetY < 0.0D && other.minY >= this.maxY) {
|
||||
double d0 = this.maxY - other.minY;
|
||||
|
||||
if (d0 > offsetY) {
|
||||
offsetY = d0;
|
||||
@@ -315,15 +307,15 @@ public class SimpleCollisionBox implements CollisionBox {
|
||||
* calculated offset. Otherwise return the calculated offset.
|
||||
*/
|
||||
public double calculateZOffset(SimpleCollisionBox other, double offsetZ) {
|
||||
if (other.xMax > this.xMin && other.xMin < this.xMax && other.yMax > this.yMin && other.yMin < this.yMax) {
|
||||
if (offsetZ > 0.0D && other.zMax <= this.zMin) {
|
||||
double d1 = this.zMin - other.zMax;
|
||||
if (other.maxX > this.minX && other.minX < this.maxX && other.maxY > this.minY && other.minY < this.maxY) {
|
||||
if (offsetZ > 0.0D && other.maxZ <= this.minZ) {
|
||||
double d1 = this.minZ - other.maxZ;
|
||||
|
||||
if (d1 < offsetZ) {
|
||||
offsetZ = d1;
|
||||
}
|
||||
} else if (offsetZ < 0.0D && other.zMin >= this.zMax) {
|
||||
double d0 = this.zMax - other.zMin;
|
||||
} else if (offsetZ < 0.0D && other.minZ >= this.maxZ) {
|
||||
double d0 = this.maxZ - other.minZ;
|
||||
|
||||
if (d0 > offsetZ) {
|
||||
offsetZ = d0;
|
||||
@@ -337,7 +329,7 @@ public class SimpleCollisionBox implements CollisionBox {
|
||||
}
|
||||
|
||||
public BoundingBox toBoundingBox() {
|
||||
return new BoundingBox(new Vector(xMin, yMin, zMin), new Vector(xMax, yMax, zMax));
|
||||
return new BoundingBox(new Vector(minX, minY, minZ), new Vector(maxX, maxY, maxZ));
|
||||
}
|
||||
|
||||
public <T> T toAxisAlignedBB() {
|
||||
@@ -345,9 +337,9 @@ public class SimpleCollisionBox implements CollisionBox {
|
||||
}
|
||||
|
||||
public double distance(SimpleCollisionBox box) {
|
||||
double xwidth = (xMax - xMin) / 2, zwidth = (zMax - zMin) / 2;
|
||||
double bxwidth = (box.xMax - box.xMin) / 2, bzwidth = (box.zMax - box.zMin) / 2;
|
||||
double hxz = Math.hypot(xMin - box.xMin, zMin - box.zMin);
|
||||
double xwidth = (maxX - minX) / 2, zwidth = (maxZ - minZ) / 2;
|
||||
double bxwidth = (box.maxX - box.minX) / 2, bzwidth = (box.maxZ - box.minZ) / 2;
|
||||
double hxz = Math.hypot(minX - box.minX, minZ - box.minZ);
|
||||
|
||||
return hxz - (xwidth + zwidth + bxwidth + bzwidth) / 4;
|
||||
}
|
||||
@@ -357,23 +349,23 @@ public class SimpleCollisionBox implements CollisionBox {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
SimpleCollisionBox that = (SimpleCollisionBox) o;
|
||||
return Double.compare(that.xMin, xMin) == 0 && Double.compare(that.yMin, yMin) == 0 && Double.compare(that.zMin, zMin) == 0 && Double.compare(that.xMax, xMax) == 0 && Double.compare(that.yMax, yMax) == 0 && Double.compare(that.zMax, zMax) == 0;
|
||||
return Double.compare(that.minX, minX) == 0 && Double.compare(that.minY, minY) == 0 && Double.compare(that.minZ, minZ) == 0 && Double.compare(that.maxX, maxX) == 0 && Double.compare(that.maxY, maxY) == 0 && Double.compare(that.maxZ, maxZ) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(xMin, yMin, zMin, xMax, yMax, zMax);
|
||||
return Objects.hash(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SimpleCollisionBox{" +
|
||||
"xMin=" + xMin +
|
||||
", yMin=" + yMin +
|
||||
", zMin=" + zMin +
|
||||
", xMax=" + xMax +
|
||||
", yMax=" + yMax +
|
||||
", zMax=" + zMax +
|
||||
"xMin=" + minX +
|
||||
", yMin=" + minY +
|
||||
", zMin=" + minZ +
|
||||
", xMax=" + maxX +
|
||||
", yMax=" + maxY +
|
||||
", zMax=" + maxZ +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user