Skip to content

Commit

Permalink
Okay fine auri
Browse files Browse the repository at this point in the history
  • Loading branch information
enjarai committed Sep 20, 2024
1 parent aed0eef commit 6f85ed9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ public void updateSpell(SpellPart spell) {
((ServerPlayerEntity) player()).getServerWorld().playSoundFromEntity(
null, player(), ModSounds.CAST, SoundCategory.PLAYERS, 1f, ModSounds.randomPitch(0.8f, 0.2f));
} else {
spell.brutallyMurderEphemerals();
this.spell.set(spell);
this.spell.set(spell.applyEphemeral());
}

SpellComponent.setSpellPart(scrollStack, spell, Optional.empty(), false);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/dev/enjarai/trickster/spell/Fragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ default SerializedSpellInstruction asSerialized() {
return new SerializedSpellInstruction(SpellInstructionType.FRAGMENT, this);
}

/**
* Potentially recursively remove ephemeral values from this fragment.
* May return <pre>this</pre> or any other new fragment.
* Potentially results in cloning the entire fragment if required.
*/
default Fragment applyEphemeral() {
return this;
}
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/dev/enjarai/trickster/spell/SpellPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@ public SpellExecutor makeFork(SpellContext ctx, List<Fragment> args) throws Blun
return new DefaultSpellExecutor(this, ctx.executionState().recurseOrThrow(args));
}

public void brutallyMurderEphemerals() {
subParts.forEach(SpellPart::brutallyMurderEphemerals);

if (glyph instanceof SpellPart spellPart) {
spellPart.brutallyMurderEphemerals();
} else {
glyph = glyph.applyEphemeral();
}
/**
* Since spell parts are mutable, this implementation deeply clones the entire object.
*/
@Override
public SpellPart applyEphemeral() {
return new SpellPart(glyph.applyEphemeral(), subParts.stream()
.map(SpellPart::applyEphemeral).toList());
}

public Fragment destructiveRun(SpellContext ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.enjarai.trickster.spell.Fragment;
import dev.enjarai.trickster.spell.Pattern;
import dev.enjarai.trickster.spell.SpellContext;
import dev.enjarai.trickster.spell.SpellPart;
import dev.enjarai.trickster.spell.fragment.BooleanFragment;
import dev.enjarai.trickster.spell.fragment.FragmentType;
import dev.enjarai.trickster.spell.trick.Trick;
Expand Down Expand Up @@ -38,11 +39,7 @@ public Fragment activate(SpellContext ctx, List<Fragment> fragments, boolean clo
} else {
return Optional.of(expectType(s, FragmentType.SPELL_PART));
}
}).map(s -> {
var n = s.deepClone();
n.brutallyMurderEphemerals();
return n;
});
}).map(SpellPart::applyEphemeral);

return player.map(serverPlayerEntity -> Pair.of(serverPlayerEntity, serverPlayerEntity.getOffHandStack())).map(pair -> {
var serverPlayer = pair.getFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public Fragment activate(SpellContext ctx, List<Fragment> fragments) throws Blun
if (ctx.source().getWorld().getBlockState(blockPos).isAir()) {
ctx.useMana(this, 496);

var spell = executable.deepClone();
spell.brutallyMurderEphemerals();
var spell = executable.applyEphemeral();

ctx.source().getWorld().setBlockState(blockPos,
ModBlocks.SPELL_CIRCLE.getDefaultState().with(SpellCircleBlock.FACING, facing));
Expand Down

0 comments on commit 6f85ed9

Please sign in to comment.