Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ManInMyVan committed Dec 30, 2024
1 parent 8d72174 commit 7bb1f01
Show file tree
Hide file tree
Showing 20 changed files with 130 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@
import java.util.List;

public class BlockPlace {
protected static final BlockFace[] UPDATE_SHAPE_ORDER = new BlockFace[]{BlockFace.WEST, BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.DOWN, BlockFace.UP};
private static final BlockFace[] BY_2D = new BlockFace[]{BlockFace.SOUTH, BlockFace.WEST, BlockFace.NORTH, BlockFace.EAST};
static final BlockFace[] BY_3D = new BlockFace[]{BlockFace.DOWN, BlockFace.UP, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST, BlockFace.EAST};
protected static final BlockFace[] UPDATE_SHAPE_ORDER = { BlockFace.WEST, BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.DOWN, BlockFace.UP };
private static final BlockFace[] BY_2D = { BlockFace.SOUTH, BlockFace.WEST, BlockFace.NORTH, BlockFace.EAST };
static final BlockFace[] BY_3D = { BlockFace.DOWN, BlockFace.UP, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST, BlockFace.EAST };
@Setter
Vector3i blockPosition;
@Getter
InteractionHand hand;
@Getter
@Setter
boolean replaceClicked;
@Getter
boolean isCancelled = false;
GrimPlayer player;
@Getter
Expand Down Expand Up @@ -437,7 +438,7 @@ public boolean isBlockPlacedPowered() {
return false;
}

public BlockFace[] getHorizontalFaces() {
public static BlockFace[] getHorizontalFaces() {
return BY_2D;
}

Expand Down Expand Up @@ -529,10 +530,6 @@ public boolean isXAxis() {
return face == BlockFace.WEST || face == BlockFace.EAST;
}

public boolean isCancelled() {
return isCancelled;
}

public Vector3i getPlacedBlockPos() {
if (replaceClicked) return blockPosition;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public double distance(SimpleCollisionBox box) {
// Copied from hawk lol
// I would like to point out that this is magic to me and I have not attempted to understand this code
public Vector intersectsRay(Ray ray, float minDist, float maxDist) {
Vector invDir = new Vector(1f / ray.calculateDirection().getX(), 1f / ray.calculateDirection().getY(), 1f / ray.calculateDirection().getZ());
Vector invDir = new Vector(1f / ray.getDirection().getX(), 1f / ray.getDirection().getY(), 1f / ray.getDirection().getZ());

boolean signDirX = invDir.getX() < 0;
boolean signDirY = invDir.getY() < 0;
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/ac/grim/grimac/utils/data/VehicleData.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,4 @@ public class VehicleData {
public float horseJump = 0;
public boolean horseJumping = false;
public int camelDashCooldown;

public VehicleData() {

}
}
4 changes: 1 addition & 3 deletions src/main/java/ac/grim/grimac/utils/inventory/slot/Slot.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ public ItemStack safeInsert(ItemStack stack, int amount) {
itemstack.grow(i);
this.set(itemstack);
}
return stack;
} else {
return stack;
}
return stack;
}

public ItemStack remove(int p_40227_) {
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/ac/grim/grimac/utils/lists/ListWrapper.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package ac.grim.grimac.utils.lists;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.List;

// https://github.com/ThomasOM/Pledge/blob/master/src/main/java/dev/thomazz/pledge/util/collection/ListWrapper.java
@Getter
@RequiredArgsConstructor
public abstract class ListWrapper<T> implements List<T> {
protected final List<T> base;

public ListWrapper(List<T> base) {
this.base = base;
}

public List<T> getBase() {
return this.base;
}
}
6 changes: 2 additions & 4 deletions src/main/java/ac/grim/grimac/utils/lists/RunningMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ac.grim.grimac.utils.data.Pair;
import it.unimi.dsi.fastutil.doubles.Double2IntMap;
import it.unimi.dsi.fastutil.doubles.Double2IntOpenHashMap;
import lombok.Getter;

import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
Expand All @@ -13,6 +14,7 @@
public class RunningMode {
Queue<Double> addList;
Double2IntMap popularityMap = new Double2IntOpenHashMap();
@Getter
int maxSize;

private static final double threshold = 1e-3;
Expand All @@ -27,10 +29,6 @@ public int size() {
return addList.size();
}

public int getMaxSize() {
return maxSize;
}

public void add(double value) {
pop();

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/ac/grim/grimac/utils/math/GrimMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@UtilityClass
public class GrimMath {
public static final double MINIMUM_DIVISOR = ((Math.pow(0.2f, 3) * 8) * 0.15) - 1e-3; // 1e-3 for float imprecision

private static final float DEGREES_TO_RADIANS = (float) Math.PI / 180f;

public static double gcd(double a, double b) {
if (a == 0) return 0;
Expand Down Expand Up @@ -107,8 +107,12 @@ public static boolean isNearlySame(double a, double b, double epoch) {
}

public static long hashCode(double x, int y, double z) {
long l = (long)(x * 3129871) ^ (long)z * 116129781L ^ (long)y;
long l = (long) (x * 3129871) ^ (long) z * 116129781L ^ (long) y;
l = l * l * 42317861L + l * 11L;
return l >> 16;
}

public static float radians(float degrees) {
return degrees * DEGREES_TO_RADIANS;
}
}
8 changes: 4 additions & 4 deletions src/main/java/ac/grim/grimac/utils/math/LegacyFastMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ public class LegacyFastMath {

static {
for (int i = 0; i < 4096; ++i) {
SIN_TABLE_FAST[i] = (float) Math.sin(((float) i + 0.5F) / 4096.0F * ((float) Math.PI * 2F));
SIN_TABLE_FAST[i] = (float) Math.sin(((float) i + 0.5f) / 4096f * ((float) Math.PI * 2f));
}

for (int i = 0; i < 360; i += 90) {
SIN_TABLE_FAST[(int) ((float) i * 11.377778F) & 4095] = (float) Math.sin((float) i * 0.017453292F);
SIN_TABLE_FAST[(int) ((float) i * 11.377778f) & 4095] = (float) Math.sin(GrimMath.radians((float) i));
}
}

public static float sin(float par0) {
return SIN_TABLE_FAST[(int) (par0 * 651.8986F) & 4095];
return SIN_TABLE_FAST[(int) (par0 * 651.8986f) & 4095];
}

public static float cos(float par0) {
return SIN_TABLE_FAST[(int) ((par0 + ((float) Math.PI / 2F)) * 651.8986F) & 4095];
return SIN_TABLE_FAST[(int) ((par0 + ((float) Math.PI / 2f)) * 651.8986f) & 4095];
}
}
8 changes: 4 additions & 4 deletions src/main/java/ac/grim/grimac/utils/math/OptifineFastMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
//
public class OptifineFastMath {
private static final float[] SIN_TABLE_FAST = new float[4096];
private static final float radToIndex = roundToFloat(651.8986469044033D);
private static final float radToIndex = roundToFloat(651.8986469044033d);

static {
for (int j = 0; j < SIN_TABLE_FAST.length; ++j) {
SIN_TABLE_FAST[j] = roundToFloat(StrictMath.sin((double) j * Math.PI * 2.0D / 4096.0D));
SIN_TABLE_FAST[j] = roundToFloat(StrictMath.sin((double) j * Math.PI * 2d / 4096d));
}
}

Expand All @@ -51,10 +51,10 @@ public static float sin(float value) {
}

public static float cos(float value) {
return SIN_TABLE_FAST[(int) (value * radToIndex + 1024.0F) & 4095];
return SIN_TABLE_FAST[(int) (value * radToIndex + 1024f) & 4095];
}

public static float roundToFloat(double d) {
return (float) ((double) Math.round(d * 1.0E8D) / 1.0E8D);
return (float) ((double) Math.round(d * 1.0E8d) / 1.0E8d);
}
}
8 changes: 4 additions & 4 deletions src/main/java/ac/grim/grimac/utils/math/TrigHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public void toggleShitMath() {
}

public Vector getVanillaMathMovement(Vector wantedMovement, float f, float f2) {
float f3 = VanillaMath.sin(f2 * 0.017453292f);
float f4 = VanillaMath.cos(f2 * 0.017453292f);
float f3 = VanillaMath.sin(GrimMath.radians(f2));
float f4 = VanillaMath.cos(GrimMath.radians(f2));

float bestTheoreticalX = (float) (f3 * wantedMovement.getZ() + f4 * wantedMovement.getX()) / (f3 * f3 + f4 * f4) / f;
float bestTheoreticalZ = (float) (-f3 * wantedMovement.getX() + f4 * wantedMovement.getZ()) / (f3 * f3 + f4 * f4) / f;
Expand All @@ -30,8 +30,8 @@ public Vector getVanillaMathMovement(Vector wantedMovement, float f, float f2) {
}

public Vector getShitMathMovement(Vector wantedMovement, float f, float f2) {
float f3 = player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_8) ? OptifineFastMath.sin(f2 * 0.017453292f) : LegacyFastMath.sin(f2 * 0.017453292f);
float f4 = player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_8) ? OptifineFastMath.cos(f2 * 0.017453292f) : LegacyFastMath.cos(f2 * 0.017453292f);
float f3 = player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_8) ? OptifineFastMath.sin(GrimMath.radians(f2)) : LegacyFastMath.sin(GrimMath.radians(f2));
float f4 = player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_8) ? OptifineFastMath.cos(GrimMath.radians(f2)) : LegacyFastMath.cos(GrimMath.radians(f2));

float bestTheoreticalX = (float) (f3 * wantedMovement.getZ() + f4 * wantedMovement.getX()) / (f3 * f3 + f4 * f4) / f;
float bestTheoreticalZ = (float) (-f3 * wantedMovement.getX() + f4 * wantedMovement.getZ()) / (f3 * f3 + f4 * f4) / f;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ac/grim/grimac/utils/math/VanillaMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class VanillaMath {

static {
for (int i = 0; i < SIN.length; ++i) {
SIN[i] = (float) StrictMath.sin(i * 3.141592653589793 * 2.0 / 65536.0);
SIN[i] = (float) StrictMath.sin(i * 3.141592653589793 * 2d / 65536d);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public static float getFrictionInfluencedSpeed(float f, GrimPlayer player) {
return player.lastSprintingForSpeed ? (float) ((double) 0.02f + 0.005999999865889549D) : 0.02f;
}


/**
* This is used for falling onto a block (We care if there is a bouncy block)
* This is also used for striders checking if they are on lava
Expand Down
68 changes: 35 additions & 33 deletions src/main/java/ac/grim/grimac/utils/nmsutil/BoundingBoxSize.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ac.grim.grimac.utils.data.packetentity.PacketEntityHorse;
import ac.grim.grimac.utils.data.packetentity.PacketEntitySizeable;
import ac.grim.grimac.utils.data.packetentity.PacketEntityTrackXRot;
import ac.grim.grimac.utils.math.GrimMath;
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
Expand Down Expand Up @@ -61,13 +62,13 @@ private static float getWidthMinusBaby(GrimPlayer player, PacketEntity packetEnt
} else if (EntityTypes.ELDER_GUARDIAN.equals(type)) { // TODO: 2.35 * guardian?
return 1.9975f;
} else if (EntityTypes.END_CRYSTAL.equals(type)) {
return 2.0f;
return 2f;
} else if (EntityTypes.ENDER_DRAGON.equals(type)) {
return 16.0f;
return 16f;
} else if (EntityTypes.FIREBALL.equals(type)) {
return 1f;
} else if (EntityTypes.GHAST.equals(type)) {
return 4.0f;
return 4f;
} else if (EntityTypes.GIANT.equals(type)) {
return 3.6f;
} else if (EntityTypes.GUARDIAN.equals(type)) {
Expand All @@ -93,7 +94,7 @@ private static float getWidthMinusBaby(GrimPlayer player, PacketEntity packetEnt
} else if (EntityTypes.RAVAGER.equals(type)) {
return 1.95f;
} else if (EntityTypes.SHULKER.equals(type)) {
return 1.0f;
return 1f;
} else if (EntityTypes.SLIME.equals(type)) {
if (packetEntity instanceof PacketEntitySizeable) {
float size = ((PacketEntitySizeable) packetEntity).size;
Expand All @@ -118,16 +119,16 @@ private static float getWidthMinusBaby(GrimPlayer player, PacketEntity packetEnt
} else if (EntityTypes.CAMEL.equals(type)) {
return 1.7f;
} else if (EntityTypes.WIND_CHARGE.equals(type)) {
return 0.3125F;
return 0.3125f;
}
return 0.6f;
}

public static Vector3d getRidingOffsetFromVehicle(PacketEntity entity, GrimPlayer player) {
SimpleCollisionBox box = entity.getPossibleCollisionBoxes();
double x = (box.maxX + box.minX) / 2.0;
double x = (box.maxX + box.minX) / 2d;
double y = box.minY;
double z = (box.maxZ + box.minZ) / 2.0;
double z = (box.maxZ + box.minZ) / 2d;

if (entity instanceof PacketEntityTrackXRot xRotEntity) {
// Horses desync here, and we can't do anything about it without interpolating animations.
Expand All @@ -136,44 +137,45 @@ public static Vector3d getRidingOffsetFromVehicle(PacketEntity entity, GrimPlaye
// At least the only people using buckets are people in boats for villager transportation
// and people trying to false the anticheat.
if (EntityTypes.isTypeInstanceOf(entity.getType(), EntityTypes.BOAT)) {
float f = 0.0F;
float f = 0f;
float f1 = (float) (getPassengerRidingOffset(player, entity) - 0.35f); // hardcoded player offset

if (!entity.passengers.isEmpty()) {
int i = entity.passengers.indexOf(player.compensatedEntities.getSelf());

if (i == 0) {
f = 0.2F;
f = 0.2f;
} else if (i == 1) {
f = -0.6F;
f = -0.6f;
}
}

Vector3d vec3 = (new Vector3d(f, 0.0D, 0.0D));
vec3 = yRot(-xRotEntity.interpYaw * ((float) Math.PI / 180F) - ((float) Math.PI / 2F), vec3);
Vector3d vec3 = new Vector3d(f, 0d, 0d);
vec3 = yRot(GrimMath.radians(-xRotEntity.interpYaw) - ((float) Math.PI / 2f), vec3);
return new Vector3d(x + vec3.x, y + (double) f1, z + vec3.z);
} else if (entity.getType() == EntityTypes.LLAMA) {
float f = player.trigHandler.cos(xRotEntity.interpYaw * ((float) Math.PI / 180F));
float f1 = player.trigHandler.sin(xRotEntity.interpYaw * ((float) Math.PI / 180F));
return new Vector3d(x + (double) (0.3F * f1), y + getPassengerRidingOffset(player, entity) - 0.35f, z + (double) (0.3F * f));
float f = player.trigHandler.cos(GrimMath.radians(xRotEntity.interpYaw));
float f1 = player.trigHandler.sin(GrimMath.radians(xRotEntity.interpYaw));
return new Vector3d(x + (double) (0.3f * f1), y + getPassengerRidingOffset(player, entity) - 0.35f, z + (double) (0.3f * f));
} else if (entity.getType() == EntityTypes.CHICKEN) {
float f = player.trigHandler.sin(xRotEntity.interpYaw * ((float) Math.PI / 180F));
float f1 = player.trigHandler.cos(xRotEntity.interpYaw * ((float) Math.PI / 180F));
float f = player.trigHandler.sin(GrimMath.radians(xRotEntity.interpYaw));
float f1 = player.trigHandler.cos(GrimMath.radians(xRotEntity.interpYaw));
y = y + (getHeight(player, entity) * 0.5f);
return new Vector3d(x + (double) (0.1F * f), y - 0.35f, z - (double) (0.1F * f1));
return new Vector3d(x + (double) (0.1f * f), y - 0.35f, z - (double) (0.1f * f1));
}
}

return new Vector3d(x, y + getPassengerRidingOffset(player, entity) - 0.35f, z);
}

private static Vector3d yRot(float p_82525_, Vector3d start) {
float f = (float) Math.cos(p_82525_);
float f1 = (float) Math.sin(p_82525_);
double d0 = start.getX() * (double) f + start.getZ() * (double) f1;
double d1 = start.getY();
double d2 = start.getZ() * (double) f - start.getX() * (double) f1;
return new Vector3d(d0, d1, d2);
private static Vector3d yRot(float yaw, Vector3d start) {
double cos = (float) Math.cos(yaw);
double sin = (float) Math.sin(yaw);
return new Vector3d(
start.x * cos + start.z * sin,
start.y,
start.z * cos - start.x * sin
);
}

public static float getHeight(GrimPlayer player, PacketEntity packetEntity) {
Expand Down Expand Up @@ -276,17 +278,17 @@ private static float getHeightMinusBaby(GrimPlayer player, PacketEntity packetEn
} else if (EntityTypes.ENDERMITE.equals(type) || EntityTypes.COD.equals(type)) {
return 0.3f;
} else if (EntityTypes.END_CRYSTAL.equals(type)) {
return 2.0f;
return 2f;
} else if (EntityTypes.ENDER_DRAGON.equals(type)) {
return 8.0f;
return 8f;
} else if (EntityTypes.FIREBALL.equals(type)) {
return 1f;
} else if (EntityTypes.FOX.equals(type)) {
return 0.7f;
} else if (EntityTypes.GHAST.equals(type)) {
return 4.0f;
return 4f;
} else if (EntityTypes.GIANT.equals(type)) {
return 12.0f;
return 12f;
} else if (EntityTypes.GUARDIAN.equals(type)) {
return 0.85f;
} else if (EntityTypes.HORSE.equals(type)) {
Expand Down Expand Up @@ -338,7 +340,7 @@ private static float getHeightMinusBaby(GrimPlayer player, PacketEntity packetEn
} else if (EntityTypes.SHEEP.equals(type) || EntityTypes.GOAT.equals(type)) {
return 1.3f;
} else if (EntityTypes.SHULKER.equals(type)) { // Could maybe guess peek size, although seems useless
return 2.0f;
return 2f;
} else if (EntityTypes.SILVERFISH.equals(type)) {
return 0.3f;
} else if (EntityTypes.SKELETON.equals(type)) {
Expand Down Expand Up @@ -378,11 +380,11 @@ private static float getHeightMinusBaby(GrimPlayer player, PacketEntity packetEn
} else if (EntityTypes.CAMEL.equals(type)) {
return 2.375f;
} else if (EntityTypes.BREEZE.equals(type)) {
return 1.77F;
return 1.77f;
} else if (EntityTypes.BOGGED.equals(type)) {
return 1.99F;
return 1.99f;
} else if (EntityTypes.WIND_CHARGE.equals(type)) {
return 0.3125F;
return 0.3125f;
}
return 1.95f;
}
Expand Down
Loading

0 comments on commit 7bb1f01

Please sign in to comment.