mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 07:17:58 +01:00
Remove the update argument when interacting with spell slots
This commit is contained in:
parent
b9015c9220
commit
4bac633a23
34 changed files with 80 additions and 80 deletions
|
@ -51,7 +51,7 @@ public class ChangelingDisguiseAbility extends ChangelingFeedAbility {
|
|||
|
||||
player.getEntityWorld().playSound(null, player.getBlockPos(), USounds.ENTITY_PLAYER_CHANGELING_TRANSFORM, SoundCategory.PLAYERS, 1.4F, 0.4F);
|
||||
|
||||
Disguise currentDisguise = iplayer.getSpellSlot().get(SpellType.CHANGELING_DISGUISE, true)
|
||||
Disguise currentDisguise = iplayer.getSpellSlot().get(SpellType.CHANGELING_DISGUISE)
|
||||
.orElseGet(() -> SpellType.CHANGELING_DISGUISE.withTraits().apply(iplayer, CastingMethod.INNATE));
|
||||
|
||||
if (currentDisguise.isOf(looked)) {
|
||||
|
|
|
@ -57,9 +57,7 @@ public class TimeChangeAbility implements Ability<Rot> {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (player.getSpellSlot().contains(SpellType.TIME_CONTROL)) {
|
||||
player.getSpellSlot().removeWhere(SpellType.TIME_CONTROL, true);
|
||||
} else {
|
||||
if (!player.getSpellSlot().removeWhere(SpellType.TIME_CONTROL)) {
|
||||
SpellType.TIME_CONTROL.withTraits().apply(player, CastingMethod.INNATE).update(player, data.applyTo(player));
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ public class UnicornCastingAbility extends AbstractSpellCastingAbility {
|
|||
}
|
||||
|
||||
boolean hasExact = !spell.isStackable() && player.getSpellSlot().contains(s -> !s.getTypeAndTraits().isStackable() && spell.test(s));
|
||||
boolean removed = !spell.isStackable() && player.getSpellSlot().removeWhere(s -> !s.getTypeAndTraits().isStackable() && s.findMatches(spell.type()).findAny().isPresent(), true);
|
||||
boolean removed = !spell.isStackable() && player.getSpellSlot().removeWhere(s -> !s.getTypeAndTraits().isStackable() && s.findMatches(spell.type()).findAny().isPresent());
|
||||
player.subtractEnergyCost(removed ? 2 : 4);
|
||||
if (!hasExact && !spell.isEmpty()) {
|
||||
Spell s = spell.apply(player, CastingMethod.DIRECT);
|
||||
|
|
|
@ -97,7 +97,7 @@ public class UnicornDispellAbility implements Ability<Pos> {
|
|||
spell.setDead();
|
||||
spell.tickDying(target);
|
||||
return Operation.ofBoolean(!spell.isDead());
|
||||
}, true);
|
||||
});
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -19,20 +19,20 @@ public interface SpellContainer {
|
|||
* Checks if any matching spells are active.
|
||||
*/
|
||||
default boolean contains(@Nullable SpellPredicate<?> type) {
|
||||
return get(type, true).isPresent();
|
||||
return get(type).isPresent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the active effect for this caster updating it if needed.
|
||||
*/
|
||||
default <T extends Spell> Optional<T> get(boolean update) {
|
||||
return get(null, update);
|
||||
default <T extends Spell> Optional<T> get() {
|
||||
return get(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the active effect for this caster updating it if needed.
|
||||
*/
|
||||
<T extends Spell> Optional<T> get(@Nullable SpellPredicate<T> type, boolean update);
|
||||
<T extends Spell> Optional<T> get(@Nullable SpellPredicate<T> type);
|
||||
|
||||
/**
|
||||
* Sets the active effect.
|
||||
|
@ -51,8 +51,8 @@ public interface SpellContainer {
|
|||
*
|
||||
* @return True if the collection was changed
|
||||
*/
|
||||
default boolean removeIf(Predicate<Spell> test, boolean update) {
|
||||
return removeWhere(spell -> spell.findMatches(test).findFirst().isPresent(), update);
|
||||
default boolean removeIf(Predicate<Spell> test) {
|
||||
return removeWhere(spell -> spell.findMatches(test).findFirst().isPresent());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,25 +60,25 @@ public interface SpellContainer {
|
|||
*
|
||||
* @return True if the collection was changed
|
||||
*/
|
||||
boolean removeWhere(Predicate<Spell> test, boolean update);
|
||||
boolean removeWhere(Predicate<Spell> test);
|
||||
|
||||
/**
|
||||
* Iterates active spells and optionally removes matching ones.
|
||||
*
|
||||
* @return True if any matching spells remain active
|
||||
*/
|
||||
boolean forEach(Function<Spell, Operation> action, boolean update);
|
||||
boolean forEach(Function<Spell, Operation> action);
|
||||
|
||||
|
||||
/**
|
||||
* Gets all active effects for this caster updating it if needed.
|
||||
*/
|
||||
Stream<Spell> stream(boolean update);
|
||||
Stream<Spell> stream();
|
||||
|
||||
/**
|
||||
* Gets all active effects for this caster that match the given type updating it if needed.
|
||||
*/
|
||||
<T extends Spell> Stream<T> stream(@Nullable SpellPredicate<T> type, boolean update);
|
||||
<T extends Spell> Stream<T> stream(@Nullable SpellPredicate<T> type);
|
||||
|
||||
/**
|
||||
* Removes all effects currently active in this slot.
|
||||
|
|
|
@ -71,7 +71,7 @@ public abstract class AbstractDisguiseSpell extends AbstractSpell implements Dis
|
|||
public static Entity getAppearance(Entity e) {
|
||||
return e instanceof PlayerEntity ? Pony.of((PlayerEntity)e)
|
||||
.getSpellSlot()
|
||||
.get(SpellPredicate.IS_DISGUISE, true)
|
||||
.get(SpellPredicate.IS_DISGUISE)
|
||||
.map(AbstractDisguiseSpell::getDisguise)
|
||||
.map(EntityAppearance::getAppearance)
|
||||
.orElse(e) : e;
|
||||
|
|
|
@ -71,8 +71,7 @@ public class BubbleSpell extends AbstractSpell implements TimedSpell,
|
|||
@Override
|
||||
public boolean apply(Caster<?> source) {
|
||||
|
||||
if (getType().isOn(source)) {
|
||||
source.getSpellSlot().removeWhere(getType(), true);
|
||||
if (source.getSpellSlot().removeWhere(getType())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ public class DisperseIllusionSpell extends AbstractAreaEffectSpell {
|
|||
}
|
||||
|
||||
source.findAllSpellsInRange(range).forEach(e -> {
|
||||
e.getSpellSlot().get(SpellPredicate.CAN_SUPPRESS, false)
|
||||
e.getSpellSlot().get(SpellPredicate.CAN_SUPPRESS)
|
||||
.filter(spell -> spell.isVulnerable(source, this))
|
||||
.ifPresent(spell -> {
|
||||
spell.onSuppressed(source, 1 + getTraits().get(Trait.STRENGTH));
|
||||
|
|
|
@ -60,8 +60,8 @@ public class MindSwapSpell extends MimicSpell implements ProjectileDelegate.Enti
|
|||
LivingEntity master = caster.getMaster();
|
||||
Caster<?> other = Caster.of(e).get();
|
||||
|
||||
other.getSpellSlot().removeIf(SpellType.MIMIC, true);
|
||||
caster.getSpellSlot().removeIf(getType(), true);
|
||||
other.getSpellSlot().removeIf(SpellType.MIMIC);
|
||||
caster.getSpellSlot().removeIf(getType());
|
||||
|
||||
if (!isValidTarget(master) || !isValidTarget(e)) {
|
||||
master.damage(caster.asWorld().getDamageSources().magic(), Float.MAX_VALUE);
|
||||
|
|
|
@ -43,7 +43,7 @@ public class DismissSpellScreen extends GameGui {
|
|||
|
||||
List<PlaceableSpell> placeableSpells = new ArrayList<>();
|
||||
|
||||
for (Spell spell : pony.getSpellSlot().stream(true).filter(SpellPredicate.IS_VISIBLE).toList()) {
|
||||
for (Spell spell : pony.getSpellSlot().stream().filter(SpellPredicate.IS_VISIBLE).toList()) {
|
||||
|
||||
if (spell instanceof PlaceableSpell placeable) {
|
||||
if (placeable.getPosition().isPresent()) {
|
||||
|
@ -147,7 +147,7 @@ public class DismissSpellScreen extends GameGui {
|
|||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (isMouseOver(relativeMouseX, relativeMouseY)) {
|
||||
remove(this);
|
||||
pony.getSpellSlot().removeIf(spell -> spell == this.spell, true);
|
||||
pony.getSpellSlot().removeIf(spell -> spell == this.spell);
|
||||
Channel.REMOVE_SPELL.sendToServer(new MsgRemoveSpell(spell));
|
||||
playClickEffect();
|
||||
return true;
|
||||
|
|
|
@ -35,11 +35,11 @@ public interface SpellIconRenderer {
|
|||
|
||||
DrawableUtil.drawArc(modelStack, radius, radius + 3, 0, DrawableUtil.TAU, color & 0xFFFFFF2F, false);
|
||||
DrawableUtil.drawArc(modelStack, radius + 3, radius + 4, 0, DrawableUtil.TAU, color & 0xFFFFFFAF, false);
|
||||
pony.getSpellSlot().get(spell.and(SpellPredicate.IS_TIMED), false).map(TimedSpell::getTimer).ifPresent(timer -> {
|
||||
pony.getSpellSlot().get(spell.and(SpellPredicate.IS_TIMED)).map(TimedSpell::getTimer).ifPresent(timer -> {
|
||||
DrawableUtil.drawArc(modelStack, radius, radius + 3, 0, DrawableUtil.TAU * timer.getPercentTimeRemaining(client.getTickDelta()), 0xFFFFFFFF, false);
|
||||
});
|
||||
|
||||
long count = pony.getSpellSlot().stream(spell, false).count();
|
||||
long count = pony.getSpellSlot().stream(spell).count();
|
||||
if (count > 1) {
|
||||
modelStack.push();
|
||||
modelStack.translate(1, 1, 900);
|
||||
|
|
|
@ -105,7 +105,7 @@ public class SpellbookProfilePageContent implements SpellbookChapterList.Content
|
|||
int color = 0x10404000 | alpha;
|
||||
int xpColor = 0xAA0040FF | ((int)((0.3F + 0.7F * xpPercentage) * 0xFF) & 0xFF) << 16;
|
||||
int manaColor = 0xFF00F040;
|
||||
if (pony.getSpellSlot().get(SpellPredicate.IS_CORRUPTING, false).isPresent()) {
|
||||
if (pony.getSpellSlot().get(SpellPredicate.IS_CORRUPTING).isPresent()) {
|
||||
manaColor = ColorHelper.lerp(Math.abs(MathHelper.sin(pony.asEntity().age / 15F)), manaColor, 0xFF0030F0);
|
||||
}
|
||||
manaColor |= (int)((0.3F + 0.7F * alphaF) * 0x40) << 16;
|
||||
|
|
|
@ -114,7 +114,7 @@ public class DisguisedArmsFeatureRenderer<E extends LivingEntity> implements Acc
|
|||
}
|
||||
|
||||
private Entity getAppearance(E entity) {
|
||||
return Caster.of(entity).flatMap(caster -> caster.getSpellSlot().get(SpellPredicate.IS_DISGUISE, false)).map(Disguise.class::cast)
|
||||
return Caster.of(entity).flatMap(caster -> caster.getSpellSlot().get(SpellPredicate.IS_DISGUISE)).map(Disguise.class::cast)
|
||||
.flatMap(Disguise::getAppearance)
|
||||
.map(EntityAppearance::getAppearance)
|
||||
.orElse(null);
|
||||
|
|
|
@ -51,7 +51,7 @@ class EntityReplacementManager implements Disguise {
|
|||
return Optional.of(this);
|
||||
}
|
||||
|
||||
return caster.getSpellSlot().get(SpellPredicate.IS_DISGUISE, false).map(Disguise.class::cast);
|
||||
return caster.getSpellSlot().get(SpellPredicate.IS_DISGUISE).map(Disguise.class::cast);
|
||||
}
|
||||
|
||||
private List<EntityType<?>> getMobTypePool(EntityType<?> type) {
|
||||
|
|
|
@ -55,7 +55,9 @@ public class HornFeatureRenderer<E extends LivingEntity> implements AccessoryFea
|
|||
return pony.getAbilities().getActiveStat()
|
||||
.flatMap(Stat::getActiveAbility)
|
||||
.map(ability -> ability.getColor(pony))
|
||||
.filter(i -> i != -1).or(() -> pony.getSpellSlot().get(SpellPredicate.IS_NOT_PLACED, false).map(spell -> spell.getTypeAndTraits().type().getColor()));
|
||||
.filter(i -> i != -1).or(() -> pony.getSpellSlot()
|
||||
.get(SpellPredicate.IS_NOT_PLACED)
|
||||
.map(spell -> spell.getTypeAndTraits().type().getColor()));
|
||||
}).ifPresent(color -> {
|
||||
model.setState(true);
|
||||
model.render(stack, ItemRenderer.getArmorGlintConsumer(renderContext, RenderLayers.getMagicColored((0x99 << 24) | color), false, false), lightUv, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1);
|
||||
|
|
|
@ -56,7 +56,7 @@ public class MagicBeamEntityRenderer extends EntityRenderer<MagicBeamEntity> {
|
|||
-entity.getPitch(tickDelta) * MathHelper.RADIANS_PER_DEGREE
|
||||
);
|
||||
|
||||
RenderLayer layer = entity.getSpellSlot().get(true)
|
||||
RenderLayer layer = entity.getSpellSlot().get()
|
||||
.map(spell -> (0x99 << 24) | spell.getTypeAndTraits().type().getColor())
|
||||
.map(RenderLayers::getMagicColored)
|
||||
.orElseGet(RenderLayers::getMagicColored);
|
||||
|
|
|
@ -90,7 +90,7 @@ public class SpellEffectsRenderDispatcher implements SynchronousResourceReloader
|
|||
caster.getSpellSlot().forEach(spell -> {
|
||||
render(matrices, vertices, spell, caster, light, limbAngle, limbDistance, tickDelta, animationProgress, headYaw, headPitch);
|
||||
return Operation.SKIP;
|
||||
}, false);
|
||||
});
|
||||
|
||||
if (client.getEntityRenderDispatcher().shouldRenderHitboxes()
|
||||
&& !client.hasReducedDebugInfo()
|
||||
|
@ -125,7 +125,7 @@ public class SpellEffectsRenderDispatcher implements SynchronousResourceReloader
|
|||
caster.asEntity().getDisplayName().copy().append(" (" + Registries.ENTITY_TYPE.getId(caster.asEntity().getType()) + ")"),
|
||||
caster.getMaster() != null ? Text.literal("Master: ").append(caster.getMaster().getDisplayName()) : Text.empty()
|
||||
),
|
||||
caster.getSpellSlot().stream(SpellPredicate.ALL, false).flatMap(spell ->
|
||||
caster.getSpellSlot().stream(SpellPredicate.ALL).flatMap(spell ->
|
||||
Stream.of(
|
||||
Text.literal("UUID: " + spell.getUuid()),
|
||||
Text.literal("|>Type: ").append(Text.literal(spell.getTypeAndTraits().type().getId().toString()).styled(s -> s.withColor(spell.getTypeAndTraits().type().getColor()))),
|
||||
|
|
|
@ -80,7 +80,7 @@ public class DisguiseCommand {
|
|||
}
|
||||
|
||||
Pony iplayer = Pony.of(player);
|
||||
iplayer.getSpellSlot().get(SpellType.CHANGELING_DISGUISE, true)
|
||||
iplayer.getSpellSlot().get(SpellType.CHANGELING_DISGUISE)
|
||||
.orElseGet(() -> SpellType.CHANGELING_DISGUISE.withTraits().apply(iplayer, CastingMethod.INNATE))
|
||||
.setDisguise(entity);
|
||||
|
||||
|
@ -109,7 +109,7 @@ public class DisguiseCommand {
|
|||
|
||||
static int reveal(ServerCommandSource source, PlayerEntity player) {
|
||||
Pony iplayer = Pony.of(player);
|
||||
iplayer.getSpellSlot().removeIf(SpellPredicate.IS_DISGUISE, true);
|
||||
iplayer.getSpellSlot().removeIf(SpellPredicate.IS_DISGUISE);
|
||||
|
||||
if (source.getEntity() == player) {
|
||||
source.sendFeedback(() -> Text.translatable("commands.disguise.removed.self"), true);
|
||||
|
|
|
@ -311,7 +311,7 @@ public class Creature extends Living<LivingEntity> implements WeaklyOwned.Mutabl
|
|||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
super.toNBT(compound);
|
||||
getSpellSlot().get(true).ifPresent(effect -> {
|
||||
getSpellSlot().get().ifPresent(effect -> {
|
||||
compound.put("effect", Spell.writeNbt(effect));
|
||||
});
|
||||
compound.put("master", getMasterReference().toNBT());
|
||||
|
|
|
@ -290,7 +290,7 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
|||
public boolean canBeSeenBy(Entity entity) {
|
||||
return !isInvisible()
|
||||
&& getSpellSlot()
|
||||
.get(SpellPredicate.IS_DISGUISE, true)
|
||||
.get(SpellPredicate.IS_DISGUISE)
|
||||
.filter(spell -> spell.getDisguise().getAppearance() == entity)
|
||||
.isEmpty();
|
||||
}
|
||||
|
@ -424,7 +424,7 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
|||
}
|
||||
|
||||
public Optional<BlockPos> chooseClimbingPos() {
|
||||
return getSpellSlot().get(SpellPredicate.IS_DISGUISE, false)
|
||||
return getSpellSlot().get(SpellPredicate.IS_DISGUISE)
|
||||
.map(AbstractDisguiseSpell::getDisguise)
|
||||
.filter(EntityAppearance::canClimbWalls)
|
||||
.map(v -> entity.getBlockPos());
|
||||
|
@ -459,7 +459,7 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
|||
|
||||
@Override
|
||||
public boolean onProjectileImpact(ProjectileEntity projectile) {
|
||||
return getSpellSlot().get(true)
|
||||
return getSpellSlot().get()
|
||||
.filter(effect -> !effect.isDead()
|
||||
&& effect instanceof ProjectileImpactListener
|
||||
&& ((ProjectileImpactListener)effect).onProjectileImpact(projectile))
|
||||
|
@ -469,7 +469,7 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
|||
public float onImpact(float distance, float damageMultiplier, DamageSource cause) {
|
||||
float fallDistance = landEvent.fire(getEffectiveFallDistance(distance));
|
||||
|
||||
getSpellSlot().get(SpellPredicate.IS_DISGUISE, false).ifPresent(spell -> {
|
||||
getSpellSlot().get(SpellPredicate.IS_DISGUISE).ifPresent(spell -> {
|
||||
spell.getDisguise().onImpact(this, fallDistance, damageMultiplier, cause);
|
||||
});
|
||||
return fallDistance;
|
||||
|
|
|
@ -44,7 +44,7 @@ public class EntityCollisions {
|
|||
ShapeContext ctx = entity == null ? ShapeContext.absent() : ShapeContext.of(entity);
|
||||
return collectCollisionBoxes(box, collector -> {
|
||||
world.getOtherEntities(entity, box.expand(50), e -> {
|
||||
Caster.of(e).flatMap(c -> c.getSpellSlot().get(SpellPredicate.IS_DISGUISE, false)).ifPresent(p -> {
|
||||
Caster.of(e).flatMap(c -> c.getSpellSlot().get(SpellPredicate.IS_DISGUISE)).ifPresent(p -> {
|
||||
p.getDisguise().getCollissionShapes(ctx, collector);
|
||||
});
|
||||
if (e instanceof ComplexCollidable collidable) {
|
||||
|
|
|
@ -77,7 +77,7 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster<CastS
|
|||
|
||||
@Override
|
||||
public EntityDimensions getDimensions(EntityPose pose) {
|
||||
return super.getDimensions(pose).scaled(getSpellSlot().get(SpellType.IS_PLACED, false).map(spell -> spell.getScale(1)).orElse(1F));
|
||||
return super.getDimensions(pose).scaled(getSpellSlot().get(SpellType.IS_PLACED).map(spell -> spell.getScale(1)).orElse(1F));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -108,7 +108,7 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster<CastS
|
|||
|
||||
@Override
|
||||
public Affinity getAffinity() {
|
||||
return getSpellSlot().get(true).map(Spell::getAffinity).orElse(Affinity.NEUTRAL);
|
||||
return getSpellSlot().get().map(Spell::getAffinity).orElse(Affinity.NEUTRAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -142,7 +142,7 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster<CastS
|
|||
tag.put("owner", owner.toNBT());
|
||||
tag.put("level", level.toNbt());
|
||||
tag.put("corruption", corruption.toNbt());
|
||||
getSpellSlot().get(true).ifPresent(effect -> {
|
||||
getSpellSlot().get().ifPresent(effect -> {
|
||||
tag.put("effect", Spell.writeNbt(effect));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class CorruptionHandler implements Tickable {
|
|||
}
|
||||
|
||||
public boolean hasCorruptingMagic() {
|
||||
return pony.getSpellSlot().get(SpellPredicate.IS_CORRUPTING, false).isPresent() || UItems.ALICORN_AMULET.isApplicable(pony.asEntity());
|
||||
return pony.getSpellSlot().get(SpellPredicate.IS_CORRUPTING).isPresent() || UItems.ALICORN_AMULET.isApplicable(pony.asEntity());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -53,7 +53,7 @@ public class PlayerCamera extends MotionCompositor {
|
|||
|
||||
public Optional<Double> calculateDistance(double distance) {
|
||||
return player.getSpellSlot()
|
||||
.get(SpellPredicate.IS_DISGUISE, false)
|
||||
.get(SpellPredicate.IS_DISGUISE)
|
||||
.map(AbstractDisguiseSpell::getDisguise)
|
||||
.flatMap(d -> d.getDistance(player))
|
||||
.map(d -> distance * d);
|
||||
|
|
|
@ -39,7 +39,7 @@ public final class PlayerDimensions {
|
|||
}
|
||||
|
||||
Optional<Provider> getPredicate() {
|
||||
return pony.getSpellSlot().get(true)
|
||||
return pony.getSpellSlot().get()
|
||||
.filter(effect -> !effect.isDead() && effect instanceof Provider)
|
||||
.map(effect -> (Provider)effect);
|
||||
}
|
||||
|
|
|
@ -210,7 +210,7 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
|
|||
return FlightType.ARTIFICIAL;
|
||||
}
|
||||
|
||||
return pony.getSpellSlot().get(true)
|
||||
return pony.getSpellSlot().get()
|
||||
.filter(effect -> !effect.isDead() && effect instanceof FlightType.Provider)
|
||||
.map(effect -> ((FlightType.Provider)effect).getFlightType())
|
||||
.filter(FlightType::isPresent)
|
||||
|
|
|
@ -479,7 +479,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
|
|||
Race intrinsicRace = getSpecies();
|
||||
Race suppressedRace = getSuppressedRace();
|
||||
compositeRace = MetamorphosisStatusEffect.getEffectiveRace(entity, getSpellSlot()
|
||||
.get(SpellPredicate.IS_MIMIC, true)
|
||||
.get(SpellPredicate.IS_MIMIC)
|
||||
.map(AbstractDisguiseSpell::getDisguise)
|
||||
.map(EntityAppearance::getAppearance)
|
||||
.flatMap(Pony::of)
|
||||
|
@ -495,7 +495,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
|
|||
|
||||
@Override
|
||||
public Optional<BlockPos> chooseClimbingPos() {
|
||||
if (getObservedSpecies() == Race.CHANGELING && getSpellSlot().get(SpellPredicate.IS_DISGUISE, false).isEmpty()) {
|
||||
if (getObservedSpecies() == Race.CHANGELING && getSpellSlot().get(SpellPredicate.IS_DISGUISE).isEmpty()) {
|
||||
if (acrobatics.isFaceClimbable(entity.getWorld(), entity.getBlockPos(), entity.getHorizontalFacing()) || acrobatics.canHangAt(entity.getBlockPos())) {
|
||||
return Optional.of(entity.getBlockPos());
|
||||
}
|
||||
|
@ -718,7 +718,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
|
|||
|
||||
@Override
|
||||
protected float getEffectiveFallDistance(float distance) {
|
||||
boolean extraProtection = getSpellSlot().get(SpellType.SHIELD, false).isPresent();
|
||||
boolean extraProtection = getSpellSlot().get(SpellType.SHIELD).isPresent();
|
||||
|
||||
if (!entity.isCreative() && !entity.isSpectator()) {
|
||||
|
||||
|
@ -745,7 +745,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
|
|||
if (getObservedSpecies() == Race.KIRIN
|
||||
&& (stack.isIn(UTags.Items.COOLS_OFF_KIRINS) || PotionUtil.getPotion(stack) == Potions.WATER)) {
|
||||
getMagicalReserves().getCharge().multiply(0.5F);
|
||||
getSpellSlot().get(SpellType.RAGE, false).ifPresent(RageAbilitySpell::setExtenguishing);
|
||||
getSpellSlot().get(SpellType.RAGE).ifPresent(RageAbilitySpell::setExtenguishing);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -758,7 +758,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
|
|||
@Override
|
||||
public boolean subtractEnergyCost(double foodSubtract) {
|
||||
|
||||
if (getSpellSlot().get(SpellPredicate.IS_CORRUPTING, false).isPresent()) {
|
||||
if (getSpellSlot().get(SpellPredicate.IS_CORRUPTING).isPresent()) {
|
||||
int corruptionTaken = (int)(foodSubtract * (AmuletSelectors.ALICORN_AMULET.test(entity) ? 0.9F : 0.5F));
|
||||
foodSubtract -= corruptionTaken;
|
||||
getCorruption().add(corruptionTaken);
|
||||
|
@ -888,13 +888,13 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
|
|||
Race oldSuppressedRace = oldPlayer.getSuppressedRace();
|
||||
|
||||
if (alive) {
|
||||
oldPlayer.getSpellSlot().stream(true).forEach(getSpellSlot()::put);
|
||||
oldPlayer.getSpellSlot().stream().forEach(getSpellSlot()::put);
|
||||
} else {
|
||||
if (forcedSwap) {
|
||||
oldSuppressedRace = Race.UNSET;
|
||||
Channel.SERVER_SELECT_TRIBE.sendToPlayer(new MsgTribeSelect(Race.allPermitted(entity), "gui.unicopia.tribe_selection.respawn"), (ServerPlayerEntity)entity);
|
||||
} else {
|
||||
oldPlayer.getSpellSlot().stream(true).filter(SpellPredicate.IS_PLACED).forEach(getSpellSlot()::put);
|
||||
oldPlayer.getSpellSlot().stream().filter(SpellPredicate.IS_PLACED).forEach(getSpellSlot()::put);
|
||||
}
|
||||
|
||||
// putting it here instead of adding another injection point into ServerPlayerEntity.copyFrom()
|
||||
|
|
|
@ -47,7 +47,7 @@ public class EnchantedStaffItem extends StaffItem implements EnchantableItem, Ch
|
|||
|
||||
public static SpellType<?> getSpellType(Entity entity, boolean remove) {
|
||||
if (entity instanceof CastSpellEntity cast) {
|
||||
return cast.getSpellSlot().get(c -> !SpellPredicate.IS_PLACED.test(c), true)
|
||||
return cast.getSpellSlot().get(c -> !SpellPredicate.IS_PLACED.test(c))
|
||||
.map(Spell::getTypeAndTraits)
|
||||
.map(CustomisedSpellType::type)
|
||||
.orElse(SpellType.empty());
|
||||
|
|
|
@ -108,7 +108,7 @@ abstract class MixinLivingEntity extends Entity implements LivingEntityDuck, Equ
|
|||
@Inject(method = "isPushable()Z", at = @At("HEAD"), cancellable = true)
|
||||
private void onIsPushable(CallbackInfoReturnable<Boolean> info) {
|
||||
Caster.of(this)
|
||||
.flatMap(c -> c.getSpellSlot().get(SpellPredicate.IS_DISGUISE, false))
|
||||
.flatMap(c -> c.getSpellSlot().get(SpellPredicate.IS_DISGUISE))
|
||||
.map(AbstractDisguiseSpell::getDisguise)
|
||||
.map(EntityAppearance::getAppearance)
|
||||
.filter(Entity::isPushable)
|
||||
|
|
|
@ -24,7 +24,7 @@ abstract class MixinClientPlayNetworkHandler {
|
|||
Living<?> living = Living.living(packet.getEntity(world));
|
||||
if (living != null) {
|
||||
living.getSpellSlot()
|
||||
.get(SpellPredicate.IS_DISGUISE, false)
|
||||
.get(SpellPredicate.IS_DISGUISE)
|
||||
.map(Disguise::getDisguise)
|
||||
.map(EntityAppearance::getAppearance)
|
||||
.ifPresent(appearance -> {
|
||||
|
|
|
@ -50,7 +50,7 @@ public record MsgCasterLookRequest (UUID spellId) implements Packet<PlayerEntity
|
|||
@Override
|
||||
public void handle(ServerPlayerEntity sender) {
|
||||
Pony.of(sender).getSpellSlot()
|
||||
.get(SpellPredicate.IS_ORIENTED.withId(spellId), false)
|
||||
.get(SpellPredicate.IS_ORIENTED.withId(spellId))
|
||||
.ifPresent(spell -> {
|
||||
spell.setOrientation(rotation);
|
||||
});
|
||||
|
|
|
@ -66,7 +66,7 @@ public class EffectSync implements SpellContainer, NbtSerialisable {
|
|||
Unicopia.LOGGER.error("Error whilst ticking spell on entity {}", owner, t);
|
||||
}
|
||||
return Operation.REMOVE;
|
||||
}, owner.isClient());
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Unicopia.LOGGER.error("Error whilst ticking spell on entity {}", owner.asEntity(), e);
|
||||
}
|
||||
|
@ -80,12 +80,12 @@ public class EffectSync implements SpellContainer, NbtSerialisable {
|
|||
|
||||
@Override
|
||||
public boolean contains(@Nullable SpellPredicate<?> type) {
|
||||
return read(type, true, false).findFirst().isPresent();
|
||||
return read(type).findFirst().isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Spell> Optional<T> get(@Nullable SpellPredicate<T> type, boolean update) {
|
||||
return read(type, update, true).findFirst();
|
||||
public <T extends Spell> Optional<T> get(@Nullable SpellPredicate<T> type) {
|
||||
return read(type).findFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -108,8 +108,8 @@ public class EffectSync implements SpellContainer, NbtSerialisable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean removeWhere(Predicate<Spell> test, boolean update) {
|
||||
return reduce(update, (initial, spell) -> {
|
||||
public boolean removeWhere(Predicate<Spell> test) {
|
||||
return reduce((initial, spell) -> {
|
||||
if (!test.test(spell)) {
|
||||
return initial;
|
||||
}
|
||||
|
@ -123,8 +123,8 @@ public class EffectSync implements SpellContainer, NbtSerialisable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean forEach(Function<Spell, Operation> test, boolean update) {
|
||||
return reduce(update, (initial, effect) -> {
|
||||
public boolean forEach(Function<Spell, Operation> test) {
|
||||
return reduce((initial, effect) -> {
|
||||
Operation op = test.apply(effect);
|
||||
if (op == Operation.REMOVE) {
|
||||
spells.removeReference(effect);
|
||||
|
@ -136,13 +136,13 @@ public class EffectSync implements SpellContainer, NbtSerialisable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Stream<Spell> stream(boolean update) {
|
||||
return stream(null, update);
|
||||
public Stream<Spell> stream() {
|
||||
return stream(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Spell> Stream<T> stream(@Nullable SpellPredicate<T> type, boolean update) {
|
||||
return read(type, update, true);
|
||||
public <T extends Spell> Stream<T> stream(@Nullable SpellPredicate<T> type) {
|
||||
return read(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -158,10 +158,11 @@ public class EffectSync implements SpellContainer, NbtSerialisable {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends Spell> Stream<T> read(@Nullable SpellPredicate<T> type, boolean synchronize, boolean sendUpdate) {
|
||||
if (synchronize && spells.fromNbt(owner.asEntity().getDataTracker().get(param)) && sendUpdate) {
|
||||
write();
|
||||
private <T extends Spell> Stream<T> read(@Nullable SpellPredicate<T> type) {
|
||||
if (owner.isClient()) {
|
||||
spells.fromNbt(owner.asEntity().getDataTracker().get(param));
|
||||
}
|
||||
write();
|
||||
|
||||
if (type == null) {
|
||||
return (Stream<T>)spells.getReferences();
|
||||
|
@ -169,9 +170,9 @@ public class EffectSync implements SpellContainer, NbtSerialisable {
|
|||
return (Stream<T>)spells.getReferences().flatMap(s -> s.findMatches(type));
|
||||
}
|
||||
|
||||
private boolean reduce(boolean update, Alteration alteration) {
|
||||
private boolean reduce(Alteration alteration) {
|
||||
boolean initial = false;
|
||||
for (Spell i : read(null, update, false).toList()) {
|
||||
for (Spell i : read(null).toList()) {
|
||||
initial = alteration.apply(initial, i);
|
||||
}
|
||||
|
||||
|
@ -180,7 +181,7 @@ public class EffectSync implements SpellContainer, NbtSerialisable {
|
|||
}
|
||||
|
||||
private void write() {
|
||||
if (spells.isDirty()) {
|
||||
if (spells.isDirty() && !owner.isClient()) {
|
||||
owner.asEntity().getDataTracker().set(param, spells.toNbt());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ public class MagicBeamEntity extends MagicProjectileEntity implements Caster<Mag
|
|||
|
||||
@Override
|
||||
public Affinity getAffinity() {
|
||||
return getSpellSlot().get(true).map(Affine::getAffinity).orElse(Affinity.NEUTRAL);
|
||||
return getSpellSlot().get().map(Affine::getAffinity).orElse(Affinity.NEUTRAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -163,7 +163,7 @@ public class MagicBeamEntity extends MagicProjectileEntity implements Caster<Mag
|
|||
super.writeCustomDataToNbt(compound);
|
||||
compound.putBoolean("hydrophobic", getHydrophobic());
|
||||
physics.toNBT(compound);
|
||||
getSpellSlot().get(true).ifPresent(effect -> {
|
||||
getSpellSlot().get().ifPresent(effect -> {
|
||||
compound.put("effect", Spell.writeNbt(effect));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -242,7 +242,7 @@ public class Ether extends PersistentState {
|
|||
spell = entity
|
||||
.getOrEmpty(world)
|
||||
.flatMap(Caster::of)
|
||||
.flatMap(caster -> caster.getSpellSlot().<T>get(s -> s.getUuid().equals(spellId), true))
|
||||
.flatMap(caster -> caster.getSpellSlot().<T>get(s -> s.getUuid().equals(spellId)))
|
||||
.orElse(null);
|
||||
|
||||
if (spell != null) {
|
||||
|
|
Loading…
Reference in a new issue