Search in sources :

Example 1 with AbstractBuildingGuards

use of com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards in project minecolonies by Minecolonies.

the class ItemScepterGuard method handleItemUsage.

/**
 * Handles the usage of the item.
 *
 * @param worldIn  the world it is used in.
 * @param pos      the position.
 * @param compound the compound.
 * @param playerIn the player using it.
 * @return if it has been successful.
 */
@NotNull
private static EnumActionResult handleItemUsage(final World worldIn, final BlockPos pos, final NBTTagCompound compound, final EntityPlayer playerIn) {
    final Colony colony = ColonyManager.getClosestColony(worldIn, pos);
    if (colony == null) {
        return EnumActionResult.FAIL;
    }
    final BlockPos guardTower = BlockPosUtil.readFromNBT(compound, "pos");
    final AbstractBuilding hut = colony.getBuildingManager().getBuilding(guardTower);
    if (!(hut instanceof AbstractBuildingGuards)) {
        return EnumActionResult.FAIL;
    }
    final AbstractBuildingGuards tower = (AbstractBuildingGuards) hut;
    if (BlockPosUtil.getDistance2D(pos, guardTower) > tower.getPatrolDistance()) {
        LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickGuardTooFar");
        return EnumActionResult.FAIL;
    }
    final Task task = Task.values()[compound.getInteger("task")];
    final CitizenData citizen = tower.getMainWorker();
    String name = "";
    if (citizen != null) {
        name = " " + citizen.getName();
    }
    if (task.equals(Task.GUARD)) {
        LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickGuard", pos, name);
        tower.setGuardTarget(pos);
        playerIn.inventory.removeStackFromSlot(playerIn.inventory.currentItem);
    } else {
        if (!compound.hasKey(TAG_LAST_POS)) {
            tower.resetPatrolTargets();
        }
        tower.addPatrolTargets(pos);
        LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickPatrol", pos, name);
    }
    BlockPosUtil.writeToNBT(compound, TAG_LAST_POS, pos);
    return EnumActionResult.SUCCESS;
}
Also used : AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) Task(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards.Task) Colony(com.minecolonies.coremod.colony.Colony) BlockPos(net.minecraft.util.math.BlockPos) CitizenData(com.minecolonies.coremod.colony.CitizenData) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with AbstractBuildingGuards

use of com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards in project minecolonies by Minecolonies.

the class GuardTaskMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final GuardTaskMessage message, final EntityPlayerMP player) {
    final Colony colony = ColonyManager.getColony(message.colonyId);
    if (colony != null) {
        // Verify player has permission to change this huts settings
        if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
            return;
        }
        @Nullable final AbstractBuildingGuards building = colony.getBuildingManager().getBuilding(message.buildingId, AbstractBuildingGuards.class);
        if (building != null) {
            if (message.job != -1) {
                building.setJob(AbstractBuildingGuards.GuardJob.values()[message.job]);
            }
            building.setAssignManually(message.assignmentMode);
            building.setPatrolManually(message.patrollingMode);
            building.setRetrieveOnLowHealth(message.retrieval);
            building.setTask(AbstractBuildingGuards.Task.values()[message.task]);
            if (building.getTask().equals(AbstractBuildingGuards.Task.FOLLOW)) {
                building.setPlayerToFollow(player);
            }
        }
    }
}
Also used : AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) Colony(com.minecolonies.coremod.colony.Colony) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with AbstractBuildingGuards

use of com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards in project minecolonies by Minecolonies.

the class AbstractEntityAIGuard method patrol.

/**
 * Lets the guard patrol inside the colony area searching for mobs.
 *
 * @return the next state to go.
 */
protected AIState patrol() {
    worker.setAIMoveSpeed(1);
    final AbstractBuilding building = getOwnBuilding();
    if (worker.getPosition().equals(lastPos)) {
        ticksAtSamePos++;
    } else {
        ticksAtSamePos = 0;
        lastPos = worker.getPosition();
    }
    if (building instanceof AbstractBuildingGuards) {
        if (currentPathTarget == null || !building.getColony().isCoordInColony(world, currentPathTarget) || currentPathTarget.getY() < 2) {
            return getNextPatrollingTarget((AbstractBuildingGuards) building);
        }
        if (worker.isWorkerAtSiteWithMove(currentPathTarget, PATH_CLOSE) || ((AbstractBuildingGuards) building).getTask().equals(AbstractBuildingGuards.Task.FOLLOW) || ticksAtSamePos >= SWITCH_TARGET_AFTER_TICKS) {
            return getNextPatrollingTarget((AbstractBuildingGuards) building);
        }
    }
    return GUARD_SEARCH_TARGET;
}
Also used : AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 4 with AbstractBuildingGuards

use of com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards in project minecolonies by Minecolonies.

the class AbstractEntityAIGuard method checkIfExecute.

/**
 * Checks if the worker is in a state where he can execute well.
 *
 * @return true if so.
 */
private boolean checkIfExecute() {
    final AbstractBuilding building = getOwnBuilding();
    if (!(building instanceof AbstractBuildingGuards)) {
        return true;
    }
    if (!((AbstractBuildingGuards) building).shallRetrieveOnLowHealth()) {
        return false;
    }
    if (worker.getHealth() > LOW_HEALTH) {
        return false;
    }
    worker.isWorkerAtSiteWithMove(building.getLocation(), PATH_CLOSE);
    return true;
}
Also used : AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Aggregations

AbstractBuildingGuards (com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards)4 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)3 Colony (com.minecolonies.coremod.colony.Colony)2 CitizenData (com.minecolonies.coremod.colony.CitizenData)1 Task (com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards.Task)1 BlockPos (net.minecraft.util.math.BlockPos)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1