made a proper registry for the Arithmetics, made it so media flow can enter/exit from the bottom of slates

This commit is contained in:
Talia-12 2023-05-31 22:03:38 +10:00
parent 9c830ef082
commit 99a1ad6528
8 changed files with 76 additions and 11 deletions

View file

@ -20,7 +20,7 @@ data class OperationAction(val pattern: HexPattern) : Action {
stack.addAll(stackList)
val startingLength = stackList.size
return try {
val ret: Iterable<Iota> = HexArithmetics.ENGINE.run(pattern, stack, startingLength)
val ret: Iterable<Iota> = HexArithmetics.getEngine().run(pattern, stack, startingLength)
ret.forEach(Consumer { e: Iota -> stack.add(e) })
val image2 = image.copy(stack = stack, opsConsumed = image.opsConsumed + 1)
OperationResult(image2, listOf(), continuation, HexEvalSounds.NORMAL_EXECUTE)

View file

@ -104,7 +104,7 @@ public class BlockSlate extends BlockCircleComponent implements EntityBlock, Sim
@Override
public boolean canEnterFromDirection(Direction enterDir, BlockPos pos, BlockState bs, ServerLevel world) {
var thisNormal = this.normalDir(pos, bs, world);
return enterDir != thisNormal && enterDir != thisNormal.getOpposite();
return enterDir != thisNormal.getOpposite(); // && enterDir != thisNormal;
}
@Override
@ -112,7 +112,7 @@ public class BlockSlate extends BlockCircleComponent implements EntityBlock, Sim
var allDirs = EnumSet.allOf(Direction.class);
var normal = this.normalDir(pos, bs, world);
allDirs.remove(normal);
allDirs.remove(normal.getOpposite());
// allDirs.remove(normal.getOpposite());
return allDirs;
}

View file

@ -1,12 +1,51 @@
package at.petrak.hexcasting.common.lib.hex;
import at.petrak.hexcasting.api.casting.arithmetic.Arithmetic;
import at.petrak.hexcasting.api.casting.arithmetic.engine.ArithmeticEngine;
import at.petrak.hexcasting.common.casting.arithmetic.DoubleArithmetic;
import at.petrak.hexcasting.common.casting.arithmetic.ListArithmetic;
import at.petrak.hexcasting.common.casting.arithmetic.Vec3Arithmetic;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import java.util.List;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import static at.petrak.hexcasting.api.HexAPI.modLoc;
public class HexArithmetics {
public static ArithmeticEngine ENGINE = new ArithmeticEngine(List.of(DoubleArithmetic.INSTANCE, Vec3Arithmetic.INSTANCE, ListArithmetic.INSTANCE));
private static ArithmeticEngine ENGINE;
public static ArithmeticEngine getEngine() {
if (ENGINE == null) {
ENGINE = new ArithmeticEngine(REGISTRY.holders().map(Holder.Reference::value).collect(Collectors.toList()));
}
return ENGINE;
}
public static final Registry<Arithmetic> REGISTRY = IXplatAbstractions.INSTANCE.getArithmeticRegistry();
public static void register(BiConsumer<Arithmetic, ResourceLocation> r) {
for (var e : ARITHMETICS.entrySet()) {
r.accept(e.getValue(), e.getKey());
}
}
private static final Map<ResourceLocation, Arithmetic> ARITHMETICS = new LinkedHashMap<>();
public static DoubleArithmetic DOUBLE = make("double", DoubleArithmetic.INSTANCE);
public static Vec3Arithmetic VEC3 = make("vec3", Vec3Arithmetic.INSTANCE);
public static ListArithmetic LIST = make("list", ListArithmetic.INSTANCE);
private static <T extends Arithmetic> T make(String name, T arithmetic) {
var old = ARITHMETICS.put(modLoc(name), arithmetic);
if (old != null) {
throw new IllegalArgumentException("Typo? Duplicate id " + name);
}
return arithmetic;
}
}

View file

@ -5,6 +5,7 @@ import at.petrak.hexcasting.api.addldata.ADHexHolder;
import at.petrak.hexcasting.api.addldata.ADIotaHolder;
import at.petrak.hexcasting.api.addldata.ADMediaHolder;
import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
import at.petrak.hexcasting.api.casting.arithmetic.Arithmetic;
import at.petrak.hexcasting.api.casting.castables.SpecialHandler;
import at.petrak.hexcasting.api.casting.eval.ResolvedPattern;
import at.petrak.hexcasting.api.casting.eval.sideeffects.EvalSound;
@ -168,6 +169,8 @@ public interface IXplatAbstractions {
Registry<IotaType<?>> getIotaTypeRegistry();
Registry<Arithmetic> getArithmeticRegistry();
Registry<EvalSound> getEvalSoundRegistry();
boolean isBreakingAllowed(Level world, BlockPos pos, BlockState state, Player player);

View file

@ -16,6 +16,7 @@ import at.petrak.hexcasting.common.entities.HexEntities
import at.petrak.hexcasting.common.items.ItemJewelerHammer
import at.petrak.hexcasting.common.lib.*
import at.petrak.hexcasting.common.lib.hex.HexActions
import at.petrak.hexcasting.common.lib.hex.HexArithmetics
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes
import at.petrak.hexcasting.common.lib.hex.HexSpecialHandlers
@ -53,7 +54,7 @@ import net.minecraft.world.entity.player.Player
import java.util.function.BiConsumer
object FabricHexInitializer : ModInitializer {
public lateinit var CONFIG: FabricHexConfig
lateinit var CONFIG: FabricHexConfig
override fun onInitialize() {
this.CONFIG = FabricHexConfig.setup()
@ -142,6 +143,7 @@ object FabricHexInitializer : ModInitializer {
HexIotaTypes.registerTypes(bind(IXplatAbstractions.INSTANCE.iotaTypeRegistry))
HexActions.register(bind(IXplatAbstractions.INSTANCE.actionRegistry))
HexSpecialHandlers.register(bind(IXplatAbstractions.INSTANCE.specialHandlerRegistry))
HexArithmetics.register(bind(IXplatAbstractions.INSTANCE.arithmeticRegistry))
HexEvalSounds.register(bind(IXplatAbstractions.INSTANCE.evalSoundRegistry))
// Because of Java's lazy-loading of classes, can't use Kotlin static initialization for

View file

@ -5,6 +5,7 @@ import at.petrak.hexcasting.api.addldata.ADHexHolder;
import at.petrak.hexcasting.api.addldata.ADIotaHolder;
import at.petrak.hexcasting.api.addldata.ADMediaHolder;
import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
import at.petrak.hexcasting.api.casting.arithmetic.Arithmetic;
import at.petrak.hexcasting.api.casting.castables.SpecialHandler;
import at.petrak.hexcasting.api.casting.eval.ResolvedPattern;
import at.petrak.hexcasting.api.casting.eval.sideeffects.EvalSound;
@ -321,7 +322,7 @@ public class FabricXplatImpl implements IXplatAbstractions {
return FabricUnsealedIngredient.of(stack);
}
private static Supplier<CreativeModeTab> TAB = Suppliers.memoize(() -> FabricItemGroupBuilder.create(
private static final Supplier<CreativeModeTab> TAB = Suppliers.memoize(() -> FabricItemGroupBuilder.create(
modLoc("creative_tab"))
.icon(HexItems::tabIcon)
.build());
@ -423,6 +424,13 @@ public class FabricXplatImpl implements IXplatAbstractions {
Lifecycle.stable(), null))
.buildAndRegister()
);
private static final Supplier<Registry<Arithmetic>> ARITHMETIC_REGISTRY = Suppliers.memoize(() ->
FabricRegistryBuilder.from(new DefaultedRegistry<Arithmetic>(
HexAPI.MOD_ID + ":null", ResourceKey.createRegistryKey(modLoc("arithmetic")),
Lifecycle.stable(), null))
.buildAndRegister()
);
private static final Supplier<Registry<EvalSound>> EVAL_SOUNDS_REGISTRY = Suppliers.memoize(() ->
FabricRegistryBuilder.from(new DefaultedRegistry<EvalSound>(
HexAPI.MOD_ID + ":nothing", ResourceKey.createRegistryKey(modLoc("eval_sound")),
@ -445,6 +453,11 @@ public class FabricXplatImpl implements IXplatAbstractions {
return IOTA_TYPE_REGISTRY.get();
}
@Override
public Registry<Arithmetic> getArithmeticRegistry() {
return ARITHMETIC_REGISTRY.get();
}
@Override
public Registry<EvalSound> getEvalSoundRegistry() {
return EVAL_SOUNDS_REGISTRY.get();

View file

@ -12,10 +12,7 @@ import at.petrak.hexcasting.common.casting.operators.spells.great.OpAltiora;
import at.petrak.hexcasting.common.entities.HexEntities;
import at.petrak.hexcasting.common.items.ItemJewelerHammer;
import at.petrak.hexcasting.common.lib.*;
import at.petrak.hexcasting.common.lib.hex.HexActions;
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds;
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes;
import at.petrak.hexcasting.common.lib.hex.HexSpecialHandlers;
import at.petrak.hexcasting.common.lib.hex.*;
import at.petrak.hexcasting.common.misc.AkashicTreeGrower;
import at.petrak.hexcasting.common.misc.BrainsweepingEvents;
import at.petrak.hexcasting.common.misc.PlayerPositionRecorder;
@ -115,6 +112,7 @@ public class ForgeHexInitializer {
bind(IXplatAbstractions.INSTANCE.getIotaTypeRegistry().key(), HexIotaTypes::registerTypes);
bind(IXplatAbstractions.INSTANCE.getActionRegistry().key(), HexActions::register);
bind(IXplatAbstractions.INSTANCE.getSpecialHandlerRegistry().key(), HexSpecialHandlers::register);
bind(IXplatAbstractions.INSTANCE.getArithmeticRegistry().key(), HexArithmetics::register);
bind(IXplatAbstractions.INSTANCE.getEvalSoundRegistry().key(), HexEvalSounds::register);
ForgeHexArgumentTypeRegistry.ARGUMENT_TYPES.register(getModEventBus());

View file

@ -5,6 +5,7 @@ import at.petrak.hexcasting.api.addldata.ADHexHolder;
import at.petrak.hexcasting.api.addldata.ADIotaHolder;
import at.petrak.hexcasting.api.addldata.ADMediaHolder;
import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
import at.petrak.hexcasting.api.casting.arithmetic.Arithmetic;
import at.petrak.hexcasting.api.casting.castables.SpecialHandler;
import at.petrak.hexcasting.api.casting.eval.ResolvedPattern;
import at.petrak.hexcasting.api.casting.eval.env.StaffCastEnv;
@ -472,6 +473,10 @@ public class ForgeXplatImpl implements IXplatAbstractions {
ResourceKey.createRegistryKey(modLoc("iota_type")),
HexAPI.MOD_ID + ":null", registry -> HexIotaTypes.NULL)
);
private static final Supplier<Registry<Arithmetic>> ARITHMETIC_REGISTRY = Suppliers.memoize(() ->
ForgeAccessorRegistry.hex$registerSimple(
ResourceKey.createRegistryKey(modLoc("arithmetic")), null)
);
private static final Supplier<Registry<EvalSound>> EVAL_SOUND_REGISTRY = Suppliers.memoize(() ->
ForgeAccessorRegistry.hex$registerDefaulted(
ResourceKey.createRegistryKey(modLoc("eval_sound")),
@ -493,6 +498,11 @@ public class ForgeXplatImpl implements IXplatAbstractions {
return IOTA_TYPE_REGISTRY.get();
}
@Override
public Registry<Arithmetic> getArithmeticRegistry() {
return ARITHMETIC_REGISTRY.get();
}
@Override
public Registry<EvalSound> getEvalSoundRegistry() {
return EVAL_SOUND_REGISTRY.get();