Block block = cart.worldObj.getBlock(i, j, k);
if (isLiving && RailcraftBlocks.getBlockElevator() != null && block == RailcraftBlocks.getBlockElevator())
return;
// System.out.println(cart.getClass().getSimpleName() + ": " + cart.entityId + " collided with " + other.getClass().getSimpleName() + ": " + other.entityId);
Vec2D cartPos = new Vec2D(cart.posX, cart.posZ);
Vec2D otherPos = new Vec2D(other.posX, other.posZ);
Vec2D unit = Vec2D.subtract(otherPos, cartPos);
unit.normalize();
double distance = cart.getDistanceToEntity(other);
double depth = distance - OPTIMAL_DISTANCE;
double forceX = 0;
double forceZ = 0;
if (depth < 0) {
double spring = isPlayer ? COEF_SPRING_PLAYER : COEF_SPRING;
double penaltyX = spring * depth * unit.getX();
double penaltyZ = spring * depth * unit.getY();
forceX += penaltyX;
forceZ += penaltyZ;
if (!isPlayer) {
double impulseX = unit.getX();
double impulseZ = unit.getY();
impulseX *= -(1.0 + COEF_RESTITUTION);
impulseZ *= -(1.0 + COEF_RESTITUTION);
Vec2D cartVel = new Vec2D(cart.motionX, cart.motionZ);
Vec2D otherVel = new Vec2D(other.motionX, other.motionZ);
double dot = Vec2D.subtract(otherVel, cartVel).dotProduct(unit);
impulseX *= dot;
impulseZ *= dot;
impulseX *= 0.5;
impulseZ *= 0.5;
forceX -= impulseX;
forceZ -= impulseZ;
}
}
if (other instanceof EntityMinecart) {
EntityMinecart otherCart = (EntityMinecart) other;
if (!cart.isPoweredCart() || otherCart.isPoweredCart())
if (!RailTools.isCartLockedDown(cart))
cart.addVelocity(forceX, 0, forceZ);
if (!otherCart.isPoweredCart() || cart.isPoweredCart())
if (!RailTools.isCartLockedDown(otherCart))
other.addVelocity(-forceX, 0, -forceZ);
} else {
// if(isPlayer) {
// forceX += Math.abs(cart.motionX - other.motionX) / 2;
// forceZ += Math.abs(cart.motionZ - other.motionZ) / 2;
// }
// System.out.printf("forceX=%f, forceZ=%f%n", forceX, forceZ);
Vec2D cartVel = new Vec2D(cart.motionX + forceX, cart.motionZ + forceZ);
Vec2D otherVel = new Vec2D(other.motionX - forceX, other.motionZ - forceZ);
double dot = Vec2D.subtract(otherVel, cartVel).dotProduct(unit);
double dampX = COEF_DAMPING * dot * unit.getX();
double dampZ = COEF_DAMPING * dot * unit.getY();