From 4bac633a235c9cbaf16aa2f7d034e9947565d4d2 Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 21 May 2024 23:10:02 +0100 Subject: [PATCH] Remove the update argument when interacting with spell slots --- .../ability/ChangelingDisguiseAbility.java | 2 +- .../unicopia/ability/TimeChangeAbility.java | 4 +- .../ability/UnicornCastingAbility.java | 2 +- .../ability/UnicornDispellAbility.java | 2 +- .../ability/magic/SpellContainer.java | 20 +++++----- .../magic/spell/AbstractDisguiseSpell.java | 2 +- .../magic/spell/effect/BubbleSpell.java | 3 +- .../spell/effect/DisperseIllusionSpell.java | 2 +- .../magic/spell/effect/MindSwapSpell.java | 4 +- .../client/gui/DismissSpellScreen.java | 4 +- .../client/gui/SpellIconRenderer.java | 4 +- .../SpellbookProfilePageContent.java | 2 +- .../render/DisguisedArmsFeatureRenderer.java | 2 +- .../render/EntityReplacementManager.java | 2 +- .../client/render/HornFeatureRenderer.java | 4 +- .../entity/MagicBeamEntityRenderer.java | 2 +- .../spell/SpellEffectsRenderDispatcher.java | 4 +- .../unicopia/command/DisguiseCommand.java | 4 +- .../unicopia/entity/Creature.java | 2 +- .../unicopia/entity/Living.java | 8 ++-- .../entity/collision/EntityCollisions.java | 2 +- .../unicopia/entity/mob/CastSpellEntity.java | 6 +-- .../entity/player/CorruptionHandler.java | 2 +- .../unicopia/entity/player/PlayerCamera.java | 2 +- .../entity/player/PlayerDimensions.java | 2 +- .../unicopia/entity/player/PlayerPhysics.java | 2 +- .../unicopia/entity/player/Pony.java | 14 +++---- .../unicopia/item/EnchantedStaffItem.java | 2 +- .../unicopia/mixin/MixinLivingEntity.java | 2 +- .../client/MixinClientPlayNetworkHandler.java | 2 +- .../network/MsgCasterLookRequest.java | 2 +- .../unicopia/network/datasync/EffectSync.java | 37 ++++++++++--------- .../unicopia/projectile/MagicBeamEntity.java | 4 +- .../unicopia/server/world/Ether.java | 2 +- 34 files changed, 80 insertions(+), 80 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java index 6f3e2c60..dd6af2cc 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java @@ -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)) { diff --git a/src/main/java/com/minelittlepony/unicopia/ability/TimeChangeAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/TimeChangeAbility.java index b06df709..99e7d543 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/TimeChangeAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/TimeChangeAbility.java @@ -57,9 +57,7 @@ public class TimeChangeAbility implements Ability { 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)); } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java index 44edde82..6542072f 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java @@ -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); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornDispellAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornDispellAbility.java index 4eb6f47a..61f4a3e8 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/UnicornDispellAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/UnicornDispellAbility.java @@ -97,7 +97,7 @@ public class UnicornDispellAbility implements Ability { spell.setDead(); spell.tickDying(target); return Operation.ofBoolean(!spell.isDead()); - }, true); + }); }); return true; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellContainer.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellContainer.java index e703911d..0cae9891 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellContainer.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellContainer.java @@ -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 Optional get(boolean update) { - return get(null, update); + default Optional get() { + return get(null); } /** * Gets the active effect for this caster updating it if needed. */ - Optional get(@Nullable SpellPredicate type, boolean update); + Optional get(@Nullable SpellPredicate type); /** * Sets the active effect. @@ -51,8 +51,8 @@ public interface SpellContainer { * * @return True if the collection was changed */ - default boolean removeIf(Predicate test, boolean update) { - return removeWhere(spell -> spell.findMatches(test).findFirst().isPresent(), update); + default boolean removeIf(Predicate 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 test, boolean update); + boolean removeWhere(Predicate test); /** * Iterates active spells and optionally removes matching ones. * * @return True if any matching spells remain active */ - boolean forEach(Function action, boolean update); + boolean forEach(Function action); /** * Gets all active effects for this caster updating it if needed. */ - Stream stream(boolean update); + Stream stream(); /** * Gets all active effects for this caster that match the given type updating it if needed. */ - Stream stream(@Nullable SpellPredicate type, boolean update); + Stream stream(@Nullable SpellPredicate type); /** * Removes all effects currently active in this slot. diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDisguiseSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDisguiseSpell.java index 1c34f82d..14a35e99 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDisguiseSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDisguiseSpell.java @@ -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; diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/BubbleSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/BubbleSpell.java index db9f7d5e..2cc4dd51 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/BubbleSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/BubbleSpell.java @@ -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; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DisperseIllusionSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DisperseIllusionSpell.java index 9affae3e..3d88d40f 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DisperseIllusionSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DisperseIllusionSpell.java @@ -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)); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/MindSwapSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/MindSwapSpell.java index 4b2f9cb0..ed55f91b 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/MindSwapSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/MindSwapSpell.java @@ -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); diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/DismissSpellScreen.java b/src/main/java/com/minelittlepony/unicopia/client/gui/DismissSpellScreen.java index 8633b6f7..4910981f 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/DismissSpellScreen.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/DismissSpellScreen.java @@ -43,7 +43,7 @@ public class DismissSpellScreen extends GameGui { List 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; diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/SpellIconRenderer.java b/src/main/java/com/minelittlepony/unicopia/client/gui/SpellIconRenderer.java index 77a54548..a113c369 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/SpellIconRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/SpellIconRenderer.java @@ -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); diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookProfilePageContent.java b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookProfilePageContent.java index f0829b23..f68d0790 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookProfilePageContent.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookProfilePageContent.java @@ -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; diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/DisguisedArmsFeatureRenderer.java b/src/main/java/com/minelittlepony/unicopia/client/render/DisguisedArmsFeatureRenderer.java index c130779c..6ace7501 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/DisguisedArmsFeatureRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/DisguisedArmsFeatureRenderer.java @@ -114,7 +114,7 @@ public class DisguisedArmsFeatureRenderer 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); diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/EntityReplacementManager.java b/src/main/java/com/minelittlepony/unicopia/client/render/EntityReplacementManager.java index c1a9d8c7..8b759a18 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/EntityReplacementManager.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/EntityReplacementManager.java @@ -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> getMobTypePool(EntityType type) { diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/HornFeatureRenderer.java b/src/main/java/com/minelittlepony/unicopia/client/render/HornFeatureRenderer.java index 786dee41..2b38a87f 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/HornFeatureRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/HornFeatureRenderer.java @@ -55,7 +55,9 @@ public class HornFeatureRenderer 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); diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/entity/MagicBeamEntityRenderer.java b/src/main/java/com/minelittlepony/unicopia/client/render/entity/MagicBeamEntityRenderer.java index 24d4a042..3310d883 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/entity/MagicBeamEntityRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/entity/MagicBeamEntityRenderer.java @@ -56,7 +56,7 @@ public class MagicBeamEntityRenderer extends EntityRenderer { -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); diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/spell/SpellEffectsRenderDispatcher.java b/src/main/java/com/minelittlepony/unicopia/client/render/spell/SpellEffectsRenderDispatcher.java index 4c78034a..b2bcf87a 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/spell/SpellEffectsRenderDispatcher.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/spell/SpellEffectsRenderDispatcher.java @@ -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()))), diff --git a/src/main/java/com/minelittlepony/unicopia/command/DisguiseCommand.java b/src/main/java/com/minelittlepony/unicopia/command/DisguiseCommand.java index 31306fad..d735c89a 100644 --- a/src/main/java/com/minelittlepony/unicopia/command/DisguiseCommand.java +++ b/src/main/java/com/minelittlepony/unicopia/command/DisguiseCommand.java @@ -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); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/Creature.java b/src/main/java/com/minelittlepony/unicopia/entity/Creature.java index 46453917..51ad4fa5 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/Creature.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/Creature.java @@ -311,7 +311,7 @@ public class Creature extends Living 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()); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/Living.java b/src/main/java/com/minelittlepony/unicopia/entity/Living.java index 407608f1..58dc2e00 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/Living.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/Living.java @@ -290,7 +290,7 @@ public abstract class Living implements Equine, 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 implements Equine, Caste } public Optional 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 implements Equine, 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 implements Equine, 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; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/collision/EntityCollisions.java b/src/main/java/com/minelittlepony/unicopia/entity/collision/EntityCollisions.java index d2d65f3e..b4454d66 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/collision/EntityCollisions.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/collision/EntityCollisions.java @@ -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) { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java index 649bb5d5..0643087f 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java @@ -77,7 +77,7 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster 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 { + getSpellSlot().get().ifPresent(effect -> { tag.put("effect", Spell.writeNbt(effect)); }); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/CorruptionHandler.java b/src/main/java/com/minelittlepony/unicopia/entity/player/CorruptionHandler.java index d3cbc40d..0ea3e639 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/CorruptionHandler.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/CorruptionHandler.java @@ -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 diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java index 61effece..792caec6 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java @@ -53,7 +53,7 @@ public class PlayerCamera extends MotionCompositor { public Optional 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); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerDimensions.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerDimensions.java index a2e5a329..491a66fd 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerDimensions.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerDimensions.java @@ -39,7 +39,7 @@ public final class PlayerDimensions { } Optional getPredicate() { - return pony.getSpellSlot().get(true) + return pony.getSpellSlot().get() .filter(effect -> !effect.isDead() && effect instanceof Provider) .map(effect -> (Provider)effect); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java index 77ee72e0..a9be901e 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java @@ -210,7 +210,7 @@ public class PlayerPhysics extends EntityPhysics 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) diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java index 82033249..2527bf47 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -479,7 +479,7 @@ public class Pony extends Living implements Copyable, 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 implements Copyable, Update @Override public Optional 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 implements Copyable, 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 implements Copyable, 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 implements Copyable, 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 implements Copyable, 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() diff --git a/src/main/java/com/minelittlepony/unicopia/item/EnchantedStaffItem.java b/src/main/java/com/minelittlepony/unicopia/item/EnchantedStaffItem.java index 6d08b1f7..04868e0b 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/EnchantedStaffItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/EnchantedStaffItem.java @@ -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()); diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinLivingEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinLivingEntity.java index da1cff6a..45bfa819 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinLivingEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinLivingEntity.java @@ -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 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) diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinClientPlayNetworkHandler.java b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinClientPlayNetworkHandler.java index 06821d12..e8c1179b 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinClientPlayNetworkHandler.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinClientPlayNetworkHandler.java @@ -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 -> { diff --git a/src/main/java/com/minelittlepony/unicopia/network/MsgCasterLookRequest.java b/src/main/java/com/minelittlepony/unicopia/network/MsgCasterLookRequest.java index d5be5999..5164e0f1 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/MsgCasterLookRequest.java +++ b/src/main/java/com/minelittlepony/unicopia/network/MsgCasterLookRequest.java @@ -50,7 +50,7 @@ public record MsgCasterLookRequest (UUID spellId) implements Packet { spell.setOrientation(rotation); }); diff --git a/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java b/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java index c66cac4c..36fa7a65 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java +++ b/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java @@ -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 Optional get(@Nullable SpellPredicate type, boolean update) { - return read(type, update, true).findFirst(); + public Optional get(@Nullable SpellPredicate type) { + return read(type).findFirst(); } @Override @@ -108,8 +108,8 @@ public class EffectSync implements SpellContainer, NbtSerialisable { } @Override - public boolean removeWhere(Predicate test, boolean update) { - return reduce(update, (initial, spell) -> { + public boolean removeWhere(Predicate 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 test, boolean update) { - return reduce(update, (initial, effect) -> { + public boolean forEach(Function 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 stream(boolean update) { - return stream(null, update); + public Stream stream() { + return stream(null); } @Override - public Stream stream(@Nullable SpellPredicate type, boolean update) { - return read(type, update, true); + public Stream stream(@Nullable SpellPredicate type) { + return read(type); } @Override @@ -158,10 +158,11 @@ public class EffectSync implements SpellContainer, NbtSerialisable { } @SuppressWarnings("unchecked") - private Stream read(@Nullable SpellPredicate type, boolean synchronize, boolean sendUpdate) { - if (synchronize && spells.fromNbt(owner.asEntity().getDataTracker().get(param)) && sendUpdate) { - write(); + private Stream read(@Nullable SpellPredicate type) { + if (owner.isClient()) { + spells.fromNbt(owner.asEntity().getDataTracker().get(param)); } + write(); if (type == null) { return (Stream)spells.getReferences(); @@ -169,9 +170,9 @@ public class EffectSync implements SpellContainer, NbtSerialisable { return (Stream)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()); } } diff --git a/src/main/java/com/minelittlepony/unicopia/projectile/MagicBeamEntity.java b/src/main/java/com/minelittlepony/unicopia/projectile/MagicBeamEntity.java index daea0f24..7d92a756 100644 --- a/src/main/java/com/minelittlepony/unicopia/projectile/MagicBeamEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/projectile/MagicBeamEntity.java @@ -114,7 +114,7 @@ public class MagicBeamEntity extends MagicProjectileEntity implements Caster { + getSpellSlot().get().ifPresent(effect -> { compound.put("effect", Spell.writeNbt(effect)); }); } diff --git a/src/main/java/com/minelittlepony/unicopia/server/world/Ether.java b/src/main/java/com/minelittlepony/unicopia/server/world/Ether.java index 73ffa38d..10110d70 100644 --- a/src/main/java/com/minelittlepony/unicopia/server/world/Ether.java +++ b/src/main/java/com/minelittlepony/unicopia/server/world/Ether.java @@ -242,7 +242,7 @@ public class Ether extends PersistentState { spell = entity .getOrEmpty(world) .flatMap(Caster::of) - .flatMap(caster -> caster.getSpellSlot().get(s -> s.getUuid().equals(spellId), true)) + .flatMap(caster -> caster.getSpellSlot().get(s -> s.getUuid().equals(spellId))) .orElse(null); if (spell != null) {