Skip to content

Commit aba3db1

Browse files
Add PlantTypeSetting
1 parent 21aee83 commit aba3db1

35 files changed

+425
-165
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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.PlantTypeSetting;
19+
import net.wurstclient.util.RenderUtils;
20+
import net.wurstclient.util.text.WText;
21+
22+
public final class PlantTypeComponent 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 PlantTypeSetting setting;
32+
33+
public PlantTypeComponent(PlantTypeSetting 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)
95+
GUI.setTooltip(setting.getIcon().getName().getString());
96+
else if(hName)
97+
GUI.setTooltip(setting.getWrappedDescription(200));
98+
else if(hHarvest)
99+
GUI.setTooltip("" + WText.translated("gui.wurst.autofarm.harvest"));
100+
else if(hReplant)
101+
GUI.setTooltip("" + WText.translated("gui.wurst.autofarm.replant"));
102+
103+
// background
104+
int bgColor = getFillColor(false);
105+
context.fill(x1, y1, x2, y3, bgColor);
106+
context.fill(x1, y3, x3, y2, bgColor);
107+
context.fill(x4, y3, x5, y2, bgColor);
108+
context.fill(x6, y3, x2, y2, bgColor);
109+
110+
// icon
111+
RenderUtils.drawItem(context, setting.getIcon(), x1, y1, true);
112+
113+
// boxes
114+
context.fill(x3, y3, x4, y2, getFillColor(hHarvest));
115+
context.fill(x5, y3, x6, y2, getFillColor(hReplant));
116+
int outlineColor = RenderUtils.toIntColor(GUI.getAcColor(), 0.5F);
117+
RenderUtils.drawBorder2D(context, x3, y3, x4, y2, outlineColor);
118+
RenderUtils.drawBorder2D(context, x5, y3, x6, y2, outlineColor);
119+
120+
// checks
121+
if(setting.isHarvestingEnabled())
122+
ClickGuiIcons.drawCheck(context, x3, y3, x4, y2, hHarvest, false);
123+
if(setting.isReplantingEnabled())
124+
ClickGuiIcons.drawCheck(context, x5, y3, x6, y2, hReplant, false);
125+
126+
// text
127+
String name = setting.getName();
128+
context.drawText(TR, name, x3 + 2, y1 + 3, GUI.getTxtColor(), false);
129+
context.drawText(TR, HARVEST, x4 + 2, y3 + 2, GUI.getTxtColor(), false);
130+
context.drawText(TR, REPLANT, x6 + 2, y3 + 2, GUI.getTxtColor(), false);
131+
}
132+
133+
private int getFillColor(boolean hovering)
134+
{
135+
float opacity = GUI.getOpacity() * (hovering ? 1.5F : 1);
136+
return RenderUtils.toIntColor(GUI.getBgColor(), opacity);
137+
}
138+
139+
@Override
140+
public int getDefaultWidth()
141+
{
142+
int nameWidth = TR.getWidth(setting.getName());
143+
int boxesWidth =
144+
(2 * BOX_SIZE) + TR.getWidth(HARVEST) + TR.getWidth(REPLANT) + 6;
145+
return ICON_SIZE + Math.max(nameWidth, boxesWidth);
146+
}
147+
148+
@Override
149+
public int getDefaultHeight()
150+
{
151+
return ICON_SIZE;
152+
}
153+
}

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,31 @@
1313
import net.minecraft.block.BlockState;
1414
import net.minecraft.item.Item;
1515
import net.minecraft.util.math.BlockPos;
16-
import net.wurstclient.settings.CheckboxSetting;
16+
import net.wurstclient.settings.PlantTypeSetting;
17+
import net.wurstclient.settings.Setting;
1718

1819
public abstract class AutoFarmPlantType
1920
{
20-
private final CheckboxSetting harvest;
21-
private final CheckboxSetting replant;
21+
private final PlantTypeSetting setting;
2222

2323
public AutoFarmPlantType()
2424
{
25-
harvest = Objects.requireNonNull(createHarvestSetting());
26-
replant = createReplantSetting();
25+
setting = Objects.requireNonNull(createSetting());
2726
}
2827

2928
public final boolean isHarvestingEnabled()
3029
{
31-
return harvest.isChecked();
30+
return setting.isHarvestingEnabled();
3231
}
3332

3433
public final boolean isReplantingEnabled()
3534
{
36-
return replant != null && replant.isChecked();
35+
return setting.isReplantingEnabled();
3736
}
3837

39-
public final Stream<CheckboxSetting> getSettings()
38+
public final Stream<Setting> getSettings()
4039
{
41-
return Stream.of(harvest, replant).filter(Objects::nonNull);
40+
return Stream.of(setting);
4241
}
4342

4443
/**
@@ -77,7 +76,5 @@ public boolean shouldHarvestByInteracting(BlockPos pos, BlockState state)
7776
return false;
7877
}
7978

80-
protected abstract CheckboxSetting createHarvestSetting();
81-
82-
protected abstract CheckboxSetting createReplantSetting();
79+
protected abstract PlantTypeSetting createSetting();
8380
}

src/main/java/net/wurstclient/hacks/autofarm/plants/AmethystPlantType.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import net.minecraft.item.Items;
1414
import net.minecraft.util.math.BlockPos;
1515
import net.wurstclient.hacks.autofarm.AutoFarmPlantType;
16-
import net.wurstclient.settings.CheckboxSetting;
16+
import net.wurstclient.settings.PlantTypeSetting;
1717

1818
public final class AmethystPlantType extends AutoFarmPlantType
1919
{
@@ -42,14 +42,9 @@ public boolean shouldHarvestByMining(BlockPos pos, BlockState state)
4242
}
4343

4444
@Override
45-
protected CheckboxSetting createHarvestSetting()
45+
protected PlantTypeSetting createSetting()
4646
{
47-
return new CheckboxSetting("Harvest amethyst", true);
48-
}
49-
50-
@Override
51-
protected CheckboxSetting createReplantSetting()
52-
{
53-
return new CheckboxSetting("Replant amethyst", true);
47+
return new PlantTypeSetting("Amethyst", Items.AMETHYST_SHARD, true,
48+
true);
5449
}
5550
}

src/main/java/net/wurstclient/hacks/autofarm/plants/BambooPlantType.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import net.minecraft.registry.tag.BlockTags;
1515
import net.minecraft.util.math.BlockPos;
1616
import net.wurstclient.hacks.autofarm.AutoFarmPlantType;
17-
import net.wurstclient.settings.CheckboxSetting;
17+
import net.wurstclient.settings.PlantTypeSetting;
1818
import net.wurstclient.util.BlockUtils;
1919

2020
public final class BambooPlantType extends AutoFarmPlantType
@@ -57,14 +57,8 @@ public boolean shouldHarvestByMining(BlockPos pos, BlockState state)
5757
}
5858

5959
@Override
60-
protected CheckboxSetting createHarvestSetting()
60+
protected PlantTypeSetting createSetting()
6161
{
62-
return new CheckboxSetting("Harvest bamboo", true);
63-
}
64-
65-
@Override
66-
protected CheckboxSetting createReplantSetting()
67-
{
68-
return new CheckboxSetting("Replant bamboo", true);
62+
return new PlantTypeSetting("Bamboo", Items.BAMBOO, true, true);
6963
}
7064
}

src/main/java/net/wurstclient/hacks/autofarm/plants/BeetrootsPlantType.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import net.minecraft.item.Items;
1515
import net.minecraft.util.math.BlockPos;
1616
import net.wurstclient.hacks.autofarm.AutoFarmPlantType;
17-
import net.wurstclient.settings.CheckboxSetting;
17+
import net.wurstclient.settings.PlantTypeSetting;
1818
import net.wurstclient.util.BlockUtils;
1919

2020
public final class BeetrootsPlantType extends AutoFarmPlantType
@@ -47,14 +47,8 @@ public boolean shouldHarvestByMining(BlockPos pos, BlockState state)
4747
}
4848

4949
@Override
50-
protected CheckboxSetting createHarvestSetting()
50+
protected PlantTypeSetting createSetting()
5151
{
52-
return new CheckboxSetting("Harvest beetroots", true);
53-
}
54-
55-
@Override
56-
protected CheckboxSetting createReplantSetting()
57-
{
58-
return new CheckboxSetting("Replant beetroots", true);
52+
return new PlantTypeSetting("Beetroots", Items.BEETROOT, true, true);
5953
}
6054
}

src/main/java/net/wurstclient/hacks/autofarm/plants/CactusPlantType.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import net.minecraft.util.math.BlockPos;
1717
import net.minecraft.util.math.Direction;
1818
import net.wurstclient.hacks.autofarm.AutoFarmPlantType;
19-
import net.wurstclient.settings.CheckboxSetting;
19+
import net.wurstclient.settings.PlantTypeSetting;
2020
import net.wurstclient.util.BlockUtils;
2121

2222
public final class CactusPlantType extends AutoFarmPlantType
@@ -63,14 +63,8 @@ public boolean shouldHarvestByMining(BlockPos pos, BlockState state)
6363
}
6464

6565
@Override
66-
protected CheckboxSetting createHarvestSetting()
66+
protected PlantTypeSetting createSetting()
6767
{
68-
return new CheckboxSetting("Harvest cactus", true);
69-
}
70-
71-
@Override
72-
protected CheckboxSetting createReplantSetting()
73-
{
74-
return new CheckboxSetting("Replant cactus", true);
68+
return new PlantTypeSetting("Cactus", Items.CACTUS, true, true);
7569
}
7670
}

src/main/java/net/wurstclient/hacks/autofarm/plants/CarrotsPlantType.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import net.minecraft.item.Items;
1515
import net.minecraft.util.math.BlockPos;
1616
import net.wurstclient.hacks.autofarm.AutoFarmPlantType;
17-
import net.wurstclient.settings.CheckboxSetting;
17+
import net.wurstclient.settings.PlantTypeSetting;
1818
import net.wurstclient.util.BlockUtils;
1919

2020
public final class CarrotsPlantType extends AutoFarmPlantType
@@ -47,14 +47,8 @@ public boolean shouldHarvestByMining(BlockPos pos, BlockState state)
4747
}
4848

4949
@Override
50-
protected CheckboxSetting createHarvestSetting()
50+
protected PlantTypeSetting createSetting()
5151
{
52-
return new CheckboxSetting("Harvest carrots", true);
53-
}
54-
55-
@Override
56-
protected CheckboxSetting createReplantSetting()
57-
{
58-
return new CheckboxSetting("Replant carrots", true);
52+
return new PlantTypeSetting("Carrots", Items.CARROT, true, true);
5953
}
6054
}

src/main/java/net/wurstclient/hacks/autofarm/plants/CocoaBeanPlantType.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import net.minecraft.util.math.BlockPos;
1616
import net.minecraft.util.math.Direction;
1717
import net.wurstclient.hacks.autofarm.AutoFarmPlantType;
18-
import net.wurstclient.settings.CheckboxSetting;
18+
import net.wurstclient.settings.PlantTypeSetting;
1919
import net.wurstclient.util.BlockUtils;
2020

2121
public final class CocoaBeanPlantType extends AutoFarmPlantType
@@ -50,14 +50,9 @@ public boolean shouldHarvestByMining(BlockPos pos, BlockState state)
5050
}
5151

5252
@Override
53-
protected CheckboxSetting createHarvestSetting()
53+
protected PlantTypeSetting createSetting()
5454
{
55-
return new CheckboxSetting("Harvest cocoa beans", true);
56-
}
57-
58-
@Override
59-
protected CheckboxSetting createReplantSetting()
60-
{
61-
return new CheckboxSetting("Replant cocoa beans", true);
55+
return new PlantTypeSetting("Cocoa Beans", Items.COCOA_BEANS, true,
56+
true);
6257
}
6358
}

src/main/java/net/wurstclient/hacks/autofarm/plants/GlowBerryPlantType.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import net.minecraft.util.math.Direction;
1616
import net.wurstclient.WurstClient;
1717
import net.wurstclient.hacks.autofarm.AutoFarmPlantType;
18-
import net.wurstclient.settings.CheckboxSetting;
18+
import net.wurstclient.settings.PlantTypeSetting;
1919
import net.wurstclient.util.BlockUtils;
2020

2121
public final class GlowBerryPlantType extends AutoFarmPlantType
@@ -57,14 +57,9 @@ public boolean shouldHarvestByMining(BlockPos pos, BlockState state)
5757
}
5858

5959
@Override
60-
protected CheckboxSetting createHarvestSetting()
60+
protected PlantTypeSetting createSetting()
6161
{
62-
return new CheckboxSetting("Harvest glow berries", true);
63-
}
64-
65-
@Override
66-
protected CheckboxSetting createReplantSetting()
67-
{
68-
return new CheckboxSetting("Replant glow berries", true);
62+
return new PlantTypeSetting("Glow Berries", Items.GLOW_BERRIES, true,
63+
true);
6964
}
7065
}

0 commit comments

Comments
 (0)