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