Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Swing On Abilities" #1127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.name(Text.translatable("skyblocker.config.uiAndVisuals"))

//Ungrouped Options
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.uiAndVisuals.swingOnAbilities"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.uiAndVisuals.swingOnAbilities.@Tooltip")))
.binding(defaults.uiAndVisuals.swingOnAbilities,
() -> config.uiAndVisuals.swingOnAbilities,
newValue -> config.uiAndVisuals.swingOnAbilities = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Integer>createBuilder()
.name(Text.translatable("skyblocker.config.uiAndVisuals.nightVisionStrength"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.uiAndVisuals.nightVisionStrength.@Tooltip")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
import java.util.List;

public class UIAndVisualsConfig {

@SerialEntry
public boolean swingOnAbilities = true;
AzureAaron marked this conversation as resolved.
Show resolved Hide resolved

@SerialEntry
public int nightVisionStrength = 100;

Expand Down
37 changes: 37 additions & 0 deletions src/main/java/de/hysky/skyblocker/skyblock/SwingAnimation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package de.hysky.skyblocker.skyblock;

import de.hysky.skyblocker.annotations.Init;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.ItemUtils;
import net.fabricmc.fabric.api.event.player.UseItemCallback;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;

import java.util.regex.Pattern;

public class SwingAnimation {

public static final Pattern ABILITY = Pattern.compile("^ability:\\s.*?\\s+right\\sclick$");
AzureAaron marked this conversation as resolved.
Show resolved Hide resolved

@Init
public static void init() {
UseItemCallback.EVENT.register((player, world, hand) -> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be a lot safer to mixin and call whatever code is needed to trigger just the animation since this manually sends a packet to the server. It's also means we (and other mods) can use this event to cancel an item use rather than having to mess around with event phases and init prioritization.

var config = SkyblockerConfigManager.get();
var stack = player.getStackInHand(hand);
if (config.uiAndVisuals.swingOnAbilities
&& SwingAnimation.hasAbility(stack))
return ActionResult.SUCCESS;
return ActionResult.PASS;
});
}

public static boolean hasAbility(ItemStack stack) {
if (stack.isEmpty()) return false;
var lore = ItemUtils.getLore(stack);
for (var line : lore) {
if (ABILITY.matcher(line.getString().trim().toLowerCase()).matches())
return true;
}
return false;
}
}
3 changes: 3 additions & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,9 @@

"skyblocker.config.uiAndVisuals": "UI & Visuals",

"skyblocker.config.uiAndVisuals.swingOnAbilities": "Swing On Abilities",
"skyblocker.config.uiAndVisuals.swingOnAbilities.@Tooltip": "Swings your hand whenever you use an item with a right-click ability.",

"skyblocker.config.uiAndVisuals.nightVisionStrength": "Night Vision Strength",
"skyblocker.config.uiAndVisuals.nightVisionStrength.@Tooltip": "Determines the strength of the Night Vision effect.",

Expand Down
Loading