diff --git a/data-generator/build.gradle.kts b/data-generator/build.gradle.kts index 732eddf5..3752bbf5 100644 --- a/data-generator/build.gradle.kts +++ b/data-generator/build.gradle.kts @@ -14,7 +14,7 @@ repositories { dependencies { implementation("org.vineflower:vineflower:1.10.1") - implementation("com.github.javaparser:javaparser-symbol-solver-core:3.26.2") + implementation("com.github.javaparser:javaparser-symbol-solver-core:3.26.3") } unimined.minecraft { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 571dcba2..fd94c5a4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -61,7 +61,7 @@ kyori-ansi = { module = "net.kyori:adventure-text-serializer-ansi", version.ref commons-validator = "commons-validator:commons-validator:1.9.0" commons-io = "commons-io:commons-io:2.18.0" oshi = "com.github.oshi:oshi-core:6.6.5" -guava = "com.google.guava:guava:33.3.1-jre" +guava = "com.google.guava:guava:33.4.0-jre" gson = "com.google.code.gson:gson:2.11.0" pf4j = "org.pf4j:pf4j:3.13.0" fastutil = "it.unimi.dsi:fastutil:8.5.15" @@ -80,7 +80,7 @@ grpc-stub = { module = "io.grpc:grpc-stub", version.ref = "grpc" } grpc-netty = { module = "io.grpc:grpc-netty", version.ref = "grpc" } protobuf-bom = { module = "com.google.protobuf:protobuf-bom", version.ref = "protobuf" } protobuf-util = { module = "com.google.protobuf:protobuf-java-util", version.ref = "protobuf" } -netty-bom = "io.netty:netty-bom:4.1.115.Final" +netty-bom = "io.netty:netty-bom:4.1.116.Final" armeria-bom = { module = "com.linecorp.armeria:armeria-bom", version.ref = "armeria" } armeria = { module = "com.linecorp.armeria:armeria" } armeria-grpc = { module = "com.linecorp.armeria:armeria-grpc" } @@ -92,7 +92,7 @@ spark = "me.lucko:spark-common:1.10.119-SNAPSHOT" ollama4j = "io.github.ollama4j:ollama4j:1.0.90" immutables = "org.immutables:value:2.10.1 " javax-annotations = "javax.annotation:javax.annotation-api:1.3.2" -junit = "org.junit.jupiter:junit-jupiter:5.11.3" +junit = "org.junit.jupiter:junit-jupiter:5.11.4" [bundles] bom = ["netty-bom", "armeria-bom", "protobuf-bom"] diff --git a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/DiagonalCollisionCalculator.java b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/DiagonalCollisionCalculator.java index d6932637..f02d16a1 100644 --- a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/DiagonalCollisionCalculator.java +++ b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/DiagonalCollisionCalculator.java @@ -20,7 +20,7 @@ import com.soulfiremc.server.data.BlockState; import com.soulfiremc.server.pathfinding.SFVec3i; import com.soulfiremc.server.pathfinding.graph.actions.movement.BodyPart; -import com.soulfiremc.server.pathfinding.graph.actions.movement.MovementDirection; +import com.soulfiremc.server.pathfinding.graph.actions.movement.DiagonalDirection; import com.soulfiremc.server.pathfinding.graph.actions.movement.MovementSide; import com.soulfiremc.server.protocol.bot.block.GlobalBlockPalette; import com.soulfiremc.server.protocol.bot.state.entity.Player; @@ -31,9 +31,9 @@ public class DiagonalCollisionCalculator { private static final Vector3d START_POSITION = Vector3d.from(0.5, 0, 0.5); private static final Vector3d[] STEPS = new Vector3d[]{Vector3d.from(0.25, 0, 0.25), Vector3d.from(0.5, 0, 0.5), Vector3d.from(0.75, 0, 0.75)}; private static final IDMap COLLISIONS = new IDMap<>(GlobalBlockPalette.INSTANCE.getBlockStates(), blockState -> { - var diagonalsArray = new boolean[MovementDirection.DIAGONALS.length][][]; + var diagonalsArray = new boolean[DiagonalDirection.VALUES.length][][]; - for (var diagonal : MovementDirection.DIAGONALS) { + for (var diagonal : DiagonalDirection.VALUES) { var baseOffset = diagonal.offset(SFVec3i.ZERO); var bodyPartArray = new boolean[BodyPart.VALUES.length][]; @@ -60,7 +60,7 @@ public class DiagonalCollisionCalculator { bodyPartArray[bodyPart.ordinal()] = sideArray; } - diagonalsArray[diagonal.diagonalArrayIndex()] = bodyPartArray; + diagonalsArray[diagonal.ordinal()] = bodyPartArray; } return diagonalsArray; diff --git a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/DownMovement.java b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/DownMovement.java index 283101ea..8d9c4d4e 100644 --- a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/DownMovement.java +++ b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/DownMovement.java @@ -25,7 +25,7 @@ import com.soulfiremc.server.pathfinding.graph.BlockFace; import com.soulfiremc.server.pathfinding.graph.GraphInstructions; import com.soulfiremc.server.pathfinding.graph.MinecraftGraph; -import com.soulfiremc.server.pathfinding.graph.actions.movement.BlockSafetyData; +import com.soulfiremc.server.pathfinding.graph.actions.movement.BlockSafetyType; import com.soulfiremc.server.pathfinding.graph.actions.movement.MovementMiningCost; import com.soulfiremc.server.pathfinding.graph.actions.movement.SkyDirection; import com.soulfiremc.server.util.SFBlockHelpers; @@ -86,7 +86,7 @@ private void registerCheckSafeMineBlocks(SubscriptionConsumer blockSubscribers) for (var skyDirection : SkyDirection.VALUES) { blockSubscribers.subscribe( skyDirection.offset(targetToMineBlock), - new MovementBreakSafetyCheckSubscription(BlockSafetyData.BlockSafetyType.FLUIDS)); + new MovementBreakSafetyCheckSubscription(BlockSafetyType.FLUIDS)); } } @@ -180,7 +180,7 @@ public MinecraftGraph.SubscriptionSingleResult processBlock(MinecraftGraph graph } } - private record MovementBreakSafetyCheckSubscription(BlockSafetyData.BlockSafetyType safetyType) implements DownMovementSubscription { + private record MovementBreakSafetyCheckSubscription(BlockSafetyType safetyType) implements DownMovementSubscription { @Override public MinecraftGraph.SubscriptionSingleResult processBlock(MinecraftGraph graph, SFVec3i key, DownMovement downMovement, LazyBoolean isFree, BlockState blockState, SFVec3i absoluteKey) { diff --git a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/SimpleMovement.java b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/SimpleMovement.java index cde41252..710ed937 100644 --- a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/SimpleMovement.java +++ b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/SimpleMovement.java @@ -124,11 +124,11 @@ private int registerRequiredFreeBlocks(SubscriptionConsumer blockSubscribers) { if (allowBlockActions) { blockSubscribers.subscribe(aboveHead.add(0, 1, 0), - new MovementBreakSafetyCheckSubscription(aboveHeadBlockIndex, BlockSafetyData.BlockSafetyType.FALLING_AND_FLUIDS)); + new MovementBreakSafetyCheckSubscription(aboveHeadBlockIndex, BlockSafetyType.FALLING_AND_FLUIDS)); for (var skyDirection : SkyDirection.VALUES) { blockSubscribers.subscribe(skyDirection.offset(aboveHead), - new MovementBreakSafetyCheckSubscription(aboveHeadBlockIndex, BlockSafetyData.BlockSafetyType.FLUIDS)); + new MovementBreakSafetyCheckSubscription(aboveHeadBlockIndex, BlockSafetyType.FLUIDS)); } } } @@ -139,7 +139,7 @@ private int registerRequiredFreeBlocks(SubscriptionConsumer blockSubscribers) { if (diagonal) { blockBreakSideHint = null; // We don't mine blocks in diagonals } else { - blockBreakSideHint = direction.toBlockFace(); + blockBreakSideHint = direction.toSkyDirection().blockFace(); } var blockIndex = blockIndexCounter++; @@ -154,12 +154,12 @@ private int registerRequiredFreeBlocks(SubscriptionConsumer blockSubscribers) { if (allowBlockActions) { if (bodyOffset == BodyPart.HEAD) { blockSubscribers.subscribe(block.add(0, 1, 0), - new MovementBreakSafetyCheckSubscription(blockIndex, BlockSafetyData.BlockSafetyType.FALLING_AND_FLUIDS)); + new MovementBreakSafetyCheckSubscription(blockIndex, BlockSafetyType.FALLING_AND_FLUIDS)); } for (var skyDirection : SkyDirection.VALUES) { blockSubscribers.subscribe(skyDirection.offset(block), - new MovementBreakSafetyCheckSubscription(blockIndex, BlockSafetyData.BlockSafetyType.FLUIDS)); + new MovementBreakSafetyCheckSubscription(blockIndex, BlockSafetyType.FLUIDS)); } } } @@ -177,7 +177,7 @@ private int registerRequiredFreeBlocks(SubscriptionConsumer blockSubscribers) { if (allowBlockActions) { for (var skyDirection : SkyDirection.VALUES) { blockSubscribers.subscribe(skyDirection.offset(fallFree), - new MovementBreakSafetyCheckSubscription(fallOneBlockIndex, BlockSafetyData.BlockSafetyType.FLUIDS)); + new MovementBreakSafetyCheckSubscription(fallOneBlockIndex, BlockSafetyType.FLUIDS)); } } } @@ -205,14 +205,15 @@ private void registerDiagonalCollisionBlocks(SubscriptionConsumer blockSubscribe return; } + var diagonalDirection = direction.toDiagonalDirection(); for (var side : MovementSide.VALUES) { // If these blocks are solid, the bot moves slower because the bot is running around a corner - var corner = modifier.offsetIfJump(direction.side(side).offset(FEET_POSITION_RELATIVE_BLOCK)); + var corner = modifier.offsetIfJump(diagonalDirection.side(side).offset(FEET_POSITION_RELATIVE_BLOCK)); for (var bodyOffset : BodyPart.VALUES) { // Apply jump shift to target edge and offset for body part blockSubscribers.subscribe(bodyOffset.offset(corner), new MovementDiagonalCollisionSubscription( side, - direction.diagonalArrayIndex(), + diagonalDirection.ordinal(), bodyOffset )); } @@ -236,7 +237,7 @@ private void registerPossibleBlocksToPlaceAgainst(SubscriptionConsumer blockSubs blockSubscribers.subscribe(floorBlock.sub(0, 1, 0), new MovementAgainstPlaceSolidSubscription(BlockFace.TOP)); for (var skyDirection : SkyDirection.VALUES) { - blockSubscribers.subscribe(skyDirection.offset(floorBlock), new MovementAgainstPlaceSolidSubscription(skyDirection.opposite().toBlockFace())); + blockSubscribers.subscribe(skyDirection.offset(floorBlock), new MovementAgainstPlaceSolidSubscription(skyDirection.opposite().blockFace())); } } case JUMP_UP_BLOCK, FALL_1 -> { // 4 - no scaffolding @@ -248,7 +249,7 @@ private void registerPossibleBlocksToPlaceAgainst(SubscriptionConsumer blockSubs continue; } - blockSubscribers.subscribe(skyDirection.offset(floorBlock), new MovementAgainstPlaceSolidSubscription(skyDirection.opposite().toBlockFace())); + blockSubscribers.subscribe(skyDirection.offset(floorBlock), new MovementAgainstPlaceSolidSubscription(skyDirection.opposite().blockFace())); } } default -> throw new IllegalStateException("Unexpected value: " + modifier); @@ -370,7 +371,7 @@ public MinecraftGraph.SubscriptionSingleResult processBlock(MinecraftGraph graph } } - private record MovementBreakSafetyCheckSubscription(int blockArrayIndex, BlockSafetyData.BlockSafetyType safetyType) implements SimpleMovementSubscription { + private record MovementBreakSafetyCheckSubscription(int blockArrayIndex, BlockSafetyType safetyType) implements SimpleMovementSubscription { @Override public MinecraftGraph.SubscriptionSingleResult processBlock(MinecraftGraph graph, SFVec3i key, SimpleMovement simpleMovement, LazyBoolean isFree, BlockState blockState, SFVec3i absoluteKey) { diff --git a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/UpMovement.java b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/UpMovement.java index af4f02d5..1a4c5861 100644 --- a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/UpMovement.java +++ b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/UpMovement.java @@ -27,7 +27,7 @@ import com.soulfiremc.server.pathfinding.graph.BlockFace; import com.soulfiremc.server.pathfinding.graph.GraphInstructions; import com.soulfiremc.server.pathfinding.graph.MinecraftGraph; -import com.soulfiremc.server.pathfinding.graph.actions.movement.BlockSafetyData; +import com.soulfiremc.server.pathfinding.graph.actions.movement.BlockSafetyType; import com.soulfiremc.server.pathfinding.graph.actions.movement.MovementMiningCost; import com.soulfiremc.server.pathfinding.graph.actions.movement.SkyDirection; import com.soulfiremc.server.protocol.bot.BotActionManager; @@ -76,11 +76,11 @@ private int registerRequiredFreeBlocks(SubscriptionConsumer blockSubscribers) { blockSubscribers.subscribe(aboveHead, new MovementFreeSubscription(aboveHeadBlockIndex, BlockFace.BOTTOM)); blockSubscribers.subscribe(aboveHead.add(0, 1, 0), - new MovementBreakSafetyCheckSubscription(aboveHeadBlockIndex, BlockSafetyData.BlockSafetyType.FALLING_AND_FLUIDS)); + new MovementBreakSafetyCheckSubscription(aboveHeadBlockIndex, BlockSafetyType.FALLING_AND_FLUIDS)); for (var skyDirection : SkyDirection.VALUES) { blockSubscribers.subscribe(skyDirection.offset(aboveHead), - new MovementBreakSafetyCheckSubscription(aboveHeadBlockIndex, BlockSafetyData.BlockSafetyType.FLUIDS)); + new MovementBreakSafetyCheckSubscription(aboveHeadBlockIndex, BlockSafetyType.FLUIDS)); } } @@ -208,7 +208,7 @@ public MinecraftGraph.SubscriptionSingleResult processBlock(MinecraftGraph graph } } - private record MovementBreakSafetyCheckSubscription(int blockArrayIndex, BlockSafetyData.BlockSafetyType safetyType) implements UpMovementSubscription { + private record MovementBreakSafetyCheckSubscription(int blockArrayIndex, BlockSafetyType safetyType) implements UpMovementSubscription { @Override public MinecraftGraph.SubscriptionSingleResult processBlock(MinecraftGraph graph, SFVec3i key, UpMovement upMovement, LazyBoolean isFree, BlockState blockState, SFVec3i absoluteKey) { diff --git a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/BlockSafetyData.java b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/BlockSafetyType.java similarity index 59% rename from server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/BlockSafetyData.java rename to server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/BlockSafetyType.java index 3c3f06fc..c180ac73 100644 --- a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/BlockSafetyData.java +++ b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/BlockSafetyType.java @@ -19,23 +19,20 @@ import com.soulfiremc.server.data.BlockState; import com.soulfiremc.server.data.FluidType; -import com.soulfiremc.server.pathfinding.SFVec3i; -public record BlockSafetyData(SFVec3i position, BlockSafetyType type) { - public enum BlockSafetyType { - FALLING_AND_FLUIDS { - @Override - public boolean isUnsafeBlock(BlockState state) { - return state.fluidState().type() != FluidType.EMPTY || state.blockType().fallingBlock(); - } - }, - FLUIDS { - @Override - public boolean isUnsafeBlock(BlockState state) { - return state.fluidState().type() != FluidType.EMPTY; - } - }; +public enum BlockSafetyType { + FALLING_AND_FLUIDS { + @Override + public boolean isUnsafeBlock(BlockState state) { + return state.fluidState().type() != FluidType.EMPTY || state.blockType().fallingBlock(); + } + }, + FLUIDS { + @Override + public boolean isUnsafeBlock(BlockState state) { + return state.fluidState().type() != FluidType.EMPTY; + } + }; - public abstract boolean isUnsafeBlock(BlockState state); - } + public abstract boolean isUnsafeBlock(BlockState state); } diff --git a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/BodyPart.java b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/BodyPart.java index e45057c6..aba5635b 100644 --- a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/BodyPart.java +++ b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/BodyPart.java @@ -22,15 +22,20 @@ @RequiredArgsConstructor public enum BodyPart { - HEAD, - FEET; + HEAD { + @Override + public SFVec3i offset(SFVec3i position) { + return position.add(0, 1, 0); + } + }, + FEET { + @Override + public SFVec3i offset(SFVec3i position) { + return position; + } + }; public static final BodyPart[] VALUES = values(); - public SFVec3i offset(SFVec3i position) { - return switch (this) { - case HEAD -> position.add(0, 1, 0); - case FEET -> position; - }; - } + public abstract SFVec3i offset(SFVec3i position); } diff --git a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/DiagonalDirection.java b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/DiagonalDirection.java new file mode 100644 index 00000000..d8490442 --- /dev/null +++ b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/DiagonalDirection.java @@ -0,0 +1,48 @@ +/* + * SoulFire + * Copyright (C) 2024 AlexProgrammerDE + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.soulfiremc.server.pathfinding.graph.actions.movement; + +import com.soulfiremc.server.pathfinding.SFVec3i; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum DiagonalDirection { + NORTH_EAST(new SFVec3i(1, 0, -1), SkyDirection.NORTH, SkyDirection.EAST), + NORTH_WEST(new SFVec3i(-1, 0, -1), SkyDirection.NORTH, SkyDirection.WEST), + SOUTH_EAST(new SFVec3i(1, 0, 1), SkyDirection.SOUTH, SkyDirection.EAST), + SOUTH_WEST(new SFVec3i(-1, 0, 1), SkyDirection.SOUTH, SkyDirection.WEST); + + public static final DiagonalDirection[] VALUES = values(); + private final SFVec3i offsetVector; + private final SkyDirection leftSide; + private final SkyDirection rightSide; + + public SFVec3i offset(SFVec3i vector) { + return vector.add(offsetVector); + } + + public SkyDirection side(MovementSide side) { + if (side == MovementSide.LEFT) { + return leftSide; + } else { + return rightSide; + } + } +} diff --git a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/MovementDirection.java b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/MovementDirection.java index 89913435..6579db52 100644 --- a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/MovementDirection.java +++ b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/MovementDirection.java @@ -18,55 +18,27 @@ package com.soulfiremc.server.pathfinding.graph.actions.movement; import com.soulfiremc.server.pathfinding.SFVec3i; -import com.soulfiremc.server.pathfinding.graph.BlockFace; import lombok.Getter; import lombok.RequiredArgsConstructor; -import java.util.List; - @Getter @RequiredArgsConstructor public enum MovementDirection { - NORTH, - SOUTH, - EAST, - WEST, - NORTH_EAST, - NORTH_WEST, - SOUTH_EAST, - SOUTH_WEST; + NORTH(new SFVec3i(0, 0, -1)), + SOUTH(new SFVec3i(0, 0, 1)), + EAST(new SFVec3i(1, 0, 0)), + WEST(new SFVec3i(-1, 0, 0)), + NORTH_EAST(new SFVec3i(1, 0, -1)), + NORTH_WEST(new SFVec3i(-1, 0, -1)), + SOUTH_EAST(new SFVec3i(1, 0, 1)), + SOUTH_WEST(new SFVec3i(-1, 0, 1)); public static final MovementDirection[] VALUES = values(); - public static final MovementDirection[] DIAGONALS = {NORTH_EAST, NORTH_WEST, SOUTH_EAST, SOUTH_WEST}; - - private int diagonalArrayIndex; - static { - for (var direction : VALUES) { - direction.diagonalArrayIndex = List.of(DIAGONALS).indexOf(direction); - } - } + private final SFVec3i offsetVector; - public SkyDirection side(MovementSide side) { - return switch (this) { - case NORTH_EAST -> switch (side) { - case LEFT -> SkyDirection.NORTH; - case RIGHT -> SkyDirection.EAST; - }; - case NORTH_WEST -> switch (side) { - case LEFT -> SkyDirection.NORTH; - case RIGHT -> SkyDirection.WEST; - }; - case SOUTH_EAST -> switch (side) { - case LEFT -> SkyDirection.SOUTH; - case RIGHT -> SkyDirection.EAST; - }; - case SOUTH_WEST -> switch (side) { - case LEFT -> SkyDirection.SOUTH; - case RIGHT -> SkyDirection.WEST; - }; - default -> throw new IllegalStateException("Unexpected value: " + this); - }; + public SFVec3i offset(SFVec3i vector) { + return vector.add(offsetVector); } public SkyDirection toSkyDirection() { @@ -79,30 +51,17 @@ public SkyDirection toSkyDirection() { }; } - public BlockFace toBlockFace() { + public DiagonalDirection toDiagonalDirection() { return switch (this) { - case NORTH -> BlockFace.NORTH; - case SOUTH -> BlockFace.SOUTH; - case EAST -> BlockFace.EAST; - case WEST -> BlockFace.WEST; + case NORTH_EAST -> DiagonalDirection.NORTH_EAST; + case NORTH_WEST -> DiagonalDirection.NORTH_WEST; + case SOUTH_EAST -> DiagonalDirection.SOUTH_EAST; + case SOUTH_WEST -> DiagonalDirection.SOUTH_WEST; default -> throw new IllegalStateException("Unexpected value: " + this); }; } - public SFVec3i offset(SFVec3i vector) { - return switch (this) { - case NORTH -> vector.add(0, 0, -1); - case SOUTH -> vector.add(0, 0, 1); - case EAST -> vector.add(1, 0, 0); - case WEST -> vector.add(-1, 0, 0); - case NORTH_EAST -> vector.add(1, 0, -1); - case NORTH_WEST -> vector.add(-1, 0, -1); - case SOUTH_EAST -> vector.add(1, 0, 1); - case SOUTH_WEST -> vector.add(-1, 0, 1); - }; - } - public boolean isDiagonal() { - return diagonalArrayIndex != -1; + return this == NORTH_EAST || this == NORTH_WEST || this == SOUTH_EAST || this == SOUTH_WEST; } } diff --git a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/MovementModifier.java b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/MovementModifier.java index cc218b9c..9812251a 100644 --- a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/MovementModifier.java +++ b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/MovementModifier.java @@ -44,8 +44,4 @@ public SFVec3i offset(SFVec3i vector) { public SFVec3i offsetIfJump(SFVec3i vector) { return this == MovementModifier.JUMP_UP_BLOCK ? vector.add(0, 1, 0) : vector; } - - public Vector3d offsetIfJump(Vector3d vector) { - return this == MovementModifier.JUMP_UP_BLOCK ? vector.add(0, 1, 0) : vector; - } } diff --git a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/ParkourDirection.java b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/ParkourDirection.java index 948abffe..2af16e8a 100644 --- a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/ParkourDirection.java +++ b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/ParkourDirection.java @@ -18,31 +18,21 @@ package com.soulfiremc.server.pathfinding.graph.actions.movement; import com.soulfiremc.server.pathfinding.SFVec3i; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +@Getter +@RequiredArgsConstructor public enum ParkourDirection { - NORTH, - SOUTH, - EAST, - WEST; + NORTH(new SFVec3i(0, 0, -1)), + SOUTH(new SFVec3i(0, 0, 1)), + EAST(new SFVec3i(1, 0, 0)), + WEST(new SFVec3i(-1, 0, 0)); public static final ParkourDirection[] VALUES = values(); + private final SFVec3i offsetVector; - @SuppressWarnings("DuplicatedCode") public SFVec3i offset(SFVec3i vector) { - return switch (this) { - case NORTH -> vector.add(0, 0, -1); - case SOUTH -> vector.add(0, 0, 1); - case EAST -> vector.add(1, 0, 0); - case WEST -> vector.add(-1, 0, 0); - }; - } - - public SkyDirection toSkyDirection() { - return switch (this) { - case NORTH -> SkyDirection.NORTH; - case SOUTH -> SkyDirection.SOUTH; - case EAST -> SkyDirection.EAST; - case WEST -> SkyDirection.WEST; - }; + return vector.add(offsetVector); } } diff --git a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/SkyDirection.java b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/SkyDirection.java index 6e356f6e..fcea7c8c 100644 --- a/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/SkyDirection.java +++ b/server/src/main/java/com/soulfiremc/server/pathfinding/graph/actions/movement/SkyDirection.java @@ -26,22 +26,18 @@ @Getter @RequiredArgsConstructor public enum SkyDirection { - NORTH(Direction.NORTH), - SOUTH(Direction.SOUTH), - EAST(Direction.EAST), - WEST(Direction.WEST); + NORTH(new SFVec3i(0, 0, -1), Direction.NORTH, BlockFace.NORTH), + SOUTH(new SFVec3i(0, 0, 1), Direction.SOUTH, BlockFace.SOUTH), + EAST(new SFVec3i(1, 0, 0), Direction.EAST, BlockFace.EAST), + WEST(new SFVec3i(-1, 0, 0), Direction.WEST, BlockFace.WEST); public static final SkyDirection[] VALUES = values(); + private final SFVec3i offsetVector; private final Direction direction; + private final BlockFace blockFace; - @SuppressWarnings("DuplicatedCode") public SFVec3i offset(SFVec3i vector) { - return switch (this) { - case NORTH -> vector.add(0, 0, -1); - case SOUTH -> vector.add(0, 0, 1); - case EAST -> vector.add(1, 0, 0); - case WEST -> vector.add(-1, 0, 0); - }; + return vector.add(offsetVector); } public SkyDirection opposite() { @@ -52,31 +48,4 @@ public SkyDirection opposite() { case WEST -> EAST; }; } - - public SkyDirection leftSide() { - return switch (this) { - case NORTH -> WEST; - case SOUTH -> EAST; - case EAST -> NORTH; - case WEST -> SOUTH; - }; - } - - public SkyDirection rightSide() { - return switch (this) { - case NORTH -> EAST; - case SOUTH -> WEST; - case EAST -> SOUTH; - case WEST -> NORTH; - }; - } - - public BlockFace toBlockFace() { - return switch (this) { - case NORTH -> BlockFace.NORTH; - case SOUTH -> BlockFace.SOUTH; - case EAST -> BlockFace.EAST; - case WEST -> BlockFace.WEST; - }; - } }