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