use of com.minecolonies.coremod.entity.ai.util.WorkerLoadOnlyStructureHandler in project minecolonies by Minecolonies.
the class EntityAIQuarrier method requestMaterials.
@Override
public boolean requestMaterials() {
StructurePhasePlacementResult result;
final WorkerLoadOnlyStructureHandler structure = new WorkerLoadOnlyStructureHandler(world, structurePlacer.getB().getWorldPos(), structurePlacer.getB().getBluePrint(), new PlacementSettings(), true, this);
job.getWorkOrder().setIteratorType("default");
final StructurePlacer placer = new StructurePlacer(structure, job.getWorkOrder().getIteratorType());
if (requestProgress == null) {
final AbstractBuildingStructureBuilder buildingWorker = getOwnBuilding();
buildingWorker.resetNeededResources();
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), structurePlacer.getB().getBluePrint().getSizeY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
requestState = RequestStage.SOLID;
}
final BlockPos worldPos = structure.getProgressPosInWorld(requestProgress);
final RequestStage currState = requestState;
switch(currState) {
case SOLID:
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().decrement(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> !info.getBlockInfo().getState().getMaterial().isSolid() || isDecoItem(info.getBlockInfo().getState().getBlock()) || pos.getY() < worldPos.getY())), false);
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
getOwnBuilding().addNeededResource(stack, stack.getCount());
}
if (requestProgress.getY() != -1 && result.getIteratorPos().getY() < requestProgress.getY()) {
requestProgress = new BlockPos(0, requestProgress.getY() + 1, 0);
requestState = RequestStage.DECO;
} else if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestProgress = new BlockPos(0, structurePlacer.getB().getBluePrint().getSizeY() - 2, 0);
requestState = RequestStage.DECO;
} else {
requestProgress = result.getIteratorPos();
}
return false;
case DECO:
if (requestProgress.getY() >= structurePlacer.getB().getBluePrint().getSizeY()) {
requestState = RequestStage.ENTITIES;
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
return false;
}
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getBlockInfo().getState().getMaterial().isSolid() && !isDecoItem(info.getBlockInfo().getState().getBlock()) || pos.getY() > worldPos.getY())), false);
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
getOwnBuilding().addNeededResource(stack, stack.getCount());
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.ENTITIES;
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
} else if (requestProgress.getY() != -1 && result.getIteratorPos().getY() > requestProgress.getY()) {
requestState = RequestStage.ENTITIES;
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
} else {
requestProgress = result.getIteratorPos();
}
return false;
case ENTITIES:
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().decrement(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getEntities().length == 0 || pos.getY() < worldPos.getY())), true);
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.SOLID;
requestProgress = null;
return true;
} else if (requestProgress.getY() != -1 && (result.getIteratorPos().getY() < requestProgress.getY())) {
requestState = RequestStage.SOLID;
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
} else {
requestProgress = result.getIteratorPos();
}
return false;
}
return true;
}
use of com.minecolonies.coremod.entity.ai.util.WorkerLoadOnlyStructureHandler in project minecolonies by ldtteam.
the class AbstractEntityAIStructureWithWorkOrder method requestMaterials.
@Override
public boolean requestMaterials() {
StructurePhasePlacementResult result;
final WorkerLoadOnlyStructureHandler structure = new WorkerLoadOnlyStructureHandler(world, structurePlacer.getB().getWorldPos(), structurePlacer.getB().getBluePrint(), new PlacementSettings(), true, this);
if (job.getWorkOrder().getIteratorType().isEmpty() && getOwnBuilding().hasModule(ISettingsModule.class) && getOwnBuilding().getSetting(BuildingBuilder.BUILDING_MODE) != null) {
job.getWorkOrder().setIteratorType(getOwnBuilding().getSetting(BuildingBuilder.BUILDING_MODE).getValue());
}
final StructurePlacer placer = new StructurePlacer(structure, job.getWorkOrder().getIteratorType());
if (requestProgress == null) {
final AbstractBuildingStructureBuilder buildingWorker = getOwnBuilding();
buildingWorker.resetNeededResources();
requestProgress = NULL_POS;
requestState = RequestStage.SOLID;
}
final RequestStage currState = requestState;
switch(currState) {
case SOLID:
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> !info.getBlockInfo().getState().getMaterial().isSolid() || isDecoItem(info.getBlockInfo().getState().getBlock()))), false);
requestProgress = result.getIteratorPos();
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
getOwnBuilding().addNeededResource(stack, stack.getCount());
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.DECO;
}
return false;
case DECO:
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getBlockInfo().getState().getMaterial().isSolid() && !isDecoItem(info.getBlockInfo().getState().getBlock()))), false);
requestProgress = result.getIteratorPos();
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
getOwnBuilding().addNeededResource(stack, stack.getCount());
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.ENTITIES;
}
return false;
case ENTITIES:
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getEntities().length == 0)), true);
requestProgress = result.getIteratorPos();
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
getOwnBuilding().addNeededResource(stack, stack.getCount());
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.SOLID;
requestProgress = null;
return true;
}
return false;
default:
return true;
}
}
use of com.minecolonies.coremod.entity.ai.util.WorkerLoadOnlyStructureHandler in project minecolonies by ldtteam.
the class EntityAIQuarrier method requestMaterials.
@Override
public boolean requestMaterials() {
StructurePhasePlacementResult result;
final WorkerLoadOnlyStructureHandler structure = new WorkerLoadOnlyStructureHandler(world, structurePlacer.getB().getWorldPos(), structurePlacer.getB().getBluePrint(), new PlacementSettings(), true, this);
job.getWorkOrder().setIteratorType("default");
final StructurePlacer placer = new StructurePlacer(structure, job.getWorkOrder().getIteratorType());
if (requestProgress == null) {
final AbstractBuildingStructureBuilder buildingWorker = getOwnBuilding();
buildingWorker.resetNeededResources();
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), structurePlacer.getB().getBluePrint().getSizeY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
requestState = RequestStage.SOLID;
}
final BlockPos worldPos = structure.getProgressPosInWorld(requestProgress);
final RequestStage currState = requestState;
switch(currState) {
case SOLID:
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().decrement(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> !info.getBlockInfo().getState().getMaterial().isSolid() || isDecoItem(info.getBlockInfo().getState().getBlock()) || pos.getY() < worldPos.getY())), false);
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
getOwnBuilding().addNeededResource(stack, stack.getCount());
}
if (requestProgress.getY() != -1 && result.getIteratorPos().getY() < requestProgress.getY()) {
requestProgress = new BlockPos(0, requestProgress.getY() + 1, 0);
requestState = RequestStage.DECO;
} else if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestProgress = new BlockPos(0, structurePlacer.getB().getBluePrint().getSizeY() - 2, 0);
requestState = RequestStage.DECO;
} else {
requestProgress = result.getIteratorPos();
}
return false;
case DECO:
if (requestProgress.getY() >= structurePlacer.getB().getBluePrint().getSizeY()) {
requestState = RequestStage.ENTITIES;
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
return false;
}
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getBlockInfo().getState().getMaterial().isSolid() && !isDecoItem(info.getBlockInfo().getState().getBlock()) || pos.getY() > worldPos.getY())), false);
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
getOwnBuilding().addNeededResource(stack, stack.getCount());
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.ENTITIES;
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
} else if (requestProgress.getY() != -1 && result.getIteratorPos().getY() > requestProgress.getY()) {
requestState = RequestStage.ENTITIES;
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
} else {
requestProgress = result.getIteratorPos();
}
return false;
case ENTITIES:
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().decrement(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getEntities().length == 0 || pos.getY() < worldPos.getY())), true);
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.SOLID;
requestProgress = null;
return true;
} else if (requestProgress.getY() != -1 && (result.getIteratorPos().getY() < requestProgress.getY())) {
requestState = RequestStage.SOLID;
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
} else {
requestProgress = result.getIteratorPos();
}
return false;
}
return true;
}
use of com.minecolonies.coremod.entity.ai.util.WorkerLoadOnlyStructureHandler in project minecolonies by Minecolonies.
the class AbstractEntityAIStructureWithWorkOrder method requestMaterials.
@Override
public boolean requestMaterials() {
StructurePhasePlacementResult result;
final WorkerLoadOnlyStructureHandler structure = new WorkerLoadOnlyStructureHandler(world, structurePlacer.getB().getWorldPos(), structurePlacer.getB().getBluePrint(), new PlacementSettings(), true, this);
if (job.getWorkOrder().getIteratorType().isEmpty() && getOwnBuilding().hasModule(ISettingsModule.class) && getOwnBuilding().getSetting(BuildingBuilder.BUILDING_MODE) != null) {
job.getWorkOrder().setIteratorType(getOwnBuilding().getSetting(BuildingBuilder.BUILDING_MODE).getValue());
}
final StructurePlacer placer = new StructurePlacer(structure, job.getWorkOrder().getIteratorType());
if (requestProgress == null) {
final AbstractBuildingStructureBuilder buildingWorker = getOwnBuilding();
buildingWorker.resetNeededResources();
requestProgress = NULL_POS;
requestState = RequestStage.SOLID;
}
final RequestStage currState = requestState;
switch(currState) {
case SOLID:
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> !info.getBlockInfo().getState().getMaterial().isSolid() || isDecoItem(info.getBlockInfo().getState().getBlock()))), false);
requestProgress = result.getIteratorPos();
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
getOwnBuilding().addNeededResource(stack, stack.getCount());
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.DECO;
}
return false;
case DECO:
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getBlockInfo().getState().getMaterial().isSolid() && !isDecoItem(info.getBlockInfo().getState().getBlock()))), false);
requestProgress = result.getIteratorPos();
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
getOwnBuilding().addNeededResource(stack, stack.getCount());
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.ENTITIES;
}
return false;
case ENTITIES:
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getEntities().length == 0)), true);
requestProgress = result.getIteratorPos();
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
getOwnBuilding().addNeededResource(stack, stack.getCount());
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.SOLID;
requestProgress = null;
return true;
}
return false;
default:
return true;
}
}
Aggregations