Skip to content

Commit 851a3ec

Browse files
committed
new
1 parent 5a62d14 commit 851a3ec

File tree

5 files changed

+168
-35
lines changed

5 files changed

+168
-35
lines changed

src/main/java/FarmHelper/FarmHelper.java

Lines changed: 101 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
import net.minecraft.client.Minecraft;
1111
import net.minecraft.client.gui.GuiDisconnected;
1212
import net.minecraft.client.gui.GuiScreen;
13+
import net.minecraft.client.gui.inventory.GuiInventory;
1314
import net.minecraft.client.settings.KeyBinding;
1415
import net.minecraft.init.Blocks;
16+
import net.minecraft.inventory.ContainerChest;
17+
import net.minecraft.item.Item;
1518
import net.minecraft.item.ItemStack;
1619
import net.minecraft.network.play.client.C07PacketPlayerDigging;
1720
import net.minecraft.util.*;
@@ -83,12 +86,15 @@ public class FarmHelper
8386
boolean set = false; //whether HAS CHANGED motion (1&2)
8487
boolean set3 = false; //same but motion 3
8588
boolean rotating = false;
89+
boolean full = false;
8690

8791

8892
double beforeX = 0;
8993
double beforeZ = 0;
94+
double beforeY = 0;
9095
double deltaX = 10000;
9196
double deltaZ = 10000;
97+
double deltaY = 0;
9298
double initialX = 0;
9399
double initialZ = 0;
94100

@@ -103,14 +109,15 @@ public class FarmHelper
103109
public int keybindW = mc.gameSettings.keyBindForward.getKeyCode();
104110
public int keybindS = mc.gameSettings.keyBindBack.getKeyCode();
105111
public int keybindAttack = mc.gameSettings.keyBindAttack.getKeyCode();
112+
public int keybindUseItem = mc.gameSettings.keyBindUseItem.getKeyCode();
106113

107114
static KeyBinding[] customKeyBinds = new KeyBinding[2];
108115

109116
static volatile int totalMnw = 0;
110117
static volatile int totalEnw = 0;
111118
static volatile int totalMoney = 0;
112119
static volatile int prevMoney = -999;
113-
int cycles = 0;
120+
static int cycles = 0;
114121
static volatile int moneyper10sec = 0;
115122

116123

@@ -272,8 +279,6 @@ public void OnTickPlayer(TickEvent.ClientTickEvent event) { //Client -> player
272279
}
273280

274281
Utils.hardRotate(playerYaw);
275-
276-
277282
}
278283
//INITIALIZE
279284
if (!locked) {
@@ -296,15 +301,15 @@ public void OnTickPlayer(TickEvent.ClientTickEvent event) { //Client -> player
296301
}
297302

298303
}
299-
if(deltaX < 0.8d && deltaZ < 0.8d && !notInIsland && !emergency && !setAntiStuck && Config.FarmType.equals(FarmEnum.LAYERED)){
304+
if(deltaX < 0.8d && deltaZ < 0.8d && deltaY < 0.0001d && !notInIsland && !emergency && !setAntiStuck && Config.FarmType.equals(FarmEnum.LAYERED)){
300305

301306
mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN +
302307
"[Farm Helper] : " + EnumChatFormatting.DARK_GREEN + "Detected stuck"));
303308
setAntiStuck = true;
304309
process4 = true;
305310
ScheduleRunnable(stopAntistuck, 800, TimeUnit.MILLISECONDS);
306311

307-
}else if(deltaX < 0.0001d && deltaZ < 0.0001d && !notInIsland && !emergency && !setAntiStuck && Config.FarmType.equals(FarmEnum.VERTICAL)){
312+
}else if(deltaX < 0.0001d && deltaZ < 0.0001d && deltaY < 0.0001d && !notInIsland && !emergency && !setAntiStuck && Config.FarmType.equals(FarmEnum.VERTICAL)){
308313
//tp pad fix
309314
deltaX = 10000;
310315
deltaZ = 10000;
@@ -367,7 +372,16 @@ else if(!set3 && (mc.thePlayer.posZ != initialZ || mc.thePlayer.posX != initialX
367372
KeyBinding.setKeyBindState(keybindD, true);
368373
KeyBinding.setKeyBindState(keybindA, false);
369374
KeyBinding.setKeyBindState(keybindW, false);
370-
if(!setspawned){mc.thePlayer.sendChatMessage("/setspawn"); setspawned = true; cycles++;}
375+
if(!setspawned)
376+
{
377+
if(full && Config.autosell)
378+
ExecuteRunnable(clearInventory);
379+
else {
380+
mc.thePlayer.sendChatMessage("/setspawn");
381+
setspawned = true;
382+
cycles++;
383+
}
384+
}
371385
}
372386

373387
} else if (process2 && !process3 && !process4) {
@@ -395,8 +409,19 @@ else if(!set3 && (mc.thePlayer.posZ != initialZ || mc.thePlayer.posX != initialX
395409

396410
}
397411
}
398-
if(cycles == 4 && Config.resync)
412+
413+
//resync
414+
if(cycles == 4 && Config.resync && !full && !rotating)
399415
ExecuteRunnable(reSync);
416+
else if(cycles == 4 && Config.resync)
417+
cycles = 0;
418+
419+
420+
//autoSell
421+
if(mc.thePlayer.inventory.getFirstEmptyStack() == -1 && !rotating)
422+
full = true;
423+
424+
400425

401426
} else{
402427
locked = false;
@@ -409,9 +434,59 @@ else if(!set3 && (mc.thePlayer.posZ != initialZ || mc.thePlayer.posX != initialX
409434

410435
//multi-threads
411436

437+
438+
Runnable clearInventory = new Runnable() {
439+
@Override
440+
public void run() {
441+
try {
442+
stop();
443+
enabled = false;
444+
mc.thePlayer.inventory.currentItem = 8;
445+
mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN +
446+
"[Farm Helper] : " + EnumChatFormatting.DARK_GREEN + "Activating autosell"));
447+
Thread.sleep(500);
448+
KeyBinding.onTick(keybindUseItem);
449+
Thread.sleep(1000);
450+
clickWindow(mc.thePlayer.openContainer.windowId, 22, 0, 0);
451+
Thread.sleep(600);
452+
if(mc.thePlayer.openContainer.getSlot(49).getStack().getItem() == Item.getItemFromBlock(Blocks.barrier)) {
453+
mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN +
454+
"[Farm Helper] : " + EnumChatFormatting.DARK_GREEN + "You didn't eat cookie!"));
455+
Config.autosell = false;
456+
throw new Exception();
457+
}
458+
Thread.sleep(400);
459+
while(Utils.hasEnchatedCarrotInInv()) {
460+
clickWindow(mc.thePlayer.openContainer.windowId, 45 + Utils.getFirstSlotWithEnchantedCarrot(), 0, 0);
461+
Thread.sleep(500 + Utils.nextInt(100));
462+
}
463+
Thread.sleep(400);
464+
mc.thePlayer.closeScreen();
465+
full = false;
466+
Thread.sleep(800);
467+
enabled = true;
468+
469+
}catch(Exception e) {
470+
try {
471+
Thread.sleep(500);
472+
mc.thePlayer.closeScreen();
473+
Thread.sleep(800);
474+
enabled = true;
475+
full = false;
476+
} catch(Exception e2){
477+
e2.printStackTrace();
478+
}
479+
}
480+
}
481+
};
412482
Runnable reSync = new Runnable() {
413483
@Override
414484
public void run() {
485+
if(full||rotating) {
486+
cycles = 0;
487+
return;
488+
}
489+
415490
cycles = 0;
416491
mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN +
417492
"[Farm Helper] : " + EnumChatFormatting.DARK_GREEN + "Resyncing.. "));
@@ -426,9 +501,11 @@ public void run() {
426501
if(!notInIsland && !emergency && enabled) {
427502
deltaX = Math.abs(mc.thePlayer.posX - beforeX);
428503
deltaZ = Math.abs(mc.thePlayer.posZ - beforeZ);
504+
deltaY = Math.abs(mc.thePlayer.posY - beforeY);
429505

430506
beforeX = mc.thePlayer.posX;
431507
beforeZ = mc.thePlayer.posZ;
508+
beforeY = mc.thePlayer.posY;
432509

433510
ScheduleRunnable(checkChange, 3, TimeUnit.SECONDS);
434511

@@ -445,13 +522,12 @@ public void run() {
445522
stop();
446523
rotating = true;
447524
enabled = false;
448-
Thread.sleep(500);
525+
Thread.sleep(1000);
449526
Config.Angle = Config.Angle.ordinal() < 2 ? AngleEnum.values()[Config.Angle.ordinal() + 2] : AngleEnum.values()[Config.Angle.ordinal() - 2];
450527
playerYaw = angleToValue(Config.Angle);
451-
Utils.hardRotate(playerYaw);
452-
Thread.sleep(500);
528+
Utils.smoothRotateClockwise(180);
529+
Thread.sleep(2000);
453530
rotating = false;
454-
455531
enabled = true;
456532
}catch(Exception e){
457533
e.printStackTrace();
@@ -677,15 +753,28 @@ void ExecuteRunnable(Runnable r){
677753
eTemp.execute(r);
678754
eTemp.shutdown();
679755
}
756+
757+
void clickWindow(int windowID, int slotID, int mouseButtonClicked, int mode) throws Exception{
758+
Minecraft mc = Minecraft.getMinecraft();
759+
if(mc.thePlayer.openContainer instanceof ContainerChest || mc.currentScreen instanceof GuiInventory)
760+
mc.playerController.windowClick(windowID, slotID, mouseButtonClicked, mode, mc.thePlayer);
761+
else {
762+
mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN +
763+
"[Farm Helper] : " + EnumChatFormatting.DARK_GREEN + "Didn't open window! Autosell failed"));
764+
throw new Exception();
765+
}
766+
}
680767
void initialize(){
681768
deltaX = 10000;
682769
deltaZ = 10000;
770+
deltaY = 0;
683771

684772
process1 = true;
685773
process2 = false;
686774
process3 = false;
687775
process4 = false;
688776

777+
setspawned = false;
689778
shdBePressingKey = true;
690779
notInIsland = false;
691780
beforeX = mc.thePlayer.posX;
@@ -696,6 +785,7 @@ void initialize(){
696785
set3 = false;
697786
cycles = 0;
698787
rotating = false;
788+
full = false;
699789
}
700790
int angleToValue(AngleEnum c){
701791
return !c.toString().replace("A", "").contains("N") ?

src/main/java/FarmHelper/GUI/GUI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.io.IOException;
2222
import java.io.Serializable;
2323

24-
public class GUI extends GuiScreen implements Serializable {
24+
public class GUI extends GuiScreen{
2525

2626

2727
int buttonWidth = 85;

src/main/java/FarmHelper/GUI/GuiSettings.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void initGui() {
3535
this.buttonList.add(new GuiCustomSwitchButton(1, this.width/2 + 120, this.height/2 - 10, 40, 15, 30, "Inventory price calculator"));
3636
this.buttonList.add(new GuiCustomSwitchButton(2, this.width/2 + 120, this.height/2 + 30, 40, 15, 30, "Profit calculator"));
3737
this.buttonList.add(new GuiCustomSwitchButton(3, this.width/2 + 120, this.height/2 + 70, 40, 15, 30, "Auto resync"));
38-
//this.buttonList.add(new GuiCustomSwitchButton(4, this.width/2 + 120, this.height/2 + 110, 40, 15, 30, "Fastbreak"));
38+
this.buttonList.add(new GuiCustomSwitchButton(4, this.width/2 + 120, this.height/2 + 110, 40, 15, 30, "Autosell (make sure you have cookies on!!)"));
3939
initialSelect();
4040
}
4141

@@ -84,12 +84,12 @@ protected void actionPerformed(GuiButton button) throws IOException {
8484
updateScreen();
8585
Config.writeConfig();
8686
}
87-
/*if(button.id == 4){
87+
if(button.id == 4){
8888
GuiCustomSwitchButton temp = (GuiCustomSwitchButton) button;
8989
temp.switchSelect();
90-
Config.fastbreak = !Config.fastbreak;
90+
Config.autosell = !Config.autosell;
9191
updateScreen();
92-
}*/
92+
}
9393

9494

9595
}
@@ -111,10 +111,10 @@ void initialSelect(){
111111
GuiCustomSwitchButton temp = (GuiCustomSwitchButton) this.buttonList.get(3);
112112
temp.switchSelect();
113113
}
114-
/* if(Config.fastbreak) {
114+
if(Config.autosell) {
115115
GuiCustomSwitchButton temp = (GuiCustomSwitchButton) this.buttonList.get(4);
116116
temp.switchSelect();
117-
}*/
117+
}
118118
}
119119

120120

src/main/java/FarmHelper/Utils/Utils.java

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66
import net.minecraft.client.Minecraft;
77
import net.minecraft.client.gui.FontRenderer;
88
import net.minecraft.client.gui.Gui;
9+
import net.minecraft.client.gui.inventory.GuiInventory;
910
import net.minecraft.client.renderer.GlStateManager;
11+
import net.minecraft.client.settings.KeyBinding;
12+
import net.minecraft.init.Blocks;
13+
import net.minecraft.inventory.ContainerChest;
14+
import net.minecraft.inventory.Slot;
15+
import net.minecraft.item.Item;
16+
import net.minecraft.util.ChatComponentText;
17+
import net.minecraft.util.EnumChatFormatting;
1018
import org.lwjgl.opengl.GL11;
1119
import scala.sys.process.ProcessBuilderImpl;
1220

@@ -38,7 +46,39 @@ public static void hardRotate(float yaw) {
3846

3947
}
4048
}
49+
public static boolean hasEnchatedCarrotInInv(){
4150

51+
for(Slot slot : Minecraft.getMinecraft().thePlayer.inventoryContainer.inventorySlots) {
52+
if (slot != null) {
53+
try {
54+
if (slot.getStack().getDisplayName().contains("Enchanted Carrot")) {
55+
return true;
56+
}
57+
}catch(Exception e){
58+
59+
}
60+
}
61+
}
62+
return false;
63+
}
64+
65+
public static int getFirstSlotWithEnchantedCarrot() {
66+
for (Slot slot : Minecraft.getMinecraft().thePlayer.inventoryContainer.inventorySlots) {
67+
if (slot != null) {
68+
if (slot.getStack() != null) {
69+
try {
70+
if (slot.getStack().getDisplayName().contains("Enchanted Carrot"))
71+
return slot.slotNumber;
72+
}catch(Exception e){
73+
74+
}
75+
}
76+
}
77+
78+
}
79+
return 0;
80+
81+
}
4282

4383

4484

@@ -77,19 +117,19 @@ static int getOppositeAngle(int angle){
77117
static boolean shouldRotateClockwise(int currentAngle, int boundAngle){
78118
return false;
79119
}
80-
public static void rotateTo(final int rotation360){
120+
public static void smoothRotateTo(final int rotation360){
81121
new Thread(new Runnable() {
82122
@Override
83123
public void run() {
84-
boolean clockwise = shouldRotateClockwise((int) get360RotationYaw(), getOppositeAngle(rotation360));
124+
85125
while (get360RotationYaw() != rotation360) {
86-
if(Math.abs(rotation360 - get360RotationYaw()) < 2) {
87-
Minecraft.getMinecraft().thePlayer.rotationYaw = (int)(Minecraft.getMinecraft().thePlayer.rotationYaw + (rotation360 - get360RotationYaw()));
88-
break;
126+
if(Math.abs(get360RotationYaw() - rotation360) < 1f) {
127+
Minecraft.getMinecraft().thePlayer.rotationYaw = Math.round(Minecraft.getMinecraft().thePlayer.rotationYaw + Math.abs(get360RotationYaw() - rotation360));
128+
return;
89129
}
90-
Minecraft.getMinecraft().thePlayer.rotationYaw += 0.5f + nextInt(6)/10.0;
130+
Minecraft.getMinecraft().thePlayer.rotationYaw += 0.3f + nextInt(3)/10.0f;
91131
try {
92-
Thread.sleep(2);
132+
Thread.sleep(1);
93133
} catch (Exception e) {
94134
e.printStackTrace();
95135
}
@@ -98,20 +138,20 @@ public void run() {
98138
}).start();
99139

100140
}
101-
public static void rotateClockwise(final int rotationClockwise){
141+
public static void smoothRotateClockwise(final int rotationClockwise360){
102142
new Thread(new Runnable() {
103143
@Override
104144
public void run() {
105-
int initialYaw = (int)Minecraft.getMinecraft().thePlayer.rotationYaw;
106-
while (Minecraft.getMinecraft().thePlayer.rotationYaw != initialYaw + rotationClockwise) {
107-
if(Math.abs(Minecraft.getMinecraft().thePlayer.rotationYaw - initialYaw + rotationClockwise) < 2) {
108-
Minecraft.getMinecraft().thePlayer.rotationYaw = (int)(Minecraft.getMinecraft().thePlayer.rotationYaw + rotationClockwise);
109-
break;
110-
}
111145

112-
Minecraft.getMinecraft().thePlayer.rotationYaw += 0.1f + nextInt(5)/5.0;
146+
int targetYaw = (Math.round(get360RotationYaw()) + rotationClockwise360) % 360;
147+
while (get360RotationYaw() != targetYaw) {
148+
if(Math.abs(get360RotationYaw() - targetYaw) < 1f) {
149+
Minecraft.getMinecraft().thePlayer.rotationYaw = Math.round(Minecraft.getMinecraft().thePlayer.rotationYaw + Math.abs(get360RotationYaw() - targetYaw));
150+
return;
151+
}
152+
Minecraft.getMinecraft().thePlayer.rotationYaw += 0.3f + nextInt(3)/10.0f;
113153
try {
114-
Thread.sleep(2);
154+
Thread.sleep(1);
115155
} catch (Exception e) {
116156
e.printStackTrace();
117157
}

0 commit comments

Comments
 (0)