Utilize sendSettingsToServer
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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.IGameSettings;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.entity.player.EnumPlayerModelParts;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 3/6/2020
|
||||
*/
|
||||
@Mixin(GameSettings.class)
|
||||
public abstract class MixinGameSettings implements IGameSettings {
|
||||
|
||||
@Accessor
|
||||
@Override
|
||||
public abstract void setSetModelParts(Set<EnumPlayerModelParts> setModelParts);
|
||||
|
||||
@Accessor
|
||||
@Override
|
||||
public abstract void setMc(Minecraft mc);
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
"MixinEntityLivingBase",
|
||||
"MixinEntityPlayerSP",
|
||||
"MixinEntityRenderer",
|
||||
"MixinGameSettings",
|
||||
"MixinGuiScreen",
|
||||
"MixinIntegratedServer",
|
||||
"MixinItemStack",
|
||||
|
||||
@@ -154,6 +154,7 @@ public final class UserManager implements IUserManager, Helper {
|
||||
|
||||
return ConnectionResult.success(user);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ConnectionResult.failed(CONNECTION_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package baritone.bot.handler;
|
||||
|
||||
import baritone.bot.BaritoneUser;
|
||||
import baritone.bot.spec.BotMinecraft;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.network.NetHandlerLoginClient;
|
||||
import net.minecraft.network.EnumConnectionState;
|
||||
@@ -43,7 +44,7 @@ public class BotNetHandlerLoginClient extends NetHandlerLoginClient {
|
||||
/**
|
||||
* The {@link Minecraft} game instance
|
||||
*/
|
||||
private final Minecraft mc;
|
||||
private final BotMinecraft mc;
|
||||
|
||||
/**
|
||||
* The bot of this connection
|
||||
|
||||
@@ -19,12 +19,12 @@ package baritone.bot.handler;
|
||||
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.bot.BaritoneUser;
|
||||
import baritone.bot.spec.BotMinecraft;
|
||||
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;
|
||||
@@ -36,7 +36,6 @@ 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;
|
||||
@@ -48,8 +47,6 @@ 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;
|
||||
@@ -78,10 +75,9 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
||||
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}.
|
||||
* The bot's minecraft game instance. {@link BaritoneUser#getMinecraft()}
|
||||
*/
|
||||
private final IThreadListener client;
|
||||
private final BotMinecraft client;
|
||||
|
||||
/**
|
||||
* The bot of this connection
|
||||
@@ -103,7 +99,7 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
||||
*/
|
||||
private BotPlayerController playerController;
|
||||
|
||||
public BotNetHandlerPlayClient(NetworkManager networkManager, BaritoneUser user, Minecraft client, GameProfile profile) {
|
||||
public BotNetHandlerPlayClient(NetworkManager networkManager, BaritoneUser user, BotMinecraft client, GameProfile profile) {
|
||||
// noinspection ConstantConditions
|
||||
super(client, null, networkManager, profile);
|
||||
this.networkManager = networkManager;
|
||||
@@ -357,7 +353,7 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
||||
|
||||
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.player = new EntityBot(this.user, 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);
|
||||
@@ -366,7 +362,7 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
||||
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.client.gameSettings.sendSettingsToServer();
|
||||
this.networkManager.sendPacket(new CPacketCustomPayload("MC|Brand", new PacketBuffer(Unpooled.buffer()).writeString("vanilla")));
|
||||
|
||||
this.world.registerBot(packetIn.getPlayerId(), this.player);
|
||||
@@ -477,7 +473,7 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
||||
|
||||
EntityBot prev = this.player;
|
||||
|
||||
this.player = new EntityBot(this.user, (Minecraft) this.client, this.world, this, prev.getStatFileWriter(), prev.getRecipeBook());
|
||||
this.player = new EntityBot(this.user, 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());
|
||||
|
||||
@@ -20,6 +20,7 @@ package baritone.bot.spec;
|
||||
import baritone.api.bot.IBaritoneUser;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.utils.ObjectAllocator;
|
||||
import baritone.utils.accessor.IGameSettings;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -27,9 +28,12 @@ import net.minecraft.client.main.GameConfiguration;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.client.tutorial.Tutorial;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.EnumHandSide;
|
||||
import net.minecraft.util.Session;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
@@ -41,14 +45,6 @@ import java.util.concurrent.Callable;
|
||||
*/
|
||||
public final class BotMinecraft extends Minecraft implements Helper {
|
||||
|
||||
private static final GameSettings BOT_GAME_SETTINGS;
|
||||
|
||||
static {
|
||||
BOT_GAME_SETTINGS = ObjectAllocator.allocate(GameSettings.class);
|
||||
BOT_GAME_SETTINGS.keyBindSprint = ObjectAllocator.allocate(KeyBinding.class);
|
||||
BOT_GAME_SETTINGS.autoJump = false;
|
||||
}
|
||||
|
||||
private IBaritoneUser user;
|
||||
private BotTutorial tutorial;
|
||||
|
||||
@@ -87,7 +83,29 @@ public final class BotMinecraft extends Minecraft implements Helper {
|
||||
BotMinecraft bm = ObjectAllocator.allocate(BotMinecraft.class);
|
||||
bm.user = user;
|
||||
bm.tutorial = new BotTutorial(bm);
|
||||
bm.gameSettings = BOT_GAME_SETTINGS;
|
||||
bm.gameSettings = createGameSettings(bm);
|
||||
return bm;
|
||||
}
|
||||
|
||||
private static GameSettings createGameSettings(BotMinecraft bm) {
|
||||
GameSettings settings = ObjectAllocator.allocate(GameSettings.class);
|
||||
|
||||
// Settings that get accessed on entity tick
|
||||
settings.keyBindSprint = ObjectAllocator.allocate(KeyBinding.class);
|
||||
settings.autoJump = false;
|
||||
|
||||
// Settings that are sent to the server
|
||||
settings.language = "en_us";
|
||||
settings.renderDistanceChunks = 8;
|
||||
settings.chatVisibility = EntityPlayer.EnumChatVisibility.FULL;
|
||||
settings.chatColours = true;
|
||||
settings.mainHand = EnumHandSide.RIGHT;
|
||||
|
||||
// Private fields that must be initialized
|
||||
IGameSettings accessor = (IGameSettings) settings;
|
||||
accessor.setMc(bm);
|
||||
accessor.setSetModelParts(new HashSet<>());
|
||||
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
|
||||
34
src/main/java/baritone/utils/accessor/IGameSettings.java
Normal file
34
src/main/java/baritone/utils/accessor/IGameSettings.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.Minecraft;
|
||||
import net.minecraft.entity.player.EnumPlayerModelParts;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 3/6/2020
|
||||
*/
|
||||
public interface IGameSettings {
|
||||
|
||||
void setSetModelParts(Set<EnumPlayerModelParts> setModelParts);
|
||||
|
||||
void setMc(Minecraft mc);
|
||||
}
|
||||
Reference in New Issue
Block a user