Search in sources :

Example 51 with Colony

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

the class EntityAIWorkDeliveryman method checkIfExecute.

/**
 * Check if the deliveryman code should be executed.
 * More concretely if he has a warehouse to work at.
 *
 * @return false if should continue as planned.
 */
private boolean checkIfExecute() {
    worker.setAIMoveSpeed((float) (BASE_MOVEMENT_SPEED + BASE_MOVEMENT_SPEED * worker.getLevel() / WALKING_SPEED_MULTIPLIER));
    if (getWareHouse() != null && getWareHouse().getTileEntity() != null) {
        return false;
    }
    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 false;
        }
    }
    chatSpamFilter.talkWithoutSpam(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_NOWAREHOUSE);
    return true;
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) BlockPos(net.minecraft.util.math.BlockPos)

Example 52 with Colony

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

the class EntityAIWorkDeliveryman method gather.

/**
 * Gather items from a random hut which the hut doesn't need.
 *
 * @return the next state to go to.
 */
public AIState gather() {
    if (maximalGatherCount < 0) {
        maximalGatherCount = Configurations.requestSystem.minimalBuildingsToGather + worker.getRandom().nextInt(Math.max(1, Configurations.requestSystem.maximalBuildingsToGather - Configurations.requestSystem.minimalBuildingsToGather));
    }
    if (gatherTarget == null) {
        if (gatherCount == maximalGatherCount) {
            maximalGatherCount = Configurations.requestSystem.minimalBuildingsToGather + worker.getRandom().nextInt(Math.max(1, Configurations.requestSystem.maximalBuildingsToGather - Configurations.requestSystem.minimalBuildingsToGather));
            gatherCount = 0;
            return DUMPING;
        }
        gatherTarget = getRandomBuilding();
    }
    if (gatherTarget == null) {
        return START_WORKING;
    }
    worker.setLatestStatus(new TextComponentTranslation("com.minecolonies.coremod.status.gathering"));
    if (!worker.isWorkerAtSiteWithMove(gatherTarget, MIN_DISTANCE_TO_WAREHOUSE)) {
        return GATHERING;
    }
    final Colony colony = getOwnBuilding().getColony();
    if (colony != null) {
        final AbstractBuilding building = colony.getBuildingManager().getBuilding(gatherTarget);
        if (building == null) {
            gatherTarget = null;
            return START_WORKING;
        }
        if (gatherFromBuilding(building) || cannotHoldMoreItems()) {
            this.alreadyKept = new ArrayList<>();
            this.currentSlot = 0;
            building.setBeingGathered(false);
            gatherCount++;
            if (hasGathered) {
                this.hasGathered = false;
                building.alterPickUpPriority(1);
            } else {
                building.alterPickUpPriority(-1);
                if (job.getCurrentTask() == null) {
                    gatherTarget = null;
                    return GATHERING;
                }
            }
            gatherCount = 0;
            return DUMPING;
        }
        currentSlot++;
        return GATHERING;
    }
    return START_WORKING;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Colony(com.minecolonies.coremod.colony.Colony)

Example 53 with Colony

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

the class AbstractEntityAIGuard method onKilledEntity.

/**
 * Called when a guard killed an entity.
 *
 * @param killedEntity the entity being killed.
 */
protected void onKilledEntity(final EntityLivingBase killedEntity) {
    final Colony colony = this.getOwnBuilding().getColony();
    colony.getStatsManager().incrementStatistic("mobs");
    this.incrementActionsDoneAndDecSaturation();
    worker.getNavigator().clearPath();
}
Also used : Colony(com.minecolonies.coremod.colony.Colony)

Example 54 with Colony

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

the class ShowColonyInfoCommand method execute.

public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final ActionMenu actionMenu) throws CommandException {
    // See if we have a valid colony,
    Colony colony = actionMenu.getColonyForArgument("colony");
    EntityPlayer player = null;
    if (null == colony) {
        // see if we have a valid player
        player = actionMenu.getPlayerForArgument("player");
        if (null != player) {
            final IColony iColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), player);
            if (iColony != null) {
                if (!canPlayerUseCommand(player, SHOWCOLONYINFO, iColony.getID())) {
                    sender.sendMessage(new TextComponentString(NOT_PERMITTED));
                    return;
                }
                colony = ColonyManager.getColony(iColony.getID());
            }
        }
    }
    if (null == colony) {
        // see if we have a sender that is a valid player
        if (sender instanceof EntityPlayer) {
            player = (EntityPlayer) sender;
            final UUID mayorID = player.getUniqueID();
            final IColony iColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), mayorID);
            if (iColony != null) {
                if (!canPlayerUseCommand(player, SHOWCOLONYINFO, iColony.getID())) {
                    sender.sendMessage(new TextComponentString(NOT_PERMITTED));
                    return;
                }
                colony = ColonyManager.getColony(iColony.getID());
            }
        }
    }
    if (colony == null) {
        if (null != player) {
            sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOR_PLAYER_FOUND_MESSAGE, player.getName())));
        } else {
            sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOUND_MESSAGE)));
        }
        return;
    }
    executeShared(server, sender, colony);
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IColony(com.minecolonies.api.colony.IColony) UUID(java.util.UUID) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 55 with Colony

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

the class RSResetCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final ActionMenu actionMenu) throws CommandException {
    final Colony colony = actionMenu.getColonyForArgument("colony");
    if (colony == null) {
        sender.sendMessage(new TextComponentString(COLONY_NOT_FOUND));
        return;
    }
    executeShared(server, sender, colony);
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) TextComponentString(net.minecraft.util.text.TextComponentString)

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