Search in sources :

Example 21 with ChunkPos

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

the class EntityCartWorldspike method forceChunkLoading.

public void forceChunkLoading(int xChunk, int zChunk) {
    if (ticket == null)
        return;
    setupChunks(xChunk, zChunk);
    Set<ChunkPos> innerChunks = ChunkManager.getInstance().getChunksAround(xChunk, zChunk, 1);
    //        System.out.println("Chunks Loaded = " + Arrays.toString(chunks.toArray()));
    for (ChunkPos chunk : chunks) {
        ForgeChunkManager.forceChunk(ticket, chunk);
        ForgeChunkManager.reorderChunk(ticket, chunk);
    }
    for (ChunkPos chunk : innerChunks) {
        ForgeChunkManager.forceChunk(ticket, chunk);
        ForgeChunkManager.reorderChunk(ticket, chunk);
    }
    ChunkPos myChunk = new ChunkPos(xChunk, zChunk);
    ForgeChunkManager.forceChunk(ticket, myChunk);
    ForgeChunkManager.reorderChunk(ticket, myChunk);
}
Also used : ChunkPos(net.minecraft.util.math.ChunkPos)

Example 22 with ChunkPos

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

the class CommandDecorate method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    BlockSurfaceArea area = new BlockSurfaceArea(parameters.iv().surfacePos(commandSender.getPosition(), false).require(), parameters.iv().move(2).surfacePos(commandSender.getPosition(), false).require());
    BlockSurfaceArea chunkArea = new BlockSurfaceArea(getChunkPos(area.getPoint1()), getChunkPos(area.getPoint2()));
    Predicate<Structure> structurePredicate = parameters.rc("exp").structurePredicate().optional().orElse(structureInfo -> true);
    WorldServer world = (WorldServer) commandSender.getEntityWorld();
    chunkArea.forEach(coord -> WorldGenStructures.decorate(world, world.rand, new ChunkPos(coord.x, coord.z), structurePredicate));
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) BlockSurfaceArea(ivorius.ivtoolkit.blocks.BlockSurfaceArea) WorldServer(net.minecraft.world.WorldServer) ChunkPos(net.minecraft.util.math.ChunkPos) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure)

Example 23 with ChunkPos

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

the class StructureGenerator method generate.

/**
     * @return null when creation failed, empty when no entry was created and an entry when there was
     */
public Optional<WorldStructureGenerationData.StructureEntry> generate() {
    Optional<S> optionalInstanceData = instanceData();
    if (!optionalInstanceData.isPresent())
        return failGenerate("failed to place");
    S instanceData = optionalInstanceData.get();
    StructureSpawnContext spawn = spawn().get();
    Structure<S> structure = structure();
    String structureID = structureID();
    boolean firstTime = spawn.generateMaturity.isFirstTime();
    WorldServer world = spawn.environment.world;
    StructureBoundingBox boundingBox = spawn.boundingBox;
    if (maturity().isSuggest() && (boundingBox.minY < MIN_DIST_TO_LIMIT || boundingBox.maxY > world.getHeight() - 1 - MIN_DIST_TO_LIMIT || (RCConfig.avoidOverlappingGeneration && !allowOverlaps && !WorldStructureGenerationData.get(world).entriesAt(boundingBox).noneMatch(WorldStructureGenerationData.Entry::blocking)) || RCEventBus.INSTANCE.post(new StructureGenerationEvent.Suggest(structure, spawn)) || (structureID != null && MinecraftForge.EVENT_BUS.post(new StructureGenerationEventLite.Suggest(world, structureID, boundingBox, spawn.generationLayer, firstTime)))))
        return failGenerate("unknown reason");
    if (firstTime) {
        RCEventBus.INSTANCE.post(new StructureGenerationEvent.Pre(structure, spawn));
        if (structureID != null)
            MinecraftForge.EVENT_BUS.post(new StructureGenerationEventLite.Pre(world, structureID, boundingBox, spawn.generationLayer, firstTime));
    }
    structure.generate(spawn, instanceData, RCConfig.getUniversalTransformer());
    if (!firstTime)
        return Optional.empty();
    RecurrentComplex.logger.trace(String.format("Generated structure '%s' in %s (%d)", name(structureID), boundingBox, world.provider.getDimension()));
    RCEventBus.INSTANCE.post(new StructureGenerationEvent.Post(structure, spawn));
    if (structureID != null)
        MinecraftForge.EVENT_BUS.post(new StructureGenerationEventLite.Post(world, structureID, boundingBox, spawn.generationLayer, firstTime));
    if (structureID == null || !memorize)
        return Optional.empty();
    String generationInfoID = generationType != null ? generationType.id() : null;
    WorldStructureGenerationData.StructureEntry structureEntry = WorldStructureGenerationData.StructureEntry.complete(structureID, generationInfoID, boundingBox, spawn.transform, !partially);
    structureEntry.blocking = structure.isBlocking();
    // Been there done that
    structureEntry.firstTime = false;
    structureEntry.seed = seed();
    try {
        structureEntry.instanceData = instanceData.writeToNBT();
    } catch (Exception e) {
        RecurrentComplex.logger.error(String.format("Error saving instance data for structure %s in %s", structure, boundingBox), e);
    }
    Collection<ChunkPos> existingChunks = WorldStructureGenerationData.get(world).addEntry(structureEntry).stream().collect(Collectors.toList());
    // Complement in all chunks that already exist
    if (partially) {
        maturity(StructureSpawnContext.GenerateMaturity.COMPLEMENT);
        StructureBoundingBox oldBB = this.generationBB;
        for (ChunkPos existingChunk : existingChunks) {
            generationBB(Structures.chunkBoundingBox(existingChunk));
            structure.generate(spawn().get(), instanceData, RCConfig.getUniversalTransformer());
        }
        generationBB(oldBB);
    }
    return Optional.of(structureEntry);
}
Also used : StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) StructureGenerationEvent(ivorius.reccomplex.events.StructureGenerationEvent) WorldServer(net.minecraft.world.WorldServer) ChunkPos(net.minecraft.util.math.ChunkPos) StructureSpawnContext(ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext)

Example 24 with ChunkPos

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

the class GenerationSanityChecker method init.

public static void init() {
    FAILED_DIMENSIONS.clear();
    // Sanity check for chunk population
    GameRegistry.registerWorldGenerator((Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) -> {
        ChunkPos pos = new ChunkPos(chunkX, chunkZ);
        if (!WorldStructureGenerationData.get(world).checkChunk(pos))
            return;
        if (FAILED_DIMENSIONS.add(world.provider.getDimension()))
            RecurrentComplex.logger.error(String.format("Chunk finished generating without Forge population being triggered (dimension %d). This is a bug with the dimension - please report this to the dimension's author. Recurrent Complex will proceed to generate in compatibility mode.", world.provider.getDimension()));
        WorldGenStructures.decorate((WorldServer) world, random, pos, null);
    }, 1);
}
Also used : IChunkGenerator(net.minecraft.world.chunk.IChunkGenerator) Random(java.util.Random) IChunkProvider(net.minecraft.world.chunk.IChunkProvider) ChunkPos(net.minecraft.util.math.ChunkPos) World(net.minecraft.world.World)

Example 25 with ChunkPos

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

the class WorldStructureGenerationData method addEntry.

public Set<ChunkPos> addEntry(Entry entry) {
    entryMap.put(entry.getUuid(), entry);
    Set<ChunkPos> rasterized = entry.rasterize();
    for (ChunkPos coords : rasterized) chunkMap.put(coords, entry);
    if (entry instanceof StructureEntry)
        instanceMap.put(((StructureEntry) entry).getStructureID(), (StructureEntry) entry);
    markDirty();
    return Sets.intersection(checkedChunks, rasterized);
}
Also used : 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