More handlers
This commit is contained in:
@@ -36,6 +36,7 @@ class BaritoneUser implements IBaritoneUser {
|
|||||||
private final Session session;
|
private final Session session;
|
||||||
|
|
||||||
private GameProfile profile;
|
private GameProfile profile;
|
||||||
|
private INetHandlerPlayClient netHandlerPlayClient;
|
||||||
|
|
||||||
BaritoneUser(UserManager manager, NetworkManager networkManager, Session session) {
|
BaritoneUser(UserManager manager, NetworkManager networkManager, Session session) {
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
@@ -44,8 +45,9 @@ class BaritoneUser implements IBaritoneUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoginSuccess(GameProfile profile, INetHandlerPlayClient networkHandler) {
|
public void onLoginSuccess(GameProfile profile, INetHandlerPlayClient netHandlerPlayClient) {
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
|
this.netHandlerPlayClient = netHandlerPlayClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -53,6 +55,11 @@ class BaritoneUser implements IBaritoneUser {
|
|||||||
return this.networkManager;
|
return this.networkManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public INetHandlerPlayClient getConnection() {
|
||||||
|
return this.netHandlerPlayClient;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityBot getEntity() {
|
public EntityBot getEntity() {
|
||||||
// TODO
|
// TODO
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package baritone.bot;
|
|||||||
|
|
||||||
import baritone.bot.entity.EntityBot;
|
import baritone.bot.entity.EntityBot;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import net.minecraft.network.INetHandler;
|
||||||
import net.minecraft.network.NetworkManager;
|
import net.minecraft.network.NetworkManager;
|
||||||
import net.minecraft.network.play.INetHandlerPlayClient;
|
import net.minecraft.network.play.INetHandlerPlayClient;
|
||||||
import net.minecraft.util.Session;
|
import net.minecraft.util.Session;
|
||||||
@@ -33,15 +34,24 @@ public interface IBaritoneUser {
|
|||||||
* Called when the user successfully logs into a server.
|
* Called when the user successfully logs into a server.
|
||||||
*
|
*
|
||||||
* @param profile The game profile returned by the server on login
|
* @param profile The game profile returned by the server on login
|
||||||
* @param networkHandler The client play network handler
|
* @param netHandlerPlayClient The client play network handler
|
||||||
*/
|
*/
|
||||||
void onLoginSuccess(GameProfile profile, INetHandlerPlayClient networkHandler);
|
void onLoginSuccess(GameProfile profile, INetHandlerPlayClient netHandlerPlayClient);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The network manager that is responsible for the current connection.
|
* @return The network manager that is responsible for the current connection.
|
||||||
*/
|
*/
|
||||||
NetworkManager getNetworkManager();
|
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.
|
* @return The locally managed entity for this user.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -105,8 +105,14 @@ public final class UserManager implements Helper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies the manager of an {@link IBaritoneUser} disconnect
|
||||||
|
*
|
||||||
|
* @param user The user that disconnected
|
||||||
|
* @param state The connection state at the time of disconnect
|
||||||
|
*/
|
||||||
public final void notifyDisconnect(IBaritoneUser user, EnumConnectionState state) {
|
public final void notifyDisconnect(IBaritoneUser user, EnumConnectionState state) {
|
||||||
|
this.users.remove(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Optional<IBaritoneUser> getUserByProfile(GameProfile profile) {
|
public final Optional<IBaritoneUser> getUserByProfile(GameProfile profile) {
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ import net.minecraft.network.PacketThreadUtil;
|
|||||||
import net.minecraft.network.play.INetHandlerPlayClient;
|
import net.minecraft.network.play.INetHandlerPlayClient;
|
||||||
import net.minecraft.network.play.client.*;
|
import net.minecraft.network.play.client.*;
|
||||||
import net.minecraft.network.play.server.*;
|
import net.minecraft.network.play.server.*;
|
||||||
|
import net.minecraft.potion.Potion;
|
||||||
|
import net.minecraft.potion.PotionEffect;
|
||||||
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.EnumHandSide;
|
import net.minecraft.util.EnumHandSide;
|
||||||
import net.minecraft.util.IThreadListener;
|
import net.minecraft.util.IThreadListener;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
@@ -127,6 +130,28 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
|||||||
@Override
|
@Override
|
||||||
public void handleAnimation(@Nonnull SPacketAnimation packetIn) {
|
public void handleAnimation(@Nonnull SPacketAnimation packetIn) {
|
||||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
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
|
@Override
|
||||||
@@ -152,6 +177,8 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
|||||||
@Override
|
@Override
|
||||||
public void handleBlockChange(@Nonnull SPacketBlockChange packetIn) {
|
public void handleBlockChange(@Nonnull SPacketBlockChange packetIn) {
|
||||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||||
|
|
||||||
|
this.world.invalidateRegionAndSetBlock(packetIn.getBlockPosition(), packetIn.getBlockState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -165,6 +192,10 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
|||||||
@Override
|
@Override
|
||||||
public void handleMultiBlockChange(@Nonnull SPacketMultiBlockChange packetIn) {
|
public void handleMultiBlockChange(@Nonnull SPacketMultiBlockChange packetIn) {
|
||||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||||
|
|
||||||
|
for (SPacketMultiBlockChange.BlockUpdateData data : packetIn.getChangedBlocks()) {
|
||||||
|
this.world.invalidateRegionAndSetBlock(data.getPos(), data.getBlockState());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -452,6 +483,18 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
|||||||
@Override
|
@Override
|
||||||
public void handleEntityEffect(@Nonnull SPacketEntityEffect packetIn) {
|
public void handleEntityEffect(@Nonnull SPacketEntityEffect packetIn) {
|
||||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
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 potioneffect = new PotionEffect(potion, packetIn.getDuration(), packetIn.getAmplifier(), packetIn.getIsAmbient(), packetIn.doesShowParticles());
|
||||||
|
potioneffect.setPotionDurationMax(packetIn.isMaxDuration());
|
||||||
|
((EntityLivingBase) entity).addPotionEffect(potioneffect);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -476,6 +519,8 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
|||||||
@Override
|
@Override
|
||||||
public void handleWorldBorder(@Nonnull SPacketWorldBorder packetIn) {
|
public void handleWorldBorder(@Nonnull SPacketWorldBorder packetIn) {
|
||||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||||
|
|
||||||
|
packetIn.apply(this.world.getWorldBorder());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -487,7 +532,8 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
|||||||
@Override
|
@Override
|
||||||
public void handleResourcePack(@Nonnull SPacketResourcePackSend packetIn) {
|
public void handleResourcePack(@Nonnull SPacketResourcePackSend packetIn) {
|
||||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||||
/* Lie to the server and tell them we did it in response */
|
|
||||||
|
// 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.ACCEPTED));
|
||||||
this.networkManager.sendPacket(new CPacketResourcePackStatus(CPacketResourcePackStatus.Action.SUCCESSFULLY_LOADED));
|
this.networkManager.sendPacket(new CPacketResourcePackStatus(CPacketResourcePackStatus.Action.SUCCESSFULLY_LOADED));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user