mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-27 13:28:00 +01:00
Start work on solver
This commit is contained in:
parent
5d435e1da7
commit
760bffe343
2 changed files with 96 additions and 2 deletions
|
@ -0,0 +1,78 @@
|
||||||
|
package com.simibubi.create.content.contraptions;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
|
public class KineticSolver {
|
||||||
|
|
||||||
|
private final Map<BlockPos, Connection> connectionsFrom = new HashMap<>();
|
||||||
|
private final Map<BlockPos, Connection> connectionsTo = new HashMap<>();
|
||||||
|
|
||||||
|
private final List<Goal> goals = new ArrayList<>();
|
||||||
|
|
||||||
|
private boolean needsUpdate;
|
||||||
|
|
||||||
|
public void solve() {
|
||||||
|
if (!needsUpdate) return;
|
||||||
|
needsUpdate = false;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addFact(BlockPos pos) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addGoal(Goal goal) {
|
||||||
|
goals.add(goal);
|
||||||
|
needsUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface SolverBlock {
|
||||||
|
void created(KineticSolver solver, Level level, BlockPos pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class Connection {
|
||||||
|
public final BlockPos from;
|
||||||
|
public final BlockPos to;
|
||||||
|
|
||||||
|
public Connection(BlockPos from, BlockPos to) {
|
||||||
|
this.from = from;
|
||||||
|
this.to = to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract boolean isCompatible(Connection that);
|
||||||
|
|
||||||
|
public static final class Shaft extends Connection {
|
||||||
|
|
||||||
|
public Shaft(BlockPos pos, Direction face) {
|
||||||
|
super(pos, pos.relative(face));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCompatible(Connection that) {
|
||||||
|
return that instanceof Shaft;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Goal {
|
||||||
|
public final Connection connection;
|
||||||
|
|
||||||
|
public Goal(Connection connection) {
|
||||||
|
this.connection = connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class EqualSpeed extends Goal {
|
||||||
|
public EqualSpeed(Connection connection) {
|
||||||
|
super(connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import java.util.function.Predicate;
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
import com.simibubi.create.AllBlocks;
|
||||||
import com.simibubi.create.AllShapes;
|
import com.simibubi.create.AllShapes;
|
||||||
|
import com.simibubi.create.content.contraptions.KineticSolver;
|
||||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
import com.simibubi.create.content.contraptions.relays.encased.EncasedShaftBlock;
|
import com.simibubi.create.content.contraptions.relays.encased.EncasedShaftBlock;
|
||||||
import com.simibubi.create.foundation.advancement.AllTriggers;
|
import com.simibubi.create.foundation.advancement.AllTriggers;
|
||||||
|
@ -26,7 +27,7 @@ import net.minecraft.world.phys.BlockHitResult;
|
||||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||||
|
|
||||||
public class ShaftBlock extends AbstractShaftBlock {
|
public class ShaftBlock extends AbstractShaftBlock implements KineticSolver.SolverBlock {
|
||||||
|
|
||||||
private static final int placementHelperId = PlacementHelpers.register(new PlacementHelper());
|
private static final int placementHelperId = PlacementHelpers.register(new PlacementHelper());
|
||||||
|
|
||||||
|
@ -83,6 +84,21 @@ public class ShaftBlock extends AbstractShaftBlock {
|
||||||
return InteractionResult.PASS;
|
return InteractionResult.PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void created(KineticSolver solver, Level level, BlockPos pos) {
|
||||||
|
BlockState state = level.getBlockState(pos);
|
||||||
|
|
||||||
|
Direction.Axis axis = state.getValue(AXIS);
|
||||||
|
|
||||||
|
Direction positive = Direction.fromAxisAndDirection(axis, Direction.AxisDirection.POSITIVE);
|
||||||
|
|
||||||
|
KineticSolver.Connection.Shaft c1 = new KineticSolver.Connection.Shaft(pos, positive);
|
||||||
|
KineticSolver.Connection.Shaft c2 = new KineticSolver.Connection.Shaft(pos, positive.getOpposite());
|
||||||
|
|
||||||
|
solver.addGoal(new KineticSolver.Goal.EqualSpeed(c1));
|
||||||
|
solver.addGoal(new KineticSolver.Goal.EqualSpeed(c2));
|
||||||
|
}
|
||||||
|
|
||||||
@MethodsReturnNonnullByDefault
|
@MethodsReturnNonnullByDefault
|
||||||
private static class PlacementHelper extends PoleHelper<Direction.Axis> {
|
private static class PlacementHelper extends PoleHelper<Direction.Axis> {
|
||||||
//used for extending a shaft in its axis, like the piston poles. works with shafts and cogs
|
//used for extending a shaft in its axis, like the piston poles. works with shafts and cogs
|
||||||
|
|
Loading…
Reference in a new issue