From dc7ec021c04e1fd44d2aace0c197e4dadd4c63b0 Mon Sep 17 00:00:00 2001 From: Wudji <93850120+Wudji@users.noreply.github.com> Date: Wed, 20 Mar 2024 22:54:16 +0800 Subject: [PATCH] Alert user once ... when not fishing in open water --- src/main/java/troy/autofish/Autofish.java | 25 +++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/troy/autofish/Autofish.java b/src/main/java/troy/autofish/Autofish.java index 3738915..48bbb5e 100644 --- a/src/main/java/troy/autofish/Autofish.java +++ b/src/main/java/troy/autofish/Autofish.java @@ -31,7 +31,8 @@ public class Autofish { private MinecraftClient client; private FabricModAutofish modAutofish; private FishMonitorMP fishMonitorMP; - + private boolean alreadyAlertOP = false; + private boolean alreadyPassOP = false; private boolean hookExists = false; private long hookRemovedAt = 0L; @@ -180,18 +181,26 @@ private void detectOpenWater(FishingBobberEntity bobber){ for(int yi = -2; yi <= 2; yi++){ if(!(BlockPos.stream(x - 2, y + yi, z - 2, x + 2, y + yi, z + 2).allMatch((blockPos -> // every block is water - bobber.getEntityWorld().getBlockState(blockPos).getBlock() == Blocks.WATER - )) || BlockPos.stream(x - 2, y + yi, z - 2, x + 2, y + yi, z + 2).allMatch((blockPos -> + bobber.getEntityWorld().getBlockState(blockPos).getBlock() == Blocks.WATER + )) || BlockPos.stream(x - 2, y + yi, z - 2, x + 2, y + yi, z + 2).allMatch((blockPos -> // or every block is air or lily pad - bobber.getEntityWorld().getBlockState(blockPos).getBlock() == Blocks.AIR - || bobber.getEntityWorld().getBlockState(blockPos).getBlock() == Blocks.LILY_PAD + bobber.getEntityWorld().getBlockState(blockPos).getBlock() == Blocks.AIR + || bobber.getEntityWorld().getBlockState(blockPos).getBlock() == Blocks.LILY_PAD )))){ // didn't pass the check - bobber.getPlayerOwner().sendMessage(Text.translatable("info.autofish.open_water_detection.fail"),true); - flag =false; + if(!alreadyAlertOP){ + bobber.getPlayerOwner().sendMessage(Text.translatable("info.autofish.open_water_detection.fail"),true); + alreadyAlertOP = true; + alreadyPassOP = false; + } + flag = false; } } - if(flag) bobber.getPlayerOwner().sendMessage(Text.translatable("info.autofish.open_water_detection.success"),true); + if(flag && !alreadyPassOP) { + bobber.getPlayerOwner().sendMessage(Text.translatable("info.autofish.open_water_detection.success"),true); + alreadyPassOP = true; + alreadyAlertOP = false; + } }