use of com.minecolonies.api.colony.IColonyTagCapability in project minecolonies by Minecolonies.
the class ColonyManager 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);
storage.applyToCap(cap);
chunk.markDirty();
MineColonies.getNetwork().sendToAll(new UpdateChunkCapabilityMessage(cap, chunk.x, chunk.z));
}
use of com.minecolonies.api.colony.IColonyTagCapability in project minecolonies by Minecolonies.
the class ColonyView method isCoordInColony.
@Override
public boolean isCoordInColony(@NotNull final World w, @NotNull final BlockPos pos) {
final Chunk chunk = w.getChunkFromBlockCoords(pos);
final IColonyTagCapability cap = chunk.getCapability(CLOSE_COLONY_CAP, null);
return cap.getOwningColony() == this.getID();
}
use of com.minecolonies.api.colony.IColonyTagCapability in project minecolonies by Minecolonies.
the class EventHandler method onEnteringChunk.
/**
* Event called when the player enters a new chunk.
* @param event the event.
*/
@SubscribeEvent
public void onEnteringChunk(@NotNull final PlayerEvent.EnteringChunk event) {
final Entity entity = event.getEntity();
// Add nearby players
if (entity instanceof EntityPlayerMP && entity.dimension == 0) {
final World world = entity.getEntityWorld();
final Chunk newChunk = world.getChunkFromChunkCoords(event.getNewChunkX(), event.getNewChunkZ());
ColonyManager.loadChunk(newChunk, entity.world);
final IColonyTagCapability newCloseColonies = newChunk.getCapability(CLOSE_COLONY_CAP, null);
MineColonies.getNetwork().sendToAll(new UpdateChunkCapabilityMessage(newCloseColonies, newChunk.x, newChunk.z));
@NotNull final EntityPlayerMP player = (EntityPlayerMP) entity;
final Chunk oldChunk = world.getChunkFromChunkCoords(event.getOldChunkX(), event.getOldChunkZ());
final IColonyTagCapability oldCloseColonies = oldChunk.getCapability(CLOSE_COLONY_CAP, null);
// Add new subscribers to colony.
for (final int colonyId : newCloseColonies.getAllCloseColonies()) {
final Colony colony = ColonyManager.getColony(colonyId);
if (colony != null) {
colony.getPackageManager().addSubscribers(player);
}
}
// Remove old subscribers from colony.
for (final int colonyId : oldCloseColonies.getAllCloseColonies()) {
if (!newCloseColonies.getAllCloseColonies().contains(colonyId)) {
final Colony colony = ColonyManager.getColony(colonyId);
if (colony != null) {
colony.getPackageManager().removeSubscriber(player);
}
}
}
if (newCloseColonies.getOwningColony() != oldCloseColonies.getOwningColony()) {
if (newCloseColonies.getOwningColony() == 0) {
final Colony colony = ColonyManager.getColony(oldCloseColonies.getOwningColony());
if (colony != null) {
colony.removeVisitingPlayer(player);
}
return;
}
final Colony colony = ColonyManager.getColony(newCloseColonies.getOwningColony());
if (colony != null) {
colony.addVisitingPlayer(player);
}
}
}
}
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) {
final Chunk chunk = w.getChunkFromBlockCoords(pos);
final IColonyTagCapability cap = chunk.getCapability(CLOSE_COLONY_CAP, null);
return cap.getOwningColony() == this.getID();
}
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);
}
Aggregations