clean up nether portal carriage handling

This commit is contained in:
techno-sam 2023-05-05 07:32:06 -07:00
parent d556f08876
commit cbd0cf20da
3 changed files with 10 additions and 60 deletions

View File

@ -16,8 +16,6 @@ import java.util.function.Function;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.simibubi.create.foundation.command.DebugValueCommand;
import org.apache.commons.lang3.mutable.MutableDouble; import org.apache.commons.lang3.mutable.MutableDouble;
import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
@ -327,7 +325,7 @@ public class Carriage {
dce.positionAnchor = dimension.equals(leadingBogeyDim) ? leadingBogey.getAnchorPosition() dce.positionAnchor = dimension.equals(leadingBogeyDim) ? leadingBogey.getAnchorPosition()
: pivoted(dce, dimension, point, : pivoted(dce, dimension, point,
leading ? leadingWheelSpacing / 2 : bogeySpacing + trailingWheelSpacing / 2, leading ? leadingWheelSpacing / 2 : bogeySpacing + trailingWheelSpacing / 2,
leadingUpsideDown, trailingUpsideDown, leading); leadingUpsideDown, trailingUpsideDown);
boolean backAnchorFlip = trailingBogey.isUpsideDown() ^ leadingBogey.isUpsideDown(); boolean backAnchorFlip = trailingBogey.isUpsideDown() ^ leadingBogey.isUpsideDown();
@ -335,11 +333,11 @@ public class Carriage {
dce.rotationAnchors.setFirst(dimension.equals(leadingBogeyDim) ? leadingBogey.getAnchorPosition() dce.rotationAnchors.setFirst(dimension.equals(leadingBogeyDim) ? leadingBogey.getAnchorPosition()
: pivoted(dce, dimension, point, : pivoted(dce, dimension, point,
leading ? leadingWheelSpacing / 2 : bogeySpacing + trailingWheelSpacing / 2, leading ? leadingWheelSpacing / 2 : bogeySpacing + trailingWheelSpacing / 2,
leadingUpsideDown, trailingUpsideDown, leading)); leadingUpsideDown, trailingUpsideDown));
dce.rotationAnchors.setSecond(dimension.equals(trailingBogeyDim) ? trailingBogey.getAnchorPosition(backAnchorFlip) dce.rotationAnchors.setSecond(dimension.equals(trailingBogeyDim) ? trailingBogey.getAnchorPosition(backAnchorFlip)
: pivoted(dce, dimension, point, : pivoted(dce, dimension, point,
leading ? leadingWheelSpacing / 2 + bogeySpacing : trailingWheelSpacing / 2, leading ? leadingWheelSpacing / 2 + bogeySpacing : trailingWheelSpacing / 2,
leadingUpsideDown, trailingUpsideDown, leading)); leadingUpsideDown, trailingUpsideDown));
} else { } else {
if (dimension.equals(otherDimension)) { if (dimension.equals(otherDimension)) {
@ -347,10 +345,10 @@ public class Carriage {
} else { } else {
dce.rotationAnchors.setFirst(leadingBogey.points.getFirst() == point ? point.getPosition() dce.rotationAnchors.setFirst(leadingBogey.points.getFirst() == point ? point.getPosition()
: pivoted(dce, dimension, point, leadingWheelSpacing, : pivoted(dce, dimension, point, leadingWheelSpacing,
leadingUpsideDown, trailingUpsideDown, leading)); leadingUpsideDown, trailingUpsideDown));
dce.rotationAnchors.setSecond(leadingBogey.points.getSecond() == point ? point.getPosition() dce.rotationAnchors.setSecond(leadingBogey.points.getSecond() == point ? point.getPosition()
: pivoted(dce, dimension, point, leadingWheelSpacing, : pivoted(dce, dimension, point, leadingWheelSpacing,
leadingUpsideDown, trailingUpsideDown, leading)); leadingUpsideDown, trailingUpsideDown));
} }
} }
@ -368,26 +366,16 @@ public class Carriage {
} }
private Vec3 pivoted(DimensionalCarriageEntity dce, ResourceKey<Level> dimension, TravellingPoint start, private Vec3 pivoted(DimensionalCarriageEntity dce, ResourceKey<Level> dimension, TravellingPoint start,
double offset, boolean leadingUpsideDown, boolean trailingUpsideDown, boolean isLeading) { double offset, boolean leadingUpsideDown, boolean trailingUpsideDown) {
if (train.graph == null) if (train.graph == null)
return dce.pivot == null ? null : dce.pivot.getLocation(); return dce.pivot == null ? null : dce.pivot.getLocation();
TrackNodeLocation pivot = dce.findPivot(dimension, start == getLeadingPoint()); TrackNodeLocation pivot = dce.findPivot(dimension, start == getLeadingPoint());
if (pivot == null) if (pivot == null)
return null; return null;
boolean flipped = false; boolean flipped = start != getLeadingPoint() && (leadingUpsideDown != trailingUpsideDown);
if (!leadingUpsideDown && trailingUpsideDown) { // nu // fixme this code sucks and needs to be better
flipped = start != getLeadingPoint() && (leadingBogey().isUpsideDown() != trailingBogey().isUpsideDown());
} else if (leadingUpsideDown && !trailingUpsideDown) { // un
flipped = start != getLeadingPoint() && (leadingBogey().isUpsideDown() != trailingBogey().isUpsideDown());
}
Vec3 startVec = start.getPosition(flipped); Vec3 startVec = start.getPosition(flipped);
Vec3 portalVec = pivot.getLocation() Vec3 portalVec = pivot.getLocation()
.add(0, DebugValueCommand.tmpPortalOffset(leadingUpsideDown, trailingUpsideDown, isLeading), 0); .add(0, leadingUpsideDown ? -1.0 : 1.0, 0);
// same side - other side
// n(ormal)-n(ormal)
// u(pside down)-u(pside down) what about un ? not tested yet un doesn't work with + 1 or -1. HALP
// 1 works for: nn n nu
//-1 works for: uu u
return VecHelper.lerp((float) (offset / startVec.distanceTo(portalVec)), startVec, portalVec); return VecHelper.lerp((float) (offset / startVec.distanceTo(portalVec)), startVec, portalVec);
} }

View File

@ -60,7 +60,7 @@ public class AllCommands {
.then(CameraDistanceCommand.register()) .then(CameraDistanceCommand.register())
.then(CameraAngleCommand.register()) .then(CameraAngleCommand.register())
.then(FlySpeedCommand.register()) .then(FlySpeedCommand.register())
.then(DebugValueCommand.register()) //.then(DebugValueCommand.register())
//.then(KillTPSCommand.register()) //.then(KillTPSCommand.register())
.build(); .build();

View File

@ -23,7 +23,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.CommandBlockEntity; import net.minecraft.world.level.block.entity.CommandBlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
public class DebugValueCommand { //fixme this is *very* temporary public class DebugValueCommand {
public static float value = 0; public static float value = 0;
@ -38,42 +38,4 @@ public class DebugValueCommand { //fixme this is *very* temporary
})); }));
} }
// same side - other side
// n(ormal)-n(ormal)
// u(pside down)-u(pside down)
// nu works with special handling, now to get un to work!
// 1 works for: nn n
//-1 works for: uu u
public static double tmpPortalOffset(boolean leadingUpsideDown, boolean trailingUpsideDown, boolean isLeading) {
double portalOffset = 0.0;
if (!leadingUpsideDown && !trailingUpsideDown) { // nn
return 1.0;
} else if (leadingUpsideDown && trailingUpsideDown) { // uu
return -1.0;
} else if (leadingUpsideDown && !trailingUpsideDown) { // un
if (isLeading) {
return -1.0;
} else {
return -1.0;
}
} else if (!leadingUpsideDown && trailingUpsideDown) { // nu
if (isLeading) {
return 1.0;
} else {
return 1.0;
}
}
Create.LOGGER.error("Theoretically unreachable code just got reached. HALP me please");
return 0.0; // this is actually unreachable but yay
/*if (!leadingUpsideDown) { // leading up
portalOffset = 1.0;
} else if (trailingUpsideDown) { // leading down, trailing down
portalOffset = -1.0;
} else { // leading down, trailing up - ahh
portalOffset = DebugValueCommand.value;
}
return portalOffset;*/
}
} }