Skip to content

Commit 90b52b4

Browse files
Add ChorusFruitPlantType
1 parent dcb5f20 commit 90b52b4

File tree

2 files changed

+114
-5
lines changed

2 files changed

+114
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public final class AutoFarmPlantTypeManager
2424
public final BeetrootsPlantType beetrootsType = new BeetrootsPlantType();
2525
public final CactusPlantType cactusType = new CactusPlantType();
2626
public final CarrotsPlantType carrotsType = new CarrotsPlantType();
27+
public final ChorusFruitPlantType chorusFruitType =
28+
new ChorusFruitPlantType();
2729
public final CocoaBeanPlantType cocoaBeanType = new CocoaBeanPlantType();
2830
public final GlowBerryPlantType glowBerryType = new GlowBerryPlantType();
2931
public final KelpPlantType kelpType = new KelpPlantType();
@@ -44,11 +46,12 @@ public final class AutoFarmPlantTypeManager
4446
new WeepingVinesPlantType();
4547
public final WheatPlantType wheatType = new WheatPlantType();
4648

47-
public final List<AutoFarmPlantType> plantTypes = List.of(amethystType,
48-
bambooType, beetrootsType, cactusType, carrotsType, cocoaBeanType,
49-
glowBerryType, kelpType, melonType, netherWartType, pitcherPlantType,
50-
potatoesType, pumpkinType, sugarCaneType, sweetBerryPlantType,
51-
torchflowerType, twistingVinesType, weepingVinesType, wheatType);
49+
public final List<AutoFarmPlantType> plantTypes =
50+
List.of(amethystType, bambooType, beetrootsType, cactusType,
51+
carrotsType, chorusFruitType, cocoaBeanType, glowBerryType,
52+
kelpType, melonType, netherWartType, pitcherPlantType, potatoesType,
53+
pumpkinType, sugarCaneType, sweetBerryPlantType, torchflowerType,
54+
twistingVinesType, weepingVinesType, wheatType);
5255

5356
public final ToggleAllPlantTypesSetting toggleAllSetting =
5457
new ToggleAllPlantTypesSetting("All plant types",
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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.hacks.autofarm.plants;
9+
10+
import java.util.EnumMap;
11+
import java.util.HashSet;
12+
import java.util.Map;
13+
import java.util.Map.Entry;
14+
15+
import com.google.common.collect.Maps;
16+
17+
import net.minecraft.block.BlockState;
18+
import net.minecraft.block.Blocks;
19+
import net.minecraft.block.ChorusFlowerBlock;
20+
import net.minecraft.block.ConnectingBlock;
21+
import net.minecraft.item.Item;
22+
import net.minecraft.item.Items;
23+
import net.minecraft.state.property.BooleanProperty;
24+
import net.minecraft.util.math.BlockPos;
25+
import net.minecraft.util.math.Direction;
26+
import net.wurstclient.hacks.autofarm.AutoFarmPlantType;
27+
import net.wurstclient.settings.PlantTypeSetting;
28+
import net.wurstclient.util.BlockUtils;
29+
30+
public final class ChorusFruitPlantType extends AutoFarmPlantType
31+
{
32+
private static final EnumMap<Direction, BooleanProperty> CHORUS_GROWING_DIRECTIONS =
33+
Maps.newEnumMap(Map.of(Direction.NORTH, ConnectingBlock.NORTH,
34+
Direction.SOUTH, ConnectingBlock.SOUTH, Direction.WEST,
35+
ConnectingBlock.WEST, Direction.EAST, ConnectingBlock.EAST,
36+
Direction.UP, ConnectingBlock.UP));
37+
38+
@Override
39+
public final boolean isReplantingSpot(BlockPos pos, BlockState state)
40+
{
41+
return (state.isOf(Blocks.CHORUS_FLOWER)
42+
|| state.isOf(Blocks.CHORUS_PLANT)) && hasPlantingSurface(pos);
43+
}
44+
45+
@Override
46+
public final boolean hasPlantingSurface(BlockPos pos)
47+
{
48+
return BlockUtils.getState(pos.down()).isOf(Blocks.END_STONE);
49+
}
50+
51+
@Override
52+
public Item getSeedItem()
53+
{
54+
return Items.CHORUS_FLOWER;
55+
}
56+
57+
@Override
58+
public boolean shouldHarvestByMining(BlockPos pos, BlockState state)
59+
{
60+
if(state.isOf(Blocks.CHORUS_FLOWER)
61+
&& state.get(ChorusFlowerBlock.AGE, 0) == ChorusFlowerBlock.MAX_AGE)
62+
return true;
63+
64+
if(!state.isOf(Blocks.CHORUS_PLANT))
65+
return false;
66+
67+
return !hasAttachedFlowers(pos, state, new HashSet<>());
68+
}
69+
70+
private boolean hasAttachedFlowers(BlockPos pos, BlockState state,
71+
HashSet<BlockPos> visited)
72+
{
73+
// If the plant is unreasonably large, just assume there's a flower
74+
// somewhere so we don't harvest it
75+
if(visited.size() > 1000)
76+
return true;
77+
78+
if(!visited.add(pos))
79+
return false;
80+
81+
for(Entry<Direction, BooleanProperty> entry : CHORUS_GROWING_DIRECTIONS
82+
.entrySet())
83+
{
84+
if(!state.get(entry.getValue(), false))
85+
continue;
86+
87+
BlockPos neighborPos = pos.offset(entry.getKey());
88+
BlockState neighborState = BlockUtils.getState(neighborPos);
89+
if(neighborState.isOf(Blocks.CHORUS_FLOWER))
90+
return true;
91+
92+
if(neighborState.isOf(Blocks.CHORUS_PLANT)
93+
&& hasAttachedFlowers(neighborPos, neighborState, visited))
94+
return true;
95+
}
96+
97+
return false;
98+
}
99+
100+
@Override
101+
protected PlantTypeSetting createSetting()
102+
{
103+
return new PlantTypeSetting("Chorus Fruit", Items.CHORUS_FRUIT, true,
104+
true);
105+
}
106+
}

0 commit comments

Comments
 (0)