use of com.minecolonies.coremod.colony.buildings.modules.MinerLevelManagementModule in project minecolonies by ldtteam.
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;
}
use of com.minecolonies.coremod.colony.buildings.modules.MinerLevelManagementModule 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 = building;
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 = building.getLadderLocation().subtract(building.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());
}
use of com.minecolonies.coremod.colony.buildings.modules.MinerLevelManagementModule in project minecolonies by Minecolonies.
the class EntityAIStructureMiner method searchANodeToMine.
private IAIState searchANodeToMine(@NotNull final Level currentLevel) {
final BuildingMiner buildingMiner = building;
if (buildingMiner == null) {
return IDLE;
}
final MinerLevelManagementModule module = building.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;
}
use of com.minecolonies.coremod.colony.buildings.modules.MinerLevelManagementModule in project minecolonies by Minecolonies.
the class EntityAIStructureMiner method advanceLadder.
private IAIState advanceLadder(final IAIState state) {
if (!checkIfRequestForItemExistOrCreate(new ItemStack(getLadderBackFillBlock()), COBBLE_REQUEST_BATCHES, 1) || !checkIfRequestForItemExistOrCreate(new ItemStack(Blocks.LADDER), LADDER_REQUEST_BATCHES, 1)) {
return state;
}
if (ladderDamaged()) {
return MINER_REPAIRING_LADDER;
}
final BlockPos vector = building.getLadderLocation().subtract(building.getCobbleLocation());
final int xOffset = SHAFT_RADIUS * vector.getX();
final int zOffset = SHAFT_RADIUS * vector.getZ();
@NotNull final BlockPos nextLadder = new BlockPos(building.getLadderLocation().getX(), getLastLadder(building.getLadderLocation(), world) - 1, building.getLadderLocation().getZ());
@NotNull final BlockPos safeCobble = new BlockPos(building.getLadderLocation().getX(), getLastLadder(building.getLadderLocation(), world) - 2, building.getLadderLocation().getZ());
// Check for safe floor
for (int x = -SAFE_CHECK_RANGE; x <= SAFE_CHECK_RANGE; x++) {
for (int z = -SAFE_CHECK_RANGE; z <= SAFE_CHECK_RANGE; z++) {
@NotNull final BlockPos curBlock = new BlockPos(safeCobble.getX() + x + xOffset, safeCobble.getY(), safeCobble.getZ() + z + zOffset);
if (!secureBlock(curBlock, currentStandingPosition)) {
return state;
}
}
}
@NotNull final BlockPos safeStand = new BlockPos(building.getLadderLocation().getX(), getLastLadder(building.getLadderLocation(), world), building.getLadderLocation().getZ());
@NotNull final BlockPos nextCobble = new BlockPos(building.getCobbleLocation().getX(), getLastLadder(building.getLadderLocation(), world) - 1, building.getCobbleLocation().getZ());
final MinerLevelManagementModule module = building.getFirstModuleOccurance(MinerLevelManagementModule.class);
if (module.getStartingLevelShaft() == 0) {
module.setStartingLevelShaft(nextCobble.getY() - 4);
}
if (nextCobble.getY() < module.getStartingLevelShaft()) {
return MINER_BUILDING_SHAFT;
}
if ((!mineBlock(nextCobble, safeStand) && !world.getBlockState(nextCobble).getMaterial().isReplaceable()) || (!mineBlock(nextLadder, safeStand) && !world.getBlockState(nextLadder).getMaterial().isReplaceable())) {
// waiting until blocks are mined
return state;
}
// Get ladder orientation
final BlockState metadata = getBlockState(safeStand);
// set solid block
setBlockFromInventory(nextCobble, getLadderBackFillBlock());
// set ladder
setBlockFromInventory(nextLadder, Blocks.LADDER, metadata);
this.incrementActionsDoneAndDecSaturation();
return MINER_CHECK_MINESHAFT;
}
use of com.minecolonies.coremod.colony.buildings.modules.MinerLevelManagementModule in project minecolonies by Minecolonies.
the class EntityAIStructureMiner method executeNodeMining.
@NotNull
private IAIState executeNodeMining() {
final MinerLevelManagementModule module = building.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);
}
Aggregations