Search in sources :

Example 16 with AbstractBuilding

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

the class EventHandler method onBlockBreak.

/**
     * Event when a block is broken.
     * Event gets cancelled when there no permission to break a hut.
     *
     * @param event {@link net.minecraftforge.event.world.BlockEvent.BreakEvent}
     */
@SubscribeEvent
public void onBlockBreak(@NotNull final BlockEvent.BreakEvent event) {
    final World world = event.getWorld();
    if (!world.isRemote && event.getState().getBlock() instanceof AbstractBlockHut) {
        @Nullable final AbstractBuilding building = ColonyManager.getBuilding(world, event.getPos());
        if (building == null) {
            return;
        }
        if (!building.getColony().getPermissions().hasPermission(event.getPlayer(), Action.BREAK_HUTS)) {
            event.setCanceled(true);
            return;
        }
        building.destroy();
    }
}
Also used : World(net.minecraft.world.World) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut) Nullable(org.jetbrains.annotations.Nullable) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 17 with AbstractBuilding

use of com.minecolonies.coremod.colony.buildings.AbstractBuilding 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 BuildingGuardTower)) {
        return true;
    }
    if (!((BuildingGuardTower) building).shallRetrieveOnLowHealth()) {
        return false;
    }
    if (worker.getHealth() > 2) {
        return false;
    }
    worker.isWorkerAtSiteWithMove(building.getLocation(), PATH_CLOSE);
    return true;
}
Also used : BuildingGuardTower(com.minecolonies.coremod.colony.buildings.BuildingGuardTower) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 18 with AbstractBuilding

use of com.minecolonies.coremod.colony.buildings.AbstractBuilding 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 (building instanceof BuildingGuardTower) {
        if (currentPathTarget == null || BlockPosUtil.getDistance2D(building.getColony().getCenter(), currentPathTarget) > Configurations.workingRangeTownHall + Configurations.townHallPadding || currentPathTarget.getY() < 2) {
            return getNextPatrollingTarget((BuildingGuardTower) building);
        }
        if (worker.isWorkerAtSiteWithMove(currentPathTarget, PATH_CLOSE) || ((BuildingGuardTower) building).getTask().equals(BuildingGuardTower.Task.FOLLOW)) {
            return getNextPatrollingTarget((BuildingGuardTower) building);
        }
    }
    return AIState.GUARD_SEARCH_TARGET;
}
Also used : BuildingGuardTower(com.minecolonies.coremod.colony.buildings.BuildingGuardTower) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 19 with AbstractBuilding

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

the class EntityAIStructureBuilder method executeSpecificCompleteActions.

@Override
public void executeSpecificCompleteActions() {
    if (job.getStructure() == null && job.hasWorkOrder()) {
        //fix for bad structures
        job.complete();
    }
    if (job.getStructure() == null) {
        return;
    }
    final String structureName = job.getStructure().getName();
    worker.sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILDCOMPLETE, structureName);
    final WorkOrderBuildDecoration wo = job.getWorkOrder();
    if (wo == null) {
        Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing work order(%d)", worker.getColony().getID(), worker.getCitizenData().getId(), job.getWorkOrderId()));
    } else {
        final WorkOrderBuild woh = (wo instanceof WorkOrderBuild) ? (WorkOrderBuild) wo : null;
        if (woh == null && structureName.contains(WAYPOINT_STRING)) {
            worker.getColony().addWayPoint(wo.getBuildingLocation(), world.getBlockState(wo.getBuildingLocation()));
        } else if (woh != null) {
            final AbstractBuilding building = job.getColony().getBuilding(wo.getBuildingLocation());
            if (building == null) {
                Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing building(%s)", worker.getColony().getID(), worker.getCitizenData().getId(), woh.getBuildingLocation()));
            } else {
                building.setBuildingLevel(woh.getUpgradeLevel());
            }
        }
        job.complete();
    }
    final BuildingBuilder workerBuilding = (BuildingBuilder) getOwnBuilding();
    workerBuilding.resetNeededResources();
    resetTask();
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) BuildingBuilder(com.minecolonies.coremod.colony.buildings.BuildingBuilder) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Aggregations

AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)19 BlockPos (net.minecraft.util.math.BlockPos)7 Colony (com.minecolonies.coremod.colony.Colony)5 BuildingGuardTower (com.minecolonies.coremod.colony.buildings.BuildingGuardTower)4 Nullable (org.jetbrains.annotations.Nullable)4 World (net.minecraft.world.World)3 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)2 WorkOrderBuild (com.minecolonies.coremod.colony.workorders.WorkOrderBuild)2 WorkOrderBuildDecoration (com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)2 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)2 NotNull (org.jetbrains.annotations.NotNull)2 CitizenData (com.minecolonies.coremod.colony.CitizenData)1 BuildingBuilder (com.minecolonies.coremod.colony.buildings.BuildingBuilder)1 BuildingHome (com.minecolonies.coremod.colony.buildings.BuildingHome)1 BuildingWareHouse (com.minecolonies.coremod.colony.buildings.BuildingWareHouse)1 EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1