Add an indicator to show which spell is is going to be used and allow switching between main and offhand spell by sneaking

This commit is contained in:
Sollace 2022-12-27 20:41:14 +01:00
parent a5c1d2ead8
commit 253962b5f3
6 changed files with 38 additions and 20 deletions

View file

@ -73,7 +73,8 @@ public class UnicornCastingAbility implements Ability<Hit> {
return Math.min(manaLevel, ((AmuletItem)amulet.getValue().getItem()).getChargeRemainder(amulet.getValue()));
}
TypedActionResult<CustomisedSpellType<?>> spell = player.getCharms().getSpellInHand(Hand.MAIN_HAND);
Hand hand = player.asEntity().isSneaking() ? Hand.OFF_HAND : Hand.MAIN_HAND;
TypedActionResult<CustomisedSpellType<?>> spell = player.getCharms().getSpellInHand(hand);
return !spell.getResult().isAccepted() || spell.getValue().isOn(player) ? 2 : 4;
}
@ -100,7 +101,8 @@ public class UnicornCastingAbility implements Ability<Hit> {
}
}
} else {
TypedActionResult<CustomisedSpellType<?>> newSpell = player.getCharms().getSpellInHand(Hand.MAIN_HAND);
Hand hand = player.asEntity().isSneaking() ? Hand.OFF_HAND : Hand.MAIN_HAND;
TypedActionResult<CustomisedSpellType<?>> newSpell = player.getCharms().getSpellInHand(hand);
if (newSpell.getResult() != ActionResult.FAIL) {
CustomisedSpellType<?> spell = newSpell.getValue();

View file

@ -12,7 +12,6 @@ import com.minelittlepony.unicopia.util.TraceHelper;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.TypedActionResult;
/**
@ -22,13 +21,6 @@ import net.minecraft.util.TypedActionResult;
* 2. If the player is holding a gem, consumes it and casts whatever spell is contained within onto a projectile.
*/
public class UnicornProjectileAbility implements Ability<Hit> {
@Override
public Identifier getIcon(Pony player, boolean swap) {
Identifier id = Abilities.REGISTRY.getId(this);
return new Identifier(id.getNamespace(), "textures/gui/ability/" + id.getPath() + (swap ? "_focused" : "_unfocused") + ".png");
}
@Override
public int getWarmupTime(Pony player) {
return 8;
@ -63,7 +55,8 @@ public class UnicornProjectileAbility implements Ability<Hit> {
public boolean onQuickAction(Pony player, ActivationType type) {
if (type == ActivationType.DOUBLE_TAP) {
if (!player.isClient()) {
TypedActionResult<CustomisedSpellType<?>> thrown = player.getCharms().getSpellInHand(Hand.OFF_HAND);
Hand hand = player.asEntity().isSneaking() ? Hand.MAIN_HAND : Hand.OFF_HAND;
TypedActionResult<CustomisedSpellType<?>> thrown = player.getCharms().getSpellInHand(hand);
if (thrown.getResult() != ActionResult.FAIL) {
thrown.getValue().create().toThrowable().throwProjectile(player).ifPresent(projectile -> {
@ -80,11 +73,10 @@ public class UnicornProjectileAbility implements Ability<Hit> {
@Override
public void apply(Pony player, Hit data) {
TypedActionResult<CustomisedSpellType<?>> thrown = player.getCharms().getSpellInHand(Hand.OFF_HAND);
Hand hand = player.asEntity().isSneaking() ? Hand.MAIN_HAND : Hand.OFF_HAND;
TypedActionResult<CustomisedSpellType<?>> thrown = player.getCharms().getSpellInHand(hand);
if (thrown.getResult() != ActionResult.FAIL) {
Spell spell = thrown.getValue().create();
spell.toThrowable().throwProjectile(player).ifPresent(projectile -> {

View file

@ -4,14 +4,12 @@ import java.util.List;
import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.*;
import com.minelittlepony.unicopia.ability.AbilityDispatcher;
import com.minelittlepony.unicopia.ability.AbilitySlot;
import com.minelittlepony.unicopia.ability.*;
import com.minelittlepony.unicopia.ability.magic.SpellPredicate;
import com.minelittlepony.unicopia.ability.magic.spell.AbstractDisguiseSpell;
import com.minelittlepony.unicopia.ability.magic.spell.TimedSpell;
import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellType;
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.client.KeyBindingsHandler;
import com.minelittlepony.unicopia.client.sound.*;
import com.minelittlepony.unicopia.entity.AmuletSelectors;
import com.minelittlepony.unicopia.entity.ItemTracker;
@ -21,6 +19,9 @@ import com.minelittlepony.unicopia.entity.effect.UEffects;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.item.GlassesItem;
import com.minelittlepony.unicopia.item.UItems;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.GlStateManager.DstFactor;
import com.mojang.blaze3d.platform.GlStateManager.SrcFactor;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
@ -120,13 +121,36 @@ public class UHud extends DrawableHelper {
boolean swap = client.options.sneakKey.isPressed();
slots.forEach(slot -> slot.renderBackground(matrices, abilities, swap, tickDelta));
if (pony.getObservedSpecies().canCast()) {
Ability<?> ability = pony.getAbilities().getStat(AbilitySlot.PRIMARY)
.getAbility(Unicopia.getConfig().hudPage.get())
.orElse(null);
if (ability == Abilities.CAST || ability == Abilities.SHOOT) {
matrices.push();
matrices.translate(PRIMARY_SLOT_SIZE / 2F, PRIMARY_SLOT_SIZE / 2F, 0);
boolean first = ability == Abilities.CAST;
if (pony.asEntity().isSneaking()) {
first = !first;
}
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(first ? 37 : 63));
matrices.translate(-23, 0, 0);
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(-26));
matrices.scale(0.8F, 0.8F, 1);
UHud.drawTexture(matrices, 0, 0, 3, 120, 15, 7, 128, 128);
matrices.pop();
}
}
slots.forEach(slot -> slot.renderLabel(matrices, abilities, tickDelta));
matrices.pop();
if (pony.getActualSpecies().canCast() || AmuletSelectors.ALICORN_AMULET.test(pony.asEntity())) {
renderSpell(pony.getCharms().getEquippedSpell(Hand.MAIN_HAND), hudX + 15 - xDirection * 13, hudY + 3);
renderSpell(pony.getCharms().getEquippedSpell(Hand.OFF_HAND), hudX + 15 - xDirection * 2, hudY - 3);
if (pony.getObservedSpecies().canCast()) {
renderSpell(pony.getCharms().getEquippedSpell(Hand.MAIN_HAND), hudX + 10 - xDirection * 13, hudY + 2);
renderSpell(pony.getCharms().getEquippedSpell(Hand.OFF_HAND), hudX + 8 - xDirection * 2, hudY - 6);
}
RenderSystem.disableBlend();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 838 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 33 KiB