Skip to content

Commit 04b2e7a

Browse files
committed
Cane harvester integrated (draft)
1 parent 89e89a7 commit 04b2e7a

File tree

16 files changed

+500
-144
lines changed

16 files changed

+500
-144
lines changed

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

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
package com.jelly.farmhelper;
22

33
import com.jelly.farmhelper.config.FarmHelperConfig;
4+
import com.jelly.farmhelper.config.enums.CropEnum;
5+
import com.jelly.farmhelper.config.interfaces.FarmConfig;
46
import com.jelly.farmhelper.features.Antistuck;
57
import com.jelly.farmhelper.features.Failsafe;
6-
import com.jelly.farmhelper.features.Resync;
78
import com.jelly.farmhelper.gui.MenuGUI;
89
import com.jelly.farmhelper.macros.CropMacro;
9-
import com.jelly.farmhelper.macros.MacroHandler;
10-
import com.jelly.farmhelper.player.Rotation;
10+
import com.jelly.farmhelper.macros.Macro;
11+
import com.jelly.farmhelper.macros.SugarcaneMacro;
12+
import com.jelly.farmhelper.utils.InventoryUtils;
1113
import com.jelly.farmhelper.utils.KeyBindUtils;
14+
import com.jelly.farmhelper.utils.LogUtils;
1215
import com.jelly.farmhelper.world.GameState;
1316
import net.minecraft.client.Minecraft;
17+
import net.minecraftforge.client.event.RenderWorldLastEvent;
1418
import net.minecraftforge.common.MinecraftForge;
1519
import net.minecraftforge.fml.common.Mod;
1620
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
@@ -20,8 +24,6 @@
2024
import net.minecraftforge.fml.common.gameevent.TickEvent;
2125
import org.lwjgl.opengl.Display;
2226

23-
import java.awt.*;
24-
2527

2628
@Mod(modid = FarmHelper.MODID, name = FarmHelper.NAME, version = FarmHelper.VERSION)
2729
public class FarmHelper {
@@ -33,6 +35,16 @@ public class FarmHelper {
3335
private static final Minecraft mc = Minecraft.getMinecraft();
3436
public static GameState gameState = new GameState();
3537

38+
static CropMacro cropMacro = new CropMacro();
39+
static SugarcaneMacro sugarcaneMacro = new SugarcaneMacro();
40+
41+
public static Macro currentMacro;
42+
public static int startCounter = 0;
43+
public static long startTime = 0;
44+
45+
46+
public static boolean on = false;
47+
3648
@Mod.EventHandler
3749
public void init(FMLInitializationEvent event) {
3850
// ClientCommandHandler.instance.registerCommand((ICommand)new CheetoCommand());
@@ -41,13 +53,15 @@ public void init(FMLInitializationEvent event) {
4153
KeyBindUtils.setup();
4254
MinecraftForge.EVENT_BUS.register(new FarmHelper());
4355
MinecraftForge.EVENT_BUS.register(new MenuGUI());
44-
MinecraftForge.EVENT_BUS.register(new MacroHandler());
45-
46-
MinecraftForge.EVENT_BUS.register(new CropMacro());
47-
48-
// MinecraftForge.EVENT_BUS.register(new Resync());
4956
MinecraftForge.EVENT_BUS.register(new Failsafe());
5057
MinecraftForge.EVENT_BUS.register(new Antistuck());
58+
59+
}
60+
61+
@SubscribeEvent
62+
public void onRender(RenderWorldLastEvent event){
63+
if(on)
64+
currentMacro.onRender();
5165
}
5266

5367
@SubscribeEvent
@@ -57,12 +71,44 @@ public void OnKeyPress(InputEvent.KeyInputEvent event) {
5771
mc.displayGuiScreen(new MenuGUI());
5872
// BlurUtils.renderBlurredBackground(10.0f, resolution.getScaledWidth() - translatedWidth, resolution.getScaledHeight(), resolution.getScaledWidth() - 1 - width, y, width, height);
5973
}
74+
if (KeyBindUtils.customKeyBinds[1].isPressed()) {
75+
if(FarmConfig.cropType == CropEnum.SUGARCANE)
76+
currentMacro = sugarcaneMacro;
77+
else
78+
currentMacro = cropMacro;
79+
80+
on = !on;
81+
if(on) {
82+
LogUtils.scriptLog("Starting script");
83+
startTime = System.currentTimeMillis();
84+
startCounter = InventoryUtils.getCounter();
85+
} else
86+
LogUtils.scriptLog("Disabling script");
87+
currentMacro.toggle();
88+
}
89+
90+
}
91+
public static void disableCurrentMacro(){
92+
on = false;
93+
if(currentMacro.enabled)
94+
currentMacro.toggle();
95+
}
96+
public static void enableCurrentMacro(){
97+
on = true;
98+
if(!currentMacro.enabled)
99+
currentMacro.toggle();
60100
}
61101

62102
@SubscribeEvent(priority = EventPriority.HIGHEST)
63103
public final void tick(TickEvent.ClientTickEvent event) {
64104
if (event.phase != TickEvent.Phase.START) return;
65-
if (mc.thePlayer != null && mc.theWorld != null) gameState.update();
105+
if (mc.thePlayer != null && mc.theWorld != null) {
106+
gameState.update();
107+
if(on) {
108+
109+
currentMacro.onTick();
110+
}
111+
}
66112
tickCount += 1;
67113
tickCount %= 20;
68114
}

src/main/java/com/jelly/farmhelper/config/enums/CropEnum.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ public enum CropEnum {
44
CARROT,
55
NETHERWART,
66
POTATO,
7-
WHEAT
7+
WHEAT,
8+
SUGARCANE
89
}

src/main/java/com/jelly/farmhelper/features/Antistuck.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.jelly.farmhelper.features;
22

3-
import com.jelly.farmhelper.macros.MacroHandler;
3+
import com.jelly.farmhelper.FarmHelper;
44
import com.jelly.farmhelper.utils.Clock;
55
import net.minecraft.client.Minecraft;
66
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@@ -15,7 +15,7 @@ public class Antistuck {
1515

1616
@SubscribeEvent
1717
public final void tick(TickEvent.ClientTickEvent event) {
18-
if (!MacroHandler.macroEnabled || event.phase == TickEvent.Phase.END || mc.thePlayer == null || mc.theWorld == null) return;
18+
if (!FarmHelper.on || event.phase == TickEvent.Phase.END || mc.thePlayer == null || mc.theWorld == null) return;
1919
if (cooldown.passed()) {
2020
stuck = Math.abs(mc.thePlayer.posX - lastX) < 1 && Math.abs(mc.thePlayer.posZ - lastZ) < 1;
2121
lastX = mc.thePlayer.posX;

src/main/java/com/jelly/farmhelper/features/Failsafe.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package com.jelly.farmhelper.features;
22

3+
import com.jelly.farmhelper.FarmHelper;
34
import com.jelly.farmhelper.config.interfaces.JacobConfig;
4-
import com.jelly.farmhelper.macros.MacroHandler;
55
import com.jelly.farmhelper.utils.Clock;
66
import com.jelly.farmhelper.utils.LogUtils;
77
import com.jelly.farmhelper.utils.ScoreboardUtils;
88
import net.minecraft.client.Minecraft;
9-
import net.minecraft.scoreboard.Score;
109
import net.minecraftforge.client.event.ClientChatReceivedEvent;
1110
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
1211
import net.minecraftforge.fml.common.gameevent.TickEvent;
@@ -26,7 +25,7 @@ public class Failsafe {
2625
@SubscribeEvent
2726
public void onMessageReceived(ClientChatReceivedEvent event) {
2827
String message = net.minecraft.util.StringUtils.stripControlCodes(event.message.getUnformattedText());
29-
if (MacroHandler.macroEnabled) {
28+
if (FarmHelper.on) {
3029
if (message.contains("DYNAMIC") || message.contains("Something went wrong trying to send ") || message.contains("don't spam") || message.contains("A disconnect occurred ") || message.contains("An exception occurred ") || message.contains("Couldn't warp ") || message.contains("You are sending commands ") || message.contains("Cannot join ") || message.contains("There was a problem ") || message.contains("You cannot join ") || message.contains("You were kicked while ") || message.contains("You are already playing") || message.contains("You cannot join SkyBlock from here!")) {
3130
LogUtils.debugLog("Failed teleport - waiting");
3231
teleporting = false;
@@ -37,7 +36,7 @@ public void onMessageReceived(ClientChatReceivedEvent event) {
3736

3837
@SubscribeEvent
3938
public final void tick(TickEvent.ClientTickEvent event) {
40-
if (!MacroHandler.macroEnabled || event.phase == TickEvent.Phase.END || mc.thePlayer == null || mc.theWorld == null) return;
39+
if (!FarmHelper.on || event.phase == TickEvent.Phase.END || mc.thePlayer == null || mc.theWorld == null) return;
4140

4241
switch (gameState.currentLocation) {
4342
case TELEPORTING:
@@ -68,11 +67,11 @@ public final void tick(TickEvent.ClientTickEvent event) {
6867
case ISLAND:
6968
if (jacobExceeded()) {
7069
mc.thePlayer.sendChatMessage("/setspawn");
71-
MacroHandler.disableCurrentMacro();
70+
FarmHelper.disableCurrentMacro();
7271
jacobWait.schedule(getJacobRemaining());
7372
mc.thePlayer.sendChatMessage("/lobby");
7473
} else {
75-
MacroHandler.enableCurrentMacro();
74+
FarmHelper.enableCurrentMacro();
7675
}
7776
}
7877
}

src/main/java/com/jelly/farmhelper/gui/menus/FarmMenu.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public FarmMenu() {
3131
cropList.add(new ImageBox(new SiblingConstraint(10), new PixelConstraint(10), "https://static.wikia.nocookie.net/minecraft_gamepedia/images/c/c0/Nether_Wart_%28item%29_JE1.png", cropList, 1L, "cropType").setChildOf(selector));
3232
cropList.add(new ImageBox(new PixelConstraint(10), new SiblingConstraint(10), "https://static.wikia.nocookie.net/minecraft_gamepedia/images/c/c1/Potato_JE3_BE2.png", cropList, 2L, "cropType").setChildOf(selector));
3333
cropList.add( new ImageBox(new SiblingConstraint(10), new CramSiblingConstraint(10), "https://static.wikia.nocookie.net/minecraft_gamepedia/images/7/75/Wheat_JE2_BE2.png", cropList, 3L, "cropType").setChildOf(selector));
34+
cropList.add( new ImageBox(new PixelConstraint(80), new SiblingConstraint(10), "https://static.wikia.nocookie.net/hypixel-skyblock/images/6/67/Sugar_Cane.png/revision/latest?cb=20210615232455", cropList, 4L, "cropType").setChildOf(selector));
3435

3536
farmList.add(new ImageBox(new PixelConstraint(10), new CramSiblingConstraint(10), "https://i.ibb.co/6nFDfRt/layered.png", farmList, 0L, "farmType").setChildOf(selector));
3637
farmList.add(new ImageBox(new SiblingConstraint(10), new CramSiblingConstraint(10), "https://i.ibb.co/hLG9g3X/vertical.png", farmList, 1L, "farmType").setChildOf(selector));

src/main/java/com/jelly/farmhelper/macros/CropMacro.java

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,9 @@
1313
import static com.jelly.farmhelper.utils.KeyBindUtils.updateKeys;
1414

1515
import com.jelly.farmhelper.world.GameState;
16-
import jline.internal.Log;
17-
import net.minecraft.block.BlockStone;
1816
import net.minecraft.client.Minecraft;
19-
import net.minecraft.client.settings.KeyBinding;
2017
import net.minecraft.init.Blocks;
21-
import net.minecraftforge.client.event.RenderWorldLastEvent;
22-
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
23-
import net.minecraftforge.fml.common.gameevent.TickEvent;
24-
25-
public class CropMacro {
18+
public class CropMacro extends Macro{
2619
private static final Minecraft mc = Minecraft.getMinecraft();
2720

2821
enum State {
@@ -47,7 +40,6 @@ enum StoneThrowState {
4740
}
4841

4942
private static final Rotation rotation = new Rotation();
50-
private static boolean enabled = false;
5143
private static State currentState;
5244
private static StoneThrowState stoneState;
5345
private static double layerY;
@@ -61,8 +53,9 @@ enum StoneThrowState {
6153
private static final Clock stoneDropTimer = new Clock();
6254
private static int hoeSlot;
6355

64-
public static void enable() {
65-
enabled = true;
56+
57+
@Override
58+
public void onEnable() {
6659
layerY = mc.thePlayer.posY;
6760
currentState = State.NONE;
6861
pushedFront = false;
@@ -80,18 +73,22 @@ public static void enable() {
8073
rotation.easeTo(yaw, pitch, 500);
8174
}
8275

83-
public static void disable() {
84-
enabled = false;
76+
@Override
77+
public void onDisable() {
8578
updateKeys(false, false, false, false, false);
8679
}
80+
@Override
81+
public void onRender(){
82+
if (rotation.rotating) {
83+
LogUtils.debugFullLog("onRenderWorld - Rotating");
84+
rotation.update();
85+
}
86+
}
8787

88-
@SubscribeEvent
89-
public final void tick(TickEvent.ClientTickEvent event) {
90-
if (!MacroHandler.macroEnabled || !enabled || event.phase == TickEvent.Phase.END || mc.thePlayer == null || mc.theWorld == null) return;
91-
88+
@Override
89+
public void onTick(){
9290
if (gameState.currentLocation != GameState.location.ISLAND) {
9391
updateKeys(false, false, false, false, false);
94-
disable();
9592
return;
9693
}
9794

@@ -365,13 +362,6 @@ public final void tick(TickEvent.ClientTickEvent event) {
365362
}
366363
}
367364

368-
@SubscribeEvent
369-
public void onRenderWorld(final RenderWorldLastEvent event) {
370-
if (enabled && rotation.rotating) {
371-
LogUtils.debugFullLog("onRenderWorld - Rotating");
372-
rotation.update();
373-
}
374-
}
375365

376366
private static void updateState() {
377367
State lastState = currentState;
@@ -434,11 +424,6 @@ private static State calculateDirection() {
434424
LogUtils.debugLog("Cannot find direction. Length > 180");
435425
return State.NONE;
436426
}
437-
438-
public static boolean isEnabled() {
439-
return CropMacro.enabled;
440-
}
441-
442427
public static Runnable fixRowStuck = () -> {
443428
try {
444429
Thread.sleep(20);
@@ -499,4 +484,5 @@ public static boolean isEnabled() {
499484
e.printStackTrace();
500485
}
501486
};
487+
502488
}
Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
package com.jelly.farmhelper.macros;
22

33
import com.jelly.farmhelper.utils.LogUtils;
4+
import net.minecraft.client.Minecraft;
45

5-
public interface Macro {
6-
static void enable() {
7-
LogUtils.debugLog("Missing enable handler");
6+
public class Macro {
7+
public Minecraft mc = Minecraft.getMinecraft();
8+
public boolean enabled;
9+
10+
public void toggle(){
11+
enabled = !enabled;
12+
if(enabled){
13+
onEnable();
14+
} else {
15+
onDisable();
16+
}
17+
}
18+
public void onEnable() {
19+
}
20+
21+
public void onDisable() {
22+
}
23+
24+
public void onTick(){
825
}
926

10-
static void disable() {
11-
LogUtils.debugLog("Missing disable handler");
27+
public void onRender(){
1228
}
29+
30+
31+
32+
1333
}

0 commit comments

Comments
 (0)