LAN support in production

This commit is contained in:
Brady
2020-03-04 11:12:07 -06:00
parent b34ad03bcc
commit b038cedfc5
8 changed files with 157 additions and 13 deletions

View File

@@ -33,6 +33,11 @@ public enum ConnectionStatus {
*/
CANT_RESOLVE_HOST,
/**
* The port for the detected LAN server could not be resolved.
*/
CANT_RESOLVE_LAN,
/**
* The connection initialization failed.
*/

View File

@@ -26,8 +26,16 @@ import net.minecraft.util.math.BlockPos;
*/
public interface IMovement {
/**
* @return The cost of executing this movement.
*/
double getCost();
/**
* Updates this movement, allowing it to set the controls for the player to execute.
*
* @return The new status for this movement
*/
MovementStatus update();
/**
@@ -45,10 +53,19 @@ public interface IMovement {
*/
boolean safeToCancel();
/**
* @return Whether or not the position that this movement represents was loaded in the world when calculated.
*/
boolean calculatedWhileLoaded();
/**
* @return The starting position of this movement.
*/
BetterBlockPos getSrc();
/**
* @return The destination position of this movement.
*/
BetterBlockPos getDest();
BlockPos getDirection();

View File

@@ -0,0 +1,36 @@
/*
* 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.launch.mixins;
import baritone.utils.accessor.IIntegratedServer;
import net.minecraft.client.multiplayer.ThreadLanServerPing;
import net.minecraft.server.integrated.IntegratedServer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
/**
* @author Brady
* @since 3/4/2020
*/
@Mixin(IntegratedServer.class)
public abstract class MixinIntegratedServer implements IIntegratedServer {
@Accessor
@Override
public abstract ThreadLanServerPing getLanServerPing();
}

View File

@@ -0,0 +1,35 @@
/*
* 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.launch.mixins;
import baritone.utils.accessor.IThreadLanServerPing;
import net.minecraft.client.multiplayer.ThreadLanServerPing;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
/**
* @author Brady
* @since 3/4/2020
*/
@Mixin(ThreadLanServerPing.class)
public abstract class MixinThreadLanServerPing implements IThreadLanServerPing {
@Accessor
@Override
public abstract String getAddress();
}

View File

@@ -20,6 +20,7 @@
"MixinEntityPlayerSP",
"MixinEntityRenderer",
"MixinGuiScreen",
"MixinIntegratedServer",
"MixinItemStack",
"MixinMinecraft",
"MixinNetHandlerPlayClient",
@@ -29,6 +30,7 @@
"MixinRenderList",
"MixinStateImplementation",
"MixinTabCompleter",
"MixinThreadLanServerPing",
"MixinVboRenderList",
"MixinWorldClient"
]

View File

@@ -27,17 +27,16 @@ import baritone.api.event.listener.AbstractGameEventListener;
import baritone.api.utils.Helper;
import baritone.bot.connect.ConnectionResult;
import baritone.bot.handler.BotNetHandlerLoginClient;
import baritone.utils.accessor.IIntegratedServer;
import baritone.utils.accessor.IThreadLanServerPing;
import net.minecraft.client.multiplayer.ServerAddress;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.multiplayer.ThreadLanServerPing;
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.server.integrated.IntegratedServer;
import net.minecraft.util.Session;
import java.lang.reflect.Field;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collections;
@@ -93,20 +92,14 @@ public final class UserManager implements IUserManager, Helper {
public final IConnectionResult connect(Session session) {
if (mc.getIntegratedServer() != null && mc.getIntegratedServer().getPublic()) {
try {
// TODO: (bot-system) Fix compatibility in production
Field fLanServerPing = IntegratedServer.class.getDeclaredField("lanServerPing");
fLanServerPing.setAccessible(true);
ThreadLanServerPing lanServerPing = (ThreadLanServerPing) fLanServerPing.get(mc.getIntegratedServer());
IIntegratedServer integratedServer = (IIntegratedServer) mc.getIntegratedServer();
IThreadLanServerPing lanServerPing = (IThreadLanServerPing) integratedServer.getLanServerPing();
int port = Integer.parseInt(lanServerPing.getAddress());
Field fAddress = lanServerPing.getClass().getDeclaredField("address");
fAddress.setAccessible(true);
int port = Integer.parseInt(fAddress.get(lanServerPing).toString());
// Connect to the server from the parsed server data
return connect0(session, new ServerData("", "localhost:" + port, true));
} catch (Exception e) {
e.printStackTrace();
return ConnectionResult.failed(CANT_RESOLVE_HOST);
return ConnectionResult.failed(CANT_RESOLVE_LAN);
}
}

View File

@@ -0,0 +1,29 @@
/*
* 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.utils.accessor;
import net.minecraft.client.multiplayer.ThreadLanServerPing;
/**
* @author Brady
* @since 3/4/2020
*/
public interface IIntegratedServer {
ThreadLanServerPing getLanServerPing();
}

View File

@@ -0,0 +1,27 @@
/*
* 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.utils.accessor;
/**
* @author Brady
* @since 3/4/2020
*/
public interface IThreadLanServerPing {
String getAddress();
}