use of com.minecolonies.api.util.constant.Constants.STACKSIZE in project minecolonies by Minecolonies.
the class EntityAIConcreteMixer method mixConcrete.
/**
* Mix the concrete and mine it.
*
* @return next state.
*/
private IAIState mixConcrete() {
int slot = -1;
if (currentRequest != null && currentRecipeStorage != null) {
ItemStack inputStack = currentRecipeStorage.getCleanedInput().get(0).getItemStack();
if (CONCRETE.test(inputStack)) {
slot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), s -> ItemStackUtils.compareItemStacksIgnoreStackSize(s, inputStack));
} else {
return START_WORKING;
}
} else {
slot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), CONCRETE);
}
if (slot != -1) {
final ItemStack stack = worker.getInventoryCitizen().getStackInSlot(slot);
final Block block = ((BlockItem) stack.getItem()).getBlock();
final BlockPos posToPlace = getOwnBuilding().getBlockToPlace();
if (posToPlace != null) {
if (walkToBlock(posToPlace)) {
walkTo = posToPlace;
return START_WORKING;
}
walkTo = null;
if (InventoryUtils.attemptReduceStackInItemHandler(worker.getInventoryCitizen(), stack, 1)) {
world.setBlock(posToPlace, block.defaultBlockState().updateShape(Direction.DOWN, block.defaultBlockState(), world, posToPlace, posToPlace), 0x03);
}
return START_WORKING;
}
}
final BlockPos pos = getOwnBuilding().getBlockToMine();
if (pos != null) {
if (walkToBlock(pos)) {
walkTo = pos;
return START_WORKING;
}
walkTo = null;
if (mineBlock(pos)) {
this.resetActionsDone();
return CRAFT;
}
return START_WORKING;
}
if (InventoryUtils.hasItemInItemHandler(getOwnBuilding().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElseGet(null), CONCRETE)) {
needsCurrently = new Tuple<>(CONCRETE, STACKSIZE);
return GATHERING_REQUIRED_MATERIALS;
} else {
incrementActionsDone();
}
return START_WORKING;
}
use of com.minecolonies.api.util.constant.Constants.STACKSIZE in project minecolonies by ldtteam.
the class BuildingCook method buildingRequiresCertainAmountOfItem.
@Override
public int buildingRequiresCertainAmountOfItem(final ItemStack stack, final List<ItemStorage> localAlreadyKept, final boolean inventory) {
if (stack.isEmpty()) {
return 0;
}
if (inventory && getFirstModuleOccurance(MinimumStockModule.class).isStocked(stack)) {
return stack.getCount();
}
if (isAllowedFood(stack) && (localAlreadyKept.stream().filter(storage -> ISFOOD.test(storage.getItemStack())).mapToInt(ItemStorage::getAmount).sum() < STACKSIZE || !inventory)) {
final ItemStorage kept = new ItemStorage(stack);
if (localAlreadyKept.contains(kept)) {
kept.setAmount(localAlreadyKept.remove(localAlreadyKept.indexOf(kept)).getAmount());
}
localAlreadyKept.add(kept);
return 0;
}
final Predicate<ItemStack> allowedFuel = theStack -> getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST)).isItemInList(new ItemStorage(theStack));
if (allowedFuel.test(stack) && (localAlreadyKept.stream().filter(storage -> allowedFuel.test(storage.getItemStack())).mapToInt(ItemStorage::getAmount).sum() < STACKSIZE || !inventory)) {
final ItemStorage kept = new ItemStorage(stack);
if (localAlreadyKept.contains(kept)) {
kept.setAmount(localAlreadyKept.remove(localAlreadyKept.indexOf(kept)).getAmount());
}
localAlreadyKept.add(kept);
return 0;
}
return super.buildingRequiresCertainAmountOfItem(stack, localAlreadyKept, inventory);
}
use of com.minecolonies.api.util.constant.Constants.STACKSIZE in project minecolonies by ldtteam.
the class EntityAIConcreteMixer method mixConcrete.
/**
* Mix the concrete and mine it.
*
* @return next state.
*/
private IAIState mixConcrete() {
int slot = -1;
if (currentRequest != null && currentRecipeStorage != null) {
ItemStack inputStack = currentRecipeStorage.getCleanedInput().get(0).getItemStack();
if (CONCRETE.test(inputStack)) {
slot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), s -> ItemStackUtils.compareItemStacksIgnoreStackSize(s, inputStack));
} else {
return START_WORKING;
}
} else {
slot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), CONCRETE);
}
if (slot != -1) {
final ItemStack stack = worker.getInventoryCitizen().getStackInSlot(slot);
final Block block = ((BlockItem) stack.getItem()).getBlock();
final BlockPos posToPlace = getOwnBuilding().getBlockToPlace();
if (posToPlace != null) {
if (walkToBlock(posToPlace)) {
walkTo = posToPlace;
return START_WORKING;
}
walkTo = null;
if (InventoryUtils.attemptReduceStackInItemHandler(worker.getInventoryCitizen(), stack, 1)) {
world.setBlock(posToPlace, block.defaultBlockState().updateShape(Direction.DOWN, block.defaultBlockState(), world, posToPlace, posToPlace), 0x03);
}
return START_WORKING;
}
}
final BlockPos pos = getOwnBuilding().getBlockToMine();
if (pos != null) {
if (walkToBlock(pos)) {
walkTo = pos;
return START_WORKING;
}
walkTo = null;
if (mineBlock(pos)) {
this.resetActionsDone();
return CRAFT;
}
return START_WORKING;
}
if (InventoryUtils.hasItemInItemHandler(getOwnBuilding().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElseGet(null), CONCRETE)) {
needsCurrently = new Tuple<>(CONCRETE, STACKSIZE);
return GATHERING_REQUIRED_MATERIALS;
} else {
incrementActionsDone();
}
return START_WORKING;
}
use of com.minecolonies.api.util.constant.Constants.STACKSIZE in project minecolonies by Minecolonies.
the class BuildingCook method buildingRequiresCertainAmountOfItem.
@Override
public int buildingRequiresCertainAmountOfItem(final ItemStack stack, final List<ItemStorage> localAlreadyKept, final boolean inventory) {
if (stack.isEmpty()) {
return 0;
}
if (inventory && getFirstModuleOccurance(MinimumStockModule.class).isStocked(stack)) {
return stack.getCount();
}
if (isAllowedFood(stack) && (localAlreadyKept.stream().filter(storage -> ISFOOD.test(storage.getItemStack())).mapToInt(ItemStorage::getAmount).sum() < STACKSIZE || !inventory)) {
final ItemStorage kept = new ItemStorage(stack);
if (localAlreadyKept.contains(kept)) {
kept.setAmount(localAlreadyKept.remove(localAlreadyKept.indexOf(kept)).getAmount());
}
localAlreadyKept.add(kept);
return 0;
}
final Predicate<ItemStack> allowedFuel = theStack -> getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST)).isItemInList(new ItemStorage(theStack));
if (allowedFuel.test(stack) && (localAlreadyKept.stream().filter(storage -> allowedFuel.test(storage.getItemStack())).mapToInt(ItemStorage::getAmount).sum() < STACKSIZE || !inventory)) {
final ItemStorage kept = new ItemStorage(stack);
if (localAlreadyKept.contains(kept)) {
kept.setAmount(localAlreadyKept.remove(localAlreadyKept.indexOf(kept)).getAmount());
}
localAlreadyKept.add(kept);
return 0;
}
return super.buildingRequiresCertainAmountOfItem(stack, localAlreadyKept, inventory);
}
use of com.minecolonies.api.util.constant.Constants.STACKSIZE in project minecolonies by Minecolonies.
the class EntityAIWorkFarmer method prepareForFarming.
/**
* Prepares the farmer for farming. Also requests the tools and checks if the farmer has sufficient fields.
*
* @return the next IAIState
*/
@NotNull
private IAIState prepareForFarming() {
@Nullable final BuildingFarmer building = getOwnBuilding();
if (building == null || building.getBuildingLevel() < 1) {
return PREPARING;
}
if (!job.getTaskQueue().isEmpty() || getActionsDoneUntilDumping() <= job.getActionsDone()) {
return START_WORKING;
}
worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING);
final FarmerFieldModule module = building.getFirstModuleOccurance(FarmerFieldModule.class);
module.syncWithColony(world);
if (module.getFarmerFields().size() < getOwnBuilding().getBuildingLevel() && !module.assignManually()) {
searchAndAddFields();
}
if (module.getFarmerFields().size() == getOwnBuilding().getMaxBuildingLevel()) {
AdvancementUtils.TriggerAdvancementPlayersForColony(building.getColony(), AdvancementTriggers.MAX_FIELDS::trigger);
}
final int amountOfCompostInBuilding = InventoryUtils.getCountFromBuilding(getOwnBuilding(), this::isCompost);
final int amountOfCompostInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), this::isCompost);
if (amountOfCompostInBuilding + amountOfCompostInInv <= 0) {
if (getOwnBuilding().requestFertilizer() && !getOwnBuilding().hasWorkerOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(StackList.class))) {
final List<ItemStack> compostAbleItems = new ArrayList<>();
compostAbleItems.add(new ItemStack(ModItems.compost, 1));
compostAbleItems.add(new ItemStack(Items.BONE_MEAL, 1));
worker.getCitizenData().createRequestAsync(new StackList(compostAbleItems, FERTLIZER, STACKSIZE, 1));
}
} else if (amountOfCompostInInv <= 0 && amountOfCompostInBuilding > 0) {
needsCurrently = new Tuple<>(this::isCompost, STACKSIZE);
return GATHERING_REQUIRED_MATERIALS;
}
if (module.hasNoFields()) {
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_FREE_FIELDS), ChatPriority.BLOCKING));
}
worker.getCitizenData().setIdleAtJob(true);
return PREPARING;
}
worker.getCitizenData().setIdleAtJob(false);
// If the farmer has no currentField and there is no field which needs work, check fields.
if (module.getCurrentField() == null && module.getFieldToWorkOn(world) == null) {
module.resetFields();
return IDLE;
}
@Nullable final BlockPos currentField = module.getCurrentField();
final TileEntity entity = world.getBlockEntity(currentField);
if (entity instanceof ScarecrowTileEntity && ((ScarecrowTileEntity) entity).needsWork()) {
if (((ScarecrowTileEntity) entity).getFieldStage() == ScarecrowFieldStage.PLANTED && checkIfShouldExecute((ScarecrowTileEntity) entity, this::shouldHarvest)) {
return FARMER_HARVEST;
} else if (((ScarecrowTileEntity) entity).getFieldStage() == ScarecrowFieldStage.HOED) {
return canGoPlanting((ScarecrowTileEntity) entity, building);
} else if (((ScarecrowTileEntity) entity).getFieldStage() == ScarecrowFieldStage.EMPTY && checkIfShouldExecute((ScarecrowTileEntity) entity, pos -> this.shouldHoe(pos, (ScarecrowTileEntity) entity))) {
return FARMER_HOE;
}
((ScarecrowTileEntity) entity).nextState();
} else {
module.setCurrentField(null);
}
return PREPARING;
}
Aggregations