Skip to content

Commit

Permalink
Auto Pest Exchange:
Browse files Browse the repository at this point in the history
 = Fixes and changes. Remove your current desk pos and let macro set it automatically

Auto Repellent:
 = Fixes

PD OTT:
 + Additional logs for debug purpose

Rotation Handler:
 = Potential fix for not properly setting the yaw/pitch at the end. A fix for PD OTT

Visitors Macro:
 = Pathfinder and non pathfinder tweaks
  • Loading branch information
May2Beez committed Mar 23, 2024
1 parent 649b861 commit d5ada56
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 270 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.5.6
version=2.5.7
shouldRelease=true
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ else if (testFailsafeTypeSelected != 6)

//<editor-fold desc="Pests Destroyer Main">
@Switch(
name = "Enable Pests Destroyer (USE AT YOUR OWN RISK)", category = PESTS_DESTROYER, subcategory = "Pests Destroyer",
name = "Enable Pests Destroyer", category = PESTS_DESTROYER, subcategory = "Pests Destroyer",
description = "Destroys pests"
)
public static boolean enablePestsDestroyer = false;
Expand Down Expand Up @@ -1356,6 +1356,19 @@ public static void triggerManuallyAutoPestExchange() {
+ FarmHelperConfig.pestExchangeDeskY + ", "
+ FarmHelperConfig.pestExchangeDeskZ);
};

@Button(
name = "Reset the pest exchange location", category = AUTO_PEST_EXCHANGE, subcategory = "Auto Pest Exchange",
description = "Resets the pest exchange location",
text = "Reset desk"
)
public static Runnable resetPestExchangeLocation = () -> {
pestExchangeDeskX = 0;
pestExchangeDeskY = 0;
pestExchangeDeskZ = 0;
LogUtils.sendSuccess("[Auto Pest Exchange] Reset the pest exchange location");
};

@Number(
name = "Pest Exchange Desk X", category = AUTO_PEST_EXCHANGE, subcategory = "Auto Pest Exchange",
min = -300, max = 300
Expand Down Expand Up @@ -1889,6 +1902,12 @@ public enum SPRAYONATOR_ITEM {
)
public static boolean jacobContestCurrentCropsOnly = true;

@Switch(
name = "Show Debug logs about PD OTT", category = EXPERIMENTAL, subcategory = "Debug",
description = "Shows debug logs about PD OTT"
)
public static boolean showDebugLogsAboutPDOTT = false;

//</editor-fold>
//</editor-fold>

Expand Down
360 changes: 133 additions & 227 deletions src/main/java/com/jelly/farmhelperv2/feature/impl/AutoPestExchange.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class AutoRepellent implements IFeature {
private static AutoRepellent instance;

public final static Clock repellentFailsafeClock = new Clock();
private final Pattern repellentRegex = Pattern.compile("(\\d+?)m?\\s?(\\d+)s");
private final Pattern repellentRegex = Pattern.compile("(\\d+m\\s)?(\\d+s)");

public static AutoRepellent getInstance() {
if (instance == null) {
Expand Down Expand Up @@ -391,17 +391,18 @@ public void onDrawGui(DrawScreenAfterEvent event) {

@SubscribeEvent(receiveCanceled = true)
public void onChatReceived(ClientChatReceivedEvent event) {
if (!isRunning()) return;
String message = StringUtils.stripControlCodes(event.message.getUnformattedText()); // just to be sure lol
if (state == State.CONFIRM_BUY) {
if (isRunning() && state == State.CONFIRM_BUY) {
if (message.startsWith("You bought Pest")) {
state = State.CLOSE_GUI;
delay.schedule(300 + (long) (Math.random() * 300));
}
} else if (state == State.WAIT_FOR_REPELLENT) {
if (message.startsWith("YUM! Pests will now spawn")) {
repellentFailsafeClock.schedule(TimeUnit.MILLISECONDS.convert(1, TimeUnit.HOURS) + 5_000);
LogUtils.sendDebug("Repellent used!");
}
if (message.startsWith("YUM! Pests will now spawn")) {
repellentFailsafeClock.schedule(TimeUnit.MILLISECONDS.convert(1, TimeUnit.HOURS) + 5_000);
GameStateHandler.getInstance().setPestRepellentState(GameStateHandler.BuffState.ACTIVE);
LogUtils.sendDebug("Repellent used!");
if (isRunning()) {
if (this.hotbarSlot == -1) {
state = State.NONE;
LogUtils.sendWarning("[Auto Repellent] Successfully used Repellent! Resuming macro...");
Expand All @@ -411,19 +412,34 @@ public void onChatReceived(ClientChatReceivedEvent event) {
moveRepellentState = MoveRepellentState.PUT_ITEM_BACK_PICKUP;
}
delay.schedule(2_000);
} else if (message.startsWith("You already have this effect active!")) {
state = State.END;
Matcher matcher = repellentRegex.matcher(message);
if (matcher.find()) {
int minutes = Integer.parseInt(matcher.group(1));
int seconds = Integer.parseInt(matcher.group(2));
}
} else if (message.startsWith("You already have this effect active!")) {
Matcher matcher = repellentRegex.matcher(message);
if (matcher.find()) {
try {
int minutes;
int seconds;
if (matcher.group(1).contains("m")) {
minutes = Integer.parseInt(matcher.group(1).replace("m", "").trim());
seconds = Integer.parseInt(matcher.group(2).replace("s", "").trim());
} else {
minutes = 0;
seconds = Integer.parseInt(matcher.group(1).replace("s", "").trim());
}

long totalMilliseconds = (minutes * 60L + seconds) * 1000;
long totalMilliseconds = (minutes * 60L + seconds) * 1000 + 5_000;
repellentFailsafeClock.schedule(totalMilliseconds);
} else {
LogUtils.sendError("Failed to get repellent remaining time.");
GameStateHandler.getInstance().setPestRepellentState(GameStateHandler.BuffState.FAILSAFE);
} catch (NumberFormatException e) {
LogUtils.sendError("Failed to parse repellent remaining time.");
e.printStackTrace();
}
} else {
LogUtils.sendError("Failed to get repellent remaining time.");
}

if (isRunning()) {
state = State.END;
LogUtils.sendWarning("[Auto Repellent] Already used Repellent! Resuming macro...");
stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1074,21 +1074,21 @@ public void onRender(RenderWorldLastEvent event) {
if (FarmHelperConfig.pestsESP) {
Color color = FarmHelperConfig.pestsESPColor.toJavaColor();
Vec3 entityPos = new Vec3(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ);
boolean isInVacuumRange = mc.thePlayer.getPositionEyes(1).distanceTo(entityPos) < currentVacuumRange;
double distance = mc.thePlayer.getPositionEyes(1).distanceTo(entityPos);
boolean isInVacuumRange = distance < currentVacuumRange;
if (isInVacuumRange) {
color = new Color(color.getRed(), 255, color.getBlue(), Math.min(50, color.getAlpha()));
}
float distance = mc.thePlayer.getDistanceToEntity(entity);
if (distance > 5) {
try {
EnumChatFormatting distanceColor = distance > currentVacuumRange ? EnumChatFormatting.RED : EnumChatFormatting.GREEN;
ItemStack itemStack = ((EntityArmorStand) entity).getEquipmentInSlot(4);
String pestName = this.pests.stream().filter(pest -> itemStack.getTagCompound().toString().contains(pest.getSecond())).findFirst().get().getFirst();
RenderUtils.drawText(pestName, entity.posX, entity.posY + entity.getEyeHeight() + 0.65 + 0.5, entity.posZ, 1 + Math.min((distance / 20), 3));
RenderUtils.drawText(pestName + String.format(distanceColor + " %.1fm", distance), entity.posX, entity.posY + entity.getEyeHeight() + 0.65 + 0.5, entity.posZ, (float) (1 + Math.min((distance / 20f), 2f)));
} catch (Exception ignored) {
}
}
RenderUtils.drawBox(boundingBox, color);

}
if (FarmHelperConfig.pestsTracers) {
RenderUtils.drawTracer(new Vec3(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ), FarmHelperConfig.pestsTracersColor.toJavaColor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;
Expand Down Expand Up @@ -177,8 +178,9 @@ public void onTickExecution(TickEvent.PlayerTickEvent event) {
private Optional<Entity> getPest(boolean start) {
List<Entity> entities = PestsDestroyer.getInstance().getPestsLocations();
float vacuumRange = PestsDestroyer.getInstance().getCurrentVacuumRange();
this.entities.clear();
return entities.stream()
List<Tuple<Entity, Double>> temp = new ArrayList<>();

Optional<Entity> opt = entities.stream()
.filter(e -> {
Vec3 entityPosition = new Vec3(e.posX, e.posY + e.getEyeHeight(), e.posZ);
Vec3 playerPosition = mc.thePlayer.getPositionEyes(1);
Expand All @@ -190,19 +192,24 @@ private Optional<Entity> getPest(boolean start) {

float yaw = (float) Math.toDegrees(Math.atan2(zDiff, xDiff)) - 90F;
float yawDiff = Math.abs(MathHelper.wrapAngleTo180_float(mc.thePlayer.rotationYaw) - yaw);
if (FarmHelperConfig.showDebugLogsAboutPDOTT)
LogUtils.sendDebug("Entity Pos: " + e.getPositionVector() + " | CurrenYaw: " + MathHelper.wrapAngleTo180_float(mc.thePlayer.rotationYaw) + " | YawNeeded: " + yaw + " | YawDiff: " + yawDiff + " | Dist: " + dist);
returnResult = dist <= vacuumRange - 0.5 && yawDiff <= FarmHelperConfig.pestsDestroyerOnTheTrackFOV / 2f;
} else {
returnResult = dist <= vacuumRange - 0.5;
}
if (returnResult) {
this.entities.add(new Tuple<>(e, dist));
temp.add(new Tuple<>(e, dist));
}
return returnResult;
}).min((e1, e2) -> {
double d1 = e1.getDistanceToEntity(mc.thePlayer);
double d2 = e2.getDistanceToEntity(mc.thePlayer);
return Double.compare(d1, d2);
});
this.entities.clear();
this.entities.addAll(temp);
return opt;
}

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,8 @@ private void onVisitorsState() {
return;
}
LogUtils.sendDebug("Position of visitor: " + result.entityCharacter.getPositionEyes(1));
if (mc.thePlayer.getDistanceToEntity(result.entityCharacter) > 2.5) {
Vec3 closestVec = PlayerUtils.getClosestVecAround(result.entityCharacter, 1.5);
if (mc.thePlayer.getDistanceToEntity(result.entityCharacter) > 3) {
Vec3 closestVec = PlayerUtils.getClosestVecAround(result.entityCharacter, 1.5, 45, 45);
if (closestVec == null) {
LogUtils.sendError("[Visitors Macro] Couldn't find a position to get closer");
stop();
Expand All @@ -714,7 +714,7 @@ private void onVisitorsState() {
// BaritoneHandler.walkCloserToBlockPos(result.entityCharacter.getPosition(), 1);
FlyPathFinderExecutor.getInstance().setSprinting(false);
FlyPathFinderExecutor.getInstance().setDontRotate(true);
FlyPathFinderExecutor.getInstance().findPath(closestVec.addVector(0, 1.4, 0), false, true);
FlyPathFinderExecutor.getInstance().findPath(closestVec.addVector(0, 1.8, 0), false, true);
rotation.easeTo(
new RotationConfiguration(
new Target(result.entityCharacter),
Expand Down Expand Up @@ -1024,8 +1024,8 @@ private void onVisitorsState() {
}
}
LogUtils.sendDebug("Position of visitor: " + currentCharacter.get().getPositionEyes(1));
if (mc.thePlayer.getDistanceToEntity(currentCharacter.get()) > 2.5) {
Vec3 closestVec = PlayerUtils.getClosestVecAround(currentCharacter.get(), 1.5);
if (mc.thePlayer.getDistanceToEntity(currentCharacter.get()) > 3) {
Vec3 closestVec = PlayerUtils.getClosestVecAround(currentCharacter.get(), 1.5, 45, 45);
if (closestVec == null) {
LogUtils.sendError("[Visitors Macro] Couldn't find a position to get closer");
stop();
Expand All @@ -1036,7 +1036,7 @@ private void onVisitorsState() {
// BaritoneHandler.walkCloserToBlockPos(currentCharacter.get().getPosition(), 1);
FlyPathFinderExecutor.getInstance().setSprinting(false);
FlyPathFinderExecutor.getInstance().setDontRotate(true);
FlyPathFinderExecutor.getInstance().findPath(closestVec.addVector(0, 1.4, 0), false, true);
FlyPathFinderExecutor.getInstance().findPath(closestVec.addVector(0, 1.8, 0), false, true);
rotation.easeTo(
new RotationConfiguration(
new Target(currentCharacter.get()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class GameStateHandler {
@Getter
private BuffState godPotState = BuffState.UNKNOWN;
@Getter
@Setter
private BuffState pestRepellentState = BuffState.UNKNOWN;
@Getter
private BuffState pestHunterBonus = BuffState.UNKNOWN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,10 @@ public void onRender(RenderWorldLastEvent event) {
if (configuration.callback().isPresent()) {
configuration.callback().get().run();
} else { // No callback, just reset
if (Math.abs(mc.thePlayer.rotationYaw - targetRotation.getYaw()) < 0.1 && Math.abs(mc.thePlayer.rotationPitch - targetRotation.getPitch()) < 0.1) {
if (Math.abs(mc.thePlayer.rotationYaw - targetRotation.getYaw()) < 0.1) {
mc.thePlayer.rotationYaw = targetRotation.getYaw();
}
if (Math.abs(mc.thePlayer.rotationPitch - targetRotation.getPitch()) < 0.1) {
mc.thePlayer.rotationPitch = targetRotation.getPitch();
}
reset();
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/jelly/farmhelperv2/hud/DebugHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.jelly.farmhelperv2.failsafe.impl.LowerAvgBpsFailsafe;
import com.jelly.farmhelperv2.feature.FeatureManager;
import com.jelly.farmhelperv2.feature.impl.*;
import com.jelly.farmhelperv2.handler.BaritoneHandler;
import com.jelly.farmhelperv2.handler.GameStateHandler;
import com.jelly.farmhelperv2.handler.MacroHandler;
import com.jelly.farmhelperv2.util.helper.FlyPathfinder;
Expand Down Expand Up @@ -49,6 +48,7 @@ protected void getLines(List<String> lines, boolean example) {
lines.add(" God Pot: " + GameStateHandler.getInstance().getGodPotState());
lines.add(" Cookie: " + GameStateHandler.getInstance().getCookieBuffState());
lines.add(" Pest Hunter: " + GameStateHandler.getInstance().getPestHunterBonus());
lines.add(" Pest Repellent: " + GameStateHandler.getInstance().getPestRepellentState());
lines.add("Location: " + GameStateHandler.getInstance().getLocation());
// lines.add("Pests in Vacuum: " + GameStateHandler.getInstance().getPestsFromVacuum());
MacroHandler.getInstance().getCurrentMacro().ifPresent(macro -> {
Expand Down Expand Up @@ -147,9 +147,8 @@ protected void getLines(List<String> lines, boolean example) {
lines.add(" Forward: " + FlyPathfinder.getInstance().isDeceleratingForward);
lines.add(" Backward: " + FlyPathfinder.getInstance().isDeceleratingBackward);
}
if (AutoSprayonator.getInstance().isToggled()) {
if (AutoSprayonator.getInstance().isRunning()) {
lines.add("Auto Sprayonator");
lines.add(" Running: " + AutoSprayonator.getInstance().isRunning());
lines.add(" Enable Delay: " + AutoSprayonator.getInstance().getEnableDelay().getRemainingTime());
lines.add(" State: " + AutoSprayonator.getInstance().getSprayState());
lines.add(" Item: " + AutoSprayonator.getInstance().getSprayItem());
Expand All @@ -167,11 +166,9 @@ protected void getLines(List<String> lines, boolean example) {
}
if (AutoPestExchange.getInstance().isRunning()) {
lines.add("Auto Pest Hunter");
lines.add(" State: " + AutoPestExchange.getInstance().getState());
lines.add(" State: " + AutoPestExchange.getInstance().getNewState());
lines.add(" Clock: " + AutoPestExchange.getInstance().getDelayClock().getRemainingTime());
lines.add(" Stuck clock: " + AutoPestExchange.getInstance().getStuckClock().getRemainingTime());
lines.add(" isPathing: " + BaritoneHandler.isPathing());
lines.add(" isWalkingToGoalBlock: " + BaritoneHandler.isWalkingToGoalBlock());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ public void onTickNeededYaw(TickEvent.ClientTickEvent event) {
Multithreading.schedule(() -> KeyBindUtils.stopMovement(true), 500, TimeUnit.MILLISECONDS);
return;
}
Vec3 lastElem = copyPath.get(copyPath.size() - 1);
if (targetEntity != null) {
float velocity = (float) Math.sqrt(mc.thePlayer.motionX * mc.thePlayer.motionX + mc.thePlayer.motionZ * mc.thePlayer.motionZ);
if (targetEntity instanceof EntityArmorStand) {
Expand All @@ -378,12 +379,12 @@ public void onTickNeededYaw(TickEvent.ClientTickEvent event) {
targetPos = targetPos.addVector(targetEntity.motionX * 1.3, targetEntity.motionY, targetEntity.motionZ * 1.3);
}
float distance = (float) mc.thePlayer.getPositionVector().distanceTo(targetPos);
float distancePath = (float) mc.thePlayer.getPositionVector().distanceTo(copyPath.get(copyPath.size() - 1));
float distancePath = (float) mc.thePlayer.getPositionVector().distanceTo(lastElem);
System.out.println("Velo: " + velocity);
System.out.println("TargetPos: " + targetPos);
System.out.println("Distance: " + distance);
System.out.println("EntityVelo: " + entityVelocity);
if (willArriveAtDestinationAfterStopping(copyPath.get(copyPath.size() - 1)) && entityVelocity < 0.15) {
if (willArriveAtDestinationAfterStopping(lastElem) && entityVelocity < 0.15) {
System.out.println("Will arrive");
stop();
return;
Expand All @@ -392,13 +393,13 @@ public void onTickNeededYaw(TickEvent.ClientTickEvent event) {
stop();
return;
}
} else if (willArriveAtDestinationAfterStopping(copyPath.get(copyPath.size() - 1))) {
} else if (willArriveAtDestinationAfterStopping(lastElem) || mc.thePlayer.getDistance(lastElem.xCoord, lastElem.yCoord, lastElem.zCoord) < 0.3) {
System.out.println("stopping");
stop();
return;
}
if (!mc.thePlayer.capabilities.allowFlying) {
Vec3 lastWithoutY = new Vec3(copyPath.get(copyPath.size() - 1).xCoord, current.yCoord, copyPath.get(copyPath.size() - 1).zCoord);
Vec3 lastWithoutY = new Vec3(lastElem.xCoord, current.yCoord, lastElem.zCoord);
if (current.distanceTo(lastWithoutY) < 1) {
stop();
LogUtils.sendSuccess("Arrived at destination");
Expand Down
Loading

0 comments on commit d5ada56

Please sign in to comment.