use of com.minecolonies.api.util.ChunkLoadStorage 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.util.ChunkLoadStorage in project minecolonies by ldtteam.
the class ChunkDataHelper method loadChunk.
/**
* Load the colony info for a certain chunk.
*
* @param chunk the chunk.
* @param world the worldg to.
*/
public static void loadChunk(final Chunk chunk, final World world) {
// If colony is farther away from a capability then this times the default colony distance it will delete the capability.
final int distanceToDelete = MineColonies.getConfig().getServer().maxColonySize.get() * BLOCKS_PER_CHUNK * 2 * 5;
final IChunkmanagerCapability chunkManager = world.getCapability(CHUNK_STORAGE_UPDATE_CAP, null).resolve().orElse(null);
if (chunkManager == null) {
Log.getLogger().error(UNABLE_TO_FIND_WORLD_CAP_TEXT, new Exception());
return;
}
if (!chunkManager.getAllChunkStorages().isEmpty()) {
final IColonyManagerCapability cap = world.getCapability(COLONY_MANAGER_CAP, null).resolve().orElse(null);
if (cap == null) {
return;
}
final ChunkLoadStorage existingStorage = chunkManager.getChunkStorage(chunk.getPos().x, chunk.getPos().z);
if (existingStorage != null) {
addStorageToChunk(chunk, existingStorage);
}
}
final int closeColony = chunk.getCapability(CLOSE_COLONY_CAP, null).map(IColonyTagCapability::getOwningColony).orElse(0);
if (closeColony != 0) {
final IColony colony = IColonyManager.getInstance().getColonyByDimension(closeColony, world.dimension());
if (colony != null) {
colony.addLoadedChunk(ChunkPos.asLong(chunk.getPos().x, chunk.getPos().z), chunk);
}
}
}
Aggregations