bots
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
package baritone.launch.mixins;
|
||||
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.behavior.IPathingBehavior;
|
||||
import baritone.api.event.events.ChatEvent;
|
||||
import baritone.api.event.events.PlayerUpdateEvent;
|
||||
@@ -44,7 +45,11 @@ public class MixinEntityPlayerSP {
|
||||
)
|
||||
private void sendChatMessage(String msg, CallbackInfo ci) {
|
||||
ChatEvent event = new ChatEvent((EntityPlayerSP) (Object) this, msg);
|
||||
BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onSendChatMessage(event);
|
||||
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
|
||||
System.out.println("Sending chat event to baritone " + ibaritone);
|
||||
ibaritone.getGameEventHandler().onSendChatMessage(event);
|
||||
}
|
||||
//BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onSendChatMessage(event);
|
||||
if (event.isCancelled()) {
|
||||
ci.cancel();
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ import baritone.utils.BaritoneAutoTest;
|
||||
import baritone.utils.ExampleBaritoneControl;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import baritone.utils.PathingControlManager;
|
||||
import baritone.utils.player.PrimaryPlayerContext;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import java.io.File;
|
||||
@@ -74,7 +73,7 @@ public class Baritone implements IBaritone {
|
||||
*/
|
||||
private boolean initialized;
|
||||
|
||||
private GameEventHandler gameEventHandler;
|
||||
private final GameEventHandler gameEventHandler;
|
||||
|
||||
private List<Behavior> behaviors;
|
||||
private PathingBehavior pathingBehavior;
|
||||
@@ -89,11 +88,12 @@ public class Baritone implements IBaritone {
|
||||
|
||||
private PathingControlManager pathingControlManager;
|
||||
|
||||
private IPlayerContext playerContext;
|
||||
private final IPlayerContext playerContext;
|
||||
private WorldProvider worldProvider;
|
||||
|
||||
Baritone() {
|
||||
public Baritone(IPlayerContext playerContext) {
|
||||
this.gameEventHandler = new GameEventHandler(this);
|
||||
this.playerContext = playerContext;
|
||||
}
|
||||
|
||||
public synchronized void init() {
|
||||
@@ -101,9 +101,6 @@ public class Baritone implements IBaritone {
|
||||
return;
|
||||
}
|
||||
|
||||
// Define this before behaviors try and get it, or else it will be null and the builds will fail!
|
||||
this.playerContext = PrimaryPlayerContext.INSTANCE;
|
||||
|
||||
this.behaviors = new ArrayList<>();
|
||||
{
|
||||
// the Behavior constructor calls baritone.registerBehavior(this) so this populates the behaviors arraylist
|
||||
|
||||
@@ -20,9 +20,12 @@ package baritone;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.IBaritoneProvider;
|
||||
import baritone.api.cache.IWorldScanner;
|
||||
import baritone.bot.IBaritoneUser;
|
||||
import baritone.bot.UserManager;
|
||||
import baritone.cache.WorldScanner;
|
||||
import baritone.utils.player.PrimaryPlayerContext;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -31,7 +34,7 @@ import java.util.List;
|
||||
*/
|
||||
public final class BaritoneProvider implements IBaritoneProvider {
|
||||
|
||||
private final Baritone primary = new Baritone();
|
||||
private final Baritone primary = new Baritone(PrimaryPlayerContext.INSTANCE);
|
||||
|
||||
@Override
|
||||
public IBaritone getPrimaryBaritone() {
|
||||
@@ -40,8 +43,12 @@ public final class BaritoneProvider implements IBaritoneProvider {
|
||||
|
||||
@Override
|
||||
public List<IBaritone> getAllBaritones() {
|
||||
// TODO return a CopyOnWriteArrayList
|
||||
return Collections.singletonList(primary);
|
||||
List<IBaritone> baritones = new ArrayList<>();
|
||||
baritones.add(getPrimaryBaritone());
|
||||
for (IBaritoneUser ibu : UserManager.INSTANCE.users()) {
|
||||
baritones.add(ibu.getBaritone());
|
||||
}
|
||||
return baritones;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
package baritone.bot;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.bot.spec.EntityBot;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
@@ -38,10 +40,14 @@ class BaritoneUser implements IBaritoneUser {
|
||||
private GameProfile profile;
|
||||
private INetHandlerPlayClient netHandlerPlayClient;
|
||||
|
||||
private final Baritone baritone;
|
||||
|
||||
BaritoneUser(UserManager manager, NetworkManager networkManager, Session session) {
|
||||
this.manager = manager;
|
||||
this.networkManager = networkManager;
|
||||
this.session = session;
|
||||
this.baritone = new Baritone(new BotPlayerContext(this)); // OPPA GANGNAM STYLE
|
||||
this.baritone.init(); // actually massive iq
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,4 +86,9 @@ class BaritoneUser implements IBaritoneUser {
|
||||
public UserManager getManager() {
|
||||
return this.manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBaritone getBaritone() {
|
||||
return baritone;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.bot;
|
||||
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.cache.IWorldData;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.bot.handler.BotNetHandlerPlayClient;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BotPlayerContext implements IPlayerContext {
|
||||
private final IBaritoneUser bot;
|
||||
|
||||
public BotPlayerContext(IBaritoneUser bot) {
|
||||
this.bot = bot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPlayerSP player() {
|
||||
if (bot.getConnection() == null) {
|
||||
return null;
|
||||
}
|
||||
return ((BotNetHandlerPlayClient) bot.getConnection()).player();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerControllerMP playerController() {
|
||||
return Minecraft.getMinecraft().playerController; // idk LOL
|
||||
}
|
||||
|
||||
@Override
|
||||
public World world() {
|
||||
if (bot.getConnection() == null) {
|
||||
return null;
|
||||
}
|
||||
return ((BotNetHandlerPlayClient) bot.getConnection()).world();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWorldData worldData() {
|
||||
return BaritoneAPI.getProvider().getBaritoneForPlayer(player()).getWorldProvider().getCurrentWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RayTraceResult objectMouseOver() {
|
||||
return Minecraft.getMinecraft().objectMouseOver; // idk LOL
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package baritone.bot;
|
||||
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.bot.spec.EntityBot;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.network.INetHandler;
|
||||
@@ -33,7 +34,7 @@ public interface IBaritoneUser {
|
||||
/**
|
||||
* Called when the user successfully logs into a server.
|
||||
*
|
||||
* @param profile The game profile returned by the server on login
|
||||
* @param profile The game profile returned by the server on login
|
||||
* @param netHandlerPlayClient The client play network handler
|
||||
*/
|
||||
void onLoginSuccess(GameProfile profile, INetHandlerPlayClient netHandlerPlayClient);
|
||||
@@ -76,4 +77,6 @@ public interface IBaritoneUser {
|
||||
* @return The manager that spawned this {@link IBaritoneUser}.
|
||||
*/
|
||||
UserManager getManager();
|
||||
|
||||
IBaritone getBaritone();
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import net.minecraft.util.Session;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
@@ -176,4 +177,8 @@ public final class UserManager implements Helper {
|
||||
public final BotWorldProvider getWorldProvider() {
|
||||
return this.worldProvider;
|
||||
}
|
||||
|
||||
public final List<IBaritoneUser> users() {
|
||||
return Collections.unmodifiableList(this.users);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,9 +425,9 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
PlayerCapabilities c = this.player.capabilities;
|
||||
c.disableDamage = packetIn.isInvulnerable();
|
||||
c.isFlying = packetIn.isFlying();
|
||||
c.allowFlying = packetIn.isAllowFlying();
|
||||
c.disableDamage = packetIn.isInvulnerable();
|
||||
c.isFlying = packetIn.isFlying();
|
||||
c.allowFlying = packetIn.isAllowFlying();
|
||||
c.isCreativeMode = packetIn.isCreativeMode();
|
||||
c.setFlySpeed(packetIn.getFlySpeed());
|
||||
c.setPlayerWalkSpeed(packetIn.getWalkSpeed());
|
||||
@@ -454,7 +454,7 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
||||
|
||||
Entity entity = packetIn.getEntity(this.world);
|
||||
if (entity instanceof EntityLivingBase) {
|
||||
((EntityLivingBase)entity).removeActivePotionEffect(packetIn.getPotion());
|
||||
((EntityLivingBase) entity).removeActivePotionEffect(packetIn.getPotion());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -686,4 +686,12 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
||||
public ClientAdvancementManager getAdvancementManager() {
|
||||
throw new UnsupportedOperationException("This method shouldn't have been called; That is unepic!");
|
||||
}
|
||||
|
||||
public EntityBot player() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public BotWorld world() {
|
||||
return world;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
package baritone.bot.spec;
|
||||
|
||||
import baritone.api.utils.IInputOverrideHandler;
|
||||
import baritone.api.utils.input.Input;
|
||||
import baritone.bot.IBaritoneUser;
|
||||
import net.minecraft.util.MovementInput;
|
||||
|
||||
@@ -37,8 +39,13 @@ public class BotMovementInput extends MovementInput {
|
||||
this.moveForward = 0.0F;
|
||||
|
||||
// These are placeholders until an input overrider is implemented for bots
|
||||
boolean forward, back, left, right, jump, sneak;
|
||||
forward = back = left = right = jump = sneak = false;
|
||||
IInputOverrideHandler i = user.getBaritone().getInputOverrideHandler();
|
||||
boolean forward = i.isInputForcedDown(Input.MOVE_FORWARD);
|
||||
boolean back = i.isInputForcedDown(Input.MOVE_BACK);
|
||||
boolean left = i.isInputForcedDown(Input.MOVE_LEFT);
|
||||
boolean right = i.isInputForcedDown(Input.MOVE_RIGHT);
|
||||
jump = i.isInputForcedDown(Input.JUMP); // oppa
|
||||
boolean sneak = i.isInputForcedDown(Input.SNEAK);
|
||||
|
||||
if (this.forwardKeyDown = forward) {
|
||||
this.moveForward++;
|
||||
@@ -56,8 +63,6 @@ public class BotMovementInput extends MovementInput {
|
||||
this.moveStrafe--;
|
||||
}
|
||||
|
||||
this.jump = true;
|
||||
|
||||
if (this.sneak = sneak) {
|
||||
this.moveStrafe *= 0.3D;
|
||||
this.moveForward *= 0.3D;
|
||||
|
||||
@@ -67,10 +67,6 @@ public final class GameEventHandler implements IEventBus, Helper {
|
||||
|
||||
@Override
|
||||
public final void onSendChatMessage(ChatEvent event) {
|
||||
// TODO temporary bot event call prevention
|
||||
if (event.getPlayer() != baritone.getPlayerContext().player())
|
||||
return;
|
||||
|
||||
// Ensure UserManager is created to prevent a ConcurrentModificationException
|
||||
Objects.requireNonNull(UserManager.INSTANCE);
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import baritone.api.utils.SettingsUtil;
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.behavior.PathingBehavior;
|
||||
import baritone.bot.UserManager;
|
||||
import baritone.bot.connect.ConnectionResult;
|
||||
import baritone.cache.ChunkPacker;
|
||||
import baritone.cache.Waypoint;
|
||||
import baritone.pathing.movement.Movement;
|
||||
@@ -469,7 +470,9 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
}
|
||||
// TODO: Temporary command to test bots offline
|
||||
if (msg.equals("bot")) {
|
||||
UserManager.INSTANCE.connect(new Session("Bot" + System.currentTimeMillis() % 1000, UUID.randomUUID().toString(), "", ""));
|
||||
System.out.println("DOING A BOT");
|
||||
ConnectionResult result = UserManager.INSTANCE.connect(new Session("Bot" + System.currentTimeMillis() % 1000, UUID.randomUUID().toString(), "", ""));
|
||||
System.out.println(result);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -63,7 +63,9 @@ public final class PathRenderer implements Helper {
|
||||
// System.out.println(event.getPartialTicks());
|
||||
float partialTicks = event.getPartialTicks();
|
||||
Goal goal = behavior.getGoal();
|
||||
|
||||
if (behavior.baritone.getPlayerContext().world() == null) {
|
||||
return;
|
||||
}
|
||||
int thisPlayerDimension = behavior.baritone.getPlayerContext().world().provider.getDimensionType().getId();
|
||||
int currentRenderViewDimension = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().world().provider.getDimensionType().getId();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user