mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-02-04 17:34:58 +01:00
Fix aligners taking beams from sides they shouldn't take a beam from
This commit is contained in:
parent
d2dc576644
commit
a0f01b733d
2 changed files with 39 additions and 1 deletions
|
@ -8,10 +8,12 @@ import java.util.Set;
|
|||
import javax.annotation.Nullable;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.simibubi.create.foundation.utility.Iterate;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.item.DyeColor;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -122,4 +124,36 @@ public class Beam extends ArrayList<BeamSegment> {
|
|||
public Beam getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Direction getBlockEnterFace(BlockPos blockPos) {
|
||||
Vector3d beamDir = getDirection();
|
||||
if (beamDir == null)
|
||||
return null;
|
||||
Vector3d pos = VecHelper.getCenterOf(blockPos);
|
||||
|
||||
Direction minDir = null;
|
||||
double lambda = Double.MAX_VALUE;
|
||||
|
||||
for (Direction testDir : Iterate.directions) {
|
||||
Vector3d faceNormal = Vector3d.of(testDir.getDirectionVec());
|
||||
Vector3d posOnSide = faceNormal.scale(.5)
|
||||
.add(pos);
|
||||
double dotProd = faceNormal.dotProduct(beamDir);
|
||||
if (dotProd == 0)
|
||||
continue;
|
||||
|
||||
double newLambda = (faceNormal.dotProduct(posOnSide) - faceNormal.dotProduct(get(0)
|
||||
.getStart())) / dotProd;
|
||||
Vector3d offset = get(0).getStart()
|
||||
.add(beamDir.scale(newLambda))
|
||||
.subtract(posOnSide);
|
||||
if (newLambda < lambda && (Math.abs(offset.x) < .5 && Math.abs(offset.y) < .5 && Math.abs(offset.z) < .5)) {
|
||||
lambda = newLambda;
|
||||
minDir = testDir;
|
||||
}
|
||||
|
||||
}
|
||||
return minDir;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,8 +82,12 @@ public class AlignerBehaviour extends AbstractLightHandlingBehaviour<AlignerTile
|
|||
|
||||
@Override
|
||||
public Stream<Beam> constructSubBeams(Beam beam) {
|
||||
if (beam == collectedBeam)
|
||||
return Stream.empty();
|
||||
Vector3d beamDir = beam.getDirection();
|
||||
if (!beam.isRemoved() && beamDir != null && AngleHelper.deg(Math.cos(beamDir.dotProduct(getFacingVec()))) < 60) {
|
||||
if (!beam.isRemoved() && beamDir != null && AngleHelper.deg(Math.cos(beamDir.dotProduct(getFacingVec()))) < 60
|
||||
&& getFacing().getOpposite()
|
||||
.equals(beam.getBlockEnterFace(getBlockPos()))) {
|
||||
beams.add(beam);
|
||||
requestBeamUpdate();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue