More NetHandlerPlayClient utilization
This commit is contained in:
@@ -21,6 +21,7 @@ import baritone.api.IBaritone;
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.network.INetHandler;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.INetHandlerPlayClient;
|
||||
@@ -56,6 +57,11 @@ public interface IBaritoneUser {
|
||||
*/
|
||||
EntityPlayerSP getEntity();
|
||||
|
||||
/**
|
||||
* @return The world the user belongs to
|
||||
*/
|
||||
WorldClient getWorld();
|
||||
|
||||
/**
|
||||
* @return The bot player controller
|
||||
*/
|
||||
|
||||
@@ -30,6 +30,7 @@ import baritone.utils.player.WrappedPlayerController;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.INetHandlerPlayClient;
|
||||
import net.minecraft.util.Session;
|
||||
@@ -74,7 +75,7 @@ public final class BaritoneUser implements IBaritoneUser {
|
||||
this.baritone.getGameEventHandler().onWorldEvent(new WorldEvent(world, EventState.PRE));
|
||||
|
||||
this.mc.player = this.player = player;
|
||||
this.player.world = this.mc.world = this.world = world;
|
||||
this.mc.world = this.world = world;
|
||||
this.playerController = new WrappedPlayerController(controller);
|
||||
|
||||
this.baritone.getGameEventHandler().onWorldEvent(new WorldEvent(world, EventState.POST));
|
||||
@@ -95,6 +96,11 @@ public final class BaritoneUser implements IBaritoneUser {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldClient getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPlayerController getPlayerController() {
|
||||
return this.playerController;
|
||||
|
||||
@@ -53,10 +53,7 @@ public final class BotPlayerContext implements IPlayerContext {
|
||||
|
||||
@Override
|
||||
public World world() {
|
||||
if (bot.getEntity() == null) {
|
||||
return null;
|
||||
}
|
||||
return bot.getEntity().world;
|
||||
return bot.getWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,20 +29,14 @@ import io.netty.buffer.Unpooled;
|
||||
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.PlayerCapabilities;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.PacketThreadUtil;
|
||||
import net.minecraft.network.play.client.*;
|
||||
import net.minecraft.network.play.server.*;
|
||||
import net.minecraft.stats.StatisticsManager;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.Explosion;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -100,7 +94,7 @@ public final class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
||||
|
||||
@Override
|
||||
public void handleSpawnObject(@Nonnull SPacketSpawnObject packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
super.handleSpawnObject(packetIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -127,29 +121,7 @@ public final class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
super.handleAnimation(packetIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -218,28 +190,7 @@ public final class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.handleSetSlot(packetIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -274,13 +225,7 @@ public final class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
||||
|
||||
@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 += packetIn.getMotionX();
|
||||
this.player.motionY += packetIn.getMotionY();
|
||||
this.player.motionZ += packetIn.getMotionZ();
|
||||
super.handleExplosion(packetIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -338,48 +283,7 @@ public final class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
||||
|
||||
@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;
|
||||
super.handlePlayerPosLook(packetIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -80,6 +80,7 @@ public final class BotMinecraft extends Minecraft implements Helper {
|
||||
return this.tutorial;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SoundHandler getSoundHandler() {
|
||||
return BotSoundHandler.INSTANCE;
|
||||
@@ -90,6 +91,7 @@ public final class BotMinecraft extends Minecraft implements Helper {
|
||||
bm.user = user;
|
||||
bm.tutorial = new Tutorial(bm);
|
||||
bm.gameSettings = createGameSettings(bm);
|
||||
bm.effectRenderer = BotParticleManager.INSTANCE;
|
||||
return bm;
|
||||
}
|
||||
|
||||
|
||||
43
src/main/java/baritone/bot/spec/BotParticleManager.java
Normal file
43
src/main/java/baritone/bot/spec/BotParticleManager.java
Normal file
@@ -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.bot.spec;
|
||||
|
||||
import net.minecraft.client.particle.ParticleManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 3/8/2020
|
||||
*/
|
||||
public final class BotParticleManager extends ParticleManager {
|
||||
|
||||
public static final BotParticleManager INSTANCE = new BotParticleManager();
|
||||
|
||||
private BotParticleManager() {
|
||||
super(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitParticleAtEntity(Entity entityIn, @Nonnull EnumParticleTypes particleTypes) {}
|
||||
|
||||
@Override
|
||||
public void emitParticleAtEntity(Entity p_191271_1_, @Nonnull EnumParticleTypes p_191271_2_, int p_191271_3_) {}
|
||||
}
|
||||
@@ -30,10 +30,10 @@ import javax.annotation.Nonnull;
|
||||
*/
|
||||
public final class BotSoundHandler extends SoundHandler {
|
||||
|
||||
public static final BotSoundHandler INSTANCE = new BotSoundHandler(null, null);
|
||||
public static final BotSoundHandler INSTANCE = new BotSoundHandler();
|
||||
|
||||
public BotSoundHandler(IResourceManager manager, GameSettings gameSettingsIn) {
|
||||
super(manager, gameSettingsIn);
|
||||
private BotSoundHandler() {
|
||||
super(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -71,32 +71,32 @@ public final class EntityBot extends EntityPlayerSP {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStatusMessage(ITextComponent chatComponent, boolean actionBar) {
|
||||
public void sendStatusMessage(@Nonnull ITextComponent chatComponent, boolean actionBar) {
|
||||
// TODO: Custom message handling
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(ITextComponent component) {
|
||||
public void sendMessage(@Nonnull ITextComponent component) {
|
||||
// TODO: Custom message handling
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openEditSign(TileEntitySign signTile) {
|
||||
public void openEditSign(@Nonnull TileEntitySign signTile) {
|
||||
// TODO: Custom GUI handling
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayGuiEditCommandCart(CommandBlockBaseLogic commandBlock) {
|
||||
public void displayGuiEditCommandCart(@Nonnull CommandBlockBaseLogic commandBlock) {
|
||||
// TODO: Custom GUI handling
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayGuiCommandBlock(TileEntityCommandBlock commandBlock) {
|
||||
public void displayGuiCommandBlock(@Nonnull TileEntityCommandBlock commandBlock) {
|
||||
// TODO: Custom GUI handling
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openEditStructure(TileEntityStructure structure) {
|
||||
public void openEditStructure(@Nonnull TileEntityStructure structure) {
|
||||
// TODO: Custom GUI handling
|
||||
}
|
||||
|
||||
@@ -106,12 +106,12 @@ public final class EntityBot extends EntityPlayerSP {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayGUIChest(IInventory chestInventory) {
|
||||
public void displayGUIChest(@Nonnull IInventory chestInventory) {
|
||||
// TODO: Custom GUI handling
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openGuiHorseInventory(AbstractHorse horse, IInventory inventoryIn) {
|
||||
public void openGuiHorseInventory(@Nonnull AbstractHorse horse, IInventory inventoryIn) {
|
||||
// TODO: Custom GUI handling
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user