Made BlockCircleComponent extend ICircleComponent, fixed all the problems that caused.

This commit is contained in:
Talia-12 2023-04-02 23:02:42 +10:00
parent 4b1e5e997e
commit 88cfca2d4e
8 changed files with 70 additions and 74 deletions

View file

@ -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<Direction> exitDirections(BlockPos pos, BlockState bs, Level world) {
public EnumSet<Direction> 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);

View file

@ -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<Direction> 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) {

View file

@ -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)) {

View file

@ -49,6 +49,11 @@ public interface ICircleComponent {
@Contract(pure = true)
EnumSet<Direction> possibleExitDirections(BlockPos pos, BlockState bs, Level world);
@Contract(pure = true)
default Pair<BlockPos, Direction> 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;

View file

@ -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<Direction> exitDirections(BlockPos pos, BlockState bs, Level world) {
public EnumSet<Direction> 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);

View file

@ -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<Direction> 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<Direction> 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) {

View file

@ -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<Direction.Axis> 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<Direction> 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<Direction> 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

View file

@ -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<Direction> 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<Direction> possibleExitDirections(BlockPos pos, BlockState bs, Level world) {
return EnumSet.of(bs.getValue(FACING), bs.getValue(FACING).getOpposite());
}
@Override