This repository was archived by the owner on Feb 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathAutoSprayonator.java
More file actions
266 lines (233 loc) · 7.81 KB
/
AutoSprayonator.java
File metadata and controls
266 lines (233 loc) · 7.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
package com.jelly.farmhelperv2.feature.impl;
import com.jelly.farmhelperv2.config.FarmHelperConfig;
import com.jelly.farmhelperv2.event.UpdateTablistEvent;
import com.jelly.farmhelperv2.failsafe.FailsafeManager;
import com.jelly.farmhelperv2.feature.FeatureManager;
import com.jelly.farmhelperv2.feature.IFeature;
import com.jelly.farmhelperv2.handler.GameStateHandler;
import com.jelly.farmhelperv2.handler.GameStateHandler.BuffState;
import com.jelly.farmhelperv2.handler.MacroHandler;
import com.jelly.farmhelperv2.util.InventoryUtils;
import com.jelly.farmhelperv2.util.KeyBindUtils;
import com.jelly.farmhelperv2.util.LogUtils;
import com.jelly.farmhelperv2.util.helper.Clock;
import com.jelly.farmhelperv2.util.PlayerUtils;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
public class AutoSprayonator implements IFeature {
private static AutoSprayonator instance;
public static AutoSprayonator getInstance() {
if (instance == null) {
instance = new AutoSprayonator();
}
return instance;
}
private final String[] SPRAY_MATERIAL = {"Fine Flour", "Compost", "Honey Jar", "Dung", "Plant Matter", "Tasty Cheese"};
private final Minecraft mc = Minecraft.getMinecraft();
private boolean enabled = false;
private boolean pause = false;
private State state = State.STARTING;
private final Clock timer = new Clock();
@Override
public String getName() {
return "AutoSprayonator";
}
@Override
public boolean isRunning() {
return this.enabled;
}
@Override
public boolean shouldPauseMacroExecution() {
return true;
}
@Override
public boolean shouldStartAtMacroStart() {
return false;
}
@Override
public void resetStatesAfterMacroDisabled() {
this.pause = false;
this.state = State.STARTING;
}
@Override
public boolean isToggled() {
return FarmHelperConfig.autoSprayonator;
}
@Override
public boolean shouldCheckForFailsafes() {
return false;
}
private String getSprayMaterial() {
return this.SPRAY_MATERIAL[FarmHelperConfig.autoSprayonatorSprayMaterial];
}
@Override
public void start() {
if (this.enabled) {
return;
}
if (!InventoryUtils.hasItemInHotbar("Sprayonator")) {
LogUtils.sendError("Cannot find sprayonator in hotbar. Pausing until restart.");
this.pause = true;
return;
}
boolean correctMaterialSelected = false;
for (String lore : InventoryUtils.getLoreOfItemInContainer(InventoryUtils.getSlotIdOfItemInContainer("Sprayonator"))) {
if (lore.startsWith("Selected Material")) {
correctMaterialSelected = lore.endsWith(this.getSprayMaterial());
break;
}
}
if (!correctMaterialSelected) {
LogUtils.sendError("Please select " + this.getSprayMaterial() + " as your spray material. Pausing until restart.");
this.pause = true;
return;
}
MacroHandler.getInstance().pauseMacro();
this.timer.schedule(FarmHelperConfig.autoSprayonatorAdditionalDelay);
this.enabled = true;
}
@Override
public void stop() {
this.enabled = false;
this.state = State.STARTING;
if (MacroHandler.getInstance().isMacroToggled()) {
MacroHandler.getInstance().resumeMacro();
}
}
@SubscribeEvent
public void onTablistUpdate(UpdateTablistEvent event) {
if (!this.isToggled() || !MacroHandler.getInstance().isCurrentMacroEnabled() || this.enabled || this.pause) {
return;
}
if (this.isTimerRunning()) {
return;
}
if (!GameStateHandler.getInstance().inGarden()) {
return;
}
if (GameStateHandler.getInstance().getServerClosingSeconds().isPresent()) {
return;
}
if (!Scheduler.getInstance().isFarming()) {
return;
}
if (FailsafeManager.getInstance().triggeredFailsafe.isPresent()) {
return;
}
if (FeatureManager.getInstance().isAnyOtherFeatureEnabled(this)) {
return;
}
if (GameStateHandler.getInstance().getSprayonatorState() != BuffState.NOT_ACTIVE) {
if (this.timer.isScheduled()) this.timer.reset();
return;
}
if (!this.timer.isScheduled()) {
this.timer.schedule(FarmHelperConfig.autoSprayonatorStartDelay);
} else if (this.timer.passed()) {
this.start();
}
}
@SubscribeEvent
public void onChatEvent(ClientChatReceivedEvent event) {
if (!this.enabled || this.state != State.WAITING) {
return;
}
final String message = event.message.getUnformattedText();
if (message.startsWith("SPRAYONATOR!") || message.equals("This plot was sprayed with that item recently! Try again soon!")) {
this.swapState(State.END, FarmHelperConfig.autoSprayonatorAdditionalDelay);
return;
}
if (message.startsWith("You don't have any ")) {
if (!FarmHelperConfig.autoSprayonatorAutoBuyItem) {
LogUtils.sendError("Don't have any spray item and not allowed to buy any. Pausing until restart.");
this.pause = true;
this.swapState(State.END, FarmHelperConfig.autoSprayonatorAdditionalDelay);
} else {
this.swapState(State.BUYING_MATERIAL, FarmHelperConfig.autoSprayonatorAdditionalDelay);
}
}
}
@SubscribeEvent
public void onTickSpray(ClientTickEvent event) {
if (!this.enabled) {
return;
}
switch (this.state) {
case STARTING:
if (this.isTimerRunning()) {
break;
}
if (!InventoryUtils.holdItem("Sprayonator")) {
LogUtils.sendError("Cannot hold sprayonator. Pausing until restart");
this.pause = true;
this.stop();
break;
}
this.swapState(State.SPRAYING, FarmHelperConfig.autoSprayonatorAdditionalDelay);
break;
case SPRAYING:
if (this.isTimerRunning()) {
break;
}
KeyBindUtils.rightClick();
this.swapState(State.WAITING, 5000);
break;
case BUYING_MATERIAL:
if (this.isTimerRunning()) {
break;
}
if (PlayerUtils.isInventoryFull(mc.thePlayer)) {
LogUtils.sendError("AutoBazaar could not buy " + this.getSprayMaterial() + " because inventory is full. Pausing until restart");
this.pause = true;
this.stop();
break;
}
AutoBazaar.getInstance().buy(this.getSprayMaterial(), FarmHelperConfig.autoSprayonatorAutoBuyAmount);
this.swapState(State.WAITING_FOR_PURCHASE, 20000);
break;
case WAITING_FOR_PURCHASE:
if (!this.isTimerRunning()) {
LogUtils.sendError("AutoBazaar took more than 20 seconds. Pausing until restart"); // should never toggle
this.pause = true;
this.stop();
break;
}
if (AutoBazaar.getInstance().isRunning()) {
break;
}
if (AutoBazaar.getInstance().hasFailed()) {
LogUtils.sendError("AutoBazaar could not buy " + this.getSprayMaterial() + ". Pausing until restart");
this.pause = true;
this.stop();
break;
}
this.swapState(State.STARTING, FarmHelperConfig.autoSprayonatorAdditionalDelay);
break;
case WAITING:
if (!this.isTimerRunning()) {
LogUtils.sendError("Could not verify spray before time ended.");
this.stop();
}
break;
case END:
if (this.isTimerRunning()) {
break;
}
this.timer.schedule(2000);
this.stop();
break;
}
}
public void swapState(State swapTo, int delay) {
this.state = swapTo;
this.timer.schedule(delay);
}
public boolean isTimerRunning() {
return this.timer.isScheduled() && !this.timer.passed();
}
enum State {
STARTING, SPRAYING, BUYING_MATERIAL, WAITING_FOR_PURCHASE, WAITING, END
}
}