Search in sources :

Example 16 with ChunkPos

use of net.minecraft.util.math.ChunkPos in project MorePlanets by SteveKunG.

the class MapGenNibiruStronghold method generatePositions.

private void generatePositions() {
    this.initializeStructureData(this.world);
    int i = 0;
    for (StructureStart structurestart : this.structureMap.values()) {
        if (i < this.structureCoords.length) {
            this.structureCoords[i++] = new ChunkPos(structurestart.getChunkPosX(), structurestart.getChunkPosZ());
        }
    }
    Random rand = new Random();
    rand.setSeed(this.world.getSeed());
    double d1 = rand.nextDouble() * Math.PI * 2.0D;
    int j = 0;
    int k = 0;
    int l = this.structureMap.size();
    if (l < this.structureCoords.length) {
        for (int i1 = 0; i1 < this.structureCoords.length; ++i1) {
            double d0 = 4.0D * this.distance + this.distance * j * 6.0D + (rand.nextDouble() - 0.5D) * this.distance * 2.5D;
            int j1 = (int) Math.round(Math.cos(d1) * d0);
            int k1 = (int) Math.round(Math.sin(d1) * d0);
            BlockPos blockpos = this.world.getBiomeProvider().findBiomePosition((j1 << 4) + 8, (k1 << 4) + 8, 112, this.allowedBiomes, rand);
            if (blockpos != null) {
                j1 = blockpos.getX() >> 4;
                k1 = blockpos.getZ() >> 4;
            }
            if (i1 >= l) {
                this.structureCoords[i1] = new ChunkPos(j1, k1);
            }
            d1 += Math.PI * 2D / this.spread;
            ++k;
            if (k == this.spread) {
                ++j;
                k = 0;
                this.spread += 2 * this.spread / (j + 1);
                this.spread = Math.min(this.spread, this.structureCoords.length - i1);
                d1 += rand.nextDouble() * Math.PI * 2.0D;
            }
        }
    }
}
Also used : Random(java.util.Random) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) StructureStart(net.minecraft.world.gen.structure.StructureStart)

Example 17 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 18 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 19 with ChunkPos

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

the class TileWorldspike method setTicket.

public void setTicket(@Nullable Ticket t) {
    boolean changed = false;
    Ticket ticket = getTicket();
    if (ticket != t) {
        if (ticket != null) {
            if (ticket.world == worldObj) {
                for (ChunkPos chunk : ticket.getChunkList()) {
                    if (ForgeChunkManager.getPersistentChunksFor(worldObj).keys().contains(chunk))
                        ForgeChunkManager.unforceChunk(ticket, chunk);
                }
                ForgeChunkManager.releaseTicket(ticket);
            }
            tickets.remove(getUUID());
        }
        changed = true;
    }
    hasTicket = t != null;
    if (hasTicket)
        tickets.put(getUUID(), t);
    if (changed)
        sendUpdateToClient();
}
Also used : Ticket(net.minecraftforge.common.ForgeChunkManager.Ticket) ChunkPos(net.minecraft.util.math.ChunkPos)

Example 20 with ChunkPos

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

the class ChunkManager method getChunksBetween.

/**
     * Returns a Set of ChunkCoordIntPair containing the chunks between the
     * start and end chunks.
     * <p/>
     * One of the pairs of start/end coords need to be equal.
     * <p/>
     * Coordinates are in chunk coordinates, not world coordinates.
     *
     * @param xChunkA Start Chunk x-Coord
     * @param zChunkA Start Chunk z-Coord
     * @param xChunkB End Chunk x-Coord
     * @param zChunkB End Chunk z-Coord
     * @param max     Max number of chunks to return
     * @return A set of chunks.
     */
public Set<ChunkPos> getChunksBetween(int xChunkA, int zChunkA, int xChunkB, int zChunkB, int max) {
    Set<ChunkPos> chunkList = new HashSet<ChunkPos>();
    if (xChunkA != xChunkB && zChunkA != zChunkB) {
        return chunkList;
    }
    int xStart = Math.min(xChunkA, xChunkB);
    int xEnd = Math.max(xChunkA, xChunkB);
    int zStart = Math.min(zChunkA, zChunkB);
    int zEnd = Math.max(zChunkA, zChunkB);
    for (int xx = xStart; xx <= xEnd; xx++) {
        for (int zz = zStart; zz <= zEnd; zz++) {
            chunkList.add(new ChunkPos(xx, zz));
            if (chunkList.size() >= max) {
                return chunkList;
            }
        }
    }
    return chunkList;
}
Also used : ChunkPos(net.minecraft.util.math.ChunkPos) HashSet(java.util.HashSet)

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