mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-15 09:33:40 +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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Iterator<Entry<Entity, MutableInt>> iterator = collidingEntities.entrySet()
|
collidingEntities.entrySet().removeIf(e -> e.getValue().incrementAndGet() > 3);
|
||||||
.iterator(); iterator.hasNext();)
|
|
||||||
if (iterator.next()
|
|
||||||
.getValue()
|
|
||||||
.incrementAndGet() > 3)
|
|
||||||
iterator.remove();
|
|
||||||
|
|
||||||
xo = getX();
|
xo = getX();
|
||||||
yo = getY();
|
yo = getY();
|
||||||
|
@ -642,7 +637,7 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit
|
||||||
public boolean hasExactlyOnePlayerPassenger() {
|
public boolean hasExactlyOnePlayerPassenger() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public abstract void doLocalTransforms(float partialTicks, PoseStack[] matrixStacks);
|
public abstract void doLocalTransforms(float partialTicks, PoseStack[] matrixStacks);
|
||||||
|
|
||||||
|
|
|
@ -74,17 +74,12 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity {
|
||||||
|
|
||||||
public float prevPitch;
|
public float prevPitch;
|
||||||
public float pitch;
|
public float pitch;
|
||||||
public float targetPitch;
|
|
||||||
|
|
||||||
// When placed using a contraption item
|
|
||||||
private float initialYawOffset;
|
|
||||||
|
|
||||||
public OrientedContraptionEntity(EntityType<?> type, Level world) {
|
public OrientedContraptionEntity(EntityType<?> type, Level world) {
|
||||||
super(type, world);
|
super(type, world);
|
||||||
motionBeforeStall = Vec3.ZERO;
|
motionBeforeStall = Vec3.ZERO;
|
||||||
attachedExtraInventories = false;
|
attachedExtraInventories = false;
|
||||||
isSerializingFurnaceCart = false;
|
isSerializingFurnaceCart = false;
|
||||||
initialYawOffset = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OrientedContraptionEntity create(Level world, Contraption contraption, Direction initialOrientation) {
|
public static OrientedContraptionEntity create(Level world, Contraption contraption, Direction initialOrientation) {
|
||||||
|
@ -112,11 +107,6 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity {
|
||||||
return entityData.get(INITIAL_ORIENTATION);
|
return entityData.get(INITIAL_ORIENTATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deferOrientation(Direction newInitialAngle) {
|
|
||||||
entityData.set(INITIAL_ORIENTATION, Direction.UP);
|
|
||||||
yaw = initialYawOffset = newInitialAngle.toYRot();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getYawOffset() {
|
public float getYawOffset() {
|
||||||
return getInitialYaw();
|
return getInitialYaw();
|
||||||
|
@ -398,7 +388,8 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity {
|
||||||
|
|
||||||
prevYaw = yaw;
|
prevYaw = yaw;
|
||||||
float maxApproachSpeed = (float) (motion.length() * 12f / (Math.max(1, getBoundingBox().getXsize() / 6f)));
|
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);
|
approach = Mth.clamp(approach, -maxApproachSpeed, maxApproachSpeed);
|
||||||
yaw += approach;
|
yaw += approach;
|
||||||
if (Math.abs(AngleHelper.getShortestAngleDiff(yaw, targetYaw)) < 1f)
|
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;
|
||||||
import net.minecraft.core.Direction.Axis;
|
import net.minecraft.core.Direction.Axis;
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
|
|
||||||
public class AngleHelper {
|
public class AngleHelper {
|
||||||
|
|
||||||
|
@ -40,4 +41,12 @@ public class AngleHelper {
|
||||||
return (float) (((((target - current) % 360) + 540) % 360) - 180);
|
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