Merge branch 'master' of github.com:cabaletta/baritone
This commit is contained in:
commit
c0eb94b318
@ -211,6 +211,11 @@ public class Settings {
|
|||||||
*/
|
*/
|
||||||
public Setting<Boolean> fadePath = new Setting<>(false);
|
public Setting<Boolean> fadePath = new Setting<>(false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move without having to force the client-sided rotations
|
||||||
|
*/
|
||||||
|
public Setting<Boolean> freeLook = new Setting<>(true);
|
||||||
|
|
||||||
public final Map<String, Setting<?>> byLowerName;
|
public final Map<String, Setting<?>> byLowerName;
|
||||||
public final List<Setting<?>> allSettings;
|
public final List<Setting<?>> allSettings;
|
||||||
|
|
||||||
@ -219,6 +224,7 @@ public class Settings {
|
|||||||
private String name;
|
private String name;
|
||||||
private final Class<T> klass;
|
private final Class<T> klass;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private Setting(T value) {
|
private Setting(T value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new IllegalArgumentException("Cannot determine value type class from null");
|
throw new IllegalArgumentException("Cannot determine value type class from null");
|
||||||
@ -227,6 +233,7 @@ public class Settings {
|
|||||||
this.klass = (Class<T>) value.getClass();
|
this.klass = (Class<T>) value.getClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public final <K extends T> K get() {
|
public final <K extends T> K get() {
|
||||||
return (K) value;
|
return (K) value;
|
||||||
}
|
}
|
||||||
@ -253,7 +260,7 @@ public class Settings {
|
|||||||
try {
|
try {
|
||||||
for (Field field : temp) {
|
for (Field field : temp) {
|
||||||
if (field.getType().equals(Setting.class)) {
|
if (field.getType().equals(Setting.class)) {
|
||||||
Setting<?> setting = (Setting<? extends Object>) field.get(this);
|
Setting<?> setting = (Setting<?>) field.get(this);
|
||||||
String name = field.getName();
|
String name = field.getName();
|
||||||
setting.name = name;
|
setting.name = name;
|
||||||
name = name.toLowerCase();
|
name = name.toLowerCase();
|
||||||
@ -271,6 +278,7 @@ public class Settings {
|
|||||||
allSettings = Collections.unmodifiableList(tmpAll);
|
allSettings = Collections.unmodifiableList(tmpAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> List<Setting<T>> getByValueType(Class<T> klass) {
|
public <T> List<Setting<T>> getByValueType(Class<T> klass) {
|
||||||
ArrayList<Setting<T>> result = new ArrayList<>();
|
ArrayList<Setting<T>> result = new ArrayList<>();
|
||||||
for (Setting<?> setting : allSettings) {
|
for (Setting<?> setting : allSettings) {
|
||||||
|
@ -17,8 +17,11 @@
|
|||||||
|
|
||||||
package baritone.bot.behavior.impl;
|
package baritone.bot.behavior.impl;
|
||||||
|
|
||||||
|
import baritone.bot.Baritone;
|
||||||
|
import baritone.bot.Settings;
|
||||||
import baritone.bot.behavior.Behavior;
|
import baritone.bot.behavior.Behavior;
|
||||||
import baritone.bot.event.events.PlayerUpdateEvent;
|
import baritone.bot.event.events.PlayerUpdateEvent;
|
||||||
|
import baritone.bot.event.events.RelativeMoveEvent;
|
||||||
import baritone.bot.event.events.type.EventState;
|
import baritone.bot.event.events.type.EventState;
|
||||||
import baritone.bot.utils.Rotation;
|
import baritone.bot.utils.Rotation;
|
||||||
|
|
||||||
@ -36,21 +39,50 @@ public class LookBehavior extends Behavior {
|
|||||||
*/
|
*/
|
||||||
private Rotation target;
|
private Rotation target;
|
||||||
|
|
||||||
public void updateTarget(Rotation target) {
|
/**
|
||||||
|
* Whether or not rotations are currently being forced
|
||||||
|
*/
|
||||||
|
private boolean force;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The last player yaw angle. Used when free looking
|
||||||
|
*
|
||||||
|
* @see Settings#freeLook
|
||||||
|
*/
|
||||||
|
private float lastYaw;
|
||||||
|
|
||||||
|
public void updateTarget(Rotation target, boolean force) {
|
||||||
this.target = target;
|
this.target = target;
|
||||||
|
this.force = force || !Baritone.settings().freeLook.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerUpdate(PlayerUpdateEvent event) {
|
public void onPlayerUpdate(PlayerUpdateEvent event) {
|
||||||
if (event.getState() == EventState.PRE && target != null) {
|
if (event.getState() == EventState.PRE && this.target != null && this.force) {
|
||||||
player().rotationYaw = target.getFirst();
|
player().rotationYaw = this.target.getFirst();
|
||||||
float oldPitch = player().rotationPitch;
|
float oldPitch = player().rotationPitch;
|
||||||
float desiredPitch = target.getSecond();
|
float desiredPitch = this.target.getSecond();
|
||||||
player().rotationPitch = desiredPitch;
|
player().rotationPitch = desiredPitch;
|
||||||
if (desiredPitch == oldPitch) {
|
if (desiredPitch == oldPitch) {
|
||||||
nudgeToLevel();
|
nudgeToLevel();
|
||||||
}
|
}
|
||||||
target = null;
|
this.target = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerRelativeMove(RelativeMoveEvent event) {
|
||||||
|
if (this.target != null && !force) {
|
||||||
|
switch (event.getState()) {
|
||||||
|
case PRE:
|
||||||
|
this.lastYaw = player().rotationYaw;
|
||||||
|
player().rotationYaw = this.target.getFirst();
|
||||||
|
break;
|
||||||
|
case POST:
|
||||||
|
player().rotationYaw = this.lastYaw;
|
||||||
|
this.target = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,17 +156,22 @@ public final class GameEventHandler implements IGameEventListener, Helper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onSendPacket(PacketEvent event) {
|
public final void onSendPacket(PacketEvent event) {
|
||||||
dispatch(behavior -> behavior.onSendPacket(event));
|
dispatch(listener -> listener.onSendPacket(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onReceivePacket(PacketEvent event) {
|
public final void onReceivePacket(PacketEvent event) {
|
||||||
dispatch(behavior -> behavior.onReceivePacket(event));
|
dispatch(listener -> listener.onReceivePacket(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onQueryItemSlotForBlocks(ItemSlotEvent event) {
|
public final void onQueryItemSlotForBlocks(ItemSlotEvent event) {
|
||||||
dispatch(behavior -> behavior.onQueryItemSlotForBlocks(event));
|
dispatch(listener -> listener.onQueryItemSlotForBlocks(event));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerRelativeMove(RelativeMoveEvent event) {
|
||||||
|
dispatch(listener -> listener.onPlayerRelativeMove(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void registerEventListener(IGameEventListener listener) {
|
public final void registerEventListener(IGameEventListener listener) {
|
||||||
|
@ -40,5 +40,4 @@ public final class PlayerUpdateEvent {
|
|||||||
public final EventState getState() {
|
public final EventState getState() {
|
||||||
return this.state;
|
return this.state;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone 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.
|
||||||
|
*
|
||||||
|
* Baritone 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 Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.bot.event.events;
|
||||||
|
|
||||||
|
import baritone.bot.event.events.type.EventState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brady
|
||||||
|
* @since 8/21/2018
|
||||||
|
*/
|
||||||
|
public final class RelativeMoveEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The state of the event
|
||||||
|
*/
|
||||||
|
private final EventState state;
|
||||||
|
|
||||||
|
public RelativeMoveEvent(EventState state) {
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The state of the event
|
||||||
|
*/
|
||||||
|
public final EventState getState() {
|
||||||
|
return this.state;
|
||||||
|
}
|
||||||
|
}
|
@ -77,4 +77,7 @@ public interface AbstractGameEventListener extends IGameEventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void onQueryItemSlotForBlocks(ItemSlotEvent event) {}
|
default void onQueryItemSlotForBlocks(ItemSlotEvent event) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void onPlayerRelativeMove(RelativeMoveEvent event) {}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ import net.minecraft.client.entity.EntityPlayerSP;
|
|||||||
import net.minecraft.client.multiplayer.WorldClient;
|
import net.minecraft.client.multiplayer.WorldClient;
|
||||||
import net.minecraft.client.renderer.EntityRenderer;
|
import net.minecraft.client.renderer.EntityRenderer;
|
||||||
import net.minecraft.client.settings.GameSettings;
|
import net.minecraft.client.settings.GameSettings;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.network.NetworkManager;
|
import net.minecraft.network.NetworkManager;
|
||||||
import net.minecraft.network.Packet;
|
import net.minecraft.network.Packet;
|
||||||
@ -60,7 +61,8 @@ public interface IGameEventListener {
|
|||||||
void onTick(TickEvent event);
|
void onTick(TickEvent event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run once per game tick from before the player rotation is sent to the server.
|
* Run once per game tick from before and after the player rotation is sent to the server.
|
||||||
|
*
|
||||||
* @see EntityPlayerSP#onUpdate()
|
* @see EntityPlayerSP#onUpdate()
|
||||||
*/
|
*/
|
||||||
void onPlayerUpdate(PlayerUpdateEvent event);
|
void onPlayerUpdate(PlayerUpdateEvent event);
|
||||||
@ -123,4 +125,11 @@ public interface IGameEventListener {
|
|||||||
* @see InventoryPlayer#canHarvestBlock(IBlockState)
|
* @see InventoryPlayer#canHarvestBlock(IBlockState)
|
||||||
*/
|
*/
|
||||||
void onQueryItemSlotForBlocks(ItemSlotEvent event);
|
void onQueryItemSlotForBlocks(ItemSlotEvent event);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run once per game tick from before and after the player's moveRelative method is called
|
||||||
|
*
|
||||||
|
* @see Entity#moveRelative(float, float, float, float)
|
||||||
|
*/
|
||||||
|
void onPlayerRelativeMove(RelativeMoveEvent event);
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,13 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||||||
if (BlockStateInterface.isLiquid(playerFeet())) {
|
if (BlockStateInterface.isLiquid(playerFeet())) {
|
||||||
latestState.setInput(Input.JUMP, true);
|
latestState.setInput(Input.JUMP, true);
|
||||||
}
|
}
|
||||||
latestState.getTarget().getRotation().ifPresent(LookBehavior.INSTANCE::updateTarget);
|
|
||||||
|
// If the movement target has to force the new rotations, or we aren't using silent move, then force the rotations
|
||||||
|
latestState.getTarget().getRotation().ifPresent(rotation ->
|
||||||
|
LookBehavior.INSTANCE.updateTarget(
|
||||||
|
rotation,
|
||||||
|
latestState.getTarget().hasToForceRotations()));
|
||||||
|
|
||||||
// TODO: calculate movement inputs from latestState.getGoal().position
|
// TODO: calculate movement inputs from latestState.getGoal().position
|
||||||
// latestState.getTarget().position.ifPresent(null); NULL CONSUMER REALLY SHOULDN'T BE THE FINAL THING YOU SHOULD REALLY REPLACE THIS WITH ALMOST ACTUALLY ANYTHING ELSE JUST PLEASE DON'T LEAVE IT AS IT IS THANK YOU KANYE
|
// latestState.getTarget().position.ifPresent(null); NULL CONSUMER REALLY SHOULDN'T BE THE FINAL THING YOU SHOULD REALLY REPLACE THIS WITH ALMOST ACTUALLY ANYTHING ELSE JUST PLEASE DON'T LEAVE IT AS IT IS THANK YOU KANYE
|
||||||
latestState.getInputStates().forEach((input, forced) -> {
|
latestState.getInputStates().forEach((input, forced) -> {
|
||||||
|
56
src/main/java/baritone/launch/mixins/MixinEntity.java
Normal file
56
src/main/java/baritone/launch/mixins/MixinEntity.java
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone 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.
|
||||||
|
*
|
||||||
|
* Baritone 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 Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.launch.mixins;
|
||||||
|
|
||||||
|
import baritone.bot.Baritone;
|
||||||
|
import baritone.bot.event.events.RelativeMoveEvent;
|
||||||
|
import baritone.bot.event.events.type.EventState;
|
||||||
|
import baritone.bot.utils.Helper;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brady
|
||||||
|
* @since 8/21/2018
|
||||||
|
*/
|
||||||
|
@Mixin(Entity.class)
|
||||||
|
public class MixinEntity {
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "moveRelative",
|
||||||
|
at = @At("HEAD")
|
||||||
|
)
|
||||||
|
private void preMoveRelative(float strafe, float up, float forward, float friction, CallbackInfo ci) {
|
||||||
|
Entity _this = (Entity) (Object) this;
|
||||||
|
if (_this == Helper.mc.player)
|
||||||
|
Baritone.INSTANCE.getGameEventHandler().onPlayerRelativeMove(new RelativeMoveEvent(EventState.PRE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "moveRelative",
|
||||||
|
at = @At("RETURN")
|
||||||
|
)
|
||||||
|
private void postMoveRelative(float strafe, float up, float forward, float friction, CallbackInfo ci) {
|
||||||
|
Entity _this = (Entity) (Object) this;
|
||||||
|
if (_this == Helper.mc.player)
|
||||||
|
Baritone.INSTANCE.getGameEventHandler().onPlayerRelativeMove(new RelativeMoveEvent(EventState.POST));
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@
|
|||||||
"maxShiftBy": 2
|
"maxShiftBy": 2
|
||||||
},
|
},
|
||||||
"client": [
|
"client": [
|
||||||
|
"MixinEntity",
|
||||||
"MixinEntityPlayerSP",
|
"MixinEntityPlayerSP",
|
||||||
"MixinEntityRenderer",
|
"MixinEntityRenderer",
|
||||||
"MixinGameSettings",
|
"MixinGameSettings",
|
||||||
|
Loading…
Reference in New Issue
Block a user