Remove dependency for PlayerControllerMP implementation
This commit is contained in:
@@ -20,7 +20,6 @@ package baritone.api.utils;
|
||||
import baritone.api.cache.IWorldData;
|
||||
import net.minecraft.block.BlockSlab;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
@@ -37,7 +36,7 @@ public interface IPlayerContext {
|
||||
|
||||
EntityPlayerSP player();
|
||||
|
||||
PlayerControllerMP playerController();
|
||||
IPlayerController playerController();
|
||||
|
||||
World world();
|
||||
|
||||
|
||||
@@ -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.api.utils;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.GameType;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 12/14/2018
|
||||
*/
|
||||
public interface IPlayerController {
|
||||
|
||||
boolean clickBlock(BlockPos pos, EnumFacing side);
|
||||
|
||||
boolean onPlayerDamageBlock(BlockPos pos, EnumFacing side);
|
||||
|
||||
void resetBlockRemoving();
|
||||
|
||||
void setGameType(GameType type);
|
||||
|
||||
GameType getGameType();
|
||||
|
||||
default double getBlockReachDistance() {
|
||||
return this.getGameType().isCreative() ? 5.0F : 4.5F;
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ package baritone.bot;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.bot.spec.BotPlayerController;
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import baritone.bot.spec.BotWorld;
|
||||
import baritone.bot.spec.EntityBot;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
@@ -44,7 +44,7 @@ class BaritoneUser implements IBaritoneUser {
|
||||
|
||||
private BotWorld world;
|
||||
private EntityBot player;
|
||||
private BotPlayerController playerController;
|
||||
private IPlayerController playerController;
|
||||
|
||||
private final Baritone baritone;
|
||||
|
||||
@@ -57,14 +57,14 @@ class BaritoneUser implements IBaritoneUser {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorldLoad(BotWorld world, EntityBot player, BotPlayerController playerController) {
|
||||
public void onWorldLoad(BotWorld world, EntityBot player, IPlayerController playerController) {
|
||||
this.world = world;
|
||||
this.player = player;
|
||||
this.playerController = playerController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BotPlayerController getPlayerController() {
|
||||
public IPlayerController getPlayerController() {
|
||||
return this.playerController;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ package baritone.bot;
|
||||
|
||||
import baritone.api.cache.IWorldData;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -45,7 +45,7 @@ public class BotPlayerContext implements IPlayerContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerControllerMP playerController() {
|
||||
public IPlayerController playerController() {
|
||||
if (bot.getEntity() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package baritone.bot;
|
||||
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import baritone.bot.spec.BotPlayerController;
|
||||
import baritone.bot.spec.BotWorld;
|
||||
import baritone.bot.spec.EntityBot;
|
||||
@@ -48,7 +49,7 @@ public interface IBaritoneUser {
|
||||
* @param player The player object
|
||||
* @param playerController The player controller
|
||||
*/
|
||||
void onWorldLoad(BotWorld world, EntityBot player, BotPlayerController playerController);
|
||||
void onWorldLoad(BotWorld world, EntityBot player, IPlayerController playerController);
|
||||
|
||||
/**
|
||||
* @return The network manager that is responsible for the current connection.
|
||||
@@ -72,7 +73,7 @@ public interface IBaritoneUser {
|
||||
/**
|
||||
* @return The bot player controller
|
||||
*/
|
||||
BotPlayerController getPlayerController();
|
||||
IPlayerController getPlayerController();
|
||||
|
||||
/**
|
||||
* Returns the user login session. Should never be {@code null}, as this should be set when the
|
||||
|
||||
@@ -355,7 +355,7 @@ public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
|
||||
public void handleJoinGame(@Nonnull SPacketJoinGame packetIn) {
|
||||
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
|
||||
|
||||
this.playerController = new BotPlayerController((Minecraft) this.client, this);
|
||||
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.preparePlayerToSpawn();
|
||||
|
||||
@@ -17,203 +17,48 @@
|
||||
|
||||
package baritone.bot.spec;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ClickType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.stats.RecipeBook;
|
||||
import net.minecraft.stats.StatisticsManager;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import baritone.bot.IBaritoneUser;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.GameType;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 11/14/2018
|
||||
*/
|
||||
public class BotPlayerController extends PlayerControllerMP {
|
||||
public class BotPlayerController implements IPlayerController {
|
||||
|
||||
public BotPlayerController(Minecraft mcIn, NetHandlerPlayClient netHandler) {
|
||||
super(mcIn, netHandler);
|
||||
private final IBaritoneUser user;
|
||||
private GameType gameType;
|
||||
|
||||
public BotPlayerController(IBaritoneUser user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerCapabilities(EntityPlayer player) {
|
||||
super.setPlayerCapabilities(player);
|
||||
public boolean clickBlock(BlockPos pos, EnumFacing side) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpectator() {
|
||||
return super.isSpectator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGameType(@Nonnull GameType type) {
|
||||
super.setGameType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flipPlayer(EntityPlayer playerIn) {
|
||||
super.flipPlayer(playerIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldDrawHUD() {
|
||||
return super.shouldDrawHUD();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPlayerDestroyBlock(@Nonnull BlockPos pos) {
|
||||
return super.onPlayerDestroyBlock(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clickBlock(@Nonnull BlockPos loc, @Nonnull EnumFacing face) {
|
||||
return super.clickBlock(loc, face);
|
||||
public boolean onPlayerDamageBlock(BlockPos pos, EnumFacing side) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetBlockRemoving() {
|
||||
super.resetBlockRemoving();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPlayerDamageBlock(@Nonnull BlockPos posBlock, @Nonnull EnumFacing directionFacing) {
|
||||
return super.onPlayerDamageBlock(posBlock, directionFacing);
|
||||
public void setGameType(GameType type) {
|
||||
this.gameType = type;
|
||||
this.gameType.configurePlayerCapabilities(this.user.getEntity().capabilities);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getBlockReachDistance() {
|
||||
return super.getBlockReachDistance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateController() {
|
||||
super.updateController();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public EnumActionResult processRightClickBlock(EntityPlayerSP player, @Nonnull WorldClient worldIn, BlockPos pos, @Nonnull EnumFacing direction, Vec3d vec, @Nonnull EnumHand hand) {
|
||||
return super.processRightClickBlock(player, worldIn, pos, direction, vec, hand);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public EnumActionResult processRightClick(@Nonnull EntityPlayer player, @Nonnull World worldIn, @Nonnull EnumHand hand) {
|
||||
return super.processRightClick(player, worldIn, hand);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public EntityPlayerSP createPlayer(World p_192830_1_, @Nonnull StatisticsManager p_192830_2_, @Nonnull RecipeBook p_192830_3_) {
|
||||
return super.createPlayer(p_192830_1_, p_192830_2_, p_192830_3_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attackEntity(@Nonnull EntityPlayer playerIn, Entity targetEntity) {
|
||||
super.attackEntity(playerIn, targetEntity);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public EnumActionResult interactWithEntity(@Nonnull EntityPlayer player, Entity target, @Nonnull EnumHand hand) {
|
||||
return super.interactWithEntity(player, target, hand);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public EnumActionResult interactWithEntity(@Nonnull EntityPlayer player, Entity target, RayTraceResult ray, @Nonnull EnumHand hand) {
|
||||
return super.interactWithEntity(player, target, ray, hand);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack windowClick(int windowId, int slotId, int mouseButton, @Nonnull ClickType type, EntityPlayer player) {
|
||||
return super.windowClick(windowId, slotId, mouseButton, type, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void func_194338_a(int p_194338_1_, @Nonnull IRecipe p_194338_2_, boolean p_194338_3_, EntityPlayer p_194338_4_) {
|
||||
super.func_194338_a(p_194338_1_, p_194338_2_, p_194338_3_, p_194338_4_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendEnchantPacket(int windowID, int button) {
|
||||
super.sendEnchantPacket(windowID, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSlotPacket(@Nonnull ItemStack itemStackIn, int slotId) {
|
||||
super.sendSlotPacket(itemStackIn, slotId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacketDropItem(@Nonnull ItemStack itemStackIn) {
|
||||
super.sendPacketDropItem(itemStackIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStoppedUsingItem(EntityPlayer playerIn) {
|
||||
super.onStoppedUsingItem(playerIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean gameIsSurvivalOrAdventure() {
|
||||
return super.gameIsSurvivalOrAdventure();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNotCreative() {
|
||||
return super.isNotCreative();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInCreativeMode() {
|
||||
return super.isInCreativeMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean extendedReach() {
|
||||
return super.extendedReach();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRidingHorse() {
|
||||
return super.isRidingHorse();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpectatorMode() {
|
||||
return super.isSpectatorMode();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public GameType getCurrentGameType() {
|
||||
return super.getCurrentGameType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIsHittingBlock() {
|
||||
return super.getIsHittingBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pickItem(int index) {
|
||||
super.pickItem(index);
|
||||
public GameType getGameType() {
|
||||
return this.gameType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package baritone.utils.player;
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.cache.IWorldData;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import baritone.utils.Helper;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
@@ -42,8 +43,8 @@ public enum PrimaryPlayerContext implements IPlayerContext, Helper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerControllerMP playerController() {
|
||||
return mc.playerController;
|
||||
public IPlayerController playerController() {
|
||||
return PrimaryPlayerController.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.player;
|
||||
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import baritone.utils.Helper;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.GameType;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 12/14/2018
|
||||
*/
|
||||
public enum PrimaryPlayerController implements IPlayerController, Helper {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public boolean clickBlock(BlockPos pos, EnumFacing side) {
|
||||
return mc.playerController.clickBlock(pos, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPlayerDamageBlock(BlockPos pos, EnumFacing side) {
|
||||
return mc.playerController.onPlayerDamageBlock(pos, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetBlockRemoving() {
|
||||
mc.playerController.resetBlockRemoving();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGameType(GameType type) {
|
||||
mc.playerController.setGameType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameType getGameType() {
|
||||
return mc.playerController.getCurrentGameType();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user