More handlers

This commit is contained in:
Brady
2018-11-07 12:23:28 -06:00
parent 7c92817801
commit 41c74cb08c
4 changed files with 74 additions and 5 deletions
+8 -1
View File
@@ -36,6 +36,7 @@ class BaritoneUser implements IBaritoneUser {
private final Session session;
private GameProfile profile;
private INetHandlerPlayClient netHandlerPlayClient;
BaritoneUser(UserManager manager, NetworkManager networkManager, Session session) {
this.manager = manager;
@@ -44,8 +45,9 @@ class BaritoneUser implements IBaritoneUser {
}
@Override
public void onLoginSuccess(GameProfile profile, INetHandlerPlayClient networkHandler) {
public void onLoginSuccess(GameProfile profile, INetHandlerPlayClient netHandlerPlayClient) {
this.profile = profile;
this.netHandlerPlayClient = netHandlerPlayClient;
}
@Override
@@ -53,6 +55,11 @@ class BaritoneUser implements IBaritoneUser {
return this.networkManager;
}
@Override
public INetHandlerPlayClient getConnection() {
return this.netHandlerPlayClient;
}
@Override
public EntityBot getEntity() {
// TODO
+12 -2
View File
@@ -19,6 +19,7 @@ package baritone.bot;
import baritone.bot.entity.EntityBot;
import com.mojang.authlib.GameProfile;
import net.minecraft.network.INetHandler;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.INetHandlerPlayClient;
import net.minecraft.util.Session;
@@ -33,15 +34,24 @@ public interface IBaritoneUser {
* Called when the user successfully logs into a server.
*
* @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.
*/
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.
*/
+7 -1
View File
@@ -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) {
this.users.remove(user);
}
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.client.*;
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.IThreadListener;
import net.minecraft.util.text.ITextComponent;
@@ -127,6 +130,28 @@ public 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;
}
}
}
}
@Override
@@ -152,6 +177,8 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
@Override
public void handleBlockChange(@Nonnull SPacketBlockChange packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
this.world.invalidateRegionAndSetBlock(packetIn.getBlockPosition(), packetIn.getBlockState());
}
@Override
@@ -165,6 +192,10 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
@Override
public void handleMultiBlockChange(@Nonnull SPacketMultiBlockChange packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
for (SPacketMultiBlockChange.BlockUpdateData data : packetIn.getChangedBlocks()) {
this.world.invalidateRegionAndSetBlock(data.getPos(), data.getBlockState());
}
}
@Override
@@ -452,6 +483,18 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
@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 potioneffect = new PotionEffect(potion, packetIn.getDuration(), packetIn.getAmplifier(), packetIn.getIsAmbient(), packetIn.doesShowParticles());
potioneffect.setPotionDurationMax(packetIn.isMaxDuration());
((EntityLivingBase) entity).addPotionEffect(potioneffect);
}
}
}
@Override
@@ -476,6 +519,8 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
@Override
public void handleWorldBorder(@Nonnull SPacketWorldBorder packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
packetIn.apply(this.world.getWorldBorder());
}
@Override
@@ -487,7 +532,8 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
@Override
public void handleResourcePack(@Nonnull SPacketResourcePackSend packetIn) {
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.SUCCESSFULLY_LOADED));
}