Skip to content

Commit

Permalink
= Pests Destroyer - Small bug fix regarding pests on plots display
Browse files Browse the repository at this point in the history
= AntiStuck - Weird crash potential fix
  • Loading branch information
May2Beez committed Dec 19, 2023
1 parent 92e190f commit 353cd2e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 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.6-pre
version=2.2.7-pre
shouldRelease=true
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class AntiStuck implements IFeature {
private boolean enabled = false;
@Setter
private BlockPos intersectingBlockPos = null;
private ArrayList<KeyBinding> oppositeKeys = null;
private ArrayList<KeyBinding> oppositeKeys = new ArrayList<>();

public static AntiStuck getInstance() {
if (instance == null) {
Expand Down Expand Up @@ -225,10 +225,12 @@ public void onTickUnstuck(TickEvent.ClientTickEvent event) {
EnumFacing facing = closestSide.get();
Vec3 movementTarget = getMovementTarget(intersectingBlockPos, facing);
List<KeyBinding> keys = getNeededKeyPresses(mc.thePlayer.getPositionVector(), movementTarget);
oppositeKeys = new ArrayList<>();
oppositeKeys.clear();
for (KeyBinding key : keys) {
oppositeKeys.add(getOppositeKey(key));
}
oppositeKeys.add(mc.gameSettings.keyBindSneak);
oppositeKeys.add(mc.gameSettings.keyBindAttack);
keys.add(mc.gameSettings.keyBindSneak);
keys.add(mc.gameSettings.keyBindAttack);
KeyBindUtils.holdThese(keys.toArray(new KeyBinding[0]));
Expand All @@ -241,7 +243,8 @@ public void onTickUnstuck(TickEvent.ClientTickEvent event) {
delayBetweenMovementsClock.schedule(100 + (int) (Math.random() * 100));
break;
case COME_BACK:
KeyBindUtils.holdThese(oppositeKeys.toArray(new KeyBinding[0]));
if (oppositeKeys != null)
KeyBindUtils.holdThese(oppositeKeys.toArray(new KeyBinding[0]));
unstuckState = UnstuckState.DISABLE;
delayBetweenMovementsClock.schedule(100 + (int) (Math.random() * 100));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1114,31 +1114,29 @@ public void onEntityDeath(LivingDeathEvent event) {
LogUtils.sendError("[Pests Destroyer] Failed to get plot number for entity: " + entity.getName() + " at: " + entity.getPosition());
return;
}
currentEntityTarget.ifPresent(ent -> {
if (ent.equals(entity) || PlayerUtils.getEntityCuttingOtherEntity(ent).equals(entity)) {
Plot plot;
try {
plot = pestsPlotMap.entrySet().stream().filter(entry -> entry.getKey().plotNumber == plotNumber).findFirst().get().getKey();
} catch (Exception e) {
LogUtils.sendError("[Pests Destroyer] Failed to get plot for entity: " + entity.getName() + " at: " + entity.getPosition());
return;
}
if (pestsPlotMap.get(plot) > 1) {
pestsPlotMap.replace(plot, pestsPlotMap.get(plot) - 1);
LogUtils.sendDebug("[Pests Destroyer] Removed 1 pest from plot number: " + plotNumber);
} else {
pestsPlotMap.remove(plot);
LogUtils.sendDebug("[Pests Destroyer] Removed all pests from plot number: " + plotNumber);
}
lastKilledEntity = entity;
currentEntityTarget = Optional.empty();
lastFireworkLocation = Optional.empty();
lastFireworkTime = 0;
KeyBindUtils.stopMovement();
stuckClock.reset();
RotationHandler.getInstance().reset();
delayClock.schedule(500);
}
Plot plot;
try {
plot = pestsPlotMap.entrySet().stream().filter(entry -> entry.getKey().plotNumber == plotNumber).findFirst().get().getKey();
} catch (Exception e) {
LogUtils.sendError("[Pests Destroyer] Failed to get plot for entity: " + entity.getName() + " at: " + entity.getPosition());
return;
}
if (pestsPlotMap.get(plot) > 1) {
pestsPlotMap.replace(plot, pestsPlotMap.get(plot) - 1);
LogUtils.sendDebug("[Pests Destroyer] Removed 1 pest from plot number: " + plotNumber);
} else {
pestsPlotMap.remove(plot);
LogUtils.sendDebug("[Pests Destroyer] Removed all pests from plot number: " + plotNumber);
}
lastKilledEntity = entity;
lastFireworkLocation = Optional.empty();
lastFireworkTime = 0;
currentEntityTarget.ifPresent(e -> {
KeyBindUtils.stopMovement();
currentEntityTarget = Optional.empty();
stuckClock.reset();
RotationHandler.getInstance().reset();
delayClock.schedule(500);
});
}

Expand Down

0 comments on commit 353cd2e

Please sign in to comment.