-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement one block gap jumps and prepare for towering and digging st…
…raight down
- Loading branch information
1 parent
d22c563
commit d8a0421
Showing
8 changed files
with
455 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/main/java/net/pistonmaster/serverwrecker/pathfinding/execution/GapJumpAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* ServerWrecker | ||
* | ||
* Copyright (C) 2023 ServerWrecker | ||
* | ||
* 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 | ||
* <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
*/ | ||
package net.pistonmaster.serverwrecker.pathfinding.execution; | ||
|
||
import com.github.steveice10.mc.protocol.data.game.entity.RotationOrigin; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.ToString; | ||
import net.pistonmaster.serverwrecker.protocol.BotConnection; | ||
import net.pistonmaster.serverwrecker.util.BlockTypeHelper; | ||
import org.cloudburstmc.math.vector.Vector3d; | ||
|
||
@ToString | ||
@RequiredArgsConstructor | ||
public class GapJumpAction implements WorldAction { | ||
private final Vector3d position; | ||
private boolean didLook = false; | ||
private int noJumpTicks = 0; | ||
private boolean didJump = false; | ||
|
||
@Override | ||
public boolean isCompleted(BotConnection connection) { | ||
var movementManager = connection.sessionDataManager().getBotMovementManager(); | ||
var botPosition = movementManager.getPlayerPos(); | ||
var levelState = connection.sessionDataManager().getCurrentLevel(); | ||
if (levelState == null) { | ||
return false; | ||
} | ||
|
||
var blockMeta = levelState.getBlockStateAt(position.toInt()); | ||
var insideBlock = blockMeta.isPresent() && !BlockTypeHelper.isEmpty(blockMeta.get()); | ||
|
||
if (insideBlock) { | ||
// We are inside a block, so being close is good enough | ||
var distance = botPosition.distance(position); | ||
return distance <= 1; | ||
} else if (botPosition.getY() != position.getY()) { | ||
// We want to be on the same Y level | ||
return false; | ||
} else { | ||
var distance = botPosition.distance(position); | ||
return distance <= 0.3; | ||
} | ||
} | ||
|
||
@Override | ||
public void tick(BotConnection connection) { | ||
var movementManager = connection.sessionDataManager().getBotMovementManager(); | ||
var botPosition = movementManager.getPlayerPos(); | ||
|
||
var previousYaw = movementManager.getYaw(); | ||
movementManager.lookAt(RotationOrigin.EYES, position); | ||
movementManager.setPitch(0); | ||
var newYaw = movementManager.getYaw(); | ||
|
||
var yawDifference = Math.abs(previousYaw - newYaw); | ||
|
||
// We should only set the yaw once to the server to prevent the bot looking weird due to inaccuracy | ||
if (didLook && yawDifference > 5) { | ||
movementManager.setLastSentYaw(movementManager.getYaw()); | ||
} else { | ||
didLook = true; | ||
} | ||
|
||
// Don't let the bot look up or down (makes it look weird) | ||
movementManager.getControlState().resetAll(); | ||
movementManager.getControlState().setForward(true); | ||
|
||
if (shouldJump()) { | ||
movementManager.getControlState().setJumping(true); | ||
} | ||
} | ||
|
||
private boolean shouldJump() { | ||
if (noJumpTicks < 1) { | ||
noJumpTicks++; | ||
return false; | ||
} else { | ||
noJumpTicks = 0; | ||
return true; | ||
} | ||
} | ||
|
||
@Override | ||
public int getAllowedTicks() { | ||
// 5-seconds max to walk to a block | ||
return 5 * 20; | ||
} | ||
} |
241 changes: 148 additions & 93 deletions
241
src/main/java/net/pistonmaster/serverwrecker/pathfinding/graph/MinecraftGraph.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...va/net/pistonmaster/serverwrecker/pathfinding/graph/actions/parkour/ParkourDirection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* ServerWrecker | ||
* | ||
* Copyright (C) 2023 ServerWrecker | ||
* | ||
* 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 | ||
* <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
*/ | ||
package net.pistonmaster.serverwrecker.pathfinding.graph.actions.parkour; | ||
|
||
import org.cloudburstmc.math.vector.Vector3i; | ||
|
||
public enum ParkourDirection { | ||
NORTH, | ||
SOUTH, | ||
EAST, | ||
WEST; | ||
|
||
public static final ParkourDirection[] VALUES = values(); | ||
|
||
@SuppressWarnings("DuplicatedCode") | ||
public Vector3i offset(Vector3i 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); | ||
}; | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
...ava/net/pistonmaster/serverwrecker/pathfinding/graph/actions/parkour/ParkourMovement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* ServerWrecker | ||
* | ||
* Copyright (C) 2023 ServerWrecker | ||
* | ||
* 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 | ||
* <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
*/ | ||
package net.pistonmaster.serverwrecker.pathfinding.graph.actions.parkour; | ||
|
||
import it.unimi.dsi.fastutil.objects.ObjectArrayList; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import net.pistonmaster.serverwrecker.pathfinding.BotEntityState; | ||
import net.pistonmaster.serverwrecker.pathfinding.Costs; | ||
import net.pistonmaster.serverwrecker.pathfinding.execution.GapJumpAction; | ||
import net.pistonmaster.serverwrecker.pathfinding.graph.actions.GraphAction; | ||
import net.pistonmaster.serverwrecker.pathfinding.graph.actions.GraphInstructions; | ||
import net.pistonmaster.serverwrecker.util.VectorHelper; | ||
import org.cloudburstmc.math.vector.Vector3i; | ||
|
||
import java.util.List; | ||
|
||
public class ParkourMovement implements GraphAction { | ||
private static final Vector3i FEET_POSITION_RELATIVE_BLOCK = Vector3i.ZERO; | ||
private final ParkourDirection direction; | ||
private final Vector3i targetFeetBlock; | ||
@Setter | ||
@Getter | ||
private boolean isImpossible = false; | ||
|
||
public ParkourMovement(ParkourDirection direction) { | ||
this.direction = direction; | ||
this.targetFeetBlock = direction.offset(direction.offset(FEET_POSITION_RELATIVE_BLOCK)); | ||
} | ||
|
||
private ParkourMovement(ParkourMovement other) { | ||
this.direction = other.direction; | ||
this.targetFeetBlock = other.targetFeetBlock; | ||
this.isImpossible = other.isImpossible; | ||
} | ||
|
||
public List<Vector3i> listRequiredFreeBlocks() { | ||
List<Vector3i> requiredFreeBlocks = new ObjectArrayList<>(); | ||
|
||
// Make head block free (maybe head block is a slab) | ||
requiredFreeBlocks.add(FEET_POSITION_RELATIVE_BLOCK.add(0, 1, 0)); | ||
|
||
// Make block above the head block free for jump | ||
requiredFreeBlocks.add(FEET_POSITION_RELATIVE_BLOCK.add(0, 2, 0)); | ||
|
||
var oneFurther = direction.offset(FEET_POSITION_RELATIVE_BLOCK); | ||
|
||
// The gap to jump over | ||
requiredFreeBlocks.add(oneFurther.sub(0, 1, 0)); | ||
|
||
// Room for jumping | ||
requiredFreeBlocks.add(oneFurther); | ||
requiredFreeBlocks.add(oneFurther.add(0, 1, 0)); | ||
requiredFreeBlocks.add(oneFurther.add(0, 2, 0)); | ||
|
||
var twoFurther = direction.offset(oneFurther); | ||
|
||
// Room for jumping | ||
requiredFreeBlocks.add(twoFurther); | ||
requiredFreeBlocks.add(twoFurther.add(0, 1, 0)); | ||
requiredFreeBlocks.add(twoFurther.add(0, 2, 0)); | ||
|
||
return requiredFreeBlocks; | ||
} | ||
|
||
public Vector3i requiredSolidBlock() { | ||
// Floor block | ||
return targetFeetBlock.sub(0, 1, 0); | ||
} | ||
|
||
@Override | ||
public boolean isImpossibleToComplete() { | ||
return isImpossible; | ||
} | ||
|
||
@Override | ||
public GraphInstructions getInstructions(BotEntityState previousEntityState) { | ||
var absoluteTargetFeetBlock = previousEntityState.positionBlock().add(targetFeetBlock); | ||
var targetFeetDoublePosition = VectorHelper.middleOfBlockNormalize(absoluteTargetFeetBlock.toDouble()); | ||
|
||
return new GraphInstructions(new BotEntityState( | ||
targetFeetDoublePosition, | ||
absoluteTargetFeetBlock, | ||
previousEntityState.levelState(), | ||
previousEntityState.inventory() | ||
), Costs.ONE_GAP_JUMP, List.of(new GapJumpAction(targetFeetDoublePosition))); | ||
} | ||
|
||
@Override | ||
public ParkourMovement copy(BotEntityState previousEntityState) { | ||
return new ParkourMovement(this); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...java/net/pistonmaster/serverwrecker/pathfinding/graph/actions/updown/UpDownDirection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* ServerWrecker | ||
* | ||
* Copyright (C) 2023 ServerWrecker | ||
* | ||
* 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 | ||
* <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
*/ | ||
package net.pistonmaster.serverwrecker.pathfinding.graph.actions.updown; | ||
|
||
public enum UpDownDirection { | ||
UP, | ||
DOWN | ||
} |
23 changes: 23 additions & 0 deletions
23
.../java/net/pistonmaster/serverwrecker/pathfinding/graph/actions/updown/UpDownMovement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* ServerWrecker | ||
* | ||
* Copyright (C) 2023 ServerWrecker | ||
* | ||
* 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 | ||
* <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
*/ | ||
package net.pistonmaster.serverwrecker.pathfinding.graph.actions.updown; | ||
|
||
public class UpDownMovement { | ||
} |