Skip to content

Commit

Permalink
Merge pull request #646 from olim88/extended-fishing
Browse files Browse the repository at this point in the history
Add fishing fetures
  • Loading branch information
kevinthegreat1 authored Apr 16, 2024
2 parents a505ac7 + 8dbe780 commit a2c92d2
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,18 @@ public static class Experiments {
public static class Fishing {
@SerialEntry
public boolean enableFishingHelper = true;

@SerialEntry
public boolean enableFishingTimer = false;

@SerialEntry
public boolean changeTimerColor = true;

@SerialEntry
public float fishingTimerScale = 1f;

@SerialEntry
public boolean hideOtherPlayersRods = false;
}

public static class FairySouls {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,38 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
newValue -> config.general.fishing.enableFishingHelper = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.general.fishing.enableFishingTimer"))
.description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.general.fishing.enableFishingTimer.@Tooltip")))
.binding(defaults.general.fishing.enableFishingTimer,
() -> config.general.fishing.enableFishingTimer,
newValue -> config.general.fishing.enableFishingTimer = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.general.fishing.changeTimerColor"))
.description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.general.fishing.changeTimerColor.@Tooltip")))
.binding(defaults.general.fishing.changeTimerColor,
() -> config.general.fishing.changeTimerColor,
newValue -> config.general.fishing.changeTimerColor = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Float>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.general.fishing.fishingTimerScale"))
.description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.general.fishing.fishingTimerScale.@Tooltip")))
.binding(defaults.general.fishing.fishingTimerScale,
() -> config.general.fishing.fishingTimerScale,
newValue -> config.general.fishing.fishingTimerScale = newValue)
.controller(FloatFieldControllerBuilder::create)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.general.fishing.hideOtherPlayers"))
.description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.general.fishing.hideOtherPlayers.@Tooltip")))
.binding(defaults.general.fishing.hideOtherPlayersRods,
() -> config.general.fishing.hideOtherPlayersRods,
newValue -> config.general.fishing.hideOtherPlayersRods = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.build())

//Fairy Souls Helper
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/de/hysky/skyblocker/mixin/RenderFishMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.hysky.skyblocker.mixin;


import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.Utils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.FishingBobberEntityRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.projectile.FishingBobberEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(FishingBobberEntityRenderer.class)
public abstract class RenderFishMixin {

@Inject(method = "render", at = @At("HEAD"), cancellable = true)
private void skyblocker$render(FishingBobberEntity fishingBobberEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) {
//if rendered bobber is not the players and option to hide others is enabled do not render the bobber
if (Utils.isOnSkyblock() && fishingBobberEntity.getPlayerOwner() != MinecraftClient.getInstance().player && SkyblockerConfigManager.get().general.fishing.hideOtherPlayersRods) {
ci.cancel();
}
}
}
35 changes: 33 additions & 2 deletions src/main/java/de/hysky/skyblocker/skyblock/FishingHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.render.RenderHelper;
import de.hysky.skyblocker.utils.render.title.Title;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
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;
Expand All @@ -19,6 +22,7 @@
public class FishingHelper {
private static final Title title = new Title("skyblocker.fishing.reelNow", Formatting.GREEN);
private static long startTime;
private static long startTimeFish;
private static Vec3d normalYawVector;

public static void init() {
Expand All @@ -36,31 +40,58 @@ public static void init() {
}
return TypedActionResult.pass(stack);
});
WorldRenderEvents.AFTER_TRANSLUCENT.register(FishingHelper::render);
}

public static void start(PlayerEntity player) {
startTime = System.currentTimeMillis();
startTimeFish = System.currentTimeMillis();
float yawRad = player.getYaw() * 0.017453292F;
normalYawVector = new Vec3d(-MathHelper.sin(yawRad), 0, MathHelper.cos(yawRad));
}

public static void reset() {
startTime = 0;
startTimeFish = 0;
}

public static void resetFish() {
startTimeFish = 0;
}

public static void onSound(PlaySoundS2CPacket packet) {
String path = packet.getSound().value().getId().getPath();
if (SkyblockerConfigManager.get().general.fishing.enableFishingHelper && startTime != 0 && System.currentTimeMillis() >= startTime + 2000 && ("entity.generic.splash".equals(path) || "entity.player.splash".equals(path))) {
if (SkyblockerConfigManager.get().general.fishing.enableFishingHelper && startTimeFish != 0 && System.currentTimeMillis() >= startTimeFish + 2000 && ("entity.generic.splash".equals(path) || "entity.player.splash".equals(path))) {
ClientPlayerEntity player = MinecraftClient.getInstance().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) {
RenderHelper.displayInTitleContainerAndPlaySound(title, 10);
reset();
resetFish();
}
} else {
reset();
}
}
}

public static void render(WorldRenderContext context) {
if (SkyblockerConfigManager.get().general.fishing.enableFishingTimer && startTime != 0) {
ClientPlayerEntity player = MinecraftClient.getInstance().player;
if (player != null && player.fishHook != null) {
float time = (int) ((System.currentTimeMillis() - startTime) / 100f) / 10f; //leave 1dp in seconds
float scale = SkyblockerConfigManager.get().general.fishing.fishingTimerScale;
Vec3d pos = player.fishHook.getPos().add(0, 0.4 + scale / 10, 0);

Text text;
if (time >= 20 && SkyblockerConfigManager.get().general.fishing.changeTimerColor) {
text = Text.literal(String.valueOf(time)).formatted(Formatting.GREEN);
} else {
text = Text.literal(String.valueOf(time));
}

RenderHelper.renderText(context, text, pos, scale, true);
}
}
}
}
8 changes: 8 additions & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
"text.autoconfig.skyblocker.option.general.etherwarpOverlay": "Etherwarp Overlay",
"text.autoconfig.skyblocker.option.general.fishing": "Fishing Helper",
"text.autoconfig.skyblocker.option.general.fishing.enableFishingHelper": "Enable Fishing Helper",
"text.autoconfig.skyblocker.option.general.fishing.enableFishingTimer": "Enable Timer",
"text.autoconfig.skyblocker.option.general.fishing.enableFishingTimer.@Tooltip": "Display fishing time above bobber",
"text.autoconfig.skyblocker.option.general.fishing.changeTimerColor": "Change Timer At 20s",
"text.autoconfig.skyblocker.option.general.fishing.changeTimerColor.@Tooltip": "Changes timer to green after 20 seconds has passed",
"text.autoconfig.skyblocker.option.general.fishing.fishingTimerScale": "Fishing Timer Scale",
"text.autoconfig.skyblocker.option.general.fishing.fishingTimerScale.@Tooltip": "How big to display the fishing timer",
"text.autoconfig.skyblocker.option.general.fishing.hideOtherPlayers": "Hide Other Players Rods",
"text.autoconfig.skyblocker.option.general.fishing.hideOtherPlayers.@Tooltip": "Hide other players fishing rods from showing for you",
"text.autoconfig.skyblocker.option.general.fairySouls": "Fairy Souls Helper",
"text.autoconfig.skyblocker.option.general.fairySouls.enableFairySoulsHelper": "Enable Fairy Souls Helper",
"text.autoconfig.skyblocker.option.general.fairySouls.highlightFoundSouls": "Highlight found fairy souls",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/skyblocker.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"PlayerListHudMixin",
"PlayerSkinProviderMixin",
"PlayerSkinTextureMixin",
"RenderFishMixin",
"ScoreboardMixin",
"SocialInteractionsPlayerListWidgetMixin",
"WorldRendererMixin",
Expand Down

0 comments on commit a2c92d2

Please sign in to comment.