diff --git a/build.gradle.kts b/build.gradle.kts index e9b722928d..4f754584ee 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,8 +11,10 @@ plugins { group = "ac.grim.grimac" version = "2.3.68" description = "Libre simulation anticheat designed for 1.21 with 1.8-1.21 support, powered by PacketEvents 2.0." -java.sourceCompatibility = JavaVersion.VERSION_1_8 -java.targetCompatibility = JavaVersion.VERSION_1_8 + +java { + toolchain.languageVersion.set(JavaLanguageVersion.of(17)) +} // Set to false for debug builds // You cannot live reload classes if the jar relocates dependencies diff --git a/src/main/java/ac/grim/grimac/checks/impl/aim/processor/AimProcessor.java b/src/main/java/ac/grim/grimac/checks/impl/aim/processor/AimProcessor.java index f3046a9eb3..4676408b54 100644 --- a/src/main/java/ac/grim/grimac/checks/impl/aim/processor/AimProcessor.java +++ b/src/main/java/ac/grim/grimac/checks/impl/aim/processor/AimProcessor.java @@ -59,15 +59,15 @@ public void process(final RotationUpdate rotationUpdate) { if (this.xRotMode.size() > SIGNIFICANT_SAMPLES_THRESHOLD) { Pair modeX = this.xRotMode.getMode(); - if (modeX.getSecond() > SIGNIFICANT_SAMPLES_THRESHOLD) { - this.modeX = modeX.getFirst(); + if (modeX.second() > SIGNIFICANT_SAMPLES_THRESHOLD) { + this.modeX = modeX.first(); this.sensitivityX = convertToSensitivity(this.modeX); } } if (this.yRotMode.size() > SIGNIFICANT_SAMPLES_THRESHOLD) { Pair modeY = this.yRotMode.getMode(); - if (modeY.getSecond() > SIGNIFICANT_SAMPLES_THRESHOLD) { - this.modeY = modeY.getFirst(); + if (modeY.second() > SIGNIFICANT_SAMPLES_THRESHOLD) { + this.modeY = modeY.first(); this.sensitivityY = convertToSensitivity(this.modeY); } } diff --git a/src/main/java/ac/grim/grimac/checks/impl/badpackets/BadPacketsO.java b/src/main/java/ac/grim/grimac/checks/impl/badpackets/BadPacketsO.java index d538ac600c..ab7b79760a 100644 --- a/src/main/java/ac/grim/grimac/checks/impl/badpackets/BadPacketsO.java +++ b/src/main/java/ac/grim/grimac/checks/impl/badpackets/BadPacketsO.java @@ -39,7 +39,7 @@ public void onPacketReceive(PacketReceiveEvent event) { boolean hasID = false; for (Pair iterator : keepaliveMap) { - if (iterator.getFirst() == id) { + if (iterator.first() == id) { hasID = true; break; } @@ -55,7 +55,7 @@ public void onPacketReceive(PacketReceiveEvent event) { do { data = keepaliveMap.poll(); if (data == null) break; - } while (data.getFirst() != id); + } while (data.first() != id); } } } diff --git a/src/main/java/ac/grim/grimac/checks/impl/combat/Reach.java b/src/main/java/ac/grim/grimac/checks/impl/combat/Reach.java index 2876d3664d..6c0e3a5828 100644 --- a/src/main/java/ac/grim/grimac/checks/impl/combat/Reach.java +++ b/src/main/java/ac/grim/grimac/checks/impl/combat/Reach.java @@ -206,7 +206,7 @@ private String checkReach(PacketEntity reachEntity, Vector3d from, boolean isPre Vector eyePos = new Vector(from.getX(), from.getY() + eye, from.getZ()); Vector endReachPos = eyePos.clone().add(new Vector(lookVec.getX() * distance, lookVec.getY() * distance, lookVec.getZ() * distance)); - Vector intercept = ReachUtils.calculateIntercept(targetBox, eyePos, endReachPos).getFirst(); + Vector intercept = ReachUtils.calculateIntercept(targetBox, eyePos, endReachPos).first(); if (ReachUtils.isVecInside(targetBox, eyePos)) { minDistance = 0; diff --git a/src/main/java/ac/grim/grimac/checks/impl/scaffolding/PositionPlace.java b/src/main/java/ac/grim/grimac/checks/impl/scaffolding/PositionPlace.java index 3b20196c04..a5b5522e25 100644 --- a/src/main/java/ac/grim/grimac/checks/impl/scaffolding/PositionPlace.java +++ b/src/main/java/ac/grim/grimac/checks/impl/scaffolding/PositionPlace.java @@ -44,27 +44,21 @@ public void onBlockPlace(final BlockPlace place) { // So now we have the player's possible eye positions // So then look at the face that the player has clicked - boolean flag = false; - switch (place.getDirection()) { - case NORTH: // Z- face - flag = eyePositions.minZ > combined.minZ; - break; - case SOUTH: // Z+ face - flag = eyePositions.maxZ < combined.maxZ; - break; - case EAST: // X+ face - flag = eyePositions.maxX < combined.maxX; - break; - case WEST: // X- face - flag = eyePositions.minX > combined.minX; - break; - case UP: // Y+ face - flag = eyePositions.maxY < combined.maxY; - break; - case DOWN: // Y- face - flag = eyePositions.minY > combined.minY; - break; - } + boolean flag = switch (place.getDirection()) { + case NORTH -> // Z- face + eyePositions.minZ > combined.minZ; + case SOUTH -> // Z+ face + eyePositions.maxZ < combined.maxZ; + case EAST -> // X+ face + eyePositions.maxX < combined.maxX; + case WEST -> // X- face + eyePositions.minX > combined.minX; + case UP -> // Y+ face + eyePositions.maxY < combined.maxY; + case DOWN -> // Y- face + eyePositions.minY > combined.minY; + default -> false; + }; if (flag) { if (flagAndAlert() && shouldModifyPackets() && shouldCancel()) { diff --git a/src/main/java/ac/grim/grimac/checks/impl/scaffolding/RotationPlace.java b/src/main/java/ac/grim/grimac/checks/impl/scaffolding/RotationPlace.java index e1081c4d9e..eea5c3a830 100644 --- a/src/main/java/ac/grim/grimac/checks/impl/scaffolding/RotationPlace.java +++ b/src/main/java/ac/grim/grimac/checks/impl/scaffolding/RotationPlace.java @@ -107,7 +107,7 @@ private boolean didRayTraceHit(BlockPlace place) { Ray trace = new Ray(player, starting.getX(), starting.getY(), starting.getZ(), lookDir.getX(), lookDir.getY()); Pair intercept = ReachUtils.calculateIntercept(box, trace.getOrigin(), trace.getPointAtDistance(distance)); - if (intercept.getFirst() != null) return true; + if (intercept.first() != null) return true; } } diff --git a/src/main/java/ac/grim/grimac/commands/GrimSpectate.java b/src/main/java/ac/grim/grimac/commands/GrimSpectate.java index 2b6617c4e9..21cb9091ea 100644 --- a/src/main/java/ac/grim/grimac/commands/GrimSpectate.java +++ b/src/main/java/ac/grim/grimac/commands/GrimSpectate.java @@ -23,8 +23,7 @@ public class GrimSpectate extends BaseCommand { @CommandPermission("grim.spectate") @CommandCompletion("@players") public void onSpectate(CommandSender sender, @Optional OnlinePlayer target) { - if (!(sender instanceof Player)) return; - Player player = (Player) sender; + if (!(sender instanceof Player player)) return; if (target != null && target.getPlayer().getUniqueId().equals(player.getUniqueId())) { String message = GrimAPI.INSTANCE.getConfigManager().getConfig().getStringElse("cannot-run-on-self", "%prefix% &cYou cannot use this command on yourself!"); diff --git a/src/main/java/ac/grim/grimac/commands/GrimStopSpectating.java b/src/main/java/ac/grim/grimac/commands/GrimStopSpectating.java index ffbe0f6d9e..aa2b0fcfbe 100644 --- a/src/main/java/ac/grim/grimac/commands/GrimStopSpectating.java +++ b/src/main/java/ac/grim/grimac/commands/GrimStopSpectating.java @@ -17,8 +17,7 @@ public class GrimStopSpectating extends BaseCommand { @CommandCompletion("here") public void onStopSpectate(CommandSender sender, String[] args) { String string = args.length > 0 ? args[0] : null; - if (!(sender instanceof Player)) return; - Player player = (Player) sender; + if (!(sender instanceof Player player)) return; if (GrimAPI.INSTANCE.getSpectateManager().isSpectating(player.getUniqueId())) { boolean teleportBack = string == null || !string.equalsIgnoreCase("here"); GrimAPI.INSTANCE.getSpectateManager().disable(player, teleportBack); diff --git a/src/main/java/ac/grim/grimac/events/packets/CheckManagerListener.java b/src/main/java/ac/grim/grimac/events/packets/CheckManagerListener.java index 610f87507b..2389f5a2ed 100644 --- a/src/main/java/ac/grim/grimac/events/packets/CheckManagerListener.java +++ b/src/main/java/ac/grim/grimac/events/packets/CheckManagerListener.java @@ -224,11 +224,10 @@ private static void handleUseItem(GrimPlayer player, ItemStack placedWith, Inter } } - private static void handleBlockPlaceOrUseItem(PacketWrapper packet, GrimPlayer player) { + private static void handleBlockPlaceOrUseItem(PacketWrapper packet, GrimPlayer player) { // Legacy "use item" packet - if (packet instanceof WrapperPlayClientPlayerBlockPlacement && + if (packet instanceof WrapperPlayClientPlayerBlockPlacement place && PacketEvents.getAPI().getServerManager().getVersion().isOlderThan(ServerVersion.V_1_9)) { - WrapperPlayClientPlayerBlockPlacement place = (WrapperPlayClientPlayerBlockPlacement) packet; if (player.gamemode == GameMode.SPECTATOR || player.gamemode == GameMode.ADVENTURE) return; @@ -243,9 +242,7 @@ private static void handleBlockPlaceOrUseItem(PacketWrapper packet, GrimPlayer p } } - if (packet instanceof WrapperPlayClientUseItem) { - WrapperPlayClientUseItem place = (WrapperPlayClientUseItem) packet; - + if (packet instanceof WrapperPlayClientUseItem place) { if (player.gamemode == GameMode.SPECTATOR || player.gamemode == GameMode.ADVENTURE) return; ItemStack placedWith = player.getInventory().getHeldItem(); @@ -257,9 +254,7 @@ private static void handleBlockPlaceOrUseItem(PacketWrapper packet, GrimPlayer p } // Check for interactable first (door, etc) - if (packet instanceof WrapperPlayClientPlayerBlockPlacement) { - WrapperPlayClientPlayerBlockPlacement place = (WrapperPlayClientPlayerBlockPlacement) packet; - + if (packet instanceof WrapperPlayClientPlayerBlockPlacement place) { ItemStack placedWith = player.getInventory().getHeldItem(); ItemStack offhand = player.getInventory().getOffHand(); @@ -295,8 +290,7 @@ private static void handleBlockPlaceOrUseItem(PacketWrapper packet, GrimPlayer p } } - if (packet instanceof WrapperPlayClientPlayerBlockPlacement) { - WrapperPlayClientPlayerBlockPlacement place = (WrapperPlayClientPlayerBlockPlacement) packet; + if (packet instanceof WrapperPlayClientPlayerBlockPlacement place) { Vector3i blockPosition = place.getBlockPosition(); BlockFace face = place.getFace(); @@ -797,14 +791,14 @@ private static HitData getNearestHitResult(GrimPlayer player, StateType heldItem for (SimpleCollisionBox box : boxes) { Pair intercept = ReachUtils.calculateIntercept(box, trace.getOrigin(), trace.getPointAtDistance(distance)); - if (intercept.getFirst() == null) continue; // No intercept + if (intercept.first() == null) continue; // No intercept - Vector hitLoc = intercept.getFirst(); + Vector hitLoc = intercept.first(); if (hitLoc.distanceSquared(startingVec) < bestHitResult) { bestHitResult = hitLoc.distanceSquared(startingVec); bestHitLoc = hitLoc; - bestFace = intercept.getSecond(); + bestFace = intercept.second(); } } if (bestHitLoc != null) { @@ -819,8 +813,8 @@ private static HitData getNearestHitResult(GrimPlayer player, StateType heldItem Pair intercept = ReachUtils.calculateIntercept(box, trace.getOrigin(), trace.getPointAtDistance(distance)); - if (intercept.getFirst() != null) { - return new HitData(vector3i, intercept.getFirst(), intercept.getSecond(), block); + if (intercept.first() != null) { + return new HitData(vector3i, intercept.first(), intercept.second(), block); } } diff --git a/src/main/java/ac/grim/grimac/events/packets/PacketEntityReplication.java b/src/main/java/ac/grim/grimac/events/packets/PacketEntityReplication.java index 9083beba27..e17178b793 100644 --- a/src/main/java/ac/grim/grimac/events/packets/PacketEntityReplication.java +++ b/src/main/java/ac/grim/grimac/events/packets/PacketEntityReplication.java @@ -228,9 +228,8 @@ public void onPacketSend(PacketSendEvent event) { if (status.getStatus() == 31) { PacketEntity hook = player.compensatedEntities.getEntity(status.getEntityId()); - if (!(hook instanceof PacketEntityHook)) return; + if (!(hook instanceof PacketEntityHook hookEntity)) return; - PacketEntityHook hookEntity = (PacketEntityHook) hook; if (hookEntity.attached == player.entityID) { player.sendTransaction(); // We don't transaction sandwich this, it's too rare to be a real problem. @@ -455,8 +454,7 @@ private void handleMoveEntity(PacketSendEvent event, int entityId, double deltaX player.latencyUtils.addRealTimeTask(lastTrans, () -> { PacketEntity entity = player.compensatedEntities.getEntity(entityId); if (entity == null) return; - if (entity instanceof PacketEntityTrackXRot && yaw != null) { - PacketEntityTrackXRot xRotEntity = (PacketEntityTrackXRot) entity; + if (entity instanceof PacketEntityTrackXRot xRotEntity && yaw != null) { xRotEntity.packetYaw = yaw; xRotEntity.steps = entity.isBoat() ? 10 : 3; } diff --git a/src/main/java/ac/grim/grimac/events/packets/worldreader/PacketWorldReaderEight.java b/src/main/java/ac/grim/grimac/events/packets/worldreader/PacketWorldReaderEight.java index 3d5e76232d..25ccd1339d 100644 --- a/src/main/java/ac/grim/grimac/events/packets/worldreader/PacketWorldReaderEight.java +++ b/src/main/java/ac/grim/grimac/events/packets/worldreader/PacketWorldReaderEight.java @@ -15,7 +15,7 @@ public class PacketWorldReaderEight extends BasePacketWorldReader { @Override public void handleMapChunkBulk(final GrimPlayer player, final PacketSendEvent event) { - PacketWrapper wrapper = new PacketWrapper(event); + PacketWrapper wrapper = new PacketWrapper<>(event); ByteBuf buffer = (ByteBuf) wrapper.getBuffer(); boolean skylight = wrapper.readBoolean(); @@ -47,7 +47,7 @@ public void handleMapChunkBulk(final GrimPlayer player, final PacketSendEvent ev @Override public void handleMapChunk(final GrimPlayer player, final PacketSendEvent event) { - PacketWrapper wrapper = new PacketWrapper(event); + PacketWrapper wrapper = new PacketWrapper<>(event); final int chunkX = wrapper.readInt(); final int chunkZ = wrapper.readInt(); diff --git a/src/main/java/ac/grim/grimac/manager/SetbackTeleportUtil.java b/src/main/java/ac/grim/grimac/manager/SetbackTeleportUtil.java index 0b9f6299ec..27413910c9 100644 --- a/src/main/java/ac/grim/grimac/manager/SetbackTeleportUtil.java +++ b/src/main/java/ac/grim/grimac/manager/SetbackTeleportUtil.java @@ -153,12 +153,12 @@ private void blockMovementsUntilResync(boolean simulateNextTickPosition, boolean VelocityData futureExplosion = player.checkManager.getExplosionHandler().getFutureExplosion(); // Velocity sets - if (futureKb.getFirst() != null) { - clientVel = futureKb.getSecond(); + if (futureKb.first() != null) { + clientVel = futureKb.second(); } // Explosion adds - if (futureExplosion != null && (futureKb.getFirst() == null || futureKb.getFirst().transaction < futureExplosion.transaction)) { + if (futureExplosion != null && (futureKb.first() == null || futureKb.first().transaction < futureExplosion.transaction)) { clientVel.add(futureExplosion.vector); } @@ -328,16 +328,16 @@ public boolean checkVehicleTeleportQueue(double x, double y, double z) { while (true) { Pair teleportPos = player.vehicleData.vehicleTeleports.peek(); if (teleportPos == null) break; - if (lastTransaction < teleportPos.getFirst()) { + if (lastTransaction < teleportPos.first()) { break; } - Vector3d position = teleportPos.getSecond(); + Vector3d position = teleportPos.second(); if (position.getX() == x && position.getY() == y && position.getZ() == z) { player.vehicleData.vehicleTeleports.poll(); return true; - } else if (lastTransaction > teleportPos.getFirst() + 1) { + } else if (lastTransaction > teleportPos.first() + 1) { player.vehicleData.vehicleTeleports.poll(); // Vehicles have terrible netcode so just ignore it if the teleport wasn't from us setting the player back diff --git a/src/main/java/ac/grim/grimac/manager/SpectateManager.java b/src/main/java/ac/grim/grimac/manager/SpectateManager.java index e7e3fa154b..5a16b1e828 100644 --- a/src/main/java/ac/grim/grimac/manager/SpectateManager.java +++ b/src/main/java/ac/grim/grimac/manager/SpectateManager.java @@ -71,14 +71,8 @@ public void handlePlayerStopSpectating(UUID uuid) { spectatingPlayers.remove(uuid); } - private static class PreviousState { - public PreviousState(org.bukkit.GameMode gameMode, Location location) { - this.gameMode = gameMode; - this.location = location; - } + private record PreviousState(org.bukkit.GameMode gameMode, Location location) { - private final org.bukkit.GameMode gameMode; - private final Location location; } } diff --git a/src/main/java/ac/grim/grimac/manager/init/start/TickEndEvent.java b/src/main/java/ac/grim/grimac/manager/init/start/TickEndEvent.java index 918324ea4f..5a20a554bf 100644 --- a/src/main/java/ac/grim/grimac/manager/init/start/TickEndEvent.java +++ b/src/main/java/ac/grim/grimac/manager/init/start/TickEndEvent.java @@ -42,7 +42,7 @@ public void start() { // but whatever. At least plugins can't break it, I guess. // // Pledge injects into another list, so we should be safe injecting into this one - List wrapper = Collections.synchronizedList(new HookedListWrapper(endOfTickObject) { + List wrapper = Collections.synchronizedList(new HookedListWrapper<>(endOfTickObject) { @Override public void onIterator() { hasTicked = true; diff --git a/src/main/java/ac/grim/grimac/player/GrimPlayer.java b/src/main/java/ac/grim/grimac/player/GrimPlayer.java index 106110eed1..f78771ce88 100644 --- a/src/main/java/ac/grim/grimac/player/GrimPlayer.java +++ b/src/main/java/ac/grim/grimac/player/GrimPlayer.java @@ -35,7 +35,6 @@ import com.github.retrooper.packetevents.protocol.player.GameMode; import com.github.retrooper.packetevents.protocol.player.User; import com.github.retrooper.packetevents.protocol.world.BlockFace; -import com.github.retrooper.packetevents.protocol.world.Dimension; import com.github.retrooper.packetevents.protocol.world.dimension.DimensionType; import com.github.retrooper.packetevents.util.Vector3d; import com.github.retrooper.packetevents.wrapper.PacketWrapper; @@ -305,7 +304,7 @@ public boolean addTransactionResponse(short id) { boolean hasID = false; int skipped = 0; for (Pair iterator : transactionsSent) { - if (iterator.getFirst() == id) { + if (iterator.first() == id) { hasID = true; break; } @@ -325,9 +324,9 @@ public boolean addTransactionResponse(short id) { lastTransactionReceived.incrementAndGet(); lastTransReceived = System.currentTimeMillis(); - transactionPing = (System.nanoTime() - data.getSecond()); - playerClockAtLeast = data.getSecond(); - } while (data.getFirst() != id); + transactionPing = (System.nanoTime() - data.second()); + playerClockAtLeast = data.second(); + } while (data.first() != id); // A transaction means a new tick, so apply any block places CheckManagerListener.handleQueuedPlaces(this, false, 0, 0, System.currentTimeMillis()); @@ -335,7 +334,7 @@ public boolean addTransactionResponse(short id) { } // Were we the ones who sent the packet? - return data != null && data.getFirst() == id; + return data != null && data.first() == id; } public void baseTickAddWaterPushing(Vector vector) { @@ -421,8 +420,7 @@ public void timedOut() { public void disconnect(Component reason) { String textReason; - if (reason instanceof TranslatableComponent) { - TranslatableComponent translatableComponent = (TranslatableComponent) reason; + if (reason instanceof TranslatableComponent translatableComponent) { textReason = translatableComponent.key(); } else { textReason = LegacyComponentSerializer.legacySection().serialize(reason); diff --git a/src/main/java/ac/grim/grimac/predictionengine/MovementCheckRunner.java b/src/main/java/ac/grim/grimac/predictionengine/MovementCheckRunner.java index dfb78fe7c1..ab040534db 100644 --- a/src/main/java/ac/grim/grimac/predictionengine/MovementCheckRunner.java +++ b/src/main/java/ac/grim/grimac/predictionengine/MovementCheckRunner.java @@ -22,7 +22,6 @@ import ac.grim.grimac.utils.data.packetentity.PacketEntityRideable; import ac.grim.grimac.utils.data.packetentity.PacketEntityTrackXRot; import ac.grim.grimac.utils.enums.Pose; -import ac.grim.grimac.utils.inventory.EnchantmentHelper; import ac.grim.grimac.utils.latency.CompensatedWorld; import ac.grim.grimac.utils.math.GrimMath; import ac.grim.grimac.utils.math.VectorUtils; @@ -32,7 +31,6 @@ import com.github.retrooper.packetevents.protocol.attribute.Attributes; import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; import com.github.retrooper.packetevents.protocol.item.ItemStack; -import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentTypes; import com.github.retrooper.packetevents.protocol.item.type.ItemType; import com.github.retrooper.packetevents.protocol.item.type.ItemTypes; import com.github.retrooper.packetevents.protocol.player.ClientVersion; @@ -260,8 +258,7 @@ private void check(PositionUpdate update) { // When in control of the entity, the player sets the entity position to their current position riding.setPositionRaw(GetBoundingBox.getPacketEntityBoundingBox(player, player.x, player.y, player.z, riding)); - if (riding instanceof PacketEntityTrackXRot) { - PacketEntityTrackXRot boat = (PacketEntityTrackXRot) riding; + if (riding instanceof PacketEntityTrackXRot boat) { boat.packetYaw = player.xRot; boat.interpYaw = player.xRot; boat.steps = 0; @@ -341,7 +338,7 @@ private void check(PositionUpdate update) { boolean clientClaimsRiptide = player.packetStateData.tryingToRiptide; if (player.packetStateData.tryingToRiptide) { long currentTime = System.currentTimeMillis(); - boolean isInWater = player.compensatedWorld.isRaining || Collisions.hasMaterial(player, player.boundingBox.copy().expand(0.1f), (block) -> Materials.isWater(CompensatedWorld.blockVersion, block.getFirst())); + boolean isInWater = player.compensatedWorld.isRaining || Collisions.hasMaterial(player, player.boundingBox.copy().expand(0.1f), (block) -> Materials.isWater(CompensatedWorld.blockVersion, block.first())); if (currentTime - player.packetStateData.lastRiptide < 450 || !isInWater) { player.packetStateData.tryingToRiptide = false; @@ -352,7 +349,7 @@ private void check(PositionUpdate update) { SimpleCollisionBox steppingOnBB = GetBoundingBox.getCollisionBoxForPlayer(player, player.x, player.y, player.z).expand(0.03).offset(0, -1, 0); Collisions.hasMaterial(player, steppingOnBB, (pair) -> { - WrappedBlockState data = pair.getFirst(); + WrappedBlockState data = pair.first(); if (data.getType() == StateTypes.SLIME_BLOCK && player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_8)) { player.uncertaintyHandler.isSteppingOnSlime = true; player.uncertaintyHandler.isSteppingOnBouncyBlock = true; @@ -398,8 +395,8 @@ private void check(PositionUpdate update) { player.uncertaintyHandler.isNearGlitchyBlock = player.getClientVersion().isOlderThan(ClientVersion.V_1_9) && Collisions.hasMaterial(player, expandedBB.copy().expand(0.2), - checkData -> BlockTags.ANVIL.contains(checkData.getFirst().getType()) - || checkData.getFirst().getType() == StateTypes.CHEST || checkData.getFirst().getType() == StateTypes.TRAPPED_CHEST); + checkData -> BlockTags.ANVIL.contains(checkData.first().getType()) + || checkData.first().getType() == StateTypes.CHEST || checkData.first().getType() == StateTypes.TRAPPED_CHEST); player.uncertaintyHandler.isOrWasNearGlitchyBlock = isGlitchy || player.uncertaintyHandler.isNearGlitchyBlock; player.uncertaintyHandler.checkForHardCollision(); diff --git a/src/main/java/ac/grim/grimac/predictionengine/PlayerBaseTick.java b/src/main/java/ac/grim/grimac/predictionengine/PlayerBaseTick.java index 3c7d0409a1..f43ba340f6 100644 --- a/src/main/java/ac/grim/grimac/predictionengine/PlayerBaseTick.java +++ b/src/main/java/ac/grim/grimac/predictionengine/PlayerBaseTick.java @@ -154,7 +154,7 @@ public void updatePowderSnow() { // Might be null after respawn? final Optional property = playerSpeed.property(); - if (!property.isPresent()) return; + if (property.isEmpty()) return; // The client first desync's this attribute property.get().getModifiers().removeIf(modifier -> modifier.getUUID().equals(CompensatedEntities.SNOW_MODIFIER_UUID) || modifier.getName().getKey().equals("powder_snow")); @@ -363,22 +363,12 @@ private void moveTowardsClosestSpaceModern(double xPosition, double zPosition) { double d7 = direction2 == BlockFace.WEST || direction2 == BlockFace.EAST ? relativeXMovement : relativeZMovement; d6 = direction2 == BlockFace.EAST || direction2 == BlockFace.SOUTH ? 1.0 - d7 : d7; // d7 and d6 flip the movement direction based on desired movement direction - boolean doesSuffocate; - switch (direction2) { - case EAST: - doesSuffocate = this.suffocatesAt(blockX + 1, blockZ); - break; - case WEST: - doesSuffocate = this.suffocatesAt(blockX - 1, blockZ); - break; - case NORTH: - doesSuffocate = this.suffocatesAt(blockX, blockZ - 1); - break; - default: - case SOUTH: - doesSuffocate = this.suffocatesAt(blockX, blockZ + 1); - break; - } + boolean doesSuffocate = switch (direction2) { + case EAST -> this.suffocatesAt(blockX + 1, blockZ); + case WEST -> this.suffocatesAt(blockX - 1, blockZ); + case NORTH -> this.suffocatesAt(blockX, blockZ - 1); + default -> this.suffocatesAt(blockX, blockZ + 1); + }; if (d6 >= lowestValue || doesSuffocate) continue; lowestValue = d6; diff --git a/src/main/java/ac/grim/grimac/predictionengine/PointThreeEstimator.java b/src/main/java/ac/grim/grimac/predictionengine/PointThreeEstimator.java index bed899ce36..e07882b7b8 100644 --- a/src/main/java/ac/grim/grimac/predictionengine/PointThreeEstimator.java +++ b/src/main/java/ac/grim/grimac/predictionengine/PointThreeEstimator.java @@ -248,21 +248,21 @@ private void checkNearbyBlocks(SimpleCollisionBox pointThreeBox) { // Check for flowing water Collisions.hasMaterial(player, pointThreeBox, (pair) -> { - final WrappedBlockState state = pair.getFirst(); + final WrappedBlockState state = pair.first(); final StateType stateType = state.getType(); if (player.tagManager.block(SyncedTags.CLIMBABLE).contains(stateType) || (stateType == StateTypes.POWDER_SNOW && !player.compensatedEntities.getSelf().inVehicle() && player.getInventory().getBoots().getType() == ItemTypes.LEATHER_BOOTS)) { isNearClimbable = true; } if (BlockTags.TRAPDOORS.contains(stateType)) { - isNearClimbable = isNearClimbable || Collisions.trapdoorUsableAsLadder(player, pair.getSecond().getX(), pair.getSecond().getY(), pair.getSecond().getZ(), state); + isNearClimbable = isNearClimbable || Collisions.trapdoorUsableAsLadder(player, pair.second().getX(), pair.second().getY(), pair.second().getZ(), state); } if (stateType == StateTypes.BUBBLE_COLUMN) { isNearBubbleColumn = true; } - if (Materials.isWater(player.getClientVersion(), pair.getFirst()) || pair.getFirst().getType() == StateTypes.LAVA) { + if (Materials.isWater(player.getClientVersion(), pair.first()) || pair.first().getType() == StateTypes.LAVA) { isNearFluid = true; } diff --git a/src/main/java/ac/grim/grimac/predictionengine/UncertaintyHandler.java b/src/main/java/ac/grim/grimac/predictionengine/UncertaintyHandler.java index 359a09da6c..dbf2a8fb86 100644 --- a/src/main/java/ac/grim/grimac/predictionengine/UncertaintyHandler.java +++ b/src/main/java/ac/grim/grimac/predictionengine/UncertaintyHandler.java @@ -303,8 +303,7 @@ public double reduceOffset(double offset) { // This is the end of that section. // I can't figure out how the client exactly tracks boost time - if (player.compensatedEntities.getSelf().getRiding() instanceof PacketEntityRideable) { - PacketEntityRideable vehicle = (PacketEntityRideable) player.compensatedEntities.getSelf().getRiding(); + if (player.compensatedEntities.getSelf().getRiding() instanceof PacketEntityRideable vehicle) { if (vehicle.currentBoostTime < vehicle.boostTimeMax + 20) offset -= 0.01; } diff --git a/src/main/java/ac/grim/grimac/predictionengine/predictions/PredictionEngine.java b/src/main/java/ac/grim/grimac/predictionengine/predictions/PredictionEngine.java index 0d75b8e69f..58612c751e 100644 --- a/src/main/java/ac/grim/grimac/predictionengine/predictions/PredictionEngine.java +++ b/src/main/java/ac/grim/grimac/predictionengine/predictions/PredictionEngine.java @@ -12,7 +12,6 @@ import ac.grim.grimac.utils.nmsutil.JumpPower; import ac.grim.grimac.utils.nmsutil.Riptide; import com.github.retrooper.packetevents.protocol.attribute.Attributes; -import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; import com.github.retrooper.packetevents.protocol.player.ClientVersion; import org.bukkit.util.Vector; @@ -134,8 +133,8 @@ private void doPredictions(GrimPlayer player, List possibleVelocitie // Returns pair of primary push movement, and then outputvel Pair output = doSeekingWallCollisions(player, primaryPushMovement, originalClientVel, clientVelAfterInput); - primaryPushMovement = output.getFirst(); - Vector outputVel = clampMovementToHardBorder(player, output.getSecond()); + primaryPushMovement = output.first(); + Vector outputVel = clampMovementToHardBorder(player, output.second()); double resultAccuracy = outputVel.distanceSquared(player.actualMovement); diff --git a/src/main/java/ac/grim/grimac/predictionengine/predictions/PredictionEngineNormal.java b/src/main/java/ac/grim/grimac/predictionengine/predictions/PredictionEngineNormal.java index c4f8de75c1..3b39e7f49d 100644 --- a/src/main/java/ac/grim/grimac/predictionengine/predictions/PredictionEngineNormal.java +++ b/src/main/java/ac/grim/grimac/predictionengine/predictions/PredictionEngineNormal.java @@ -47,7 +47,7 @@ public void addJumpsToPossibilities(GrimPlayer player, Set existingV // And 0.03 didn't affect onGround status // The player cannot jump final OptionalInt jumpBoost = player.compensatedEntities.getPotionLevelForPlayer(PotionTypes.JUMP_BOOST); - if (((!jumpBoost.isPresent() || jumpBoost.getAsInt() >= 0) && player.onGround) || !player.lastOnGround) + if (((jumpBoost.isEmpty() || jumpBoost.getAsInt() >= 0) && player.onGround) || !player.lastOnGround) return; JumpPower.jumpFromGround(player, jump); diff --git a/src/main/java/ac/grim/grimac/predictionengine/predictions/rideable/PredictionEngineRideableUtils.java b/src/main/java/ac/grim/grimac/predictionengine/predictions/rideable/PredictionEngineRideableUtils.java index 190cfd0b48..c94a699890 100644 --- a/src/main/java/ac/grim/grimac/predictionengine/predictions/rideable/PredictionEngineRideableUtils.java +++ b/src/main/java/ac/grim/grimac/predictionengine/predictions/rideable/PredictionEngineRideableUtils.java @@ -17,9 +17,7 @@ public class PredictionEngineRideableUtils { public static Set handleJumps(GrimPlayer player, Set possibleVectors) { - if (!(player.compensatedEntities.getSelf().getRiding() instanceof PacketEntityHorse)) return possibleVectors; - - PacketEntityHorse horse = (PacketEntityHorse) player.compensatedEntities.getSelf().getRiding(); + if (!(player.compensatedEntities.getSelf().getRiding() instanceof PacketEntityHorse horse)) return possibleVectors; // Setup player inputs float f = player.vehicleData.vehicleHorizontal * 0.5F; diff --git a/src/main/java/ac/grim/grimac/utils/anticheat/MessageUtil.java b/src/main/java/ac/grim/grimac/utils/anticheat/MessageUtil.java index 10914621ad..5aa7d9ca4e 100644 --- a/src/main/java/ac/grim/grimac/utils/anticheat/MessageUtil.java +++ b/src/main/java/ac/grim/grimac/utils/anticheat/MessageUtil.java @@ -35,7 +35,7 @@ public String formatWithNoColor(String string) { private String translateHexCodes(String message) { final String hexPattern = "#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})"; Matcher matcher = Pattern.compile(hexPattern).matcher(message); - StringBuffer sb = new StringBuffer(message.length()); + StringBuilder sb = new StringBuilder(message.length()); while (matcher.find()) { String hex = matcher.group(1); ChatColor color = ChatColor.of("#" + hex); diff --git a/src/main/java/ac/grim/grimac/utils/anticheat/update/BlockPlace.java b/src/main/java/ac/grim/grimac/utils/anticheat/update/BlockPlace.java index 3e615f0657..acb2945ccb 100644 --- a/src/main/java/ac/grim/grimac/utils/anticheat/update/BlockPlace.java +++ b/src/main/java/ac/grim/grimac/utils/anticheat/update/BlockPlace.java @@ -537,21 +537,14 @@ public Vector3i getPlacedBlockPos() { } public Vector3i getNormalBlockFace() { - switch (face) { - default: - case UP: - return new Vector3i(0, 1, 0); - case DOWN: - return new Vector3i(0, -1, 0); - case SOUTH: - return new Vector3i(0, 0, 1); - case NORTH: - return new Vector3i(0, 0, -1); - case WEST: - return new Vector3i(-1, 0, 0); - case EAST: - return new Vector3i(1, 0, 0); - } + return switch (face) { + case DOWN -> new Vector3i(0, -1, 0); + case SOUTH -> new Vector3i(0, 0, 1); + case NORTH -> new Vector3i(0, 0, -1); + case WEST -> new Vector3i(-1, 0, 0); + case EAST -> new Vector3i(1, 0, 0); + default -> new Vector3i(0, 1, 0); + }; } public void set(StateType material) { @@ -672,7 +665,7 @@ public Vector getClickedLocation() { final double distance = player.compensatedEntities.getSelf().getAttributeValue(Attributes.PLAYER_BLOCK_INTERACTION_RANGE) + 3; Vector eyePos = new Vector(player.x, player.y + player.getEyeHeight(), player.z); Vector endReachPos = eyePos.clone().add(new Vector(look.getX() * distance, look.getY() * distance, look.getZ() * distance)); - Vector intercept = ReachUtils.calculateIntercept(box, eyePos, endReachPos).getFirst(); + Vector intercept = ReachUtils.calculateIntercept(box, eyePos, endReachPos).first(); // Bring this back to relative to the block // The player didn't even click the block... (we should force resync BEFORE we get here!) diff --git a/src/main/java/ac/grim/grimac/utils/blockplace/ConsumesBlockPlace.java b/src/main/java/ac/grim/grimac/utils/blockplace/ConsumesBlockPlace.java index bafecb721e..ed4e96b4db 100644 --- a/src/main/java/ac/grim/grimac/utils/blockplace/ConsumesBlockPlace.java +++ b/src/main/java/ac/grim/grimac/utils/blockplace/ConsumesBlockPlace.java @@ -107,17 +107,11 @@ private static boolean isProperHit(WrappedBlockState bell, BlockFace direction, Attachment attachment = bell.getAttachment(); BlockFace dir2 = BlockFace.valueOf(direction.name()); - switch (attachment) { - case FLOOR: - return AxisUtil.isSameAxis(dir, dir2); - case SINGLE_WALL: - case DOUBLE_WALL: - return !AxisUtil.isSameAxis(dir, dir2); - case CEILING: - return true; - default: - return false; - } + return switch (attachment) { + case FLOOR -> AxisUtil.isSameAxis(dir, dir2); + case SINGLE_WALL, DOUBLE_WALL -> !AxisUtil.isSameAxis(dir, dir2); + case CEILING -> true; + }; } else { return false; } diff --git a/src/main/java/ac/grim/grimac/utils/blockstate/helper/BlockFaceHelper.java b/src/main/java/ac/grim/grimac/utils/blockstate/helper/BlockFaceHelper.java index 45ed2877eb..0437d0ca41 100644 --- a/src/main/java/ac/grim/grimac/utils/blockstate/helper/BlockFaceHelper.java +++ b/src/main/java/ac/grim/grimac/utils/blockstate/helper/BlockFaceHelper.java @@ -18,64 +18,42 @@ public static boolean isFaceHorizontal(BlockFace face) { */ @Deprecated public static BlockFace fromBukkitFace(org.bukkit.block.BlockFace face) { - switch (face) { - case NORTH: - return BlockFace.NORTH; - case SOUTH: - return BlockFace.SOUTH; - case WEST: - return BlockFace.WEST; - case EAST: - return BlockFace.EAST; - case UP: - return BlockFace.UP; - case DOWN: - return BlockFace.DOWN; - default: - return BlockFace.OTHER; - } + return switch (face) { + case NORTH -> BlockFace.NORTH; + case SOUTH -> BlockFace.SOUTH; + case WEST -> BlockFace.WEST; + case EAST -> BlockFace.EAST; + case UP -> BlockFace.UP; + case DOWN -> BlockFace.DOWN; + default -> BlockFace.OTHER; + }; } public static BlockFace getClockWise(BlockFace face) { - switch (face) { - case NORTH: - return BlockFace.EAST; - case SOUTH: - return BlockFace.WEST; - case WEST: - return BlockFace.NORTH; - case EAST: - default: - return BlockFace.SOUTH; - } + return switch (face) { + case NORTH -> BlockFace.EAST; + case SOUTH -> BlockFace.WEST; + case WEST -> BlockFace.NORTH; + default -> BlockFace.SOUTH; + }; } public static BlockFace getPEClockWise(BlockFace face) { - switch (face) { - case NORTH: - return BlockFace.EAST; - case SOUTH: - return BlockFace.WEST; - case WEST: - return BlockFace.NORTH; - case EAST: - default: - return BlockFace.SOUTH; - } + return switch (face) { + case NORTH -> BlockFace.EAST; + case SOUTH -> BlockFace.WEST; + case WEST -> BlockFace.NORTH; + default -> BlockFace.SOUTH; + }; } public static BlockFace getCounterClockwise(BlockFace face) { - switch (face) { - case NORTH: - return BlockFace.WEST; - case SOUTH: - return BlockFace.EAST; - case WEST: - return BlockFace.SOUTH; - case EAST: - default: - return BlockFace.NORTH; - } + return switch (face) { + case NORTH -> BlockFace.WEST; + case SOUTH -> BlockFace.EAST; + case WEST -> BlockFace.SOUTH; + default -> BlockFace.NORTH; + }; } public Vector offset(Vector toOffset, BlockFace face) { diff --git a/src/main/java/ac/grim/grimac/utils/collisions/AxisUtil.java b/src/main/java/ac/grim/grimac/utils/collisions/AxisUtil.java index 0b34f74cf7..e2f3038af2 100644 --- a/src/main/java/ac/grim/grimac/utils/collisions/AxisUtil.java +++ b/src/main/java/ac/grim/grimac/utils/collisions/AxisUtil.java @@ -54,36 +54,22 @@ public static SimpleCollisionBox combine(SimpleCollisionBox base, SimpleCollisio } public static AxisSelect getAxis(BlockFace face) { - switch (face) { - case EAST: - return EAST.select; - case WEST: - return WEST.select; - case NORTH: - return NORTH.select; - case SOUTH: - return SOUTH.select; - case UP: - return UP.select; - case DOWN: - default: - return DOWN.select; - } + return switch (face) { + case EAST -> EAST.select; + case WEST -> WEST.select; + case NORTH -> NORTH.select; + case SOUTH -> SOUTH.select; + case UP -> UP.select; + default -> DOWN.select; + }; } public static boolean isSameAxis(BlockFace one, BlockFace two) { - switch (one) { - case WEST: - case EAST: - return two == BlockFace.WEST || two == BlockFace.EAST; - case NORTH: - case SOUTH: - return two == BlockFace.NORTH || two == BlockFace.SOUTH; - case UP: - case DOWN: - return two == BlockFace.UP || two == BlockFace.DOWN; - default: - return false; - } + return switch (one) { + case WEST, EAST -> two == BlockFace.WEST || two == BlockFace.EAST; + case NORTH, SOUTH -> two == BlockFace.NORTH || two == BlockFace.SOUTH; + case UP, DOWN -> two == BlockFace.UP || two == BlockFace.DOWN; + default -> false; + }; } } diff --git a/src/main/java/ac/grim/grimac/utils/collisions/CollisionData.java b/src/main/java/ac/grim/grimac/utils/collisions/CollisionData.java index 67f5f330a0..b3778f2e2b 100644 --- a/src/main/java/ac/grim/grimac/utils/collisions/CollisionData.java +++ b/src/main/java/ac/grim/grimac/utils/collisions/CollisionData.java @@ -182,32 +182,22 @@ public enum CollisionData { // Overwrite previous SKULL enum for legacy, where head and wall skull isn't separate WALL_SKULL((player, version, data, x, y, z) -> { - switch (data.getFacing()) { - default: - case NORTH: - return new SimpleCollisionBox(0.25F, 0.25F, 0.5F, 0.75F, 0.75F, 1.0F, false); - case SOUTH: - return new SimpleCollisionBox(0.25F, 0.25F, 0.0F, 0.75F, 0.75F, 0.5F, false); - case WEST: - return new SimpleCollisionBox(0.5F, 0.25F, 0.25F, 1.0F, 0.75F, 0.75F, false); - case EAST: - return new SimpleCollisionBox(0.0F, 0.25F, 0.25F, 0.5F, 0.75F, 0.75F, false); - } + return switch (data.getFacing()) { + case SOUTH -> new SimpleCollisionBox(0.25F, 0.25F, 0.0F, 0.75F, 0.75F, 0.5F, false); + case WEST -> new SimpleCollisionBox(0.5F, 0.25F, 0.25F, 1.0F, 0.75F, 0.75F, false); + case EAST -> new SimpleCollisionBox(0.0F, 0.25F, 0.25F, 0.5F, 0.75F, 0.75F, false); + default -> new SimpleCollisionBox(0.25F, 0.25F, 0.5F, 0.75F, 0.75F, 1.0F, false); + }; }, StateTypes.CREEPER_WALL_HEAD, StateTypes.DRAGON_WALL_HEAD, StateTypes.PLAYER_WALL_HEAD, StateTypes.ZOMBIE_WALL_HEAD, StateTypes.SKELETON_WALL_SKULL, StateTypes.WITHER_SKELETON_WALL_SKULL), PIGLIN_WALL_HEAD((player, version, data, x, y, z) -> { - switch (data.getFacing()) { - default: - case NORTH: - return new HexCollisionBox(3.0D, 4.0D, 8.0D, 13.0D, 12.0D, 16.0D); - case SOUTH: - return new HexCollisionBox(3.0D, 4.0D, 0.0D, 13.0D, 12.0D, 8.0D); - case EAST: - return new HexCollisionBox(0.0D, 4.0D, 3.0D, 8.0D, 12.0D, 13.0D); - case WEST: - return new HexCollisionBox(8.0D, 4.0D, 3.0D, 16.0D, 12.0D, 13.0D); - } + return switch (data.getFacing()) { + case SOUTH -> new HexCollisionBox(3.0D, 4.0D, 0.0D, 13.0D, 12.0D, 8.0D); + case EAST -> new HexCollisionBox(0.0D, 4.0D, 3.0D, 8.0D, 12.0D, 13.0D); + case WEST -> new HexCollisionBox(8.0D, 4.0D, 3.0D, 16.0D, 12.0D, 13.0D); + default -> new HexCollisionBox(3.0D, 4.0D, 8.0D, 13.0D, 12.0D, 16.0D); + }; }, StateTypes.PIGLIN_WALL_HEAD), BANNER(new HexCollisionBox(4.0D, 0.0D, 4.0D, 12.0D, 16.0D, 12.0D), @@ -386,17 +376,12 @@ public enum CollisionData { if (version.isOlderThanOrEquals(ClientVersion.V_1_8)) width = 2; - switch (data.getFacing()) { - case NORTH: - return new HexCollisionBox(0.0D, 0.0D, 16.0D - width, 16.0D, 16.0D, 16.0D); - case SOUTH: - return new HexCollisionBox(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, width); - case WEST: - return new HexCollisionBox(16.0D - width, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D); - default: - case EAST: - return new HexCollisionBox(0.0D, 0.0D, 0.0D, width, 16.0D, 16.0D); - } + return switch (data.getFacing()) { + case NORTH -> new HexCollisionBox(0.0D, 0.0D, 16.0D - width, 16.0D, 16.0D, 16.0D); + case SOUTH -> new HexCollisionBox(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, width); + case WEST -> new HexCollisionBox(16.0D - width, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D); + default -> new HexCollisionBox(0.0D, 0.0D, 0.0D, width, 16.0D, 16.0D); + }; }, StateTypes.LADDER), CAMPFIRE((player, version, data, x, y, z) -> { @@ -583,18 +568,13 @@ public enum CollisionData { if (data.isOpen()) return NoCollisionBox.INSTANCE; - switch (data.getFacing()) { - case NORTH: - case SOUTH: - return new SimpleCollisionBox(0.0F, 0.0F, 0.375F, 1.0F, 1.5F, 0.625F, false); - case WEST: - case EAST: - return new SimpleCollisionBox(0.375F, 0.0F, 0.0F, 0.625F, 1.5F, 1.0F, false); - } - - // This code is unreachable but the compiler does not know this - return NoCollisionBox.INSTANCE; - + return switch (data.getFacing()) { + case NORTH, SOUTH -> new SimpleCollisionBox(0.0F, 0.0F, 0.375F, 1.0F, 1.5F, 0.625F, false); + case WEST, EAST -> new SimpleCollisionBox(0.375F, 0.0F, 0.0F, 0.625F, 1.5F, 1.0F, false); + default -> + // This code is unreachable but the compiler does not know this + NoCollisionBox.INSTANCE; + }; }, BlockTags.FENCE_GATES.getStates().toArray(new StateType[0])), FENCE(new DynamicFence(), BlockTags.FENCES.getStates().toArray(new StateType[0])), @@ -794,32 +774,22 @@ public enum CollisionData { BlockTags.FLOWER_POTS.getStates().toArray(new StateType[0])), WALL_SIGN((player, version, data, x, y, z) -> { - switch (data.getFacing()) { - case NORTH: - return new HexCollisionBox(0.0D, 4.5D, 14.0D, 16.0D, 12.5D, 16.0D); - case SOUTH: - return new HexCollisionBox(0.0D, 4.5D, 0.0D, 16.0D, 12.5D, 2.0D); - case WEST: - return new HexCollisionBox(14.0D, 4.5D, 0.0D, 16.0D, 12.5D, 16.0D); - case EAST: - return new HexCollisionBox(0.0D, 4.5D, 0.0D, 2.0D, 12.5D, 16.0D); - default: - return NoCollisionBox.INSTANCE; - } + return switch (data.getFacing()) { + case NORTH -> new HexCollisionBox(0.0D, 4.5D, 14.0D, 16.0D, 12.5D, 16.0D); + case SOUTH -> new HexCollisionBox(0.0D, 4.5D, 0.0D, 16.0D, 12.5D, 2.0D); + case WEST -> new HexCollisionBox(14.0D, 4.5D, 0.0D, 16.0D, 12.5D, 16.0D); + case EAST -> new HexCollisionBox(0.0D, 4.5D, 0.0D, 2.0D, 12.5D, 16.0D); + default -> NoCollisionBox.INSTANCE; + }; }, BlockTags.WALL_SIGNS.getStates().toArray(new StateType[0])), WALL_FAN((player, version, data, x, y, z) -> { - switch (data.getFacing()) { - case NORTH: - return new HexCollisionBox(0.0D, 4.0D, 5.0D, 16.0D, 12.0D, 16.0D); - case SOUTH: - return new HexCollisionBox(0.0D, 4.0D, 0.0D, 16.0D, 12.0D, 11.0D); - case WEST: - return new HexCollisionBox(5.0D, 4.0D, 0.0D, 16.0D, 12.0D, 16.0D); - case EAST: - default: - return new HexCollisionBox(0.0D, 4.0D, 0.0D, 11.0D, 12.0D, 16.0D); - } + return switch (data.getFacing()) { + case NORTH -> new HexCollisionBox(0.0D, 4.0D, 5.0D, 16.0D, 12.0D, 16.0D); + case SOUTH -> new HexCollisionBox(0.0D, 4.0D, 0.0D, 16.0D, 12.0D, 11.0D); + case WEST -> new HexCollisionBox(5.0D, 4.0D, 0.0D, 16.0D, 12.0D, 16.0D); + default -> new HexCollisionBox(0.0D, 4.0D, 0.0D, 11.0D, 12.0D, 16.0D); + }; }, BlockTags.WALL_CORALS.getStates().toArray(new StateType[0])), CORAL_PLANT((player, version, data, x, y, z) -> { @@ -848,45 +818,30 @@ public enum CollisionData { BUTTON((player, version, data, x, y, z) -> { double f2 = (float) (data.isPowered() ? 1 : 2) / 16.0; - switch (data.getFacing()) { - case WEST: - return new SimpleCollisionBox(0.0, 0.375, 0.3125, f2, 0.625, 0.6875, false); - case EAST: - return new SimpleCollisionBox(1.0 - f2, 0.375, 0.3125, 1.0, 0.625, 0.6875, false); - case NORTH: - return new SimpleCollisionBox(0.3125, 0.375, 0.0, 0.6875, 0.625, f2, false); - case SOUTH: - return new SimpleCollisionBox(0.3125, 0.375, 1.0 - f2, 0.6875, 0.625, 1.0, false); - case DOWN: - return new SimpleCollisionBox(0.3125, 0.0, 0.375, 0.6875, 0.0 + f2, 0.625, false); - case UP: - return new SimpleCollisionBox(0.3125, 1.0 - f2, 0.375, 0.6875, 1.0, 0.625, false); - } - - return NoCollisionBox.INSTANCE; + return switch (data.getFacing()) { + case WEST -> new SimpleCollisionBox(0.0, 0.375, 0.3125, f2, 0.625, 0.6875, false); + case EAST -> new SimpleCollisionBox(1.0 - f2, 0.375, 0.3125, 1.0, 0.625, 0.6875, false); + case NORTH -> new SimpleCollisionBox(0.3125, 0.375, 0.0, 0.6875, 0.625, f2, false); + case SOUTH -> new SimpleCollisionBox(0.3125, 0.375, 1.0 - f2, 0.6875, 0.625, 1.0, false); + case DOWN -> new SimpleCollisionBox(0.3125, 0.0, 0.375, 0.6875, 0.0 + f2, 0.625, false); + case UP -> new SimpleCollisionBox(0.3125, 1.0 - f2, 0.375, 0.6875, 1.0, 0.625, false); + default -> NoCollisionBox.INSTANCE; + }; }, BlockTags.BUTTONS.getStates().toArray(new StateType[0])), LEVER((player, version, data, x, y, z) -> { double f = 0.1875; - switch (data.getFacing()) { - case WEST: - return new SimpleCollisionBox(1.0 - f * 2.0, 0.2, 0.5 - f, 1.0, 0.8, 0.5 + f, false); - case EAST: - return new SimpleCollisionBox(0.0, 0.2, 0.5 - f, f * 2.0, 0.8, 0.5 + f, false); - case NORTH: - return new SimpleCollisionBox(0.5 - f, 0.2, 1.0 - f * 2.0, 0.5 + f, 0.8, 1.0, false); - case SOUTH: - return new SimpleCollisionBox(0.5 - f, 0.2, 0.0, 0.5 + f, 0.8, f * 2.0, false); - case DOWN: - return new SimpleCollisionBox(0.25, 0.4, 0.25, 0.75, 1.0, 0.75, false); - case UP: - return new SimpleCollisionBox(0.25, 0.0, 0.25, 0.75, 0.6, 0.75, false); - } - - return NoCollisionBox.INSTANCE; - + return switch (data.getFacing()) { + case WEST -> new SimpleCollisionBox(1.0 - f * 2.0, 0.2, 0.5 - f, 1.0, 0.8, 0.5 + f, false); + case EAST -> new SimpleCollisionBox(0.0, 0.2, 0.5 - f, f * 2.0, 0.8, 0.5 + f, false); + case NORTH -> new SimpleCollisionBox(0.5 - f, 0.2, 1.0 - f * 2.0, 0.5 + f, 0.8, 1.0, false); + case SOUTH -> new SimpleCollisionBox(0.5 - f, 0.2, 0.0, 0.5 + f, 0.8, f * 2.0, false); + case DOWN -> new SimpleCollisionBox(0.25, 0.4, 0.25, 0.75, 1.0, 0.75, false); + case UP -> new SimpleCollisionBox(0.25, 0.0, 0.25, 0.75, 0.6, 0.75, false); + default -> NoCollisionBox.INSTANCE; + }; }, StateTypes.LEVER), STONE_PRESSURE_PLATE((player, version, data, x, y, z) -> { @@ -924,17 +879,12 @@ public enum CollisionData { if (version.isOlderThan(ClientVersion.V_1_13)) return new HexCollisionBox(7.0D, 0.0D, 7.0D, 9.0D, 16.0D, 9.0D); - switch (data.getFacing()) { - case SOUTH: - return new HexCollisionBox(6.0D, 0.0D, 6.0D, 10.0D, 10.0D, 16.0D); - case WEST: - return new HexCollisionBox(0.0D, 0.0D, 6.0D, 10.0D, 10.0D, 10.0D); - case NORTH: - return new HexCollisionBox(6.0D, 0.0D, 0.0D, 10.0D, 10.0D, 10.0D); - case EAST: - default: - return new HexCollisionBox(6.0D, 0.0D, 6.0D, 16.0D, 10.0D, 10.0D); - } + return switch (data.getFacing()) { + case SOUTH -> new HexCollisionBox(6.0D, 0.0D, 6.0D, 10.0D, 10.0D, 16.0D); + case WEST -> new HexCollisionBox(0.0D, 0.0D, 6.0D, 10.0D, 10.0D, 10.0D); + case NORTH -> new HexCollisionBox(6.0D, 0.0D, 0.0D, 10.0D, 10.0D, 10.0D); + default -> new HexCollisionBox(6.0D, 0.0D, 6.0D, 16.0D, 10.0D, 10.0D); + }; }, StateTypes.ATTACHED_MELON_STEM, StateTypes.ATTACHED_PUMPKIN_STEM), PUMPKIN_STEM((player, version, data, x, y, z) -> { @@ -942,37 +892,26 @@ public enum CollisionData { }, StateTypes.PUMPKIN_STEM, StateTypes.MELON_STEM), TRIPWIRE_HOOK((player, version, data, x, y, z) -> { - switch (data.getFacing()) { - case NORTH: - return new HexCollisionBox(5.0D, 0.0D, 10.0D, 11.0D, 10.0D, 16.0D); - case SOUTH: - return new HexCollisionBox(5.0D, 0.0D, 0.0D, 11.0D, 10.0D, 6.0D); - case WEST: - return new HexCollisionBox(10.0D, 0.0D, 5.0D, 16.0D, 10.0D, 11.0D); - case EAST: - default: - return new HexCollisionBox(0.0D, 0.0D, 5.0D, 6.0D, 10.0D, 11.0D); - } + return switch (data.getFacing()) { + case NORTH -> new HexCollisionBox(5.0D, 0.0D, 10.0D, 11.0D, 10.0D, 16.0D); + case SOUTH -> new HexCollisionBox(5.0D, 0.0D, 0.0D, 11.0D, 10.0D, 6.0D); + case WEST -> new HexCollisionBox(10.0D, 0.0D, 5.0D, 16.0D, 10.0D, 11.0D); + default -> new HexCollisionBox(0.0D, 0.0D, 5.0D, 6.0D, 10.0D, 11.0D); + }; }, StateTypes.TRIPWIRE_HOOK), TORCH(new HexCollisionBox(6.0D, 0.0D, 6.0D, 10.0D, 10.0D, 10.0D), StateTypes.TORCH, StateTypes.REDSTONE_TORCH), WALL_TORCH((player, version, data, x, y, z) -> { - switch (data.getFacing()) { - case NORTH: - return new HexCollisionBox(5.5D, 3.0D, 11.0D, 10.5D, 13.0D, 16.0D); - case SOUTH: - return new HexCollisionBox(5.5D, 3.0D, 0.0D, 10.5D, 13.0D, 5.0D); - case WEST: - return new HexCollisionBox(11.0D, 3.0D, 5.5D, 16.0D, 13.0D, 10.5D); - case EAST: - return new HexCollisionBox(0.0D, 3.0D, 5.5D, 5.0D, 13.0D, 10.5D); - default: // 1.13 separates wall and normal torches, 1.12 does not - case UP: - return new HexCollisionBox(6.0D, 0.0D, 6.0D, 10.0D, 10.0D, 10.0D); - } - + return switch (data.getFacing()) { + case NORTH -> new HexCollisionBox(5.5D, 3.0D, 11.0D, 10.5D, 13.0D, 16.0D); + case SOUTH -> new HexCollisionBox(5.5D, 3.0D, 0.0D, 10.5D, 13.0D, 5.0D); + case WEST -> new HexCollisionBox(11.0D, 3.0D, 5.5D, 16.0D, 13.0D, 10.5D); + case EAST -> new HexCollisionBox(0.0D, 3.0D, 5.5D, 5.0D, 13.0D, 10.5D); + // 1.13 separates wall and normal torches, 1.12 does not + default -> new HexCollisionBox(6.0D, 0.0D, 6.0D, 10.0D, 10.0D, 10.0D); + }; }, StateTypes.WALL_TORCH, StateTypes.REDSTONE_WALL_TORCH), RAILS((player, version, data, x, y, z) -> { @@ -992,17 +931,12 @@ public enum CollisionData { // 1.17 blocks CANDLE((player, version, data, x, y, z) -> { if (version.isNewerThanOrEquals(ClientVersion.V_1_17)) { - switch (data.getCandles()) { - case 1: - return new HexCollisionBox(7.0, 0.0, 7.0, 9.0, 6.0, 9.0); - case 2: - return new HexCollisionBox(5.0, 0.0, 6.0, 11.0, 6.0, 9.0); - case 3: - return new HexCollisionBox(5.0, 0.0, 6.0, 10.0, 6.0, 11.0); - default: - case 4: - return new HexCollisionBox(5.0, 0.0, 5.0, 11.0, 6.0, 10.0); - } + return switch (data.getCandles()) { + case 1 -> new HexCollisionBox(7.0, 0.0, 7.0, 9.0, 6.0, 9.0); + case 2 -> new HexCollisionBox(5.0, 0.0, 6.0, 11.0, 6.0, 9.0); + case 3 -> new HexCollisionBox(5.0, 0.0, 6.0, 10.0, 6.0, 11.0); + default -> new HexCollisionBox(5.0, 0.0, 5.0, 11.0, 6.0, 10.0); + }; } return getPicklesBox(version, data.getCandles()); @@ -1121,19 +1055,14 @@ public enum CollisionData { if (!data.isHanging()) { return new HexCollisionBox(7.0D, 0.0D, 7.0D, 9.0D, 16.0D, 9.0D); } - switch (data.getAge()) { - case 0: - return new HexCollisionBox(7.0D, 13.0D, 7.0D, 9.0D, 16.0D, 9.0D); - case 1: - return new HexCollisionBox(7.0D, 10.0D, 7.0D, 9.0D, 16.0D, 9.0D); - case 2: - return new HexCollisionBox(7.0D, 7.0D, 7.0D, 9.0D, 16.0D, 9.0D); - case 3: - return new HexCollisionBox(7.0D, 3.0D, 7.0D, 9.0D, 16.0D, 9.0D); - case 4: - default: - return new HexCollisionBox(7.0D, 0.0D, 7.0D, 9.0D, 16.0D, 9.0D); - } + + return switch (data.getAge()) { + case 0 -> new HexCollisionBox(7.0D, 13.0D, 7.0D, 9.0D, 16.0D, 9.0D); + case 1 -> new HexCollisionBox(7.0D, 10.0D, 7.0D, 9.0D, 16.0D, 9.0D); + case 2 -> new HexCollisionBox(7.0D, 7.0D, 7.0D, 9.0D, 16.0D, 9.0D); + case 3 -> new HexCollisionBox(7.0D, 3.0D, 7.0D, 9.0D, 16.0D, 9.0D); + default -> new HexCollisionBox(7.0D, 0.0D, 7.0D, 9.0D, 16.0D, 9.0D); + }; }, StateTypes.MANGROVE_PROPAGULE), SCULK_SHRIKER(new HexCollisionBox(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D), StateTypes.SCULK_SHRIEKER), @@ -1164,16 +1093,11 @@ public enum CollisionData { }, StateTypes.PITCHER_CROP), WALL_HANGING_SIGNS((player, version, data, x, y, z) -> { - switch (data.getFacing()) { - case NORTH: - case SOUTH: - return new HexCollisionBox(0.0, 14.0, 6.0, 16.0, 16.0, 10.0); - case WEST: - case EAST: - return new HexCollisionBox(6.0, 14.0, 0.0, 10.0, 16.0, 16.0); - default: - return NoCollisionBox.INSTANCE; - } + return switch (data.getFacing()) { + case NORTH, SOUTH -> new HexCollisionBox(0.0, 14.0, 6.0, 16.0, 16.0, 10.0); + case WEST, EAST -> new HexCollisionBox(6.0, 14.0, 0.0, 10.0, 16.0, 16.0); + default -> NoCollisionBox.INSTANCE; + }; }, BlockTags.WALL_HANGING_SIGNS.getStates().toArray(new StateType[0])), NONE(NoCollisionBox.INSTANCE, StateTypes.AIR, StateTypes.CAVE_AIR, StateTypes.VOID_AIR, StateTypes.LIGHT), @@ -1213,21 +1137,14 @@ private static CollisionBox getAmethystBox(ClientVersion version, com.github.ret if (version.isOlderThanOrEquals(ClientVersion.V_1_16_4)) return NoCollisionBox.INSTANCE; - switch (facing) { - default: - case UP: - return new HexCollisionBox(param_1, 0.0, param_1, 16 - param_1, param_0, 16 - param_1); - case DOWN: - return new HexCollisionBox(param_1, 16 - param_0, param_1, 16 - param_1, 16.0, 16 - param_1); - case NORTH: - return new HexCollisionBox(param_1, param_1, 16 - param_0, 16 - param_1, 16 - param_1, 16.0); - case SOUTH: - return new HexCollisionBox(param_1, param_1, 0.0, 16 - param_1, 16 - param_1, param_0); - case EAST: - return new HexCollisionBox(0.0, param_1, param_1, param_0, 16 - param_1, 16 - param_1); - case WEST: - return new HexCollisionBox(16 - param_0, param_1, param_1, 16.0, 16 - param_1, 16 - param_1); - } + return switch (facing) { + case DOWN -> new HexCollisionBox(param_1, 16 - param_0, param_1, 16 - param_1, 16.0, 16 - param_1); + case NORTH -> new HexCollisionBox(param_1, param_1, 16 - param_0, 16 - param_1, 16 - param_1, 16.0); + case SOUTH -> new HexCollisionBox(param_1, param_1, 0.0, 16 - param_1, 16 - param_1, param_0); + case EAST -> new HexCollisionBox(0.0, param_1, param_1, param_0, 16 - param_1, 16 - param_1); + case WEST -> new HexCollisionBox(16 - param_0, param_1, param_1, 16.0, 16 - param_1, 16 - param_1); + default -> new HexCollisionBox(param_1, 0.0, param_1, 16 - param_1, param_0, 16 - param_1); + }; } private static CollisionBox getPicklesBox(ClientVersion version, int pickles) { @@ -1236,17 +1153,13 @@ private static CollisionBox getPicklesBox(ClientVersion version, int pickles) { return getCocoa(version, pickles, BlockFace.WEST); } - switch (pickles) { - case 1: - return new HexCollisionBox(6.0D, 0.0D, 6.0D, 10.0D, 6.0D, 10.0D); - case 2: - return new HexCollisionBox(3.0D, 0.0D, 3.0D, 13.0D, 6.0D, 13.0D); - case 3: - return new HexCollisionBox(2.0D, 0.0D, 2.0D, 14.0D, 6.0D, 14.0D); - case 4: - return new HexCollisionBox(2.0D, 0.0D, 2.0D, 14.0D, 7.0D, 14.0D); - } - return NoCollisionBox.INSTANCE; + return switch (pickles) { + case 1 -> new HexCollisionBox(6.0D, 0.0D, 6.0D, 10.0D, 6.0D, 10.0D); + case 2 -> new HexCollisionBox(3.0D, 0.0D, 3.0D, 13.0D, 6.0D, 13.0D); + case 3 -> new HexCollisionBox(2.0D, 0.0D, 2.0D, 14.0D, 6.0D, 14.0D); + case 4 -> new HexCollisionBox(2.0D, 0.0D, 2.0D, 14.0D, 7.0D, 14.0D); + default -> NoCollisionBox.INSTANCE; + }; } private static CollisionBox getCocoa(ClientVersion version, int age, BlockFace direction) { @@ -1301,18 +1214,11 @@ private static CollisionBox getEndRod(ClientVersion version, BlockFace face) { if (version.isOlderThan(ClientVersion.V_1_9)) return NoCollisionBox.INSTANCE; - switch (face) { - case UP: - case DOWN: - default: - return new HexCollisionBox(6.0D, 0.0D, 6.0D, 10.0D, 16.0D, 10.0); - case NORTH: - case SOUTH: - return new HexCollisionBox(6.0D, 6.0D, 0.0D, 10.0D, 10.0D, 16.0D); - case EAST: - case WEST: - return new HexCollisionBox(0.0D, 6.0D, 6.0D, 16.0D, 10.0D, 10.0D); - } + return switch (face) { + case NORTH, SOUTH -> new HexCollisionBox(6.0D, 6.0D, 0.0D, 10.0D, 10.0D, 16.0D); + case EAST, WEST -> new HexCollisionBox(0.0D, 6.0D, 6.0D, 16.0D, 10.0D, 10.0D); + default -> new HexCollisionBox(6.0D, 0.0D, 6.0D, 10.0D, 16.0D, 10.0); + }; } // Would pre-computing all states be worth the memory cost? I doubt it diff --git a/src/main/java/ac/grim/grimac/utils/collisions/HitboxData.java b/src/main/java/ac/grim/grimac/utils/collisions/HitboxData.java index fe8fc9e4cc..6d35e76d38 100644 --- a/src/main/java/ac/grim/grimac/utils/collisions/HitboxData.java +++ b/src/main/java/ac/grim/grimac/utils/collisions/HitboxData.java @@ -164,18 +164,13 @@ public enum HitboxData { }, StateTypes.LECTERN), WALL_HANGING_SIGNS((player, item, version, data, x, y, z) -> { - switch (data.getFacing()) { - case NORTH: - case SOUTH: - return new ComplexCollisionBox(new HexCollisionBox(0.0D, 14.0D, 6.0D, 16.0D, 16.0D, 10.0D), - new HexCollisionBox(1.0D, 0.0D, 7.0D, 15.0D, 10.0D, 9.0D)); - case WEST: - case EAST: - return new ComplexCollisionBox(new HexCollisionBox(6.0D, 14.0D, 0.0D, 10.0D, 16.0D, 16.0D), - new HexCollisionBox(7.0D, 0.0D, 1.0D, 9.0D, 10.0D, 15.0D)); - default: - return NoCollisionBox.INSTANCE; - } + return switch (data.getFacing()) { + case NORTH, SOUTH -> new ComplexCollisionBox(new HexCollisionBox(0.0D, 14.0D, 6.0D, 16.0D, 16.0D, 10.0D), + new HexCollisionBox(1.0D, 0.0D, 7.0D, 15.0D, 10.0D, 9.0D)); + case WEST, EAST -> new ComplexCollisionBox(new HexCollisionBox(6.0D, 14.0D, 0.0D, 10.0D, 16.0D, 16.0D), + new HexCollisionBox(7.0D, 0.0D, 1.0D, 9.0D, 10.0D, 15.0D)); + default -> NoCollisionBox.INSTANCE; + }; }, BlockTags.WALL_HANGING_SIGNS.getStates().toArray(new StateType[0])), PITCHER_CROP((player, item, version, data, x, y, z) -> { @@ -201,27 +196,17 @@ public enum HitboxData { return powered ? new HexCollisionBox(5.0, 0.0, 6.0, 11.0, 1.0, 10.0) : new HexCollisionBox(5.0, 0.0, 6.0, 11.0, 2.0, 10.0); case WALL: - CollisionBox shape; - switch (facing) { - case EAST: - shape = powered ? new HexCollisionBox(0.0, 6.0, 5.0, 1.0, 10.0, 11.0) : new HexCollisionBox(0.0, 6.0, 5.0, 2.0, 10.0, 11.0); - break; - case WEST: - shape = powered ? new HexCollisionBox(15.0, 6.0, 5.0, 16.0, 10.0, 11.0) : new HexCollisionBox(14.0, 6.0, 5.0, 16.0, 10.0, 11.0); - break; - case SOUTH: - shape = powered ? new HexCollisionBox(5.0, 6.0, 0.0, 11.0, 10.0, 1.0) : new HexCollisionBox(5.0, 6.0, 0.0, 11.0, 10.0, 2.0); - break; - case NORTH: - case UP: - case DOWN: - shape = powered ? new HexCollisionBox(5.0, 6.0, 15.0, 11.0, 10.0, 16.0) : new HexCollisionBox(5.0, 6.0, 14.0, 11.0, 10.0, 16.0); - break; - default: - shape = NoCollisionBox.INSTANCE; - } - - return shape; + return switch (facing) { + case EAST -> + powered ? new HexCollisionBox(0.0, 6.0, 5.0, 1.0, 10.0, 11.0) : new HexCollisionBox(0.0, 6.0, 5.0, 2.0, 10.0, 11.0); + case WEST -> + powered ? new HexCollisionBox(15.0, 6.0, 5.0, 16.0, 10.0, 11.0) : new HexCollisionBox(14.0, 6.0, 5.0, 16.0, 10.0, 11.0); + case SOUTH -> + powered ? new HexCollisionBox(5.0, 6.0, 0.0, 11.0, 10.0, 1.0) : new HexCollisionBox(5.0, 6.0, 0.0, 11.0, 10.0, 2.0); + case NORTH, UP, DOWN -> + powered ? new HexCollisionBox(5.0, 6.0, 15.0, 11.0, 10.0, 16.0) : new HexCollisionBox(5.0, 6.0, 14.0, 11.0, 10.0, 16.0); + default -> NoCollisionBox.INSTANCE; + }; case CEILING: default: // x axis @@ -234,30 +219,22 @@ public enum HitboxData { }, BlockTags.BUTTONS.getStates().toArray(new StateType[0])), WALL_SIGN((player, item, version, data, x, y, z) -> { - switch (data.getFacing()) { - case NORTH: - return new HexCollisionBox(0.0, 4.5, 14.0, 16.0, 12.5, 16.0); - case SOUTH: - return new HexCollisionBox(0.0, 4.5, 0.0, 16.0, 12.5, 2.0); - case EAST: - return new HexCollisionBox(0.0, 4.5, 0.0, 2.0, 12.5, 16.0); - case WEST: - return new HexCollisionBox(14.0, 4.5, 0.0, 16.0, 12.5, 16.0); - default: - return NoCollisionBox.INSTANCE; - } + return switch (data.getFacing()) { + case NORTH -> new HexCollisionBox(0.0, 4.5, 14.0, 16.0, 12.5, 16.0); + case SOUTH -> new HexCollisionBox(0.0, 4.5, 0.0, 16.0, 12.5, 2.0); + case EAST -> new HexCollisionBox(0.0, 4.5, 0.0, 2.0, 12.5, 16.0); + case WEST -> new HexCollisionBox(14.0, 4.5, 0.0, 16.0, 12.5, 16.0); + default -> NoCollisionBox.INSTANCE; + }; }, BlockTags.WALL_SIGNS.getStates().toArray(new StateType[0])), WALL_HANGING_SIGN((player, item, version, data, x, y, z) -> { - switch (data.getFacing()) { - case NORTH: - case SOUTH: - return new ComplexCollisionBox(new HexCollisionBox(0.0D, 14.0D, 6.0D, 16.0D, 16.0D, 10.0D), - new HexCollisionBox(1.0D, 0.0D, 7.0D, 15.0D, 10.0D, 9.0D)); - default: - return new ComplexCollisionBox(new HexCollisionBox(6.0D, 14.0D, 0.0D, 10.0D, 16.0D, 16.0D), - new HexCollisionBox(7.0D, 0.0D, 1.0D, 9.0D, 10.0D, 15.0D)); - } + return switch (data.getFacing()) { + case NORTH, SOUTH -> new ComplexCollisionBox(new HexCollisionBox(0.0D, 14.0D, 6.0D, 16.0D, 16.0D, 10.0D), + new HexCollisionBox(1.0D, 0.0D, 7.0D, 15.0D, 10.0D, 9.0D)); + default -> new ComplexCollisionBox(new HexCollisionBox(6.0D, 14.0D, 0.0D, 10.0D, 16.0D, 16.0D), + new HexCollisionBox(7.0D, 0.0D, 1.0D, 9.0D, 10.0D, 15.0D)); + }; }, BlockTags.WALL_HANGING_SIGNS.getStates().toArray(new StateType[0])), STANDING_SIGN((player, item, version, data, x, y, z) -> diff --git a/src/main/java/ac/grim/grimac/utils/collisions/blocks/DoorHandler.java b/src/main/java/ac/grim/grimac/utils/collisions/blocks/DoorHandler.java index 5a4d561981..7e8760f85e 100644 --- a/src/main/java/ac/grim/grimac/utils/collisions/blocks/DoorHandler.java +++ b/src/main/java/ac/grim/grimac/utils/collisions/blocks/DoorHandler.java @@ -21,18 +21,14 @@ public class DoorHandler implements CollisionFactory { @Override public CollisionBox fetch(GrimPlayer player, ClientVersion version, WrappedBlockState block, int x, int y, int z) { - switch (fetchDirection(player, version, block, x, y, z)) { - case NORTH: - return NORTH_AABB.copy(); - case SOUTH: - return SOUTH_AABB.copy(); - case EAST: - return EAST_AABB.copy(); - case WEST: - return WEST_AABB.copy(); - } + return switch (fetchDirection(player, version, block, x, y, z)) { + case NORTH -> NORTH_AABB.copy(); + case SOUTH -> SOUTH_AABB.copy(); + case EAST -> EAST_AABB.copy(); + case WEST -> WEST_AABB.copy(); + default -> NoCollisionBox.INSTANCE; + }; - return NoCollisionBox.INSTANCE; } public BlockFace fetchDirection(GrimPlayer player, ClientVersion version, WrappedBlockState door, int x, int y, int z) { @@ -80,16 +76,11 @@ public BlockFace fetchDirection(GrimPlayer player, ClientVersion version, Wrappe isRightHinge = door.getHinge() == Hinge.RIGHT; } - switch (facingDirection) { - case EAST: - default: - return isClosed ? BlockFace.EAST : (isRightHinge ? BlockFace.NORTH : BlockFace.SOUTH); - case SOUTH: - return isClosed ? BlockFace.SOUTH : (isRightHinge ? BlockFace.EAST : BlockFace.WEST); - case WEST: - return isClosed ? BlockFace.WEST : (isRightHinge ? BlockFace.SOUTH : BlockFace.NORTH); - case NORTH: - return isClosed ? BlockFace.NORTH : (isRightHinge ? BlockFace.WEST : BlockFace.EAST); - } + return switch (facingDirection) { + case SOUTH -> isClosed ? BlockFace.SOUTH : (isRightHinge ? BlockFace.EAST : BlockFace.WEST); + case WEST -> isClosed ? BlockFace.WEST : (isRightHinge ? BlockFace.SOUTH : BlockFace.NORTH); + case NORTH -> isClosed ? BlockFace.NORTH : (isRightHinge ? BlockFace.WEST : BlockFace.EAST); + default -> isClosed ? BlockFace.EAST : (isRightHinge ? BlockFace.NORTH : BlockFace.SOUTH); + }; } } diff --git a/src/main/java/ac/grim/grimac/utils/collisions/blocks/DynamicStair.java b/src/main/java/ac/grim/grimac/utils/collisions/blocks/DynamicStair.java index 80609ef5e2..34daed22a6 100644 --- a/src/main/java/ac/grim/grimac/utils/collisions/blocks/DynamicStair.java +++ b/src/main/java/ac/grim/grimac/utils/collisions/blocks/DynamicStair.java @@ -77,17 +77,12 @@ private static boolean isDifferentAxis(BlockFace faceOne, BlockFace faceTwo) { } private static BlockFace rotateYCCW(BlockFace face) { - switch (face) { - default: - case NORTH: - return BlockFace.WEST; - case EAST: - return BlockFace.NORTH; - case SOUTH: - return BlockFace.EAST; - case WEST: - return BlockFace.SOUTH; - } + return switch (face) { + case EAST -> BlockFace.NORTH; + case SOUTH -> BlockFace.EAST; + case WEST -> BlockFace.SOUTH; + default -> BlockFace.WEST; + }; } private static CollisionBox[] makeShapes(CollisionBox p_199779_0_, CollisionBox p_199779_1_, CollisionBox p_199779_2_, CollisionBox p_199779_3_, CollisionBox p_199779_4_) { @@ -134,36 +129,23 @@ private int getShapeIndex(WrappedBlockState state, int shapeOrdinal) { } private int directionToValue(BlockFace face) { - switch (face) { - default: - case UP: - case DOWN: - return -1; - case NORTH: - return 2; - case SOUTH: - return 0; - case WEST: - return 1; - case EAST: - return 3; - } + return switch (face) { + case NORTH -> 2; + case SOUTH -> 0; + case WEST -> 1; + case EAST -> 3; + default -> -1; + }; } private EnumShape toEnumShape(Shape shape) { - switch (shape) { - default: - case STRAIGHT: - return EnumShape.STRAIGHT; - case INNER_LEFT: - return EnumShape.INNER_LEFT; - case INNER_RIGHT: - return EnumShape.INNER_RIGHT; - case OUTER_LEFT: - return EnumShape.OUTER_LEFT; - case OUTER_RIGHT: - return EnumShape.OUTER_RIGHT; - } + return switch (shape) { + case INNER_LEFT -> EnumShape.INNER_LEFT; + case INNER_RIGHT -> EnumShape.INNER_RIGHT; + case OUTER_LEFT -> EnumShape.OUTER_LEFT; + case OUTER_RIGHT -> EnumShape.OUTER_RIGHT; + default -> EnumShape.STRAIGHT; + }; } enum EnumShape { diff --git a/src/main/java/ac/grim/grimac/utils/collisions/blocks/PistonBaseCollision.java b/src/main/java/ac/grim/grimac/utils/collisions/blocks/PistonBaseCollision.java index 80a894bfbf..b4ebd56454 100644 --- a/src/main/java/ac/grim/grimac/utils/collisions/blocks/PistonBaseCollision.java +++ b/src/main/java/ac/grim/grimac/utils/collisions/blocks/PistonBaseCollision.java @@ -14,20 +14,13 @@ public class PistonBaseCollision implements CollisionFactory { public CollisionBox fetch(GrimPlayer player, ClientVersion version, WrappedBlockState block, int x, int y, int z) { if (!block.isExtended()) return new SimpleCollisionBox(0, 0, 0, 1, 1, 1, true); - switch (block.getFacing()) { - default: - case DOWN: - return new HexCollisionBox(0, 4, 0, 16, 16, 16); - case UP: - return new HexCollisionBox(0, 0, 0, 16, 12, 16); - case NORTH: - return new HexCollisionBox(0, 0, 4, 16, 16, 16); - case SOUTH: - return new HexCollisionBox(0, 0, 0, 16, 16, 12); - case WEST: - return new HexCollisionBox(4, 0, 0, 16, 16, 16); - case EAST: - return new HexCollisionBox(0, 0, 0, 12, 16, 16); - } + return switch (block.getFacing()) { + case UP -> new HexCollisionBox(0, 0, 0, 16, 12, 16); + case NORTH -> new HexCollisionBox(0, 0, 4, 16, 16, 16); + case SOUTH -> new HexCollisionBox(0, 0, 0, 16, 16, 12); + case WEST -> new HexCollisionBox(4, 0, 0, 16, 16, 16); + case EAST -> new HexCollisionBox(0, 0, 0, 12, 16, 16); + default -> new HexCollisionBox(0, 4, 0, 16, 16, 16); + }; } } diff --git a/src/main/java/ac/grim/grimac/utils/collisions/blocks/PistonHeadCollision.java b/src/main/java/ac/grim/grimac/utils/collisions/blocks/PistonHeadCollision.java index 0e1c63cd6d..82d999b942 100644 --- a/src/main/java/ac/grim/grimac/utils/collisions/blocks/PistonHeadCollision.java +++ b/src/main/java/ac/grim/grimac/utils/collisions/blocks/PistonHeadCollision.java @@ -38,38 +38,35 @@ public CollisionBox fetch(GrimPlayer player, ClientVersion version, WrappedBlock longAmount = 0; - switch (block.getFacing()) { - case DOWN: - default: - return new ComplexCollisionBox(new HexCollisionBox(0, 0, 0, 16, 4, 16), - new HexCollisionBox(6, 4, 6, 10, 16 + longAmount, 10)); - case UP: - return new ComplexCollisionBox(new HexCollisionBox(0, 12, 0, 16, 16, 16), - new HexCollisionBox(6, 0 - longAmount, 6, 10, 12, 10)); - case NORTH: - return new ComplexCollisionBox(new HexCollisionBox(0, 0, 0, 16, 16, 4), - new HexCollisionBox(6, 6, 4, 10, 10, 16 + longAmount)); - case SOUTH: + return switch (block.getFacing()) { + case UP -> new ComplexCollisionBox(new HexCollisionBox(0, 12, 0, 16, 16, 16), + new HexCollisionBox(6, 0 - longAmount, 6, 10, 12, 10)); + case NORTH -> new ComplexCollisionBox(new HexCollisionBox(0, 0, 0, 16, 16, 4), + new HexCollisionBox(6, 6, 4, 10, 10, 16 + longAmount)); + case SOUTH -> { // SOUTH piston is glitched in 1.7 and 1.8, fixed in 1.9 // Don't bother with short piston boxes as 1.7/1.8 clients don't have them if (version.isOlderThanOrEquals(ClientVersion.V_1_8)) - return new ComplexCollisionBox(new HexCollisionBox(0, 0, 12, 16, 16, 16), + yield new ComplexCollisionBox(new HexCollisionBox(0, 0, 12, 16, 16, 16), new HexCollisionBox(4, 6, 0, 12, 10, 12)); - return new ComplexCollisionBox(new HexCollisionBox(0, 0, 12, 16, 16, 16), + yield new ComplexCollisionBox(new HexCollisionBox(0, 0, 12, 16, 16, 16), new HexCollisionBox(6, 6, 0 - longAmount, 10, 10, 12)); - case WEST: + } + case WEST -> { // WEST piston is glitched in 1.7 and 1.8, fixed in 1.9 // Don't bother with short piston boxes as 1.7/1.8 clients don't have them if (version.isOlderThanOrEquals(ClientVersion.V_1_8)) - return new ComplexCollisionBox(new HexCollisionBox(0, 0, 0, 4, 16, 16), + yield new ComplexCollisionBox(new HexCollisionBox(0, 0, 0, 4, 16, 16), new HexCollisionBox(6, 4, 4, 10, 12, 16)); - return new ComplexCollisionBox(new HexCollisionBox(0, 0, 0, 4, 16, 16), + yield new ComplexCollisionBox(new HexCollisionBox(0, 0, 0, 4, 16, 16), new HexCollisionBox(4, 6, 6, 16 + longAmount, 10, 10)); - case EAST: - return new ComplexCollisionBox(new HexCollisionBox(12, 0, 0, 16, 16, 16), - new HexCollisionBox(0 - longAmount, 6, 4, 12, 10, 12)); - } + } + case EAST -> new ComplexCollisionBox(new HexCollisionBox(12, 0, 0, 16, 16, 16), + new HexCollisionBox(0 - longAmount, 6, 4, 12, 10, 12)); + default -> new ComplexCollisionBox(new HexCollisionBox(0, 0, 0, 16, 4, 16), + new HexCollisionBox(6, 4, 6, 10, 16 + longAmount, 10)); + }; } } diff --git a/src/main/java/ac/grim/grimac/utils/collisions/datatypes/SimpleCollisionBox.java b/src/main/java/ac/grim/grimac/utils/collisions/datatypes/SimpleCollisionBox.java index 0c1cf2bdd2..e653bd86c3 100644 --- a/src/main/java/ac/grim/grimac/utils/collisions/datatypes/SimpleCollisionBox.java +++ b/src/main/java/ac/grim/grimac/utils/collisions/datatypes/SimpleCollisionBox.java @@ -264,19 +264,13 @@ public boolean isSideFullBlock(BlockFace axis) { // Get the direction of block we are trying to connect to -> towards the block that is trying to connect final BlockFace faceToSourceConnector = axis.getOppositeFace(); - switch (faceToSourceConnector) { - case EAST: - case WEST: - return this.minX == 0 && this.maxX == 1; - case UP: - case DOWN: - return this.minY == 0 && this.maxY == 1; - case NORTH: - case SOUTH: - return this.minZ == 0 && this.maxZ == 1; - } + return switch (faceToSourceConnector) { + case EAST, WEST -> this.minX == 0 && this.maxX == 1; + case UP, DOWN -> this.minY == 0 && this.maxY == 1; + case NORTH, SOUTH -> this.minZ == 0 && this.maxZ == 1; + default -> false; + }; - return false; } public boolean isFullBlockNoCache() { diff --git a/src/main/java/ac/grim/grimac/utils/data/Pair.java b/src/main/java/ac/grim/grimac/utils/data/Pair.java index 757f5c04b8..83362122f7 100644 --- a/src/main/java/ac/grim/grimac/utils/data/Pair.java +++ b/src/main/java/ac/grim/grimac/utils/data/Pair.java @@ -20,25 +20,10 @@ import java.util.Objects; -public class Pair { - private final A first; - private final B second; - - public Pair(A first, B second) { - this.first = first; - this.second = second; - } +public record Pair(A first, B second) { public static Pair of(T a, K b) { - return new Pair(a, b); - } - - public A getFirst() { - return first; - } - - public B getSecond() { - return second; + return new Pair<>(a, b); } @Override diff --git a/src/main/java/ac/grim/grimac/utils/inventory/EquipmentType.java b/src/main/java/ac/grim/grimac/utils/inventory/EquipmentType.java index df09e2e471..a07ae199f0 100644 --- a/src/main/java/ac/grim/grimac/utils/inventory/EquipmentType.java +++ b/src/main/java/ac/grim/grimac/utils/inventory/EquipmentType.java @@ -13,18 +13,13 @@ public enum EquipmentType { HEAD; public static EquipmentType byArmorID(int id) { - switch (id) { - case 0: - return HEAD; - case 1: - return CHEST; - case 2: - return LEGS; - case 3: - return FEET; - default: - return MAINHAND; - } + return switch (id) { + case 0 -> HEAD; + case 1 -> CHEST; + case 2 -> LEGS; + case 3 -> FEET; + default -> MAINHAND; + }; } public static EquipmentType getEquipmentSlotForItem(ItemStack p_147234_) { @@ -64,21 +59,11 @@ public boolean isArmor() { } public int getIndex() { - switch (this) { - case MAINHAND: - return 0; - case OFFHAND: - return 1; - case FEET: - return 0; - case LEGS: - return 1; - case CHEST: - return 2; - case HEAD: - return 3; - default: - return -1; - } + return switch (this) { + case MAINHAND, FEET -> 0; + case OFFHAND, LEGS -> 1; + case CHEST -> 2; + case HEAD -> 3; + }; } } diff --git a/src/main/java/ac/grim/grimac/utils/inventory/inventory/MenuType.java b/src/main/java/ac/grim/grimac/utils/inventory/inventory/MenuType.java index 3350a45c17..769a8776f5 100644 --- a/src/main/java/ac/grim/grimac/utils/inventory/inventory/MenuType.java +++ b/src/main/java/ac/grim/grimac/utils/inventory/inventory/MenuType.java @@ -58,38 +58,24 @@ public static MenuType getMenuType(int id) { public static AbstractContainerMenu getMenuFromID(GrimPlayer player, Inventory playerInventory, MenuType type) { - switch (type) { - case GENERIC_9x1: - case GENERIC_9x2: - case GENERIC_9x3: - case GENERIC_9x4: - case GENERIC_9x5: - case GENERIC_9x6: - return new BasicInventoryMenu(player, playerInventory, type.getId() + 1); - case GENERIC_3x3: - return new DispenserMenu(player, playerInventory); - case HOPPER: - return new HopperMenu(player, playerInventory); - default: - return new NotImplementedMenu(player, playerInventory); - } + return switch (type) { + case GENERIC_9x1, GENERIC_9x2, GENERIC_9x3, GENERIC_9x4, GENERIC_9x5, GENERIC_9x6 -> + new BasicInventoryMenu(player, playerInventory, type.getId() + 1); + case GENERIC_3x3 -> new DispenserMenu(player, playerInventory); + case HOPPER -> new HopperMenu(player, playerInventory); + default -> new NotImplementedMenu(player, playerInventory); + }; } public static AbstractContainerMenu getMenuFromString(GrimPlayer player, Inventory inventory, String legacyType, int slots, int horse) { - switch (legacyType) { - case "minecraft:chest": - case "minecraft:container": - return new BasicInventoryMenu(player, inventory, slots / 9); - case "minecraft:dispenser": - case "minecraft:dropper": - return new DispenserMenu(player, inventory); - case "minecraft:hopper": - return new HopperMenu(player, inventory); - case "minecraft:shulker_box": - return new BasicInventoryMenu(player, inventory, 3); - default: // Villager menu - return new NotImplementedMenu(player, inventory); - } + return switch (legacyType) { + case "minecraft:chest", "minecraft:container" -> new BasicInventoryMenu(player, inventory, slots / 9); + case "minecraft:dispenser", "minecraft:dropper" -> new DispenserMenu(player, inventory); + case "minecraft:hopper" -> new HopperMenu(player, inventory); + case "minecraft:shulker_box" -> new BasicInventoryMenu(player, inventory, 3); + default -> // Villager menu + new NotImplementedMenu(player, inventory); + }; } } diff --git a/src/main/java/ac/grim/grimac/utils/latency/CompensatedEntities.java b/src/main/java/ac/grim/grimac/utils/latency/CompensatedEntities.java index f4f93504ab..67bc7901d0 100644 --- a/src/main/java/ac/grim/grimac/utils/latency/CompensatedEntities.java +++ b/src/main/java/ac/grim/grimac/utils/latency/CompensatedEntities.java @@ -24,7 +24,6 @@ import com.github.retrooper.packetevents.util.Vector3d; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateAttributes; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import org.bukkit.Bukkit; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import java.util.*; @@ -73,8 +72,7 @@ public void removeEntity(int entityID) { PacketEntity entity = entityMap.remove(entityID); if (entity == null) return; - if (entity instanceof PacketEntityEnderDragon) { - PacketEntityEnderDragon dragon = (PacketEntityEnderDragon) entity; + if (entity instanceof PacketEntityEnderDragon dragon) { for (int i = 1; i < dragon.getParts().size() + 1; i++) { entityMap.remove(entityID + i); } @@ -137,7 +135,7 @@ public void updateAttributes(int entityID, List valuedAttribute = entity.getAttribute(attribute); - if (!valuedAttribute.isPresent()) { + if (valuedAttribute.isEmpty()) { // Not an attribute we want to track continue; } @@ -374,8 +372,7 @@ public void updateEntityMetadata(int entityID, List watchableObjects // track camel dashing if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_20)) { - if (entity instanceof PacketEntityCamel) { - PacketEntityCamel camel = (PacketEntityCamel) entity; + if (entity instanceof PacketEntityCamel camel) { EntityData entityData = WatchableIndexUtil.getIndex(watchableObjects, 18); if (entityData != null) { camel.dashing = (boolean) entityData.getValue(); diff --git a/src/main/java/ac/grim/grimac/utils/latency/CompensatedInventory.java b/src/main/java/ac/grim/grimac/utils/latency/CompensatedInventory.java index bece20fc48..123b6c7f3b 100644 --- a/src/main/java/ac/grim/grimac/utils/latency/CompensatedInventory.java +++ b/src/main/java/ac/grim/grimac/utils/latency/CompensatedInventory.java @@ -166,25 +166,17 @@ public ItemStack getBoots() { } private ItemStack getByEquipmentType(EquipmentType type) { - switch (type) { - case HEAD: - return getHelmet(); - case CHEST: - return getChestplate(); - case LEGS: - return getLeggings(); - case FEET: - return getBoots(); - case OFFHAND: - return getOffHand(); - case MAINHAND: - return getHeldItem(); - default: - return ItemStack.EMPTY; - } + return switch (type) { + case HEAD -> getHelmet(); + case CHEST -> getChestplate(); + case LEGS -> getLeggings(); + case FEET -> getBoots(); + case OFFHAND -> getOffHand(); + case MAINHAND -> getHeldItem(); + default -> ItemStack.EMPTY; + }; } - public boolean hasItemType(ItemType type) { if (isPacketInventoryActive || player.bukkitPlayer == null) return inventory.hasItemType(type); diff --git a/src/main/java/ac/grim/grimac/utils/latency/CompensatedWorld.java b/src/main/java/ac/grim/grimac/utils/latency/CompensatedWorld.java index 6bcda08dfc..a355f25fe6 100644 --- a/src/main/java/ac/grim/grimac/utils/latency/CompensatedWorld.java +++ b/src/main/java/ac/grim/grimac/utils/latency/CompensatedWorld.java @@ -607,7 +607,7 @@ public boolean isWaterSourceBlock(int x, int y, int z) { } public boolean containsLiquid(SimpleCollisionBox var0) { - return Collisions.hasMaterial(player, var0, data -> Materials.isWater(player.getClientVersion(), data.getFirst()) || data.getFirst().getType() == StateTypes.LAVA); + return Collisions.hasMaterial(player, var0, data -> Materials.isWater(player.getClientVersion(), data.first()) || data.first().getType() == StateTypes.LAVA); } public double getLavaFluidLevelAt(int x, int y, int z) { @@ -629,7 +629,7 @@ public double getLavaFluidLevelAt(int x, int y, int z) { } public boolean containsLava(SimpleCollisionBox var0) { - return Collisions.hasMaterial(player, var0, data -> data.getFirst().getType() == StateTypes.LAVA); + return Collisions.hasMaterial(player, var0, data -> data.first().getType() == StateTypes.LAVA); } public double getWaterFluidLevelAt(double x, double y, double z) { diff --git a/src/main/java/ac/grim/grimac/utils/latency/LatencyUtils.java b/src/main/java/ac/grim/grimac/utils/latency/LatencyUtils.java index 05bdad1f68..8b56882e2b 100644 --- a/src/main/java/ac/grim/grimac/utils/latency/LatencyUtils.java +++ b/src/main/java/ac/grim/grimac/utils/latency/LatencyUtils.java @@ -43,17 +43,17 @@ public void handleNettySyncTransaction(int transaction) { Pair pair = iterator.next(); // We are at most a tick ahead when running tasks based on transactions, meaning this is too far - if (transaction + 1 < pair.getFirst()) + if (transaction + 1 < pair.first()) return; // This is at most tick ahead of what we want - if (transaction == pair.getFirst() - 1) + if (transaction == pair.first() - 1) continue; try { // Run the task - pair.getSecond().run(); + pair.second().run(); } catch (Exception e) { System.out.println("An error has occurred when running transactions for player: " + player.user.getName()); e.printStackTrace(); diff --git a/src/main/java/ac/grim/grimac/utils/lists/CorrectingPlayerInventoryStorage.java b/src/main/java/ac/grim/grimac/utils/lists/CorrectingPlayerInventoryStorage.java index 2a490fb59a..d22c830afc 100644 --- a/src/main/java/ac/grim/grimac/utils/lists/CorrectingPlayerInventoryStorage.java +++ b/src/main/java/ac/grim/grimac/utils/lists/CorrectingPlayerInventoryStorage.java @@ -18,7 +18,7 @@ * Or copy (and debug) over around 5k lines of code to accomplish inventories * Grim uses a hybrid system for inventories - we lag compensate but rely on the server * for the ultimate source of truth, and resync if what we found is different from what the server sees - * + *

* This also patches most desync's that happen with inventories on some versions like 1.8 or * other desync's introduced by mojang or viabackwards * diff --git a/src/main/java/ac/grim/grimac/utils/nmsutil/BlockBreakSpeed.java b/src/main/java/ac/grim/grimac/utils/nmsutil/BlockBreakSpeed.java index bdde14c1a8..08d9fccadf 100644 --- a/src/main/java/ac/grim/grimac/utils/nmsutil/BlockBreakSpeed.java +++ b/src/main/java/ac/grim/grimac/utils/nmsutil/BlockBreakSpeed.java @@ -136,7 +136,7 @@ public static double getBlockDamage(GrimPlayer player, Vector3i position) { OptionalInt conduit = player.compensatedEntities.getPotionLevelForPlayer(PotionTypes.CONDUIT_POWER); if (digSpeed.isPresent() || conduit.isPresent()) { - int hasteLevel = Math.max(!digSpeed.isPresent() ? 0 : digSpeed.getAsInt(), !conduit.isPresent() ? 0 : conduit.getAsInt()); + int hasteLevel = Math.max(digSpeed.isEmpty() ? 0 : digSpeed.getAsInt(), !conduit.isPresent() ? 0 : conduit.getAsInt()); speedMultiplier *= (float) (1 + (0.2 * (hasteLevel + 1))); } diff --git a/src/main/java/ac/grim/grimac/utils/nmsutil/BlockProperties.java b/src/main/java/ac/grim/grimac/utils/nmsutil/BlockProperties.java index e516832fe5..007d299ed9 100644 --- a/src/main/java/ac/grim/grimac/utils/nmsutil/BlockProperties.java +++ b/src/main/java/ac/grim/grimac/utils/nmsutil/BlockProperties.java @@ -29,13 +29,12 @@ public static float getFrictionInfluencedSpeed(float f, GrimPlayer player) { return (float) (player.speed * 0.1f); } - if (player.compensatedEntities.getSelf().getRiding() instanceof PacketEntityStrider) { + if (player.compensatedEntities.getSelf().getRiding() instanceof PacketEntityStrider strider) { // Unsure which version the speed changed in if (player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_20)) { return (float) player.speed * 0.1f; } - PacketEntityStrider strider = (PacketEntityStrider) player.compensatedEntities.getSelf().getRiding(); // Vanilla multiplies by 0.1 to calculate speed return (float) strider.getAttributeValue(Attributes.GENERIC_MOVEMENT_SPEED) * (strider.isShaking ? 0.66F : 1.0F) * 0.1f; } diff --git a/src/main/java/ac/grim/grimac/utils/nmsutil/BoundingBoxSize.java b/src/main/java/ac/grim/grimac/utils/nmsutil/BoundingBoxSize.java index c841f8d33b..5bea4802f5 100644 --- a/src/main/java/ac/grim/grimac/utils/nmsutil/BoundingBoxSize.java +++ b/src/main/java/ac/grim/grimac/utils/nmsutil/BoundingBoxSize.java @@ -129,9 +129,7 @@ public static Vector3d getRidingOffsetFromVehicle(PacketEntity entity, GrimPlaye double y = box.minY; double z = (box.maxZ + box.minZ) / 2.0; - if (entity instanceof PacketEntityTrackXRot) { - PacketEntityTrackXRot xRotEntity = (PacketEntityTrackXRot) entity; - + if (entity instanceof PacketEntityTrackXRot xRotEntity) { // Horses desync here, and we can't do anything about it without interpolating animations. // Mojang just has to fix it. I'm not attempting to fix it. // Striders also do the same with animations, causing a desync. diff --git a/src/main/java/ac/grim/grimac/utils/nmsutil/MainSupportingBlockPosFinder.java b/src/main/java/ac/grim/grimac/utils/nmsutil/MainSupportingBlockPosFinder.java index cfc664315e..ead3762a72 100644 --- a/src/main/java/ac/grim/grimac/utils/nmsutil/MainSupportingBlockPosFinder.java +++ b/src/main/java/ac/grim/grimac/utils/nmsutil/MainSupportingBlockPosFinder.java @@ -21,7 +21,7 @@ public MainSupportingBlockData findMainSupportingBlockPos(GrimPlayer player, Mai SimpleCollisionBox slightlyBelowPlayer = new SimpleCollisionBox(maxPose.minX, maxPose.minY - 1.0E-6D, maxPose.minZ, maxPose.maxX, maxPose.minY, maxPose.maxZ); Optional supportingBlock = findSupportingBlock(player, slightlyBelowPlayer); - if (!supportingBlock.isPresent() && (!lastSupportingBlock.lastOnGroundAndNoBlock())) { + if (supportingBlock.isEmpty() && (!lastSupportingBlock.lastOnGroundAndNoBlock())) { if (lastMovement != null) { SimpleCollisionBox aabb2 = slightlyBelowPlayer.offset(-lastMovement.x, 0.0D, -lastMovement.z); supportingBlock = findSupportingBlock(player, aabb2);