Search in sources :

Example 6 with DoubleRange

use of com.almuradev.toolbox.util.math.DoubleRange in project Almura by AlmuraDev.

the class FlowerGeneratorImpl method decorate.

@SubscribeEvent
public void decorate(final DecorateBiomeEvent.Decorate event) {
    if (event.getType() != DecorateBiomeEvent.Decorate.EventType.FLOWERS || 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));
        ((FlowerFeature) this.flower.require()).generate(world, random, pos, this.requires);
        event.setResult(Event.Result.DENY);
    }
}
Also used : DoubleRange(com.almuradev.toolbox.util.math.DoubleRange) Random(java.util.Random) FlowerFeature(com.almuradev.content.type.flower.FlowerFeature) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 7 with DoubleRange

use of com.almuradev.toolbox.util.math.DoubleRange in project Almura by AlmuraDev.

the class GrassGeneratorImpl method decorate.

@SubscribeEvent
public void decorate(final DecorateBiomeEvent.Decorate event) {
    if (event.getType() != DecorateBiomeEvent.Decorate.EventType.GRASS || 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));
        ((GrassFeature) this.grass.require()).generate(world, random, pos, this.requires);
        event.setResult(Event.Result.DENY);
    }
}
Also used : GrassFeature(com.almuradev.content.type.grass.GrassFeature) DoubleRange(com.almuradev.toolbox.util.math.DoubleRange) Random(java.util.Random) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 8 with DoubleRange

use of com.almuradev.toolbox.util.math.DoubleRange in project Almura by AlmuraDev.

the class TreeGeneratorImpl method decorate.

@SubscribeEvent
public void decorate(final DecorateBiomeEvent.Decorate event) {
    if (event.getType() != DecorateBiomeEvent.Decorate.EventType.TREE || event.getResult() == Event.Result.DENY) {
        return;
    }
    final World world = event.getWorld();
    if (!this.in(world)) {
        return;
    }
    final DoubleRange chance = DoubleRangeFunctionPredicatePair.range(this.biomes, 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));
        this.tree(world.getBiome(pos), random).generate(world, random, pos, this.requires);
        event.setResult(Event.Result.DENY);
    }
}
Also used : DoubleRange(com.almuradev.toolbox.util.math.DoubleRange) Random(java.util.Random) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 9 with DoubleRange

use of com.almuradev.toolbox.util.math.DoubleRange in project Almura by AlmuraDev.

the class MixinBlockTallGrass method getDrops.

/**
 * @author Zidane - Chris Sanders
 * @reason Add in content seeds to drop list for Tall Grass
 */
@Overwrite(remap = false)
public void getDrops(final NonNullList<ItemStack> drops, final IBlockAccess access, final BlockPos pos, final IBlockState state, final int fortune) {
    World world;
    if (access instanceof ChunkCache) {
        world = ((ChunkCache) access).world;
    } else if (access instanceof World) {
        world = (World) access;
    } else {
        return;
    }
    final Random random = world.rand;
    // Roll 1 is Vanilla's 1/8 chance to drop a seed
    final int roll1 = random.nextInt(8);
    if (roll1 == 0) {
        // Forge Start - Lookup seed each time and then do random check. Almura handles its own chance code
        final ItemStack modSeed = net.minecraftforge.common.ForgeHooks.getGrassSeed(random, fortune);
        if (!modSeed.isEmpty()) {
            drops.add(modSeed);
            // Don't double up with Vanilla/mod drops
            return;
        }
        final Biome biome = world.getBiome(pos);
        // Roll 2 is shuffling Almura seeds and picking the first one after shuffling
        registry.getAllOf(ItemType.class).stream().filter(itemType -> itemType instanceof SeedItem && ((SeedItem) itemType).getGrass() != null).collect(Collectors.collectingAndThen(Collectors.toList(), collected -> {
            Collections.shuffle(collected);
            return collected.stream();
        })).findFirst().ifPresent((itemType) -> {
            final SeedItem seed = (SeedItem) itemType;
            final IntRange amountRange = seed.getGrass().getOrLoadAmountRequiredRangeForBiome(biome);
            if (amountRange != null) {
                final int stackSize = amountRange.random(random);
                final DoubleRange chanceRange = seed.getGrass().getOrLoadChanceRangeForBiome(biome);
                if (chanceRange != null) {
                    final double chance = chanceRange.random(random);
                    // Roll 3 is allowing the seed configuration to determine the chance for the drop
                    if (random.nextDouble() <= (chance / 100)) {
                        drops.add((ItemStack) (Object) org.spongepowered.api.item.inventory.ItemStack.of(itemType, stackSize));
                    }
                } else {
                    drops.add((ItemStack) (Object) org.spongepowered.api.item.inventory.ItemStack.of(itemType, stackSize));
                }
            }
        });
    }
// Almura End
}
Also used : ChunkCache(net.minecraft.world.ChunkCache) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) Random(java.util.Random) Overwrite(org.spongepowered.asm.mixin.Overwrite) SeedItem(com.almuradev.content.type.item.type.seed.SeedItem) BlockTallGrass(net.minecraft.block.BlockTallGrass) Collectors(java.util.stream.Collectors) GameRegistry(org.spongepowered.api.GameRegistry) Inject(javax.inject.Inject) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) Mixin(org.spongepowered.asm.mixin.Mixin) MixinBlock(com.almuradev.content.type.block.mixin.impl.MixinBlock) DoubleRange(com.almuradev.toolbox.util.math.DoubleRange) NonNullList(net.minecraft.util.NonNullList) ItemType(org.spongepowered.api.item.ItemType) Collections(java.util.Collections) IntRange(com.almuradev.toolbox.util.math.IntRange) IBlockAccess(net.minecraft.world.IBlockAccess) Biome(net.minecraft.world.biome.Biome) ChunkCache(net.minecraft.world.ChunkCache) ItemType(org.spongepowered.api.item.ItemType) IntRange(com.almuradev.toolbox.util.math.IntRange) World(net.minecraft.world.World) SeedItem(com.almuradev.content.type.item.type.seed.SeedItem) DoubleRange(com.almuradev.toolbox.util.math.DoubleRange) Biome(net.minecraft.world.biome.Biome) Random(java.util.Random) ItemStack(net.minecraft.item.ItemStack) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 10 with DoubleRange

use of com.almuradev.toolbox.util.math.DoubleRange in project Almura by AlmuraDev.

the class Grass method getOrLoadChanceRangeForBiome.

@Nullable
public DoubleRange getOrLoadChanceRangeForBiome(final Biome biome) {
    @Nullable DoubleRange found = this.biomeChanceRanges.get(biome);
    if (found == null) {
        for (final Map.Entry<FunctionPredicate<Biome, ResourceLocation>, DoubleRange> entry : this.biomeChancePredicates.entrySet()) {
            final FunctionPredicate<Biome, ResourceLocation> predicate = entry.getKey();
            if (predicate.test(biome)) {
                final DoubleRange range = entry.getValue();
                this.biomeChanceRanges.put(biome, range);
                found = range;
                break;
            }
        }
    }
    if (found == null && this.globalChanceRange != null) {
        this.biomeChanceRanges.put(biome, this.globalChanceRange);
        found = this.globalChanceRange;
    }
    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)

Aggregations

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