use of com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder 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.colony.buildings.AbstractBuildingStructureBuilder in project minecolonies by Minecolonies.
the class AbstractEntityAIStructure method hasListOfResInInvOrRequest.
/**
* Check the placers inventory for the items in the itemList and remove it of the list if found.
*
* @param placer the placer.
* @param itemList the list to check.
* @param force if force insertion.
* @return true if need to request.
*/
public static <J extends AbstractJobStructure<?, J>, B extends AbstractBuildingStructureBuilder> ItemCheckResult hasListOfResInInvOrRequest(@NotNull final AbstractEntityAIStructure<J, B> placer, final List<ItemStack> itemList, final boolean force) {
for (final ItemStack stack : itemList) {
if (!InventoryUtils.hasItemInItemHandler(placer.getInventory(), stack1 -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, stack1)) && !placer.getOwnBuilding().hasResourceInBucket(stack)) {
return RECALC;
}
}
final List<ItemStack> foundStacks = InventoryUtils.filterItemHandler(placer.getWorker().getInventoryCitizen(), itemStack -> itemList.stream().anyMatch(targetStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(targetStack, itemStack)));
if (force) {
for (final ItemStack foundStack : new ArrayList<>(foundStacks)) {
final Optional<ItemStack> opt = itemList.stream().filter(targetStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(targetStack, foundStack)).findFirst();
if (opt.isPresent()) {
final ItemStack stack = opt.get();
itemList.remove(stack);
if (stack.getCount() > foundStack.getCount()) {
stack.setCount(stack.getCount() - foundStack.getCount());
itemList.add(stack);
}
}
}
} else {
itemList.removeIf(itemStack -> ItemStackUtils.isEmpty(itemStack) || foundStacks.stream().anyMatch(target -> ItemStackUtils.compareItemStacksIgnoreStackSize(target, itemStack)));
}
itemList.removeIf(itemstack -> itemstack.getItem() instanceof BlockItem && isBlockFree(((BlockItem) itemstack.getItem()).getBlock()));
final Map<ItemStorage, Integer> list = new HashMap<>();
for (final ItemStack stack : itemList) {
ItemStorage tempStorage = new ItemStorage(stack.copy());
if (list.containsKey(tempStorage)) {
final int oldSize = list.get(tempStorage);
tempStorage.setAmount(tempStorage.getAmount() + oldSize);
}
list.put(tempStorage, placer.getTotalAmount(tempStorage.getItemStack()).getCount());
}
for (final Map.Entry<ItemStorage, Integer> placedStack : list.entrySet()) {
if (ItemStackUtils.isEmpty(placedStack.getKey().getItemStack())) {
return FAIL;
}
final ImmutableList<IRequest<? extends IDeliverable>> requests = placer.getOwnBuilding().getOpenRequestsOfTypeFiltered(placer.getWorker().getCitizenData(), TypeConstants.DELIVERABLE, (IRequest<? extends IDeliverable> r) -> r.getRequest().matches(placedStack.getKey().getItemStack()));
final ImmutableList<IRequest<? extends IDeliverable>> completedRequests = placer.getOwnBuilding().getCompletedRequestsOfTypeFiltered(placer.getWorker().getCitizenData(), TypeConstants.DELIVERABLE, (IRequest<? extends IDeliverable> r) -> r.getRequest().matches(placedStack.getKey().getItemStack()));
if (requests.isEmpty() && completedRequests.isEmpty()) {
final com.minecolonies.api.colony.requestsystem.requestable.Stack stackRequest = new Stack(placedStack.getKey().getItemStack(), placedStack.getValue(), 1);
placer.getWorker().getCitizenData().createRequest(stackRequest);
placer.registerBlockAsNeeded(placedStack.getKey().getItemStack());
return FAIL;
} else {
for (final IRequest<? extends IDeliverable> request : requests) {
if (placer.worker.getCitizenJobHandler().getColonyJob().getAsyncRequests().contains(request.getId())) {
placer.worker.getCitizenJobHandler().getColonyJob().markRequestSync(request.getId());
}
}
for (final IRequest<? extends IDeliverable> request : completedRequests) {
if (placer.worker.getCitizenJobHandler().getColonyJob().getAsyncRequests().contains(request.getId())) {
placer.worker.getCitizenJobHandler().getColonyJob().markRequestSync(request.getId());
}
}
}
return FAIL;
}
return SUCCESS;
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder in project minecolonies by ldtteam.
the class AbstractEntityAIStructureWithWorkOrder method getTotalAmount.
/**
* Check how much of a certain stuck is actually required.
*
* @param stack the stack to check.
* @return the new stack with the correct amount.
*/
@Override
@Nullable
public ItemStack getTotalAmount(@Nullable final ItemStack stack) {
if (ItemStackUtils.isEmpty(stack)) {
return null;
}
final int hashCode = stack.hasTag() ? stack.getTag().hashCode() : 0;
final AbstractBuildingStructureBuilder buildingWorker = getOwnBuilding();
BuildingBuilderResource resource = buildingWorker.getNeededResources().get(stack.getDescriptionId() + "-" + hashCode);
if (resource == null) {
requestMaterials();
resource = buildingWorker.getNeededResources().get(stack.getDescriptionId() + "-" + hashCode);
}
if (resource == null) {
return stack;
}
final ItemStack resStack = new ItemStack(resource.getItem(), Math.min(STACKSIZE, resource.getAmount()));
resStack.setTag(resource.getItemStack().getTag());
return resStack;
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder 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.colony.buildings.AbstractBuildingStructureBuilder 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;
}
Aggregations