Search in sources :

Example 1 with BuildingMiner

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

the class MinerLevelManagementModule method repairLevel.

/**
 * Repair the level.
 * @param level the level to repair.
 */
public void repairLevel(final int level) {
    if (building instanceof BuildingMiner) {
        final BlockPos ladderPos = ((BuildingMiner) building).getLadderLocation();
        final BlockPos vector = ladderPos.subtract(((BuildingMiner) building).getCobbleLocation());
        final int xOffset = SHAFT_RADIUS * vector.getX();
        final int zOffset = SHAFT_RADIUS * vector.getZ();
        BuildingMiner.initStructure(null, 0, new BlockPos(ladderPos.getX() + xOffset, levels.get(level).getDepth(), ladderPos.getZ() + zOffset), (BuildingMiner) building, building.getColony().getWorld(), null);
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) BuildingMiner(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingMiner)

Example 2 with BuildingMiner

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

the class EntityAIStructureMiner method searchANodeToMine.

private IAIState searchANodeToMine(@NotNull final Level currentLevel) {
    final BuildingMiner buildingMiner = getOwnBuilding();
    if (buildingMiner == null) {
        return IDLE;
    }
    final MinerLevelManagementModule module = getOwnBuilding().getFirstModuleOccurance(MinerLevelManagementModule.class);
    ;
    if (workingNode == null || workingNode.getStatus() == Node.NodeStatus.COMPLETED) {
        workingNode = module.getActiveNode();
        module.setActiveNode(workingNode);
        if (workingNode == null) {
            final int levelId = module.getLevelId(currentLevel);
            if (levelId > 0) {
                module.setCurrentLevel(levelId - 1);
            }
        }
        return MINER_CHECK_MINESHAFT;
    }
    // normal facing +x
    int rotation = 0;
    final int workingNodeX = workingNode.getX() > workingNode.getParent().getX() ? 1 : 0;
    final int workingNodeZ = workingNode.getZ() > workingNode.getParent().getZ() ? 1 : 0;
    final int vectorX = workingNode.getX() < workingNode.getParent().getX() ? -1 : workingNodeX;
    final int vectorZ = workingNode.getZ() < workingNode.getParent().getZ() ? -1 : workingNodeZ;
    if (vectorX == -1) {
        rotation = ROTATE_TWICE;
    } else if (vectorZ == -1) {
        rotation = ROTATE_THREE_TIMES;
    } else if (vectorZ == 1) {
        rotation = ROTATE_ONCE;
    }
    if (workingNode.getRot().isPresent() && workingNode.getRot().get() != rotation) {
        Log.getLogger().warn("Calculated rotation doesn't match recorded: x:" + workingNodeX + " z:" + workingNodeZ);
    }
    final Node parentNode = currentLevel.getNode(workingNode.getParent());
    if (parentNode != null && parentNode.getStyle() != Node.NodeType.SHAFT && parentNode.getStatus() != Node.NodeStatus.COMPLETED) {
        workingNode = parentNode;
        workingNode.setStatus(Node.NodeStatus.AVAILABLE);
        module.setActiveNode(parentNode);
        buildingMiner.markDirty();
        // We need to make sure to walk back to the last valid parent
        return MINER_CHECK_MINESHAFT;
    }
    @NotNull final BlockPos standingPosition = new BlockPos(workingNode.getParent().getX(), currentLevel.getDepth(), workingNode.getParent().getZ());
    currentStandingPosition = standingPosition;
    if (workingNode != null && currentLevel.getNode(new Vec2i(workingNode.getX(), workingNode.getZ())) == null) {
        module.setActiveNode(null);
        module.setOldNode(null);
        return MINER_MINING_SHAFT;
    }
    if ((workingNode.getStatus() == Node.NodeStatus.AVAILABLE || workingNode.getStatus() == Node.NodeStatus.IN_PROGRESS) && !walkToBlock(standingPosition)) {
        workingNode.setRot(rotation);
        return executeStructurePlacement(workingNode, standingPosition, rotation);
    }
    return MINER_CHECK_MINESHAFT;
}
Also used : MinerLevelManagementModule(com.minecolonies.coremod.colony.buildings.modules.MinerLevelManagementModule) BlockPos(net.minecraft.util.math.BlockPos) BuildingMiner(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingMiner) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with BuildingMiner

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

the class EntityAIStructureMiner method getNodeMiningPosition.

/**
 * Create a save mining position for the miner.
 *
 * @param blockToMine block which should be mined or placed.
 * @return the save position.
 */
private BlockPos getNodeMiningPosition(final BlockPos blockToMine) {
    final BuildingMiner buildingMiner = getOwnBuilding();
    final MinerLevelManagementModule module = buildingMiner.getFirstModuleOccurance(MinerLevelManagementModule.class);
    ;
    if (module.getCurrentLevel() == null || module.getActiveNode() == null) {
        return blockToMine;
    }
    final Vec2i parentPos = module.getActiveNode().getParent();
    final BlockPos vector = getOwnBuilding().getLadderLocation().subtract(getOwnBuilding().getCobbleLocation());
    if (parentPos != null && module.getCurrentLevel().getNode(parentPos) != null && module.getCurrentLevel().getNode(parentPos).getStyle() == Node.NodeType.SHAFT) {
        final BlockPos ladderPos = buildingMiner.getLadderLocation();
        return new BlockPos(ladderPos.getX() + vector.getX() * OTHER_SIDE_OF_SHAFT, module.getCurrentLevel().getDepth(), ladderPos.getZ() + vector.getZ() * OTHER_SIDE_OF_SHAFT);
    }
    final Vec2i pos = module.getActiveNode().getParent();
    return new BlockPos(pos.getX(), module.getCurrentLevel().getDepth(), pos.getZ());
}
Also used : MinerLevelManagementModule(com.minecolonies.coremod.colony.buildings.modules.MinerLevelManagementModule) BlockPos(net.minecraft.util.math.BlockPos) BuildingMiner(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingMiner)

Example 4 with BuildingMiner

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

the class AbstractEntityAIGuard method patrolMine.

/**
 * Patrol between all completed nodes in the assigned mine
 *
 * @return the next point to patrol to
 */
public IAIState patrolMine() {
    if (buildingGuards.getMinePos() == null) {
        return PREPARING;
    }
    if (currentPatrolPoint == null || worker.isWorkerAtSiteWithMove(currentPatrolPoint, 2)) {
        final IBuilding building = buildingGuards.getColony().getBuildingManager().getBuilding(buildingGuards.getMinePos());
        if (building != null) {
            if (building instanceof BuildingMiner) {
                final BuildingMiner buildingMiner = (BuildingMiner) building;
                final Level level = buildingMiner.getFirstModuleOccurance(MinerLevelManagementModule.class).getCurrentLevel();
                if (level == null) {
                    setNextPatrolTarget(buildingMiner.getPosition());
                } else {
                    setNextPatrolTarget(level.getRandomCompletedNode(buildingMiner));
                }
            } else {
                buildingGuards.getFirstModuleOccurance(ISettingsModule.class).getSetting(AbstractBuildingGuards.GUARD_TASK).set(GuardTaskSetting.PATROL);
            }
        } else {
            buildingGuards.getFirstModuleOccurance(ISettingsModule.class).getSetting(AbstractBuildingGuards.GUARD_TASK).set(GuardTaskSetting.PATROL);
        }
    }
    return null;
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) MinerLevelManagementModule(com.minecolonies.coremod.colony.buildings.modules.MinerLevelManagementModule) Level(com.minecolonies.coremod.entity.ai.citizen.miner.Level) BuildingMiner(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingMiner)

Example 5 with BuildingMiner

use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingMiner in project minecolonies by ldtteam.

the class MinerLevelManagementModule method repairLevel.

/**
 * Repair the level.
 * @param level the level to repair.
 */
public void repairLevel(final int level) {
    if (building instanceof BuildingMiner) {
        final BlockPos ladderPos = ((BuildingMiner) building).getLadderLocation();
        final BlockPos vector = ladderPos.subtract(((BuildingMiner) building).getCobbleLocation());
        final int xOffset = SHAFT_RADIUS * vector.getX();
        final int zOffset = SHAFT_RADIUS * vector.getZ();
        BuildingMiner.initStructure(null, 0, new BlockPos(ladderPos.getX() + xOffset, levels.get(level).getDepth(), ladderPos.getZ() + zOffset), (BuildingMiner) building, building.getColony().getWorld(), null);
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) BuildingMiner(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingMiner)

Aggregations

BuildingMiner (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingMiner)12 MinerLevelManagementModule (com.minecolonies.coremod.colony.buildings.modules.MinerLevelManagementModule)8 BlockPos (net.minecraft.util.math.BlockPos)8 NotNull (org.jetbrains.annotations.NotNull)6 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 StandardInteraction (com.minecolonies.coremod.colony.interactionhandling.StandardInteraction)2 Level (com.minecolonies.coremod.entity.ai.citizen.miner.Level)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2 Nullable (org.jetbrains.annotations.Nullable)2