Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add public methods for getting min and max on ranges #47

Merged
merged 1 commit into from
Apr 19, 2024

Conversation

ix0rai
Copy link
Member

@ix0rai ix0rai commented Apr 7, 2024

without this, it's impossible for you to check the min and max of a tracked value

context:
this method in my mod

	private static Option<Double> createOptional(TrackedValue<Float> trackedValue) {
		Constraint.Range<?> range = null;

		for (Constraint<?> c : trackedValue.constraints()) {
			if (c instanceof Constraint.Range<?> constraintRange) {
				range = constraintRange;
			}
		}

		if (range == null) {
			throw new RuntimeException("value must have float range constraint " + trackedValue);
		}

		return new Option<>(
				trackedValue.key().toString(),
				Option.constantTooltip(Text.empty()),
				(text, value) -> GameOptions.getGenericValueText(text, Text.translatable("options.multiplier", value)),
				new Option.IntRangeValueSet((int) range.min() * 10, (int) range.max() * 10).withModifier(i -> (double) i / 10.0, double_ -> (int) (double_ * 10.0)),
				Codec.doubleRange(range.min(), range.max()),
				(double) trackedValue.getDefaultValue(),
				value -> {
					trackedValue.setValue(value.floatValue());
				}
		);
	}

requires an access widener to work, and there should be a proper way to do this

@ix0rai ix0rai added the enhancement New feature or request label Apr 7, 2024
@ix0rai ix0rai requested a review from anonymous123-code April 8, 2024 02:11
@ix0rai ix0rai merged commit 846000f into QuiltMC:master Apr 19, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants