Search in sources :

Example 86 with Biome

use of net.minecraft.world.biome.Biome in project RFToolsDimensions by McJty.

the class DimensionInformation method setupFromNBT.

private void setupFromNBT(NBTTagCompound tagCompound) {
    terrainType = TerrainType.values()[tagCompound.getInteger("terrain")];
    featureTypes = toEnumSet(getIntArraySafe(tagCompound, "features"), FeatureType.values());
    structureTypes = toEnumSet(getIntArraySafe(tagCompound, "structures"), StructureType.values());
    effectTypes = toEnumSet(getIntArraySafe(tagCompound, "effects"), EffectType.values());
    biomes.clear();
    for (int a : getIntArraySafe(tagCompound, "biomes")) {
        Biome biome = Biome.getBiome(a);
        if (biome != null) {
            biomes.add(biome);
        } else {
            // Protect against deleted biomes (i.e. a mod with biomes gets removed and this dimension still uses it).
            // We will pick a replacement biome here.
            biomes.add(Biomes.PLAINS);
        }
    }
    if (tagCompound.hasKey("controller")) {
        controllerType = ControllerType.values()[tagCompound.getInteger("controller")];
    } else {
        // Support for old type.
        if (biomes.isEmpty()) {
            controllerType = ControllerType.CONTROLLER_DEFAULT;
        } else {
            controllerType = ControllerType.CONTROLLER_SINGLE;
        }
    }
    digitString = tagCompound.getString("digits");
    forcedDimensionSeed = tagCompound.getLong("forcedSeed");
    baseSeed = tagCompound.getLong("baseSeed");
    worldVersion = tagCompound.getInteger("worldVersion");
    baseBlockForTerrain = getBlockMeta(tagCompound, "baseBlock");
    tendrilBlock = getBlockMeta(tagCompound, "tendrilBlock");
    canyonBlock = getBlockMeta(tagCompound, "canyonBlock");
    fluidForTerrain = Block.REGISTRY.getObjectById(tagCompound.getInteger("fluidBlock"));
    hugeLiquidSphereFluids = readFluidsFromNBT(tagCompound, "hugeLiquidSphereFluids");
    hugeLiquidSphereBlocks = readBlockArrayFromNBT(tagCompound, "hugeLiquidSphereBlocks");
    // Support for the old format with only one liquid block.
    Block oldLiquidSphereFluid = Block.REGISTRY.getObjectById(tagCompound.getInteger("liquidSphereFluid"));
    liquidSphereFluids = readFluidsFromNBT(tagCompound, "liquidSphereFluids");
    if (liquidSphereFluids.length == 0) {
        liquidSphereFluids = new Block[] { oldLiquidSphereFluid };
    }
    // Support for the old format with only one sphere block.
    IBlockState oldLiquidSphereBlock = getBlockMeta(tagCompound, "liquidSphereBlock");
    liquidSphereBlocks = readBlockArrayFromNBT(tagCompound, "liquidSphereBlocks");
    if (liquidSphereBlocks.length == 0) {
        liquidSphereBlocks = new IBlockState[] { oldLiquidSphereBlock };
    }
    pyramidBlocks = readBlockArrayFromNBT(tagCompound, "pyramidBlocks");
    if (pyramidBlocks.length == 0) {
        pyramidBlocks = new IBlockState[] { Blocks.STONE.getDefaultState() };
    }
    // Support for the old format with only one sphere block.
    IBlockState oldSphereBlock = getBlockMeta(tagCompound, "sphereBlock");
    sphereBlocks = readBlockArrayFromNBT(tagCompound, "sphereBlocks");
    if (sphereBlocks.length == 0) {
        sphereBlocks = new IBlockState[] { oldSphereBlock };
    }
    hugeSphereBlocks = readBlockArrayFromNBT(tagCompound, "hugeSphereBlocks");
    scatteredSphereBlocks = readBlockArrayFromNBT(tagCompound, "scatteredSphereBlocks");
    extraOregen = readBlockArrayFromNBT(tagCompound, "extraOregen");
    fluidsForLakes = readFluidsFromNBT(tagCompound, "lakeFluids");
    peaceful = tagCompound.getBoolean("peaceful");
    noanimals = tagCompound.getBoolean("noanimals");
    shelter = tagCompound.getBoolean("shelter");
    respawnHere = tagCompound.getBoolean("respawnHere");
    cheater = tagCompound.getBoolean("cheater");
    if (tagCompound.hasKey("celestialAngle")) {
        celestialAngle = tagCompound.getFloat("celestialAngle");
    } else {
        celestialAngle = null;
    }
    if (tagCompound.hasKey("timeSpeed")) {
        timeSpeed = tagCompound.getFloat("timeSpeed");
    } else {
        timeSpeed = null;
    }
    probeCounter = tagCompound.getInteger("probes");
    actualRfCost = tagCompound.getInteger("actualCost");
    injectedDimlets = tagCompound.getString("injectedDimlets");
    skyDescriptor = new SkyDescriptor.Builder().fromNBT(tagCompound).build();
    calculateCelestialBodyDescriptors();
    patreon1 = tagCompound.getLong("patreon1");
    weatherDescriptor = new WeatherDescriptor.Builder().fromNBT(tagCompound).build();
    extraMobs.clear();
    NBTTagList list = tagCompound.getTagList("mobs", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < list.tagCount(); i++) {
        NBTTagCompound tc = list.getCompoundTagAt(i);
        String className = tc.getString("class");
        int chance = tc.getInteger("chance");
        int minGroup = tc.getInteger("minGroup");
        int maxGroup = tc.getInteger("maxGroup");
        int maxLoaded = tc.getInteger("maxLoaded");
        Class<? extends EntityLiving> c = null;
        try {
            c = GenericTools.castClass(Class.forName(className), EntityLiving.class);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        MobDescriptor mob = new MobDescriptor(c, chance, minGroup, maxGroup, maxLoaded);
        extraMobs.add(mob);
    }
    String ds = tagCompound.getString("dimensionTypes");
    dimensionTypes = StringUtils.split(ds, ",");
    if (dimensionTypes == null) {
        dimensionTypes = new String[0];
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EntityLiving(net.minecraft.entity.EntityLiving) Biome(net.minecraft.world.biome.Biome) Block(net.minecraft.block.Block)

Example 87 with Biome

use of net.minecraft.world.biome.Biome in project RFToolsDimensions by McJty.

the class DimletRandomizer method getRandomBiome.

public static DimletKey getRandomBiome(Random random) {
    List<ResourceLocation> keys = new ArrayList<>(Biome.REGISTRY.getKeys());
    keys.sort(null);
    int size = keys.size();
    while (true) {
        Biome biome = Biome.REGISTRY.getObject(keys.get(random.nextInt(size)));
        if (biome != null) {
            return new DimletKey(DimletType.DIMLET_BIOME, biome.biomeName);
        }
    }
}
Also used : Biome(net.minecraft.world.biome.Biome) ResourceLocation(net.minecraft.util.ResourceLocation) ArrayList(java.util.ArrayList)

Example 88 with Biome

use of net.minecraft.world.biome.Biome in project RFToolsDimensions by McJty.

the class KnownDimletConfiguration method getDisplayName.

public static String getDisplayName(DimletKey key) {
    switch(key.getType()) {
        case DIMLET_BIOME:
            Biome biome = Biome.REGISTRY.getObject(new ResourceLocation(key.getId()));
            return biome == null ? "<invalid>" : biome.biomeName;
        case DIMLET_LIQUID:
            return DimensionInformation.getDisplayName(DimletObjectMapping.getFluid(key));
        case DIMLET_MATERIAL:
            return DimensionInformation.getDisplayName(DimletObjectMapping.getBlock(key));
        case DIMLET_MOB:
            if (DimletObjectMapping.DEFAULT_ID.equals(key.getId())) {
                return key.getId();
            }
            EntityEntry entry = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(EntityTools.fixEntityId(key.getId())));
            Class<? extends Entity> entityClass = entry == null ? null : entry.getEntityClass();
            if (entityClass == null) {
                return "<Unknown>";
            }
            return EntityTools.findEntityLocNameByClass(entityClass);
        case DIMLET_SKY:
            return StringUtils.capitalize(StringUtils.join(StringUtils.split(key.getId(), '.'), ' '));
        case DIMLET_STRUCTURE:
            return key.getId();
        case DIMLET_TERRAIN:
            return key.getId();
        case DIMLET_FEATURE:
            return key.getId();
        case DIMLET_TIME:
            return key.getId();
        case DIMLET_DIGIT:
            return key.getId();
        case DIMLET_EFFECT:
            return key.getId();
        case DIMLET_SPECIAL:
            return key.getId();
        case DIMLET_CONTROLLER:
            return key.getId();
        case DIMLET_WEATHER:
            return StringUtils.capitalize(StringUtils.join(StringUtils.split(key.getId(), '.'), ' '));
        case DIMLET_PATREON:
            return key.getId();
    }
    return "Unknown";
}
Also used : EntityEntry(net.minecraftforge.fml.common.registry.EntityEntry) Biome(net.minecraft.world.biome.Biome) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 89 with Biome

use of net.minecraft.world.biome.Biome in project RFToolsDimensions by McJty.

the class BiomeControllerMapping method findSuitableBiomes.

private static int findSuitableBiomes(Biome biome, ControllerType.BiomeFilter filter) {
    double bestdist = 1000000000.0f;
    // Make sure we always have some matching biome.
    int bestidx = 0;
    for (Biome base : Biome.REGISTRY) {
        try {
            if (base != null && filter.match(base)) {
                // This 'base' could be a replacement. Check if it is close enough.
                if (biome.getBiomeClass() == base.getBiomeClass()) {
                    // Same class, that's good enough for me.
                    return Biome.getIdForBiome(base);
                }
                double dist = filter.calculateBiomeDistance(biome, base);
                if (dist < bestdist) {
                    bestdist = dist;
                    bestidx = Biome.getIdForBiome(base);
                }
            }
        } catch (RuntimeException e) {
            throw new RuntimeException("Checking suitability of biome " + base.biomeName + " (" + Biome.REGISTRY.getNameForObject(base) + ")", e);
        }
    }
    return bestidx;
}
Also used : Biome(net.minecraft.world.biome.Biome)

Example 90 with Biome

use of net.minecraft.world.biome.Biome in project RFToolsDimensions by McJty.

the class GenericChunkGenerator method populate.

@Override
public void populate(int chunkX, int chunkZ) {
    BlockFalling.fallInstantly = true;
    int x = chunkX * 16;
    int z = chunkZ * 16;
    World w = this.worldObj;
    Biome Biome = w.getBiomeForCoordsBody(new BlockPos(x + 16, 0, z + 16));
    this.rand.setSeed(w.getSeed());
    long i1 = this.rand.nextLong() / 2L * 2L + 1L;
    long j1 = this.rand.nextLong() / 2L * 2L + 1L;
    this.rand.setSeed(chunkX * i1 + chunkZ * j1 ^ w.getSeed());
    boolean flag = false;
    if (dimensionInformation.getTerrainType() == TerrainType.TERRAIN_INVERTIGO) {
        if (upsidedownWorld == null) {
            World ww = worldObj;
            // This anonymous subclass is necessary to store the capture of ww before WorldServer's constructor
            // is called, as that will call createChunkProvider which needs ww to be set.
            upsidedownWorld = new UpsidedownWorld((WorldServer) worldObj) {

                @Override
                protected IChunkProvider createChunkProvider() {
                    IChunkLoader ichunkloader = ww.getSaveHandler().getChunkLoader(ww.provider);
                    return new ChunkProviderServer((WorldServer) ww, ichunkloader, ww.provider.createChunkGenerator());
                }

                @Override
                public ChunkProviderServer getChunkProvider() {
                    return (ChunkProviderServer) ww.getChunkProvider();
                }
            };
            net.minecraftforge.common.DimensionManager.setWorld(ww.provider.getDimension(), (WorldServer) ww, ww.getMinecraftServer());
        }
        upsidedownWorld.worldObj = (WorldServer) worldObj;
        w = upsidedownWorld;
    }
    MinecraftForge.EVENT_BUS.post(new PopulateChunkEvent.Pre(this, w, rand, chunkX, chunkZ, flag));
    ChunkPos cp = new ChunkPos(chunkX, chunkZ);
    if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_MINESHAFT)) {
        this.mineshaftGenerator.generateStructure(w, this.rand, cp);
    }
    if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_VILLAGE)) {
        flag = this.villageGenerator.generateStructure(w, this.rand, cp);
    }
    if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_STRONGHOLD)) {
        this.strongholdGenerator.generateStructure(w, this.rand, cp);
    }
    if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_FORTRESS)) {
        this.genNetherBridge.generateStructure(w, this.rand, cp);
    }
    if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_SCATTERED)) {
        this.scatteredFeatureGenerator.generateStructure(w, this.rand, cp);
    }
    if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_SWAMPHUT)) {
        this.genSwampHut.generateStructure(w, this.rand, cp);
    }
    if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_DESERTTEMPLE)) {
        this.genDesertTemple.generateStructure(w, this.rand, cp);
    }
    if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_JUNGLETEMPLE)) {
        this.genJungleTemple.generateStructure(w, this.rand, cp);
    }
    if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_IGLOO)) {
        this.genIgloo.generateStructure(w, this.rand, cp);
    }
    if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_OCEAN_MONUMENT)) {
        this.oceanMonumentGenerator.generateStructure(w, this.rand, cp);
    }
    int k1;
    int l1;
    int i2;
    if (dimensionInformation.getTerrainType() != TerrainType.TERRAIN_INVERTIGO) {
        if (dimensionInformation.hasFeatureType(FeatureType.FEATURE_LAKES)) {
            if (dimensionInformation.getFluidsForLakes().length == 0) {
                // No specific liquid dimlets specified: we generate default lakes (water and lava were appropriate).
                if (Biome != Biomes.DESERT && Biome != Biomes.DESERT_HILLS && !flag && this.rand.nextInt(4) == 0 && TerrainGen.populate(this, w, rand, chunkX, chunkZ, flag, PopulateChunkEvent.Populate.EventType.LAKE)) {
                    k1 = x + this.rand.nextInt(16) + 8;
                    l1 = this.rand.nextInt(256);
                    i2 = z + this.rand.nextInt(16) + 8;
                    (new WorldGenLakes(Blocks.WATER)).generate(w, this.rand, new BlockPos(k1, l1, i2));
                }
                if (TerrainGen.populate(this, w, rand, chunkX, chunkZ, flag, PopulateChunkEvent.Populate.EventType.LAVA) && !flag && this.rand.nextInt(8) == 0) {
                    k1 = x + this.rand.nextInt(16) + 8;
                    l1 = this.rand.nextInt(this.rand.nextInt(248) + 8);
                    i2 = z + this.rand.nextInt(16) + 8;
                    if (l1 < 63 || this.rand.nextInt(10) == 0) {
                        (new WorldGenLakes(Blocks.LAVA)).generate(w, this.rand, new BlockPos(k1, l1, i2));
                    }
                }
            } else {
                // Generate lakes for the specified biomes.
                for (Block liquid : dimensionInformation.getFluidsForLakes()) {
                    if (!flag && this.rand.nextInt(4) == 0 && TerrainGen.populate(this, w, rand, chunkX, chunkZ, flag, PopulateChunkEvent.Populate.EventType.LAKE)) {
                        k1 = x + this.rand.nextInt(16) + 8;
                        l1 = this.rand.nextInt(256);
                        i2 = z + this.rand.nextInt(16) + 8;
                        (new WorldGenLakes(liquid)).generate(w, this.rand, new BlockPos(k1, l1, i2));
                    }
                }
            }
        }
    }
    boolean doGen = false;
    if (dimensionInformation.hasStructureType(StructureType.STRUCTURE_DUNGEON)) {
        doGen = TerrainGen.populate(this, w, rand, chunkX, chunkZ, flag, PopulateChunkEvent.Populate.EventType.DUNGEON);
        for (k1 = 0; doGen && k1 < 8; ++k1) {
            l1 = x + this.rand.nextInt(16) + 8;
            i2 = this.rand.nextInt(256);
            int j2 = z + this.rand.nextInt(16) + 8;
            (new WorldGenDungeons()).generate(w, this.rand, new BlockPos(l1, i2, j2));
        }
    }
    BlockPos pos = new BlockPos(x, 0, z);
    Biome.decorate(w, this.rand, pos);
    // OresAPlenty
    if (dimensionInformation.hasFeatureType(FeatureType.FEATURE_ORESAPLENTY)) {
        generateOre(w, this.rand, coalGen, OreGenEvent.GenerateMinable.EventType.COAL, pos, OresAPlentyConfiguration.coal);
        generateOre(w, this.rand, ironGen, OreGenEvent.GenerateMinable.EventType.IRON, pos, OresAPlentyConfiguration.iron);
        generateOre(w, this.rand, goldGen, OreGenEvent.GenerateMinable.EventType.GOLD, pos, OresAPlentyConfiguration.gold);
        generateOre(w, this.rand, lapisGen, OreGenEvent.GenerateMinable.EventType.LAPIS, pos, OresAPlentyConfiguration.lapis);
        generateOre(w, this.rand, diamondGen, OreGenEvent.GenerateMinable.EventType.DIAMOND, pos, OresAPlentyConfiguration.diamond);
        generateOre(w, this.rand, redstoneGen, OreGenEvent.GenerateMinable.EventType.REDSTONE, pos, OresAPlentyConfiguration.redstone);
        generateOre(w, this.rand, emeraldGen, OreGenEvent.GenerateMinable.EventType.EMERALD, pos, OresAPlentyConfiguration.emerald);
    }
    if (TerrainGen.populate(this, w, rand, chunkX, chunkZ, flag, PopulateChunkEvent.Populate.EventType.ANIMALS)) {
        WorldEntitySpawner.performWorldGenSpawning(w, Biome, x + 8, z + 8, 16, 16, this.rand);
    }
    x += 8;
    z += 8;
    doGen = TerrainGen.populate(this, w, rand, chunkX, chunkZ, flag, PopulateChunkEvent.Populate.EventType.ICE);
    for (k1 = 0; doGen && k1 < 16; ++k1) {
        for (l1 = 0; l1 < 16; ++l1) {
            i2 = w.getPrecipitationHeight(new BlockPos(x + k1, 0, z + l1)).getY();
            if (w.canBlockFreeze(new BlockPos(k1 + x, i2 - 1, l1 + z), false)) {
                w.setBlockState(new BlockPos(k1 + x, i2 - 1, l1 + z), Blocks.ICE.getDefaultState(), 2);
            }
            if (w.canSnowAt(new BlockPos(k1 + x, i2, l1 + z), true)) {
                w.setBlockState(new BlockPos(k1 + x, i2, l1 + z), Blocks.SNOW_LAYER.getDefaultState(), 2);
            }
        }
    }
    MinecraftForge.EVENT_BUS.post(new PopulateChunkEvent.Post(this, w, rand, chunkX, chunkZ, flag));
    BlockFalling.fallInstantly = false;
}
Also used : IChunkLoader(net.minecraft.world.chunk.storage.IChunkLoader) WorldServer(net.minecraft.world.WorldServer) PopulateChunkEvent(net.minecraftforge.event.terraingen.PopulateChunkEvent) World(net.minecraft.world.World) WorldGenLakes(net.minecraft.world.gen.feature.WorldGenLakes) Biome(net.minecraft.world.biome.Biome) IChunkProvider(net.minecraft.world.chunk.IChunkProvider) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos) WorldGenDungeons(net.minecraft.world.gen.feature.WorldGenDungeons)

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