Better define Action scope and functionality
This commit is contained in:
parent
3f1137b5a6
commit
cda55b8ac7
@ -0,0 +1,6 @@
|
|||||||
|
package baritone.bot.behavior.impl;
|
||||||
|
|
||||||
|
import baritone.bot.behavior.Behavior;
|
||||||
|
|
||||||
|
public class MovementBehavior extends Behavior {
|
||||||
|
}
|
@ -1,5 +1,52 @@
|
|||||||
package baritone.bot.pathing.actions;
|
package baritone.bot.pathing.actions;
|
||||||
|
|
||||||
public interface Action {
|
import baritone.bot.behavior.Behavior;
|
||||||
double cost();
|
import baritone.bot.utils.Utils;
|
||||||
|
import net.minecraft.block.state.BlockStateBase;
|
||||||
|
import net.minecraft.block.state.BlockStateContainer;
|
||||||
|
import net.minecraft.block.state.BlockWorldState;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.util.Tuple;
|
||||||
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
public abstract class Action extends Behavior {
|
||||||
|
|
||||||
|
protected ActionState currentState;
|
||||||
|
|
||||||
|
Action(BlockPos dest) {
|
||||||
|
BlockPos playerEyePos = new BlockPos(player.posX, player.posY+1.62, player.posZ);
|
||||||
|
Tuple<Float, Float> desiredRotation = Utils.calcRotationFromCoords(
|
||||||
|
Utils.calcCenterFromCoords(dest, world),
|
||||||
|
playerEyePos);
|
||||||
|
|
||||||
|
// There's honestly not a good reason for this (Builder Pattern), I just believed strongly in it
|
||||||
|
currentState = new ActionState().setDesiredMovement(dest)
|
||||||
|
.setDesiredLook(desiredRotation)
|
||||||
|
.setFinished(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lowest denominator of the dynamic costs.
|
||||||
|
* TODO: Investigate performant ways to assign costs to actions
|
||||||
|
*
|
||||||
|
* @return Cost
|
||||||
|
*/
|
||||||
|
public double cost() { return 0; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTick() {
|
||||||
|
ActionState latestState = calcState();
|
||||||
|
currentState = latestState;
|
||||||
|
player.setPositionAndRotation(player.posX, player.posY, player.posZ,
|
||||||
|
latestState.desiredRotation.getFirst(), latestState.desiredRotation.getSecond());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate latest action state.
|
||||||
|
* Gets called once a tick.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract ActionState calcState();
|
||||||
}
|
}
|
||||||
|
18
src/main/java/baritone/bot/pathing/actions/ActionAscend.java
Normal file
18
src/main/java/baritone/bot/pathing/actions/ActionAscend.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package baritone.bot.pathing.actions;
|
||||||
|
|
||||||
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class ActionAscend extends Action {
|
||||||
|
|
||||||
|
public ActionAscend(BlockPos destination) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionState calcState() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,11 @@
|
|||||||
package baritone.bot.pathing.actions;
|
package baritone.bot.pathing.actions;
|
||||||
|
|
||||||
public interface ActionCosts {
|
public interface ActionCosts {
|
||||||
|
/**
|
||||||
//These costs are measured roughly in ticks btw
|
* These costs are measured roughly in ticks btw
|
||||||
|
* Blocks/Tick: 0.2806167m / tick
|
||||||
|
* Tick/Block: 3.563579787t
|
||||||
|
*/
|
||||||
double WALK_ONE_BLOCK_COST = 20 / 4.317;
|
double WALK_ONE_BLOCK_COST = 20 / 4.317;
|
||||||
double WALK_ONE_IN_WATER_COST = 20 / 2.2;
|
double WALK_ONE_IN_WATER_COST = 20 / 2.2;
|
||||||
double JUMP_ONE_BLOCK_COST = 5.72854;//see below calculation for fall. 1.25 blocks
|
double JUMP_ONE_BLOCK_COST = 5.72854;//see below calculation for fall. 1.25 blocks
|
||||||
@ -10,6 +13,7 @@ public interface ActionCosts {
|
|||||||
double LADDER_DOWN_ONE_COST = 20 / 3;
|
double LADDER_DOWN_ONE_COST = 20 / 3;
|
||||||
double SNEAK_ONE_BLOCK_COST = 20 / 1.3;
|
double SNEAK_ONE_BLOCK_COST = 20 / 1.3;
|
||||||
double SPRINT_ONE_BLOCK_COST = 20 / 5.612;
|
double SPRINT_ONE_BLOCK_COST = 20 / 5.612;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Doesn't include walking forwards, just the falling
|
* Doesn't include walking forwards, just the falling
|
||||||
*
|
*
|
||||||
@ -22,11 +26,13 @@ public interface ActionCosts {
|
|||||||
double FALL_ONE_BLOCK_COST = 5.11354;
|
double FALL_ONE_BLOCK_COST = 5.11354;
|
||||||
double FALL_TWO_BLOCK_COST = 7.28283;
|
double FALL_TWO_BLOCK_COST = 7.28283;
|
||||||
double FALL_THREE_BLOCK_COST = 8.96862;
|
double FALL_THREE_BLOCK_COST = 8.96862;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It doesn't actually take ten ticks to place a block, this cost is so high
|
* It doesn't actually take ten ticks to place a block, this cost is so high
|
||||||
* because we want to generally conserve blocks which might be limited
|
* because we want to generally conserve blocks which might be limited
|
||||||
*/
|
*/
|
||||||
double PLACE_ONE_BLOCK_COST = 20;
|
double PLACE_ONE_BLOCK_COST = 20;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add this to the cost of breaking any block. The cost of breaking any
|
* Add this to the cost of breaking any block. The cost of breaking any
|
||||||
* block is calculated as the number of ticks that block takes to break with
|
* block is calculated as the number of ticks that block takes to break with
|
||||||
|
54
src/main/java/baritone/bot/pathing/actions/ActionState.java
Normal file
54
src/main/java/baritone/bot/pathing/actions/ActionState.java
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package baritone.bot.pathing.actions;
|
||||||
|
|
||||||
|
import net.minecraft.util.Tuple;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
public class ActionState {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is Action finished?
|
||||||
|
*/
|
||||||
|
protected boolean finished;
|
||||||
|
|
||||||
|
public boolean isFinished() {
|
||||||
|
return finished;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionState setFinished(boolean finished) {
|
||||||
|
this.finished = finished;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Necessary movement to achieve
|
||||||
|
*
|
||||||
|
* TODO: Decide desiredMovement type
|
||||||
|
*/
|
||||||
|
protected BlockPos desiredMovement;
|
||||||
|
|
||||||
|
public BlockPos getDesiredMovement() {
|
||||||
|
return desiredMovement;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionState setDesiredMovement(BlockPos desiredMovement) {
|
||||||
|
this.desiredMovement = desiredMovement;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Yaw and pitch angles that must be matched
|
||||||
|
*
|
||||||
|
* getFirst() -> YAW
|
||||||
|
* getSecond() -> PITCH
|
||||||
|
*/
|
||||||
|
protected Tuple<Float, Float> desiredRotation;
|
||||||
|
|
||||||
|
public Tuple<Float, Float> getDesiredRotation() {
|
||||||
|
return desiredRotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionState setDesiredLook(Tuple<Float, Float> desiredRotation) {
|
||||||
|
this.desiredRotation = desiredRotation;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,9 @@ import java.util.List;
|
|||||||
|
|
||||||
public abstract class Movement {
|
public abstract class Movement {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flat list of ordered actions
|
||||||
|
*/
|
||||||
protected List<Action> actions;
|
protected List<Action> actions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,4 +25,11 @@ public abstract class Movement {
|
|||||||
* @return Movement's final block position
|
* @return Movement's final block position
|
||||||
*/
|
*/
|
||||||
public abstract BlockPos getDest();
|
public abstract BlockPos getDest();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate the movement's cost
|
||||||
|
*
|
||||||
|
* @return Cost
|
||||||
|
*/
|
||||||
|
public abstract double calcCost();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package baritone.bot.utils;
|
package baritone.bot.utils;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
|
import net.minecraft.client.multiplayer.WorldClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Brady
|
* @author Brady
|
||||||
@ -9,4 +11,7 @@ import net.minecraft.client.Minecraft;
|
|||||||
public interface Helper {
|
public interface Helper {
|
||||||
|
|
||||||
Minecraft mc = Minecraft.getMinecraft();
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
EntityPlayerSP player = mc.player;
|
||||||
|
WorldClient world = mc.world;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
package baritone.bot.utils;
|
package baritone.bot.utils;
|
||||||
|
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.client.multiplayer.WorldClient;
|
||||||
|
import net.minecraft.util.Tuple;
|
||||||
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -13,4 +20,25 @@ public final class Utils {
|
|||||||
runnable.run();
|
runnable.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Tuple<Float, Float> calcRotationFromCoords(BlockPos orig, BlockPos dest) {
|
||||||
|
double yaw = Math.atan2(orig.getX() - dest.getX(), -orig.getZ() + dest.getZ());
|
||||||
|
double dist = Math.sqrt((orig.getX() - dest.getX()) * (orig.getX() - dest.getX()) + (-orig.getZ() + dest.getZ()) * (-orig.getZ() + dest.getZ()));
|
||||||
|
double pitch = Math.atan2(orig.getY() - dest.getY(), dist);
|
||||||
|
Tuple<Float, Float> rotation = new Tuple<>((float) (yaw * 180 / Math.PI),
|
||||||
|
(float) (pitch * 180 / Math.PI));
|
||||||
|
return rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BlockPos calcCenterFromCoords(BlockPos orig, World world) {
|
||||||
|
IBlockState b = world.getBlockState(orig);
|
||||||
|
AxisAlignedBB bbox = b.getBoundingBox(world, orig);
|
||||||
|
double xDiff = (bbox.minX + bbox.maxX) / 2;
|
||||||
|
double yDiff = (bbox.minY + bbox.maxY) / 2;
|
||||||
|
double zDiff = (bbox.minZ + bbox.maxZ) / 2;
|
||||||
|
BlockPos centerPos = new BlockPos(orig.getX() + xDiff,
|
||||||
|
orig.getY() + yDiff,
|
||||||
|
orig.getZ() + zDiff);
|
||||||
|
return centerPos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user