Search in sources :

Example 6 with MinerLevelManagementModule

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

the class EntityAIStructureMiner method executeSpecificCompleteActions.

@Override
public void executeSpecificCompleteActions() {
    final BuildingMiner minerBuilding = building;
    // If shaft isn't cleared we're in shaft clearing mode.
    final MinerLevelManagementModule module = building.getFirstModuleOccurance(MinerLevelManagementModule.class);
    if (job.getBlueprint() != null) {
        if (job.getBlueprint().getName().contains("minermainshaft")) {
            final int depth = job.getWorkOrder().getLocation().getY();
            boolean exists = false;
            for (final Level level : module.getLevels()) {
                if (level.getDepth() == depth) {
                    exists = true;
                    break;
                }
            }
            @Nullable final BlockPos levelSignPos = WorkerUtil.findFirstLevelSign(job.getBlueprint(), job.getWorkOrder().getLocation());
            @NotNull final Level currentLevel = new Level(minerBuilding, job.getWorkOrder().getLocation().getY(), levelSignPos);
            if (!exists) {
                module.addLevel(currentLevel);
                module.setCurrentLevel(module.getNumberOfLevels());
            }
            WorkerUtil.updateLevelSign(world, currentLevel, module.getLevelId(currentLevel));
        } else {
            final Level currentLevel = module.getCurrentLevel();
            currentLevel.closeNextNode(structurePlacer.getB().getSettings().rotation.ordinal(), module.getActiveNode(), world);
            module.setActiveNode(null);
            module.setOldNode(workingNode);
            WorkerUtil.updateLevelSign(world, currentLevel, module.getLevelId(currentLevel));
        }
    }
    super.executeSpecificCompleteActions();
    // Send out update to client
    building.markDirty();
    job.setBlueprint(null);
}
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) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with MinerLevelManagementModule

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

the class EntityCitizenWalkToProxy method getMinerProxy.

/**
 * Returns a proxy point to the goal for the miner especially.
 *
 * @param target         the target.
 * @param distanceToPath the total distance.
 * @param building       the building to walk to.
 * @return a proxy or, if not applicable null.
 */
@NotNull
private BlockPos getMinerProxy(final BlockPos target, final double distanceToPath, @NotNull final BuildingMiner building) {
    final MinerLevelManagementModule module = building.getFirstModuleOccurance(MinerLevelManagementModule.class);
    final Level level = module.getCurrentLevel();
    final BlockPos ladderPos = building.getLadderLocation();
    // If his current working level is null, we have nothing to worry about.
    if (level != null) {
        final BlockPos vector = building.getLadderLocation().subtract(building.getCobbleLocation());
        final int levelDepth = level.getDepth() + 2;
        final int targetY = target.getY();
        final int workerY = citizen.blockPosition().getY();
        // Check if miner is underground in shaft and his target is overground.
        if (workerY <= levelDepth && targetY > levelDepth) {
            if (module.getActiveNode() != null && module.getActiveNode().getParent() != null) {
                com.minecolonies.coremod.entity.ai.citizen.miner.Node currentNode = level.getNode(module.getActiveNode().getParent());
                if (currentNode == null) {
                    module.setActiveNode(null);
                    module.setOldNode(null);
                    return getProxy(target, citizen.blockPosition(), distanceToPath);
                }
                while (currentNode.getParent() != null) {
                    if (currentNode.getStyle() == Node.NodeType.SHAFT) {
                        final Direction facing = BlockPosUtil.getXZFacing(ladderPos, new BlockPos(currentNode.getX(), 0, currentNode.getZ()));
                        final BlockPos ladderHeight = new BlockPos(ladderPos.getX(), targetY + 1, ladderPos.getZ());
                        return new BlockPos(ladderHeight.relative(facing, 7));
                    } else {
                        addToProxyList(new BlockPos(currentNode.getX(), levelDepth, currentNode.getZ()));
                    }
                    currentNode = level.getNode(currentNode.getParent());
                }
            }
            addToProxyList(new BlockPos(ladderPos.getX() + vector.getX() * OTHER_SIDE_OF_SHAFT, level.getDepth(), ladderPos.getZ() + vector.getZ() * OTHER_SIDE_OF_SHAFT));
            return getProxy(target, citizen.blockPosition(), distanceToPath);
        // If he already is at ladder location, the closest node automatically will be his hut block.
        } else // Check if target is underground in shaft and miner is over it.
        if (targetY <= levelDepth && workerY > levelDepth) {
            final BlockPos buildingPos = building.getPosition();
            final BlockPos newProxy;
            // First calculate way to miner building.
            newProxy = getProxy(buildingPos, citizen.blockPosition(), BlockPosUtil.getDistanceSquared(citizen.blockPosition(), buildingPos));
            if (buildingPos.getY() - level.getDepth() > 25) {
                addToProxyList(new BlockPos(ladderPos.getX() + vector.getX(), level.getDepth() + (buildingPos.getY() - level.getDepth()) / 2, ladderPos.getZ() + vector.getZ()));
            }
            // Then add the ladder position as the latest node.
            addToProxyList(new BlockPos(ladderPos.getX() + vector.getX() * OTHER_SIDE_OF_SHAFT, level.getDepth(), ladderPos.getZ() + vector.getZ() * OTHER_SIDE_OF_SHAFT));
            if (module.getActiveNode() != null && module.getActiveNode().getParent() != null) {
                calculateNodes(level, levelDepth, building);
            }
            return newProxy;
        } else // If he is on the same Y level as his target and both underground.
        if (targetY <= levelDepth) {
            double closestNode = Double.MAX_VALUE;
            com.minecolonies.coremod.entity.ai.citizen.miner.Node lastNode = null;
            for (final Map.Entry<Vec2i, com.minecolonies.coremod.entity.ai.citizen.miner.Node> node : level.getNodes().entrySet()) {
                final double distanceToNode = node.getKey().distanceSq(citizen.blockPosition().getX(), citizen.blockPosition().getZ());
                if (distanceToNode < closestNode) {
                    lastNode = node.getValue();
                    closestNode = distanceToNode;
                }
            }
            if (lastNode != null && lastNode.getStyle() == Node.NodeType.SHAFT) {
                final Direction facing = BlockPosUtil.getXZFacing(ladderPos, new BlockPos(lastNode.getX(), 0, lastNode.getZ()));
                final BlockPos ladderHeight = new BlockPos(ladderPos.getX(), targetY + 1, ladderPos.getZ());
                return new BlockPos(ladderHeight.relative(facing, 7));
            }
            if (lastNode != null && lastNode.getParent() != null) {
                com.minecolonies.coremod.entity.ai.citizen.miner.Node currentNode = level.getNode(lastNode.getParent());
                while (new Vec2i(currentNode.getX(), currentNode.getZ()).equals(currentNode.getParent()) && currentNode.getParent() != null) {
                    addToProxyList(new BlockPos(currentNode.getX(), levelDepth, currentNode.getZ()));
                    currentNode = level.getNode(currentNode.getParent());
                }
            }
            if (module.getActiveNode() != null && module.getActiveNode().getParent() != null) {
                calculateNodes(level, levelDepth, building);
            }
            if (!getProxyList().isEmpty()) {
                return getProxyList().get(0);
            }
            return target;
        }
    }
    return getProxy(target, citizen.blockPosition(), distanceToPath);
}
Also used : Vec2i(com.minecolonies.api.util.Vec2i) Node(com.minecolonies.coremod.entity.ai.citizen.miner.Node) Direction(net.minecraft.util.Direction) MinerLevelManagementModule(com.minecolonies.coremod.colony.buildings.modules.MinerLevelManagementModule) Node(com.minecolonies.coremod.entity.ai.citizen.miner.Node) Level(com.minecolonies.coremod.entity.ai.citizen.miner.Level) BlockPos(net.minecraft.util.math.BlockPos) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with MinerLevelManagementModule

use of com.minecolonies.coremod.colony.buildings.modules.MinerLevelManagementModule in project minecolonies by ldtteam.

the class EntityAIStructureMiner method executeNodeMining.

@NotNull
private IAIState executeNodeMining() {
    final MinerLevelManagementModule module = getOwnBuilding().getFirstModuleOccurance(MinerLevelManagementModule.class);
    ;
    @Nullable final Level currentLevel = module.getCurrentLevel();
    if (currentLevel == null) {
        Log.getLogger().warn("Current Level not set, resetting...");
        module.setCurrentLevel(module.getNumberOfLevels() - 1);
        return executeNodeMining();
    }
    return searchANodeToMine(currentLevel);
}
Also used : MinerLevelManagementModule(com.minecolonies.coremod.colony.buildings.modules.MinerLevelManagementModule) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with MinerLevelManagementModule

use of com.minecolonies.coremod.colony.buildings.modules.MinerLevelManagementModule in project minecolonies by ldtteam.

the class EntityAIStructureMiner method executeSpecificCompleteActions.

@Override
public void executeSpecificCompleteActions() {
    final BuildingMiner minerBuilding = getOwnBuilding();
    // If shaft isn't cleared we're in shaft clearing mode.
    final MinerLevelManagementModule module = getOwnBuilding().getFirstModuleOccurance(MinerLevelManagementModule.class);
    if (job.getBlueprint() != null) {
        if (job.getBlueprint().getName().contains("minermainshaft")) {
            final int depth = job.getWorkOrder().getSchematicLocation().getY();
            boolean exists = false;
            for (final Level level : module.getLevels()) {
                if (level.getDepth() == depth) {
                    exists = true;
                    break;
                }
            }
            @Nullable final BlockPos levelSignPos = WorkerUtil.findFirstLevelSign(job.getBlueprint(), job.getWorkOrder().getSchematicLocation());
            @NotNull final Level currentLevel = new Level(minerBuilding, job.getWorkOrder().getSchematicLocation().getY(), levelSignPos);
            if (!exists) {
                module.addLevel(currentLevel);
                module.setCurrentLevel(module.getNumberOfLevels());
            }
            WorkerUtil.updateLevelSign(world, currentLevel, module.getLevelId(currentLevel));
        } else {
            final Level currentLevel = module.getCurrentLevel();
            currentLevel.closeNextNode(structurePlacer.getB().getSettings().rotation.ordinal(), module.getActiveNode(), world);
            module.setActiveNode(null);
            module.setOldNode(workingNode);
            WorkerUtil.updateLevelSign(world, currentLevel, module.getLevelId(currentLevel));
        }
    }
    super.executeSpecificCompleteActions();
    // Send out update to client
    getOwnBuilding().markDirty();
    job.setBlueprint(null);
}
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) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with MinerLevelManagementModule

use of com.minecolonies.coremod.colony.buildings.modules.MinerLevelManagementModule in project minecolonies by ldtteam.

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)

Aggregations

MinerLevelManagementModule (com.minecolonies.coremod.colony.buildings.modules.MinerLevelManagementModule)12 BlockPos (net.minecraft.util.math.BlockPos)10 NotNull (org.jetbrains.annotations.NotNull)10 BuildingMiner (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingMiner)6 Nullable (org.jetbrains.annotations.Nullable)4 Vec2i (com.minecolonies.api.util.Vec2i)2 Level (com.minecolonies.coremod.entity.ai.citizen.miner.Level)2 Node (com.minecolonies.coremod.entity.ai.citizen.miner.Node)2 ItemStack (net.minecraft.item.ItemStack)2 Direction (net.minecraft.util.Direction)2