mirror of
https://github.com/funkemunky/KauriV3.git
synced 2026-05-31 05:51:55 +00:00
Trying out new phase check
This commit is contained in:
@@ -1,24 +1,27 @@
|
||||
package dev.brighten.ac.check.impl.movement;
|
||||
|
||||
import dev.brighten.ac.api.check.CheckType;
|
||||
import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.check.CheckData;
|
||||
import dev.brighten.ac.check.WTimedAction;
|
||||
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.*;
|
||||
import dev.brighten.ac.utils.Helper;
|
||||
import dev.brighten.ac.utils.KLocation;
|
||||
import dev.brighten.ac.utils.Materials;
|
||||
import dev.brighten.ac.utils.XMaterial;
|
||||
import dev.brighten.ac.utils.timer.Timer;
|
||||
import dev.brighten.ac.utils.timer.impl.TickTimer;
|
||||
import dev.brighten.ac.utils.world.BlockData;
|
||||
import dev.brighten.ac.utils.world.CollisionBox;
|
||||
import dev.brighten.ac.utils.world.types.RayCollision;
|
||||
import dev.brighten.ac.utils.world.types.SimpleCollisionBox;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@CheckData(name = "Phase", checkId = "phase", type = CheckType.MOVEMENT)
|
||||
public class Phase extends Check {
|
||||
|
||||
private static final Set<Material> allowedMaterials = EnumSet.noneOf(Material.class);
|
||||
@@ -52,106 +55,34 @@ public class Phase extends Check {
|
||||
return;
|
||||
}
|
||||
|
||||
TagsBuilder tags = new TagsBuilder();
|
||||
SimpleCollisionBox fromBox = player.getMovement().getFrom().getBox().copy(), toBox = fromBox.copy();
|
||||
|
||||
SimpleCollisionBox
|
||||
toUpdate = new SimpleCollisionBox(player.getMovement().getTo().getLoc(), 0.6,1.8)
|
||||
.expand(-0.0425),
|
||||
playerBox = new SimpleCollisionBox(player.getBukkitPlayer().getLocation(), 0.6, 1.8)
|
||||
.expand(-0.0425);
|
||||
double deltaX = player.getMovement().getDeltaX(), deltaY = player.getMovement().getDeltaY(),
|
||||
deltaZ = player.getMovement().getDeltaZ();
|
||||
|
||||
SimpleCollisionBox concatted = Helper.wrap(playerBox, toUpdate);
|
||||
List<SimpleCollisionBox> collisions = Helper.getCollisions(player, fromBox.copy().addCoord(deltaX, deltaY, deltaZ),
|
||||
Materials.SOLID);
|
||||
|
||||
List<Block> blocks = Helper.blockCollisions(player.getBlockInfo().blocks, concatted);
|
||||
|
||||
phaseIntoBlock: {
|
||||
List<Block> current = Helper.blockCollisions(blocks, playerBox),
|
||||
newb = Helper.blockCollisions(blocks, toUpdate);
|
||||
|
||||
for (Block block : newb) {
|
||||
if(!current.contains(block)) {
|
||||
Material type = block.getType();
|
||||
if(Materials.checkFlag(type, Materials.COLLIDABLE)
|
||||
&& !allowedMaterials.contains(type)
|
||||
&& !Materials.checkFlag(type, Materials.STAIRS)) {
|
||||
tags.addTag("INTO_BLOCK");
|
||||
tags.addTag("material=" + type.name());
|
||||
vl++;
|
||||
break;
|
||||
} else debug(type.name());
|
||||
}
|
||||
}
|
||||
for (SimpleCollisionBox collision : collisions) {
|
||||
deltaY = collision.calculateYOffset(toBox, deltaY);
|
||||
}
|
||||
|
||||
phaseThru: {
|
||||
if(playerBox.isIntersected(toUpdate)) break phaseThru;
|
||||
toBox.offset(0, deltaY, 0);
|
||||
|
||||
Vector to = player.getMovement().getTo().getLoc().toVector(),
|
||||
from =player.getMovement().getFrom().getLoc().toVector();
|
||||
|
||||
to.add(new Vector(0, player.getInfo().sneaking ? 1.54f : 1.62f, 0));
|
||||
from.add(new Vector(0, player.getInfo().lsneaking ? 1.54f : 1.62f, 0));
|
||||
|
||||
double dist = to.distance(from);
|
||||
|
||||
Vector direction = to.subtract(from);
|
||||
RayCollision ray = new RayCollision(from, direction);
|
||||
|
||||
for (Block block : blocks) {
|
||||
Material type = block.getType();
|
||||
if(!Materials.checkFlag(type, Materials.COLLIDABLE)
|
||||
|| allowedMaterials.contains(type) || Materials.checkFlag(type, Materials.STAIRS))
|
||||
continue;
|
||||
|
||||
CollisionBox box = BlockData.getData(type).getBox(block, player.getPlayerVersion());
|
||||
|
||||
if(box instanceof SimpleCollisionBox) {
|
||||
Tuple<Double, Double> result = new Tuple<>(0., 0.);
|
||||
boolean intersected = RayCollision.intersect(ray, (SimpleCollisionBox) box);
|
||||
|
||||
if(intersected && result.one <= dist) {
|
||||
vl++;
|
||||
tags.addTag("THROUGH_BLOCK");
|
||||
tags.addTag("material=" + type);
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
List<SimpleCollisionBox> downcasted = new ArrayList<>();
|
||||
|
||||
box.downCast(downcasted);
|
||||
|
||||
boolean flagged = false;
|
||||
for (SimpleCollisionBox sbox : downcasted) {
|
||||
Tuple<Double, Double> result = new Tuple<>(0., 0.);
|
||||
boolean intersected = RayCollision.intersect(ray, sbox);
|
||||
|
||||
if(intersected && result.one <= dist) {
|
||||
flagged = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(flagged) {
|
||||
vl++;
|
||||
tags.addTag("THROUGH_BLOCK");
|
||||
tags.addTag("material=" + type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (SimpleCollisionBox collision : collisions) {
|
||||
deltaX = collision.calculateXOffset(toBox, deltaX);
|
||||
}
|
||||
|
||||
if(tags.getSize() > 0) {
|
||||
flag("tags=%s", tags.build());
|
||||
if(fromWhereShitAintBad == null) fromWhereShitAintBad = player.getMovement().getFrom().getLoc();
|
||||
final Location finalSetbackLocation = fromWhereShitAintBad.toLocation(player.getBukkitPlayer().getWorld());
|
||||
if(finalSetbackLocation != null) {
|
||||
RunUtils.task(() -> player.getBukkitPlayer().teleport(finalSetbackLocation));
|
||||
}
|
||||
lastFlag.reset();
|
||||
} else if(lastFlag.isPassed(5) && !player.getBlockInfo().collidesHorizontally) {
|
||||
fromWhereShitAintBad = player.getMovement().getFrom().getLoc().clone();
|
||||
toBox.offset(deltaX, 0, 0);
|
||||
|
||||
for (SimpleCollisionBox collision : collisions) {
|
||||
deltaZ = collision.calculateZOffset(toBox, deltaZ);
|
||||
}
|
||||
|
||||
toBox.offset(0, 0, deltaZ);
|
||||
|
||||
debug("(%s): new=[%.3f, %.3f, %.3f] old=[%.3f, %.3f, %.3f]", deltaX, deltaY, deltaZ,
|
||||
player.getMovement().getDeltaX(), player.getMovement().getDeltaY(),
|
||||
player.getMovement().getDeltaZ());
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user