Search in sources :

Example 1 with IColonyTagCapability

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));
}
Also used : UpdateChunkCapabilityMessage(com.minecolonies.coremod.network.messages.UpdateChunkCapabilityMessage) IColonyTagCapability(com.minecolonies.api.colony.IColonyTagCapability)

Example 2 with IColonyTagCapability

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();
}
Also used : Chunk(net.minecraft.world.chunk.Chunk) IColonyTagCapability(com.minecolonies.api.colony.IColonyTagCapability)

Example 3 with IColonyTagCapability

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);
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) World(net.minecraft.world.World) Chunk(net.minecraft.world.chunk.Chunk) UpdateChunkCapabilityMessage(com.minecolonies.coremod.network.messages.UpdateChunkCapabilityMessage) NotNull(org.jetbrains.annotations.NotNull) IColonyTagCapability(com.minecolonies.api.colony.IColonyTagCapability) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with IColonyTagCapability

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();
}
Also used : Chunk(net.minecraft.world.chunk.Chunk) IColonyTagCapability(com.minecolonies.api.colony.IColonyTagCapability)

Example 5 with IColonyTagCapability

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);
}
Also used : Chunk(net.minecraft.world.chunk.Chunk) UpdateChunkCapabilityMessage(com.minecolonies.coremod.network.messages.UpdateChunkCapabilityMessage) IColonyTagCapability(com.minecolonies.api.colony.IColonyTagCapability)

Aggregations

IColonyTagCapability (com.minecolonies.api.colony.IColonyTagCapability)8 Chunk (net.minecraft.world.chunk.Chunk)7 UpdateChunkCapabilityMessage (com.minecolonies.coremod.network.messages.UpdateChunkCapabilityMessage)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 IColony (com.minecolonies.api.colony.IColony)2 Colony (com.minecolonies.coremod.colony.Colony)1 Entity (net.minecraft.entity.Entity)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1