use of net.minecraftforge.items.wrapper.InvWrapper in project minecolonies by Minecolonies.
the class EntityAIWorkFarmer method plantCrop.
/**
* Plants the crop at a given location.
*
* @param item the crop.
* @param position the location.
*/
private boolean plantCrop(final ItemStack item, @NotNull final BlockPos position) {
final int slot = worker.findFirstSlotInInventoryWith(item.getItem(), item.getItemDamage());
if (slot == -1) {
return false;
} else {
@NotNull final IPlantable seed = (IPlantable) item.getItem();
world.setBlockState(position.up(), seed.getPlant(world, position));
new InvWrapper(getInventory()).extractItem(slot, 1, false);
requestSeeds = false;
//Flag 1+2 is needed for updates
return true;
}
}
use of net.minecraftforge.items.wrapper.InvWrapper in project minecolonies by Minecolonies.
the class EntityAIWorkDeliveryman method deliver.
/**
* Deliver the items to the hut.
*
* @return the next state.
*/
private AIState deliver() {
final BuildingDeliveryman deliveryHut = (getOwnBuilding() instanceof BuildingDeliveryman) ? (BuildingDeliveryman) getOwnBuilding() : null;
final AbstractBuilding buildingToDeliver = deliveryHut == null ? null : deliveryHut.getBuildingToDeliver();
if (deliveryHut == null || buildingToDeliver == null) {
return START_WORKING;
}
if (!worker.isWorkerAtSiteWithMove(buildingToDeliver.getLocation(), 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 (InventoryUtils.isItemStackEmpty(stack)) {
continue;
}
final ItemStack insertionResultStack = buildingToDeliver.forceTransferStack(stack, world);
if (!InventoryUtils.isItemStackEmpty(insertionResultStack)) {
if (ItemStack.areItemStacksEqual(insertionResultStack, stack)) {
//same stack, we could not deliver ?
if (buildingToDeliver instanceof AbstractBuildingWorker) {
chatSpamFilter.talkWithoutSpam(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_NAMEDCHESTFULL, ((AbstractBuildingWorker) buildingToDeliver).getWorker().getName());
} else {
chatSpamFilter.talkWithoutSpam(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL, new TextComponentString(" :" + buildingToDeliver.getSchematicName()));
}
}
//Insert the result back into the inventory so we do not loose it.
workerInventory.insertItem(i, insertionResultStack, false);
}
}
worker.addExperience(1.0D);
worker.setHeldItem(SLOT_HAND);
buildingToDeliver.setOnGoingDelivery(false);
deliveryHut.setBuildingToDeliver(null);
if (buildingToDeliver instanceof BuildingHome) {
((BuildingHome) buildingToDeliver).setFoodNeeded(false);
}
gatherTarget = buildingToDeliver.getLocation();
return GATHERING;
}
Aggregations