Search in sources :

Example 21 with IColonyTagCapability

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

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)

Example 22 with IColonyTagCapability

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

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 23 with IColonyTagCapability

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

the class ChunkDataHelper method tryClaimBuilding.

/**
 * Add the data to the chunk directly for dynamic claiming.
 * <p>
 * ----- Only for dynamic claiming -----
 *
 * @param world        the world.
 * @param chunkBlockPos          the position.
 * @param add          if add or delete.
 * @param colony           the colony.
 * @param buildingPos  the building pos.
 * @param chunkManager the chunk manager capability.
 * @return true if successful.
 */
public static boolean tryClaimBuilding(final World world, final BlockPos chunkBlockPos, final boolean add, final IColony colony, final BlockPos buildingPos, final IChunkmanagerCapability chunkManager) {
    if (!WorldUtil.isBlockLoaded(world, chunkBlockPos)) {
        final ChunkLoadStorage newStorage = new ChunkLoadStorage(colony.getID(), new ChunkPos(chunkBlockPos).toLong(), world.dimension().location(), buildingPos, add);
        chunkManager.addChunkStorage(SectionPos.blockToSectionCoord(chunkBlockPos.getX()), SectionPos.blockToSectionCoord(chunkBlockPos.getZ()), newStorage);
        return false;
    }
    final Chunk chunk = world.getChunkAt(chunkBlockPos);
    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(colony.getID(), buildingPos, chunk);
    } else {
        cap.removeBuildingClaim(colony.getID(), buildingPos, chunk);
    }
    Network.getNetwork().sendToTrackingChunk(new UpdateChunkCapabilityMessage(cap, chunk.getPos().x, chunk.getPos().z), chunk);
    return true;
}
Also used : ChunkPos(net.minecraft.util.math.ChunkPos) 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)

Example 24 with IColonyTagCapability

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

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 25 with IColonyTagCapability

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

the class CommandShowClaim method onExecute.

/**
 * What happens when the command is executed after preConditions are successful.
 *
 * @param context the context of the command execution
 */
@Override
public int onExecute(final CommandContext<CommandSource> context) {
    final ServerWorld level = context.getSource().getLevel();
    // Colony
    BlockPos pos = new BlockPos(context.getSource().getPosition());
    try {
        pos = BlockPosArgument.getLoadedBlockPos(context, POS_ARG);
    } catch (Exception e) {
    }
    final Chunk chunk = (Chunk) level.getChunk(pos);
    final IColonyTagCapability cap = chunk.getCapability(CLOSE_COLONY_CAP, null).resolve().orElse(null);
    if (cap == null) {
        context.getSource().sendFailure(new StringTextComponent("No capability for chunk found!"));
        return 0;
    }
    context.getSource().sendSuccess(buildClaimCommandResult(cap, pos, level), true);
    return 1;
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) BlockPos(net.minecraft.util.math.BlockPos) Chunk(net.minecraft.world.chunk.Chunk) 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