Java Code Examples for net.minecraft.util.math.Vec3d#length()

The following examples show how to use net.minecraft.util.math.Vec3d#length() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static float signAngle(Vec3d a, Vec3d b, Vec3d n) {
	Vec3d cross = a.crossProduct(b);
	double s = cross.length();
	double c = a.dotProduct(b);
	double angle = MathHelper.atan2(s, c);

	if (n != null) {
		if (n.dotProduct(cross) < 0) {
			angle = -angle;
		}
	}

	return (float) Math.toDegrees(angle);
}
 
Example 2
Source File: MixinEntity.java    From multiconnect with MIT License 4 votes vote down vote up
@Inject(method = "updateMovementInFluid", at = @At("HEAD"), cancellable = true)
private void modifyFluidMovementBoundingBox(Tag<Fluid> fluidTag, double d, CallbackInfoReturnable<Boolean> ci) {
    if (ConnectionInfo.protocolVersion > Protocols.V1_12_2)
        return;

    Box box = getBoundingBox().expand(0, -0.4, 0).contract(0.001);
    int minX = MathHelper.floor(box.minX);
    int maxX = MathHelper.ceil(box.maxX);
    int minY = MathHelper.floor(box.minY);
    int maxY = MathHelper.ceil(box.maxY);
    int minZ = MathHelper.floor(box.minZ);
    int maxZ = MathHelper.ceil(box.maxZ);

    if (!world.isRegionLoaded(minX, minY, minZ, maxX, maxY, maxZ))
        ci.setReturnValue(false);

    double waterHeight = 0;
    boolean foundFluid = false;
    Vec3d pushVec = Vec3d.ZERO;

    BlockPos.Mutable mutable = new BlockPos.Mutable();

    for (int x = minX; x < maxX; x++) {
        for (int y = minY - 1; y < maxY; y++) {
            for (int z = minZ; z < maxZ; z++) {
                mutable.set(x, y, z);
                FluidState state = world.getFluidState(mutable);
                if (state.isIn(fluidTag)) {
                    double height = y + state.getHeight(world, mutable);
                    if (height >= box.minY - 0.4)
                        waterHeight = Math.max(height - box.minY + 0.4, waterHeight);
                    if (y >= minY && maxY >= height) {
                        foundFluid = true;
                        pushVec = pushVec.add(state.getVelocity(world, mutable));
                    }
                }
            }
        }
    }

    if (pushVec.length() > 0) {
        pushVec = pushVec.normalize().multiply(0.014);
        setVelocity(getVelocity().add(pushVec));
    }

    this.fluidHeight.put(fluidTag, waterHeight);
    ci.setReturnValue(foundFluid);
}