use of com.almuradev.toolbox.util.math.DoubleRange in project Almura by AlmuraDev.
the class DropParserImpl method parse.
@Override
public List<? extends Drop> parse(final ConfigurationNode config) {
if (config.isVirtual()) {
return Collections.emptyList();
}
// Assume item if drop is a string
if (config.getValue() instanceof String) {
return parseSimpleItem(config).map(Collections::singletonList).orElse(Collections.emptyList());
}
final List<? extends ConfigurationNode> children = config.getChildrenList();
final List<Drop> drops = new ArrayList<>(children.size());
for (final ConfigurationNode child : children) {
if (child.getValue() instanceof String) {
parseSimpleItem(child).ifPresent(drops::add);
} else if (child.getValue() instanceof Map) {
final DoubleRange amount = DoubleRanges.deserialize(child.getNode(Config.AMOUNT), DoubleRanges.FIXED_1);
@Nullable final DoubleRange bonusAmount = DoubleRanges.deserialize(child.getNode(Config.BONUS, Config.BONUS_AMOUNT)).orElse(null);
@Nullable final DoubleRange bonusChance = DoubleRanges.deserialize(child.getNode(Config.BONUS, Config.BONUS_CHANCE)).orElse(null);
final ConfigurationNode item = child.getNode(ItemDefinitionConfig.ITEM);
if (!item.isVirtual()) {
parseFullItem(item).map(itemDef -> itemDef.asDrop(amount, bonusAmount, bonusChance)).ifPresent(drops::add);
} else if (!child.getNode(ExperienceDrop.EXPERIENCE).isVirtual()) {
drops.add(new ExperienceDrop(amount, bonusAmount, bonusChance));
}
}
}
return drops;
}
use of com.almuradev.toolbox.util.math.DoubleRange in project Almura by AlmuraDev.
the class IngameFarmersAlmanac method loadProperties.
@SuppressWarnings("unchecked")
private void loadProperties(World world, IBlockState blockState, BlockPos blockPos) {
final Hydration hydration = getHydrationDefinition(blockState).orElse(null);
if (hydration != null) {
this.addLineLabel(Text.of(TextColors.WHITE, "Hydrated by:"));
hydration.blockStates().forEach(bs -> {
this.addLineLabel(Text.of(TextColors.WHITE, "- ", bs.block().getLocalizedName()), 2, false);
bs.properties().forEach(property -> bs.value(property).ifPresent(stateValue -> {
final String formattedValue;
if (stateValue instanceof RangeStateValue) {
final RangeStateValue rangeStateValue = (RangeStateValue) stateValue;
formattedValue = numberFormat.format(rangeStateValue.min()) + "-" + numberFormat.format(rangeStateValue.max());
} else {
final Comparable rawValue = stateValue.get((IProperty) property);
formattedValue = rawValue == null ? "" : rawValue.toString();
}
this.addLineLabel(this.getGenericPropertyText("- " + property.getName(), formattedValue), 6, false);
}));
});
this.addLineLabel(this.getGenericPropertyText("Hydration Radius", String.valueOf(hydration.getMaxRadius())));
}
// Growth stage
getGrowthStage(blockState).ifPresent(growthStage -> this.addLineLabel(this.getGenericPropertyText("Growth Stage", String.format("%d of %d", growthStage.getFirst(), growthStage.getSecond()))));
// Ground moisture
final int moistureLevel = getMoistureLevel(blockState);
final boolean isFertile = moistureLevel > 0;
final TextColor fertileColor = isFertile ? TextColors.DARK_GREEN : TextColors.RED;
this.addLineLabel(Text.of(TextColors.WHITE, "Moisture: ", fertileColor, isFertile ? "Fertile" : "Too dry"));
// Ground temperature
final DoubleRange temperatureRange = getTemperatureRange(world, blockState, blockPos).orElse(null);
if (temperatureRange != null) {
this.addLineLabel(Text.of(TextColors.WHITE, "Ground Temperature: ", (temperatureRange.min() == -1 || temperatureRange.max() == -1) ? TextColors.RED : TextColors.DARK_GREEN, numberFormat.format(message.biomeTemperature)));
this.addLineLabel(this.getGenericPropertyText("Required", String.format("%s-%s", numberFormat.format(temperatureRange.min()), numberFormat.format(temperatureRange.max()))), 2, false);
}
// Biome rain
this.addLineLabel(Text.of(TextColors.WHITE, "Rain: ", message.biomeRainfall > 0.4 ? TextColors.DARK_GREEN : TextColors.RED, numberFormat.format(message.biomeRainfall)));
// Sunlight value
final int sunlight = world.getLightFor(EnumSkyBlock.SKY, blockPos) - world.getSkylightSubtracted();
this.addLineLabel(this.getGenericPropertyText("Sunlight", String.valueOf(sunlight)));
// Area light value
final DoubleRange lightRange = getLightRange(world, blockState, blockPos).orElse(null);
if (lightRange != null) {
final int lightValue = world.getLightFor(EnumSkyBlock.SKY, blockPos);
final TextColor valueColor = lightValue < 6 ? (sunlight < 6 ? TextColors.RED : TextColors.YELLOW) : TextColors.DARK_GREEN;
this.addLineLabel(Text.of(TextColors.WHITE, "Area light: ", valueColor, String.valueOf(lightValue)));
this.addLineLabel(this.getGenericPropertyText("Required", String.format("%s-%s", numberFormat.format(lightRange.min()), numberFormat.format(lightRange.max()))), 2, false);
}
// Can Die
this.addLineLabel(this.getGenericPropertyText("Can Die", String.valueOf(canRollback(blockState))));
// Harvest Tool
final String harvestTool = blockState.getBlock().getHarvestTool(blockState);
if (harvestTool != null && !harvestTool.isEmpty()) {
addLineLabel(this.getGenericPropertyText("Harvested by", harvestTool));
}
}
use of com.almuradev.toolbox.util.math.DoubleRange in project Almura by AlmuraDev.
the class Growth method getOrLoadLightRangeForBiome.
@Nullable
public DoubleRange getOrLoadLightRangeForBiome(final Biome biome) {
@Nullable DoubleRange found = this.biomeLightRanges.get(biome);
if (found == null) {
for (final Map.Entry<FunctionPredicate<Biome, ResourceLocation>, DoubleRange> entry : this.biomeLightPredicates.entrySet()) {
final FunctionPredicate<Biome, ResourceLocation> predicate = entry.getKey();
if (predicate.test(biome)) {
final DoubleRange range = entry.getValue();
this.biomeLightRanges.put(biome, range);
found = range;
break;
}
}
}
if (found == null && this.globalLightRange != null) {
this.biomeLightRanges.put(biome, this.globalLightRange);
found = this.globalLightRange;
}
return found;
}
use of com.almuradev.toolbox.util.math.DoubleRange in project Almura by AlmuraDev.
the class CactusGeneratorImpl method decorate.
@SubscribeEvent
public void decorate(final DecorateBiomeEvent.Decorate event) {
if (event.getType() != DecorateBiomeEvent.Decorate.EventType.CACTUS || event.getResult() == Event.Result.DENY) {
return;
}
final World world = event.getWorld();
if (!this.in(world)) {
return;
}
final DoubleRange chance = this.chance(world.getBiome(event.getPos()));
if (chance == null || chance.max() == 0) {
return;
}
final Random random = event.getRand();
if (random.nextDouble() <= (chance.random(random) / 100d)) {
final int x = random.nextInt(16) + 8;
final int z = random.nextInt(16) + 8;
final BlockPos pos = world.getHeight(event.getPos().add(x, 0, z));
((CactusFeature) this.cactus.require()).generate(world, random, pos, this.requires);
event.setResult(Event.Result.DENY);
}
}
Aggregations