Java Code Examples for net.minecraft.util.math.MathHelper#lerp()
The following examples show how to use
net.minecraft.util.math.MathHelper#lerp() .
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: StoneCircleFeature.java From the-hallow with MIT License | 6 votes |
private void generateStone(ModifiableWorld world, Random rand, final BlockPos centre, BlockPos.Mutable mutable, int height, int lowY) { final int posX = centre.getX(); final int posZ = centre.getZ(); for (int xOffset = -3; xOffset < 4; ++xOffset) { mutable.setX(posX + xOffset); for (int zOffset = -3; zOffset < 4; ++zOffset) { mutable.setZ(posZ + zOffset); mutable.setY(0); double squaredDistanceTo = centre.getSquaredDistance(mutable) / 9D; int localHeight = (int) offsetNoise.sample(mutable.getX(), mutable.getZ()) + (int) MathHelper.lerp(squaredDistanceTo, height, 0D) + lowY; for (int y = lowY - 5; y < localHeight + 1; ++y) { mutable.setY(y); world.setBlockState(mutable, rand.nextInt(3) == 0 ? COBBLESTONE : STONE, 19); } } } }
Example 2
Source File: Pony.java From MineLittlePony with MIT License | 6 votes |
@Override public Vec3d getAbsoluteRidingOffset(LivingEntity entity) { IPony ridingPony = getMountedPony(entity); if (ridingPony != null) { LivingEntity ridee = (LivingEntity)entity.getVehicle(); Vec3d offset = PonyTransformation.forSize(ridingPony.getMetadata().getSize()).getRiderOffset(); float scale = ridingPony.getMetadata().getSize().getScaleFactor(); return ridingPony.getAbsoluteRidingOffset(ridee) .add(0, offset.y - ridee.getHeight() * 1/scale, 0); } float delta = MinecraftClient.getInstance().getTickDelta(); return new Vec3d( MathHelper.lerp(delta, entity.prevX, entity.getX()), MathHelper.lerp(delta, entity.prevY, entity.getY()), MathHelper.lerp(delta, entity.prevZ, entity.getZ()) ); }
Example 3
Source File: BarrowFeature.java From the-hallow with MIT License | 5 votes |
private boolean generate(IWorld world, Random rand, BlockPos pos, CoordinateFunction<SurfaceConfig> configFunction) { int centreX = pos.getX() + rand.nextInt(16) - 8; int centreZ = pos.getZ() + rand.nextInt(16) - 8; int lowY = pos.getY() - 3; int radius = rand.nextInt(6) + 7; int height = rand.nextInt(4) + 6; double radiusSquared = radius * radius; Vec3d origin = new Vec3d(centreX, 0, centreZ); BlockPos.Mutable posMutable = new BlockPos.Mutable(); for (int xOffset = -radius; xOffset <= radius; ++xOffset) { int x = centreX + xOffset; for (int zOffset = -radius; zOffset <= radius; ++zOffset) { int z = centreZ + zOffset; Vec3d position = new Vec3d(x, 0, z); double sqrDistTo = position.squaredDistanceTo(origin); if (sqrDistTo <= radiusSquared) { double progress = MathHelper.perlinFade(sqrDistTo / radiusSquared); int heightOffset = (int) MathHelper.lerp(progress, height, 0); heightOffset += (int) MathHelper.lerp(progress, offsetNoise.sample(x, z), 0); posMutable.setX(x); posMutable.setZ(z); this.generateBarrowColumn(world, rand, lowY, heightOffset, posMutable, configFunction.get(posMutable)); } } } return true; }
Example 4
Source File: GameRendererMixin.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
@Redirect( at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;lerp(FFF)F", ordinal = 0), method = { "renderWorld(FJLnet/minecraft/client/util/math/MatrixStack;)V"}) private float wurstNauseaLerp(float delta, float first, float second) { if(!WurstClient.INSTANCE.getHax().antiWobbleHack.isEnabled()) return MathHelper.lerp(delta, first, second); return 0; }
Example 5
Source File: RenderMiningLaser.java From MiningGadgets with MIT License | 5 votes |
private static float getSpeedModifier(ItemStack stack) { if (UpgradeTools.containsUpgrade(stack, Upgrade.EFFICIENCY_1)) { double efficiency = UpgradeTools.getUpgradeFromGadget(stack, Upgrade.EFFICIENCY_1).get().getTier() / 5f; double speedModifier = MathHelper.lerp(efficiency, 0.02, 0.05); return (float) -speedModifier; } else { return -0.02f; } }
Example 6
Source File: RenderMiningLaser.java From MiningGadgets with MIT License | 5 votes |
private static void drawBeam(double xOffset, double yOffset, double zOffset, float thickness, Hand hand, double distance, BufferBuilder wr, double v1, double v2, float ticks) { ClientPlayerEntity player = Minecraft.getInstance().player; float startXOffset = -0.25f; float startYOffset = -.115f; float startZOffset = 0.65f + (1 - player.getFovModifier()); float f = (MathHelper.lerp(ticks, player.prevRotationPitch, player.rotationPitch) - MathHelper.lerp(ticks, player.prevRenderArmPitch, player.renderArmPitch)); float f1 = (MathHelper.lerp(ticks, player.prevRotationYaw, player.rotationYaw) - MathHelper.lerp(ticks, player.prevRenderArmYaw, player.renderArmYaw)); startXOffset = startXOffset + (f1 / 1000); startYOffset = startYOffset + (f / 1000); // Support for hand sides remembering to take into account of Skin options if( Minecraft.getInstance().gameSettings.mainHand != HandSide.RIGHT ) hand = hand == Hand.MAIN_HAND ? Hand.OFF_HAND : Hand.MAIN_HAND; wr.begin(GL_QUADS, DefaultVertexFormats.POSITION_TEX); if (hand == Hand.MAIN_HAND) { wr.pos(startXOffset, -thickness + startYOffset, startZOffset).tex(1, (float) v1).endVertex(); wr.pos(xOffset, -thickness + yOffset, distance + zOffset).tex(1, (float) v2).endVertex(); wr.pos(xOffset, thickness + yOffset, distance + zOffset).tex(0, (float) v2).endVertex(); wr.pos(startXOffset, thickness + startYOffset, startZOffset).tex(0, (float) v1).endVertex(); } else { startYOffset = -.120f; wr.pos(-startXOffset, thickness + startYOffset, startZOffset).tex(0, (float) v1).endVertex(); wr.pos(xOffset, thickness + yOffset, distance + zOffset).tex(0, (float) v2).endVertex(); wr.pos(xOffset, -thickness + yOffset, distance + zOffset).tex(1, (float) v2).endVertex(); wr.pos(-startXOffset, -thickness + startYOffset, startZOffset).tex(1, (float) v1).endVertex(); } Tessellator.getInstance().draw(); }
Example 7
Source File: RenderMiningLaser2.java From MiningGadgets with MIT License | 5 votes |
private static float getSpeedModifier(ItemStack stack) { if (UpgradeTools.containsUpgrade(stack, Upgrade.EFFICIENCY_1)) { double efficiency = UpgradeTools.getUpgradeFromGadget(stack, Upgrade.EFFICIENCY_1).get().getTier() / 5f; double speedModifier = MathHelper.lerp(efficiency, 0.02, 0.05); return (float) -speedModifier; } else { return -0.02f; } }
Example 8
Source File: CapeFeature.java From MineLittlePony with MIT License | 5 votes |
@Override public void render(MatrixStack stack, VertexConsumerProvider renderContext, int lightUv, AbstractClientPlayerEntity player, float limbDistance, float limbAngle, float tickDelta, float age, float headYaw, float headPitch) { M model = getContextModel(); if (player.hasSkinTexture() && !player.isInvisible() && player.isPartVisible(PlayerModelPart.CAPE) && player.getCapeTexture() != null && player.getEquippedStack(EquipmentSlot.CHEST).getItem() != Items.ELYTRA) { stack.push(); model.transform(BodyPart.BODY, stack); stack.translate(0, 0.24F, 0); model.getBodyPart(BodyPart.BODY).rotate(stack); double capeX = MathHelper.lerp(tickDelta, player.capeX, player.prevCapeX) - MathHelper.lerp(tickDelta, player.prevX, player.getX()); double capeY = MathHelper.lerp(tickDelta, player.capeY, player.prevCapeY) - MathHelper.lerp(tickDelta, player.prevY, player.getY()); double capeZ = MathHelper.lerp(tickDelta, player.capeZ, player.prevCapeZ) - MathHelper.lerp(tickDelta, player.prevZ, player.getZ()); float motionYaw = player.prevBodyYaw + (player.bodyYaw - player.prevBodyYaw); double sin = MathHelper.sin(motionYaw * PI / 180); double cos = (-MathHelper.cos(motionYaw * PI / 180)); float capeMotionY = (float) capeY * 10; if (capeMotionY < -6) capeMotionY = -6; if (capeMotionY > 32) capeMotionY = 32; float capeMotionX = (float) (capeX * sin + capeZ * cos) * 100; float diagMotion = (float) (capeX * cos - capeZ * sin) * 100; if (capeMotionX < 0) capeMotionX = 0; float camera = MathHelper.lerp(tickDelta, player.prevStrideDistance, player.strideDistance); capeMotionY += MathHelper.sin(MathHelper.lerp(tickDelta, player.prevHorizontalSpeed, player.horizontalSpeed) * 6) * 32 * camera; stack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(2 + capeMotionX / 12 + capeMotionY)); stack.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion( diagMotion / 2)); stack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(-diagMotion / 2)); stack.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(180)); stack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(90)); VertexConsumer vertices = renderContext.getBuffer(RenderLayer.getEntitySolid(player.getCapeTexture())); model.renderCape(stack, vertices, lightUv, OverlayTexture.DEFAULT_UV); stack.pop(); } }
Example 9
Source File: GCOreFeature.java From Galacticraft-Rewoven with MIT License | 4 votes |
@SuppressWarnings("PointlessArithmeticExpression") protected boolean generateVeinPart(WorldAccess world, Random random, GCOreFeatureConfig config, double startX, double endX, double startZ, double endZ, double startY, double endY, int x, int y, int z, int size, int i) { int j = 0; BitSet bitSet = new BitSet(size * i * size); BlockPos.Mutable mutable = new BlockPos.Mutable(); double[] ds = new double[config.size * 4]; int m; double o; double p; double q; double r; for (m = 0; m < config.size; ++m) { float f = (float) m / (float) config.size; o = MathHelper.lerp(f, startX, endX); p = MathHelper.lerp(f, startY, endY); q = MathHelper.lerp(f, startZ, endZ); r = random.nextDouble() * (double) config.size / 16.0D; double l = ((double) (MathHelper.sin(3.1415927F * f) + 1.0F) * r + 1.0D) / 2.0D; ds[m * 4 + 0] = o; ds[m * 4 + 1] = p; ds[m * 4 + 2] = q; ds[m * 4 + 3] = l; } for (m = 0; m < config.size - 1; ++m) { if (ds[m * 4 + 3] > 0.0D) { for (int n = m + 1; n < config.size; ++n) { if (ds[n * 4 + 3] > 0.0D) { o = ds[m * 4 + 0] - ds[n * 4 + 0]; p = ds[m * 4 + 1] - ds[n * 4 + 1]; q = ds[m * 4 + 2] - ds[n * 4 + 2]; r = ds[m * 4 + 3] - ds[n * 4 + 3]; if (r * r > o * o + p * p + q * q) { if (r > 0.0D) { ds[n * 4 + 3] = -1.0D; } else { ds[m * 4 + 3] = -1.0D; } } } } } } for (m = 0; m < config.size; ++m) { double t = ds[m * 4 + 3]; if (t >= 0.0D) { double u = ds[m * 4 + 0]; double v = ds[m * 4 + 1]; double w = ds[m * 4 + 2]; int aa = Math.max(MathHelper.floor(u - t), x); int ab = Math.max(MathHelper.floor(v - t), y); int ac = Math.max(MathHelper.floor(w - t), z); int ad = Math.max(MathHelper.floor(u + t), aa); int ae = Math.max(MathHelper.floor(v + t), ab); int af = Math.max(MathHelper.floor(w + t), ac); for (int ag = aa; ag <= ad; ++ag) { double ah = ((double) ag + 0.5D - u) / t; if (ah * ah < 1.0D) { for (int ai = ab; ai <= ae; ++ai) { double aj = ((double) ai + 0.5D - v) / t; if (ah * ah + aj * aj < 1.0D) { for (int ak = ac; ak <= af; ++ak) { double al = ((double) ak + 0.5D - w) / t; if (ah * ah + aj * aj + al * al < 1.0D) { int am = ag - x + (ai - y) * size + (ak - z) * size * i; if (!bitSet.get(am)) { bitSet.set(am); mutable.set(ag, ai, ak); if (config.target.predicate.test(world.getBlockState(mutable))) { world.setBlockState(mutable, config.state, 2); ++j; } } } } } } } } } } return j > 0; }
Example 10
Source File: HallowedOreFeature.java From the-hallow with MIT License | 4 votes |
protected boolean generateVeinPart(IWorld world, Random random, HallowedOreFeatureConfig oreFeatureConfig, double positiveX, double negativeX, double positiveZ, double negativeZ, double double_5, double double_6, int startX, int yPosition, int startZ, int xSize, int int_5) { int stonesPlaced = 0; BitSet bitSet = new BitSet(xSize * int_5 * xSize); Mutable blockPos = new Mutable(); double[] doubles_1 = new double[oreFeatureConfig.size * 4]; int counter; double currentX; double currentY; double currentZ; double double_15; for (counter = 0; counter < oreFeatureConfig.size; ++counter) { float progress = (float) counter / (float) oreFeatureConfig.size; currentX = MathHelper.lerp(progress, positiveX, negativeX); currentY = MathHelper.lerp(progress, double_5, double_6); currentZ = MathHelper.lerp(progress, positiveZ, negativeZ); double_15 = random.nextDouble() * (double) oreFeatureConfig.size / 16.0D; double double_11 = ((double) (MathHelper.sin(3.1415927F * progress) + 1.0F) * double_15 + 1.0D) / 2.0D; doubles_1[counter * 4 + 0] = currentX; doubles_1[counter * 4 + 1] = currentY; doubles_1[counter * 4 + 2] = currentZ; doubles_1[counter * 4 + 3] = double_11; } for (counter = 0; counter < oreFeatureConfig.size - 1; ++counter) { if (doubles_1[counter * 4 + 3] > 0.0D) { for (int int_9 = counter + 1; int_9 < oreFeatureConfig.size; ++int_9) { if (doubles_1[int_9 * 4 + 3] > 0.0D) { currentX = doubles_1[counter * 4 + 0] - doubles_1[int_9 * 4 + 0]; currentY = doubles_1[counter * 4 + 1] - doubles_1[int_9 * 4 + 1]; currentZ = doubles_1[counter * 4 + 2] - doubles_1[int_9 * 4 + 2]; double_15 = doubles_1[counter * 4 + 3] - doubles_1[int_9 * 4 + 3]; if (double_15 * double_15 > currentX * currentX + currentY * currentY + currentZ * currentZ) { if (double_15 > 0.0D) { doubles_1[int_9 * 4 + 3] = -1.0D; } else { doubles_1[counter * 4 + 3] = -1.0D; } } } } } } for (counter = 0; counter < oreFeatureConfig.size; ++counter) { double double_16 = doubles_1[counter * 4 + 3]; if (double_16 >= 0.0D) { double double_17 = doubles_1[counter * 4 + 0]; double double_18 = doubles_1[counter * 4 + 1]; double double_19 = doubles_1[counter * 4 + 2]; int int_11 = Math.max(MathHelper.floor(double_17 - double_16), startX); int int_12 = Math.max(MathHelper.floor(double_18 - double_16), yPosition); int int_13 = Math.max(MathHelper.floor(double_19 - double_16), startZ); int int_14 = Math.max(MathHelper.floor(double_17 + double_16), int_11); int int_15 = Math.max(MathHelper.floor(double_18 + double_16), int_12); int int_16 = Math.max(MathHelper.floor(double_19 + double_16), int_13); for (int x = int_11; x <= int_14; ++x) { double double_20 = ((double) x + 0.5D - double_17) / double_16; if (double_20 * double_20 < 1.0D) { for (int y = int_12; y <= int_15; ++y) { double double_21 = ((double) y + 0.5D - double_18) / double_16; if (double_20 * double_20 + double_21 * double_21 < 1.0D) { for (int z = int_13; z <= int_16; ++z) { double double_22 = ((double) z + 0.5D - double_19) / double_16; if (double_20 * double_20 + double_21 * double_21 + double_22 * double_22 < 1.0D) { int int_20 = x - startX + (y - yPosition) * xSize + (z - startZ) * xSize * int_5; if (!bitSet.get(int_20)) { bitSet.set(int_20); blockPos.set(x, y, z); if (world.getBlockState(blockPos).getBlock() == HallowedBlocks.TAINTED_STONE) { world.setBlockState(blockPos, oreFeatureConfig.state, 2); ++stonesPlaced; } } } } } } } } } } return stonesPlaced > 0; }
Example 11
Source File: EntityMixin.java From fabric-carpet with MIT License | 4 votes |
public float getMainYaw(float partialTicks) { return partialTicks == 1.0F ? this.yaw : MathHelper.lerp(partialTicks, this.prevYaw, this.yaw); }
Example 12
Source File: RenderMiningLaser2.java From MiningGadgets with MIT License | 4 votes |
private static void drawBeam(double xOffset, double yOffset, double zOffset, IVertexBuilder builder, Matrix4f positionMatrix, Matrix3f matrixNormalIn, float thickness, Hand hand, double distance, double v1, double v2, float ticks, float r, float g, float b, float alpha) { Vector3f vector3f = new Vector3f(0.0f, 1.0f, 0.0f); vector3f.transform(matrixNormalIn); ClientPlayerEntity player = Minecraft.getInstance().player; // Support for hand sides remembering to take into account of Skin options if( Minecraft.getInstance().gameSettings.mainHand != HandSide.RIGHT ) hand = hand == Hand.MAIN_HAND ? Hand.OFF_HAND : Hand.MAIN_HAND; float startXOffset = -0.25f; float startYOffset = -.115f; float startZOffset = 0.65f + (1 - player.getFovModifier()); if (hand == Hand.OFF_HAND) { startYOffset = -.120f; startXOffset = 0.25f; } float f = (MathHelper.lerp(ticks, player.prevRotationPitch, player.rotationPitch) - MathHelper.lerp(ticks, player.prevRenderArmPitch, player.renderArmPitch)); float f1 = (MathHelper.lerp(ticks, player.prevRotationYaw, player.rotationYaw) - MathHelper.lerp(ticks, player.prevRenderArmYaw, player.renderArmYaw)); startXOffset = startXOffset + (f1 / 100000000); startYOffset = startYOffset + (f / 100000000); Vector4f vec1 = new Vector4f(startXOffset, -thickness + startYOffset, startZOffset, 1.0F); vec1.transform(positionMatrix); Vector4f vec2 = new Vector4f((float) xOffset, -thickness + (float) yOffset, (float) distance + (float) zOffset, 1.0F); vec2.transform(positionMatrix); Vector4f vec3 = new Vector4f((float) xOffset, thickness + (float) yOffset, (float) distance + (float) zOffset, 1.0F); vec3.transform(positionMatrix); Vector4f vec4 = new Vector4f(startXOffset, thickness + startYOffset, startZOffset, 1.0F); vec4.transform(positionMatrix); if (hand == Hand.MAIN_HAND) { builder.addVertex(vec4.getX(), vec4.getY(), vec4.getZ(), r, g, b, alpha, 0, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec3.getX(), vec3.getY(), vec3.getZ(), r, g, b, alpha, 0, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec2.getX(), vec2.getY(), vec2.getZ(), r, g, b, alpha, 1, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec1.getX(), vec1.getY(), vec1.getZ(), r, g, b, alpha, 1, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); //Rendering a 2nd time to allow you to see both sides in multiplayer, shouldn't be necessary with culling disabled but here we are.... builder.addVertex(vec1.getX(), vec1.getY(), vec1.getZ(), r, g, b, alpha, 1, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec2.getX(), vec2.getY(), vec2.getZ(), r, g, b, alpha, 1, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec3.getX(), vec3.getY(), vec3.getZ(), r, g, b, alpha, 0, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec4.getX(), vec4.getY(), vec4.getZ(), r, g, b, alpha, 0, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); } else { builder.addVertex(vec1.getX(), vec1.getY(), vec1.getZ(), r, g, b, alpha, 1, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec2.getX(), vec2.getY(), vec2.getZ(), r, g, b, alpha, 1, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec3.getX(), vec3.getY(), vec3.getZ(), r, g, b, alpha, 0, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec4.getX(), vec4.getY(), vec4.getZ(), r, g, b, alpha, 0, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); //Rendering a 2nd time to allow you to see both sides in multiplayer, shouldn't be necessary with culling disabled but here we are.... builder.addVertex(vec4.getX(), vec4.getY(), vec4.getZ(), r, g, b, alpha, 0, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec3.getX(), vec3.getY(), vec3.getZ(), r, g, b, alpha, 0, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec2.getX(), vec2.getY(), vec2.getZ(), r, g, b, alpha, 1, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec1.getX(), vec1.getY(), vec1.getZ(), r, g, b, alpha, 1, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); } }