Skip to content

Commit

Permalink
Merge branch '1.20' into 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
object-Object authored Dec 24, 2023
2 parents 7b2e47c + 704765d commit c5643a1
Show file tree
Hide file tree
Showing 75 changed files with 743 additions and 109 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"variants": {
"facing=east,in_wall=false,open=false": {
"model": "hexcasting:block/edified_fence_gate",
"uvlock": true,
"y": 270
},
"facing=east,in_wall=false,open=true": {
"model": "hexcasting:block/edified_fence_gate_open",
"uvlock": true,
"y": 270
},
"facing=east,in_wall=true,open=false": {
"model": "hexcasting:block/edified_fence_gate_wall",
"uvlock": true,
"y": 270
},
"facing=east,in_wall=true,open=true": {
"model": "hexcasting:block/edified_fence_gate_wall_open",
"uvlock": true,
"y": 270
},
"facing=north,in_wall=false,open=false": {
"model": "hexcasting:block/edified_fence_gate",
"uvlock": true,
"y": 180
},
"facing=north,in_wall=false,open=true": {
"model": "hexcasting:block/edified_fence_gate_open",
"uvlock": true,
"y": 180
},
"facing=north,in_wall=true,open=false": {
"model": "hexcasting:block/edified_fence_gate_wall",
"uvlock": true,
"y": 180
},
"facing=north,in_wall=true,open=true": {
"model": "hexcasting:block/edified_fence_gate_wall_open",
"uvlock": true,
"y": 180
},
"facing=south,in_wall=false,open=false": {
"model": "hexcasting:block/edified_fence_gate",
"uvlock": true
},
"facing=south,in_wall=false,open=true": {
"model": "hexcasting:block/edified_fence_gate_open",
"uvlock": true
},
"facing=south,in_wall=true,open=false": {
"model": "hexcasting:block/edified_fence_gate_wall",
"uvlock": true
},
"facing=south,in_wall=true,open=true": {
"model": "hexcasting:block/edified_fence_gate_wall_open",
"uvlock": true
},
"facing=west,in_wall=false,open=false": {
"model": "hexcasting:block/edified_fence_gate",
"uvlock": true,
"y": 90
},
"facing=west,in_wall=false,open=true": {
"model": "hexcasting:block/edified_fence_gate_open",
"uvlock": true,
"y": 90
},
"facing=west,in_wall=true,open=false": {
"model": "hexcasting:block/edified_fence_gate_wall",
"uvlock": true,
"y": 90
},
"facing=west,in_wall=true,open=true": {
"model": "hexcasting:block/edified_fence_gate_wall_open",
"uvlock": true,
"y": 90
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:block/template_fence_gate",
"textures": {
"texture": "hexcasting:block/edified_planks"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:block/template_fence_gate_open",
"textures": {
"texture": "hexcasting:block/edified_planks"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:block/template_fence_gate_wall",
"textures": {
"texture": "hexcasting:block/edified_planks"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:block/template_fence_gate_wall_open",
"textures": {
"texture": "hexcasting:block/edified_planks"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "hexcasting:block/edified_fence_gate"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld_rod",
"textures": {
"layer0": "hexcasting:item/staff/bamboo"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld_rod",
"textures": {
"layer0": "hexcasting:item/staff/cherry"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"overrides": [
{
"model": "hexcasting:item/bamboo_staff",
"predicate": {
"hexcasting:funny_level": 0.0
}
},
{
"model": "hexcasting:item/cherry_staff",
"predicate": {
"hexcasting:funny_level": 2.0
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"overrides": [
{
"model": "hexcasting:item/cherry_staff",
"predicate": {
"hexcasting:funny_level": 0.0
}
},
{
"model": "hexcasting:item/cherry_staff",
"predicate": {
"hexcasting:funny_level": 2.0
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import at.petrak.hexcasting.api.casting.arithmetic.Arithmetic;
import at.petrak.hexcasting.api.casting.arithmetic.operator.Operator;
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment;
import at.petrak.hexcasting.api.casting.eval.OperationResult;
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage;
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation;
import at.petrak.hexcasting.api.casting.iota.Iota;
import at.petrak.hexcasting.api.casting.math.HexPattern;
import at.petrak.hexcasting.api.casting.mishaps.Mishap;
Expand Down Expand Up @@ -64,29 +67,34 @@ public Iterable<HexPattern> operatorSyms() {
/**
* Runs one of the contained Operators assigned to the given pattern, modifying the passed stack of iotas.
* @param pattern The pattern that was drawn, used to determine which operators are candidates.
* @param iotas The current stack.
* @param startingLength The length of the stack before the operator executes (used for errors).
* @param env The casting environment.
* @param image The casting image.
* @param continuation The current continuation.
* @return The iotas to be added to the stack.
* @throws Mishap mishaps if invalid input to the operators is given by the caster.
*/
public Iterable<Iota> run(HexPattern pattern, Stack<Iota> iotas, int startingLength, CastingEnvironment env) throws Mishap {
public OperationResult run(HexPattern pattern, CastingEnvironment env, CastingImage image, SpellContinuation continuation) throws Mishap {
var stackList = image.getStack();
var stack = new Stack<Iota>();
stack.addAll(stackList);
var startingLength = stackList.size();

var candidates = operators.get(pattern);
if (candidates == null)
throw new InvalidOperatorException("the pattern " + pattern + " is not an operator."); //
HashCons hash = new HashCons.Pattern(pattern);
var args = new ArrayList<Iota>(candidates.arity());
for (var i = 0; i < candidates.arity(); i++) {
if (iotas.isEmpty()) {
if (stack.isEmpty()) {
throw new MishapNotEnoughArgs(candidates.arity, startingLength);
}
var iota = iotas.pop();
var iota = stack.pop();
hash = new HashCons.Pair(iota.getType(), hash);
args.add(iota);
}
Collections.reverse(args);
var op = resolveCandidates(args, hash, candidates);
return op.apply(args, env);
return op.operate(env, image, continuation);
}

private Operator resolveCandidates(List<Iota> args, HashCons hash, OpCandidates candidates) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package at.petrak.hexcasting.api.casting.arithmetic.operator

import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.eval.OperationResult
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.iota.IotaType
import at.petrak.hexcasting.api.casting.mishaps.Mishap
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
import java.util.function.Consumer

abstract class Operator
/**
* @param arity The number of arguments from the stack that this Operator requires; all Operators with the same pattern must have arity.
* @param accepts A function that should return true if the passed list of Iotas satisfies this Operator's type constraints, and false otherwise.
*/
(
@JvmField
val arity: Int,
@JvmField
val accepts: IotaMultiPredicate
) {

/**
* Functionally update the image. Return the image and any side effects.
*/
@Throws(Mishap::class)
abstract fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult


companion object {
/**
* A helper method to take an iota that you know is of iotaType and returning it as an iota of that type.
*/
@JvmStatic
fun <T : Iota?> downcast(iota: Iota, iotaType: IotaType<T>): T {
check(iota.type === iotaType) { "Attempting to downcast $iota to type: $iotaType" }
return iota as T
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package at.petrak.hexcasting.api.casting.arithmetic.operator

import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.eval.OperationResult
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.mishaps.Mishap
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
import java.util.function.Consumer

abstract class OperatorBasic(arity: Int, accepts: IotaMultiPredicate) : Operator(arity, accepts) {

@Throws(Mishap::class)
override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult {
val stack = image.stack.toMutableList()
val args = stack.takeLast(arity)
repeat(arity) { stack.removeLast() }

val ret = apply(args, env)
ret.forEach(Consumer { e: Iota -> stack.add(e) })

val image2 = image.copy(stack = stack, opsConsumed = image.opsConsumed + 1)
return OperationResult(image2, listOf(), continuation, HexEvalSounds.NORMAL_EXECUTE)
}

/**
* / **
* The method called when this Operator is actually acting on the stack, for real.
* @param iotas An iterable of iotas with [Operator.arity] elements that satisfied [Operator.accepts].
* @param env The casting environment, to make use of if this operator needs it.
* @return the iotas that this operator will return to the stack (with the first element of the returned iterable being placed deepest into the stack, and the last element on top of the stack).
* @throws Mishap if the Operator mishaps for any reason it will be passed up the chain.
*/
@Throws(Mishap::class)
abstract fun apply(iotas: Iterable<Iota>, env: CastingEnvironment): Iterable<Iota>

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* A helper class for defining {@link Operator}s of two iotas.
*/
public class OperatorBinary extends Operator {
public class OperatorBinary extends OperatorBasic {
public BinaryOperator<Iota> inner;

public OperatorBinary(IotaMultiPredicate accepts, BinaryOperator<Iota> inner) {
Expand All @@ -21,7 +21,7 @@ public OperatorBinary(IotaMultiPredicate accepts, BinaryOperator<Iota> inner) {
}

@Override
public @NotNull Iterable<Iota> apply(@NotNull Iterable<Iota> iotas, @NotNull CastingEnvironment env) {
public @NotNull Iterable<Iota> apply(Iterable<? extends Iota> iotas, @NotNull CastingEnvironment env) {
var it = iotas.iterator();
return List.of(inner.apply(it.next(), it.next()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* A helper class for defining {@link Operator}s of one iota.
*/
public class OperatorUnary extends Operator {
public class OperatorUnary extends OperatorBasic {
public UnaryOperator<Iota> inner;

public OperatorUnary(IotaMultiPredicate accepts, UnaryOperator<Iota> inner) {
Expand All @@ -21,7 +21,7 @@ public OperatorUnary(IotaMultiPredicate accepts, UnaryOperator<Iota> inner) {
}

@Override
public @NotNull Iterable<Iota> apply(@NotNull Iterable<Iota> iotas, @NotNull CastingEnvironment env) {
public @NotNull Iterable<Iota> apply(Iterable<? extends Iota> iotas, @NotNull CastingEnvironment env) {
return List.of(inner.apply(iotas.iterator().next()));
}
}
Loading

0 comments on commit c5643a1

Please sign in to comment.