Search in sources :

Example 6 with IColonyTagCapability

use of com.minecolonies.api.colony.IColonyTagCapability in project minecolonies by ldtteam.

the class Colony method isCoordInColony.

@Override
public boolean isCoordInColony(@NotNull final World w, @NotNull final BlockPos pos) {
    if (w.dimension() != this.dimensionId) {
        return false;
    }
    final Chunk chunk = w.getChunkAt(pos);
    final IColonyTagCapability cap = chunk.getCapability(CLOSE_COLONY_CAP, null).resolve().orElse(null);
    return cap != null && cap.getOwningColony() == this.getID();
}
Also used : Chunk(net.minecraft.world.chunk.Chunk) IColonyTagCapability(com.minecolonies.api.colony.IColonyTagCapability)

Example 7 with IColonyTagCapability

use of com.minecolonies.api.colony.IColonyTagCapability in project minecolonies by ldtteam.

the class ChunkClientDataHelper method applyCap.

/**
 * Applies the data tuple to the respective chunk
 *
 * @param chunkCapData colony data to apply
 * @param chunk        the chunk to apply to
 */
public static void applyCap(final ChunkCapData chunkCapData, final Chunk chunk) {
    final IColonyTagCapability cap = chunk.getCapability(CLOSE_COLONY_CAP, null).orElseGet(null);
    if (cap != null) {
        cap.setOwningColony(chunkCapData.owningColony, chunk);
        cap.setCloseColonies(chunkCapData.closeColonies);
    }
    MinecraftForge.EVENT_BUS.post(new ClientChunkUpdatedEvent(chunk));
}
Also used : ClientChunkUpdatedEvent(com.minecolonies.api.colony.event.ClientChunkUpdatedEvent) IColonyTagCapability(com.minecolonies.api.colony.IColonyTagCapability)

Example 8 with IColonyTagCapability

use of com.minecolonies.api.colony.IColonyTagCapability in project minecolonies by ldtteam.

the class ChunkDataHelper method canClaimChunksInRange.

/**
 * Check if all chunks within a certain range can be claimed, if range is too big this might require to load chunks. Use carefully.
 * <p>
 * --- This is only for dynamic claiming ---
 *
 * @param w     the world.
 * @param pos   the center position.
 * @param range the range to check.
 * @return true if possible.
 */
public static boolean canClaimChunksInRange(final World w, final BlockPos pos, final int range) {
    final IChunkmanagerCapability worldCapability = w.getCapability(CHUNK_STORAGE_UPDATE_CAP, null).resolve().orElse(null);
    if (worldCapability == null) {
        return true;
    }
    final Chunk centralChunk = w.getChunkAt(pos);
    final int chunkX = centralChunk.getPos().x;
    final int chunkZ = centralChunk.getPos().z;
    for (int i = chunkX - range; i <= chunkX + range; i++) {
        for (int j = chunkZ - range; j <= chunkZ + range; j++) {
            final Chunk chunk = w.getChunk(i, j);
            final IColonyTagCapability colonyCap = chunk.getCapability(CLOSE_COLONY_CAP, null).resolve().orElse(null);
            if (colonyCap == null) {
                return true;
            }
            final ChunkLoadStorage storage = worldCapability.getChunkStorage(chunk.getPos().x, chunk.getPos().z);
            if (storage != null) {
                storage.applyToCap(colonyCap, chunk);
            }
            if (colonyCap.getOwningColony() != 0) {
                return false;
            }
        }
    }
    return true;
}
Also used : IChunkmanagerCapability(com.minecolonies.api.colony.IChunkmanagerCapability) ChunkLoadStorage(com.minecolonies.api.util.ChunkLoadStorage) Chunk(net.minecraft.world.chunk.Chunk) IColonyTagCapability(com.minecolonies.api.colony.IColonyTagCapability)

Example 9 with IColonyTagCapability

use of com.minecolonies.api.colony.IColonyTagCapability in project minecolonies by ldtteam.

the class ChunkDataHelper method addStorageToChunk.

/**
 * Add a chunk storage to a chunk.
 *
 * @param chunk   the chunk to add it to.
 * @param storage the said storage.
 */
public static void addStorageToChunk(final Chunk chunk, final ChunkLoadStorage storage) {
    final IColonyTagCapability cap = chunk.getCapability(CLOSE_COLONY_CAP, null).resolve().orElse(null);
    storage.applyToCap(cap, chunk);
    if (cap != null) {
        Network.getNetwork().sendToEveryone(new UpdateChunkCapabilityMessage(cap, chunk.getPos().x, chunk.getPos().z));
    }
}
Also used : UpdateChunkCapabilityMessage(com.minecolonies.coremod.network.messages.client.UpdateChunkCapabilityMessage) IColonyTagCapability(com.minecolonies.api.colony.IColonyTagCapability)

Example 10 with IColonyTagCapability

use of com.minecolonies.api.colony.IColonyTagCapability in project minecolonies by ldtteam.

the class ChunkDataHelper method loadChunkAndAddData.

/**
 * Add the data to the chunk directly for dynamic claiming.
 * <p>
 * ----- Only for dynamic claiming -----
 *
 * @param world        the world.
 * @param pos          the position.
 * @param add          if add or delete.
 * @param id           the id.
 * @param buildingPos  the building pos.
 * @param chunkManager the chunk manager capability.
 * @return true if successful.
 */
public static boolean loadChunkAndAddData(final World world, final BlockPos pos, final boolean add, final int id, final BlockPos buildingPos, final IChunkmanagerCapability chunkManager) {
    if (!WorldUtil.isBlockLoaded(world, pos)) {
        return false;
    }
    final Chunk chunk = world.getChunkAt(pos);
    final IColonyTagCapability cap = chunk.getCapability(CLOSE_COLONY_CAP, null).resolve().orElse(null);
    if (cap == null) {
        return false;
    }
    // Before directly adding cap data, apply data from our cache.
    final ChunkLoadStorage chunkLoadStorage = chunkManager.getChunkStorage(chunk.getPos().x, chunk.getPos().z);
    if (chunkLoadStorage != null) {
        chunkLoadStorage.applyToCap(cap, chunk);
    }
    if (add) {
        cap.addBuildingClaim(id, buildingPos, chunk);
    } else {
        cap.removeBuildingClaim(id, buildingPos, chunk);
    }
    Network.getNetwork().sendToEveryone(new UpdateChunkCapabilityMessage(cap, chunk.getPos().x, chunk.getPos().z));
    return true;
}
Also used : ChunkLoadStorage(com.minecolonies.api.util.ChunkLoadStorage) Chunk(net.minecraft.world.chunk.Chunk) UpdateChunkCapabilityMessage(com.minecolonies.coremod.network.messages.client.UpdateChunkCapabilityMessage) IColonyTagCapability(com.minecolonies.api.colony.IColonyTagCapability)

Aggregations

IColonyTagCapability (com.minecolonies.api.colony.IColonyTagCapability)29 Chunk (net.minecraft.world.chunk.Chunk)21 ChunkPos (net.minecraft.util.math.ChunkPos)7 ChunkLoadStorage (com.minecolonies.api.util.ChunkLoadStorage)6 UpdateChunkCapabilityMessage (com.minecolonies.coremod.network.messages.client.UpdateChunkCapabilityMessage)6 BlockPos (net.minecraft.util.math.BlockPos)6 IChunkmanagerCapability (com.minecolonies.api.colony.IChunkmanagerCapability)4 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)3 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)3 World (net.minecraft.world.World)3 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 ClientChunkUpdatedEvent (com.minecolonies.api.colony.event.ClientChunkUpdatedEvent)2 UpdateChunkCapabilityMessage (com.minecolonies.coremod.network.messages.UpdateChunkCapabilityMessage)2 GameProfile (com.mojang.authlib.GameProfile)2 ClientWorld (net.minecraft.client.world.ClientWorld)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 IChunk (net.minecraft.world.chunk.IChunk)2 IColony (com.minecolonies.api.colony.IColony)1 ServerWorld (net.minecraft.world.server.ServerWorld)1 Nullable (org.jetbrains.annotations.Nullable)1