diff options
author | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2023-05-20 14:10:46 -0400 |
---|---|---|
committer | Kevin <92656833+kevinthegreat1@users.noreply.github.com> | 2023-05-26 16:31:26 -0400 |
commit | 18e0b1c1b18a6a0795894b71565f1950b513f666 (patch) | |
tree | d0d2259307045cea6ddf8fb1cbd943ef2d030898 | |
parent | 81698fb9e2f3064877b1aeeecf73e1ed1b28add4 (diff) | |
download | Skyblocker-18e0b1c1b18a6a0795894b71565f1950b513f666.tar.gz Skyblocker-18e0b1c1b18a6a0795894b71565f1950b513f666.tar.bz2 Skyblocker-18e0b1c1b18a6a0795894b71565f1950b513f666.zip |
Add Fishing Helper
5 files changed, 99 insertions, 1 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java index e2e7b4ca..13f70137 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java @@ -142,6 +142,10 @@ public class SkyblockerConfig implements ConfigData { @ConfigEntry.Gui.CollapsibleObject() public Bars bars = new Bars(); + @ConfigEntry.Category("fishing") + @ConfigEntry.Gui.CollapsibleObject() + public Fishing fishing = new Fishing(); + @ConfigEntry.Category("itemList") @ConfigEntry.Gui.CollapsibleObject() public ItemList itemList = new ItemList(); @@ -199,6 +203,10 @@ public class SkyblockerConfig implements ConfigData { } } + public static class Fishing { + public boolean enableFishingHelper = true; + } + public static class Hitbox { public boolean oldFarmlandHitbox = true; public boolean oldLeverHitbox = false; diff --git a/src/main/java/me/xmrvizzy/skyblocker/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/me/xmrvizzy/skyblocker/mixin/ClientPlayNetworkHandlerMixin.java new file mode 100644 index 00000000..80c98473 --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/mixin/ClientPlayNetworkHandlerMixin.java @@ -0,0 +1,24 @@ +package me.xmrvizzy.skyblocker.mixin; + +import me.xmrvizzy.skyblocker.skyblock.FishingHelper; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ClientPlayNetworkHandler.class) +public abstract class ClientPlayNetworkHandlerMixin { + @Shadow + @Final + private MinecraftClient client; + + @Inject(method = "onPlaySound", at = @At("RETURN")) + private void skyblockmod_onPlaySound(PlaySoundS2CPacket packet, CallbackInfo ci) { + FishingHelper.onSound(client, packet); + } +} diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FishingHelper.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FishingHelper.java new file mode 100644 index 00000000..790b27bf --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FishingHelper.java @@ -0,0 +1,61 @@ +package me.xmrvizzy.skyblocker.skyblock; + +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import net.fabricmc.fabric.api.event.player.UseItemCallback; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.FishingRodItem; +import net.minecraft.item.ItemStack; +import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import net.minecraft.util.TypedActionResult; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; + +public class FishingHelper { + private static long startTime; + private static Vec3d normalYawVector; + + public static void init() { + UseItemCallback.EVENT.register((player, world, hand) -> { + ItemStack stack = player.getStackInHand(hand); + if (stack.getItem() instanceof FishingRodItem) { + if (player.fishHook == null) { + start(player); + } else { + reset(); + } + } + return TypedActionResult.pass(stack); + }); + } + + public static void start(PlayerEntity player) { + startTime = System.currentTimeMillis(); + float yawRad = player.getYaw() * 0.017453292F; + normalYawVector = new Vec3d(-MathHelper.sin(yawRad), 0, MathHelper.cos(yawRad)); + } + + public static void reset() { + startTime = 0; + } + + public static void onSound(MinecraftClient client, PlaySoundS2CPacket packet) { + String path = packet.getSound().value().getId().getPath(); + if (SkyblockerConfig.get().general.fishing.enableFishingHelper && startTime != 0 && System.currentTimeMillis() >= startTime + 2000 && ("entity.generic.splash".equals(path) || "entity.player.splash".equals(path))) { + ClientPlayerEntity player = client.player; + if (player != null && player.fishHook != null) { + Vec3d soundToFishHook = player.fishHook.getPos().subtract(packet.getX(), 0, packet.getZ()); + if (Math.abs(normalYawVector.x * soundToFishHook.z - normalYawVector.z * soundToFishHook.x) < 0.2D && Math.abs(normalYawVector.dotProduct(soundToFishHook)) < 4D && player.getPos().squaredDistanceTo(packet.getX(), packet.getY(), packet.getZ()) > 1D) { + client.inGameHud.setTitleTicks(0, 10, 5); + client.inGameHud.setTitle(Text.translatable("skyblocker.fishing.reelNow").formatted(Formatting.GREEN)); + reset(); + } + } else { + reset(); + } + } + } +} diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 4809b8ab..80e3e05e 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -17,6 +17,8 @@ "text.autoconfig.skyblocker.option.general.bars.barpositions.manaBarPosition": "Mana Bar Position", "text.autoconfig.skyblocker.option.general.bars.barpositions.defenceBarPosition": "Defence Bar Position", "text.autoconfig.skyblocker.option.general.bars.barpositions.experienceBarPosition": "Experience Bar Position", + "text.autoconfig.skyblocker.option.general.fishing": "Fishing Helper", + "text.autoconfig.skyblocker.option.general.fishing.enableFishingHelper": "Enable Fishing Helper", "text.autoconfig.skyblocker.option.general.quicknav": "Quicknav", "text.autoconfig.skyblocker.option.general.quicknav.enableQuicknav": "Enable Quicknav", "text.autoconfig.skyblocker.option.general.backpackPreviewWithoutShift": "View backpack preview without holding Shift", @@ -197,5 +199,7 @@ "skyblocker.updaterepository.failed": "§b[§6Skyblocker§b] §cUpdating local repository failed. Remove files manually and restart game.", - "skyblocker.api.got_key": "§b[§6Skyblocker§b] §2Automatically set your API key!" + "skyblocker.api.got_key": "§b[§6Skyblocker§b] §2Automatically set your API key!", + + "skyblocker.fishing.reelNow": "Reel in now!" } diff --git a/src/main/resources/skyblocker.mixins.json b/src/main/resources/skyblocker.mixins.json index 2eba53e3..1744b5ba 100644 --- a/src/main/resources/skyblocker.mixins.json +++ b/src/main/resources/skyblocker.mixins.json @@ -5,6 +5,7 @@ "client": [ "AccessorWorldRenderer", "ClientPlayerEntityMixin", + "ClientPlayNetworkHandlerMixin", "FarmlandBlockMixin", "GenericContainerScreenHandlerMixin", "HandledScreenAccessor", |