Search in sources :

Example 11 with IChunk

use of net.minecraft.world.chunk.IChunk in project FrostedHeart by TeamMoegMC.

the class ChunkData method removeChunkAdjust.

/**
 * Used on a ServerWorld context to set temperature in certain 3D region in a
 * ChunkData instance
 * Updates server side cache first. Then send a sync packet to every client.
 */
private static void removeChunkAdjust(IWorld world, ChunkPos chunkPos, ITemperatureAdjust adj) {
    if (world != null && !world.isRemote()) {
        IChunk chunk = world.getChunk(chunkPos.x, chunkPos.z);
        ChunkData data = ChunkData.getCapability(chunk).orElseGet(() -> null);
        if (data != null)
            data.adjusters.remove(adj);
    }
}
Also used : IChunk(net.minecraft.world.chunk.IChunk)

Example 12 with IChunk

use of net.minecraft.world.chunk.IChunk in project LoliServer by Loli-Server.

the class ChunkGenWorker method doWork.

@Override
public boolean doWork() {
    /* TODO: Check how many things are pending save, and slow down world gen if to many
        AnvilChunkLoader loader = dim.getChunkProvider().chunkLoader instanceof AnvilChunkLoader ? (AnvilChunkLoader)world.getChunkProvider().chunkLoader : null;
        if (loader != null && loader.getPendingSaveCount() > 100)
        {

            if (lastNotifcationTime < System.currentTimeMillis() - 10*1000)
            {
                listener.sendSuccess(new TranslationTextComponent("commands.forge.gen.progress", total - queue.size(), total), true);
                lastNotifcationTime = System.currentTimeMillis();
            }
            return false;
        }
        */
    BlockPos next = queue.poll();
    if (next != null) {
        if (++lastNotification >= notificationFrequency || lastNotifcationTime < System.currentTimeMillis() - 60 * 1000) {
            listener.sendSuccess(new TranslationTextComponent("commands.forge.gen.progress", total - queue.size(), total), true);
            lastNotification = 0;
            lastNotifcationTime = System.currentTimeMillis();
        }
        int x = next.getX();
        int z = next.getZ();
        if (!dim.hasChunk(x, z)) {
            // Chunk is unloaded
            IChunk chunk = dim.getChunk(x, z, ChunkStatus.EMPTY, true);
            if (!chunk.getStatus().isOrAfter(ChunkStatus.FULL)) {
                chunk = dim.getChunk(x, z, ChunkStatus.FULL);
                // There isn't a way to check if the chunk is actually created just if it was loaded
                genned++;
            }
        }
    }
    if (queue.size() == 0) {
        listener.sendSuccess(new TranslationTextComponent("commands.forge.gen.complete", genned, total, dim.dimension().location()), true);
        /* TODO: Readd if/when we introduce world unloading, or get Mojang to do it.
            if (keepingLoaded != null && !keepingLoaded)
                DimensionManager.keepLoaded(dim, false);
            */
        return false;
    }
    return true;
}
Also used : IChunk(net.minecraft.world.chunk.IChunk) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos)

Example 13 with IChunk

use of net.minecraft.world.chunk.IChunk in project ChocolateQuestRepoured by TeamChocoQuest.

the class BlockPlacingHelper method setBlockState.

public static boolean setBlockState(World world, BlockPos pos, BlockState state, @Nullable TileEntity tileEntity, int flags, boolean updateLight) {
    if (CQRMain.isPhosphorInstalled || CQRConfig.advanced.instantLightUpdates || updateLight) {
        if (!world.setBlock(pos, state, flags)) {
            return false;
        }
        if (tileEntity != null) {
            world.setBlockEntity(pos, tileEntity);
            tileEntity.updateContainingBlockInfo();
        }
        return true;
    }
    if (world.isOutsideBuildHeight(pos)) {
        return false;
    }
    if (!world.isRemote && world.getWorldInfo().getTerrainType() == WorldType.DEBUG_ALL_BLOCK_STATES) {
        return false;
    }
    IChunk chunk = world.getChunk(pos);
    ChunkSection blockStorage = chunk.getSections()[pos.getY() >> 4];
    if (blockStorage == Chunk.EMPTY_SECTION) {
        if (state == Blocks.AIR.defaultBlockState()) {
            return false;
        }
        blockStorage = new ChunkSection(pos.getY() >> 4 << 4);
        chunk.getSections()[pos.getY() >> 4] = blockStorage;
    }
    return setBlockState(world, chunk, blockStorage, pos, state, tileEntity, flags);
}
Also used : IChunk(net.minecraft.world.chunk.IChunk) ChunkSection(net.minecraft.world.chunk.ChunkSection)

Example 14 with IChunk

use of net.minecraft.world.chunk.IChunk in project FastAsyncWorldEdit by IntellectualSites.

the class ForgeWorld method setBiome.

@Override
public boolean setBiome(BlockVector2 position, BiomeType biome) {
    checkNotNull(position);
    checkNotNull(biome);
    IChunk chunk = getWorld().getChunk(position.getBlockX() >> 4, position.getBlockZ() >> 4, ChunkStatus.FULL, false);
    BiomeContainer container = chunk == null ? null : chunk.getBiomes();
    if (chunk == null || container == null) {
        return false;
    }
    // Temporary, while biome setting is 2D only
    for (int i = 0; i < BiomeMath.VERTICAL_BIT_MASK; i++) {
        int idx = BiomeMath.computeBiomeIndex(position.getX(), i, position.getZ());
        container.biomes[idx] = ForgeAdapter.adapt(biome);
    }
    chunk.setModified(true);
    return true;
}
Also used : IChunk(net.minecraft.world.chunk.IChunk) BiomeContainer(net.minecraft.world.biome.BiomeContainer)

Example 15 with IChunk

use of net.minecraft.world.chunk.IChunk in project minecolonies by Minecolonies.

the class Tree method checkIfInColonyAndNotInBuilding.

/**
 * Calculates with a colony if the position is inside the colony and if it is inside a building.
 *
 * @param pos    the position.
 * @param colony the colony.
 * @param world  the world to use
 * @return return false if not inside the colony or if inside a building.
 */
public static boolean checkIfInColonyAndNotInBuilding(final BlockPos pos, final IColony colony, final IWorldReader world) {
    final IChunk chunk = world.getChunk(pos);
    if (!(chunk instanceof Chunk)) {
        return false;
    }
    final IColonyTagCapability cap = ((Chunk) chunk).getCapability(CLOSE_COLONY_CAP, null).resolve().orElse(null);
    if (cap != null && cap.getOwningColony() != colony.getID()) {
        return false;
    }
    // Dynamic tree's are never part of buildings
    if (Compatibility.isDynamicBlock(world.getBlockState(pos).getBlock())) {
        return true;
    }
    for (final IBuilding building : colony.getBuildingManager().getBuildings().values()) {
        if (building.isInBuilding(pos)) {
            return false;
        }
    }
    return true;
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IChunk(net.minecraft.world.chunk.IChunk) Chunk(net.minecraft.world.chunk.Chunk) IChunk(net.minecraft.world.chunk.IChunk) IColonyTagCapability(com.minecolonies.api.colony.IColonyTagCapability)

Aggregations

IChunk (net.minecraft.world.chunk.IChunk)24 BlockPos (net.minecraft.util.math.BlockPos)8 ChunkPos (net.minecraft.util.math.ChunkPos)7 Direction (net.minecraft.util.Direction)4 Chunk (net.minecraft.world.chunk.Chunk)4 JsonParseException (com.google.gson.JsonParseException)3 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)3 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)3 ArrayList (java.util.ArrayList)3 CancellationException (java.util.concurrent.CancellationException)3 ExecutionException (java.util.concurrent.ExecutionException)3 BlockState (net.minecraft.block.BlockState)3 CommandException (net.minecraft.command.CommandException)3 ChunkStatus (net.minecraft.world.chunk.ChunkStatus)3 ChunkHolder (net.minecraft.world.server.ChunkHolder)3 ServerWorld (net.minecraft.world.server.ServerWorld)3 IColonyTagCapability (com.minecolonies.api.colony.IColonyTagCapability)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)2 ObjectOpenHashSet (it.unimi.dsi.fastutil.objects.ObjectOpenHashSet)2