Search in sources :

Example 46 with Biome

use of net.minecraft.world.biome.Biome in project Almura by AlmuraDev.

the class Grass method getOrLoadAmountRequiredRangeForBiome.

@Nullable
public IntRange getOrLoadAmountRequiredRangeForBiome(final Biome biome) {
    @Nullable IntRange found = this.biomeAmountRanges.get(biome);
    if (found == null) {
        for (final Map.Entry<FunctionPredicate<Biome, ResourceLocation>, IntRange> entry : this.biomeAmountPredicates.entrySet()) {
            final FunctionPredicate<Biome, ResourceLocation> predicate = entry.getKey();
            if (predicate.test(biome)) {
                final IntRange range = entry.getValue();
                this.biomeAmountRanges.put(biome, range);
                found = range;
                break;
            }
        }
    }
    if (found == null && this.globalAmountRange != null) {
        this.biomeAmountRanges.put(biome, this.globalAmountRange);
        found = this.globalAmountRange;
    }
    return found;
}
Also used : Biome(net.minecraft.world.biome.Biome) ResourceLocation(net.minecraft.util.ResourceLocation) IntRange(com.almuradev.toolbox.util.math.IntRange) FunctionPredicate(com.almuradev.content.component.predicate.FunctionPredicate) HashMap(java.util.HashMap) Map(java.util.Map) Nullable(javax.annotation.Nullable) Nullable(javax.annotation.Nullable)

Example 47 with Biome

use of net.minecraft.world.biome.Biome in project Almura by AlmuraDev.

the class TreeFeature method generate.

@Override
public boolean generate(final World world, final Random random, final BlockPos origin, final List<LazyBlockState> requires) {
    final Biome biome = world.getBiome(origin);
    final int height = AbstractTreeFeature.height(this.height, biome, random);
    boolean canPlace = true;
    if (origin.getY() < 1 || origin.getY() + height + 1 > world.getHeight()) {
        return false;
    }
    for (int y = origin.getY(); y <= origin.getY() + 1 + height; y++) {
        int k = 1;
        if (y == origin.getY()) {
            k = 0;
        }
        if (y >= origin.getY() + 1 + height - 2) {
            k = 2;
        }
        final BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
        for (int x = origin.getX() - k; x <= origin.getX() + k && canPlace; x++) {
            for (int z = origin.getZ() - k; z <= origin.getZ() + k && canPlace; z++) {
                if (y >= 0 && y < world.getHeight()) {
                    if (!this.replaceable(world, pos.setPos(x, y, z))) {
                        canPlace = false;
                    }
                } else {
                    canPlace = false;
                }
            }
        }
    }
    if (!canPlace) {
        return false;
    }
    final BlockPos belowOrigin = origin.down();
    IBlockState state = world.getBlockState(belowOrigin);
    if (AbstractTreeFeature.canSustainPlant(state, world, belowOrigin, EnumFacing.UP, (BlockSapling) Blocks.SAPLING, requires) && origin.getY() < world.getHeight() - height - 1) {
        state.getBlock().onPlantGrow(state, world, belowOrigin, origin);
        for (int y = origin.getY() - 3 + height; y <= origin.getY() + height; y++) {
            final int yd = y - (origin.getY() + height);
            final int os = 1 - yd / 2;
            for (int x = origin.getX() - os; x <= origin.getX() + os; x++) {
                final int ox = x - origin.getX();
                for (int z = origin.getZ() - os; z <= origin.getZ() + os; z++) {
                    final int oz = z - origin.getZ();
                    if (Math.abs(ox) != os || Math.abs(oz) != os || random.nextInt(2) != 0 && yd != 0) {
                        final BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(x, y, z);
                        state = world.getBlockState(pos);
                        if (state.getBlock().isAir(state, world, pos) || state.getBlock().isLeaves(state, world, pos) || state.getMaterial() == Material.VINE) {
                            final IBlockState leavesOrFruitState = AbstractTreeFeature.leavesOrFruitBlock(this.leaves, this.fruit, biome, random);
                            this.setBlockAndNotifyAdequately(world, pos, leavesOrFruitState);
                            state = world.getBlockState(pos);
                            // Enforce hanging only hanging from a leaves or fruit
                            if (state.equals(leavesOrFruitState) && AbstractTreeFeature.shouldPlaceHanging(this.hanging, biome, random)) {
                                pos.setPos(x, y - 1, z);
                                final IBlockState underLeafOrFruitState = world.getBlockState(pos);
                                if (underLeafOrFruitState.getBlock().isAir(underLeafOrFruitState, world, pos)) {
                                    this.setBlockAndNotifyAdequately(world, pos, AbstractTreeFeature.hangingBlock(this.hanging));
                                }
                            }
                        }
                    }
                }
            }
        }
        final BlockPos.MutableBlockPos mutPos = new BlockPos.MutableBlockPos(origin);
        for (int i = 0; i < height; i++) {
            final BlockPos pos = mutPos.setPos(mutPos.getX(), origin.getY() + i, mutPos.getZ());
            state = world.getBlockState(pos);
            if (state.getBlock().isAir(state, world, pos) || state.getBlock().isLeaves(state, world, pos) || AbstractTreeFeature.hangingBlock(this.hanging).equals(state) || state.getMaterial() == Material.VINE) {
                this.setBlockAndNotifyAdequately(world, pos, this.log.get());
            }
        }
        return true;
    }
    return false;
}
Also used : Biome(net.minecraft.world.biome.Biome) IBlockState(net.minecraft.block.state.IBlockState) BlockSapling(net.minecraft.block.BlockSapling) BlockPos(net.minecraft.util.math.BlockPos)

Example 48 with Biome

use of net.minecraft.world.biome.Biome in project Almura by AlmuraDev.

the class BiomeServerFeature method getBiomeConfigs.

private Map<Integer, BiomeConfig> getBiomeConfigs() {
    final ForgeRegistry<Biome> registry = (ForgeRegistry<Biome>) ForgeRegistries.BIOMES;
    final List<Biome> values = registry.getValues();
    final Map<Integer, BiomeConfig> biomes = new HashMap<>(values.size());
    for (Biome biome : values) {
        biomes.put(registry.getID(biome), BiomeConfig.of(biome));
    }
    return biomes;
}
Also used : ForgeRegistry(net.minecraftforge.registries.ForgeRegistry) Biome(net.minecraft.world.biome.Biome) HashMap(java.util.HashMap)

Example 49 with Biome

use of net.minecraft.world.biome.Biome in project Almura by AlmuraDev.

the class MixinWorld method redirectCanSnowAt.

@Redirect(method = "isRainingAt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;canSnowAt(Lnet/minecraft/util/math/BlockPos;Z)Z"))
private boolean redirectCanSnowAt(World world, BlockPos pos, boolean checkLight) {
    final BiomeChunk biomeChunk = BiomeUtil.getChunk(pos);
    if (biomeChunk == null) {
        return world.canSnowAt(pos, checkLight);
    }
    final Biome biome = world.getBiome(pos);
    final float temperature = biomeChunk.getTemperature(pos, biome);
    return temperature < 0.15f;
}
Also used : Biome(net.minecraft.world.biome.Biome) BiomeChunk(com.almuradev.almura.feature.biome.BiomeChunk) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 50 with Biome

use of net.minecraft.world.biome.Biome in project Almura by AlmuraDev.

the class MixinBiomeColorHelper method getColorAtPos.

/**
 * @author Zidane - Chris Sanders
 * @reason Have water respect our config
 */
@Overwrite
private static int getColorAtPos(IBlockAccess blockAccess, BlockPos pos, BiomeColorHelper.ColorResolver colorResolver) {
    int i = 0;
    int j = 0;
    int k = 0;
    for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(pos.add(-1, 0, -1), pos.add(1, 0, 1))) {
        final Biome biome = blockAccess.getBiome(blockpos$mutableblockpos);
        int l;
        if (colorResolver == BiomeColorHelper.WATER_COLOR) {
            final BiomeChunk biomeChunk = BiomeUtil.getChunk(blockpos$mutableblockpos);
            if (biomeChunk == null) {
                l = colorResolver.getColorAtPos(biome, blockpos$mutableblockpos);
            } else {
                l = biomeChunk.getWaterColor(pos, biome);
            }
        } else {
            l = colorResolver.getColorAtPos(biome, blockpos$mutableblockpos);
        }
        i += (l & 16711680) >> 16;
        j += (l & 65280) >> 8;
        k += l & 255;
    }
    return (i / 9 & 255) << 16 | (j / 9 & 255) << 8 | k / 9 & 255;
}
Also used : Biome(net.minecraft.world.biome.Biome) BiomeChunk(com.almuradev.almura.feature.biome.BiomeChunk) BlockPos(net.minecraft.util.math.BlockPos) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

Biome (net.minecraft.world.biome.Biome)110 BlockPos (net.minecraft.util.math.BlockPos)39 IBlockState (net.minecraft.block.state.IBlockState)16 ResourceLocation (net.minecraft.util.ResourceLocation)9 World (net.minecraft.world.World)9 Nullable (javax.annotation.Nullable)8 Random (java.util.Random)7 ChunkPos (net.minecraft.util.math.ChunkPos)7 DoubleRange (com.almuradev.toolbox.util.math.DoubleRange)6 HashMap (java.util.HashMap)6 FunctionPredicate (com.almuradev.content.component.predicate.FunctionPredicate)5 Map (java.util.Map)5 Block (net.minecraft.block.Block)5 WorldServer (net.minecraft.world.WorldServer)5 BiomeChunk (com.almuradev.almura.feature.biome.BiomeChunk)4 Overwrite (org.spongepowered.asm.mixin.Overwrite)4 Entity (net.minecraft.entity.Entity)3 IntRange (com.almuradev.toolbox.util.math.IntRange)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2