diff --git a/src/main/java/FarmHelper/FarmHelper.java b/src/main/java/FarmHelper/FarmHelper.java index a4a560fb..c8dd030f 100644 --- a/src/main/java/FarmHelper/FarmHelper.java +++ b/src/main/java/FarmHelper/FarmHelper.java @@ -10,8 +10,11 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiDisconnected; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.settings.KeyBinding; import net.minecraft.init.Blocks; +import net.minecraft.inventory.ContainerChest; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.network.play.client.C07PacketPlayerDigging; import net.minecraft.util.*; @@ -83,12 +86,15 @@ public class FarmHelper boolean set = false; //whether HAS CHANGED motion (1&2) boolean set3 = false; //same but motion 3 boolean rotating = false; + boolean full = false; double beforeX = 0; double beforeZ = 0; + double beforeY = 0; double deltaX = 10000; double deltaZ = 10000; + double deltaY = 0; double initialX = 0; double initialZ = 0; @@ -103,6 +109,7 @@ public class FarmHelper public int keybindW = mc.gameSettings.keyBindForward.getKeyCode(); public int keybindS = mc.gameSettings.keyBindBack.getKeyCode(); public int keybindAttack = mc.gameSettings.keyBindAttack.getKeyCode(); + public int keybindUseItem = mc.gameSettings.keyBindUseItem.getKeyCode(); static KeyBinding[] customKeyBinds = new KeyBinding[2]; @@ -110,7 +117,7 @@ public class FarmHelper static volatile int totalEnw = 0; static volatile int totalMoney = 0; static volatile int prevMoney = -999; - int cycles = 0; + static int cycles = 0; static volatile int moneyper10sec = 0; @@ -272,8 +279,6 @@ public void OnTickPlayer(TickEvent.ClientTickEvent event) { //Client -> player } Utils.hardRotate(playerYaw); - - } //INITIALIZE if (!locked) { @@ -296,7 +301,7 @@ public void OnTickPlayer(TickEvent.ClientTickEvent event) { //Client -> player } } - if(deltaX < 0.8d && deltaZ < 0.8d && !notInIsland && !emergency && !setAntiStuck && Config.FarmType.equals(FarmEnum.LAYERED)){ + if(deltaX < 0.8d && deltaZ < 0.8d && deltaY < 0.0001d && !notInIsland && !emergency && !setAntiStuck && Config.FarmType.equals(FarmEnum.LAYERED)){ mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "[Farm Helper] : " + EnumChatFormatting.DARK_GREEN + "Detected stuck")); @@ -304,7 +309,7 @@ public void OnTickPlayer(TickEvent.ClientTickEvent event) { //Client -> player process4 = true; ScheduleRunnable(stopAntistuck, 800, TimeUnit.MILLISECONDS); - }else if(deltaX < 0.0001d && deltaZ < 0.0001d && !notInIsland && !emergency && !setAntiStuck && Config.FarmType.equals(FarmEnum.VERTICAL)){ + }else if(deltaX < 0.0001d && deltaZ < 0.0001d && deltaY < 0.0001d && !notInIsland && !emergency && !setAntiStuck && Config.FarmType.equals(FarmEnum.VERTICAL)){ //tp pad fix deltaX = 10000; deltaZ = 10000; @@ -367,7 +372,16 @@ else if(!set3 && (mc.thePlayer.posZ != initialZ || mc.thePlayer.posX != initialX KeyBinding.setKeyBindState(keybindD, true); KeyBinding.setKeyBindState(keybindA, false); KeyBinding.setKeyBindState(keybindW, false); - if(!setspawned){mc.thePlayer.sendChatMessage("/setspawn"); setspawned = true; cycles++;} + if(!setspawned) + { + if(full && Config.autosell) + ExecuteRunnable(clearInventory); + else { + mc.thePlayer.sendChatMessage("/setspawn"); + setspawned = true; + cycles++; + } + } } } else if (process2 && !process3 && !process4) { @@ -395,8 +409,19 @@ else if(!set3 && (mc.thePlayer.posZ != initialZ || mc.thePlayer.posX != initialX } } - if(cycles == 4 && Config.resync) + + //resync + if(cycles == 4 && Config.resync && !full && !rotating) ExecuteRunnable(reSync); + else if(cycles == 4 && Config.resync) + cycles = 0; + + + //autoSell + if(mc.thePlayer.inventory.getFirstEmptyStack() == -1 && !rotating) + full = true; + + } else{ locked = false; @@ -409,9 +434,59 @@ else if(!set3 && (mc.thePlayer.posZ != initialZ || mc.thePlayer.posX != initialX //multi-threads + + Runnable clearInventory = new Runnable() { + @Override + public void run() { + try { + stop(); + enabled = false; + mc.thePlayer.inventory.currentItem = 8; + mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + + "[Farm Helper] : " + EnumChatFormatting.DARK_GREEN + "Activating autosell")); + Thread.sleep(500); + KeyBinding.onTick(keybindUseItem); + Thread.sleep(1000); + clickWindow(mc.thePlayer.openContainer.windowId, 22, 0, 0); + Thread.sleep(600); + if(mc.thePlayer.openContainer.getSlot(49).getStack().getItem() == Item.getItemFromBlock(Blocks.barrier)) { + mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + + "[Farm Helper] : " + EnumChatFormatting.DARK_GREEN + "You didn't eat cookie!")); + Config.autosell = false; + throw new Exception(); + } + Thread.sleep(400); + while(Utils.hasEnchatedCarrotInInv()) { + clickWindow(mc.thePlayer.openContainer.windowId, 45 + Utils.getFirstSlotWithEnchantedCarrot(), 0, 0); + Thread.sleep(500 + Utils.nextInt(100)); + } + Thread.sleep(400); + mc.thePlayer.closeScreen(); + full = false; + Thread.sleep(800); + enabled = true; + + }catch(Exception e) { + try { + Thread.sleep(500); + mc.thePlayer.closeScreen(); + Thread.sleep(800); + enabled = true; + full = false; + } catch(Exception e2){ + e2.printStackTrace(); + } + } + } + }; Runnable reSync = new Runnable() { @Override public void run() { + if(full||rotating) { + cycles = 0; + return; + } + cycles = 0; mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "[Farm Helper] : " + EnumChatFormatting.DARK_GREEN + "Resyncing.. ")); @@ -426,9 +501,11 @@ public void run() { if(!notInIsland && !emergency && enabled) { deltaX = Math.abs(mc.thePlayer.posX - beforeX); deltaZ = Math.abs(mc.thePlayer.posZ - beforeZ); + deltaY = Math.abs(mc.thePlayer.posY - beforeY); beforeX = mc.thePlayer.posX; beforeZ = mc.thePlayer.posZ; + beforeY = mc.thePlayer.posY; ScheduleRunnable(checkChange, 3, TimeUnit.SECONDS); @@ -445,13 +522,12 @@ public void run() { stop(); rotating = true; enabled = false; - Thread.sleep(500); + Thread.sleep(1000); Config.Angle = Config.Angle.ordinal() < 2 ? AngleEnum.values()[Config.Angle.ordinal() + 2] : AngleEnum.values()[Config.Angle.ordinal() - 2]; playerYaw = angleToValue(Config.Angle); - Utils.hardRotate(playerYaw); - Thread.sleep(500); + Utils.smoothRotateClockwise(180); + Thread.sleep(2000); rotating = false; - enabled = true; }catch(Exception e){ e.printStackTrace(); @@ -677,15 +753,28 @@ void ExecuteRunnable(Runnable r){ eTemp.execute(r); eTemp.shutdown(); } + + void clickWindow(int windowID, int slotID, int mouseButtonClicked, int mode) throws Exception{ + Minecraft mc = Minecraft.getMinecraft(); + if(mc.thePlayer.openContainer instanceof ContainerChest || mc.currentScreen instanceof GuiInventory) + mc.playerController.windowClick(windowID, slotID, mouseButtonClicked, mode, mc.thePlayer); + else { + mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + + "[Farm Helper] : " + EnumChatFormatting.DARK_GREEN + "Didn't open window! Autosell failed")); + throw new Exception(); + } + } void initialize(){ deltaX = 10000; deltaZ = 10000; + deltaY = 0; process1 = true; process2 = false; process3 = false; process4 = false; + setspawned = false; shdBePressingKey = true; notInIsland = false; beforeX = mc.thePlayer.posX; @@ -696,6 +785,7 @@ void initialize(){ set3 = false; cycles = 0; rotating = false; + full = false; } int angleToValue(AngleEnum c){ return !c.toString().replace("A", "").contains("N") ? diff --git a/src/main/java/FarmHelper/GUI/GUI.java b/src/main/java/FarmHelper/GUI/GUI.java index f50eab97..8a6d9006 100644 --- a/src/main/java/FarmHelper/GUI/GUI.java +++ b/src/main/java/FarmHelper/GUI/GUI.java @@ -21,7 +21,7 @@ import java.io.IOException; import java.io.Serializable; -public class GUI extends GuiScreen implements Serializable { +public class GUI extends GuiScreen{ int buttonWidth = 85; diff --git a/src/main/java/FarmHelper/GUI/GuiSettings.java b/src/main/java/FarmHelper/GUI/GuiSettings.java index 0783f6e2..cc65d930 100644 --- a/src/main/java/FarmHelper/GUI/GuiSettings.java +++ b/src/main/java/FarmHelper/GUI/GuiSettings.java @@ -35,7 +35,7 @@ public void initGui() { this.buttonList.add(new GuiCustomSwitchButton(1, this.width/2 + 120, this.height/2 - 10, 40, 15, 30, "Inventory price calculator")); this.buttonList.add(new GuiCustomSwitchButton(2, this.width/2 + 120, this.height/2 + 30, 40, 15, 30, "Profit calculator")); this.buttonList.add(new GuiCustomSwitchButton(3, this.width/2 + 120, this.height/2 + 70, 40, 15, 30, "Auto resync")); - //this.buttonList.add(new GuiCustomSwitchButton(4, this.width/2 + 120, this.height/2 + 110, 40, 15, 30, "Fastbreak")); + this.buttonList.add(new GuiCustomSwitchButton(4, this.width/2 + 120, this.height/2 + 110, 40, 15, 30, "Autosell (make sure you have cookies on!!)")); initialSelect(); } @@ -84,12 +84,12 @@ protected void actionPerformed(GuiButton button) throws IOException { updateScreen(); Config.writeConfig(); } - /*if(button.id == 4){ + if(button.id == 4){ GuiCustomSwitchButton temp = (GuiCustomSwitchButton) button; temp.switchSelect(); - Config.fastbreak = !Config.fastbreak; + Config.autosell = !Config.autosell; updateScreen(); - }*/ + } } @@ -111,10 +111,10 @@ void initialSelect(){ GuiCustomSwitchButton temp = (GuiCustomSwitchButton) this.buttonList.get(3); temp.switchSelect(); } - /* if(Config.fastbreak) { + if(Config.autosell) { GuiCustomSwitchButton temp = (GuiCustomSwitchButton) this.buttonList.get(4); temp.switchSelect(); - }*/ + } } diff --git a/src/main/java/FarmHelper/Utils/Utils.java b/src/main/java/FarmHelper/Utils/Utils.java index 98c272f5..238a3691 100644 --- a/src/main/java/FarmHelper/Utils/Utils.java +++ b/src/main/java/FarmHelper/Utils/Utils.java @@ -6,7 +6,15 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.init.Blocks; +import net.minecraft.inventory.ContainerChest; +import net.minecraft.inventory.Slot; +import net.minecraft.item.Item; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; import org.lwjgl.opengl.GL11; import scala.sys.process.ProcessBuilderImpl; @@ -38,7 +46,39 @@ public static void hardRotate(float yaw) { } } + public static boolean hasEnchatedCarrotInInv(){ + for(Slot slot : Minecraft.getMinecraft().thePlayer.inventoryContainer.inventorySlots) { + if (slot != null) { + try { + if (slot.getStack().getDisplayName().contains("Enchanted Carrot")) { + return true; + } + }catch(Exception e){ + + } + } + } + return false; + } + + public static int getFirstSlotWithEnchantedCarrot() { + for (Slot slot : Minecraft.getMinecraft().thePlayer.inventoryContainer.inventorySlots) { + if (slot != null) { + if (slot.getStack() != null) { + try { + if (slot.getStack().getDisplayName().contains("Enchanted Carrot")) + return slot.slotNumber; + }catch(Exception e){ + + } + } + } + + } + return 0; + + } @@ -77,19 +117,19 @@ static int getOppositeAngle(int angle){ static boolean shouldRotateClockwise(int currentAngle, int boundAngle){ return false; } - public static void rotateTo(final int rotation360){ + public static void smoothRotateTo(final int rotation360){ new Thread(new Runnable() { @Override public void run() { - boolean clockwise = shouldRotateClockwise((int) get360RotationYaw(), getOppositeAngle(rotation360)); + while (get360RotationYaw() != rotation360) { - if(Math.abs(rotation360 - get360RotationYaw()) < 2) { - Minecraft.getMinecraft().thePlayer.rotationYaw = (int)(Minecraft.getMinecraft().thePlayer.rotationYaw + (rotation360 - get360RotationYaw())); - break; + if(Math.abs(get360RotationYaw() - rotation360) < 1f) { + Minecraft.getMinecraft().thePlayer.rotationYaw = Math.round(Minecraft.getMinecraft().thePlayer.rotationYaw + Math.abs(get360RotationYaw() - rotation360)); + return; } - Minecraft.getMinecraft().thePlayer.rotationYaw += 0.5f + nextInt(6)/10.0; + Minecraft.getMinecraft().thePlayer.rotationYaw += 0.3f + nextInt(3)/10.0f; try { - Thread.sleep(2); + Thread.sleep(1); } catch (Exception e) { e.printStackTrace(); } @@ -98,20 +138,20 @@ public void run() { }).start(); } - public static void rotateClockwise(final int rotationClockwise){ + public static void smoothRotateClockwise(final int rotationClockwise360){ new Thread(new Runnable() { @Override public void run() { - int initialYaw = (int)Minecraft.getMinecraft().thePlayer.rotationYaw; - while (Minecraft.getMinecraft().thePlayer.rotationYaw != initialYaw + rotationClockwise) { - if(Math.abs(Minecraft.getMinecraft().thePlayer.rotationYaw - initialYaw + rotationClockwise) < 2) { - Minecraft.getMinecraft().thePlayer.rotationYaw = (int)(Minecraft.getMinecraft().thePlayer.rotationYaw + rotationClockwise); - break; - } - Minecraft.getMinecraft().thePlayer.rotationYaw += 0.1f + nextInt(5)/5.0; + int targetYaw = (Math.round(get360RotationYaw()) + rotationClockwise360) % 360; + while (get360RotationYaw() != targetYaw) { + if(Math.abs(get360RotationYaw() - targetYaw) < 1f) { + Minecraft.getMinecraft().thePlayer.rotationYaw = Math.round(Minecraft.getMinecraft().thePlayer.rotationYaw + Math.abs(get360RotationYaw() - targetYaw)); + return; + } + Minecraft.getMinecraft().thePlayer.rotationYaw += 0.3f + nextInt(3)/10.0f; try { - Thread.sleep(2); + Thread.sleep(1); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/FarmHelper/config/Config.java b/src/main/java/FarmHelper/config/Config.java index 06074287..d64e82a7 100644 --- a/src/main/java/FarmHelper/config/Config.java +++ b/src/main/java/FarmHelper/config/Config.java @@ -13,11 +13,12 @@ public class Config{ public static boolean inventoryPriceCalculator = false; public static boolean profitCalculator = false; public static boolean resync = false; + public static boolean autosell = false; public static AngleEnum Angle = AngleEnum.A0; public static void setConfig(CropEnum crop, FarmEnum farm, boolean rotateAfterTeleport, - boolean inventoryPriceCalculator, boolean profitCalculator, boolean resync){ + boolean inventoryPriceCalculator, boolean profitCalculator, boolean resync, boolean autosell){ CropType = crop; FarmType = farm; Config.rotateAfterTeleport = rotateAfterTeleport; @@ -34,6 +35,7 @@ public static void writeConfig(){ bufferedWriter.write("\n" + inventoryPriceCalculator); bufferedWriter.write("\n" + profitCalculator); bufferedWriter.write("\n" + resync); + bufferedWriter.write("\n" + autosell); bufferedWriter.close(); }catch(Exception e){ e.printStackTrace(); @@ -49,6 +51,7 @@ public static void readConfig () throws Exception { Boolean.parseBoolean(bufferedReader.readLine()), Boolean.parseBoolean(bufferedReader.readLine()), Boolean.parseBoolean(bufferedReader.readLine()), + Boolean.parseBoolean(bufferedReader.readLine()), Boolean.parseBoolean(bufferedReader.readLine())); bufferedReader.close();