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;
}
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();
}
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;
}
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);
}
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;
}
Aggregations