Skip to content

Commit

Permalink
Fix: #11 (theoretically)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wudji committed May 15, 2024
1 parent e9a4b5b commit 57d188e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/main/java/troy/autofish/Autofish.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import troy.autofish.monitor.FishMonitorMPSound;
import troy.autofish.scheduler.ActionType;

import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -135,7 +136,9 @@ public void handleChat(GameMessageS2CPacket packet) {

public void catchFish() {
if(!modAutofish.getScheduler().isRecastQueued()) { //prevents double reels
detectOpenWater(client.player.fishHook);
if (client.player != null) {
detectOpenWater(client.player.fishHook);
}
//queue actions
queueRodSwitch();
queueRecast();
Expand Down Expand Up @@ -190,15 +193,15 @@ private void detectOpenWater(FishingBobberEntity bobber){
)))){
// didn't pass the check
if(!alreadyAlertOP){
bobber.getPlayerOwner().sendMessage(Text.translatable("info.autofish.open_water_detection.fail"),true);
Objects.requireNonNull(bobber.getPlayerOwner()).sendMessage(Text.translatable("info.autofish.open_water_detection.fail"),true);
alreadyAlertOP = true;
alreadyPassOP = false;
}
flag = false;
}
}
if(flag && !alreadyPassOP) {
bobber.getPlayerOwner().sendMessage(Text.translatable("info.autofish.open_water_detection.success"),true);
Objects.requireNonNull(bobber.getPlayerOwner()).sendMessage(Text.translatable("info.autofish.open_water_detection.success"),true);
alreadyPassOP = true;
alreadyAlertOP = false;
}
Expand Down Expand Up @@ -242,8 +245,11 @@ public void switchToFirstRod(ClientPlayerEntity player) {
public void useRod() {
if(client.player != null && client.world != null) {
Hand hand = getCorrectHand();
ActionResult actionResult = client.interactionManager.interactItem(client.player, hand);
if (actionResult.isAccepted()) {
ActionResult actionResult = null;
if (client.interactionManager != null) {
actionResult = client.interactionManager.interactItem(client.player, hand);
}
if (actionResult != null && actionResult.isAccepted()) {
if (actionResult.shouldSwingHand()) {
client.player.swingHand(hand);
}
Expand All @@ -258,12 +264,15 @@ public boolean isHoldingFishingRod() {

private Hand getCorrectHand() {
if (!modAutofish.getConfig().isMultiRod()) {
if (isItemFishingRod(client.player.getOffHandStack().getItem())) return Hand.OFF_HAND;
if (client.player != null && isItemFishingRod(client.player.getOffHandStack().getItem()))
return Hand.OFF_HAND;
}
return Hand.MAIN_HAND;
}

private ItemStack getHeldItem() {
if (client.player == null) return ItemStack.EMPTY;

if (!modAutofish.getConfig().isMultiRod()) {
if (isItemFishingRod(client.player.getOffHandStack().getItem()))
return client.player.getOffHandStack();
Expand Down

0 comments on commit 57d188e

Please sign in to comment.