Skip to content

Commit

Permalink
Added Iteration Stratagem
Browse files Browse the repository at this point in the history
  • Loading branch information
StellarWitch7 committed Jul 4, 2024
1 parent d177aa2 commit b24d8df
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 2 deletions.
Binary file added libs/sodium-fabric-0.5.11+mc1.21.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import java.util.function.Supplier;

@Mixin(targets = "net/minecraft/client/render/chunk/RenderedChunk")
@Mixin(targets = "net.minecraft.client.render.chunk.RenderedChunk")
public class RenderedChunkMixin {
@Shadow @Final
private WorldChunk chunk;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package dev.enjarai.trickster.mixin.client;

public class SodiumLevelSliceMixin {
}
58 changes: 58 additions & 0 deletions src/main/java/dev/enjarai/trickster/ConditionalMixins.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package dev.enjarai.trickster;

import com.google.common.collect.ImmutableMap;
import net.fabricmc.loader.api.FabricLoader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;

// stole this impl from https://github.com/Juuxel/Adorn/blob/bd70a2955640897bc68ff1f4f201fe5e6c10bc32/fabric/src/main/java/juuxel/adorn/AdornMixinPlugin.java
public class ClientConditionalMixins implements IMixinConfigPlugin {
private static final Supplier<Boolean> TRUE = () -> true;

private static final Map<String, Supplier<Boolean>> CONDITIONS = ImmutableMap.of(
"dev.enjarai.trickster.mixin.client.SodiumLevelSliceMixin", () -> FabricLoader.getInstance().isModLoaded("sodium")
);

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return CONDITIONS.getOrDefault(mixinClassName, TRUE).get();
}

// Boilerplate

@Override
public void onLoad(String mixinPackage) {

}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {

}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}
}
2 changes: 2 additions & 0 deletions src/main/java/dev/enjarai/trickster/spell/tricks/Tricks.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.enjarai.trickster.spell.Pattern;
import dev.enjarai.trickster.spell.tricks.func.ClosureTrick;
import dev.enjarai.trickster.spell.tricks.func.ExecuteTrick;
import dev.enjarai.trickster.spell.tricks.func.IteratorTrick;
import dev.enjarai.trickster.spell.tricks.func.LoadArgumentTrick;
import dev.enjarai.trickster.spell.tricks.basic.*;
import dev.enjarai.trickster.spell.tricks.block.*;
Expand Down Expand Up @@ -39,6 +40,7 @@ public RegistryEntry.Reference<Trick> add(RegistryKey<Trick> key, Trick value, R

// Functions
public static final ExecuteTrick EXECUTE = register("execute", new ExecuteTrick());
public static final IteratorTrick ITERATOR = register("iterator", new IteratorTrick());
public static final ClosureTrick CLOSURE = register("closure", new ClosureTrick());
public static final LoadArgumentTrick LOAD_ARGUMENT_1 = register("load_argument_1", new LoadArgumentTrick(Pattern.of(4, 1), 0));
public static final LoadArgumentTrick LOAD_ARGUMENT_2 = register("load_argument_2", new LoadArgumentTrick(Pattern.of(4, 2), 1));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dev.enjarai.trickster.spell.tricks.func;

import dev.enjarai.trickster.spell.Fragment;
import dev.enjarai.trickster.spell.Pattern;
import dev.enjarai.trickster.spell.SpellContext;
import dev.enjarai.trickster.spell.fragment.FragmentType;
import dev.enjarai.trickster.spell.fragment.ListFragment;
import dev.enjarai.trickster.spell.fragment.NumberFragment;
import dev.enjarai.trickster.spell.tricks.Trick;
import dev.enjarai.trickster.spell.tricks.blunder.BlunderException;

import java.util.ArrayList;
import java.util.List;

public class IteratorTrick extends Trick {
public IteratorTrick() {
super(Pattern.of(3, 6, 4, 0, 1, 2, 5, 8, 7, 4, 3));
}

@Override
public Fragment activate(SpellContext ctx, List<Fragment> fragments) throws BlunderException {
var executable = expectInput(fragments, FragmentType.SPELL_PART, 0);
var list = expectInput(fragments, FragmentType.LIST, 1);
var result = new ArrayList<Fragment>();
int index = 0;

for (var item : list.fragments()) {
var args = new ArrayList<Fragment>();
args.add(item);
args.add(new NumberFragment(index));
args.addAll(fragments.subList(1, fragments.size()));
ctx.pushPartGlyph(args);
ctx.pushStackTrace(-2);
result.add(executable.run(ctx));
ctx.popStackTrace();
ctx.popPartGlyph();
index++;
}

return new ListFragment(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ Makes the target block temporarily affected by gravity as if it were sand.

;;;;;

<|page-title@lavender:book_components|title=Note: Shadow Blocks|>Shadow blocks,
sometimes also referred to as echoes or echo blocks,
are illusions superimposed onto a material block.
They are dispelled when the state of the material block changes,
but can also be removed using a Revelation Ploy.

;;;;;

<|glyph@trickster:templates|trick-id=trickster:disguise_block,title=Shadow Ploy|>

vector, block -> boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,32 @@ spell, [spell, any]... -> spell

---

Replaces any occurrence of any of the latter spell's patterns inside the first spell
Replaces any occurrence of any of the latter spell's patterns inside the first spell
with the fragment immediately following them.

;;;;;

<|glyph@trickster:templates|trick-id=trickster:iterator,title=Iteration Stratagem|>

spell, any[], any... -> any[]

---

For each item in the given list, execute the given spell, creating a new list from the results.

;;;;;

any, number, any[], any...

---

These arguments are provided to each execution of the given spell,
where the first argument is the item, the second is its index in the given list,
the third is the given list, followed by up to five more arguments provided by this glyph's inputs.
The results of each execution are collected into a new list, which is the result of this glyph.

;;;;;

<|page-title@lavender:book_components|title=Note: Arguments|>Fragments can be passed into executed spell fragments as arguments.


Expand Down

0 comments on commit b24d8df

Please sign in to comment.