Offline bot testing
This commit is contained in:
@@ -20,6 +20,7 @@ package baritone.bot;
|
|||||||
import baritone.bot.entity.EntityBot;
|
import baritone.bot.entity.EntityBot;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import net.minecraft.network.NetworkManager;
|
import net.minecraft.network.NetworkManager;
|
||||||
|
import net.minecraft.network.play.INetHandlerPlayClient;
|
||||||
import net.minecraft.util.Session;
|
import net.minecraft.util.Session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,18 +31,20 @@ import net.minecraft.util.Session;
|
|||||||
*/
|
*/
|
||||||
class BaritoneUser implements IBaritoneUser {
|
class BaritoneUser implements IBaritoneUser {
|
||||||
|
|
||||||
|
private final UserManager manager;
|
||||||
private final NetworkManager networkManager;
|
private final NetworkManager networkManager;
|
||||||
private final Session session;
|
private final Session session;
|
||||||
|
|
||||||
private GameProfile profile;
|
private GameProfile profile;
|
||||||
|
|
||||||
BaritoneUser(NetworkManager networkManager, Session session) {
|
BaritoneUser(UserManager manager, NetworkManager networkManager, Session session) {
|
||||||
|
this.manager = manager;
|
||||||
this.networkManager = networkManager;
|
this.networkManager = networkManager;
|
||||||
this.session = session;
|
this.session = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoginSuccess(GameProfile profile) {
|
public void onLoginSuccess(GameProfile profile, INetHandlerPlayClient networkHandler) {
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,4 +68,9 @@ class BaritoneUser implements IBaritoneUser {
|
|||||||
public GameProfile getProfile() {
|
public GameProfile getProfile() {
|
||||||
return this.profile;
|
return this.profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserManager getManager() {
|
||||||
|
return this.manager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package baritone.bot;
|
|||||||
import baritone.bot.entity.EntityBot;
|
import baritone.bot.entity.EntityBot;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import net.minecraft.network.NetworkManager;
|
import net.minecraft.network.NetworkManager;
|
||||||
|
import net.minecraft.network.play.INetHandlerPlayClient;
|
||||||
import net.minecraft.util.Session;
|
import net.minecraft.util.Session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,8 +31,11 @@ public interface IBaritoneUser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the user successfully logs into a server.
|
* Called when the user successfully logs into a server.
|
||||||
|
*
|
||||||
|
* @param profile The game profile returned by the server on login
|
||||||
|
* @param networkHandler The client play network handler
|
||||||
*/
|
*/
|
||||||
void onLoginSuccess(GameProfile profile);
|
void onLoginSuccess(GameProfile profile, INetHandlerPlayClient networkHandler);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The network manager that is responsible for the current connection.
|
* @return The network manager that is responsible for the current connection.
|
||||||
@@ -57,4 +61,9 @@ public interface IBaritoneUser {
|
|||||||
* @return This users's profile.
|
* @return This users's profile.
|
||||||
*/
|
*/
|
||||||
GameProfile getProfile();
|
GameProfile getProfile();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The manager that spawned this {@link IBaritoneUser}.
|
||||||
|
*/
|
||||||
|
UserManager getManager();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
package baritone.bot;
|
package baritone.bot;
|
||||||
|
|
||||||
import baritone.bot.connect.ConnectionResult;
|
import baritone.bot.connect.ConnectionResult;
|
||||||
import baritone.bot.connect.ConnectionStatus;
|
|
||||||
import baritone.bot.handler.BotNetHandlerLoginClient;
|
import baritone.bot.handler.BotNetHandlerLoginClient;
|
||||||
import baritone.utils.Helper;
|
import baritone.utils.Helper;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
@@ -43,7 +42,11 @@ import static baritone.bot.connect.ConnectionStatus.*;
|
|||||||
* @author Brady
|
* @author Brady
|
||||||
* @since 11/6/2018
|
* @since 11/6/2018
|
||||||
*/
|
*/
|
||||||
public class UserManager implements Helper {
|
public final class UserManager implements Helper {
|
||||||
|
|
||||||
|
public static final UserManager INSTANCE = new UserManager();
|
||||||
|
|
||||||
|
private UserManager() {}
|
||||||
|
|
||||||
private final List<IBaritoneUser> users = new ArrayList<>();
|
private final List<IBaritoneUser> users = new ArrayList<>();
|
||||||
|
|
||||||
@@ -88,7 +91,7 @@ public class UserManager implements Helper {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Create User
|
// Create User
|
||||||
IBaritoneUser user = new BaritoneUser(networkManager, session);
|
IBaritoneUser user = new BaritoneUser(this, networkManager, session);
|
||||||
this.users.add(user);
|
this.users.add(user);
|
||||||
|
|
||||||
// Setup login handler and send connection packets
|
// Setup login handler and send connection packets
|
||||||
@@ -102,6 +105,10 @@ public class UserManager implements Helper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final void notifyDisconnect(IBaritoneUser user, EnumConnectionState state) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public final Optional<IBaritoneUser> getUserByProfile(GameProfile profile) {
|
public final Optional<IBaritoneUser> getUserByProfile(GameProfile profile) {
|
||||||
return this.users.stream().filter(user -> user.getSession().getProfile().equals(profile)).findFirst();
|
return this.users.stream().filter(user -> user.getSession().getProfile().equals(profile)).findFirst();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ public class BotNetHandlerLoginClient extends NetHandlerLoginClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisconnect(@Nonnull ITextComponent reason) {
|
public void onDisconnect(@Nonnull ITextComponent reason) {
|
||||||
// TODO Notify the bot manager that we are no longer connected
|
|
||||||
// It's important that we don't call the superclass method because that would mess up GUIs and make us upset
|
// It's important that we don't call the superclass method because that would mess up GUIs and make us upset
|
||||||
|
this.user.getManager().notifyDisconnect(this.user, EnumConnectionState.LOGIN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,20 +20,24 @@ package baritone.bot.handler;
|
|||||||
import baritone.bot.IBaritoneUser;
|
import baritone.bot.IBaritoneUser;
|
||||||
import baritone.bot.entity.EntityBot;
|
import baritone.bot.entity.EntityBot;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
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.WorldClient;
|
import net.minecraft.client.multiplayer.WorldClient;
|
||||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.entity.player.PlayerCapabilities;
|
import net.minecraft.entity.player.PlayerCapabilities;
|
||||||
|
import net.minecraft.network.EnumConnectionState;
|
||||||
import net.minecraft.network.NetworkManager;
|
import net.minecraft.network.NetworkManager;
|
||||||
|
import net.minecraft.network.PacketBuffer;
|
||||||
import net.minecraft.network.PacketThreadUtil;
|
import net.minecraft.network.PacketThreadUtil;
|
||||||
import net.minecraft.network.play.INetHandlerPlayClient;
|
import net.minecraft.network.play.INetHandlerPlayClient;
|
||||||
import net.minecraft.network.play.client.CPacketClientStatus;
|
import net.minecraft.network.play.client.*;
|
||||||
import net.minecraft.network.play.client.CPacketResourcePackStatus;
|
|
||||||
import net.minecraft.network.play.server.*;
|
import net.minecraft.network.play.server.*;
|
||||||
|
import net.minecraft.util.EnumHandSide;
|
||||||
import net.minecraft.util.IThreadListener;
|
import net.minecraft.util.IThreadListener;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
|
|
||||||
@@ -88,7 +92,7 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
|||||||
this.user = user;
|
this.user = user;
|
||||||
|
|
||||||
// Notify the user that we're ingame
|
// Notify the user that we're ingame
|
||||||
this.user.onLoginSuccess(profile);
|
this.user.onLoginSuccess(profile, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -236,7 +240,7 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleKeepAlive(@Nonnull SPacketKeepAlive packetIn) {
|
public void handleKeepAlive(@Nonnull SPacketKeepAlive packetIn) {
|
||||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
this.networkManager.sendPacket(new CPacketKeepAlive(packetIn.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -258,7 +262,23 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
|||||||
public void handleJoinGame(@Nonnull SPacketJoinGame packetIn) {
|
public void handleJoinGame(@Nonnull SPacketJoinGame packetIn) {
|
||||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||||
|
|
||||||
// TODO: Set world and player
|
// TODO: Set world and player (See Below)
|
||||||
|
/*
|
||||||
|
- Create player controller
|
||||||
|
- Set game difficulty
|
||||||
|
- Create world
|
||||||
|
- Load world
|
||||||
|
- Create player
|
||||||
|
- Set entity ID
|
||||||
|
- Set player dimension
|
||||||
|
- Set player
|
||||||
|
- Spawn player into world
|
||||||
|
- Set player game mode
|
||||||
|
- Define max players? (Might be useful when determining if Bots are in the same world)
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.networkManager.sendPacket(new CPacketClientSettings("en_us", 8, EntityPlayer.EnumChatVisibility.FULL, true, 0, EnumHandSide.RIGHT));
|
||||||
|
this.networkManager.sendPacket(new CPacketCustomPayload("MC|Brand", new PacketBuffer(Unpooled.buffer()).writeString("vanilla")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -351,7 +371,11 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
|||||||
|
|
||||||
Entity entity = this.world.getEntityByID(packetIn.getEntityID());
|
Entity entity = this.world.getEntityByID(packetIn.getEntityID());
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
entity.setVelocity((double)packetIn.getMotionX() / 8000.0D, (double)packetIn.getMotionY() / 8000.0D, (double)packetIn.getMotionZ() / 8000.0D);
|
entity.setVelocity(
|
||||||
|
(double) packetIn.getMotionX() / 8000.0D,
|
||||||
|
(double) packetIn.getMotionY() / 8000.0D,
|
||||||
|
(double) packetIn.getMotionZ() / 8000.0D
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,6 +523,7 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisconnect(@Nonnull ITextComponent reason) {
|
public void onDisconnect(@Nonnull ITextComponent reason) {
|
||||||
// TODO Unload the world and notify the bot manager that we are no longer connected
|
// TODO: Unload the world
|
||||||
|
this.user.getManager().notifyDisconnect(this.user, EnumConnectionState.PLAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ 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;
|
||||||
|
import baritone.bot.UserManager;
|
||||||
import baritone.cache.ChunkPacker;
|
import baritone.cache.ChunkPacker;
|
||||||
import baritone.cache.Waypoint;
|
import baritone.cache.Waypoint;
|
||||||
import baritone.cache.WorldProvider;
|
import baritone.cache.WorldProvider;
|
||||||
@@ -38,6 +39,7 @@ import net.minecraft.block.Block;
|
|||||||
import net.minecraft.client.multiplayer.ChunkProviderClient;
|
import net.minecraft.client.multiplayer.ChunkProviderClient;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.util.Session;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
@@ -463,6 +465,11 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
if (msg.equals("damn")) {
|
if (msg.equals("damn")) {
|
||||||
logDirect("daniel");
|
logDirect("daniel");
|
||||||
}
|
}
|
||||||
|
// TODO: Temporary command to test bots offline
|
||||||
|
if (msg.equals("bot")) {
|
||||||
|
UserManager.INSTANCE.connect(new Session("Lol" + System.currentTimeMillis() % 1000, UUID.randomUUID().toString(), "", ""));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user