-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
478 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 11 additions & 1 deletion
12
src/main/java/dev/enjarai/trickster/spell/SpellContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/dev/enjarai/trickster/spell/fragment/BooleanFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package dev.enjarai.trickster.spell.fragment; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.MapCodec; | ||
import dev.enjarai.trickster.spell.Fragment; | ||
|
||
public record BooleanFragment(boolean bool) implements Fragment { | ||
public static final MapCodec<BooleanFragment> CODEC = Codec.BOOL | ||
.fieldOf("bool").xmap(BooleanFragment::new, BooleanFragment::bool); | ||
public static final BooleanFragment TRUE = new BooleanFragment(true); | ||
public static final BooleanFragment FALSE = new BooleanFragment(false); | ||
|
||
@Override | ||
public FragmentType<?> type() { | ||
return FragmentType.BOOLEAN; | ||
} | ||
|
||
@Override | ||
public String asString() { | ||
return "" + bool; | ||
} | ||
|
||
@Override | ||
public BooleanFragment asBoolean() { | ||
return bool ? TRUE : FALSE; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/dev/enjarai/trickster/spell/fragment/EntityFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dev.enjarai.trickster.spell.fragment; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import dev.enjarai.trickster.spell.Fragment; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Uuids; | ||
|
||
import java.util.UUID; | ||
|
||
public record EntityFragment(UUID uuid, Text name) implements Fragment { | ||
public static final MapCodec<EntityFragment> CODEC = Uuids.CODEC | ||
.xmap(uuid -> new EntityFragment(uuid, Text.of(uuid)), EntityFragment::uuid).fieldOf("uuid"); | ||
|
||
@Override | ||
public FragmentType<?> type() { | ||
return FragmentType.ENTITY; | ||
} | ||
|
||
@Override | ||
public String asString() { | ||
return name.getString(); | ||
} | ||
|
||
@Override | ||
public BooleanFragment asBoolean() { | ||
return BooleanFragment.TRUE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/dev/enjarai/trickster/spell/fragment/RoundableFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package dev.enjarai.trickster.spell.fragment; | ||
|
||
import dev.enjarai.trickster.spell.Fragment; | ||
import dev.enjarai.trickster.spell.tricks.blunder.BlunderException; | ||
|
||
public interface RoundableFragment extends Fragment { | ||
RoundableFragment floor() throws BlunderException; | ||
|
||
RoundableFragment ceil() throws BlunderException; | ||
|
||
RoundableFragment round() throws BlunderException; | ||
} |
95 changes: 95 additions & 0 deletions
95
src/main/java/dev/enjarai/trickster/spell/fragment/VectorFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package dev.enjarai.trickster.spell.fragment; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.DataResult; | ||
import com.mojang.serialization.MapCodec; | ||
import dev.enjarai.trickster.spell.Fragment; | ||
import dev.enjarai.trickster.spell.tricks.Tricks; | ||
import dev.enjarai.trickster.spell.tricks.blunder.BlunderException; | ||
import dev.enjarai.trickster.spell.tricks.blunder.DivideByZeroBlunder; | ||
import dev.enjarai.trickster.spell.tricks.blunder.IncompatibleTypesBlunder; | ||
import org.joml.Vector3d; | ||
import org.joml.Vector3dc; | ||
|
||
import java.util.List; | ||
|
||
public record VectorFragment(Vector3dc vector) implements Fragment, AddableFragment, SubtractableFragment, MultiplicableFragment, DivisibleFragment, RoundableFragment { | ||
public static final MapCodec<VectorFragment> CODEC = Codec.DOUBLE.listOf(3, 3) | ||
.<Vector3dc>xmap(list -> new Vector3d(list.get(0), list.get(1), list.get(2)), vec -> List.of(vec.x(), vec.y(), vec.z())) | ||
.xmap(VectorFragment::new, VectorFragment::vector) | ||
.fieldOf("vector"); | ||
|
||
@Override | ||
public FragmentType<?> type() { | ||
return FragmentType.VECTOR; | ||
} | ||
|
||
@Override | ||
public String asString() { | ||
return "(" + vector.x() + ", " + vector.y() + ", " + vector.z() + ")"; | ||
} | ||
|
||
@Override | ||
public BooleanFragment asBoolean() { | ||
return new BooleanFragment(!new Vector3d().equals(vector)); | ||
} | ||
|
||
@Override | ||
public AddableFragment add(Fragment other) throws BlunderException { | ||
if (other instanceof VectorFragment vec) { | ||
return new VectorFragment(vector.add(vec.vector, new Vector3d())); | ||
} | ||
throw new IncompatibleTypesBlunder(Tricks.ADD); | ||
} | ||
|
||
@Override | ||
public SubtractableFragment subtract(Fragment other) throws BlunderException { | ||
if (other instanceof VectorFragment vec) { | ||
return new VectorFragment(vector.sub(vec.vector, new Vector3d())); | ||
} | ||
throw new IncompatibleTypesBlunder(Tricks.SUBTRACT); | ||
} | ||
|
||
@Override | ||
public MultiplicableFragment multiply(Fragment other) throws BlunderException { | ||
if (other instanceof NumberFragment num) { | ||
return new VectorFragment(vector.mul(num.number(), new Vector3d())); | ||
} else if (other instanceof VectorFragment vec) { | ||
return new VectorFragment(vector.mul(vec.vector, new Vector3d())); | ||
} | ||
throw new IncompatibleTypesBlunder(Tricks.MULTIPLY); | ||
} | ||
|
||
@Override | ||
public DivisibleFragment divide(Fragment other) throws BlunderException { | ||
if (other instanceof VectorFragment vec) { | ||
if (vec.vector.x() == 0 || vec.vector.y() == 0 || vec.vector.z() == 0) { | ||
throw new DivideByZeroBlunder(Tricks.DIVIDE); | ||
} | ||
|
||
return new VectorFragment(vector.div(vec.vector, new Vector3d())); | ||
} else if (other instanceof NumberFragment num) { | ||
if (num.number() == 0) { | ||
throw new DivideByZeroBlunder(Tricks.DIVIDE); | ||
} | ||
|
||
return new VectorFragment(vector.div(num.number(), new Vector3d())); | ||
} | ||
throw new IncompatibleTypesBlunder(Tricks.DIVIDE); | ||
} | ||
|
||
@Override | ||
public RoundableFragment floor() throws BlunderException { | ||
return new VectorFragment(vector.floor(new Vector3d())); | ||
} | ||
|
||
@Override | ||
public RoundableFragment ceil() throws BlunderException { | ||
return new VectorFragment(vector.ceil(new Vector3d())); | ||
} | ||
|
||
@Override | ||
public RoundableFragment round() throws BlunderException { | ||
return new VectorFragment(vector.round(new Vector3d())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/dev/enjarai/trickster/spell/tricks/CeilTrick.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package dev.enjarai.trickster.spell.tricks; | ||
|
||
import dev.enjarai.trickster.spell.Fragment; | ||
import dev.enjarai.trickster.spell.Pattern; | ||
import dev.enjarai.trickster.spell.SpellContext; | ||
import dev.enjarai.trickster.spell.fragment.RoundableFragment; | ||
import dev.enjarai.trickster.spell.tricks.blunder.BlunderException; | ||
|
||
import java.util.List; | ||
|
||
public class CeilTrick extends Trick { | ||
protected CeilTrick() { | ||
super(Pattern.of(6, 7, 4, 5)); | ||
} | ||
|
||
@Override | ||
public Fragment activate(SpellContext ctx, List<Fragment> fragments) throws BlunderException { | ||
var param = expectInput(fragments, RoundableFragment.class, 0); | ||
|
||
return param.ceil(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/dev/enjarai/trickster/spell/tricks/FloorTrick.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package dev.enjarai.trickster.spell.tricks; | ||
|
||
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.NumberFragment; | ||
import dev.enjarai.trickster.spell.fragment.RoundableFragment; | ||
import dev.enjarai.trickster.spell.tricks.blunder.BlunderException; | ||
|
||
import java.util.List; | ||
|
||
public class FloorTrick extends Trick { | ||
protected FloorTrick() { | ||
super(Pattern.of(0, 1, 4, 5)); | ||
} | ||
|
||
@Override | ||
public Fragment activate(SpellContext ctx, List<Fragment> fragments) throws BlunderException { | ||
var param = expectInput(fragments, RoundableFragment.class, 0); | ||
|
||
return param.floor(); | ||
} | ||
} |
Oops, something went wrong.