JEI fix accuracy of min/max and add support for summation
This commit is contained in:
parent
0838f3149e
commit
c58982fdba
|
|
@ -40,6 +40,7 @@ import net.minecraft.world.level.storage.loot.providers.number.UniformGenerator;
|
||||||
import net.minecraftforge.common.util.Lazy;
|
import net.minecraftforge.common.util.Lazy;
|
||||||
import thedarkcolour.exdeorum.compat.GroupedSieveRecipe;
|
import thedarkcolour.exdeorum.compat.GroupedSieveRecipe;
|
||||||
import thedarkcolour.exdeorum.data.TranslationKeys;
|
import thedarkcolour.exdeorum.data.TranslationKeys;
|
||||||
|
import thedarkcolour.exdeorum.loot.SummationGenerator;
|
||||||
import thedarkcolour.exdeorum.recipe.RecipeUtil;
|
import thedarkcolour.exdeorum.recipe.RecipeUtil;
|
||||||
import thedarkcolour.exdeorum.registry.EBlocks;
|
import thedarkcolour.exdeorum.registry.EBlocks;
|
||||||
|
|
||||||
|
|
@ -116,14 +117,14 @@ class SieveCategory implements IRecipeCategory<GroupedSieveRecipe> {
|
||||||
addAvgOutput(tooltipLines, RecipeUtil.getExpectedValue(provider));
|
addAvgOutput(tooltipLines, RecipeUtil.getExpectedValue(provider));
|
||||||
}
|
}
|
||||||
|
|
||||||
addMinMaxes(tooltipLines, ConstantValue.exactly(0), binomial.n);
|
addMinMaxes(tooltipLines, 0, getMax(binomial.n));
|
||||||
} else if (provider.getClass() != ConstantValue.class) {
|
} else if (provider.getClass() != ConstantValue.class) {
|
||||||
var val = RecipeUtil.getExpectedValue(provider);
|
var val = RecipeUtil.getExpectedValue(provider);
|
||||||
if (val != -1.0) {
|
if (val != -1.0) {
|
||||||
addAvgOutput(tooltipLines, val);
|
addAvgOutput(tooltipLines, val);
|
||||||
|
|
||||||
if (provider instanceof UniformGenerator uniform) {
|
if (provider instanceof UniformGenerator || provider instanceof SummationGenerator) {
|
||||||
addMinMaxes(tooltipLines, uniform.min, uniform.max);
|
addMinMaxes(tooltipLines, getMin(provider), getMax(provider));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -134,15 +135,55 @@ class SieveCategory implements IRecipeCategory<GroupedSieveRecipe> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static double getMin(NumberProvider provider) {
|
||||||
|
if (provider instanceof ConstantValue value) {
|
||||||
|
return value.value;
|
||||||
|
} else if (provider instanceof UniformGenerator uniform) {
|
||||||
|
return getMin(uniform.min);
|
||||||
|
} else if (provider instanceof BinomialDistributionGenerator) {
|
||||||
|
return 0;
|
||||||
|
} else if (provider instanceof SummationGenerator summation) {
|
||||||
|
double sum = 0;
|
||||||
|
|
||||||
|
for (var child : summation.providers()) {
|
||||||
|
sum += getMin(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double getMax(NumberProvider provider) {
|
||||||
|
if (provider instanceof ConstantValue value) {
|
||||||
|
return value.value;
|
||||||
|
} else if (provider instanceof UniformGenerator uniform) {
|
||||||
|
return getMax(uniform.max);
|
||||||
|
} else if (provider instanceof BinomialDistributionGenerator binomial) {
|
||||||
|
return getMax(binomial.n);
|
||||||
|
} else if (provider instanceof SummationGenerator summation) {
|
||||||
|
double sum = 0;
|
||||||
|
|
||||||
|
for (var child : summation.providers()) {
|
||||||
|
sum += getMax(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
private static void addAvgOutput(ImmutableList.Builder<Component> tooltipLines, double avgValue) {
|
private static void addAvgOutput(ImmutableList.Builder<Component> tooltipLines, double avgValue) {
|
||||||
String avgOutput = ClientJeiUtil.FORMATTER.format(avgValue);
|
String avgOutput = ClientJeiUtil.FORMATTER.format(avgValue);
|
||||||
tooltipLines.add(Component.translatable(TranslationKeys.SIEVE_RECIPE_AVERAGE_OUTPUT, avgOutput).withStyle(ChatFormatting.GRAY));
|
tooltipLines.add(Component.translatable(TranslationKeys.SIEVE_RECIPE_AVERAGE_OUTPUT, avgOutput).withStyle(ChatFormatting.GRAY));
|
||||||
}
|
}
|
||||||
|
|
||||||
// when the player holds shift, they can see the min/max amounts of a drop
|
// when the player holds shift, they can see the min/max amounts of a drop
|
||||||
private static void addMinMaxes(ImmutableList.Builder<Component> tooltipLines, NumberProvider min, NumberProvider max) {
|
private static void addMinMaxes(ImmutableList.Builder<Component> tooltipLines, double min, double max) {
|
||||||
var minFormatted = ClientJeiUtil.FORMATTER.format(RecipeUtil.getExpectedValue(min));
|
String minFormatted = ClientJeiUtil.FORMATTER.format(min);
|
||||||
var maxFormatted = ClientJeiUtil.FORMATTER.format(RecipeUtil.getExpectedValue(max));
|
String maxFormatted = ClientJeiUtil.FORMATTER.format(max);
|
||||||
|
|
||||||
tooltipLines.add(Component.translatable(TranslationKeys.SIEVE_RECIPE_MIN_OUTPUT, minFormatted).withStyle(ChatFormatting.GRAY));
|
tooltipLines.add(Component.translatable(TranslationKeys.SIEVE_RECIPE_MIN_OUTPUT, minFormatted).withStyle(ChatFormatting.GRAY));
|
||||||
tooltipLines.add(Component.translatable(TranslationKeys.SIEVE_RECIPE_MAX_OUTPUT, maxFormatted).withStyle(ChatFormatting.GRAY));
|
tooltipLines.add(Component.translatable(TranslationKeys.SIEVE_RECIPE_MAX_OUTPUT, maxFormatted).withStyle(ChatFormatting.GRAY));
|
||||||
|
|
|
||||||
|
|
@ -328,6 +328,20 @@ public final class RecipeUtil {
|
||||||
return getExpectedValue(uniform.min) + getExpectedValue(uniform.max) / 2.0;
|
return getExpectedValue(uniform.min) + getExpectedValue(uniform.max) / 2.0;
|
||||||
} else if (provider instanceof BinomialDistributionGenerator binomial) {
|
} else if (provider instanceof BinomialDistributionGenerator binomial) {
|
||||||
return getExpectedValue(binomial.n) * getExpectedValue(binomial.p);
|
return getExpectedValue(binomial.n) * getExpectedValue(binomial.p);
|
||||||
|
} else if (provider instanceof SummationGenerator summation) {
|
||||||
|
double avgSum = 0.0;
|
||||||
|
|
||||||
|
for (var child : summation.providers()) {
|
||||||
|
double expectedValue = getExpectedValue(child);
|
||||||
|
|
||||||
|
if (expectedValue == -1.0f) {
|
||||||
|
return -1.0f;
|
||||||
|
} else {
|
||||||
|
avgSum += expectedValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return avgSum;
|
||||||
} else {
|
} else {
|
||||||
// no way of knowing beforehand so just put them last
|
// no way of knowing beforehand so just put them last
|
||||||
return -1.0;
|
return -1.0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user