Search in sources :

Example 16 with IChunk

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

the class ColonyDeathpoints method tryCreatingWaypoint.

@Nullable
private static Waypoint tryCreatingWaypoint(@NotNull final Journeymap jmap, @NotNull final IColonyView colony, @NotNull final BlockPos pos) {
    final ChunkPos chunkPos = new ChunkPos(pos);
    final IChunk chunk = colony.getWorld().getChunk(chunkPos.x, chunkPos.z, ChunkStatus.FULL, false);
    return (chunk == null) ? null : tryCreatingWaypoint(jmap, colony, chunk, pos);
}
Also used : IChunk(net.minecraft.world.chunk.IChunk) ChunkPos(net.minecraft.util.math.ChunkPos) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with IChunk

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

the class ServerProtectedRegionManager method getProtectedRegionsAt.

@Override
public List<ProtectedRegion> getProtectedRegionsAt(BlockPos pos) {
    // load chunk which also loads all associated protected regions
    IChunk ichunk = this.world.getChunk(pos);
    if (!(ichunk instanceof Chunk)) {
        return Collections.emptyList();
    }
    Chunk chunk = (Chunk) ichunk;
    LazyOptional<CapabilityProtectedRegionData> lOpCap = chunk.getCapability(CapabilityProtectedRegionDataProvider.PROTECTED_REGION_DATA, null);
    if (!lOpCap.isPresent()) {
        return Collections.emptyList();
    }
    List<ProtectedRegion> list = new ArrayList<>();
    lOpCap.ifPresent((cap) -> {
        cap.removeIf(uuid -> {
            ProtectedRegionContainer container = this.protectedRegions.get(uuid);
            if (container != null && container.protectedRegion.isInsideProtectedRegion(pos)) {
                list.add(container.protectedRegion);
            }
            return container == null;
        });
    });
    return list;
}
Also used : IChunk(net.minecraft.world.chunk.IChunk) SPacketUnloadProtectedRegion(team.cqr.cqrepoured.network.server.packet.SPacketUnloadProtectedRegion) SPacketUpdateProtectedRegion(team.cqr.cqrepoured.network.server.packet.SPacketUpdateProtectedRegion) ArrayList(java.util.ArrayList) CapabilityProtectedRegionData(team.cqr.cqrepoured.capability.protectedregions.CapabilityProtectedRegionData) Chunk(net.minecraft.world.chunk.Chunk) IChunk(net.minecraft.world.chunk.IChunk)

Example 18 with IChunk

use of net.minecraft.world.chunk.IChunk in project dynmap by webbukkit.

the class DynmapExpCommand method registerEvents.

private void registerEvents() {
    // To trigger rendering.
    onblockchange = core.isTrigger("blockupdate");
    onchunkpopulate = core.isTrigger("chunkpopulate");
    onchunkgenerate = core.isTrigger("chunkgenerate");
    onblockchange_with_id = core.isTrigger("blockupdate-with-id");
    if (onblockchange_with_id)
        onblockchange = true;
    if ((worldTracker == null) && (onblockchange || onchunkpopulate || onchunkgenerate)) {
        worldTracker = new WorldTracker();
        MinecraftForge.EVENT_BUS.register(worldTracker);
    }
    // Prime the known full chunks
    if (onchunkgenerate && (server.getWorlds() != null)) {
        for (ServerWorld world : server.getWorlds()) {
            ForgeWorld fw = getWorld(world);
            if (fw == null)
                continue;
            Long2ObjectLinkedOpenHashMap<ChunkHolder> chunks = world.getChunkProvider().chunkManager.immutableLoadedChunks;
            for (Entry<Long, ChunkHolder> k : chunks.long2ObjectEntrySet()) {
                long key = k.getKey().longValue();
                ChunkHolder ch = k.getValue();
                IChunk c = null;
                try {
                    c = ch.func_219302_f().getNow(null);
                } catch (Exception x) {
                }
                if (c == null)
                    continue;
                ChunkStatus cs = c.getStatus();
                ChunkPos pos = ch.getPosition();
                if (cs == ChunkStatus.FULL) {
                    // Cooked?
                    // Add it as known
                    addKnownChunk(fw, pos);
                }
            }
        }
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) IServerWorld(net.minecraft.world.IServerWorld) ChunkHolder(net.minecraft.world.server.ChunkHolder) IChunk(net.minecraft.world.chunk.IChunk) ChunkStatus(net.minecraft.world.chunk.ChunkStatus) ChunkPos(net.minecraft.util.math.ChunkPos) CommandException(net.minecraft.command.CommandException) CancellationException(java.util.concurrent.CancellationException) ExecutionException(java.util.concurrent.ExecutionException) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) JsonParseException(com.google.gson.JsonParseException)

Example 19 with IChunk

use of net.minecraft.world.chunk.IChunk in project Mekanism by mekanism.

the class TransporterPathfinder method getPaths.

private static List<Destination> getPaths(LogisticalTransporterBase start, TransporterStack stack, TransitRequest request, int min) {
    InventoryNetwork network = start.getTransmitterNetwork();
    if (network == null) {
        return Collections.emptyList();
    }
    Long2ObjectMap<IChunk> chunkMap = new Long2ObjectOpenHashMap<>();
    List<AcceptorData> acceptors = network.calculateAcceptors(request, stack, chunkMap);
    List<Destination> paths = new ArrayList<>();
    for (AcceptorData data : acceptors) {
        Destination path = getPath(network, data, start, stack, min, chunkMap);
        if (path != null) {
            paths.add(path);
        }
    }
    Collections.sort(paths);
    return paths;
}
Also used : IChunk(net.minecraft.world.chunk.IChunk) ArrayList(java.util.ArrayList) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) AcceptorData(mekanism.common.content.network.InventoryNetwork.AcceptorData) InventoryNetwork(mekanism.common.content.network.InventoryNetwork)

Example 20 with IChunk

use of net.minecraft.world.chunk.IChunk in project Mekanism by mekanism.

the class TransporterPathfinder method getIdlePath.

public static Pair<List<BlockPos>, Path> getIdlePath(LogisticalTransporterBase start, TransporterStack stack) {
    InventoryNetwork network = start.getTransmitterNetwork();
    if (network == null) {
        return null;
    }
    if (stack.homeLocation != null) {
        Long2ObjectMap<IChunk> chunkMap = new Long2ObjectOpenHashMap<>();
        Pathfinder p = new Pathfinder(new DestChecker() {

            @Override
            public boolean isValid(TransporterStack stack, Direction side, TileEntity tile) {
                return TransporterUtils.canInsert(tile, stack.color, stack.itemStack, side, true);
            }
        }, network, start.getTileWorld(), stack.homeLocation, start.getTilePos(), stack);
        p.find(chunkMap);
        List<BlockPos> path = p.getPath();
        if (path.size() >= 2) {
            return Pair.of(path, Path.HOME);
        }
        stack.homeLocation = null;
    }
    IdlePath d = new IdlePath(network, start.getTilePos(), stack);
    Destination dest = d.find();
    if (dest == null) {
        return null;
    }
    return Pair.of(dest.getPath(), dest.getPathType());
}
Also used : DestChecker(mekanism.common.content.transporter.TransporterPathfinder.Pathfinder.DestChecker) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) Direction(net.minecraft.util.Direction) InventoryNetwork(mekanism.common.content.network.InventoryNetwork) TileEntity(net.minecraft.tileentity.TileEntity) IChunk(net.minecraft.world.chunk.IChunk) SidedBlockPos(mekanism.common.lib.SidedBlockPos) BlockPos(net.minecraft.util.math.BlockPos)

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