mirror of
https://github.com/funkemunky/KauriV3.git
synced 2026-07-01 18:28:25 +00:00
Optimizations
This commit is contained in:
@@ -26,9 +26,9 @@ import dev.brighten.ac.utils.reflections.types.WrappedMethod;
|
||||
import dev.brighten.ac.utils.timer.Timer;
|
||||
import dev.brighten.ac.utils.timer.impl.TickTimer;
|
||||
import dev.brighten.ac.utils.world.WorldInfo;
|
||||
import dev.brighten.loader.LoaderPlugin;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.PackagePrivate;
|
||||
import me.mat1337.loader.plugin.LoaderPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@@ -7,6 +7,7 @@ import dev.brighten.ac.check.WAction;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying;
|
||||
import dev.brighten.ac.utils.Color;
|
||||
import dev.brighten.ac.utils.annotation.Async;
|
||||
import dev.brighten.ac.utils.timer.Timer;
|
||||
import dev.brighten.ac.utils.timer.impl.TickTimer;
|
||||
|
||||
@@ -21,6 +22,7 @@ public class Aim extends Check {
|
||||
private float buffer;
|
||||
protected Timer lastGrid = new TickTimer(3);
|
||||
|
||||
@Async
|
||||
WAction<WPacketPlayInFlying> onFlying = (packet) -> {
|
||||
if(!packet.isLooked()) return;
|
||||
|
||||
|
||||
@@ -7,13 +7,12 @@ 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.BlockUtils;
|
||||
import dev.brighten.ac.utils.KLocation;
|
||||
import dev.brighten.ac.utils.MathHelper;
|
||||
import dev.brighten.ac.utils.math.IntVector;
|
||||
import dev.brighten.ac.utils.wrapper.Wrapper;
|
||||
import lombok.val;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.util.CraftMagicNumbers;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@@ -39,19 +38,6 @@ public class Horizontal extends Check {
|
||||
|
||||
check:
|
||||
{
|
||||
Block underBlock = BlockUtils.getBlock((previousFrom != null ? player.getMovement().getFrom().getLoc() : player.getMovement().getTo().getLoc())
|
||||
.toLocation(player.getBukkitPlayer().getWorld())
|
||||
.subtract(0, 1, 0)),
|
||||
lastUnderBlock = BlockUtils.getBlock((previousFrom != null ? previousFrom : player.getMovement().getFrom().getLoc())
|
||||
.toLocation(player.getBukkitPlayer().getWorld())
|
||||
.subtract(0, 1, 0));
|
||||
if (underBlock == null || lastUnderBlock == null)
|
||||
break check;
|
||||
|
||||
Deque<Material> frictionList = player.getBlockUpdateHandler()
|
||||
.getPossibleMaterials(new IntVector(underBlock.getX(), underBlock.getY(), underBlock.getZ())),
|
||||
lfrictionList = player.getBlockUpdateHandler()
|
||||
.getPossibleMaterials(new IntVector(lastUnderBlock.getX(), lastUnderBlock.getY(), lastUnderBlock.getZ()));
|
||||
|
||||
if (!packet.isMoved()
|
||||
|| player.getMovement().getMoveTicks() == 0
|
||||
@@ -62,6 +48,18 @@ public class Horizontal extends Check {
|
||||
|| player.getBlockInfo().collidesHorizontally) {
|
||||
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), MathHelper.floor_double(underBlockLoc.z))),
|
||||
lfrictionList = player.getBlockUpdateHandler()
|
||||
.getPossibleMaterials(new IntVector(MathHelper.floor_double(lastUnderBlockLoc.x),
|
||||
MathHelper.floor_double(lastUnderBlockLoc.y),
|
||||
MathHelper.floor_double(lastUnderBlockLoc.z)));
|
||||
|
||||
double smallestDelta = Double.MAX_VALUE;
|
||||
|
||||
double pmotionx = 0, pmotionz = 0;
|
||||
@@ -73,13 +71,13 @@ public class Horizontal extends Check {
|
||||
for (Material underMaterial : frictionList) {
|
||||
for (Material lastUnderMaterial : lfrictionList) {
|
||||
for (int s = -1; s < 2; s++) {
|
||||
for (boolean sprinting : TRUE_FALSE) {
|
||||
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 : TRUE_FALSE) {
|
||||
for (boolean jumped : TRUE_FALSE) {
|
||||
for (boolean sneaking : getSneakingIteration(sprinting)) {
|
||||
for (boolean jumped : getJumpingIteration(sprinting)) {
|
||||
|
||||
float forward = f, strafe = s;
|
||||
|
||||
@@ -92,8 +90,8 @@ public class Horizontal extends Check {
|
||||
strafe *= 0.3;
|
||||
}
|
||||
|
||||
float friction = CraftMagicNumbers.getBlock(underMaterial).frictionFactor;
|
||||
float lfriction = CraftMagicNumbers.getBlock(lastUnderMaterial).frictionFactor;
|
||||
float friction = Wrapper.getInstance().getFriction(underMaterial);
|
||||
float lfriction = Wrapper.getInstance().getFriction(lastUnderMaterial);
|
||||
|
||||
if (using) {
|
||||
forward *= 0.2;
|
||||
@@ -272,7 +270,21 @@ public class Horizontal extends Check {
|
||||
};
|
||||
|
||||
|
||||
private static boolean[] getSprintIteration(int f) {
|
||||
if(f > 0) {
|
||||
return new boolean[] {true, false};
|
||||
}
|
||||
|
||||
return new boolean[] {false};
|
||||
}
|
||||
|
||||
private static boolean[] getSneakingIteration(boolean sprinting) {
|
||||
return sprinting ? new boolean[] {false} : new boolean[] {true, false};
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -53,6 +53,7 @@ public class VelocityB extends Check {
|
||||
|
||||
check:
|
||||
{
|
||||
if (ticks == 0) break check;
|
||||
Block underBlock = BlockUtils.getBlock((previousFrom != null ? player.getMovement().getFrom().getLoc() : player.getMovement().getTo().getLoc())
|
||||
.toLocation(player.getBukkitPlayer().getWorld())
|
||||
.subtract(0, 1, 0)),
|
||||
@@ -67,8 +68,6 @@ public class VelocityB extends Check {
|
||||
lfrictionList = player.getBlockUpdateHandler()
|
||||
.getPossibleMaterials(new IntVector(lastUnderBlock.getX(), lastUnderBlock.getY(), lastUnderBlock.getZ()));
|
||||
|
||||
if (ticks == 0) break check;
|
||||
|
||||
if (player.getMovement().getMoveTicks() == 0
|
||||
|| player.getInfo().isGeneralCancel()
|
||||
|| player.getBlockInfo().onClimbable
|
||||
|
||||
@@ -185,7 +185,7 @@ public class AnticheatCommand extends BaseCommand {
|
||||
return crc.getValue();
|
||||
}
|
||||
|
||||
private static final LongList acceptableHashes = new LongArrayList(Arrays.asList(3436861907L, 679626389L));
|
||||
private static final LongList acceptableHashes = new LongArrayList(Arrays.asList(3912178420L));
|
||||
|
||||
@Subcommand("alerts")
|
||||
@CommandPermission("anticheat.command.alerts")
|
||||
|
||||
@@ -105,7 +105,7 @@ public class PlayerRegistry {
|
||||
return crc.getValue();
|
||||
}
|
||||
|
||||
private static final LongList acceptableHashes = new LongArrayList(Arrays.asList(3436861907L, 679626389L));
|
||||
private static final LongList acceptableHashes = new LongArrayList(Arrays.asList(3912178420L));
|
||||
|
||||
public Optional<APlayer> getPlayer(UUID uuid) {
|
||||
return Optional.ofNullable(aplayerMap.get(uuid.hashCode()));
|
||||
|
||||
@@ -3,14 +3,13 @@ package dev.brighten.ac.data.info;
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.ProtocolVersion;
|
||||
import dev.brighten.ac.packet.wrapper.objects.EnumParticle;
|
||||
import dev.brighten.ac.utils.*;
|
||||
import dev.brighten.ac.utils.math.IntVector;
|
||||
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 org.bukkit.Chunk;
|
||||
import dev.brighten.ac.utils.wrapper.Wrapper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@@ -26,8 +25,6 @@ public class BlockInformation {
|
||||
onSoulSand, blocksAbove, collidesVertically, bedNear, collidesHorizontally, blocksNear, inBlock, miscNear,
|
||||
collidedWithEntity, roseBush, inPortal, blocksBelow, pistonNear, fenceBelow, inScaffolding, inHoney,
|
||||
nearSteppableEntity;
|
||||
public CollisionHandler
|
||||
handler = new CollisionHandler(new ArrayList<>(), new ArrayList<>(), new KLocation(0,0,0), null);
|
||||
public final List<SimpleCollisionBox> aboveCollisions = Collections.synchronizedList(new ArrayList<>()),
|
||||
belowCollisions = Collections.synchronizedList(new ArrayList<>());
|
||||
public final List<Block> blocks = Collections.synchronizedList(new ArrayList<>());
|
||||
@@ -126,12 +123,7 @@ public class BlockInformation {
|
||||
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++) {
|
||||
Optional<Block> block = BlockUtils.getBlockAsync(
|
||||
new Location(player.getBukkitPlayer().getWorld(), x, y, z));
|
||||
|
||||
if(!block.isPresent()) continue;
|
||||
|
||||
Material type = block.get().getType();
|
||||
Material type = Wrapper.getInstance().getType(player.getBukkitPlayer().getWorld(), x, y, z);
|
||||
|
||||
collisionMaterialCount.compute(type, (key, count) -> {
|
||||
if(count == null) return 1;
|
||||
@@ -344,13 +336,9 @@ public class BlockInformation {
|
||||
if(!player.getInfo().isWorldLoaded())
|
||||
return;
|
||||
|
||||
CollisionHandler handler = new CollisionHandler(blocks,
|
||||
player.getInfo().getNearbyEntities(),
|
||||
player.getMovement().getTo().getLoc(), player);
|
||||
|
||||
//Bukkit.broadcastMessage("chigga4");
|
||||
|
||||
for (Entity entity : handler.getEntities()) {
|
||||
for (Entity entity : player.getInfo().getNearbyEntities()) {
|
||||
boolean isBlockEntity = !(entity instanceof LivingEntity);
|
||||
|
||||
if(!isBlockEntity) continue;
|
||||
@@ -380,12 +368,6 @@ public class BlockInformation {
|
||||
onClimbable = player.getInfo().getBlockOnTo().isPresent()
|
||||
&& BlockUtils.isClimbableBlock(player.getInfo().getBlockOnTo().get());
|
||||
}
|
||||
|
||||
handler.setSize(0.6f, 1.8f);
|
||||
handler.setOffset(0f);
|
||||
|
||||
this.handler.getEntities().clear();
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public SimpleCollisionBox getBox() {
|
||||
|
||||
@@ -11,6 +11,7 @@ import dev.brighten.ac.utils.Tuple;
|
||||
import dev.brighten.ac.utils.XMaterial;
|
||||
import dev.brighten.ac.utils.math.IntVector;
|
||||
import dev.brighten.ac.utils.world.types.RayCollision;
|
||||
import dev.brighten.ac.utils.wrapper.Wrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.val;
|
||||
import org.bukkit.Material;
|
||||
@@ -148,23 +149,7 @@ public class BlockUpdateHandler {
|
||||
}
|
||||
|
||||
public Deque<Material> getPossibleMaterials(IntVector loc) {
|
||||
return new LinkedList<>(blockInformation.compute(loc, (blockLoc, blockI) -> {
|
||||
if(blockI == null) {
|
||||
blockI = new LinkedList<>();
|
||||
|
||||
val optional = BlockUtils
|
||||
.getBlockAsync(loc.toBukkitVector()
|
||||
.toLocation(player.getBukkitPlayer().getWorld()));
|
||||
|
||||
if(optional.isPresent()) {
|
||||
Block block = optional.get();
|
||||
|
||||
blockI.add(block.getType());
|
||||
}
|
||||
}
|
||||
|
||||
return blockI;
|
||||
}));
|
||||
return new LinkedList<>(getDirectPossibleMaterials(loc));
|
||||
}
|
||||
|
||||
private Deque<Material> getDirectPossibleMaterials(IntVector loc) {
|
||||
@@ -172,15 +157,10 @@ public class BlockUpdateHandler {
|
||||
if(blockI == null) {
|
||||
blockI = new LinkedList<>();
|
||||
|
||||
val optional = BlockUtils
|
||||
.getBlockAsync(loc.toBukkitVector()
|
||||
.toLocation(player.getBukkitPlayer().getWorld()));
|
||||
Material type = Wrapper.getInstance().getType(player.getBukkitPlayer().getWorld(),
|
||||
loc.getX(), loc.getY(), loc.getZ());
|
||||
|
||||
if(optional.isPresent()) {
|
||||
Block block = optional.get();
|
||||
|
||||
blockI.add(block.getType());
|
||||
}
|
||||
blockI.add(type);
|
||||
}
|
||||
|
||||
return blockI;
|
||||
|
||||
@@ -2,10 +2,10 @@ package dev.brighten.ac.handler.keepalive;
|
||||
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -20,15 +20,20 @@ public class KeepAlive {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public final Map<UUID, KAReceived> receivedKeepalive = new HashMap<>();
|
||||
public final Int2ObjectMap<KAReceived> receivedKeepalive = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
public void received(APlayer player) {
|
||||
receivedKeepalive.put(player.getBukkitPlayer().getUniqueId(),
|
||||
receivedKeepalive.put(player.getBukkitPlayer().getUniqueId().hashCode(),
|
||||
new KAReceived(player, Anticheat.INSTANCE.getKeepaliveProcessor().tick));
|
||||
}
|
||||
|
||||
public Optional<KAReceived> getReceived(UUID uuid) {
|
||||
return Optional.ofNullable(receivedKeepalive.getOrDefault(uuid, null));
|
||||
int hashCode = uuid.hashCode();
|
||||
if(receivedKeepalive.containsKey(hashCode)) {
|
||||
return Optional.of(receivedKeepalive.get(hashCode));
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
|
||||
@@ -56,7 +56,7 @@ public class ThreadHandler {
|
||||
}
|
||||
|
||||
private PlayerThread generatePlayerThread() {
|
||||
PlayerThread thread = new PlayerThread(Executors.newSingleThreadExecutor(new ThreadFactoryBuilder()
|
||||
PlayerThread thread = new PlayerThread(Executors.newFixedThreadPool(1, new ThreadFactoryBuilder()
|
||||
.setNameFormat("Kauri Player Thread " + services.size() + 1)
|
||||
.setUncaughtExceptionHandler((t, e) -> RunUtils.task(e::printStackTrace))
|
||||
.build()));
|
||||
|
||||
@@ -65,7 +65,7 @@ public class JoinListener implements Listener {
|
||||
case BLOCK_CHANGE:
|
||||
case MULTI_BLOCK_CHANGE:
|
||||
case MAP_CHUNK: {
|
||||
if(player.getLagInfo().getLastClientTransaction().isPassed(100L) && player.getCreation().isPassed(6000L)) {
|
||||
if(player.getLagInfo().getLastClientTransaction().isPassed(200L) && player.getCreation().isPassed(6000L)) {
|
||||
synchronized (player.getPacketQueue()) {
|
||||
player.getPacketQueue().add(event.getPacket());
|
||||
}
|
||||
|
||||
@@ -80,18 +80,14 @@ public class BlockUtils {
|
||||
public static boolean isUsable(Material material) {
|
||||
if(material.isEdible()) return true;
|
||||
|
||||
XMaterial xmat = XMaterial.matchXMaterial(material);
|
||||
|
||||
switch (xmat) {
|
||||
switch (material) {
|
||||
case STONE_SWORD:
|
||||
case DIAMOND_SWORD:
|
||||
case GOLDEN_SWORD:
|
||||
case IRON_SWORD:
|
||||
case NETHERITE_SWORD:
|
||||
case WOODEN_SWORD:
|
||||
case SHIELD:
|
||||
case BOW:
|
||||
case CROSSBOW:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
||||
@@ -1,215 +0,0 @@
|
||||
package dev.brighten.ac.utils;
|
||||
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.ProtocolVersion;
|
||||
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 lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Getter
|
||||
public class
|
||||
CollisionHandler {
|
||||
private final List<Block> blocks;
|
||||
private final List<Entity> entities;
|
||||
private final APlayer data;
|
||||
private final KLocation location;
|
||||
private final List<Triad<Double[], Integer, Consumer<Boolean>>> intersects = new ArrayList<>();
|
||||
private final List<Triad<Double[], Integer, Consumer<Boolean>>> collides = new ArrayList<>();
|
||||
|
||||
private double width, height;
|
||||
private double shift;
|
||||
@Setter
|
||||
private boolean single = false;
|
||||
@Setter
|
||||
private boolean debugging;
|
||||
|
||||
public CollisionHandler(List<Block> blocks, Collection<Entity> entities, KLocation to, APlayer data) {
|
||||
this.blocks = blocks;
|
||||
this.entities = new ArrayList<>(entities);
|
||||
this.location = to;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void setSize(double width, double height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public void setOffset(double shift) {
|
||||
this.shift = shift;
|
||||
}
|
||||
|
||||
public boolean containsFlag(int bitmask) {
|
||||
for (Block b : blocks) {
|
||||
if (Materials.checkFlag(b.getType(), bitmask)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean contains(EntityType type) {
|
||||
return entities.stream().anyMatch(e -> e.getType() == type);
|
||||
}
|
||||
|
||||
public void intersectsWithFuture(int bitMask, Consumer<Boolean> intersects) {
|
||||
String bitMaskString = bitMask + "%%__NONCE__%%";
|
||||
this.intersects.add(new Triad<>(new Double[] {width, height, shift}, bitMask, intersects));
|
||||
}
|
||||
|
||||
public void collidesWithFuture(int bitMask, Consumer<Boolean> collides) {
|
||||
this.collides.add(new Triad<>(new Double[] {width, height, shift}, bitMask, collides));
|
||||
}
|
||||
|
||||
public boolean isCollidedWithEntity(SimpleCollisionBox box) {
|
||||
for(Entity entity : entities) {
|
||||
if(EntityData.getEntityBox(entity.getLocation(), entity).isCollided(box))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isCollidedWithEntity() {
|
||||
SimpleCollisionBox playerBox = new SimpleCollisionBox()
|
||||
.offset(location.x, location.y, location.z)
|
||||
.expandMin(0, shift, 0)
|
||||
.expandMax(0, height, 0)
|
||||
.expand(width / 2, 0, width / 2);
|
||||
|
||||
return isCollidedWithEntity(playerBox);
|
||||
}
|
||||
|
||||
public List<CollisionBox> getCollisionBoxes(SimpleCollisionBox playerBox) {
|
||||
List<CollisionBox> collided = new ArrayList<>();
|
||||
|
||||
for (Block b : blocks) {
|
||||
Material material = b.getType();
|
||||
|
||||
CollisionBox box;
|
||||
if((box = BlockData.getData(material).getBox(b, ProtocolVersion.getGameVersion())).isCollided(playerBox)) {
|
||||
collided.add(box);
|
||||
}
|
||||
}
|
||||
|
||||
for(Entity entity : entities) {
|
||||
CollisionBox box = EntityData.getEntityBox(entity.getLocation(), entity);
|
||||
if(box.isCollided(playerBox))
|
||||
collided.add(box);
|
||||
}
|
||||
|
||||
return collided;
|
||||
}
|
||||
public List<CollisionBox> getCollisionBoxes() {
|
||||
SimpleCollisionBox playerBox = new SimpleCollisionBox()
|
||||
.offset(location.x, location.y, location.z)
|
||||
.expandMin(0, shift, 0)
|
||||
.expandMax(0, height, 0)
|
||||
.expand(width / 2, 0, width / 2);
|
||||
|
||||
return getCollisionBoxes(playerBox);
|
||||
}
|
||||
|
||||
public boolean isCollidedWith(CollisionBox box) {
|
||||
SimpleCollisionBox playerBox = new SimpleCollisionBox()
|
||||
.offset(location.x, location.y, location.z)
|
||||
.expandMin(0, shift, 0)
|
||||
.expandMax(0, height, 0)
|
||||
.expand(width / 2, 0, width / 2);
|
||||
|
||||
return box.isCollided(playerBox);
|
||||
}
|
||||
|
||||
public boolean isCollidedWith(SimpleCollisionBox playerBox, Material... materials) {
|
||||
for (Block b : blocks) {
|
||||
Location block = b.getLocation();
|
||||
Material material = b.getType();
|
||||
|
||||
if (materials.length == 0 || MiscUtils.contains(materials, material)) {
|
||||
if (BlockData.getData(material).getBox(b, ProtocolVersion.getGameVersion()).isCollided(playerBox))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(materials.length == 0) {
|
||||
for(Entity entity : entities) {
|
||||
if(EntityData.getEntityBox(entity.getLocation(), entity).isCollided(playerBox))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
public boolean isCollidedWith(Material... materials) {
|
||||
SimpleCollisionBox playerBox = new SimpleCollisionBox()
|
||||
.offset(location.x, location.y, location.z)
|
||||
.expandMin(0, shift, 0)
|
||||
.expandMax(0, height, 0)
|
||||
.expand(width / 2, 0, width / 2);
|
||||
|
||||
return isCollidedWith(playerBox, materials);
|
||||
}
|
||||
|
||||
public void runFutures() {
|
||||
Triad<Double[], Integer, Consumer<Boolean>> value = null;
|
||||
Queue<Consumer<Boolean>> successful = new LinkedList<>();
|
||||
//To remove objects
|
||||
Queue<Triad<Double[], Integer, Consumer<Boolean>>> collisionRemove = new LinkedList<>(),
|
||||
intersectsRemove = new LinkedList<>();
|
||||
|
||||
for (Block b : blocks) {
|
||||
Location block = b.getLocation();
|
||||
Material material = b.getType();
|
||||
for (Triad<Double[], Integer, Consumer<Boolean>> intersect : intersects) {
|
||||
if(!Materials.checkFlag(material, intersect.second)) continue;
|
||||
|
||||
SimpleCollisionBox playerBox = new SimpleCollisionBox()
|
||||
.offset(location.x, location.y, location.z)
|
||||
.expandMin(0, intersect.first[2], 0)
|
||||
.expandMax(0, intersect.first[1], 0)
|
||||
.expand(intersect.first[0] / 2, 0, intersect.first[0] / 2);
|
||||
|
||||
if (BlockData.getData(material).getBox(b, ProtocolVersion.getGameVersion()).isIntersected(playerBox)) {
|
||||
successful.add(intersect.third);
|
||||
intersectsRemove.add(intersect);
|
||||
}
|
||||
}
|
||||
for (Triad<Double[], Integer, Consumer<Boolean>> collides : collides) {
|
||||
if(!Materials.checkFlag(material, collides.second)) continue;
|
||||
|
||||
SimpleCollisionBox playerBox = new SimpleCollisionBox()
|
||||
.offset(location.x, location.y, location.z)
|
||||
.expandMin(0, collides.first[2], 0)
|
||||
.expandMax(0, collides.first[1], 0)
|
||||
.expand(collides.first[0] / 2, 0, collides.first[0] / 2);
|
||||
|
||||
if (BlockData.getData(material).getBox(b, ProtocolVersion.getGameVersion()).isCollided(playerBox)) {
|
||||
successful.add(collides.third);
|
||||
intersectsRemove.add(collides);
|
||||
}
|
||||
}
|
||||
|
||||
while((value = intersectsRemove.poll()) != null) {
|
||||
intersects.remove(value);
|
||||
}
|
||||
while((value = collisionRemove.poll()) != null) {
|
||||
collides.remove(value);
|
||||
}
|
||||
}
|
||||
collides.clear();
|
||||
intersects.clear();
|
||||
|
||||
Consumer<Boolean> consumer = null;
|
||||
while((consumer = successful.poll()) != null) {
|
||||
consumer.accept(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public class IntegrityCheck {
|
||||
return crc.getValue();
|
||||
}
|
||||
|
||||
private static final LongList acceptableHashes = new LongArrayList(Arrays.asList(3436861907L, 679626389L));
|
||||
private static final LongList acceptableHashes = new LongArrayList(Arrays.asList(3912178420L));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import dev.brighten.ac.utils.reflections.impl.MinecraftReflection;
|
||||
import dev.brighten.ac.utils.reflections.types.WrappedClass;
|
||||
import dev.brighten.ac.utils.reflections.types.WrappedField;
|
||||
import dev.brighten.ac.utils.world.types.SimpleCollisionBox;
|
||||
import dev.brighten.ac.utils.wrapper.Wrapper;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -82,13 +83,10 @@ public class MiscUtils {
|
||||
for(int x = startX ; x < endX ; x++) {
|
||||
for(int y = startY ; y < endY ; y++) {
|
||||
for(int z = startZ ; z < endZ ; z++) {
|
||||
Location loc = new Location(world, x, y, z);
|
||||
Optional<Block> op = BlockUtils.getBlockAsync(loc);
|
||||
Material type = Wrapper.getInstance().getType(world, x, y, z);
|
||||
|
||||
if(op.isPresent()) {
|
||||
if(Materials.checkFlag(op.get().getType(), bitmask))
|
||||
return true;
|
||||
}
|
||||
if(Materials.checkFlag(type, bitmask))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class IntVector {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("IntVector[%s, %s, %s]", x, y, z);
|
||||
return "IntVector[" + x + ", " + y + ", " + z + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,6 +4,7 @@ import dev.brighten.ac.packet.ProtocolVersion;
|
||||
import dev.brighten.ac.utils.wrapper.impl.Wrapper_18R3;
|
||||
import dev.brighten.ac.utils.wrapper.impl.Wrapper_Reflection;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
|
||||
public abstract class Wrapper {
|
||||
|
||||
@@ -24,4 +25,6 @@ public abstract class Wrapper {
|
||||
}
|
||||
|
||||
public abstract float getFriction(Material material);
|
||||
|
||||
public abstract Material getType(World world, double x, double y, double z);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package dev.brighten.ac.utils.wrapper.impl;
|
||||
|
||||
import dev.brighten.ac.utils.wrapper.Wrapper;
|
||||
import net.minecraft.server.v1_8_R3.BlockPosition;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.util.CraftMagicNumbers;
|
||||
|
||||
public class Wrapper_18R3 extends Wrapper {
|
||||
@@ -9,4 +12,10 @@ public class Wrapper_18R3 extends Wrapper {
|
||||
public float getFriction(Material material) {
|
||||
return CraftMagicNumbers.getBlock(material).frictionFactor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getType(World world, double x, double y, double z) {
|
||||
BlockPosition blockPos = new BlockPosition(x, y, z);
|
||||
return CraftMagicNumbers.getMaterial(((CraftWorld)world).getHandle().getType(blockPos).getBlock());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package dev.brighten.ac.utils.wrapper.impl;
|
||||
|
||||
import dev.brighten.ac.utils.BlockUtils;
|
||||
import dev.brighten.ac.utils.reflections.Reflections;
|
||||
import dev.brighten.ac.utils.reflections.types.WrappedClass;
|
||||
import dev.brighten.ac.utils.reflections.types.WrappedField;
|
||||
import dev.brighten.ac.utils.reflections.types.WrappedMethod;
|
||||
import dev.brighten.ac.utils.wrapper.Wrapper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
public class Wrapper_Reflection extends Wrapper {
|
||||
|
||||
@@ -17,4 +21,9 @@ public class Wrapper_Reflection extends Wrapper {
|
||||
public float getFriction(Material material) {
|
||||
return fieldFriction.get(getById.invoke(material));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getType(World world, double x, double y, double z) {
|
||||
return BlockUtils.getBlockAsync(new Location(world, x, y, z)).map(Block::getType).orElse(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user