Skip to content

Commit

Permalink
simplify interpolated function for now bc i dont want to figure it out
Browse files Browse the repository at this point in the history
  • Loading branch information
Treetrain1 authored Nov 14, 2023
1 parent aded854 commit f10e4ca
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,37 @@
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

@ApiStatus.Experimental
@ApiStatus.Internal
public record InterpolatedGravityFunction(double gravity, double minLerpGravity, double maxLerpGravity, double minLerpY, double maxLerpY) implements SerializableGravityFunction<InterpolatedGravityFunction> {
public record InterpolatedGravityFunction(
double gravity,
//double minLerpGravity,
//double maxLerpGravity,
//double minLerpY,
//double maxLerpY
) implements SerializableGravityFunction<InterpolatedGravityFunction> {

public static final Codec<InterpolatedGravityFunction> CODEC = RecordCodecBuilder.create(instance ->
instance.group(
Codec.DOUBLE.fieldOf("gravity").forGetter(InterpolatedGravityFunction::gravity),
Codec.DOUBLE.fieldOf("minLerpGravity").forGetter(InterpolatedGravityFunction::minLerpGravity),
Codec.DOUBLE.fieldOf("maxLerpGravity").forGetter(InterpolatedGravityFunction::maxLerpY),
Codec.DOUBLE.fieldOf("minLerpY").forGetter(InterpolatedGravityFunction::minLerpY),
Codec.DOUBLE.fieldOf("maxLerpY").forGetter(InterpolatedGravityFunction::maxLerpY)
//Codec.DOUBLE.fieldOf("minLerpGravity").forGetter(InterpolatedGravityFunction::minLerpGravity),
//Codec.DOUBLE.fieldOf("maxLerpGravity").forGetter(InterpolatedGravityFunction::maxLerpY),
//Codec.DOUBLE.fieldOf("minLerpY").forGetter(InterpolatedGravityFunction::minLerpY),
//Codec.DOUBLE.fieldOf("maxLerpY").forGetter(InterpolatedGravityFunction::maxLerpY)
).apply(instance, InterpolatedGravityFunction::new)
);

public static final Codec<GravityBelt<InterpolatedGravityFunction>> BELT_CODEC = GravityBelt.codec(CODEC);

@Override
public double get(@Nullable Entity entity, double y, double minY, double maxY) {
if (!(entity instanceof Player)) return 1.0;
double normalizedY = (y - minLerpY) / (maxLerpY - minLerpY);
double normalizedY = (y - minY) / (maxY - minY);
//double normalizedY = (y - minLerpY) / (maxLerpY - minLerpY);

if (normalizedY < 0) return minLerpGravity;
if (normalizedY < 0.5) return Mth.lerp(normalizedY, minLerpGravity, gravity);
return gravity * normalizedY;
/*if (normalizedY < 0.5) {
return Mth.clamp(Mth.lerp(normalizedY, minLerpGravity, gravity), minLerpGravity, gravity);
}
if (normalizedY < 1.0) return Mth.lerp(normalizedY, gravity, maxLerpGravity);
return maxLerpGravity;
return maxLerpGravity;*/
}

@Override
Expand Down

0 comments on commit f10e4ca

Please sign in to comment.