Skip to content

Commit

Permalink
+ Added support for SDS mushroom farm
Browse files Browse the repository at this point in the history
  • Loading branch information
May2Beez authored Dec 27, 2023
2 parents 957742e + 91ccdda commit ba3864c
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ baseGroup=com.jelly.farmhelperv2
mcVersion=1.8.9
modid=farmhelperv2
modName=FarmHelper
version=2.2.9-pre4
version=2.3.0
shouldRelease=true
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class FarmHelperConfig extends Config {
"S Shape - Cocoa Beans (Left/Right)", // 8
"S Shape - Mushroom (45°)", // 9
"S Shape - Mushroom (30° with rotations)", // 10
"S Shape - Mushroom SDS" // 11
}, size = 2
)
public static int macroType = 0;
Expand Down Expand Up @@ -1798,7 +1799,8 @@ public enum MacroEnum {
S_COCOA_BEANS,
S_COCOA_BEANS_LEFT_RIGHT,
S_MUSHROOM,
S_MUSHROOM_ROTATE
S_MUSHROOM_ROTATE,
S_MUSHROOM_SDS
}

public enum CropEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public <T extends AbstractMacro> T getMacro() {
return Macros.S_SHAPE_MUSHROOM_MACRO.getMacro();
case S_MUSHROOM_ROTATE:
return Macros.S_SHAPE_MUSHROOM_ROTATE_MACRO.getMacro();
case S_MUSHROOM_SDS:
return Macros.S_SHAPE_MUSHROOM_SDS.getMacro();
default:
throw new IllegalArgumentException("Invalid crop type: " + FarmHelperConfig.macroType);
}
Expand Down Expand Up @@ -389,7 +391,8 @@ public enum Macros {
S_SHAPE_COCOA_BEAN_MACRO(SShapeCocoaBeanMacro.class),
S_SHAPE_SUGARCANE_MACRO(SShapeSugarcaneMacro.class),
S_SHAPE_VERTICAL_CROP_MACRO(SShapeVerticalCropMacro.class),
S_SHAPE_MELON_PUMPKIN_DEFAULT_MACRO(SShapeMelonPumpkinDefaultMacro.class);
S_SHAPE_MELON_PUMPKIN_DEFAULT_MACRO(SShapeMelonPumpkinDefaultMacro.class),
S_SHAPE_MUSHROOM_SDS(SShapeMushroomSDSMacro.class);

private static final Map<Macros, AbstractMacro> macros = new HashMap<>();
private final Class<? extends AbstractMacro> macroClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package com.jelly.farmhelperv2.macro.impl;

import com.jelly.farmhelperv2.config.FarmHelperConfig;
import com.jelly.farmhelperv2.handler.GameStateHandler;
import com.jelly.farmhelperv2.handler.MacroHandler;
import com.jelly.farmhelperv2.macro.AbstractMacro;
import com.jelly.farmhelperv2.util.AngleUtils;
import com.jelly.farmhelperv2.util.BlockUtils;
import com.jelly.farmhelperv2.util.KeyBindUtils;
import com.jelly.farmhelperv2.util.LogUtils;
import com.jelly.farmhelperv2.util.helper.Rotation;
import com.jelly.farmhelperv2.util.helper.RotationConfiguration;

import java.util.Optional;

public class SShapeMushroomSDSMacro extends AbstractMacro {

@Override
public void onEnable() {
super.onEnable();

if (!FarmHelperConfig.customPitch && !isRestoredState()) {
setPitch((float) (6.5f + Math.random() * 1f)); // 6.5 - 7.5
}

if (!FarmHelperConfig.customYaw && !isRestoredState()) {
setYaw(AngleUtils.getClosest());
setClosest90Deg(Optional.of(AngleUtils.getClosest(getYaw())));
}

if (MacroHandler.getInstance().isTeleporting()) return;
setRestoredState(false);
Rotation newRotation = new Rotation((float) (getClosest90Deg().orElse(AngleUtils.getClosest()) + -16 + (Math.random() * 1 - 0.5)), getPitch());
getRotation().easeTo(
new RotationConfiguration(
newRotation,
FarmHelperConfig.getRandomRotationTime(), null
).easeOutBack(true)
);

setYaw(newRotation.getYaw());
}

@Override
public void actionAfterTeleport() {
}

@Override
public void updateState() {
if (getCurrentState() == null)
changeState(State.NONE);

switch (getCurrentState()) {
case LEFT: {
if (GameStateHandler.getInstance().isBackWalkable() && !FarmHelperConfig.alwaysHoldW) {
changeState(State.SWITCHING_LANE);
} else {
if (GameStateHandler.getInstance().isLeftWalkable()) {
changeState(State.LEFT);
} else {
changeState(State.NONE);
}
}
break;
}
case RIGHT: {
if (GameStateHandler.getInstance().isBackWalkable() && !FarmHelperConfig.alwaysHoldW) {
changeState(State.SWITCHING_LANE);
} else {
if (GameStateHandler.getInstance().isRightWalkable()) {
changeState(State.RIGHT);
} else {
changeState(State.NONE);
}
}
break;
}
case DROPPING: {
if (mc.thePlayer.onGround) {
changeState(State.NONE);
} else {
GameStateHandler.getInstance().scheduleNotMoving();
}
break;
}
case NONE: {
changeState(calculateDirection());
break;
}
default:
LogUtils.sendDebug("This shouldn't happen, but it did...");
changeState(State.NONE);
}
}

@Override
public void invokeState() {
if (getCurrentState() == null) return;
switch (getCurrentState()) {
case RIGHT:
KeyBindUtils.holdThese(
mc.gameSettings.keyBindRight,
mc.gameSettings.keyBindAttack
);
break;
case LEFT: {
KeyBindUtils.holdThese(
mc.gameSettings.keyBindLeft,
mc.gameSettings.keyBindAttack
);
break;
}
case SWITCHING_LANE: {
if (!BlockUtils.canWalkThrough(BlockUtils.getRelativeBlockPos(0, 0, -1, getClosest90Deg().orElse(AngleUtils.getClosest())))) {
changeState(State.NONE);
KeyBindUtils.stopMovement();
} else {
KeyBindUtils.holdThese(
mc.gameSettings.keyBindBack,
mc.gameSettings.keyBindAttack
);
}
break;
}
}
}

@Override
public State calculateDirection() {
if (BlockUtils.rightCropIsReady()) {
return State.RIGHT;
} else if (BlockUtils.leftCropIsReady()) {
return State.LEFT;
}

for (int i = 1; i < 180; i++) {
if (!BlockUtils.canWalkThrough(BlockUtils.getRelativeBlockPos(i, 0, 0, getClosest90Deg().orElse(AngleUtils.getClosest())))) {
return State.LEFT;
}
if (!BlockUtils.canWalkThrough(BlockUtils.getRelativeBlockPos(-i, 0, 0, getClosest90Deg().orElse(AngleUtils.getClosest()))))
return State.RIGHT;
}

LogUtils.sendDebug("No direction found");
return State.NONE;
}
}

0 comments on commit ba3864c

Please sign in to comment.