Indicate whether an ability can actually do something for a selected activation type

This commit is contained in:
Sollace 2024-04-12 01:24:15 +01:00
parent 86faeeaa43
commit 0a5ec3da03
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
8 changed files with 49 additions and 1 deletions

View file

@ -83,6 +83,15 @@ public interface Ability<T extends Hit> {
return false;
}
/**
* Checks whether this ability has any special actions for the given activation type.
* <p>
* The default is to only respond to press-and-hold actions.
*/
default boolean acceptsQuickAction(Pony player, ActivationType type) {
return type == ActivationType.NONE;
}
/**
* Called on the client to get any data required for the quick action.
*

View file

@ -63,6 +63,11 @@ public class CarryAbility implements Ability<Hit> {
return false;
}
@Override
public boolean acceptsQuickAction(Pony player, ActivationType type) {
return type == ActivationType.NONE || type == ActivationType.TAP;
}
@Override
public boolean apply(Pony iplayer, Hit data) {
PlayerEntity player = iplayer.asEntity();

View file

@ -116,6 +116,11 @@ public class EarthPonyKickAbility implements Ability<Pos> {
return false;
}
@Override
public boolean acceptsQuickAction(Pony player, ActivationType type) {
return type == ActivationType.NONE || type == ActivationType.TAP || type == ActivationType.DOUBLE_TAP;
}
@Nullable
@Override
public Optional<Pos> prepare(Pony player) {

View file

@ -49,6 +49,11 @@ public class FlyingDashAbility implements Ability<Hit> {
return false;
}
@Override
public boolean acceptsQuickAction(Pony player, ActivationType type) {
return type == ActivationType.NONE || type == ActivationType.TAP;
}
@Override
public boolean apply(Pony player, Hit data) {
player.getPhysics().dashForward((float)player.asWorld().random.nextTriangular(2.5F, 0.3F));

View file

@ -54,6 +54,11 @@ public class PegasusRainboomAbility implements Ability<Hit> {
return false;
}
@Override
public boolean acceptsQuickAction(Pony player, ActivationType type) {
return type == ActivationType.NONE || type == ActivationType.TAP;
}
@Override
public boolean apply(Pony player, Hit data) {

View file

@ -72,6 +72,11 @@ public class UnicornDispellAbility implements Ability<Pos> {
return false;
}
@Override
public boolean acceptsQuickAction(Pony player, ActivationType type) {
return type == ActivationType.NONE || (player.getSpecies() != Race.CHANGELING && type == ActivationType.TAP);
}
@Override
public double getCostEstimate(Pony player) {
return getTarget(player)

View file

@ -56,6 +56,11 @@ public class UnicornProjectileAbility extends AbstractSpellCastingAbility {
return false;
}
@Override
public boolean acceptsQuickAction(Pony player, ActivationType type) {
return type == ActivationType.NONE || type == ActivationType.DOUBLE_TAP;
}
@Override
public boolean apply(Pony player, Hit data) {
TypedActionResult<CustomisedSpellType<?>> thrown = player.getCharms().getSpellInHand(true);

View file

@ -1,10 +1,14 @@
package com.minelittlepony.unicopia.client.gui;
import java.util.Optional;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.ability.Ability;
import com.minelittlepony.unicopia.ability.AbilityDispatcher;
import com.minelittlepony.unicopia.ability.AbilitySlot;
import com.minelittlepony.unicopia.ability.ActivationType;
import com.minelittlepony.unicopia.client.KeyBindingsHandler;
import com.minelittlepony.unicopia.client.UnicopiaClient;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.DrawContext;
@ -132,7 +136,9 @@ class Slot {
void renderLabel(DrawContext context, AbilityDispatcher abilities, float tickDelta) {
if (abilities.getStat(aSlot).getAbility(Unicopia.getConfig().hudPage.get()).isEmpty()) {
Optional<Ability<?>> ability = abilities.getStat(aSlot).getAbility(Unicopia.getConfig().hudPage.get());
if (ability.isEmpty()) {
return;
}
@ -155,6 +161,9 @@ class Slot {
ActivationType activation = KeyBindingsHandler.INSTANCE.getForcedActivationType();
if (activation.isResult()) {
label = label.append("+T" + activation.getTapCount());
if (!ability.get().acceptsQuickAction(UnicopiaClient.getClientPony(), activation)) {
label = label.formatted(Formatting.RED);
}
}
context.drawText(uHud.font, label, 0, 0, 0xFFFFFF, true);