Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Dec 18, 2024
2 parents 9e76e29 + cb4292d commit 726e35a
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 171 deletions.
2 changes: 1 addition & 1 deletion data-generator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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" }
Expand All @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<BlockState, boolean[][][]> 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][];
Expand All @@ -60,7 +60,7 @@ public class DiagonalCollisionCalculator {
bodyPartArray[bodyPart.ordinal()] = sideArray;
}

diagonalsArray[diagonal.diagonalArrayIndex()] = bodyPartArray;
diagonalsArray[diagonal.ordinal()] = bodyPartArray;
}

return diagonalsArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand All @@ -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++;
Expand All @@ -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));
}
}
}
Expand All @@ -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));
}
}
}
Expand Down Expand Up @@ -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
));
}
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/
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;
}
}
}
Loading

0 comments on commit 726e35a

Please sign in to comment.