Skip to content

Commit 7a50988

Browse files
Add "All plant types" checkboxes to AutoFarm
1 parent aba3db1 commit 7a50988

File tree

23 files changed

+354
-10
lines changed

23 files changed

+354
-10
lines changed

src/main/java/net/wurstclient/clickgui/ClickGuiIcons.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,24 @@ public static void drawCheck(DrawContext context, float x1, float y1,
174174
RenderUtils.drawLineStrip2D(context, outlineVertices, outlineColor);
175175
}
176176

177+
public static void drawIndeterminateCheck(DrawContext context, float x1,
178+
float y1, float x2, float y2, boolean hovering, boolean grayedOut)
179+
{
180+
float xc1 = x1 + 2.5F;
181+
float xc2 = x2 - 2.5F;
182+
float yc1 = y1 + 2.5F;
183+
float yc2 = y2 - 2.5F;
184+
185+
// fill
186+
int checkColor =
187+
grayedOut ? 0xC0808080 : hovering ? 0xFF00FF00 : 0xFF00D900;
188+
RenderUtils.fill2D(context, xc1, yc1, xc2, yc2, checkColor);
189+
190+
// outline
191+
int outlineColor = 0x80101010;
192+
RenderUtils.drawBorder2D(context, xc1, yc1, xc2, yc2, outlineColor);
193+
}
194+
177195
public static void drawCross(DrawContext context, float x1, float y1,
178196
float x2, float y2, boolean hovering)
179197
{

src/main/java/net/wurstclient/clickgui/components/PlantTypeComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public int getDefaultWidth()
141141
{
142142
int nameWidth = TR.getWidth(setting.getName());
143143
int boxesWidth =
144-
(2 * BOX_SIZE) + TR.getWidth(HARVEST) + TR.getWidth(REPLANT) + 6;
144+
2 * BOX_SIZE + TR.getWidth(HARVEST) + TR.getWidth(REPLANT) + 6;
145145
return ICON_SIZE + Math.max(nameWidth, boxesWidth);
146146
}
147147

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
* Copyright (c) 2014-2025 Wurst-Imperium and contributors.
3+
*
4+
* This source code is subject to the terms of the GNU General Public
5+
* License, version 3. If a copy of the GPL was not distributed with this
6+
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
7+
*/
8+
package net.wurstclient.clickgui.components;
9+
10+
import org.lwjgl.glfw.GLFW;
11+
12+
import net.minecraft.client.font.TextRenderer;
13+
import net.minecraft.client.gui.Click;
14+
import net.minecraft.client.gui.DrawContext;
15+
import net.wurstclient.clickgui.ClickGui;
16+
import net.wurstclient.clickgui.ClickGuiIcons;
17+
import net.wurstclient.clickgui.Component;
18+
import net.wurstclient.settings.ToggleAllPlantTypesSetting;
19+
import net.wurstclient.util.RenderUtils;
20+
import net.wurstclient.util.text.WText;
21+
22+
public final class ToggleAllPlantTypesComponent extends Component
23+
{
24+
private static final ClickGui GUI = WURST.getGui();
25+
private static final TextRenderer TR = MC.textRenderer;
26+
private static final int BOX_SIZE = 11;
27+
private static final int ICON_SIZE = 24;
28+
private static final String HARVEST = "Harvest";
29+
private static final String REPLANT = "Replant";
30+
31+
private final ToggleAllPlantTypesSetting setting;
32+
33+
public ToggleAllPlantTypesComponent(ToggleAllPlantTypesSetting setting)
34+
{
35+
this.setting = setting;
36+
setWidth(getDefaultWidth());
37+
setHeight(getDefaultHeight());
38+
}
39+
40+
@Override
41+
public void handleMouseClick(double mouseX, double mouseY, int mouseButton,
42+
Click context)
43+
{
44+
if(mouseX < getX() + ICON_SIZE)
45+
return;
46+
47+
if(mouseY < getY() + getHeight() - BOX_SIZE)
48+
return;
49+
50+
boolean hHarvest =
51+
mouseX < getX() + ICON_SIZE + BOX_SIZE + TR.getWidth(HARVEST) + 4;
52+
53+
switch(mouseButton)
54+
{
55+
case GLFW.GLFW_MOUSE_BUTTON_LEFT:
56+
if(hHarvest)
57+
setting.toggleHarvestingEnabled();
58+
else
59+
setting.toggleReplantingEnabled();
60+
break;
61+
62+
case GLFW.GLFW_MOUSE_BUTTON_RIGHT:
63+
if(hHarvest)
64+
setting.resetHarvestingEnabled();
65+
else
66+
setting.resetReplantingEnabled();
67+
break;
68+
}
69+
}
70+
71+
@Override
72+
public void render(DrawContext context, int mouseX, int mouseY,
73+
float partialTicks)
74+
{
75+
int harvestWidth = TR.getWidth(HARVEST);
76+
77+
int x1 = getX();
78+
int x2 = x1 + getWidth();
79+
int x3 = x1 + ICON_SIZE;
80+
int x4 = x3 + BOX_SIZE;
81+
int x5 = x4 + harvestWidth + 4;
82+
int x6 = x5 + BOX_SIZE;
83+
int y1 = getY();
84+
int y2 = y1 + getHeight();
85+
int y3 = y2 - BOX_SIZE;
86+
87+
boolean hovering = isHovering(mouseX, mouseY);
88+
boolean hIcon = hovering && mouseX < x3;
89+
boolean hName = hovering && mouseX >= x3 && mouseY < y3;
90+
boolean hHarvest =
91+
hovering && mouseX >= x3 && mouseX < x5 && mouseY >= y3;
92+
boolean hReplant = hovering && mouseX >= x5 && mouseY >= y3;
93+
94+
if(hIcon || hName)
95+
GUI.setTooltip(
96+
"" + WText.translated("gui.wurst.autofarm.all_plant_types"));
97+
else if(hHarvest)
98+
GUI.setTooltip("" + WText.translated("gui.wurst.autofarm.harvest"));
99+
else if(hReplant)
100+
GUI.setTooltip("" + WText.translated("gui.wurst.autofarm.replant"));
101+
102+
// background
103+
int bgColor = getFillColor(false);
104+
context.fill(x1, y1, x2, y3, bgColor);
105+
context.fill(x1, y3, x3, y2, bgColor);
106+
context.fill(x4, y3, x5, y2, bgColor);
107+
context.fill(x6, y3, x2, y2, bgColor);
108+
109+
// boxes
110+
context.fill(x3, y3, x4, y2, getFillColor(hHarvest));
111+
context.fill(x5, y3, x6, y2, getFillColor(hReplant));
112+
int outlineColor = RenderUtils.toIntColor(GUI.getAcColor(), 0.5F);
113+
RenderUtils.drawBorder2D(context, x3, y3, x4, y2, outlineColor);
114+
RenderUtils.drawBorder2D(context, x5, y3, x6, y2, outlineColor);
115+
116+
// checks
117+
Boolean harvestingEnabled = setting.isHarvestingEnabled();
118+
if(harvestingEnabled == Boolean.TRUE)
119+
ClickGuiIcons.drawCheck(context, x3, y3, x4, y2, hHarvest, false);
120+
else if(harvestingEnabled == null)
121+
ClickGuiIcons.drawIndeterminateCheck(context, x3, y3, x4, y2,
122+
hHarvest, false);
123+
Boolean replantingEnabled = setting.isReplantingEnabled();
124+
if(replantingEnabled == Boolean.TRUE)
125+
ClickGuiIcons.drawCheck(context, x5, y3, x6, y2, hReplant, false);
126+
else if(replantingEnabled == null)
127+
ClickGuiIcons.drawIndeterminateCheck(context, x5, y3, x6, y2,
128+
hReplant, false);
129+
130+
// text
131+
String name = setting.getName();
132+
context.drawText(TR, name, x3 + 2, y1 + 3, GUI.getTxtColor(), false);
133+
context.drawText(TR, HARVEST, x4 + 2, y3 + 2, GUI.getTxtColor(), false);
134+
context.drawText(TR, REPLANT, x6 + 2, y3 + 2, GUI.getTxtColor(), false);
135+
}
136+
137+
private int getFillColor(boolean hovering)
138+
{
139+
float opacity = GUI.getOpacity() * (hovering ? 1.5F : 1);
140+
return RenderUtils.toIntColor(GUI.getBgColor(), opacity);
141+
}
142+
143+
@Override
144+
public int getDefaultWidth()
145+
{
146+
int nameWidth = TR.getWidth(setting.getName());
147+
int boxesWidth =
148+
2 * BOX_SIZE + TR.getWidth(HARVEST) + TR.getWidth(REPLANT) + 6;
149+
return ICON_SIZE + Math.max(nameWidth, boxesWidth);
150+
}
151+
152+
@Override
153+
public int getDefaultHeight()
154+
{
155+
return ICON_SIZE;
156+
}
157+
}

src/main/java/net/wurstclient/hacks/autofarm/AutoFarmPlantType.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import net.minecraft.item.Item;
1515
import net.minecraft.util.math.BlockPos;
1616
import net.wurstclient.settings.PlantTypeSetting;
17-
import net.wurstclient.settings.Setting;
1817

1918
public abstract class AutoFarmPlantType
2019
{
@@ -35,7 +34,7 @@ public final boolean isReplantingEnabled()
3534
return setting.isReplantingEnabled();
3635
}
3736

38-
public final Stream<Setting> getSettings()
37+
public final Stream<PlantTypeSetting> getSettings()
3938
{
4039
return Stream.of(setting);
4140
}

src/main/java/net/wurstclient/hacks/autofarm/AutoFarmPlantTypeManager.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import net.minecraft.util.math.BlockPos;
1515
import net.wurstclient.hacks.autofarm.plants.*;
1616
import net.wurstclient.settings.Setting;
17+
import net.wurstclient.settings.ToggleAllPlantTypesSetting;
1718
import net.wurstclient.util.BlockUtils;
1819

1920
public final class AutoFarmPlantTypeManager
@@ -45,6 +46,10 @@ public final class AutoFarmPlantTypeManager
4546
netherWartType, pitcherPlantType, potatoesType, pumpkinType,
4647
sugarCaneType, sweetBerryPlantType, torchflowerType, wheatType);
4748

49+
public final ToggleAllPlantTypesSetting toggleAllSetting =
50+
new ToggleAllPlantTypesSetting("All plant types",
51+
plantTypes.stream().flatMap(AutoFarmPlantType::getSettings));
52+
4853
public AutoFarmPlantType getReplantingSpotType(BlockPos pos)
4954
{
5055
BlockState state = BlockUtils.getState(pos);
@@ -71,6 +76,7 @@ public boolean shouldHarvestByInteracting(BlockPos pos)
7176

7277
public Stream<Setting> getSettings()
7378
{
74-
return plantTypes.stream().flatMap(AutoFarmPlantType::getSettings);
79+
return Stream.concat(Stream.of(toggleAllSetting),
80+
plantTypes.stream().flatMap(AutoFarmPlantType::getSettings));
7581
}
7682
}

src/main/java/net/wurstclient/hacks/templatetool/states/ChooseNameState.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ public void tick()
118118
if(nameField.getText().isEmpty())
119119
hack.setFile(null);
120120
else
121-
{
122121
try
123122
{
124123
Path folder = WURST.getHax().autoBuildHack.getFolder();
@@ -129,7 +128,6 @@ public void tick()
129128
{
130129
hack.setFile(null);
131130
}
132-
}
133131

134132
doneButton.active = hack.getFile() != null;
135133
}

src/main/java/net/wurstclient/settings/PlantTypeSetting.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public PlantTypeSetting(String name, WText description, Item icon,
3939
super(name, description);
4040
this.icon = new ItemStack(icon);
4141
this.harvest = harvest;
42-
this.harvestByDefault = harvest;
42+
harvestByDefault = harvest;
4343
this.replant = replant;
44-
this.replantByDefault = replant;
44+
replantByDefault = replant;
4545
}
4646

4747
public PlantTypeSetting(String name, String descriptionKey, Item icon,
@@ -82,17 +82,27 @@ public boolean isReplantingEnabledByDefault()
8282
}
8383

8484
public void setHarvestingEnabled(boolean harvest)
85+
{
86+
setHarvestingEnabledWithoutSaving(harvest);
87+
WurstClient.INSTANCE.saveSettings();
88+
}
89+
90+
void setHarvestingEnabledWithoutSaving(boolean harvest)
8591
{
8692
this.harvest = harvest;
8793
update();
88-
WurstClient.INSTANCE.saveSettings();
8994
}
9095

9196
public void setReplantingEnabled(boolean replant)
97+
{
98+
setReplantingEnabledWithoutSaving(replant);
99+
WurstClient.INSTANCE.saveSettings();
100+
}
101+
102+
void setReplantingEnabledWithoutSaving(boolean replant)
92103
{
93104
this.replant = replant;
94105
update();
95-
WurstClient.INSTANCE.saveSettings();
96106
}
97107

98108
public void toggleHarvestingEnabled()

0 commit comments

Comments
 (0)