Skip to content

Commit 7abf97e

Browse files
committed
feat(module): add no break for cane blocks, also unripe nether wart
1 parent bc45504 commit 7abf97e

1 file changed

Lines changed: 31 additions & 3 deletions

File tree

src/main/java/meteordevelopment/meteorclient/systems/modules/player/BetterFarming.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@
2626
import net.minecraft.world.item.Item;
2727
import net.minecraft.world.level.block.Blocks;
2828
import net.minecraft.world.level.block.CropBlock;
29+
import net.minecraft.world.level.block.NetherWartBlock;
2930
import net.minecraft.world.level.block.state.BlockState;
3031

3132
import java.util.ArrayList;
3233

3334
public class BetterFarming extends Module {
3435
private final SettingGroup sgGeneral = settings.getDefaultGroup();
36+
private final SettingGroup sgNoBreak = settings.createGroup("No Break");
3537

3638
// General
3739

@@ -49,19 +51,26 @@ public class BetterFarming extends Module {
4951
.build()
5052
);
5153

52-
private final Setting<Boolean> noBreakUnripe = sgGeneral.add(new BoolSetting.Builder()
54+
private final Setting<Boolean> noBreakUnripe = sgNoBreak.add(new BoolSetting.Builder()
5355
.name("no-break-unripe")
5456
.description("Prevents player from breaking unripe crops.")
5557
.defaultValue(true)
5658
.build()
5759
);
5860

61+
private final Setting<Boolean> noBreakCaneBase = sgNoBreak.add(new BoolSetting.Builder()
62+
.name("no-break-cane-base")
63+
.description("Prevents player from breaking the base of sugarcane and bamboo blocks.")
64+
.defaultValue(true)
65+
.build()
66+
);
67+
5968
public BetterFarming() {
6069
super(Categories.Player, "better-farming", "Improvements for crop farming.");
6170
}
6271

6372
private Item placeItem = null;
64-
private ArrayList<BlockPos> cropPlacements = new ArrayList<>();
73+
private final ArrayList<BlockPos> cropPlacements = new ArrayList<>();
6574
private int blockBreakCooldown = 0;
6675

6776
@EventHandler(priority = EventPriority.HIGH)
@@ -72,6 +81,7 @@ private void onTick(TickEvent.Pre event) {
7281
@EventHandler(priority = EventPriority.HIGH)
7382
private void onStartBreakingBlockEvent(StartBreakingBlockEvent event) {
7483
if (noBreakUnripe.get()) noBreakUnripeBreakEvent(event);
84+
if (noBreakCaneBase.get()) noBreakCaneBaseEvent(event);
7585
if (cropReplace.get()) autoPlaceBreakEvent(event);
7686
}
7787

@@ -88,6 +98,24 @@ private void noBreakUnripeBreakEvent(StartBreakingBlockEvent event) {
8898

8999
event.cancel();
90100
}
101+
102+
if (blockState.getBlock() instanceof NetherWartBlock) {
103+
if (blockState.getValue(NetherWartBlock.AGE) >= NetherWartBlock.MAX_AGE) return;
104+
105+
event.cancel();
106+
}
107+
}
108+
109+
private void noBreakCaneBaseEvent(StartBreakingBlockEvent event) {
110+
BlockState blockState = mc.level.getBlockState(event.blockPos);
111+
BlockState bsBelow = mc.level.getBlockState(event.blockPos.offset(0, -1, 0));
112+
113+
boolean bsIsCane = (blockState.is(Blocks.SUGAR_CANE) || blockState.is(Blocks.BAMBOO));
114+
boolean bsBelowIsCane = (bsBelow.is(Blocks.SUGAR_CANE) || bsBelow.is(Blocks.BAMBOO));
115+
116+
if (!bsIsCane || bsBelowIsCane) return;
117+
118+
event.cancel();
91119
}
92120

93121
private void autoPlaceTick() {
@@ -123,7 +151,7 @@ private void autoPlaceBreakEvent(StartBreakingBlockEvent event) {
123151

124152
BlockState blockState = mc.level.getBlockState(event.blockPos);
125153

126-
if (!blockState.is(BlockTags.CROPS)) return;
154+
if (!(blockState.is(BlockTags.CROPS) || blockState.is(Blocks.NETHER_WART))) return;
127155

128156
if (blockBreakCooldown > 0) {
129157
event.cancel();

0 commit comments

Comments
 (0)