Search in sources :

Example 11 with ChunkPos

use of net.minecraft.util.math.ChunkPos in project RecurrentComplex by Ivorforce.

the class RCBiomeDecorator method doDecorate.

protected static int doDecorate(WorldServer worldIn, Random random, BlockPos blockPos, DecorationType type, int amount, boolean lowChance) {
    ChunkPos chunkPos = new ChunkPos(blockPos);
    double baseWeight = RCConfig.baseDecorationWeights.get(type);
    if (baseWeight <= 0)
        return amount;
    Biome biomeIn = worldIn.getBiome(chunkPos.getBlock(16, 0, 16));
    StructureSelector<VanillaDecorationGeneration, DecorationType> selector = StructureRegistry.INSTANCE.decorationSelectors().get(biomeIn, worldIn.provider);
    double totalWeight = selector.totalWeight(type);
    if (totalWeight <= 0)
        return amount;
    return trySurface(worldIn, random, chunkPos, selector, type, totalWeight, baseWeight, amount, lowChance);
}
Also used : Biome(net.minecraft.world.biome.Biome) VanillaDecorationGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.VanillaDecorationGeneration) ChunkPos(net.minecraft.util.math.ChunkPos)

Example 12 with ChunkPos

use of net.minecraft.util.math.ChunkPos in project BetterWithAddons by DaedalusGame.

the class TerratorialData method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound nbt) {
    NBTTagList territorylist = nbt.getTagList("territoryChunks", 10);
    NBTTagList chunks = nbt.getTagList("territoryChunks", 10);
    for (int i = 0; i < territorylist.tagCount(); i++) {
        NBTTagCompound territorycompound = territorylist.getCompoundTagAt(i);
        int territoryid = territorycompound.getInteger("id");
        String typeid = territorycompound.getString("type");
        ItemStack bannerstack = new ItemStack(territorycompound.getCompoundTag("banner"));
        if (MobTerritoryType.typeList.containsKey(typeid)) {
            MobTerritory territory = new MobTerritory(territoryid, MobTerritoryType.typeList.get(typeid));
            territory.setBanner(bannerstack);
            territories.put(territoryid, territory);
        }
        currentMaxID = Math.max(currentMaxID, territoryid);
    }
    currentMaxID++;
    for (int i = 0; i < chunks.tagCount(); i++) {
        NBTTagCompound chunkcompound = chunks.getCompoundTagAt(i);
        ChunkPos chunkpos = new ChunkPos(chunkcompound.getInteger("chunkX"), chunkcompound.getInteger("chunkZ"));
        int territoryid = chunkcompound.getInteger("id");
        if (territories.containsKey(territoryid))
            territoryChunks.put(chunkpos, territories.get(territoryid));
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ChunkPos(net.minecraft.util.math.ChunkPos) ItemStack(net.minecraft.item.ItemStack)

Example 13 with ChunkPos

use of net.minecraft.util.math.ChunkPos in project MinecraftForge by MinecraftForge.

the class ForgeChunkManager method releaseTicket.

/**
     * Release the ticket back to the system. This will also unforce any chunks held by the ticket so that they can be unloaded and/or stop ticking.
     *
     * @param ticket The ticket to release
     */
public static void releaseTicket(Ticket ticket) {
    if (ticket == null) {
        return;
    }
    if (ticket.isPlayerTicket() ? !playerTickets.containsValue(ticket) : !tickets.get(ticket.world).containsEntry(ticket.modId, ticket)) {
        return;
    }
    if (ticket.requestedChunks != null) {
        for (ChunkPos chunk : ImmutableSet.copyOf(ticket.requestedChunks)) {
            unforceChunk(ticket, chunk);
        }
    }
    if (ticket.isPlayerTicket()) {
        playerTickets.remove(ticket.player, ticket);
        tickets.get(ticket.world).remove(ForgeVersion.MOD_ID, ticket);
    } else {
        tickets.get(ticket.world).remove(ticket.modId, ticket);
    }
}
Also used : ChunkPos(net.minecraft.util.math.ChunkPos)

Example 14 with ChunkPos

use of net.minecraft.util.math.ChunkPos in project MinecraftForge by MinecraftForge.

the class ForgeChunkManager method forceChunk.

/**
     * Force the supplied chunk coordinate to be loaded by the supplied ticket. If the ticket's {@link Ticket#maxDepth} is exceeded, the least
     * recently registered chunk is unforced and may be unloaded.
     * It is safe to force the chunk several times for a ticket, it will not generate duplication or change the ordering.
     *
     * @param ticket The ticket registering the chunk
     * @param chunk The chunk to force
     */
public static void forceChunk(Ticket ticket, ChunkPos chunk) {
    if (ticket == null || chunk == null) {
        return;
    }
    if (ticket.ticketType == Type.ENTITY && ticket.entity == null) {
        throw new RuntimeException("Attempted to use an entity ticket to force a chunk, without an entity");
    }
    if (ticket.isPlayerTicket() ? !playerTickets.containsValue(ticket) : !tickets.get(ticket.world).containsEntry(ticket.modId, ticket)) {
        FMLLog.severe("The mod %s attempted to force load a chunk with an invalid ticket. This is not permitted.", ticket.modId);
        return;
    }
    ticket.requestedChunks.add(chunk);
    MinecraftForge.EVENT_BUS.post(new ForceChunkEvent(ticket, chunk));
    ImmutableSetMultimap<ChunkPos, Ticket> newMap = ImmutableSetMultimap.<ChunkPos, Ticket>builder().putAll(forcedChunks.get(ticket.world)).put(chunk, ticket).build();
    forcedChunks.put(ticket.world, newMap);
    if (ticket.maxDepth > 0 && ticket.requestedChunks.size() > ticket.maxDepth) {
        ChunkPos removed = ticket.requestedChunks.iterator().next();
        unforceChunk(ticket, removed);
    }
}
Also used : ChunkPos(net.minecraft.util.math.ChunkPos)

Example 15 with ChunkPos

use of net.minecraft.util.math.ChunkPos 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;
            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

ChunkPos (net.minecraft.util.math.ChunkPos)33 BlockPos (net.minecraft.util.math.BlockPos)8 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 NBTTagList (net.minecraft.nbt.NBTTagList)6 Random (java.util.Random)4 WorldServer (net.minecraft.world.WorldServer)4 Biome (net.minecraft.world.biome.Biome)4 Structure (ivorius.reccomplex.world.gen.feature.structure.Structure)3 StructureSpawnContext (ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext)2 NaturalGeneration (ivorius.reccomplex.world.gen.feature.structure.generic.generation.NaturalGeneration)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 World (net.minecraft.world.World)2 IChunkProvider (net.minecraft.world.chunk.IChunkProvider)2 BlockWorldScale (betterwithaddons.block.BlockWorldScale)1 BlockSurfaceArea (ivorius.ivtoolkit.blocks.BlockSurfaceArea)1 BlockSurfacePos (ivorius.ivtoolkit.blocks.BlockSurfacePos)1 IvVecMathHelper (ivorius.ivtoolkit.math.IvVecMathHelper)1 RCConfig (ivorius.reccomplex.RCConfig)1