context objectMouseOver
This commit is contained in:
parent
ce6ec00a89
commit
933b295c40
@ -21,9 +21,14 @@ import baritone.api.cache.IWorldData;
|
|||||||
import net.minecraft.block.BlockSlab;
|
import net.minecraft.block.BlockSlab;
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Brady
|
* @author Brady
|
||||||
* @since 11/12/2018
|
* @since 11/12/2018
|
||||||
@ -38,6 +43,8 @@ public interface IPlayerContext {
|
|||||||
|
|
||||||
IWorldData worldData();
|
IWorldData worldData();
|
||||||
|
|
||||||
|
RayTraceResult objectMouseOver();
|
||||||
|
|
||||||
default BetterBlockPos playerFeet() {
|
default BetterBlockPos playerFeet() {
|
||||||
// TODO find a better way to deal with soul sand!!!!!
|
// TODO find a better way to deal with soul sand!!!!!
|
||||||
BetterBlockPos feet = new BetterBlockPos(player().posX, player().posY + 0.1251, player().posZ);
|
BetterBlockPos feet = new BetterBlockPos(player().posX, player().posY + 0.1251, player().posZ);
|
||||||
@ -58,4 +65,28 @@ public interface IPlayerContext {
|
|||||||
default Rotation playerRotations() {
|
default Rotation playerRotations() {
|
||||||
return new Rotation(player().rotationYaw, player().rotationPitch);
|
return new Rotation(player().rotationYaw, player().rotationPitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the block that the crosshair is currently placed over. Updated once per tick.
|
||||||
|
*
|
||||||
|
* @return The position of the highlighted block
|
||||||
|
*/
|
||||||
|
default Optional<BlockPos> getSelectedBlock() {
|
||||||
|
if (objectMouseOver() != null && objectMouseOver().typeOfHit == RayTraceResult.Type.BLOCK) {
|
||||||
|
return Optional.of(objectMouseOver().getBlockPos());
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the entity that the crosshair is currently placed over. Updated once per tick.
|
||||||
|
*
|
||||||
|
* @return The entity
|
||||||
|
*/
|
||||||
|
default Optional<Entity> getSelectedEntity() {
|
||||||
|
if (objectMouseOver() != null && objectMouseOver().typeOfHit == RayTraceResult.Type.ENTITY) {
|
||||||
|
return Optional.of(objectMouseOver().entityHit);
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,22 +17,16 @@
|
|||||||
|
|
||||||
package baritone.api.utils;
|
package baritone.api.utils;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Brady
|
* @author Brady
|
||||||
* @since 8/25/2018
|
* @since 8/25/2018
|
||||||
*/
|
*/
|
||||||
public final class RayTraceUtils {
|
public final class RayTraceUtils {
|
||||||
|
|
||||||
private static final Minecraft mc = Minecraft.getMinecraft();
|
|
||||||
|
|
||||||
private RayTraceUtils() {}
|
private RayTraceUtils() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,28 +47,4 @@ public final class RayTraceUtils {
|
|||||||
);
|
);
|
||||||
return entity.world.rayTraceBlocks(start, end, false, false, true);
|
return entity.world.rayTraceBlocks(start, end, false, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the block that the crosshair is currently placed over. Updated once per render tick.
|
|
||||||
*
|
|
||||||
* @return The position of the highlighted block
|
|
||||||
*/
|
|
||||||
public static Optional<BlockPos> getSelectedBlock() {
|
|
||||||
if (mc.objectMouseOver != null && mc.objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK) {
|
|
||||||
return Optional.of(mc.objectMouseOver.getBlockPos());
|
|
||||||
}
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the entity that the crosshair is currently placed over. Updated once per render tick.
|
|
||||||
*
|
|
||||||
* @return The entity
|
|
||||||
*/
|
|
||||||
public static Optional<Entity> getSelectedEntity() {
|
|
||||||
if (mc.objectMouseOver != null && mc.objectMouseOver.typeOfHit == RayTraceResult.Type.ENTITY) {
|
|
||||||
return Optional.of(mc.objectMouseOver.entityHit);
|
|
||||||
}
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,11 @@
|
|||||||
|
|
||||||
package baritone.api.utils;
|
package baritone.api.utils;
|
||||||
|
|
||||||
|
import baritone.api.BaritoneAPI;
|
||||||
|
import baritone.api.IBaritone;
|
||||||
import net.minecraft.block.BlockFire;
|
import net.minecraft.block.BlockFire;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.util.math.*;
|
import net.minecraft.util.math.*;
|
||||||
|
|
||||||
@ -135,8 +138,9 @@ public final class RotationUtils {
|
|||||||
* @param pos The target block position
|
* @param pos The target block position
|
||||||
* @return The optional rotation
|
* @return The optional rotation
|
||||||
*/
|
*/
|
||||||
public static Optional<Rotation> reachable(Entity entity, BlockPos pos, double blockReachDistance) {
|
public static Optional<Rotation> reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance) {
|
||||||
if (pos.equals(RayTraceUtils.getSelectedBlock().orElse(null))) {
|
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(entity);
|
||||||
|
if (pos.equals(baritone.getPlayerContext().getSelectedBlock().orElse(null))) {
|
||||||
/*
|
/*
|
||||||
* why add 0.0001?
|
* why add 0.0001?
|
||||||
* to indicate that we actually have a desired pitch
|
* to indicate that we actually have a desired pitch
|
||||||
|
@ -153,7 +153,7 @@ public abstract class Movement implements IMovement, MovementHelper {
|
|||||||
if (reachable.isPresent()) {
|
if (reachable.isPresent()) {
|
||||||
MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(ctx, blockPos));
|
MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(ctx, blockPos));
|
||||||
state.setTarget(new MovementState.MovementTarget(reachable.get(), true));
|
state.setTarget(new MovementState.MovementTarget(reachable.get(), true));
|
||||||
if (Objects.equals(RayTraceUtils.getSelectedBlock().orElse(null), blockPos)) {
|
if (Objects.equals(ctx.getSelectedBlock().orElse(null), blockPos)) {
|
||||||
state.setInput(Input.CLICK_LEFT, true);
|
state.setInput(Input.CLICK_LEFT, true);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -21,7 +21,6 @@ import baritone.Baritone;
|
|||||||
import baritone.api.IBaritone;
|
import baritone.api.IBaritone;
|
||||||
import baritone.api.pathing.movement.MovementStatus;
|
import baritone.api.pathing.movement.MovementStatus;
|
||||||
import baritone.api.utils.BetterBlockPos;
|
import baritone.api.utils.BetterBlockPos;
|
||||||
import baritone.api.utils.RayTraceUtils;
|
|
||||||
import baritone.api.utils.RotationUtils;
|
import baritone.api.utils.RotationUtils;
|
||||||
import baritone.api.utils.input.Input;
|
import baritone.api.utils.input.Input;
|
||||||
import baritone.pathing.movement.CalculationContext;
|
import baritone.pathing.movement.CalculationContext;
|
||||||
@ -31,7 +30,6 @@ import baritone.pathing.movement.MovementState;
|
|||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import net.minecraft.block.BlockFalling;
|
import net.minecraft.block.BlockFalling;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@ -181,9 +179,9 @@ public class MovementAscend extends Movement {
|
|||||||
double faceY = (dest.getY() + anAgainst.getY()) * 0.5D;
|
double faceY = (dest.getY() + anAgainst.getY()) * 0.5D;
|
||||||
double faceZ = (dest.getZ() + anAgainst.getZ() + 1.0D) * 0.5D;
|
double faceZ = (dest.getZ() + anAgainst.getZ() + 1.0D) * 0.5D;
|
||||||
state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations()), true));
|
state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations()), true));
|
||||||
EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit;
|
EnumFacing side = ctx.objectMouseOver().sideHit;
|
||||||
|
|
||||||
RayTraceUtils.getSelectedBlock().ifPresent(selectedBlock -> {
|
ctx.getSelectedBlock().ifPresent(selectedBlock -> {
|
||||||
if (Objects.equals(selectedBlock, anAgainst) && selectedBlock.offset(side).equals(positionToPlace)) {
|
if (Objects.equals(selectedBlock, anAgainst) && selectedBlock.offset(side).equals(positionToPlace)) {
|
||||||
ticksWithoutPlacement++;
|
ticksWithoutPlacement++;
|
||||||
state.setInput(Input.SNEAK, true);
|
state.setInput(Input.SNEAK, true);
|
||||||
|
@ -34,7 +34,6 @@ import baritone.utils.Helper;
|
|||||||
import baritone.utils.pathing.MutableMoveResult;
|
import baritone.utils.pathing.MutableMoveResult;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@ -232,8 +231,8 @@ public class MovementParkour extends Movement {
|
|||||||
if (res != null && res.typeOfHit == RayTraceResult.Type.BLOCK && res.getBlockPos().equals(against1) && res.getBlockPos().offset(res.sideHit).equals(dest.down())) {
|
if (res != null && res.typeOfHit == RayTraceResult.Type.BLOCK && res.getBlockPos().equals(against1) && res.getBlockPos().offset(res.sideHit).equals(dest.down())) {
|
||||||
state.setTarget(new MovementState.MovementTarget(place, true));
|
state.setTarget(new MovementState.MovementTarget(place, true));
|
||||||
}
|
}
|
||||||
RayTraceUtils.getSelectedBlock().ifPresent(selectedBlock -> {
|
ctx.getSelectedBlock().ifPresent(selectedBlock -> {
|
||||||
EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit;
|
EnumFacing side = ctx.objectMouseOver().sideHit;
|
||||||
if (Objects.equals(selectedBlock, against1) && selectedBlock.offset(side).equals(dest.down())) {
|
if (Objects.equals(selectedBlock, against1) && selectedBlock.offset(side).equals(dest.down())) {
|
||||||
state.setInput(Input.CLICK_RIGHT, true);
|
state.setInput(Input.CLICK_RIGHT, true);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,10 @@ package baritone.pathing.movement.movements;
|
|||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.api.IBaritone;
|
import baritone.api.IBaritone;
|
||||||
import baritone.api.pathing.movement.MovementStatus;
|
import baritone.api.pathing.movement.MovementStatus;
|
||||||
import baritone.api.utils.*;
|
import baritone.api.utils.BetterBlockPos;
|
||||||
|
import baritone.api.utils.Rotation;
|
||||||
|
import baritone.api.utils.RotationUtils;
|
||||||
|
import baritone.api.utils.VecUtils;
|
||||||
import baritone.api.utils.input.Input;
|
import baritone.api.utils.input.Input;
|
||||||
import baritone.pathing.movement.CalculationContext;
|
import baritone.pathing.movement.CalculationContext;
|
||||||
import baritone.pathing.movement.Movement;
|
import baritone.pathing.movement.Movement;
|
||||||
@ -29,7 +32,6 @@ import baritone.pathing.movement.MovementState;
|
|||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@ -265,8 +267,8 @@ public class MovementTraverse extends Movement {
|
|||||||
double faceZ = (dest.getZ() + against1.getZ() + 1.0D) * 0.5D;
|
double faceZ = (dest.getZ() + against1.getZ() + 1.0D) * 0.5D;
|
||||||
state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations()), true));
|
state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations()), true));
|
||||||
|
|
||||||
EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit;
|
EnumFacing side = ctx.objectMouseOver().sideHit;
|
||||||
if (Objects.equals(RayTraceUtils.getSelectedBlock().orElse(null), against1) && (ctx.player().isSneaking() || Baritone.settings().assumeSafeWalk.get()) && RayTraceUtils.getSelectedBlock().get().offset(side).equals(positionToPlace)) {
|
if (Objects.equals(ctx.getSelectedBlock().orElse(null), against1) && (ctx.player().isSneaking() || Baritone.settings().assumeSafeWalk.get()) && ctx.getSelectedBlock().get().offset(side).equals(positionToPlace)) {
|
||||||
return state.setInput(Input.CLICK_RIGHT, true);
|
return state.setInput(Input.CLICK_RIGHT, true);
|
||||||
}
|
}
|
||||||
//System.out.println("Trying to look at " + against1 + ", actually looking at" + RayTraceUtils.getSelectedBlock());
|
//System.out.println("Trying to look at " + against1 + ", actually looking at" + RayTraceUtils.getSelectedBlock());
|
||||||
@ -300,7 +302,7 @@ public class MovementTraverse extends Movement {
|
|||||||
state.setTarget(new MovementState.MovementTarget(backToFace, true));
|
state.setTarget(new MovementState.MovementTarget(backToFace, true));
|
||||||
}
|
}
|
||||||
state.setInput(Input.SNEAK, true);
|
state.setInput(Input.SNEAK, true);
|
||||||
if (Objects.equals(RayTraceUtils.getSelectedBlock().orElse(null), goalLook)) {
|
if (Objects.equals(ctx.getSelectedBlock().orElse(null), goalLook)) {
|
||||||
return state.setInput(Input.CLICK_RIGHT, true); // wait to right click until we are able to place
|
return state.setInput(Input.CLICK_RIGHT, true); // wait to right click until we are able to place
|
||||||
}
|
}
|
||||||
// Out.log("Trying to look at " + goalLook + ", actually looking at" + Baritone.whatAreYouLookingAt());
|
// Out.log("Trying to look at " + goalLook + ", actually looking at" + Baritone.whatAreYouLookingAt());
|
||||||
|
@ -23,7 +23,6 @@ import baritone.api.cache.IWaypoint;
|
|||||||
import baritone.api.event.events.ChatEvent;
|
import baritone.api.event.events.ChatEvent;
|
||||||
import baritone.api.pathing.goals.*;
|
import baritone.api.pathing.goals.*;
|
||||||
import baritone.api.pathing.movement.ActionCosts;
|
import baritone.api.pathing.movement.ActionCosts;
|
||||||
import baritone.api.utils.RayTraceUtils;
|
|
||||||
import baritone.api.utils.SettingsUtil;
|
import baritone.api.utils.SettingsUtil;
|
||||||
import baritone.behavior.Behavior;
|
import baritone.behavior.Behavior;
|
||||||
import baritone.behavior.PathingBehavior;
|
import baritone.behavior.PathingBehavior;
|
||||||
@ -270,7 +269,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
String name = msg.substring(6).trim();
|
String name = msg.substring(6).trim();
|
||||||
Optional<Entity> toFollow = Optional.empty();
|
Optional<Entity> toFollow = Optional.empty();
|
||||||
if (name.length() == 0) {
|
if (name.length() == 0) {
|
||||||
toFollow = RayTraceUtils.getSelectedEntity();
|
toFollow = ctx.getSelectedEntity();
|
||||||
} else {
|
} else {
|
||||||
for (EntityPlayer pl : ctx.world().playerEntities) {
|
for (EntityPlayer pl : ctx.world().playerEntities) {
|
||||||
String theirName = pl.getName().trim().toLowerCase();
|
String theirName = pl.getName().trim().toLowerCase();
|
||||||
|
@ -31,7 +31,6 @@ import baritone.behavior.PathingBehavior;
|
|||||||
import baritone.pathing.calc.AbstractNodeCostSearch;
|
import baritone.pathing.calc.AbstractNodeCostSearch;
|
||||||
import baritone.pathing.path.PathExecutor;
|
import baritone.pathing.path.PathExecutor;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
import net.minecraft.client.renderer.BufferBuilder;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
@ -224,9 +223,9 @@ public final class PathRenderer implements Helper {
|
|||||||
IBlockState state = BlockStateInterface.get(BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext(), pos);
|
IBlockState state = BlockStateInterface.get(BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext(), pos);
|
||||||
AxisAlignedBB toDraw;
|
AxisAlignedBB toDraw;
|
||||||
if (state.getBlock().equals(Blocks.AIR)) {
|
if (state.getBlock().equals(Blocks.AIR)) {
|
||||||
toDraw = Blocks.DIRT.getDefaultState().getSelectedBoundingBox(Minecraft.getMinecraft().world, pos);
|
toDraw = Blocks.DIRT.getDefaultState().getSelectedBoundingBox(player.world, pos);
|
||||||
} else {
|
} else {
|
||||||
toDraw = state.getSelectedBoundingBox(Minecraft.getMinecraft().world, pos);
|
toDraw = state.getSelectedBoundingBox(player.world, pos);
|
||||||
}
|
}
|
||||||
toDraw = toDraw.expand(expand, expand, expand).offset(-renderPosX, -renderPosY, -renderPosZ);
|
toDraw = toDraw.expand(expand, expand, expand).offset(-renderPosX, -renderPosY, -renderPosZ);
|
||||||
BUFFER.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION);
|
BUFFER.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION);
|
||||||
|
@ -23,6 +23,7 @@ import baritone.api.utils.IPlayerContext;
|
|||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||||
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,4 +59,9 @@ public final class LocalPlayerContext implements IPlayerContext {
|
|||||||
public IWorldData worldData() {
|
public IWorldData worldData() {
|
||||||
return BaritoneAPI.getProvider().getPrimaryBaritone().getWorldProvider().getCurrentWorld();
|
return BaritoneAPI.getProvider().getPrimaryBaritone().getWorldProvider().getCurrentWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RayTraceResult objectMouseOver() {
|
||||||
|
return mc.objectMouseOver;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user