Search in sources :

Example 31 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;
            // 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)

Example 32 with ChunkPos

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

the class TerratorialData method writeToNBT.

@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
    NBTTagList territorylist = new NBTTagList();
    NBTTagList chunklist = new NBTTagList();
    ArrayList<MobTerritory> hasNoTerritory = new ArrayList<MobTerritory>(territories.values());
    for (Map.Entry<ChunkPos, MobTerritory> entry : territoryChunks.entrySet()) {
        NBTTagCompound chunkcompound = new NBTTagCompound();
        ChunkPos chunkpos = entry.getKey();
        MobTerritory territory = entry.getValue();
        chunkcompound.setInteger("chunkX", chunkpos.x);
        chunkcompound.setInteger("chunkZ", chunkpos.z);
        chunkcompound.setInteger("territoryid", territory.getId());
        territorylist.appendTag(chunkcompound);
        if (hasNoTerritory.contains(territory))
            hasNoTerritory.remove(territory);
    }
    for (Map.Entry<Integer, MobTerritory> entry : territories.entrySet()) {
        MobTerritory territory = entry.getValue();
        if (hasNoTerritory.contains(territory))
            continue;
        NBTTagCompound territorycompound = new NBTTagCompound();
        territorycompound.setInteger("id", territory.getId());
        territorycompound.setString("type", territory.getTerritoryType().getIdentifier());
        territorycompound.setTag("banner", territory.getBanner().serializeNBT());
        territorylist.appendTag(territorycompound);
    }
    nbt.setTag("territoryChunks", chunklist);
    nbt.setTag("territories", territorylist);
    return nbt;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ChunkPos(net.minecraft.util.math.ChunkPos) Map(java.util.Map) HashMap(java.util.HashMap)

Example 33 with ChunkPos

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

the class WorldScaleData method writeToNBT.

@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
    NBTTagList shardlist = new NBTTagList();
    for (Map.Entry<ChunkPos, BlockPos> entry : WorldScales.entrySet()) {
        NBTTagCompound shardcompound = new NBTTagCompound();
        ChunkPos chunkpos = entry.getKey();
        BlockPos shardpos = entry.getValue();
        shardcompound.setInteger("chunkX", chunkpos.x);
        shardcompound.setInteger("chunkZ", chunkpos.z);
        shardcompound.setInteger("blockX", shardpos.getX());
        shardcompound.setInteger("blockY", shardpos.getY());
        shardcompound.setInteger("blockZ", shardpos.getZ());
        shardlist.appendTag(shardcompound);
    }
    nbt.setTag("worldShards", shardlist);
    return nbt;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) Map(java.util.Map) HashMap(java.util.HashMap)

Example 34 with ChunkPos

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

the class TileEntityWorldScaleActive method update.

@Override
public void update() {
    // if (!this.worldObj.isRemote)
    // {
    BlockPos pos = this.getPos();
    if (!oldPos.equals(pos)) {
        unclaimAllChunks();
        claimAllChunks();
        setOldPos();
    }
    if (updateTick++ > UPDATE_TICKRATE) {
        ChunkPos chunkpos = new ChunkPos(pos);
        claimChunk(chunkpos);
        for (int z = -MAX_RANGE; z <= MAX_RANGE; z++) for (int x = -MAX_RANGE; x <= MAX_RANGE; x++) {
            if (z == x && x == 0)
                continue;
            BlockPos newpos = pos.add(x, 0, z);
            if (!world.isBlockLoaded(newpos))
                continue;
            IBlockState blockstate = world.getBlockState(newpos);
            ChunkPos newchunk = new ChunkPos(chunkpos.x + x, chunkpos.z + z);
            Block block = blockstate.getBlock();
            if (block instanceof BlockWorldScale) {
                boolean claimed = claimChunk(newchunk);
                if (!world.isRemote)
                    ((BlockWorldScale) block).setCracked(world, newpos, blockstate, !claimed);
            } else {
                unclaimChunk(newchunk);
            }
        }
        updateTick = 0;
    }
// }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos) BlockWorldScale(betterwithaddons.block.BlockWorldScale)

Example 35 with ChunkPos

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

the class TileEntityWorldScaleActive method writeDataToNBT.

@Override
public void writeDataToNBT(NBTTagCompound compound) {
    NBTTagList shardlist = new NBTTagList();
    for (ChunkPos chunkpos : claimedChunks) {
        NBTTagCompound shardcompound = new NBTTagCompound();
        shardcompound.setInteger("chunkX", chunkpos.x);
        shardcompound.setInteger("chunkZ", chunkpos.z);
        shardlist.appendTag(shardcompound);
    }
    compound.setTag("claimedChunks", shardlist);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ChunkPos(net.minecraft.util.math.ChunkPos)

Aggregations

ChunkPos (net.minecraft.util.math.ChunkPos)41 BlockPos (net.minecraft.util.math.BlockPos)15 Biome (net.minecraft.world.biome.Biome)7 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 NBTTagList (net.minecraft.nbt.NBTTagList)6 Random (java.util.Random)5 WorldServer (net.minecraft.world.WorldServer)5 Structure (ivorius.reccomplex.world.gen.feature.structure.Structure)3 World (net.minecraft.world.World)3 WorldGenLiquidLakes (stevekung.mods.moreplanets.util.world.gen.feature.WorldGenLiquidLakes)3 WorldGenSpaceDungeons (stevekung.mods.moreplanets.util.world.gen.feature.WorldGenSpaceDungeons)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 ItemStack (net.minecraft.item.ItemStack)2 SPacketEntityEffect (net.minecraft.network.play.server.SPacketEntityEffect)2 SPacketRespawn (net.minecraft.network.play.server.SPacketRespawn)2 SPacketSetExperience (net.minecraft.network.play.server.SPacketSetExperience)2