mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-01 03:26:44 +01:00
If there isn't a primary ability, use the passive ability instead
This commit is contained in:
parent
f5d4bfeb5e
commit
497ed10cf4
4 changed files with 36 additions and 19 deletions
|
@ -2,16 +2,27 @@ package com.minelittlepony.unicopia.ability;
|
|||
|
||||
import java.util.EnumMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import com.minelittlepony.unicopia.Race;
|
||||
import com.minelittlepony.unicopia.util.Registries;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
public interface Abilities {
|
||||
Map<AbilitySlot, Set<Ability<?>>> BY_SLOT = new EnumMap<>(AbilitySlot.class);
|
||||
Registry<Ability<?>> REGISTRY = Registries.createSimple(new Identifier("unicopia", "abilities"));
|
||||
Map<AbilitySlot, Set<Ability<?>>> BY_SLOT = new EnumMap<>(AbilitySlot.class);
|
||||
BiFunction<AbilitySlot, Race, List<Ability<?>>> BY_SLOT_AND_RACE = Util.memoize((slot, race) -> {
|
||||
return BY_SLOT.computeIfAbsent(slot, s -> new LinkedHashSet<>())
|
||||
.stream()
|
||||
.filter(a -> a.canUse(race))
|
||||
.toList();
|
||||
});
|
||||
|
||||
// unicorn / alicorn
|
||||
Ability<?> CAST = register(new UnicornCastingAbility(), "cast", AbilitySlot.PRIMARY);
|
||||
|
@ -45,4 +56,5 @@ public interface Abilities {
|
|||
BY_SLOT.computeIfAbsent(slot, s -> new LinkedHashSet<>()).add(power);
|
||||
return Registry.register(REGISTRY, id, power);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package com.minelittlepony.unicopia.ability;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -70,6 +68,10 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable {
|
|||
return stats.computeIfAbsent(slot, Stat::new);
|
||||
}
|
||||
|
||||
public boolean isFilled(AbilitySlot slot) {
|
||||
return getStat(slot).getMaxPage() > 0;
|
||||
}
|
||||
|
||||
public long getMaxPage() {
|
||||
if (maxPage < 0 || prevRace != player.getSpecies()) {
|
||||
prevRace = player.getSpecies();
|
||||
|
@ -221,25 +223,16 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable {
|
|||
}
|
||||
|
||||
public Optional<Ability<?>> getAbility(long page) {
|
||||
Race race = player.getSpecies();
|
||||
List<Ability<?>> found = Abilities.BY_SLOT.computeIfAbsent(slot, c -> Collections.emptySet())
|
||||
.stream()
|
||||
.filter(a -> a.canUse(race))
|
||||
.collect(Collectors.toList());
|
||||
List<Ability<?>> found = Abilities.BY_SLOT_AND_RACE.apply(slot, player.getSpecies());
|
||||
if (found.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
page = Math.min(found.size() - 1, page);
|
||||
|
||||
return Optional.ofNullable(found.get((int)page));
|
||||
return Optional.ofNullable(found.get((int)Math.min(found.size() - 1, page)));
|
||||
}
|
||||
|
||||
public long getMaxPage() {
|
||||
Race race = player.getSpecies();
|
||||
return Abilities.BY_SLOT.computeIfAbsent(slot, c -> Collections.emptySet())
|
||||
.stream()
|
||||
.filter(a -> a.canUse(race))
|
||||
.count();
|
||||
return Abilities.BY_SLOT_AND_RACE.apply(slot, player.getSpecies()).size();
|
||||
}
|
||||
|
||||
protected synchronized Optional<Ability<?>> setActiveAbility(@Nullable Ability<?> power) {
|
||||
|
|
|
@ -78,7 +78,10 @@ public class KeyBindingsHandler {
|
|||
} else {
|
||||
for (Binding i : keys.keySet()) {
|
||||
AbilitySlot slot = keys.get(i);
|
||||
if (slot == AbilitySlot.PRIMARY && client.options.keySneak.isPressed()) {
|
||||
if (slot == AbilitySlot.PRIMARY && client.options.keySneak.isPressed() && abilities.isFilled(AbilitySlot.PASSIVE)) {
|
||||
slot = AbilitySlot.PASSIVE;
|
||||
}
|
||||
if (slot == AbilitySlot.PRIMARY && !abilities.isFilled(slot)) {
|
||||
slot = AbilitySlot.PASSIVE;
|
||||
}
|
||||
|
||||
|
|
|
@ -75,18 +75,27 @@ class Slot {
|
|||
}
|
||||
|
||||
void renderBackground(MatrixStack matrices, AbilityDispatcher abilities, boolean bSwap, float tickDelta) {
|
||||
|
||||
if (aSlot != bSlot) {
|
||||
bSwap |= !abilities.isFilled(aSlot);
|
||||
bSwap &= abilities.isFilled(bSlot);
|
||||
}
|
||||
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
RenderSystem.enableBlend();
|
||||
matrices.push();
|
||||
matrices.translate(getX(), getY(), 0);
|
||||
|
||||
float cooldown = abilities.getStat(bSwap ? bSlot : aSlot).getFillProgress();
|
||||
|
||||
// background
|
||||
UHud.drawTexture(matrices, 0, 0, backgroundU, backgroundV, size, size, 128, 128);
|
||||
|
||||
AbilityDispatcher.Stat stat = abilities.getStat(bSwap ? bSlot : aSlot);
|
||||
|
||||
|
||||
int sz = iconSize - slotPadding;
|
||||
uHud.renderAbilityIcon(matrices, abilities.getStat(bSwap ? bSlot : aSlot), slotPadding, slotPadding, sz, sz, sz, sz);
|
||||
uHud.renderAbilityIcon(matrices, stat, slotPadding, slotPadding, sz, sz, sz, sz);
|
||||
|
||||
float cooldown = stat.getFillProgress();
|
||||
|
||||
if (cooldown > 0 && cooldown <= 1) {
|
||||
float lerpCooldown = MathHelper.lerp(tickDelta, cooldown, lastCooldown);
|
||||
|
|
Loading…
Reference in a new issue