Compare commits
99 Commits
v1.5.0
...
bot-system
| Author | SHA1 | Date | |
|---|---|---|---|
| 9a33c5cd9f | |||
| 9f5f275a17 | |||
| ac4895823e | |||
| 62cea04080 | |||
| d772a97a0b | |||
| 7af0ed6ea1 | |||
| fe3f3a66ce | |||
| 9c5f82c814 | |||
| 7c66762f48 | |||
| 830c8190de | |||
| 47b258d7a4 | |||
| df80858c49 | |||
| 5dec544802 | |||
| 494c056613 | |||
| c0e947f016 | |||
| c6ce5ea160 | |||
| 7b2930d5e5 | |||
| 44ca284717 | |||
| 380a645a6c | |||
| 0249bd5dd7 | |||
| 8cd8a95763 | |||
| 029a2b7f3e | |||
| 767d0c8ec1 | |||
| 8febed2e42 | |||
| 37b1604e5d | |||
| 82d15570f3 | |||
| 2c2c420b3a | |||
| 1422b0a149 | |||
| 6b6dd916b4 | |||
| 11e44acf65 | |||
| 16fec4a1a0 | |||
| bbded21afb | |||
| 5ae4f23886 | |||
| f222980a1a | |||
| c57f65f832 | |||
| 85a6ec022e | |||
| c1032da828 | |||
| e0d894d296 | |||
| 27c818f873 | |||
| fdd758bc90 | |||
| 3a2620192b | |||
| c423d5f575 | |||
| 81a9b71429 | |||
| 81ecc209d3 | |||
| 0dc67593bb | |||
| 2e180e81ed | |||
| 0b11057449 | |||
| 186652a8d8 | |||
| 168c151901 | |||
| 18d8cfb6de | |||
| f99befd307 | |||
| 9ad35dbf28 | |||
| dfb49179c5 | |||
| 3c913a7b85 | |||
| f01cf669e8 | |||
| 2d87033f49 | |||
| f014e42aa4 | |||
| 46de72e28c | |||
| 3d5cf9772e | |||
| 7cb38352ac | |||
| 42c78337c7 | |||
| 0f81212f17 | |||
| ad0041c2c5 | |||
| 19e7585cd2 | |||
| 3aeb29ab22 | |||
| 8dfe5dfd32 | |||
| 90236962c4 | |||
| 2e9e8c1ea1 | |||
| 4bf659e14e | |||
| ceca258867 | |||
| abda4b3a31 | |||
| 98664540e2 | |||
| 484dac66b7 | |||
| 40282cd140 | |||
| 41c74cb08c | |||
| 7c92817801 | |||
| 1d56585c67 | |||
| a4ac9c6f8d | |||
| 42d15a7b93 | |||
| 335c97bae6 | |||
| 8a8afddce3 | |||
| c3f6ee87b3 | |||
| f45fb3cd8c | |||
| 71c7ed54e5 | |||
| 4f978be2a2 | |||
| 133d956b3a | |||
| 095e452632 | |||
| 047d7f06b8 | |||
| 09a119c4ca | |||
| 746e1f6652 | |||
| 1d22cf63f0 | |||
| d4b3e71694 | |||
| a08b406af9 | |||
| 1afd367e53 | |||
| 59e920b7b1 | |||
| 79d230d924 | |||
| 29cf79fe17 | |||
| 8e75817e29 | |||
| c6bd3f4f00 |
+36
@@ -0,0 +1,36 @@
|
||||
# Baritone Comms Protocol
|
||||
|
||||
## Data Types
|
||||
|
||||
| Name | Descriptor | Java |
|
||||
|------------|-----------------------------------------------------------|-----------------------------|
|
||||
| coordinate | Big endian 8-byte floating point number | [readDouble], [writeDouble] |
|
||||
| string | unsigned short (length) followed by UTF-8 character bytes | [readUTF], [writeUTF] |
|
||||
|
||||
## Inbound
|
||||
|
||||
Allows the server to execute a chat command on behalf of the client's player
|
||||
|
||||
### Chat
|
||||
|
||||
| Name | Type |
|
||||
|---------|--------|
|
||||
| Message | string |
|
||||
|
||||
## Outbound
|
||||
|
||||
Update the player position with the server
|
||||
|
||||
### Status
|
||||
|
||||
| Name | Type |
|
||||
|------|------------|
|
||||
| X | coordinate |
|
||||
| Y | coordinate |
|
||||
| Z | coordinate |
|
||||
|
||||
<!-- External links -->
|
||||
[readUTF]: https://docs.oracle.com/javase/7/docs/api/java/io/DataInputStream.html#readUTF()
|
||||
[writeUTF]: https://docs.oracle.com/javase/7/docs/api/java/io/DataOutputStream.html#writeUTF(java.lang.String)
|
||||
[readDouble]: https://docs.oracle.com/javase/7/docs/api/java/io/DataInputStream.html#readDouble()
|
||||
[writeDouble]: https://docs.oracle.com/javase/7/docs/api/java/io/DataOutputStream.html#writeDouble(double)
|
||||
@@ -34,6 +34,7 @@ import java.lang.reflect.Field;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -113,6 +114,7 @@ public class ProguardTask extends BaritoneGradleTask {
|
||||
Process p = new ProcessBuilder("java", "-verbose").start();
|
||||
String out = IOUtils.toString(p.getInputStream(), "UTF-8").split("\n")[0].split("Opened ")[1].replace("]", "");
|
||||
template.add(2, "-libraryjars '" + out + "'");
|
||||
template.add(3, "-libraryjars '" + Paths.get(out).resolveSibling("jce.jar") + "'");
|
||||
|
||||
// API config doesn't require any changes from the changes that we made to the template
|
||||
Files.write(getTemporaryFile(PROGUARD_API_CONFIG), template);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package baritone.api;
|
||||
|
||||
import baritone.api.bot.IUserManager;
|
||||
import baritone.api.cache.IWorldScanner;
|
||||
import baritone.api.command.ICommand;
|
||||
import baritone.api.command.ICommandSystem;
|
||||
@@ -69,13 +70,18 @@ public interface IBaritoneProvider {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link IWorldScanner} instance. This is not a type returned by
|
||||
* {@link IBaritone} implementation, because it is not linked with {@link IBaritone}.
|
||||
* Returns the {@link IWorldScanner} instance. This is not a type returned by a
|
||||
* {@link IBaritone} implementation because it is not linked with {@link IBaritone}.
|
||||
*
|
||||
* @return The {@link IWorldScanner} instance.
|
||||
*/
|
||||
IWorldScanner getWorldScanner();
|
||||
|
||||
/**
|
||||
* @return The {@link IUserManager} instance.
|
||||
*/
|
||||
IUserManager getUserManager();
|
||||
|
||||
/**
|
||||
* Returns the {@link ICommandSystem} instance. This is not bound to a specific {@link IBaritone}
|
||||
* instance because {@link ICommandSystem} itself controls global behavior for {@link ICommand}s.
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.api.bot;
|
||||
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.network.INetHandler;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.INetHandlerPlayClient;
|
||||
import net.minecraft.util.Session;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 10/23/2018
|
||||
*/
|
||||
public interface IBaritoneUser {
|
||||
|
||||
/**
|
||||
* @return The network manager that is responsible for the current connection.
|
||||
*/
|
||||
NetworkManager getNetworkManager();
|
||||
|
||||
/**
|
||||
* Returns the current play network handler. Can also be acquired via
|
||||
* {@link NetworkManager#getNetHandler()} from {@link #getNetworkManager()},
|
||||
* and checking if the {@link INetHandler} is an instance of {@link INetHandlerPlayClient}.
|
||||
*
|
||||
* @return The current play network handler
|
||||
*/
|
||||
INetHandlerPlayClient getConnection();
|
||||
|
||||
/**
|
||||
* @return The locally managed entity for this user.
|
||||
*/
|
||||
EntityPlayerSP getEntity();
|
||||
|
||||
/**
|
||||
* @return The bot player controller
|
||||
*/
|
||||
IPlayerController getPlayerController();
|
||||
|
||||
/**
|
||||
* Returns the user login session. Should never be {@code null}, as this should be set when the
|
||||
* user is constructed.
|
||||
*
|
||||
* @return This users's login session
|
||||
*/
|
||||
Session getSession();
|
||||
|
||||
/**
|
||||
* Returns the game profile for the account represented by this user.
|
||||
*
|
||||
* @return This users's profile.
|
||||
*/
|
||||
GameProfile getProfile();
|
||||
|
||||
/**
|
||||
* @return The manager that spawned this {@link IBaritoneUser}.
|
||||
*/
|
||||
IUserManager getManager();
|
||||
|
||||
IBaritone getBaritone();
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.api.bot;
|
||||
|
||||
import baritone.api.bot.connect.IConnectionResult;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.util.Session;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 1/17/2019
|
||||
*/
|
||||
public interface IUserManager {
|
||||
|
||||
/**
|
||||
* Connects a new user with the specified {@link Session} to the current server.
|
||||
*
|
||||
* @param session The user session
|
||||
* @return The result of the attempted connection
|
||||
*/
|
||||
IConnectionResult connect(Session session);
|
||||
|
||||
/**
|
||||
* Disconnects the specified {@link IBaritoneUser} from its current server.
|
||||
*
|
||||
* @param user The user to disconnect
|
||||
*/
|
||||
void disconnect(IBaritoneUser user);
|
||||
|
||||
/**
|
||||
* Finds the {@link IBaritoneUser} associated with the specified {@link GameProfile}
|
||||
*
|
||||
* @param profile The game profile of the user
|
||||
* @return The user, {@link Optional#empty()} if no match or {@code profile} is {@code null}
|
||||
*/
|
||||
default Optional<IBaritoneUser> getUserByProfile(GameProfile profile) {
|
||||
return profile == null ? Optional.empty() : users().stream().filter(user -> user.getProfile().equals(profile)).findFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the {@link IBaritoneUser} associated with the specified {@link UUID}
|
||||
*
|
||||
* @param uuid The uuid of the user
|
||||
* @return The user, {@link Optional#empty()} if no match or {@code uuid} is {@code null}
|
||||
*/
|
||||
default Optional<IBaritoneUser> getUserByUUID(UUID uuid) {
|
||||
return uuid == null ? Optional.empty() : users().stream().filter(user -> user.getProfile().getId().equals(uuid)).findFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return All of the users held by this manager
|
||||
*/
|
||||
List<IBaritoneUser> users();
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.api.bot.connect;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 11/6/2018
|
||||
*/
|
||||
public enum ConnectionStatus {
|
||||
|
||||
/**
|
||||
* The local player is not connected to a server, therefore, there is no target server to connect to.
|
||||
*/
|
||||
NO_CURRENT_CONNECTION,
|
||||
|
||||
/**
|
||||
* The IP of the targetted address to connect to could not be resolved.
|
||||
*/
|
||||
CANT_RESOLVE_HOST,
|
||||
|
||||
/**
|
||||
* The connection initialization failed.
|
||||
*/
|
||||
CONNECTION_FAILED,
|
||||
|
||||
/**
|
||||
* The connection was a success
|
||||
*/
|
||||
SUCCESS
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.api.bot.connect;
|
||||
|
||||
import baritone.api.bot.IBaritoneUser;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 1/17/2019
|
||||
*/
|
||||
public interface IConnectionResult {
|
||||
|
||||
/**
|
||||
* @return The actual status of the connection attempt.
|
||||
* @see ConnectionStatus
|
||||
*/
|
||||
ConnectionStatus getStatus();
|
||||
|
||||
/**
|
||||
* Returns the user that was created in this connection this result reflects, if
|
||||
* {@link #getStatus()} is {@link ConnectionStatus#SUCCESS}, otherwise it will
|
||||
* return {@link Optional#empty()}.
|
||||
*
|
||||
* @return The user created in the connection
|
||||
*/
|
||||
Optional<IBaritoneUser> getUser();
|
||||
}
|
||||
@@ -105,7 +105,7 @@ public interface IPath {
|
||||
* Returns the estimated number of ticks to complete the path from the given node index.
|
||||
*
|
||||
* @param pathPosition The index of the node we're calculating from
|
||||
* @return The estimated number of ticks remaining frm the given position
|
||||
* @return The estimated number of ticks remaining from the given position
|
||||
*/
|
||||
default double ticksRemainingFrom(int pathPosition) {
|
||||
double sum = 0;
|
||||
@@ -117,6 +117,15 @@ public interface IPath {
|
||||
return sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the estimated amount of time needed to complete this path from start to finish
|
||||
*
|
||||
* @return The estimated amount of time, in ticks
|
||||
*/
|
||||
default double totalTicks() {
|
||||
return ticksRemainingFrom(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cuts off this path at the loaded chunk border, and returns the resulting path. Default
|
||||
* implementation just returns this path, without the intended functionality.
|
||||
|
||||
@@ -46,6 +46,8 @@ public interface IPlayerController {
|
||||
|
||||
ItemStack windowClick(int windowId, int slotId, int mouseButton, ClickType type, EntityPlayer player);
|
||||
|
||||
void setGameType(GameType type);
|
||||
|
||||
GameType getGameType();
|
||||
|
||||
EnumActionResult processRightClickBlock(EntityPlayerSP player, World world, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand);
|
||||
|
||||
@@ -25,12 +25,11 @@ import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.behavior.*;
|
||||
import baritone.cache.WorldProvider;
|
||||
import baritone.command.manager.CommandManager;
|
||||
import baritone.event.GameEventHandler;
|
||||
import baritone.process.*;
|
||||
import baritone.selection.SelectionManager;
|
||||
import baritone.utils.*;
|
||||
import baritone.command.manager.CommandManager;
|
||||
import baritone.utils.player.PrimaryPlayerContext;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import java.io.File;
|
||||
@@ -87,11 +86,11 @@ public class Baritone implements IBaritone {
|
||||
|
||||
public BlockStateInterface bsi;
|
||||
|
||||
Baritone() {
|
||||
public Baritone(IPlayerContext playerContext) {
|
||||
this.gameEventHandler = new GameEventHandler(this);
|
||||
|
||||
// Define this before behaviors try and get it, or else it will be null and the builds will fail!
|
||||
this.playerContext = PrimaryPlayerContext.INSTANCE;
|
||||
this.playerContext = playerContext;
|
||||
|
||||
{
|
||||
// the Behavior constructor calls baritone.registerBehavior(this) so this populates the behaviors arraylist
|
||||
@@ -234,4 +233,4 @@ public class Baritone implements IBaritone {
|
||||
public static Executor getExecutor() {
|
||||
return threadPool;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,15 +19,19 @@ package baritone;
|
||||
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.IBaritoneProvider;
|
||||
import baritone.api.bot.IBaritoneUser;
|
||||
import baritone.api.bot.IUserManager;
|
||||
import baritone.api.cache.IWorldScanner;
|
||||
import baritone.api.command.ICommandSystem;
|
||||
import baritone.bot.UserManager;
|
||||
import baritone.api.schematic.ISchematicSystem;
|
||||
import baritone.command.BaritoneChatControl;
|
||||
import baritone.cache.WorldScanner;
|
||||
import baritone.command.CommandSystem;
|
||||
import baritone.utils.player.PrimaryPlayerContext;
|
||||
import baritone.utils.schematic.SchematicSystem;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -37,11 +41,9 @@ import java.util.List;
|
||||
public final class BaritoneProvider implements IBaritoneProvider {
|
||||
|
||||
private final Baritone primary;
|
||||
private final List<IBaritone> all;
|
||||
|
||||
{
|
||||
this.primary = new Baritone();
|
||||
this.all = Collections.singletonList(this.primary);
|
||||
this.primary = new Baritone(PrimaryPlayerContext.INSTANCE);
|
||||
|
||||
// Setup chat control, just for the primary instance
|
||||
new BaritoneChatControl(this.primary);
|
||||
@@ -54,7 +56,12 @@ public final class BaritoneProvider implements IBaritoneProvider {
|
||||
|
||||
@Override
|
||||
public List<IBaritone> getAllBaritones() {
|
||||
return all;
|
||||
List<IBaritone> baritones = new ArrayList<>();
|
||||
baritones.add(getPrimaryBaritone());
|
||||
for (IBaritoneUser ibu : UserManager.INSTANCE.users()) {
|
||||
baritones.add(ibu.getBaritone());
|
||||
}
|
||||
return baritones;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,6 +69,11 @@ public final class BaritoneProvider implements IBaritoneProvider {
|
||||
return WorldScanner.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IUserManager getUserManager() {
|
||||
return UserManager.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICommandSystem getCommandSystem() {
|
||||
return CommandSystem.INSTANCE;
|
||||
|
||||
@@ -32,6 +32,7 @@ import net.minecraft.block.BlockBed;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.client.CPacketClickWindow;
|
||||
import net.minecraft.network.play.client.CPacketCloseWindow;
|
||||
import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock;
|
||||
import net.minecraft.network.play.server.SPacketCloseWindow;
|
||||
@@ -117,6 +118,11 @@ public final class MemoryBehavior extends Behavior {
|
||||
if (p instanceof CPacketCloseWindow) {
|
||||
getCurrent().save();
|
||||
}
|
||||
|
||||
if (p instanceof CPacketClickWindow) {
|
||||
CPacketClickWindow c = event.cast();
|
||||
System.out.println("CLICK " + c.getWindowId() + " " + c.getSlotId() + " " + c.getUsedButton() + " " + c.getClickType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,9 +160,21 @@ public final class MemoryBehavior extends Behavior {
|
||||
if (p instanceof SPacketCloseWindow) {
|
||||
getCurrent().save();
|
||||
}
|
||||
|
||||
// apparently doesn't happen
|
||||
/*if (p instanceof SPacketWindowItems) {
|
||||
SPacketWindowItems meme = (SPacketWindowItems) p;
|
||||
if (meme.getWindowId() == ctx.player().openContainer.windowId && enderChestWindowId != null && meme.getWindowId() == enderChestWindowId) {
|
||||
System.out.println("RECEIVED GUARANTEED ECHEST CONTENTS" + meme.getItemStacks());
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
public boolean eChestOpen() {
|
||||
return enderChestWindowId != null && ctx.player().openContainer.windowId == enderChestWindowId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockInteract(BlockInteractEvent event) {
|
||||
if (event.getType() == BlockInteractEvent.Type.USE && BlockStateInterface.getBlock(ctx, event.getPos()) instanceof BlockBed) {
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.Baritone;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.bot.IBaritoneUser;
|
||||
import baritone.api.bot.IUserManager;
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import baritone.bot.spec.BotWorld;
|
||||
import baritone.bot.spec.EntityBot;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.INetHandlerPlayClient;
|
||||
import net.minecraft.util.Session;
|
||||
|
||||
/**
|
||||
* Implementation of {@link IBaritoneUser}
|
||||
*
|
||||
* @author Brady
|
||||
* @since 11/6/2018
|
||||
*/
|
||||
public class BaritoneUser implements IBaritoneUser {
|
||||
|
||||
private final UserManager manager;
|
||||
private final NetworkManager networkManager;
|
||||
private final Session session;
|
||||
|
||||
private GameProfile profile;
|
||||
private INetHandlerPlayClient netHandlerPlayClient;
|
||||
|
||||
private BotWorld world;
|
||||
private EntityBot player;
|
||||
private IPlayerController playerController;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
public void onLoginSuccess(GameProfile profile, INetHandlerPlayClient netHandlerPlayClient) {
|
||||
this.profile = profile;
|
||||
this.netHandlerPlayClient = netHandlerPlayClient;
|
||||
}
|
||||
|
||||
public void onWorldLoad(BotWorld world, EntityBot player, IPlayerController playerController) {
|
||||
this.world = world;
|
||||
this.player = player;
|
||||
this.playerController = playerController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkManager getNetworkManager() {
|
||||
return this.networkManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INetHandlerPlayClient getConnection() {
|
||||
return this.netHandlerPlayClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityBot getEntity() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPlayerController getPlayerController() {
|
||||
return this.playerController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Session getSession() {
|
||||
return this.session;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile getProfile() {
|
||||
return this.profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserManager getManager() {
|
||||
return this.manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBaritone getBaritone() {
|
||||
return baritone;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.bot.IBaritoneUser;
|
||||
import baritone.api.cache.IWorldData;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BotPlayerContext implements IPlayerContext {
|
||||
|
||||
/**
|
||||
* The backing {@link IBaritoneUser}
|
||||
*/
|
||||
private final IBaritoneUser bot;
|
||||
|
||||
public BotPlayerContext(IBaritoneUser bot) {
|
||||
this.bot = bot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPlayerSP player() {
|
||||
if (bot.getEntity() == null) {
|
||||
return null;
|
||||
}
|
||||
return bot.getEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPlayerController playerController() {
|
||||
if (bot.getEntity() == null) {
|
||||
return null;
|
||||
}
|
||||
return bot.getPlayerController();
|
||||
}
|
||||
|
||||
@Override
|
||||
public World world() {
|
||||
if (bot.getEntity() == null) {
|
||||
return null;
|
||||
}
|
||||
return bot.getEntity().world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWorldData worldData() {
|
||||
return bot.getBaritone().getWorldProvider().getCurrentWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RayTraceResult objectMouseOver() {
|
||||
Entity entity = this.bot.getEntity();
|
||||
|
||||
if (entity != null) {
|
||||
double blockReachDistance = this.bot.getPlayerController().getBlockReachDistance();
|
||||
return entity.rayTrace(blockReachDistance, 1.0F);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.bot.spec.BotWorld;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import net.minecraft.world.GameType;
|
||||
import net.minecraft.world.WorldSettings;
|
||||
import net.minecraft.world.WorldType;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 11/7/2018
|
||||
*/
|
||||
public class BotWorldProvider {
|
||||
|
||||
/**
|
||||
* Generic world settings for a typical survival world.
|
||||
*/
|
||||
private static final WorldSettings GENERIC_WORLD_SETTINGS = new WorldSettings(0L, GameType.SURVIVAL, true, false, WorldType.DEFAULT);
|
||||
|
||||
/**
|
||||
* All of the dimensions mapped to their respective worlds.
|
||||
*/
|
||||
private final Int2ObjectMap<BotWorld> worlds = new Int2ObjectArrayMap<>();
|
||||
|
||||
/**
|
||||
* Gets or creates the {@link BotWorld} for the specified dimension
|
||||
*
|
||||
* @param dimension The dimension id
|
||||
* @return The world
|
||||
*/
|
||||
public BotWorld getWorld(int dimension) {
|
||||
return worlds.computeIfAbsent(dimension, this::createWorldForDim);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link BotWorld} for the given dimension id.
|
||||
*
|
||||
* @param dimension The dimension id
|
||||
* @return The new world
|
||||
*/
|
||||
private BotWorld createWorldForDim(int dimension) {
|
||||
return new BotWorld(GENERIC_WORLD_SETTINGS, dimension);
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
this.worlds.forEach((dim, world) -> world.updateEntities());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* 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.bot.IBaritoneUser;
|
||||
import baritone.api.bot.IUserManager;
|
||||
import baritone.api.bot.connect.IConnectionResult;
|
||||
import baritone.api.event.events.TickEvent;
|
||||
import baritone.api.event.events.type.EventState;
|
||||
import baritone.api.event.listener.AbstractGameEventListener;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.bot.connect.ConnectionResult;
|
||||
import baritone.bot.handler.BotNetHandlerLoginClient;
|
||||
import net.minecraft.client.multiplayer.ServerAddress;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.network.EnumConnectionState;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.handshake.client.C00Handshake;
|
||||
import net.minecraft.network.login.client.CPacketLoginStart;
|
||||
import net.minecraft.util.Session;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import static baritone.api.bot.connect.ConnectionStatus.*;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 11/6/2018
|
||||
*/
|
||||
public final class UserManager implements IUserManager, Helper {
|
||||
|
||||
public static final UserManager INSTANCE = new UserManager();
|
||||
|
||||
private final List<IBaritoneUser> users = new CopyOnWriteArrayList<>();
|
||||
|
||||
private final BotWorldProvider worldProvider;
|
||||
|
||||
private UserManager() {
|
||||
// Setup an event listener that automatically disconnects bots when we're not in-game
|
||||
BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().registerEventListener(new AbstractGameEventListener() {
|
||||
|
||||
@Override
|
||||
public final void onTick(TickEvent event) {
|
||||
if (event.getState() == EventState.PRE) {
|
||||
if (event.getType() == TickEvent.Type.OUT)
|
||||
UserManager.this.users.forEach(UserManager.this::disconnect);
|
||||
|
||||
UserManager.this.worldProvider.tick();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.worldProvider = new BotWorldProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects a new user with the specified {@link Session} to the current server.
|
||||
*
|
||||
* @param session The user session
|
||||
* @return The result of the attempted connection
|
||||
*/
|
||||
@Override
|
||||
public final IConnectionResult connect(Session session) {
|
||||
ServerData data = mc.getCurrentServerData();
|
||||
if (data == null) {
|
||||
return ConnectionResult.failed(NO_CURRENT_CONNECTION);
|
||||
}
|
||||
|
||||
// Connect to the server from the parsed server data
|
||||
return connect0(session, ServerAddress.fromString(data.serverIP));
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects a new user with the specified {@link Session} to the specified server.
|
||||
* <p>
|
||||
* Hi Mickey :)
|
||||
*
|
||||
* @param session The user session
|
||||
* @param address The address of the server to connect to
|
||||
* @return The result of the attempted connection
|
||||
*/
|
||||
private IConnectionResult connect0(Session session, ServerAddress address) {
|
||||
InetAddress inetAddress;
|
||||
|
||||
try {
|
||||
inetAddress = InetAddress.getByName(address.getIP());
|
||||
} catch (UnknownHostException e) {
|
||||
return ConnectionResult.failed(CANT_RESOLVE_HOST);
|
||||
}
|
||||
|
||||
try {
|
||||
// Initialize Connection
|
||||
NetworkManager networkManager = NetworkManager.createNetworkManagerAndConnect(
|
||||
inetAddress,
|
||||
address.getPort(),
|
||||
mc.gameSettings.isUsingNativeTransport()
|
||||
);
|
||||
|
||||
// Create User
|
||||
BaritoneUser user = new BaritoneUser(this, networkManager, session);
|
||||
this.users.add(user);
|
||||
|
||||
// Setup login handler and send connection packets
|
||||
networkManager.setNetHandler(new BotNetHandlerLoginClient(networkManager, user));
|
||||
networkManager.sendPacket(new C00Handshake(address.getIP(), address.getPort(), EnumConnectionState.LOGIN));
|
||||
networkManager.sendPacket(new CPacketLoginStart(session.getProfile()));
|
||||
|
||||
return ConnectionResult.success(user);
|
||||
} catch (Exception e) {
|
||||
return ConnectionResult.failed(CONNECTION_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the manager of an {@link IBaritoneUser} disconnect, and
|
||||
* removes the {@link IBaritoneUser} from the list of users.
|
||||
*
|
||||
* @param user The user that disconnected
|
||||
* @param state The connection state at the time of disconnect
|
||||
*/
|
||||
public final void notifyDisconnect(IBaritoneUser user, EnumConnectionState state) {
|
||||
this.users.remove(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The bot world provider
|
||||
*/
|
||||
public final BotWorldProvider getWorldProvider() {
|
||||
return this.worldProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void disconnect(IBaritoneUser user) {
|
||||
// It's probably fine to pass null to this, because the handlers aren't doing anything with it
|
||||
// noinspection ConstantConditions
|
||||
user.getNetworkManager().closeChannel(null);
|
||||
this.users.remove(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<IBaritoneUser> users() {
|
||||
return Collections.unmodifiableList(this.users);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.connect;
|
||||
|
||||
import baritone.api.bot.IBaritoneUser;
|
||||
import baritone.api.bot.connect.ConnectionStatus;
|
||||
import baritone.api.bot.connect.IConnectionResult;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import static baritone.api.bot.connect.ConnectionStatus.SUCCESS;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 11/6/2018
|
||||
*/
|
||||
public final class ConnectionResult implements IConnectionResult {
|
||||
|
||||
/**
|
||||
* The result status
|
||||
*/
|
||||
private final ConnectionStatus status;
|
||||
|
||||
/**
|
||||
* The user created, if the status is {@link ConnectionStatus#SUCCESS}
|
||||
*/
|
||||
private final IBaritoneUser user;
|
||||
|
||||
private ConnectionResult(ConnectionStatus status, IBaritoneUser user) {
|
||||
this.status = status;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionStatus getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<IBaritoneUser> getUser() {
|
||||
return Optional.ofNullable(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new failed {@link ConnectionResult}.
|
||||
*
|
||||
* @param status The failed connection status
|
||||
* @return The connection result
|
||||
* @throws IllegalArgumentException if {@code status} is {@link ConnectionStatus#SUCCESS}
|
||||
*/
|
||||
public static ConnectionResult failed(ConnectionStatus status) {
|
||||
if (status == SUCCESS) {
|
||||
throw new IllegalArgumentException("Status must be a failure type");
|
||||
}
|
||||
|
||||
return new ConnectionResult(status, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new success {@link ConnectionResult}.
|
||||
*
|
||||
* @param user The user created
|
||||
* @return The connection result
|
||||
* @throws IllegalArgumentException if {@code user} is {@code null}
|
||||
*/
|
||||
public static ConnectionResult success(IBaritoneUser user) {
|
||||
Objects.requireNonNull(user);
|
||||
|
||||
return new ConnectionResult(SUCCESS, user);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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.handler;
|
||||
|
||||
import baritone.bot.BaritoneUser;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.exceptions.AuthenticationException;
|
||||
import com.mojang.authlib.exceptions.AuthenticationUnavailableException;
|
||||
import com.mojang.authlib.exceptions.InvalidCredentialsException;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.network.NetHandlerLoginClient;
|
||||
import net.minecraft.network.EnumConnectionState;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.login.client.CPacketEncryptionResponse;
|
||||
import net.minecraft.network.login.server.SPacketEncryptionRequest;
|
||||
import net.minecraft.network.login.server.SPacketLoginSuccess;
|
||||
import net.minecraft.util.CryptManager;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.crypto.SecretKey;
|
||||
import java.math.BigInteger;
|
||||
import java.security.PublicKey;
|
||||
|
||||
/**
|
||||
* Handles the login stage when connecting to a server.
|
||||
*
|
||||
* @author Brady
|
||||
* @since 10/29/2018
|
||||
*/
|
||||
public class BotNetHandlerLoginClient extends NetHandlerLoginClient {
|
||||
|
||||
/**
|
||||
* The {@link NetworkManager} that is managing the connection with the server.
|
||||
*/
|
||||
private final NetworkManager networkManager;
|
||||
|
||||
/**
|
||||
* The {@link Minecraft} game instance
|
||||
*/
|
||||
private final Minecraft mc;
|
||||
|
||||
/**
|
||||
* The bot of this connection
|
||||
*/
|
||||
private final BaritoneUser user;
|
||||
|
||||
public BotNetHandlerLoginClient(NetworkManager networkManager, BaritoneUser user) {
|
||||
super(networkManager, Minecraft.getMinecraft(), null);
|
||||
this.networkManager = networkManager;
|
||||
this.mc = Minecraft.getMinecraft();
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEncryptionRequest(SPacketEncryptionRequest packetIn) {
|
||||
SecretKey secretkey = CryptManager.createNewSharedKey();
|
||||
PublicKey publicKey = packetIn.getPublicKey();
|
||||
|
||||
// Setup joinServer payload info
|
||||
GameProfile profile = this.user.getSession().getProfile();
|
||||
String authenticationToken = this.user.getSession().getToken();
|
||||
String serverId = new BigInteger(CryptManager.getServerIdHash(packetIn.getServerId(), publicKey, secretkey)).toString(16);
|
||||
|
||||
if (this.mc.getCurrentServerData() != null && this.mc.getCurrentServerData().isOnLAN()) {
|
||||
try {
|
||||
this.mc.getSessionService().joinServer(profile, authenticationToken, serverId);
|
||||
} catch (AuthenticationException e) {
|
||||
// Couldn't connect to auth servers but will continue to join LAN
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
this.mc.getSessionService().joinServer(profile, authenticationToken, serverId);
|
||||
} catch (AuthenticationUnavailableException e) {
|
||||
this.networkManager.closeChannel(new TextComponentTranslation("disconnect.loginFailedInfo", new TextComponentTranslation("disconnect.loginFailedInfo.serversUnavailable")));
|
||||
return;
|
||||
} catch (InvalidCredentialsException e) {
|
||||
this.networkManager.closeChannel(new TextComponentTranslation("disconnect.loginFailedInfo", new TextComponentTranslation("disconnect.loginFailedInfo.invalidSession")));
|
||||
return;
|
||||
} catch (AuthenticationException e) {
|
||||
this.networkManager.closeChannel(new TextComponentTranslation("disconnect.loginFailedInfo", e.getMessage()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// noinspection unchecked
|
||||
this.networkManager.sendPacket(new CPacketEncryptionResponse(secretkey, publicKey, packetIn.getVerifyToken()),
|
||||
future -> BotNetHandlerLoginClient.this.networkManager.enableEncryption(secretkey));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleLoginSuccess(SPacketLoginSuccess packetIn) {
|
||||
this.networkManager.setConnectionState(EnumConnectionState.PLAY);
|
||||
this.networkManager.setNetHandler(new BotNetHandlerPlayClient(this.networkManager, this.user, Minecraft.getMinecraft(), packetIn.getProfile()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnect(@Nonnull ITextComponent reason) {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,706 @@
|
||||
/*
|
||||
* 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.handler;
|
||||
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.bot.BaritoneUser;
|
||||
import baritone.bot.spec.BotPlayerController;
|
||||
import baritone.bot.spec.BotWorld;
|
||||
import baritone.bot.spec.EntityBot;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.multiplayer.ClientAdvancementManager;
|
||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||
import net.minecraft.client.util.RecipeBookClient;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.entity.player.PlayerCapabilities;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.EnumConnectionState;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.PacketThreadUtil;
|
||||
import net.minecraft.network.play.INetHandlerPlayClient;
|
||||
import net.minecraft.network.play.client.*;
|
||||
import net.minecraft.network.play.server.*;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.stats.StatisticsManager;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.EnumHandSide;
|
||||
import net.minecraft.util.IThreadListener;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.Explosion;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
// Notes
|
||||
// - Make some sort of system that prevents repetition of entity info updating
|
||||
// - For some packets, such as ones that modify position, we can check if the existing server state matches the packet proposed state
|
||||
// - For other things, we'll actually need the system
|
||||
|
||||
/**
|
||||
* This class would effectively operate the same if we directly implemented {@link INetHandlerPlayClient},
|
||||
* however, the {@link EntityPlayerSP} constructor requires an actual implementation of
|
||||
* {@link NetHandlerPlayClient} in order to access the {@link GameProfile}.
|
||||
*
|
||||
* @author Brady
|
||||
* @since 10/22/2018
|
||||
*/
|
||||
public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
||||
|
||||
/**
|
||||
* The {@link NetworkManager} that is managing the connection with the server.
|
||||
*/
|
||||
private final NetworkManager networkManager;
|
||||
|
||||
/**
|
||||
* This is the {@link Minecraft} game instance, however, to prevent unwanted references
|
||||
* to the game instance fields, we refer to it as a {@link IThreadListener}.
|
||||
*/
|
||||
private final IThreadListener client;
|
||||
|
||||
/**
|
||||
* The bot of this connection
|
||||
*/
|
||||
private final BaritoneUser user;
|
||||
|
||||
/**
|
||||
* The bot entity
|
||||
*/
|
||||
private EntityBot player;
|
||||
|
||||
/**
|
||||
* The current world.
|
||||
*/
|
||||
private BotWorld world;
|
||||
|
||||
/**
|
||||
* The current player controller
|
||||
*/
|
||||
private BotPlayerController playerController;
|
||||
|
||||
public BotNetHandlerPlayClient(NetworkManager networkManager, BaritoneUser user, Minecraft client, GameProfile profile) {
|
||||
// noinspection ConstantConditions
|
||||
super(client, null, networkManager, profile);
|
||||
this.networkManager = networkManager;
|
||||
this.client = client;
|
||||
this.user = user;
|
||||
|
||||
// Notify the user that we're ingame
|
||||
this.user.onLoginSuccess(profile, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSpawnObject(@Nonnull SPacketSpawnObject packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSpawnExperienceOrb(@Nonnull SPacketSpawnExperienceOrb packetIn) { /* We will want to know this if we want Tenor to collect XP */ }
|
||||
|
||||
@Override
|
||||
public void handleSpawnGlobalEntity(@Nonnull SPacketSpawnGlobalEntity packetIn) { /* Only lightning bolts, this may change in the future */ }
|
||||
|
||||
@Override
|
||||
public void handleSpawnMob(@Nonnull SPacketSpawnMob packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleScoreboardObjective(@Nonnull SPacketScoreboardObjective packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleSpawnPainting(@Nonnull SPacketSpawnPainting packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleSpawnPlayer(@Nonnull SPacketSpawnPlayer packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleAnimation(@Nonnull SPacketAnimation packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
Entity entity = this.world.getEntityByID(packetIn.getEntityID());
|
||||
if (entity != null) {
|
||||
switch (packetIn.getAnimationType()) {
|
||||
case 0: {
|
||||
((EntityLivingBase) entity).swingArm(EnumHand.MAIN_HAND);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
entity.performHurtAnimation();
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
((EntityPlayer) entity).wakeUpPlayer(false, false, false);
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
((EntityLivingBase) entity).swingArm(EnumHand.OFF_HAND);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleStatistics(@Nonnull SPacketStatistics packetIn) { /* Lol global bot stats when?? */ }
|
||||
|
||||
@Override
|
||||
public void handleRecipeBook(@Nonnull SPacketRecipeBook packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleBlockBreakAnim(@Nonnull SPacketBlockBreakAnim packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleSignEditorOpen(@Nonnull SPacketSignEditorOpen packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleUpdateTileEntity(@Nonnull SPacketUpdateTileEntity packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleBlockAction(@Nonnull SPacketBlockAction packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleBlockChange(@Nonnull SPacketBlockChange packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
this.world.setBlockState(packetIn.getBlockPosition(), packetIn.getBlockState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleChat(@Nonnull SPacketChat packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTabComplete(@Nonnull SPacketTabComplete packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleMultiBlockChange(@Nonnull SPacketMultiBlockChange packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
for (SPacketMultiBlockChange.BlockUpdateData data : packetIn.getChangedBlocks()) {
|
||||
this.world.setBlockState(data.getPos(), data.getBlockState());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMaps(@Nonnull SPacketMaps packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleConfirmTransaction(@Nonnull SPacketConfirmTransaction packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCloseWindow(@Nonnull SPacketCloseWindow packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
this.player.closeScreenAndDropStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleWindowItems(@Nonnull SPacketWindowItems packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
(packetIn.getWindowId() == 0 ? this.player.inventoryContainer : this.player.openContainer).setAll(packetIn.getItemStacks());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleOpenWindow(@Nonnull SPacketOpenWindow packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleWindowProperty(@Nonnull SPacketWindowProperty packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleSetSlot(@Nonnull SPacketSetSlot packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
ItemStack stack = packetIn.getStack();
|
||||
int slot = packetIn.getSlot();
|
||||
|
||||
switch (packetIn.getWindowId()) {
|
||||
case -1: {
|
||||
this.player.inventory.setItemStack(stack);
|
||||
break;
|
||||
}
|
||||
case -2: {
|
||||
this.player.inventory.setInventorySlotContents(slot, stack);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if (packetIn.getWindowId() == 0 && packetIn.getSlot() >= 36 && slot < 45) {
|
||||
this.player.inventoryContainer.putStackInSlot(slot, stack);
|
||||
} else if (packetIn.getWindowId() == this.player.openContainer.windowId && packetIn.getWindowId() != 0) {
|
||||
this.player.openContainer.putStackInSlot(slot, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCustomPayload(@Nonnull SPacketCustomPayload packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleDisconnect(@Nonnull SPacketDisconnect packetIn) {
|
||||
this.networkManager.closeChannel(packetIn.getReason());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUseBed(@Nonnull SPacketUseBed packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEntityStatus(@Nonnull SPacketEntityStatus packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEntityAttach(@Nonnull SPacketEntityAttach packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSetPassengers(@Nonnull SPacketSetPassengers packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleExplosion(@Nonnull SPacketExplosion packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
// noinspection ConstantConditions
|
||||
new Explosion(this.world, null, packetIn.getX(), packetIn.getY(), packetIn.getZ(), packetIn.getStrength(), packetIn.getAffectedBlockPositions()).doExplosionB(true);
|
||||
this.player.motionX += (double) packetIn.getMotionX();
|
||||
this.player.motionY += (double) packetIn.getMotionY();
|
||||
this.player.motionZ += (double) packetIn.getMotionZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleChangeGameState(@Nonnull SPacketChangeGameState packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleKeepAlive(@Nonnull SPacketKeepAlive packetIn) {
|
||||
this.networkManager.sendPacket(new CPacketKeepAlive(packetIn.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleChunkData(@Nonnull SPacketChunkData packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
if (packetIn.isFullChunk()) {
|
||||
this.world.doPreChunk(packetIn.getChunkX(), packetIn.getChunkZ(), true);
|
||||
}
|
||||
|
||||
Chunk chunk = this.world.getChunk(packetIn.getChunkX(), packetIn.getChunkZ());
|
||||
chunk.read(packetIn.getReadBuffer(), packetIn.getExtractedSize(), packetIn.isFullChunk());
|
||||
|
||||
for (NBTTagCompound tag : packetIn.getTileEntityTags()) {
|
||||
BlockPos pos = new BlockPos(tag.getInteger("x"), tag.getInteger("y"), tag.getInteger("z"));
|
||||
TileEntity tileEntity = this.world.getTileEntity(pos);
|
||||
|
||||
if (tileEntity != null) {
|
||||
tileEntity.readFromNBT(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processChunkUnload(@Nonnull SPacketUnloadChunk packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
// TODO Unload chunks
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEffect(@Nonnull SPacketEffect packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleJoinGame(@Nonnull SPacketJoinGame packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
this.playerController = new BotPlayerController(this.user);
|
||||
this.world = this.user.getManager().getWorldProvider().getWorld(packetIn.getDimension());
|
||||
this.player = new EntityBot(this.user, (Minecraft) this.client, this.world, this, new StatisticsManager(), new RecipeBookClient());
|
||||
this.user.onWorldLoad(this.world, this.player, this.playerController);
|
||||
this.player.preparePlayerToSpawn();
|
||||
this.world.spawnEntity(this.player);
|
||||
this.player.setEntityId(packetIn.getPlayerId());
|
||||
this.player.dimension = packetIn.getDimension();
|
||||
this.playerController.setGameType(packetIn.getGameType());
|
||||
packetIn.getGameType().configurePlayerCapabilities(this.player.capabilities);
|
||||
|
||||
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")));
|
||||
|
||||
this.world.registerBot(packetIn.getPlayerId(), this.player);
|
||||
|
||||
Helper.HELPER.logDirect("Initialized Player and World");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEntityMovement(@Nonnull SPacketEntity packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePlayerPosLook(@Nonnull SPacketPlayerPosLook packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
EntityPlayer player = this.player;
|
||||
double d0 = packetIn.getX();
|
||||
double d1 = packetIn.getY();
|
||||
double d2 = packetIn.getZ();
|
||||
float f = packetIn.getYaw();
|
||||
float f1 = packetIn.getPitch();
|
||||
|
||||
if (packetIn.getFlags().contains(SPacketPlayerPosLook.EnumFlags.X)) {
|
||||
d0 += player.posX;
|
||||
} else {
|
||||
player.motionX = 0.0D;
|
||||
}
|
||||
|
||||
if (packetIn.getFlags().contains(SPacketPlayerPosLook.EnumFlags.Y)) {
|
||||
d1 += player.posY;
|
||||
} else {
|
||||
player.motionY = 0.0D;
|
||||
}
|
||||
|
||||
if (packetIn.getFlags().contains(SPacketPlayerPosLook.EnumFlags.Z)) {
|
||||
d2 += player.posZ;
|
||||
} else {
|
||||
player.motionZ = 0.0D;
|
||||
}
|
||||
|
||||
if (packetIn.getFlags().contains(SPacketPlayerPosLook.EnumFlags.X_ROT)) {
|
||||
f1 += player.rotationPitch;
|
||||
}
|
||||
|
||||
if (packetIn.getFlags().contains(SPacketPlayerPosLook.EnumFlags.Y_ROT)) {
|
||||
f += player.rotationYaw;
|
||||
}
|
||||
|
||||
player.setPositionAndRotation(d0, d1, d2, f, f1);
|
||||
this.networkManager.sendPacket(new CPacketConfirmTeleport(packetIn.getTeleportId()));
|
||||
this.networkManager.sendPacket(new CPacketPlayer.PositionRotation(player.posX, player.getEntityBoundingBox().minY, player.posZ, player.rotationYaw, player.rotationPitch, false));
|
||||
|
||||
this.player.prevPosX = this.player.posX;
|
||||
this.player.prevPosY = this.player.posY;
|
||||
this.player.prevPosZ = this.player.posZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleParticles(@Nonnull SPacketParticles packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handlePlayerAbilities(@Nonnull SPacketPlayerAbilities packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
PlayerCapabilities c = this.player.capabilities;
|
||||
c.disableDamage = packetIn.isInvulnerable();
|
||||
c.isFlying = packetIn.isFlying();
|
||||
c.allowFlying = packetIn.isAllowFlying();
|
||||
c.isCreativeMode = packetIn.isCreativeMode();
|
||||
c.setFlySpeed(packetIn.getFlySpeed());
|
||||
c.setPlayerWalkSpeed(packetIn.getWalkSpeed());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePlayerListItem(@Nonnull SPacketPlayerListItem packetIn) {
|
||||
// okay now this is awesome
|
||||
super.handlePlayerListItem(packetIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleDestroyEntities(@Nonnull SPacketDestroyEntities packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
for (int i = 0; i < packetIn.getEntityIDs().length; ++i) {
|
||||
this.world.removeEntityFromWorld(packetIn.getEntityIDs()[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRemoveEntityEffect(@Nonnull SPacketRemoveEntityEffect packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
Entity entity = packetIn.getEntity(this.world);
|
||||
if (entity instanceof EntityLivingBase) {
|
||||
((EntityLivingBase) entity).removeActivePotionEffect(packetIn.getPotion());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRespawn(@Nonnull SPacketRespawn packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
if (packetIn.getDimensionID() != this.player.dimension) {
|
||||
this.world.removeEntity(this.player);
|
||||
this.world = this.user.getManager().getWorldProvider().getWorld(packetIn.getDimensionID());
|
||||
}
|
||||
|
||||
EntityBot prev = this.player;
|
||||
|
||||
this.player = new EntityBot(this.user, (Minecraft) this.client, this.world, this, prev.getStatFileWriter(), prev.getRecipeBook());
|
||||
this.user.onWorldLoad(this.world, this.player, this.playerController);
|
||||
// noinspection ConstantConditions
|
||||
this.player.getDataManager().setEntryValues(prev.getDataManager().getAll());
|
||||
this.player.preparePlayerToSpawn();
|
||||
this.world.spawnEntity(this.player);
|
||||
this.player.setEntityId(prev.getEntityId());
|
||||
this.player.dimension = packetIn.getDimensionID();
|
||||
this.player.setServerBrand(prev.getServerBrand());
|
||||
this.playerController.setGameType(packetIn.getGameType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEntityHeadLook(@Nonnull SPacketEntityHeadLook packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleHeldItemChange(@Nonnull SPacketHeldItemChange packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
if (InventoryPlayer.isHotbar(packetIn.getHeldItemHotbarIndex())) {
|
||||
this.player.inventory.currentItem = packetIn.getHeldItemHotbarIndex();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleDisplayObjective(@Nonnull SPacketDisplayObjective packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEntityMetadata(@Nonnull SPacketEntityMetadata packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
Entity entity = this.world.getEntityByID(packetIn.getEntityId());
|
||||
if (entity != null && packetIn.getDataManagerEntries() != null) {
|
||||
entity.getDataManager().setEntryValues(packetIn.getDataManagerEntries());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEntityVelocity(@Nonnull SPacketEntityVelocity packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
Entity entity = this.world.getEntityByID(packetIn.getEntityID());
|
||||
if (entity != null) {
|
||||
entity.setVelocity(
|
||||
(double) packetIn.getMotionX() / 8000.0D,
|
||||
(double) packetIn.getMotionY() / 8000.0D,
|
||||
(double) packetIn.getMotionZ() / 8000.0D
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEntityEquipment(@Nonnull SPacketEntityEquipment packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
Entity entity = this.world.getEntityByID(packetIn.getEntityID());
|
||||
if (entity != null) {
|
||||
entity.setItemStackToSlot(packetIn.getEquipmentSlot(), packetIn.getItemStack());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSetExperience(@Nonnull SPacketSetExperience packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
this.player.setXPStats(packetIn.getExperienceBar(), packetIn.getTotalExperience(), packetIn.getLevel());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdateHealth(@Nonnull SPacketUpdateHealth packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
this.player.setPlayerSPHealth(packetIn.getHealth());
|
||||
this.player.getFoodStats().setFoodLevel(packetIn.getFoodLevel());
|
||||
this.player.getFoodStats().setFoodSaturationLevel(packetIn.getSaturationLevel());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTeams(@Nonnull SPacketTeams packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleUpdateScore(@Nonnull SPacketUpdateScore packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleSpawnPosition(@Nonnull SPacketSpawnPosition packetIn) { /* We probably don't need to know this, the server handles everything related to spawn psoition? */ }
|
||||
|
||||
@Override
|
||||
public void handleTimeUpdate(@Nonnull SPacketTimeUpdate packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
this.world.setTotalWorldTime(packetIn.getTotalWorldTime());
|
||||
this.world.setWorldTime(packetIn.getWorldTime());
|
||||
|
||||
// TODO: Calculate World TPS
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSoundEffect(@Nonnull SPacketSoundEffect packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleCustomSound(@Nonnull SPacketCustomSound packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleCollectItem(@Nonnull SPacketCollectItem packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEntityTeleport(@Nonnull SPacketEntityTeleport packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEntityProperties(@Nonnull SPacketEntityProperties packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEntityEffect(@Nonnull SPacketEntityEffect packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
Entity entity = this.world.getEntityByID(packetIn.getEntityId());
|
||||
|
||||
if (entity instanceof EntityLivingBase) {
|
||||
Potion potion = Potion.getPotionById(packetIn.getEffectId());
|
||||
|
||||
if (potion != null) {
|
||||
PotionEffect effect = new PotionEffect(potion, packetIn.getDuration(), packetIn.getAmplifier(), packetIn.getIsAmbient(), packetIn.doesShowParticles());
|
||||
effect.setPotionDurationMax(packetIn.isMaxDuration());
|
||||
((EntityLivingBase) entity).addPotionEffect(effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCombatEvent(@Nonnull SPacketCombatEvent packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
// We only care if we died
|
||||
if (packetIn.eventType == SPacketCombatEvent.Event.ENTITY_DIED) {
|
||||
if (packetIn.playerId == this.player.getEntityId()) {
|
||||
// Perform an instantaneous respawn
|
||||
this.networkManager.sendPacket(new CPacketClientStatus(CPacketClientStatus.State.PERFORM_RESPAWN));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServerDifficulty(@Nonnull SPacketServerDifficulty packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleCamera(SPacketCamera packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleWorldBorder(@Nonnull SPacketWorldBorder packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
packetIn.apply(this.world.getWorldBorder());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTitle(@Nonnull SPacketTitle packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handlePlayerListHeaderFooter(@Nonnull SPacketPlayerListHeaderFooter packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleResourcePack(@Nonnull SPacketResourcePackSend packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
// Lie to the server and tell them we accepted it in response
|
||||
this.networkManager.sendPacket(new CPacketResourcePackStatus(CPacketResourcePackStatus.Action.ACCEPTED));
|
||||
this.networkManager.sendPacket(new CPacketResourcePackStatus(CPacketResourcePackStatus.Action.SUCCESSFULLY_LOADED));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdateBossInfo(@Nonnull SPacketUpdateBossInfo packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleCooldown(@Nonnull SPacketCooldown packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
if (packetIn.getTicks() == 0) { // There is no cooldown
|
||||
this.player.getCooldownTracker().removeCooldown(packetIn.getItem());
|
||||
} else {
|
||||
this.player.getCooldownTracker().setCooldown(packetIn.getItem(), packetIn.getTicks());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMoveVehicle(@Nonnull SPacketMoveVehicle packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
/* Atm Baritone doesn't even work on vehicles that well at all, so this is a major TODO */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleAdvancementInfo(@Nonnull SPacketAdvancementInfo packetIn) {}
|
||||
|
||||
@Override
|
||||
public void handleSelectAdvancementsTab(@Nonnull SPacketSelectAdvancementsTab packetIn) { /* Lol global bot achievements when? */ }
|
||||
|
||||
@Override
|
||||
public void func_194307_a(@Nonnull SPacketPlaceGhostRecipe p_194307_1_) {}
|
||||
|
||||
@Override
|
||||
public void onDisconnect(@Nonnull ITextComponent reason) {
|
||||
// TODO Maybe more world unloadinde
|
||||
this.world.removeEntity(this.player);
|
||||
this.user.getManager().notifyDisconnect(this.user, EnumConnectionState.PLAY);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
* 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.spec;
|
||||
|
||||
import baritone.api.bot.IBaritoneUser;
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockCommandBlock;
|
||||
import net.minecraft.block.BlockStructure;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.ClickType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.play.client.CPacketClickWindow;
|
||||
import net.minecraft.network.play.client.CPacketHeldItemChange;
|
||||
import net.minecraft.network.play.client.CPacketPlayerDigging;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.GameType;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 11/14/2018
|
||||
*/
|
||||
public class BotPlayerController implements IPlayerController {
|
||||
|
||||
private final IBaritoneUser user;
|
||||
private GameType gameType;
|
||||
|
||||
private BlockPos currentBlock;
|
||||
private ItemStack currentHittingItem;
|
||||
private boolean hittingBlock;
|
||||
private float blockDamage;
|
||||
private int blockHitDelay;
|
||||
private int heldItemServer;
|
||||
|
||||
public BotPlayerController(IBaritoneUser user) {
|
||||
this.user = user;
|
||||
this.currentHittingItem = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPlayerDamageBlock(BlockPos pos, EnumFacing side) {
|
||||
this.syncHeldItem();
|
||||
|
||||
EntityPlayerSP player = this.user.getEntity();
|
||||
World world = player.world;
|
||||
|
||||
if (this.blockHitDelay > 0) {
|
||||
this.blockHitDelay--;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!this.isHittingPosition(pos)) {
|
||||
return this.clickBlock(pos, side);
|
||||
}
|
||||
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
|
||||
if (state.getMaterial() == Material.AIR) {
|
||||
this.hittingBlock = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
this.blockDamage += state.getPlayerRelativeBlockHardness(player, world, pos);
|
||||
|
||||
if (this.blockDamage >= 1.0F) {
|
||||
this.hittingBlock = false;
|
||||
this.blockDamage = 0.0F;
|
||||
this.blockHitDelay = 5;
|
||||
|
||||
player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side));
|
||||
this.handleBreak(pos);
|
||||
}
|
||||
|
||||
world.sendBlockBreakProgress(player.getEntityId(), this.currentBlock, (int) (this.blockDamage * 10.0F) - 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetBlockRemoving() {
|
||||
if (this.hittingBlock) {
|
||||
this.hittingBlock = false;
|
||||
this.blockDamage = 0.0F;
|
||||
this.user.getEntity().resetCooldown();
|
||||
this.user.getEntity().connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.ABORT_DESTROY_BLOCK, this.currentBlock, EnumFacing.DOWN));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack windowClick(int windowId, int slotId, int mouseButton, ClickType type, EntityPlayer player) {
|
||||
short transactionID = player.openContainer.getNextTransactionID(player.inventory);
|
||||
ItemStack stack = player.openContainer.slotClick(slotId, mouseButton, type, player);
|
||||
this.user.getEntity().connection.sendPacket(new CPacketClickWindow(windowId, slotId, mouseButton, type, stack, transactionID));
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGameType(GameType type) {
|
||||
this.gameType = type;
|
||||
this.gameType.configurePlayerCapabilities(this.user.getEntity().capabilities);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameType getGameType() {
|
||||
return this.gameType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clickBlock(BlockPos pos, EnumFacing side) {
|
||||
EntityPlayerSP player = this.user.getEntity();
|
||||
World world = player.world;
|
||||
|
||||
if (!canBreak(player, pos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.hittingBlock || !this.isHittingPosition(pos)) {
|
||||
if (this.hittingBlock) {
|
||||
player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.ABORT_DESTROY_BLOCK, this.currentBlock, side));
|
||||
}
|
||||
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, side));
|
||||
|
||||
if (state.getMaterial() != Material.AIR) {
|
||||
if (this.blockDamage == 0.0F) {
|
||||
state.getBlock().onBlockClicked(world, pos, player);
|
||||
}
|
||||
if (state.getPlayerRelativeBlockHardness(player, player.world, pos) >= 1.0F) {
|
||||
this.handleBreak(pos);
|
||||
}
|
||||
} else {
|
||||
this.hittingBlock = true;
|
||||
this.currentBlock = pos;
|
||||
this.blockDamage = 0.0F;
|
||||
this.currentHittingItem = player.getHeldItemMainhand();
|
||||
world.sendBlockBreakProgress(player.getEntityId(), this.currentBlock, (int) (this.blockDamage * 10.0F) - 1);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void handleBreak(BlockPos pos) {
|
||||
EntityPlayerSP player = this.user.getEntity();
|
||||
World world = player.world;
|
||||
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
Block block = state.getBlock();
|
||||
|
||||
if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !player.canUseCommandBlock()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state.getMaterial() == Material.AIR) {
|
||||
return;
|
||||
}
|
||||
|
||||
block.onBlockHarvested(world, pos, state, player);
|
||||
|
||||
if (world.setBlockState(pos, Blocks.AIR.getDefaultState(), 11)) {
|
||||
block.onPlayerDestroy(world, pos, state);
|
||||
}
|
||||
|
||||
this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ());
|
||||
|
||||
ItemStack stack = player.getHeldItemMainhand();
|
||||
|
||||
if (!stack.isEmpty()) {
|
||||
stack.onBlockDestroyed(world, state, pos, player);
|
||||
|
||||
if (stack.isEmpty()) {
|
||||
player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canBreak(EntityPlayer player, BlockPos pos) {
|
||||
if (this.gameType.isCreative() || this.gameType == GameType.SPECTATOR) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!player.world.getWorldBorder().contains(pos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.gameType.hasLimitedInteractions() && !player.isAllowEdit()) {
|
||||
ItemStack stack = player.getHeldItemMainhand();
|
||||
return !stack.isEmpty() && stack.canDestroy(player.world.getBlockState(pos).getBlock());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isHittingPosition(BlockPos pos) {
|
||||
ItemStack stack = this.user.getEntity().getHeldItemMainhand();
|
||||
boolean itemUnchanged = this.currentHittingItem.isEmpty() && stack.isEmpty();
|
||||
|
||||
if (!this.currentHittingItem.isEmpty() && !stack.isEmpty()) {
|
||||
itemUnchanged = stack.getItem() == this.currentHittingItem.getItem()
|
||||
&& ItemStack.areItemStackTagsEqual(stack, this.currentHittingItem)
|
||||
&& (stack.isItemStackDamageable() || stack.getMetadata() == this.currentHittingItem.getMetadata());
|
||||
}
|
||||
|
||||
return pos.equals(this.currentBlock) && itemUnchanged;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncHeldItem() {
|
||||
int heldItemClient = this.user.getEntity().inventory.currentItem;
|
||||
|
||||
if (heldItemClient != this.heldItemServer) {
|
||||
this.heldItemServer = heldItemClient;
|
||||
this.user.getEntity().connection.sendPacket(new CPacketHeldItemChange(this.heldItemServer));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBrokenBlock() {
|
||||
return this.currentBlock.getY() == -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumActionResult processRightClickBlock(EntityPlayerSP player, World world, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand) {
|
||||
throw new AbstractMethodError("Lol");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumActionResult processRightClick(EntityPlayerSP player, World world, EnumHand hand) {
|
||||
throw new AbstractMethodError("Lol");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHittingBlock(boolean hittingBlock) {
|
||||
this.hittingBlock = hittingBlock;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.spec;
|
||||
|
||||
import net.minecraft.client.multiplayer.ChunkProviderClient;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.profiler.Profiler;
|
||||
import net.minecraft.world.DimensionType;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldSettings;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import net.minecraft.world.storage.SaveHandlerMP;
|
||||
import net.minecraft.world.storage.WorldInfo;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 11/7/2018
|
||||
*/
|
||||
public class BotWorld extends World {
|
||||
|
||||
private static Profiler BOT_WORLD_PROFILER = new Profiler();
|
||||
private static int worldNum = 0;
|
||||
|
||||
private ChunkProviderClient chunkProviderClient;
|
||||
|
||||
public BotWorld(WorldSettings settings, int dimension) {
|
||||
super(
|
||||
new SaveHandlerMP(),
|
||||
new WorldInfo(settings, "BotWorld" + ++worldNum),
|
||||
DimensionType.getById(dimension).createDimension(),
|
||||
BOT_WORLD_PROFILER,
|
||||
true
|
||||
);
|
||||
this.provider.setWorld(this);
|
||||
this.chunkProvider = this.createChunkProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
protected IChunkProvider createChunkProvider() {
|
||||
return (this.chunkProviderClient = new ChunkProviderClient(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isChunkLoaded(int x, int z, boolean allowEmpty) {
|
||||
return allowEmpty || !this.chunkProviderClient.provideChunk(x, z).isEmpty();
|
||||
}
|
||||
|
||||
public void registerBot(int entityID, EntityBot entity) {
|
||||
this.entitiesById.addKey(entityID, entity);
|
||||
}
|
||||
|
||||
public void removeEntityFromWorld(int entityID) {
|
||||
Entity entity = this.entitiesById.removeObject(entityID);
|
||||
if (entity != null) {
|
||||
this.removeEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public void doPreChunk(int chunkX, int chunkZ, boolean loadChunk) {
|
||||
if (loadChunk) {
|
||||
this.chunkProviderClient.loadChunk(chunkX, chunkZ);
|
||||
} else {
|
||||
this.chunkProviderClient.unloadChunk(chunkX, chunkZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* 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.spec;
|
||||
|
||||
import baritone.api.bot.IBaritoneUser;
|
||||
import baritone.utils.PlayerMovementInput;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||
import net.minecraft.client.network.NetworkPlayerInfo;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.IMerchant;
|
||||
import net.minecraft.entity.passive.AbstractHorse;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.stats.RecipeBook;
|
||||
import net.minecraft.stats.StatisticsManager;
|
||||
import net.minecraft.tileentity.CommandBlockBaseLogic;
|
||||
import net.minecraft.tileentity.TileEntityCommandBlock;
|
||||
import net.minecraft.tileentity.TileEntitySign;
|
||||
import net.minecraft.tileentity.TileEntityStructure;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.GameType;
|
||||
import net.minecraft.world.IInteractionObject;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
// Some Notes:
|
||||
// startRiding references the sound manager
|
||||
// onUpdateWalkingPlayer references the gameSettings autoJump flag
|
||||
// notifyDataManagerChange references the sound manager
|
||||
// onLivingUpdate makes a lot of references to mc fields
|
||||
// - playerController
|
||||
// - currentScreen
|
||||
// - gameSettings
|
||||
// - tutorial
|
||||
// What needs to be considered
|
||||
// - The server tells us what our entity id should be, the bot entity should respect this.
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 10/23/2018
|
||||
*/
|
||||
@SuppressWarnings("EntityConstructor")
|
||||
public class EntityBot extends EntityPlayerSP {
|
||||
|
||||
private final IBaritoneUser user;
|
||||
private NetworkPlayerInfo playerInfo;
|
||||
|
||||
public EntityBot(IBaritoneUser user, Minecraft mc, World world, NetHandlerPlayClient netHandlerPlayClient, StatisticsManager statisticsManager, RecipeBook recipeBook) {
|
||||
super(mc, world, netHandlerPlayClient, statisticsManager, recipeBook);
|
||||
this.user = user;
|
||||
this.movementInput = new PlayerMovementInput(this.user.getBaritone().getInputOverrideHandler());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeScreenAndDropStack() {
|
||||
this.inventory.setItemStack(ItemStack.EMPTY);
|
||||
|
||||
// EntityPlayer#closeScreen
|
||||
this.openContainer = this.inventoryContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStatusMessage(ITextComponent chatComponent, boolean actionBar) {
|
||||
// TODO: Custom message handling
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(ITextComponent component) {
|
||||
// TODO: Custom message handling
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openEditSign(TileEntitySign signTile) {
|
||||
// TODO: Custom GUI handling
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayGuiEditCommandCart(CommandBlockBaseLogic commandBlock) {
|
||||
// TODO: Custom GUI handling
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayGuiCommandBlock(TileEntityCommandBlock commandBlock) {
|
||||
// TODO: Custom GUI handling
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openEditStructure(TileEntityStructure structure) {
|
||||
// TODO: Custom GUI handling
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openBook(ItemStack stack, EnumHand hand) {
|
||||
// TODO: Custom GUI handling
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayGUIChest(IInventory chestInventory) {
|
||||
// TODO: Custom GUI handling
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openGuiHorseInventory(AbstractHorse horse, IInventory inventoryIn) {
|
||||
// TODO: Custom GUI handling
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayGui(IInteractionObject guiOwner) {
|
||||
// TODO: Custom GUI handling
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayVillagerTradeGui(IMerchant villager) {
|
||||
// TODO: Custom GUI handling
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCriticalHit(Entity entityHit) {
|
||||
// Don't render
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnchantmentCritical(Entity entityHit) {
|
||||
// Don't render
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCurrentViewEntity() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpectator() {
|
||||
NetworkPlayerInfo networkplayerinfo = this.connection.getPlayerInfo(this.getGameProfile().getId());
|
||||
// noinspection ConstantConditions
|
||||
return networkplayerinfo != null && networkplayerinfo.getGameType() == GameType.SPECTATOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCreative() {
|
||||
NetworkPlayerInfo networkplayerinfo = this.connection.getPlayerInfo(this.getGameProfile().getId());
|
||||
// noinspection ConstantConditions
|
||||
return networkplayerinfo != null && networkplayerinfo.getGameType() == GameType.CREATIVE;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected NetworkPlayerInfo getPlayerInfo() {
|
||||
return this.playerInfo == null ? (this.playerInfo = this.connection.getPlayerInfo(this.getUniqueID())) : null;
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import baritone.api.event.events.*;
|
||||
import baritone.api.event.events.type.EventState;
|
||||
import baritone.api.event.listener.IEventBus;
|
||||
import baritone.api.event.listener.IGameEventListener;
|
||||
import baritone.bot.UserManager;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.cache.WorldProvider;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
@@ -29,6 +30,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
@@ -66,6 +68,9 @@ public final class GameEventHandler implements IEventBus, Helper {
|
||||
|
||||
@Override
|
||||
public final void onSendChatMessage(ChatEvent event) {
|
||||
// Ensure UserManager is created to prevent a ConcurrentModificationException
|
||||
Objects.requireNonNull(UserManager.INSTANCE);
|
||||
|
||||
listeners.forEach(l -> l.onSendChatMessage(event));
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,10 @@ public final class PathRenderer implements IRenderer {
|
||||
public static void render(RenderEvent event, PathingBehavior behavior) {
|
||||
float partialTicks = event.getPartialTicks();
|
||||
Goal goal = behavior.getGoal();
|
||||
if (behavior.baritone.getPlayerContext().world() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Helper.mc.currentScreen instanceof GuiClick) {
|
||||
((GuiClick) Helper.mc.currentScreen).onRender();
|
||||
}
|
||||
|
||||
@@ -17,14 +17,15 @@
|
||||
|
||||
package baritone.utils;
|
||||
|
||||
import baritone.api.utils.IInputOverrideHandler;
|
||||
import baritone.api.utils.input.Input;
|
||||
import net.minecraft.util.MovementInput;
|
||||
|
||||
public class PlayerMovementInput extends MovementInput {
|
||||
|
||||
private final InputOverrideHandler handler;
|
||||
private final IInputOverrideHandler handler;
|
||||
|
||||
PlayerMovementInput(InputOverrideHandler handler) {
|
||||
public PlayerMovementInput(IInputOverrideHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,11 @@ public enum PrimaryPlayerController implements IPlayerController, Helper {
|
||||
return mc.playerController.windowClick(windowId, slotId, mouseButton, type, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGameType(GameType type) {
|
||||
mc.playerController.setGameType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameType getGameType() {
|
||||
return mc.playerController.getCurrentGameType();
|
||||
|
||||
Reference in New Issue
Block a user