Search in sources :

Example 16 with DoubleRange

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;
}
Also used : DoubleRange(com.almuradev.toolbox.util.math.DoubleRange) Biome(net.minecraft.world.biome.Biome) ResourceLocation(net.minecraft.util.ResourceLocation) FunctionPredicate(com.almuradev.content.component.predicate.FunctionPredicate) HashMap(java.util.HashMap) Map(java.util.Map) Nullable(javax.annotation.Nullable) Nullable(javax.annotation.Nullable)

Example 17 with DoubleRange

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;
}
Also used : DoubleRange(com.almuradev.toolbox.util.math.DoubleRange) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 18 with DoubleRange

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);
    }
}
Also used : DoubleRange(com.almuradev.toolbox.util.math.DoubleRange) CactusFeature(com.almuradev.content.type.cactus.CactusFeature) Random(java.util.Random) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

DoubleRange (com.almuradev.toolbox.util.math.DoubleRange)18 BlockPos (net.minecraft.util.math.BlockPos)9 Biome (net.minecraft.world.biome.Biome)8 Map (java.util.Map)7 Nullable (javax.annotation.Nullable)7 World (net.minecraft.world.World)7 FunctionPredicate (com.almuradev.content.component.predicate.FunctionPredicate)6 HashMap (java.util.HashMap)6 Random (java.util.Random)6 ResourceLocation (net.minecraft.util.ResourceLocation)5 IBlockState (net.minecraft.block.state.IBlockState)4 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 CropBlockStateDefinition (com.almuradev.content.type.block.type.crop.state.CropBlockStateDefinition)3 Growth (com.almuradev.content.type.block.type.crop.processor.growth.Growth)2 Block (net.minecraft.block.Block)2 ItemStack (net.minecraft.item.ItemStack)2 BlockLeavesAccessor (com.almuradev.almura.asm.mixin.accessors.block.BlockLeavesAccessor)1 IMixinBlockCrops (com.almuradev.almura.feature.complex.item.almanac.asm.interfaces.IMixinBlockCrops)1 ClientboundWorldPositionInformationPacket (com.almuradev.almura.feature.complex.item.almanac.network.ClientboundWorldPositionInformationPacket)1 MathUtil (com.almuradev.almura.shared.util.MathUtil)1