mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-15 20:13:41 +01:00
Fix cart contraptions turning the wrong way on fast, tight turns
This commit is contained in:
parent
14d15089db
commit
fa22830b04
3 changed files with 13 additions and 18 deletions
|
@ -224,12 +224,7 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit
|
|||
return;
|
||||
}
|
||||
|
||||
for (Iterator<Entry<Entity, MutableInt>> iterator = collidingEntities.entrySet()
|
||||
.iterator(); iterator.hasNext();)
|
||||
if (iterator.next()
|
||||
.getValue()
|
||||
.incrementAndGet() > 3)
|
||||
iterator.remove();
|
||||
collidingEntities.entrySet().removeIf(e -> e.getValue().incrementAndGet() > 3);
|
||||
|
||||
xo = getX();
|
||||
yo = getY();
|
||||
|
@ -642,7 +637,7 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit
|
|||
public boolean hasExactlyOnePlayerPassenger() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public abstract void doLocalTransforms(float partialTicks, PoseStack[] matrixStacks);
|
||||
|
||||
|
|
|
@ -74,17 +74,12 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity {
|
|||
|
||||
public float prevPitch;
|
||||
public float pitch;
|
||||
public float targetPitch;
|
||||
|
||||
// When placed using a contraption item
|
||||
private float initialYawOffset;
|
||||
|
||||
public OrientedContraptionEntity(EntityType<?> type, Level world) {
|
||||
super(type, world);
|
||||
motionBeforeStall = Vec3.ZERO;
|
||||
attachedExtraInventories = false;
|
||||
isSerializingFurnaceCart = false;
|
||||
initialYawOffset = -1;
|
||||
}
|
||||
|
||||
public static OrientedContraptionEntity create(Level world, Contraption contraption, Direction initialOrientation) {
|
||||
|
@ -112,11 +107,6 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity {
|
|||
return entityData.get(INITIAL_ORIENTATION);
|
||||
}
|
||||
|
||||
public void deferOrientation(Direction newInitialAngle) {
|
||||
entityData.set(INITIAL_ORIENTATION, Direction.UP);
|
||||
yaw = initialYawOffset = newInitialAngle.toYRot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getYawOffset() {
|
||||
return getInitialYaw();
|
||||
|
@ -398,7 +388,8 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity {
|
|||
|
||||
prevYaw = yaw;
|
||||
float maxApproachSpeed = (float) (motion.length() * 12f / (Math.max(1, getBoundingBox().getXsize() / 6f)));
|
||||
float approach = AngleHelper.getShortestAngleDiff(yaw, targetYaw);
|
||||
float yawHint = AngleHelper.getShortestAngleDiff(yaw, yawFromVector(locationDiff));
|
||||
float approach = AngleHelper.getShortestAngleDiff(yaw, targetYaw, yawHint);
|
||||
approach = Mth.clamp(approach, -maxApproachSpeed, maxApproachSpeed);
|
||||
yaw += approach;
|
||||
if (Math.abs(AngleHelper.getShortestAngleDiff(yaw, targetYaw)) < 1f)
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simibubi.create.foundation.utility;
|
|||
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Direction.Axis;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
public class AngleHelper {
|
||||
|
||||
|
@ -40,4 +41,12 @@ public class AngleHelper {
|
|||
return (float) (((((target - current) % 360) + 540) % 360) - 180);
|
||||
}
|
||||
|
||||
public static float getShortestAngleDiff(double current, double target, float hint) {
|
||||
float diff = getShortestAngleDiff(current, target);
|
||||
if (Mth.equal(Math.abs(diff), 180) && Math.signum(diff) != Math.signum(hint)) {
|
||||
return diff + 360*Math.signum(hint);
|
||||
}
|
||||
return diff;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue