Search in sources :

Example 21 with Colony

use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.

the class EntityAIWorkDeliveryman method getWareHouse.

/**
 * Gets the colony's warehouse for the Deliveryman.
 */
public BuildingWareHouse getWareHouse() {
    final Map<BlockPos, AbstractBuilding> buildings = job.getColony().getBuildingManager().getBuildings();
    for (final AbstractBuilding building : buildings.values()) {
        if (building == null) {
            continue;
        }
        final Colony buildingColony = building.getColony();
        final Colony ownColony = worker.getColony();
        if (building instanceof BuildingWareHouse && ownColony != null && buildingColony != null && buildingColony.getID() == ownColony.getID() && ((BuildingWareHouse) building).registerWithWareHouse((BuildingDeliveryman) this.getOwnBuilding())) {
            return (BuildingWareHouse) building;
        }
    }
    return null;
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) BlockPos(net.minecraft.util.math.BlockPos)

Example 22 with Colony

use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.

the class EntityAIWorkFarmer method searchAndAddFields.

/**
 * Searches and adds a field that has not been taken yet for the farmer and then adds it to the list.
 */
private void searchAndAddFields() {
    final Colony colony = worker.getColony();
    if (colony != null) {
        @Nullable final ScarecrowTileEntity newField = colony.getBuildingManager().getFreeField(worker.getCitizenData().getId(), world);
        if (newField != null && getOwnBuilding() != null) {
            newField.setOwner(worker.getCitizenData().getId());
            newField.setTaken(true);
            newField.markDirty();
            getOwnBuilding().addFarmerFields(newField.getPos());
        }
    }
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) Nullable(org.jetbrains.annotations.Nullable)

Example 23 with Colony

use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.

the class ShowColonyInfoCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
    int colonyId = getIthArgument(args, 0, -1);
    IColony tempColony = ColonyManager.getColony(colonyId);
    if (colonyId == -1 && args.length >= 1) {
        final GameProfile playerProfile = server.getPlayerProfileCache().getGameProfileForUsername(args[0]);
        if (playerProfile != null) {
            tempColony = ColonyManager.getIColonyByOwner(server.getEntityWorld(), playerProfile.getId());
        }
    }
    if (sender.getCommandSenderEntity() != null) {
        final UUID mayorID = sender.getCommandSenderEntity().getUniqueID();
        if (tempColony == null) {
            tempColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), mayorID);
        }
        if (tempColony != null) {
            colonyId = tempColony.getID();
        }
        final EntityPlayer player = (EntityPlayer) sender;
        if (!canPlayerUseCommand(player, SHOWCOLONYINFO, colonyId)) {
            sender.getCommandSenderEntity().sendMessage(new TextComponentString(NOT_PERMITTED));
            return;
        }
    }
    if (tempColony == null) {
        if (colonyId == -1 && args.length != 0) {
            sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOR_PLAYER_FOUND_MESSAGE, args[0])));
        } else {
            sender.sendMessage(new TextComponentString(String.format(NO_COLONY_WITH_ID_FOUND_MESSAGE, colonyId)));
        }
        return;
    }
    final Colony colony = ColonyManager.getColony(tempColony.getID());
    if (colony == null) {
        if (colonyId == -1 && args.length != 0) {
            sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOR_PLAYER_FOUND_MESSAGE, args[0])));
        } else {
            sender.sendMessage(new TextComponentString(String.format(NO_COLONY_WITH_ID_FOUND_MESSAGE, colonyId)));
        }
        return;
    }
    executeShared(server, sender, colony);
}
Also used : GameProfile(com.mojang.authlib.GameProfile) IColony(com.minecolonies.api.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) UUID(java.util.UUID) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 24 with Colony

use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.

the class AbstractBuildingWorker method getHandlers.

/**
 * Get all handlers accociated with this building.
 * @return the handlers of the building + citizen.
 */
public List<IItemHandler> getHandlers() {
    final Colony colony = getColony();
    if (this.getWorkerEntities().isEmpty() || colony == null || colony.getWorld() == null) {
        return Collections.emptyList();
    }
    final List<IItemHandler> handlers = new ArrayList<>();
    for (final CitizenData workerEntity : this.getWorker()) {
        handlers.add(new InvWrapper(workerEntity.getInventory()));
    }
    handlers.add(new InvWrapper(getTileEntity()));
    for (final BlockPos pos : getAdditionalCountainers()) {
        final TileEntity entity = colony.getWorld().getTileEntity(pos);
        if (entity != null) {
            handlers.addAll(InventoryUtils.getItemHandlersFromProvider(entity));
        }
    }
    return handlers;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IItemHandler(net.minecraftforge.items.IItemHandler) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) Colony(com.minecolonies.coremod.colony.Colony) CitizenData(com.minecolonies.coremod.colony.CitizenData) BlockPos(net.minecraft.util.math.BlockPos)

Example 25 with Colony

use of com.minecolonies.coremod.colony.Colony 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)

Aggregations

Colony (com.minecolonies.coremod.colony.Colony)81 TextComponentString (net.minecraft.util.text.TextComponentString)29 IColony (com.minecolonies.api.colony.IColony)21 EntityPlayer (net.minecraft.entity.player.EntityPlayer)20 BlockPos (net.minecraft.util.math.BlockPos)19 Nullable (org.jetbrains.annotations.Nullable)16 CitizenData (com.minecolonies.coremod.colony.CitizenData)13 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)13 NotNull (org.jetbrains.annotations.NotNull)11 ItemStack (net.minecraft.item.ItemStack)9 Entity (net.minecraft.entity.Entity)8 TileEntity (net.minecraft.tileentity.TileEntity)8 World (net.minecraft.world.World)6 List (java.util.List)5 UUID (java.util.UUID)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)4 Delivery (com.minecolonies.api.colony.requestsystem.requestable.Delivery)4 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)4 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)4