diff --git a/Common/src/main/java/at/petrak/hexcasting/api/block/circle/BlockAbstractImpetus.java b/Common/src/main/java/at/petrak/hexcasting/api/block/circle/BlockAbstractImpetus.java index 9438910e..19908357 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/block/circle/BlockAbstractImpetus.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/block/circle/BlockAbstractImpetus.java @@ -1,7 +1,8 @@ package at.petrak.hexcasting.api.block.circle; import at.petrak.hexcasting.api.casting.circles.BlockEntityAbstractImpetus; -import at.petrak.hexcasting.api.casting.math.HexPattern; +import at.petrak.hexcasting.api.casting.eval.env.CircleCastEnv; +import at.petrak.hexcasting.api.casting.eval.vm.CastingImage; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; @@ -16,9 +17,9 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.DirectionProperty; -import org.jetbrains.annotations.Nullable; import java.util.EnumSet; +import java.util.List; // Facing dir is the direction it starts searching for slates in to start public abstract class BlockAbstractImpetus extends BlockCircleComponent implements EntityBlock { @@ -31,21 +32,20 @@ public abstract class BlockAbstractImpetus extends BlockCircleComponent implemen } @Override - public boolean canEnterFromDirection(Direction enterDir, Direction normalDir, BlockPos pos, BlockState bs, - Level world) { + public ControlFlow acceptControlFlow(CastingImage imageIn, CircleCastEnv env, Direction enterDir, BlockPos pos, BlockState bs, ServerLevel world) { + return new ControlFlow.Continue(imageIn, List.of(this.exitPositionFromDirection(pos, bs.getValue(FACING)))); + } + + @Override + public boolean canEnterFromDirection(Direction enterDir, BlockPos pos, BlockState bs, ServerLevel world) { return enterDir != bs.getValue(FACING); } @Override - public EnumSet exitDirections(BlockPos pos, BlockState bs, Level world) { + public EnumSet possibleExitDirections(BlockPos pos, BlockState bs, Level world) { return EnumSet.of(bs.getValue(FACING)); } - @Override - public @Nullable HexPattern getPattern(BlockPos pos, BlockState bs, Level world) { - return null; - } - @Override public Direction normalDir(BlockPos pos, BlockState bs, Level world, int recursionLeft) { return normalDirOfOther(pos.relative(bs.getValue(FACING)), world, recursionLeft); diff --git a/Common/src/main/java/at/petrak/hexcasting/api/block/circle/BlockCircleComponent.java b/Common/src/main/java/at/petrak/hexcasting/api/block/circle/BlockCircleComponent.java index 695bf21b..600ecf3b 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/block/circle/BlockCircleComponent.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/block/circle/BlockCircleComponent.java @@ -1,38 +1,27 @@ package at.petrak.hexcasting.api.block.circle; -import at.petrak.hexcasting.api.casting.math.HexPattern; +import at.petrak.hexcasting.api.casting.circles.ICircleComponent; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BooleanProperty; -import org.jetbrains.annotations.Nullable; import java.util.EnumSet; -public abstract class BlockCircleComponent extends Block { +public abstract class BlockCircleComponent extends Block implements ICircleComponent { public static final BooleanProperty ENERGIZED = BooleanProperty.create("energized"); public BlockCircleComponent(Properties p_49795_) { super(p_49795_); } - /** - * Can this component get transferred to from a block coming in from that direction, with the given normal? - */ - abstract public boolean canEnterFromDirection(Direction enterDir, Direction normalDir, BlockPos pos, - BlockState bs, Level world); - - abstract public EnumSet exitDirections(BlockPos pos, BlockState bs, Level world); - - @Nullable - abstract public HexPattern getPattern(BlockPos pos, BlockState bs, Level world); - /** * Which direction points "up" or "out" for this block? - * This is used for {@link BlockCircleComponent#canEnterFromDirection(Direction, Direction, BlockPos, BlockState, Level)} + * This is used for {@link ICircleComponent#canEnterFromDirection(Direction, BlockPos, BlockState, ServerLevel)} * as well as particles. */ public Direction normalDir(BlockPos pos, BlockState bs, Level world) { diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/CircleExecutionState.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/CircleExecutionState.java index c05856b4..26f6ca90 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/CircleExecutionState.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/CircleExecutionState.java @@ -73,7 +73,7 @@ public class CircleExecutionState { var enterDir = pair.getFirst(); var herePos = pair.getSecond(); - if (!seenPositions.add(herePos)) { + if (seenPositions.add(herePos)) { // it's new var hereBs = level.getBlockState(herePos); if (!(hereBs.getBlock() instanceof ICircleComponent cmp)) { diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/ICircleComponent.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/ICircleComponent.java index c80b1fcd..94a3287c 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/ICircleComponent.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/ICircleComponent.java @@ -49,6 +49,11 @@ public interface ICircleComponent { @Contract(pure = true) EnumSet possibleExitDirections(BlockPos pos, BlockState bs, Level world); + @Contract(pure = true) + default Pair exitPositionFromDirection(BlockPos pos, Direction dir) { + return Pair.of(new BlockPos(dir.getStepX(), dir.getStepY(), dir.getStepZ()), dir); + } + abstract sealed class ControlFlow { public static final class Continue extends ControlFlow { public final CastingImage update; diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/BlockEmptyImpetus.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/BlockEmptyImpetus.java index a4746b23..c9b9fc5c 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/BlockEmptyImpetus.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/BlockEmptyImpetus.java @@ -1,9 +1,11 @@ package at.petrak.hexcasting.common.blocks.circles; import at.petrak.hexcasting.api.block.circle.BlockCircleComponent; -import at.petrak.hexcasting.api.casting.math.HexPattern; +import at.petrak.hexcasting.api.casting.eval.env.CircleCastEnv; +import at.petrak.hexcasting.api.casting.eval.vm.CastingImage; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; @@ -14,9 +16,9 @@ import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.DirectionProperty; import net.minecraft.world.level.material.PushReaction; -import org.jetbrains.annotations.Nullable; import java.util.EnumSet; +import java.util.List; // As it turns out, not actually an impetus public class BlockEmptyImpetus extends BlockCircleComponent { @@ -29,21 +31,20 @@ public class BlockEmptyImpetus extends BlockCircleComponent { } @Override - public boolean canEnterFromDirection(Direction enterDir, Direction normalDir, BlockPos pos, BlockState bs, - Level world) { + public ControlFlow acceptControlFlow(CastingImage imageIn, CircleCastEnv env, Direction enterDir, BlockPos pos, BlockState bs, ServerLevel world) { + return new ControlFlow.Continue(imageIn, List.of(this.exitPositionFromDirection(pos, bs.getValue(FACING)))); + } + + @Override + public boolean canEnterFromDirection(Direction enterDir, BlockPos pos, BlockState bs, ServerLevel world) { return enterDir != bs.getValue(FACING); } @Override - public EnumSet exitDirections(BlockPos pos, BlockState bs, Level world) { + public EnumSet possibleExitDirections(BlockPos pos, BlockState bs, Level world) { return EnumSet.of(bs.getValue(FACING)); } - @Override - public @Nullable HexPattern getPattern(BlockPos pos, BlockState bs, Level world) { - return null; - } - @Override public Direction normalDir(BlockPos pos, BlockState bs, Level world, int recursionLeft) { return normalDirOfOther(pos.relative(bs.getValue(FACING)), world, recursionLeft); diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/BlockSlate.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/BlockSlate.java index 5ce988b5..8b5e6164 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/BlockSlate.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/BlockSlate.java @@ -2,11 +2,14 @@ package at.petrak.hexcasting.common.blocks.circles; import at.petrak.hexcasting.annotations.SoftImplement; import at.petrak.hexcasting.api.block.circle.BlockCircleComponent; +import at.petrak.hexcasting.api.casting.eval.env.CircleCastEnv; +import at.petrak.hexcasting.api.casting.eval.vm.CastingImage; import at.petrak.hexcasting.api.casting.iota.PatternIota; import at.petrak.hexcasting.api.casting.math.HexPattern; import at.petrak.hexcasting.common.lib.HexItems; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; import net.minecraft.tags.FluidTags; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -70,14 +73,18 @@ public class BlockSlate extends BlockCircleComponent implements EntityBlock, Sim } @Override - public boolean canEnterFromDirection(Direction enterDir, Direction normalDir, BlockPos pos, BlockState bs, - Level world) { - var thisNormal = this.normalDir(pos, bs, world); - return enterDir != thisNormal && normalDir == thisNormal; + public ControlFlow acceptControlFlow(CastingImage imageIn, CircleCastEnv env, Direction enterDir, BlockPos pos, BlockState bs, ServerLevel world) { + return null; } @Override - public EnumSet exitDirections(BlockPos pos, BlockState bs, Level world) { + public boolean canEnterFromDirection(Direction enterDir, BlockPos pos, BlockState bs, ServerLevel world) { + var thisNormal = this.normalDir(pos, bs, world); + return enterDir != thisNormal && enterDir != thisNormal.getOpposite(); + } + + @Override + public EnumSet possibleExitDirections(BlockPos pos, BlockState bs, Level world) { var allDirs = EnumSet.allOf(Direction.class); var normal = this.normalDir(pos, bs, world); allDirs.remove(normal); @@ -85,16 +92,6 @@ public class BlockSlate extends BlockCircleComponent implements EntityBlock, Sim return allDirs; } - @Override - public @Nullable - HexPattern getPattern(BlockPos pos, BlockState bs, Level world) { - if (world.getBlockEntity(pos) instanceof BlockEntitySlate tile) { - return tile.pattern; - } else { - return null; - } - } - @SoftImplement("forge") public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter level, BlockPos pos, Player player) { diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/directrix/BlockEmptyDirectrix.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/directrix/BlockEmptyDirectrix.java index 8eef5a46..551dff03 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/directrix/BlockEmptyDirectrix.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/directrix/BlockEmptyDirectrix.java @@ -1,9 +1,11 @@ package at.petrak.hexcasting.common.blocks.circles.directrix; import at.petrak.hexcasting.api.block.circle.BlockCircleComponent; -import at.petrak.hexcasting.api.casting.math.HexPattern; +import at.petrak.hexcasting.api.casting.eval.env.CircleCastEnv; +import at.petrak.hexcasting.api.casting.eval.vm.CastingImage; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; @@ -13,9 +15,9 @@ import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.EnumProperty; import net.minecraft.world.level.material.PushReaction; -import org.jetbrains.annotations.Nullable; import java.util.EnumSet; +import java.util.List; public class BlockEmptyDirectrix extends BlockCircleComponent { public static final EnumProperty AXIS = BlockStateProperties.AXIS; @@ -28,20 +30,21 @@ public class BlockEmptyDirectrix extends BlockCircleComponent { } @Override - public boolean canEnterFromDirection(Direction enterDir, Direction normalDir, BlockPos pos, BlockState bs, - Level world) { + public ControlFlow acceptControlFlow(CastingImage imageIn, CircleCastEnv env, Direction enterDir, BlockPos pos, BlockState bs, ServerLevel world) { + var sign = world.random.nextBoolean() ? Direction.AxisDirection.POSITIVE : Direction.AxisDirection.NEGATIVE; + return new ControlFlow.Continue(imageIn, List.of(this.exitPositionFromDirection(pos, Direction.fromAxisAndDirection(bs.getValue(AXIS), sign)))); + } + + @Override + public boolean canEnterFromDirection(Direction enterDir, BlockPos pos, BlockState bs, ServerLevel world) { return true; } @Override - public EnumSet exitDirections(BlockPos pos, BlockState bs, Level world) { - var sign = world.random.nextBoolean() ? Direction.AxisDirection.POSITIVE : Direction.AxisDirection.NEGATIVE; - return EnumSet.of(Direction.fromAxisAndDirection(bs.getValue(AXIS), sign)); - } - - @Override - public @Nullable HexPattern getPattern(BlockPos pos, BlockState bs, Level world) { - return null; + public EnumSet possibleExitDirections(BlockPos pos, BlockState bs, Level world) { + return EnumSet.of( + Direction.fromAxisAndDirection(bs.getValue(AXIS), Direction.AxisDirection.NEGATIVE), + Direction.fromAxisAndDirection(bs.getValue(AXIS), Direction.AxisDirection.POSITIVE)); } @Override diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/directrix/BlockRedstoneDirectrix.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/directrix/BlockRedstoneDirectrix.java index 867e685f..8fd03aaf 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/directrix/BlockRedstoneDirectrix.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/directrix/BlockRedstoneDirectrix.java @@ -1,10 +1,12 @@ package at.petrak.hexcasting.common.blocks.circles.directrix; import at.petrak.hexcasting.api.block.circle.BlockCircleComponent; -import at.petrak.hexcasting.api.casting.math.HexPattern; +import at.petrak.hexcasting.api.casting.eval.env.CircleCastEnv; +import at.petrak.hexcasting.api.casting.eval.vm.CastingImage; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.particles.DustParticleOptions; +import net.minecraft.server.level.ServerLevel; import net.minecraft.util.RandomSource; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.Level; @@ -18,9 +20,9 @@ import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.DirectionProperty; import net.minecraft.world.level.material.PushReaction; import net.minecraft.world.phys.Vec3; -import org.jetbrains.annotations.Nullable; import java.util.EnumSet; +import java.util.List; public class BlockRedstoneDirectrix extends BlockCircleComponent { public static final DirectionProperty FACING = BlockStateProperties.FACING; @@ -35,19 +37,18 @@ public class BlockRedstoneDirectrix extends BlockCircleComponent { } @Override - public boolean canEnterFromDirection(Direction enterDir, Direction normalDir, BlockPos pos, BlockState bs, - Level world) { + public ControlFlow acceptControlFlow(CastingImage imageIn, CircleCastEnv env, Direction enterDir, BlockPos pos, BlockState bs, ServerLevel world) { + return new ControlFlow.Continue(imageIn, List.of(this.exitPositionFromDirection(pos, getRealFacing(bs)))); + } + + @Override + public boolean canEnterFromDirection(Direction enterDir, BlockPos pos, BlockState bs, ServerLevel world) { return enterDir != getRealFacing(bs); } @Override - public EnumSet exitDirections(BlockPos pos, BlockState bs, Level world) { - return EnumSet.of(getRealFacing(bs)); - } - - @Override - public @Nullable HexPattern getPattern(BlockPos pos, BlockState bs, Level world) { - return null; + public EnumSet possibleExitDirections(BlockPos pos, BlockState bs, Level world) { + return EnumSet.of(bs.getValue(FACING), bs.getValue(FACING).getOpposite()); } @Override