Search in sources :

Example 26 with IColonyTagCapability

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

the class UpdateChunkCapabilityMessage method onExecute.

@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
    final ClientWorld world = Minecraft.getInstance().level;
    if (!WorldUtil.isChunkLoaded(world, new ChunkPos(chunkCapData.x, chunkCapData.z))) {
        ChunkClientDataHelper.addCapData(chunkCapData);
        return;
    }
    final Chunk chunk = world.getChunk(chunkCapData.x, chunkCapData.z);
    final IColonyTagCapability cap = chunk.getCapability(CLOSE_COLONY_CAP, null).orElseGet(null);
    if (cap != null && cap.getOwningColony() != chunkCapData.owningColony) {
        ChunkClientDataHelper.applyCap(chunkCapData, chunk);
    }
}
Also used : ChunkPos(net.minecraft.util.math.ChunkPos) ClientWorld(net.minecraft.client.world.ClientWorld) Chunk(net.minecraft.world.chunk.Chunk) IColonyTagCapability(com.minecolonies.api.colony.IColonyTagCapability)

Example 27 with IColonyTagCapability

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

the class WindowTownHallColonyManage method findNextNearbyColony.

/**
 * Finds the first nearby colony claim in the range
 *
 * @param world world to use
 * @param start start position
 * @param range search range
 * @return the id of the found colony
 */
private static int findNextNearbyColony(final World world, final BlockPos start, final int range) {
    int startX = start.getX() >> 4;
    int startZ = start.getZ() >> 4;
    for (int x = -range; x <= range; x++) {
        for (int z = -range; z <= range; z++) {
            final int chunkX = startX + x;
            final int chunkZ = startZ + z;
            final Chunk chunk = world.getChunk(chunkX, chunkZ);
            final IColonyTagCapability cap = chunk.getCapability(CLOSE_COLONY_CAP, null).orElseGet(null);
            if (cap != null) {
                if (cap.getOwningColony() != 0) {
                    return cap.getOwningColony();
                }
                if (!cap.getAllCloseColonies().isEmpty()) {
                    return cap.getAllCloseColonies().get(0);
                }
            }
        }
    }
    return 0;
}
Also used : Chunk(net.minecraft.world.chunk.Chunk) IColonyTagCapability(com.minecolonies.api.colony.IColonyTagCapability)

Example 28 with IColonyTagCapability

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

the class Permissions method addPlayer.

/**
 * Add a player to the rankings.
 *
 * @param player String playername of the player to add.
 * @param rank   Rank desired starting rank.
 * @param world  the world the player is in.
 * @return True if successful, otherwise false.
 */
@Override
public boolean addPlayer(@NotNull final String player, final Rank rank, final World world) {
    if (player.isEmpty()) {
        return false;
    }
    final GameProfile gameprofile = world.getServer().getProfileCache().get(player);
    // Adds new subscribers
    if (!world.isClientSide() && gameprofile != null) {
        final ServerPlayerEntity playerEntity = (ServerPlayerEntity) world.getPlayerByUUID(gameprofile.getId());
        if (playerEntity != null) {
            if (rank.getId() == OFFICER_RANK_ID) {
                colony.getPackageManager().addImportantColonyPlayer(playerEntity);
                colony.getPackageManager().updateSubscribers();
                fullyAbandoned = false;
            } else if (rank.getId() == OWNER_RANK_ID) {
                fullyAbandoned = false;
            } else {
                // Check claim
                final Chunk chunk = world.getChunk(playerEntity.xChunk, playerEntity.zChunk);
                final IColonyTagCapability colonyCap = chunk.getCapability(CLOSE_COLONY_CAP, null).orElseGet(null);
                if (colonyCap != null) {
                    if (colonyCap.getOwningColony() == colony.getID() && world.dimension() == colony.getDimension()) {
                        colony.getPackageManager().addCloseSubscriber(playerEntity);
                        colony.getPackageManager().updateSubscribers();
                    }
                }
            }
        }
    }
    return gameprofile != null && !ownerUUID.equals(gameprofile.getId()) && addPlayer(gameprofile, rank);
}
Also used : GameProfile(com.mojang.authlib.GameProfile) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Chunk(net.minecraft.world.chunk.Chunk) IColonyTagCapability(com.minecolonies.api.colony.IColonyTagCapability)

Example 29 with IColonyTagCapability

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

the class WorkManager method isWorkOrderWithinColony.

/**
 * Check if the workOrder is within a colony.
 *
 * @param order the workorder to check.
 * @return true if so.
 */
private boolean isWorkOrderWithinColony(final WorkOrderBuildDecoration order) {
    final World world = colony.getWorld();
    final Tuple<BlockPos, BlockPos> corners = ColonyUtils.calculateCorners(order.getSchematicLocation(), world, new LoadOnlyStructureHandler(world, order.getSchematicLocation(), order.getStructureName(), new PlacementSettings(), true).getBluePrint(), order.getRotation(world), order.isMirrored());
    Set<ChunkPos> chunks = new HashSet<>();
    final int minX = Math.min(corners.getA().getX(), corners.getB().getX()) + 1;
    final int maxX = Math.max(corners.getA().getX(), corners.getB().getX());
    final int minZ = Math.min(corners.getA().getZ(), corners.getB().getZ()) + 1;
    final int maxZ = Math.max(corners.getA().getZ(), corners.getB().getZ());
    for (int x = minX; x < maxX; x += 16) {
        for (int z = minZ; z < maxZ; z += 16) {
            final int chunkX = x >> 4;
            final int chunkZ = z >> 4;
            final ChunkPos pos = new ChunkPos(chunkX, chunkZ);
            if (!chunks.contains(pos)) {
                chunks.add(pos);
                final IColonyTagCapability colonyCap = world.getChunk(pos.x, pos.z).getCapability(CLOSE_COLONY_CAP, null).orElseGet(null);
                if (colonyCap == null || colonyCap.getOwningColony() != colony.getID()) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos) World(net.minecraft.world.World) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) 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