use of com.minecolonies.api.colony.requestsystem.location.ILocation in project minecolonies by Minecolonies.
the class EntityAIWorkDeliveryman method gatherItems.
/**
* Gather item from chest.
* Gathers only one stack of the item.
*
* @param request request to gather
*/
private AIState gatherItems(@NotNull final IRequest<? extends Delivery> request) {
final ILocation location = request.getRequest().getStart();
if (!location.isReachableFromLocation(worker.getLocation())) {
((BuildingDeliveryman) getOwnBuilding()).setBuildingToDeliver(null);
job.finishRequest(false);
return START_WORKING;
}
final TileEntity tileEntity = world.getTileEntity(location.getInDimensionLocation());
if (tileEntity instanceof TileEntityChest && !(tileEntity instanceof TileEntityColonyBuilding)) {
if (((TileEntityChest) tileEntity).numPlayersUsing == 0) {
this.world.addBlockEvent(tileEntity.getPos(), tileEntity.getBlockType(), 1, 1);
this.world.notifyNeighborsOfStateChange(tileEntity.getPos(), tileEntity.getBlockType(), true);
this.world.notifyNeighborsOfStateChange(tileEntity.getPos().down(), tileEntity.getBlockType(), true);
setDelay(DUMP_AND_GATHER_DELAY);
return getState();
}
this.world.addBlockEvent(tileEntity.getPos(), tileEntity.getBlockType(), 1, 0);
this.world.notifyNeighborsOfStateChange(tileEntity.getPos(), tileEntity.getBlockType(), true);
this.world.notifyNeighborsOfStateChange(tileEntity.getPos().down(), tileEntity.getBlockType(), true);
}
if (isInTileEntity(tileEntity, request.getRequest().getStack())) {
setDelay(DUMP_AND_GATHER_DELAY);
return DELIVERY;
}
((BuildingDeliveryman) getOwnBuilding()).setBuildingToDeliver(null);
job.finishRequest(true);
return START_WORKING;
}
use of com.minecolonies.api.colony.requestsystem.location.ILocation in project minecolonies by Minecolonies.
the class EntityAIWorkDeliveryman method deliver.
/**
* Deliver the items to the hut.
*
* @return the next state.
*/
private AIState deliver() {
if (job.isReturning()) {
return DUMPING;
}
final BuildingDeliveryman deliveryHut = (getOwnBuilding() instanceof BuildingDeliveryman) ? (BuildingDeliveryman) getOwnBuilding() : null;
final ILocation buildingToDeliver = deliveryHut == null ? null : deliveryHut.getBuildingToDeliver();
if (deliveryHut == null) {
return START_WORKING;
} else if (buildingToDeliver == null) {
if (job.getCurrentTask() != null && deliveryHut != null) {
final IRequest<? extends Delivery> request = job.getCurrentTask();
deliveryHut.setBuildingToDeliver(request.getRequest().getTarget());
return getState();
}
return START_WORKING;
}
worker.setLatestStatus(new TextComponentTranslation("com.minecolonies.coremod.status.delivering"));
if (!buildingToDeliver.isReachableFromLocation(worker.getLocation())) {
Log.getLogger().info(worker.getColony().getName() + ": " + worker.getName() + ": Can't inter dimension yet: ");
return START_WORKING;
}
if (!worker.isWorkerAtSiteWithMove(buildingToDeliver.getInDimensionLocation(), MIN_DISTANCE_TO_WAREHOUSE)) {
return DELIVERY;
}
final InvWrapper workerInventory = new InvWrapper(worker.getInventoryCitizen());
for (int i = 0; i < new InvWrapper(worker.getInventoryCitizen()).getSlots(); i++) {
final ItemStack stack = workerInventory.extractItem(i, Integer.MAX_VALUE, false);
if (ItemStackUtils.isEmpty(stack)) {
continue;
}
final TileEntity tileEntity = world.getTileEntity(buildingToDeliver.getInDimensionLocation());
final ItemStack insertionResultStack;
if (tileEntity instanceof TileEntityColonyBuilding && ((TileEntityColonyBuilding) tileEntity).getBuilding() instanceof AbstractBuildingWorker) {
final AbstractBuilding building = ((TileEntityColonyBuilding) tileEntity).getBuilding();
building.alterPickUpPriority(1);
insertionResultStack = InventoryUtils.forceItemStackToItemHandler(new InvWrapper((TileEntityColonyBuilding) tileEntity), stack, ((AbstractBuildingWorker) building)::isItemStackInRequest);
} else {
insertionResultStack = InventoryUtils.forceItemStackToItemHandler(new InvWrapper((TileEntityColonyBuilding) tileEntity), stack, itemStack -> false);
}
if (!ItemStackUtils.isEmpty(insertionResultStack)) {
if (ItemStack.areItemStacksEqual(insertionResultStack, stack)) {
// same stack, we could not deliver ?
if (buildingToDeliver instanceof TileEntityColonyBuilding && ((TileEntityColonyBuilding) tileEntity).getBuilding() instanceof AbstractBuildingWorker) {
chatSpamFilter.talkWithoutSpam(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_NAMEDCHESTFULL, ((AbstractBuildingWorker) ((TileEntityColonyBuilding) tileEntity).getBuilding()).getMainWorker().getName());
} else if (buildingToDeliver instanceof TileEntityColonyBuilding) {
chatSpamFilter.talkWithoutSpam(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL, new TextComponentString(" :" + ((TileEntityColonyBuilding) tileEntity).getBuilding().getSchematicName()));
} else {
chatSpamFilter.talkWithoutSpam(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL, new TextComponentString(buildingToDeliver.getInDimensionLocation().toString()));
}
}
// Insert the result back into the inventory so we do not loose it.
workerInventory.insertItem(i, insertionResultStack, false);
}
}
lastDelivery = deliveryHut.getBuildingToDeliver();
worker.addExperience(1.0D);
worker.setHeldItem(SLOT_HAND);
deliveryHut.setBuildingToDeliver(null);
job.finishRequest(true);
setDelay(WAIT_DELAY);
return START_WORKING;
}
use of com.minecolonies.api.colony.requestsystem.location.ILocation in project minecolonies by Minecolonies.
the class WarehouseRequestResolver method attemptResolve.
@Nullable
@Override
@SuppressWarnings("squid:LeftCurlyBraceStartLineCheck")
public /**
* Moving the curly braces really makes the code hard to read.
*/
List<IToken<?>> attemptResolve(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends IDeliverable> request) {
if (manager.getColony().getWorld().isRemote) {
return null;
}
final Colony colony = (Colony) manager.getColony();
final Set<TileEntityWareHouse> wareHouses = getWareHousesInColony(colony);
for (final TileEntityWareHouse wareHouse : wareHouses) {
ItemStack matchingStack = wareHouse.getFirstMatchingItemStackInWarehouse(itemStack -> request.getRequest().matches(itemStack));
if (ItemStackUtils.isEmpty(matchingStack)) {
continue;
}
matchingStack = matchingStack.copy();
matchingStack.setCount(Math.min(request.getRequest().getCount(), matchingStack.getCount()));
final ItemStack deliveryStack = matchingStack.copy();
request.setDelivery(deliveryStack.copy());
final BlockPos itemStackPos = wareHouse.getPositionOfChestWithItemStack(itemStack -> ItemStack.areItemsEqual(itemStack, deliveryStack));
final ILocation itemStackLocation = manager.getFactoryController().getNewInstance(TypeConstants.ILOCATION, itemStackPos, wareHouse.getWorld().provider.getDimension());
final Delivery delivery = new Delivery(itemStackLocation, request.getRequester().getRequesterLocation(), deliveryStack.copy());
final IToken<?> requestToken = manager.createRequest(new WarehouseRequestResolver(request.getRequester().getRequesterLocation(), request.getToken()), delivery);
return ImmutableList.of(requestToken);
}
return Lists.newArrayList();
}
use of com.minecolonies.api.colony.requestsystem.location.ILocation in project minecolonies by Minecolonies.
the class AbstractBuildingDependentRequestResolver method getBuilding.
@Override
@Nullable
public Optional<IRequester> getBuilding(@NotNull final IRequestManager manager, @NotNull final IToken<?> token) {
final IRequest request = manager.getRequestForToken(token);
if (request.getRequester() instanceof BuildingBasedRequester) {
final BuildingBasedRequester requester = (BuildingBasedRequester) request.getRequester();
final ILocation requesterLocation = requester.getRequesterLocation();
if (requesterLocation.equals(getRequesterLocation())) {
return requester.getBuilding(manager, token);
}
}
return Optional.empty();
}
use of com.minecolonies.api.colony.requestsystem.location.ILocation in project minecolonies by Minecolonies.
the class BuildingRequestResolverFactory method deserialize.
@NotNull
@Override
public BuildingRequestResolver deserialize(@NotNull final IFactoryController controller, @NotNull final NBTTagCompound nbt) {
final IToken token = controller.deserialize(nbt.getCompoundTag(NBT_TOKEN));
final ILocation location = controller.deserialize(nbt.getCompoundTag(NBT_LOCATION));
return new BuildingRequestResolver(location, token);
}
Aggregations