Skip to content

Commit d2bf8f3

Browse files
author
Ahmed Mahmud
committed
autosell
1 parent 346d1f5 commit d2bf8f3

File tree

3 files changed

+214
-22
lines changed

3 files changed

+214
-22
lines changed

src/main/java/com/jelly/FarmHelper/FarmHelper.java

Lines changed: 191 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.jelly.FarmHelper.gui.GuiSettings;
99
import com.jelly.FarmHelper.utils.DiscordWebhook;
1010
import com.jelly.FarmHelper.utils.Utils;
11+
import jdk.nashorn.internal.runtime.Debug;
1112
import net.minecraft.block.*;
1213
import net.minecraft.block.properties.PropertyInteger;
1314
import net.minecraft.block.state.IBlockState;
@@ -16,6 +17,8 @@
1617
import net.minecraft.client.gui.GuiDisconnected;
1718
import net.minecraft.client.gui.GuiIngameMenu;
1819
import net.minecraft.client.gui.ScaledResolution;
20+
import net.minecraft.client.gui.inventory.GuiChest;
21+
import net.minecraft.client.gui.inventory.GuiContainer;
1922
import net.minecraft.client.gui.inventory.GuiInventory;
2023
import net.minecraft.client.settings.KeyBinding;
2124
import net.minecraft.init.Blocks;
@@ -24,6 +27,7 @@
2427
import net.minecraft.item.EnumDyeColor;
2528
import net.minecraft.item.ItemStack;
2629
import net.minecraft.nbt.NBTTagCompound;
30+
import net.minecraft.nbt.NBTTagList;
2731
import net.minecraft.util.BlockPos;
2832
import net.minecraft.util.EnumChatFormatting;
2933
import net.minecraft.util.IChatComponent;
@@ -46,6 +50,7 @@
4650

4751
import java.awt.*;
4852
import java.util.HashMap;
53+
import java.util.Iterator;
4954
import java.util.Map;
5055
import java.util.concurrent.TimeUnit;
5156
import java.util.regex.Matcher;
@@ -93,6 +98,7 @@ enum location {
9398
public static boolean bazaarLag;
9499
public static boolean profitGUI;
95100
public static double cacheAverageAge;
101+
public static boolean selling;
96102
public static int stuckCount;
97103
public static int startCounter;
98104
public static int currentCounter;
@@ -103,6 +109,7 @@ enum location {
103109
public static boolean godPot;
104110
public static boolean cookie;
105111
public static boolean dropping;
112+
public static boolean checkFull;
106113
public static IChatComponent header;
107114
public static IChatComponent footer;
108115
public static BlockPos cachePos;
@@ -145,6 +152,7 @@ void initialize() {
145152
teleporting = false;
146153
newRow = true;
147154
stuck = false;
155+
selling = false;
148156
cached = false;
149157
crouched = true;
150158
cacheAverageAge = -1;
@@ -379,7 +387,8 @@ public void OnTickPlayer(TickEvent.ClientTickEvent event) {
379387
mc.thePlayer.sendChatMessage("/skyblock");
380388
teleporting = true;
381389
}
382-
} else if (currentLocation == location.HUB) {
390+
}
391+
if (currentLocation == location.HUB) {
383392
Utils.debugFullLog("Detected hub");
384393
updateKeys(false, false, false, false, false, false);
385394
if (!teleporting && jacobEnd < System.currentTimeMillis()) {
@@ -389,7 +398,9 @@ public void OnTickPlayer(TickEvent.ClientTickEvent event) {
389398
mc.thePlayer.sendChatMessage("/warp home");
390399
teleporting = true;
391400
}
392-
} else if (currentLocation == location.ISLAND && !crouched) {
401+
return;
402+
}
403+
if (currentLocation == location.ISLAND && !crouched) {
393404
Utils.debugLog("Back to island, holding shift");
394405
Utils.webhookLog("Back to island, restarting");
395406
updateKeys(false, false, false, false, false, true);
@@ -398,7 +409,9 @@ public void OnTickPlayer(TickEvent.ClientTickEvent event) {
398409
deltaX = 1000;
399410
setStuckCooldown(3);
400411
Utils.ScheduleRunnable(crouchReset, 500, TimeUnit.MILLISECONDS);
401-
} else if (currentLocation == location.ISLAND) {
412+
return;
413+
}
414+
if (currentLocation == location.ISLAND) {
402415
if (dropping) {
403416
updateKeys(false, false, false, false, false, false);
404417
return;
@@ -423,14 +436,17 @@ public void OnTickPlayer(TickEvent.ClientTickEvent event) {
423436
}
424437
return;
425438
}
426-
if (mc.currentScreen instanceof GuiInventory || mc.currentScreen instanceof GuiChat || mc.currentScreen instanceof GuiIngameMenu || mc.currentScreen instanceof GUI || mc.currentScreen instanceof GuiSettings) {
439+
if (mc.currentScreen instanceof GuiContainer || mc.currentScreen instanceof GuiChat || mc.currentScreen instanceof GuiIngameMenu || mc.currentScreen instanceof GUI || mc.currentScreen instanceof GuiSettings) {
427440
Utils.debugFullLog("In inventory/chat/pause, pausing");
428441
updateKeys(false, false, false, false, false, false);
429442
deltaX = 1000;
430443
deltaZ = 1000;
431444
return;
432445
}
433-
if (falling) {
446+
if (selling && checkFull) {
447+
updateKeys(false, false, false, false, false, false);
448+
Utils.debugFullLog("Waiting for inventory sell");
449+
} else if (falling) {
434450
// Stopped falling
435451
if (dy == 0) {
436452
Utils.debugFullLog("Changing layer - Landed - Doing 180 and switching back to trench state");
@@ -485,6 +501,16 @@ else if (inTrenches) {
485501
}
486502
// Cannot move forwards or backwards
487503
if (!isWalkable(Utils.getFrontBlock()) && !isWalkable(Utils.getBackBlock())) {
504+
if (!checkFull && !selling && mc.thePlayer.inventory.getFirstEmptyStack() == -1) {
505+
Utils.debugLog("Inventory possibly full");
506+
checkFull = true;
507+
Utils.ExecuteRunnable(fullInventory);
508+
} else if (!checkFull && selling) {
509+
selling = false;
510+
setStuckCooldown(3);
511+
deltaX = 100;
512+
deltaZ = 100;
513+
}
488514
cached = false;
489515
if (newRow) {
490516
newRow = false;
@@ -1037,7 +1063,7 @@ public void run() {
10371063
}
10381064
};
10391065

1040-
Runnable checkFooter = () -> {
1066+
public static Runnable checkFooter = () -> {
10411067
Utils.debugFullLog("Looking for godpot/cookie");
10421068
boolean foundGodPot = false;
10431069
boolean foundCookieText = false;
@@ -1090,7 +1116,6 @@ public void run() {
10901116
if (slotID < 9) {
10911117
slotID = 36 + slotID;
10921118
}
1093-
Utils.debugLog("waiting inv");
10941119
// while (!(mc.currentScreen instanceof GuiInventory) || Minecraft.getMinecraft().thePlayer.inventoryContainer.inventorySlots == null) {
10951120
// if (!this.mc.playerController.isInCreativeMode()) {
10961121
// mc.displayGuiScreen(new GuiInventory(mc.thePlayer));
@@ -1104,16 +1129,12 @@ public void run() {
11041129
// }
11051130
// Thread.sleep(100);
11061131
// }
1107-
Utils.debugFullLog("found inv");
1108-
Thread.sleep(300);
1132+
// Thread.sleep(300);
11091133
mc.playerController.windowClick(mc.thePlayer.inventoryContainer.windowId, slotID, 0, 0, mc.thePlayer);
1110-
Utils.debugFullLog("picked item");
11111134
Thread.sleep(300);
11121135
mc.playerController.windowClick(mc.thePlayer.inventoryContainer.windowId, slotID, 0, 6, mc.thePlayer);
1113-
Utils.debugFullLog("stacked item item");
11141136
Thread.sleep(300);
11151137
mc.playerController.windowClick(mc.thePlayer.inventoryContainer.windowId, 35 + 7, 0, 0, mc.thePlayer);
1116-
Utils.debugFullLog("put back item");
11171138
Thread.sleep(300);
11181139
// mc.thePlayer.closeScreen();
11191140
if (isWalkable(Utils.getRightBlock())) {
@@ -1157,6 +1178,164 @@ public void run() {
11571178
}
11581179
};
11591180

1181+
public static Runnable sellInventory = () -> {
1182+
try {
1183+
selling = true;
1184+
checkFull = true;
1185+
Minecraft mc = Minecraft.getMinecraft();
1186+
int keybindUseItem = mc.gameSettings.keyBindUseItem.getKeyCode();
1187+
int hoeSlot = mc.thePlayer.inventory.currentItem;
1188+
int sackSlot = -1;
1189+
1190+
Integer[] sellSlots = {11, 16, 21, 23};
1191+
Integer[] sellSlotCounts = {100, 100, 100, 100};
1192+
1193+
if (!cookie) {
1194+
Utils.debugLog("You need a cookie for auto sell!");
1195+
return;
1196+
}
1197+
1198+
// Find a sack
1199+
for (int j = 0; j < 36; j++) {
1200+
ItemStack sack = mc.thePlayer.inventory.getStackInSlot(j);
1201+
if (sack != null) {
1202+
String name = sack.getDisplayName();
1203+
if (name.contains("Large Enchanted Agronomy Sack") && sackSlot == -1) {
1204+
if (j < 9) {
1205+
sackSlot = j + 36;
1206+
} else {
1207+
sackSlot = j;
1208+
}
1209+
Utils.debugLog("Found sack, slot: " + sackSlot);
1210+
}
1211+
}
1212+
Thread.sleep(20);
1213+
}
1214+
1215+
// Go through items
1216+
for (int i = 0; i < sellSlots.length; i++) {
1217+
while (sellSlotCounts[i] != 0 && sackSlot != -1) {
1218+
mc.thePlayer.inventory.currentItem = 8;
1219+
Thread.sleep(500);
1220+
KeyBinding.onTick(keybindUseItem);
1221+
Thread.sleep(500);
1222+
mc.playerController.windowClick(mc.thePlayer.openContainer.windowId, sackSlot + 45, 1, 0, mc.thePlayer);
1223+
Thread.sleep(500);
1224+
ItemStack stack = mc.thePlayer.openContainer.getSlot(sellSlots[i]).getStack();
1225+
NBTTagList list = stack.getTagCompound().getCompoundTag("display").getTagList("Lore", 8);
1226+
Pattern pattern = Pattern.compile("^([a-zA-Z]+): ([0-9]+)(.*)");
1227+
for (int j = 0; j < list.tagCount(); j++) {
1228+
Matcher matcher = pattern.matcher(net.minecraft.util.StringUtils.stripControlCodes(list.getStringTagAt(j)));
1229+
if (matcher.matches()) {
1230+
Utils.debugLog("Stored: " + matcher.group(2));
1231+
sellSlotCounts[i] = Integer.parseInt(matcher.group(2));
1232+
}
1233+
}
1234+
boolean picked = false;
1235+
while (sellSlotCounts[i] != 0 && mc.thePlayer.inventory.getFirstEmptyStack() != -1) {
1236+
picked = true;
1237+
mc.playerController.windowClick(mc.thePlayer.openContainer.windowId, sellSlots[i], 0, 0, mc.thePlayer);
1238+
Thread.sleep(500);
1239+
stack = mc.thePlayer.openContainer.getSlot(sellSlots[i]).getStack();
1240+
list = stack.getTagCompound().getCompoundTag("display").getTagList("Lore", 8);
1241+
for (int j = 0; j < list.tagCount(); j++) {
1242+
Matcher matcher = pattern.matcher(net.minecraft.util.StringUtils.stripControlCodes(list.getStringTagAt(j)));
1243+
if (matcher.matches()) {
1244+
Utils.debugLog("New Count: " + matcher.group(2));
1245+
sellSlotCounts[i] = Integer.parseInt(matcher.group(2));
1246+
}
1247+
}
1248+
Thread.sleep(1000);
1249+
}
1250+
// Sell off
1251+
if (picked) {
1252+
Utils.debugLog("Out of space or no more to collect - Selling");
1253+
mc.thePlayer.closeScreen();
1254+
Thread.sleep(300);
1255+
mc.thePlayer.inventory.currentItem = 8;
1256+
Thread.sleep(500);
1257+
KeyBinding.onTick(keybindUseItem);
1258+
Thread.sleep(500);
1259+
mc.playerController.windowClick(mc.thePlayer.openContainer.windowId, 22, 0, 0, mc.thePlayer);
1260+
Thread.sleep(500);
1261+
for (int j = 0; j < 36; j++) {
1262+
ItemStack sellStack = mc.thePlayer.inventory.getStackInSlot(j);
1263+
if (sellStack != null) {
1264+
String name = sellStack.getDisplayName();
1265+
if (name.contains("Enchanted Brown Mushroom") || name.contains("Enchanted Red Mushroom") || name.contains("Mutant Netherwart") || name.contains("Stone") || name.contains("Enchanted Sugar Cane")) {
1266+
Utils.debugLog("Found stack, selling");
1267+
if (j < 9) {
1268+
mc.playerController.windowClick(mc.thePlayer.openContainer.windowId, 45 + 36 + j, 0, 0, mc.thePlayer);
1269+
} else {
1270+
mc.playerController.windowClick(mc.thePlayer.openContainer.windowId, 45 + j, 0, 0, mc.thePlayer);
1271+
}
1272+
Thread.sleep(200);
1273+
}
1274+
}
1275+
Thread.sleep(20);
1276+
}
1277+
}
1278+
mc.thePlayer.closeScreen();
1279+
}
1280+
}
1281+
1282+
// Sell remaining sack to bz
1283+
if (Config.CropType != CropEnum.NETHERWART) {
1284+
mc.thePlayer.sendChatMessage("/bz");
1285+
while (!(mc.currentScreen instanceof GuiContainer)) {
1286+
Thread.sleep(50);
1287+
}
1288+
Thread.sleep(100);
1289+
ItemStack stack = mc.thePlayer.openContainer.getSlot(39).getStack();
1290+
if (stack.getDisplayName().contains("Sell Sacks Now")) {
1291+
mc.playerController.windowClick(mc.thePlayer.openContainer.windowId, 39, 1, 0, mc.thePlayer);
1292+
stack = mc.thePlayer.openContainer.getSlot(11).getStack();
1293+
while (!stack.getDisplayName().contains("Selling whole inventory")) {
1294+
Thread.sleep(50);
1295+
stack = mc.thePlayer.openContainer.getSlot(11).getStack();
1296+
}
1297+
Thread.sleep(100);
1298+
while (stack.getDisplayName().contains("Selling whole inventory")) {
1299+
mc.playerController.windowClick(mc.thePlayer.openContainer.windowId, 11, 1, 0, mc.thePlayer);
1300+
Thread.sleep(200);
1301+
stack = mc.thePlayer.openContainer.getSlot(11).getStack();
1302+
}
1303+
Utils.debugLog("Sold sacks to bazaar!");
1304+
}
1305+
}
1306+
Thread.sleep(1000);
1307+
mc.thePlayer.closeScreen();
1308+
mc.thePlayer.inventory.currentItem = hoeSlot;
1309+
checkFull = false;
1310+
} catch (InterruptedException e) {
1311+
e.printStackTrace();
1312+
}
1313+
};
1314+
1315+
Runnable fullInventory = () -> {
1316+
int count = 0;
1317+
int total = 0;
1318+
int elapsed = 0;
1319+
try {
1320+
while (elapsed < 2000) {
1321+
if (mc.thePlayer.inventory.getFirstEmptyStack() == -1) {
1322+
count++;
1323+
}
1324+
total++;
1325+
elapsed += 50;
1326+
Thread.sleep(10);
1327+
}
1328+
if (count/total > 0.35) {
1329+
Utils.webhookLog("Inventory full, Auto Selling!");
1330+
Utils.ExecuteRunnable(sellInventory);
1331+
} else {
1332+
checkFull = false;
1333+
}
1334+
} catch (InterruptedException e) {
1335+
e.printStackTrace();
1336+
}
1337+
};
1338+
11601339
public static void goToBlock(int x, int z) {
11611340
new Thread(() -> {
11621341
Minecraft mc = Minecraft.getMinecraft();

src/main/java/com/jelly/FarmHelper/gui/GUI.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.jelly.FarmHelper.config.FarmEnum;
77
import com.jelly.FarmHelper.gui.buttons.GuiBetterButton;
88
import com.jelly.FarmHelper.gui.buttons.GuiCustomButton;
9+
import com.jelly.FarmHelper.gui.buttons.GuiCustomSwitchButton;
10+
import com.jelly.FarmHelper.utils.Utils;
911
import net.minecraft.client.gui.GuiButton;
1012
import net.minecraft.client.gui.GuiScreen;
1113
import net.minecraft.util.ResourceLocation;
@@ -14,6 +16,7 @@
1416

1517
import java.awt.*;
1618
import java.io.IOException;
19+
import java.util.concurrent.TimeUnit;
1720

1821
public class GUI extends GuiScreen{
1922
int buttonWidth = 115;
@@ -31,14 +34,16 @@ public void postInit(FMLPostInitializationEvent event) {
3134
@Override
3235
public void initGui() {
3336
super.initGui();
34-
this.buttonList.add(new GuiCustomButton(100, this.width/2, this.height/2 - 40, 0,0, quarterI));
35-
this.buttonList.add(new GuiCustomButton(1, this.width/2 - 100 , this.height / 2 - 140, 100, 100, quarterI));
36-
this.buttonList.add(new GuiCustomButton(2, this.width/2, this.height / 2 - 140, 100,100, quarterII));
37-
this.buttonList.add(new GuiCustomButton(3, this.width/2 - 100 , this.height / 2 - 40, 100,100, quarterIII));
38-
this.buttonList.add(new GuiCustomButton(4, this.width/2 , this.height / 2 - 40, 100,100, quarterIV));
39-
this.buttonList.add(new GuiBetterButton(5, this.width / 2 - buttonWidth / 2, this.height / 2 - buttonHeight / 2 + 130, buttonWidth, buttonHeight, "Settings"));
40-
this.buttonList.add(new GuiBetterButton(6, this.width / 2 - buttonWidth / 2, this.height / 2 - buttonHeight / 2 + 180, buttonWidth, buttonHeight, "Toggle Profit GUI"));
41-
this.buttonList.add(new GuiBetterButton(7, this.width / 2 - buttonWidth / 2, this.height / 2 - buttonHeight / 2 + 230, buttonWidth, buttonHeight, "Change farm"));
37+
this.buttonList.add(new GuiCustomButton(100, this.width/2, this.height/2 - 100, 0,0, quarterI));
38+
this.buttonList.add(new GuiCustomButton(1, this.width/2 - 100 , this.height / 2 - 200, 100, 100, quarterI));
39+
this.buttonList.add(new GuiCustomButton(2, this.width/2, this.height / 2 - 200, 100,100, quarterII));
40+
this.buttonList.add(new GuiCustomButton(3, this.width/2 - 100 , this.height / 2 - 100, 100,100, quarterIII));
41+
this.buttonList.add(new GuiCustomButton(4, this.width/2 , this.height / 2 - 100, 100,100, quarterIV));
42+
this.buttonList.add(new GuiBetterButton(5, this.width / 2 - buttonWidth / 2, this.height / 2 - buttonHeight / 2 + 60, buttonWidth, buttonHeight, "Settings"));
43+
this.buttonList.add(new GuiBetterButton(6, this.width / 2 - buttonWidth / 2, this.height / 2 - buttonHeight / 2 + 110, buttonWidth, buttonHeight, "Toggle Profit GUI"));
44+
this.buttonList.add(new GuiBetterButton(7, this.width / 2 - buttonWidth / 2, this.height / 2 - buttonHeight / 2 + 160, buttonWidth, buttonHeight, Config.FarmType.name()));
45+
this.buttonList.add(new GuiBetterButton(8, this.width / 2 - buttonWidth / 2, this.height / 2 - buttonHeight / 2 + 210, buttonWidth, buttonHeight, "Sell Inventory"));
46+
4247
GuiCustomButton temp = (GuiCustomButton) this.buttonList.get(Config.CropType.ordinal());
4348
temp.select();
4449
}
@@ -100,10 +105,19 @@ protected void actionPerformed(GuiButton button) throws IOException {
100105
}
101106
if (button.id == 6) {
102107
FarmHelper.profitGUI = !FarmHelper.profitGUI;
103-
// FarmHelper.goToBlock(4, -95);
104108
}
105109
if (button.id == 7) {
106110
Config.FarmType = FarmEnum.values()[1 - Config.FarmType.ordinal()];
111+
GuiBetterButton temp = (GuiBetterButton) button;
112+
temp.displayString = Config.FarmType.name();
113+
updateScreen();
114+
}
115+
if (button.id == 8) {
116+
FarmHelper.openedGUI = false;
117+
mc.thePlayer.closeScreen();
118+
FarmHelper.cookie = true;
119+
Utils.ExecuteRunnable(FarmHelper.checkFooter);
120+
Utils.ScheduleRunnable(FarmHelper.sellInventory, 2, TimeUnit.SECONDS);
107121
}
108122
}
109123
}

0 commit comments

Comments
 (0)