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 732d149f4b..c89a83abfd 100644 --- a/src/main/java/ac/grim/grimac/utils/collisions/CollisionData.java +++ b/src/main/java/ac/grim/grimac/utils/collisions/CollisionData.java @@ -166,32 +166,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), DOOR(new DoorHandler(), BlockTags.DOORS.getStates().toArray(new StateType[0])), @@ -351,17 +341,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) -> { @@ -528,18 +513,12 @@ 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 DynamicCollisionFence(), BlockTags.FENCES.getStates().toArray(new StateType[0])), @@ -754,32 +733,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) -> { @@ -828,53 +797,37 @@ public enum CollisionData { }, StateTypes.TRIPWIRE), 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), // 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()); @@ -992,19 +945,13 @@ 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((player, version, data, x, y, z) -> { @@ -1039,16 +986,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])), DEFAULT(new SimpleCollisionBox(0, 0, 0, 1, 1, 1, true), StateTypes.STONE); @@ -1086,21 +1028,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) { @@ -1109,17 +1044,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; + }; } public static CollisionBox getCocoa(ClientVersion version, int age, BlockFace direction) { @@ -1174,18 +1105,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 ae48640729..038156e0bd 100644 --- a/src/main/java/ac/grim/grimac/utils/collisions/HitboxData.java +++ b/src/main/java/ac/grim/grimac/utils/collisions/HitboxData.java @@ -20,32 +20,29 @@ public enum HitboxData { RAILS((player, item, version, data, x, y, z) -> { - switch (data.getShape()) { - case ASCENDING_NORTH: - case ASCENDING_SOUTH: - case ASCENDING_EAST: - case ASCENDING_WEST: + return switch (data.getShape()) { + case ASCENDING_NORTH, ASCENDING_SOUTH, ASCENDING_EAST, ASCENDING_WEST -> { if (version.isOlderThan(ClientVersion.V_1_8)) { StateType railType = data.getType(); // Activator rails always appear as flat detector rails in 1.7.10 because of ViaVersion // Ascending power rails in 1.7 have flat rail hitbox https://bugs.mojang.com/browse/MC-9134 if (railType == StateTypes.ACTIVATOR_RAIL || (railType == StateTypes.POWERED_RAIL && data.isPowered())) { - return new SimpleCollisionBox(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F, false); + yield new SimpleCollisionBox(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F, false); } - return new SimpleCollisionBox(0.0F, 0.0F, 0.0F, 1.0F, 0.625F, 1.0F, false); + yield new SimpleCollisionBox(0.0F, 0.0F, 0.0F, 1.0F, 0.625F, 1.0F, false); } else if (version.isOlderThan(ClientVersion.V_1_9)) { - return new SimpleCollisionBox(0.0F, 0.0F, 0.0F, 1.0F, 0.625F, 1.0F, false); + yield new SimpleCollisionBox(0.0F, 0.0F, 0.0F, 1.0F, 0.625F, 1.0F, false); } else if (version.isNewerThanOrEquals(ClientVersion.V_1_9) && version.isOlderThan(ClientVersion.V_1_10)) { // https://bugs.mojang.com/browse/MC-89552 sloped rails in 1.9 - it is slightly taller than a regular rail - return new SimpleCollisionBox(0.0F, 0.0F, 0.0F, 1.0F, 0.1875F, 1.0F, false); + yield new SimpleCollisionBox(0.0F, 0.0F, 0.0F, 1.0F, 0.1875F, 1.0F, false); } else if (version.isOlderThan(ClientVersion.V_1_11)) { // https://bugs.mojang.com/browse/MC-102638 All sloped rails are full blocks in 1.10 - return new SimpleCollisionBox(0, 0, 0, 1, 1, 1, true); + yield new SimpleCollisionBox(0, 0, 0, 1, 1, 1, true); } - return new HexCollisionBox(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D); - default: - return new HexCollisionBox(0.0D, 0.0D, 0.0D, 16.0D, 2.0D, 16.0D); - } + yield new HexCollisionBox(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D); + } + default -> new HexCollisionBox(0.0D, 0.0D, 0.0D, 16.0D, 2.0D, 16.0D); + }; }, BlockTags.RAILS.getStates().toArray(new StateType[0])), END_PORTAL((player, item, version, data, x, y, z) -> { @@ -109,35 +106,31 @@ public enum HitboxData { } } - switch (face) { - case FLOOR: + return switch (face) { + case FLOOR -> { // X-AXIS if (facing == BlockFace.EAST || facing == BlockFace.WEST) { - return new SimpleCollisionBox(0.25, 0.0, 0.3125, 0.75, 0.375, 0.6875, false); + yield new SimpleCollisionBox(0.25, 0.0, 0.3125, 0.75, 0.375, 0.6875, false); } // Z-AXIS - return new SimpleCollisionBox(0.3125, 0.0, 0.25, 0.6875, 0.375, 0.75, false); - case WALL: - switch (facing) { - case EAST: - return new SimpleCollisionBox(0.0, 0.25, 0.3125, 0.375, 0.75, 0.6875, false); - case WEST: - return new SimpleCollisionBox(0.625, 0.25, 0.3125, 1.0, 0.75, 0.6875, false); - case SOUTH: - return new SimpleCollisionBox(0.3125, 0.25, 0.0, 0.6875, 0.75, 0.375, false); - case NORTH: - default: - return new SimpleCollisionBox(0.3125, 0.25, 0.625, 0.6875, 0.75, 1.0, false); - } - case CEILING: - default: + yield new SimpleCollisionBox(0.3125, 0.0, 0.25, 0.6875, 0.375, 0.75, false); + // Z-AXIS + } + case WALL -> switch (facing) { + case EAST -> new SimpleCollisionBox(0.0, 0.25, 0.3125, 0.375, 0.75, 0.6875, false); + case WEST -> new SimpleCollisionBox(0.625, 0.25, 0.3125, 1.0, 0.75, 0.6875, false); + case SOUTH -> new SimpleCollisionBox(0.3125, 0.25, 0.0, 0.6875, 0.75, 0.375, false); + default -> new SimpleCollisionBox(0.3125, 0.25, 0.625, 0.6875, 0.75, 1.0, false); + }; + default -> { // X-AXIS if (facing == BlockFace.EAST || facing == BlockFace.WEST) { - return new SimpleCollisionBox(0.25, 0.625, 0.3125, 0.75, 1.0, 0.6875, false); + yield new SimpleCollisionBox(0.25, 0.625, 0.3125, 0.75, 1.0, 0.6875, false); } // Z-Axis - return new SimpleCollisionBox(0.3125, 0.625, 0.25, 0.6875, 1.0, 0.75, false); - } + yield new SimpleCollisionBox(0.3125, 0.625, 0.25, 0.6875, 1.0, 0.75, false); + } + }; }), StateTypes.LEVER), BUTTON((player, item, version, data, x, y, z) -> { @@ -171,27 +164,17 @@ public enum HitboxData { switch (face) { 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: // ViaVersion shows lever if (player.getClientVersion().isOlderThan(ClientVersion.V_1_8)) { @@ -222,30 +205,22 @@ public enum HitboxData { WALL(new DynamicHitboxWall(), BlockTags.WALLS.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) -> @@ -270,18 +245,13 @@ public enum HitboxData { return WALL_SIGN.dynamic.fetch(player, item, version, data, x, y, z); } - switch (data.getFacing()) { - case NORTH: - return new HexCollisionBox(0.0, 0.0, 14.0, 16.0, 12.5, 16.0); - case EAST: - return new HexCollisionBox(0.0, 0.0, 0.0, 2.0, 12.5, 16.0); - case WEST: - return new HexCollisionBox(14.0, 0.0, 0.0, 16.0, 12.5, 16.0); - case SOUTH: - return new HexCollisionBox(0.0, 0.0, 0.0, 16.0, 12.5, 2.0); - default: - throw new IllegalStateException("Impossible Banner Facing State; Something very wrong is going on"); - } + return switch (data.getFacing()) { + case NORTH -> new HexCollisionBox(0.0, 0.0, 14.0, 16.0, 12.5, 16.0); + case EAST -> new HexCollisionBox(0.0, 0.0, 0.0, 2.0, 12.5, 16.0); + case WEST -> new HexCollisionBox(14.0, 0.0, 0.0, 16.0, 12.5, 16.0); + case SOUTH -> new HexCollisionBox(0.0, 0.0, 0.0, 16.0, 12.5, 2.0); + default -> throw new IllegalStateException("Impossible Banner Facing State; Something very wrong is going on"); + }; }, StateTypes.WHITE_WALL_BANNER, StateTypes.ORANGE_WALL_BANNER, StateTypes.MAGENTA_WALL_BANNER, StateTypes.LIGHT_BLUE_WALL_BANNER, StateTypes.YELLOW_WALL_BANNER, StateTypes.LIME_WALL_BANNER, StateTypes.PINK_WALL_BANNER, StateTypes.GRAY_WALL_BANNER, StateTypes.LIGHT_GRAY_WALL_BANNER, @@ -425,17 +395,12 @@ public enum HitboxData { 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, item, version, data, x, y, z) -> { @@ -670,16 +635,11 @@ public static CollisionBox getBlockHitbox(GrimPlayer player, StateType heldItem, } private static int getPropaguleMinHeight(int age) { - switch (age) { - case 0: - case 1: - case 2: - return 13 - age * 3; - case 3: - case 4: - return (4 - age) * 3; - } - throw new IllegalStateException("Impossible Propagule Height"); + return switch (age) { + case 0, 1, 2 -> 13 - age * 3; + case 3, 4 -> (4 - age) * 3; + default -> throw new IllegalStateException("Impossible Propagule Height"); + }; } private static CollisionBox getVineCollisionBox(ClientVersion version, boolean isWeeping, boolean isBlock) { @@ -703,19 +663,13 @@ private static CollisionBox getVineCollisionBox(ClientVersion version, boolean i } private static int getHorizontalID(BlockFace facing) { - switch (facing) { - case DOWN: - case UP: - return -1; - case NORTH: - return 2; - case SOUTH: - return 0; - case WEST: - return 1; - case EAST: - return 3; - } - throw new IllegalStateException("Impossible blockface for getHorizontalID"); + return switch (facing) { + case DOWN, UP -> -1; + case NORTH -> 2; + case SOUTH -> 0; + case WEST -> 1; + case EAST -> 3; + default -> throw new IllegalStateException("Impossible blockface for getHorizontalID"); + }; } } diff --git a/src/main/java/ac/grim/grimac/utils/collisions/blocks/connecting/DynamicCollisionFence.java b/src/main/java/ac/grim/grimac/utils/collisions/blocks/connecting/DynamicCollisionFence.java index bb531178d5..dc4aa58c3e 100644 --- a/src/main/java/ac/grim/grimac/utils/collisions/blocks/connecting/DynamicCollisionFence.java +++ b/src/main/java/ac/grim/grimac/utils/collisions/blocks/connecting/DynamicCollisionFence.java @@ -4,7 +4,6 @@ import ac.grim.grimac.utils.collisions.CollisionData; import ac.grim.grimac.utils.collisions.datatypes.CollisionBox; import ac.grim.grimac.utils.collisions.datatypes.CollisionFactory; -import ac.grim.grimac.utils.collisions.datatypes.SimpleCollisionBox; import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.protocol.player.ClientVersion; diff --git a/src/main/java/ac/grim/grimac/utils/collisions/blocks/connecting/DynamicHitboxPane.java b/src/main/java/ac/grim/grimac/utils/collisions/blocks/connecting/DynamicHitboxPane.java index 8bc91acc84..39226ed407 100644 --- a/src/main/java/ac/grim/grimac/utils/collisions/blocks/connecting/DynamicHitboxPane.java +++ b/src/main/java/ac/grim/grimac/utils/collisions/blocks/connecting/DynamicHitboxPane.java @@ -106,4 +106,4 @@ public boolean checkCanConnect(GrimPlayer player, WrappedBlockState state, State .isSideFullBlock(direction); } } -} \ No newline at end of file +} diff --git a/src/main/java/ac/grim/grimac/utils/collisions/blocks/connecting/DynamicHitboxWall.java b/src/main/java/ac/grim/grimac/utils/collisions/blocks/connecting/DynamicHitboxWall.java index e9ec8fde1e..d633c45c9b 100644 --- a/src/main/java/ac/grim/grimac/utils/collisions/blocks/connecting/DynamicHitboxWall.java +++ b/src/main/java/ac/grim/grimac/utils/collisions/blocks/connecting/DynamicHitboxWall.java @@ -108,4 +108,4 @@ public boolean checkCanConnect(GrimPlayer player, WrappedBlockState state, State return BlockTags.WALLS.contains(one) || CollisionData.getData(one).getMovementCollisionBox(player, player.getClientVersion(), state, 0, 0, 0).isSideFullBlock(direction); } -} \ No newline at end of file +}