mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-12 07:16:54 +01:00
Track API?
Fix placement
This commit is contained in:
parent
7fbf08ba54
commit
d9ce6ce995
3 changed files with 32 additions and 9 deletions
|
@ -72,6 +72,20 @@ public class BezierConnection implements Iterable<BezierConnection.Segment>, IHa
|
|||
hasGirder, trackMaterial);
|
||||
}
|
||||
|
||||
private static boolean coupleEquals(Couple<?> a, Couple<?> b) {
|
||||
return (a.getFirst().equals(b.getFirst()) && a.getSecond().equals(b.getSecond())) || (a.getFirst() instanceof Vec3 aFirst && a.getSecond() instanceof Vec3 aSecond && b.getFirst() instanceof Vec3 bFirst && b.getSecond() instanceof Vec3 bSecond && aFirst.closerThan(bFirst, 1e-6) && aSecond.closerThan(bSecond, 1e-6));
|
||||
}
|
||||
|
||||
public boolean equalsSansMaterial(BezierConnection other) {
|
||||
return equalsSansMaterialInner(other) || equalsSansMaterialInner(other.secondary());
|
||||
}
|
||||
|
||||
private boolean equalsSansMaterialInner(BezierConnection other) {
|
||||
return this == other || (other != null && coupleEquals(this.tePositions, other.tePositions) && coupleEquals(this.starts, other.starts)
|
||||
&& coupleEquals(this.axes, other.axes) && coupleEquals(this.normals, other.normals)
|
||||
&& this.hasGirder == other.hasGirder);
|
||||
}
|
||||
|
||||
public BezierConnection(CompoundTag compound, BlockPos localTo) {
|
||||
this(Couple.deserializeEach(compound.getList("Positions", Tag.TAG_COMPOUND), NbtUtils::readBlockPos)
|
||||
.map(b -> b.offset(localTo)),
|
||||
|
|
|
@ -501,8 +501,8 @@ public class TrackPlacement {
|
|||
return onto;
|
||||
}
|
||||
|
||||
private static BlockState copyProperties(BlockState from, BlockState onto, Function<BlockState, Boolean> keepFrom) {
|
||||
return keepFrom.apply(from) ? copyProperties(from, onto) : from;
|
||||
private static BlockState copyProperties(BlockState from, BlockState onto, boolean keepFrom) {
|
||||
return keepFrom ? from : copyProperties(from, onto);
|
||||
}
|
||||
|
||||
private static PlacementInfo placeTracks(Level level, PlacementInfo info, BlockState state1, BlockState state2,
|
||||
|
@ -556,16 +556,22 @@ public class TrackPlacement {
|
|||
return info;
|
||||
|
||||
if (!simulate) {
|
||||
BlockState stateAtPos = level.getBlockState(targetPos1);
|
||||
BlockState onto = info.getMaterial().getTrackBlock().getDefaultState();
|
||||
level.setBlock(targetPos1, ProperWaterloggedBlock.withWater(level,
|
||||
copyProperties((stateAtPos.getBlock() == state1.getBlock() ? stateAtPos : state1), onto, AllTags.AllBlockTags.TRACKS::matches).setValue(TrackBlock.HAS_TE, true),
|
||||
targetPos1), 3);
|
||||
var relevantState = state1;
|
||||
BlockState stateAtPos = level.getBlockState(targetPos1);
|
||||
var stateAtPosVar = stateAtPos;
|
||||
// BlockState injectorAllocatedLocal30 = (BlockState)(stateAtPos.getBlock() == state1.getBlock() ? stateAtPos : state1).setValue(TrackBlock.HAS_TE, true);
|
||||
relevantState = copyProperties(relevantState, onto);
|
||||
var modifiedBlock = (AllTags.AllBlockTags.TRACKS.matches(stateAtPosVar) ? stateAtPosVar : relevantState).setValue(TrackBlock.HAS_TE, true);
|
||||
level.setBlock(targetPos1, ProperWaterloggedBlock.withWater(level, modifiedBlock, targetPos1), 3);
|
||||
|
||||
relevantState = state2;
|
||||
stateAtPos = level.getBlockState(targetPos2);
|
||||
level.setBlock(targetPos2, ProperWaterloggedBlock.withWater(level,
|
||||
copyProperties((stateAtPos.getBlock() == state2.getBlock() ? stateAtPos : state2), onto, AllTags.AllBlockTags.TRACKS::matches).setValue(TrackBlock.HAS_TE, true),
|
||||
targetPos2), 3);
|
||||
stateAtPosVar = stateAtPos;
|
||||
// BlockState injectorAllocatedLocal30 = (BlockState)(stateAtPos.getBlock() == state1.getBlock() ? stateAtPos : state1).setValue(TrackBlock.HAS_TE, true);
|
||||
relevantState = copyProperties(relevantState, onto);
|
||||
modifiedBlock = (AllTags.AllBlockTags.TRACKS.matches(stateAtPosVar) ? stateAtPosVar : relevantState).setValue(TrackBlock.HAS_TE, true);
|
||||
level.setBlock(targetPos2, ProperWaterloggedBlock.withWater(level, modifiedBlock, targetPos2), 3);
|
||||
}
|
||||
|
||||
BlockEntity te1 = level.getBlockEntity(targetPos1);
|
||||
|
|
|
@ -113,6 +113,9 @@ public class TrackTileEntity extends SmartTileEntity implements ITransformableTE
|
|||
}
|
||||
|
||||
public void addConnection(BezierConnection connection) {
|
||||
// don't replace existing connections with different materials
|
||||
if (connections.containsKey(connection.getKey()) && connection.equalsSansMaterial(connections.get(connection.getKey())))
|
||||
return;
|
||||
connections.put(connection.getKey(), connection);
|
||||
level.scheduleTick(worldPosition, getBlockState().getBlock(), 1);
|
||||
notifyUpdate();
|
||||
|
|
Loading…
Reference in a new issue