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 all commits
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 = false;

@SerialEntry
public int nightVisionStrength = 100;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.hysky.skyblocker.mixins;

import com.llamalad7.mixinextras.sugar.Local;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.SwingAnimation;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.Packet;
import net.minecraft.util.Hand;
import org.apache.commons.lang3.mutable.MutableObject;
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.CallbackInfoReturnable;

@Mixin(ClientPlayerInteractionManager.class)
public class ClientPlayerInteractionManagerMixin {

@Inject(method = "method_41929", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;use(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;", shift = At.Shift.AFTER))
public void onInteractItem(Hand hand, PlayerEntity playerEntity, MutableObject<?> mutableObject,
int sequence, CallbackInfoReturnable<Packet<?>> cir, @Local ItemStack itemStack) {
if (SkyblockerConfigManager.get().uiAndVisuals.swingOnAbilities
&& SwingAnimation.hasAbility(itemStack)) {
playerEntity.swingHand(hand);
}
}
}
20 changes: 20 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,20 @@
package de.hysky.skyblocker.skyblock;

import de.hysky.skyblocker.utils.ItemUtils;
import net.minecraft.item.ItemStack;

import java.util.regex.Pattern;

public class SwingAnimation {
private static final Pattern ABILITY = Pattern.compile("^ability:\\s.*?\\s+right\\sclick$");

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
1 change: 1 addition & 0 deletions src/main/resources/skyblocker.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"BatEntityMixin",
"BossBarHudMixin",
"ClientPlayerEntityMixin",
"ClientPlayerInteractionManagerMixin",
"ClientPlayNetworkHandlerMixin",
"ClientWorldMixin",
"CommandTreeS2CPacketMixin",
Expand Down
Loading