use of com.minecolonies.api.colony.IColonyTagCapability in project minecolonies by Minecolonies.
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 Minecolonies.
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 Minecolonies.
the class Tree method checkIfInColonyAndNotInBuilding.
/**
* Calculates with a colony if the position is inside the colony and if it is inside a building.
*
* @param pos the position.
* @param colony the colony.
* @param world the world to use
* @return return false if not inside the colony or if inside a building.
*/
public static boolean checkIfInColonyAndNotInBuilding(final BlockPos pos, final IColony colony, final IWorldReader world) {
final IChunk chunk = world.getChunk(pos);
if (!(chunk instanceof Chunk)) {
return false;
}
final IColonyTagCapability cap = ((Chunk) chunk).getCapability(CLOSE_COLONY_CAP, null).resolve().orElse(null);
if (cap != null && cap.getOwningColony() != colony.getID()) {
return false;
}
// Dynamic tree's are never part of buildings
if (Compatibility.isDynamicBlock(world.getBlockState(pos).getBlock())) {
return true;
}
for (final IBuilding building : colony.getBuildingManager().getBuildings().values()) {
if (building.isInBuilding(pos)) {
return false;
}
}
return true;
}
use of com.minecolonies.api.colony.IColonyTagCapability in project minecolonies by Minecolonies.
the class ColonyManager method claimColonyChunks.
/**
* Notify all chunks in the range of the colony about the colony.
* @param world the world of the colony.
* @param add remove or add
*/
public static void claimColonyChunks(final World world, final boolean add, final int id, final BlockPos center, final int dimension) {
final Chunk centralChunk = world.getChunkFromBlockCoords(center);
if (centralChunk.getCapability(CLOSE_COLONY_CAP, null).getOwningColony() == id && add) {
return;
}
final IColonyTagCapability cap = centralChunk.getCapability(CLOSE_COLONY_CAP, null);
if (add) {
cap.setOwningColony(id);
cap.addColony(id);
} else {
cap.removeColony(id);
}
centralChunk.markDirty();
MineColonies.getNetwork().sendToAll(new UpdateChunkCapabilityMessage(centralChunk.getCapability(CLOSE_COLONY_CAP, null), centralChunk.x, centralChunk.z));
final int chunkX = centralChunk.x;
final int chunkZ = centralChunk.z;
final int range = Configurations.gameplay.workingRangeTownHallChunks;
final int buffer = Configurations.gameplay.townHallPaddingChunk;
claimChunksInRange(id, dimension, add, chunkX, chunkZ, range, buffer);
}
use of com.minecolonies.api.colony.IColonyTagCapability in project minecolonies by Minecolonies.
the class UpdateChunkCapabilityMessage method onMessage.
@Nullable
@Override
public IMessage onMessage(@NotNull final UpdateChunkCapabilityMessage message, final MessageContext ctx) {
if (ctx.getClientHandler().world != null) {
final Chunk chunk = ctx.getClientHandler().world.getChunkFromChunkCoords(message.x, message.z);
final IColonyTagCapability cap = chunk.getCapability(CLOSE_COLONY_CAP, null);
cap.reset();
cap.setOwningColony(message.owningColonyId);
for (final int id : message.closeColonies) {
cap.addColony(id);
}
}
return null;
}
Aggregations