use of com.minecolonies.api.util.Tuple 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 = building.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 = building.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(building.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.Tuple in project minecolonies by Minecolonies.
the class AbstractWindowWorkerModuleBuilding method onOpened.
@Override
public void onOpened() {
super.onOpened();
final List<Tuple<String, Integer>> workers = new ArrayList<>();
for (final WorkerBuildingModuleView module : buildingView.getModuleViews(WorkerBuildingModuleView.class)) {
for (final int worker : module.getAssignedCitizens()) {
workers.add(new Tuple<>(new TranslationTextComponent(module.getJobEntry().getTranslationKey()).getString(), worker));
}
}
if (findPaneByID(LIST_WORKERS) != null) {
ScrollingList workerList = findPaneOfTypeByID(LIST_WORKERS, ScrollingList.class);
workerList.setDataProvider(new ScrollingList.DataProvider() {
@Override
public int getElementCount() {
return workers.size();
}
@Override
public void updateElement(final int index, @NotNull final Pane rowPane) {
final ICitizenDataView worker = building.getColony().getCitizen(workers.get(index).getB());
if (worker != null) {
rowPane.findPaneOfTypeByID(LABEL_WORKERNAME, Text.class).setText(new TranslationTextComponent(workers.get(index).getA()).getString() + ": " + worker.getName());
}
}
});
}
updatePriorityLabel();
}
use of com.minecolonies.api.util.Tuple 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() {
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() < building.getBuildingLevel() && !module.assignManually()) {
searchAndAddFields();
}
if (module.getFarmerFields().size() == building.getMaxBuildingLevel()) {
AdvancementUtils.TriggerAdvancementPlayersForColony(building.getColony(), AdvancementTriggers.MAX_FIELDS::trigger);
}
final int amountOfCompostInBuilding = InventoryUtils.hasBuildingEnoughElseCount(building, this::isCompost, 1);
final int amountOfCompostInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), this::isCompost);
if (amountOfCompostInBuilding + amountOfCompostInInv <= 0) {
if (building.requestFertilizer() && !building.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, RequestSystemTranslationConstants.REQUEST_TYPE_FERTILIZER, 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, pos -> this.findHarvestableSurface(pos) != null)) {
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.findHoeableSurface(pos, (ScarecrowTileEntity) entity) != null)) {
return FARMER_HOE;
}
((ScarecrowTileEntity) entity).nextState();
} else {
module.setCurrentField(null);
}
return PREPARING;
}
use of com.minecolonies.api.util.Tuple in project minecolonies by Minecolonies.
the class EntityAIWorkPlanter method checkSoil.
/**
* Check the selected soil on what to do.
*
* @return next state to go to.
*/
private IAIState checkSoil() {
if (plantableSoilPos == null) {
return START_WORKING;
}
final BuildingPlantation plantation = building;
final List<Item> availablePlants = plantation.getAvailablePlants();
if (isItemPositionAir(plantableSoilPos)) {
final Item currentItem = plantableSoilPos.getCombination().getItem();
final ItemStack currentStack = new ItemStack(currentItem);
if (!availablePlants.contains(currentItem)) {
return START_WORKING;
}
final int plantInInv = InventoryUtils.getItemCountInItemHandler((worker.getInventoryCitizen()), itemStack -> itemStack.sameItem(currentStack));
final int plantInBuilding = InventoryUtils.getCountFromBuilding(building, itemStack -> itemStack.sameItem(currentStack));
if (plantInInv + plantInBuilding <= 0) {
requestPlantable(currentItem);
return START_WORKING;
}
if (plantInInv == 0 && plantInBuilding > 0) {
needsCurrently = new Tuple<>(itemStack -> itemStack.sameItem(currentStack), Math.min(plantInBuilding, PLANT_TO_REQUEST));
return GATHERING_REQUIRED_MATERIALS;
}
return PLANTATION_PLANT;
} else {
if (positionHasInvalidBlock(plantableSoilPos)) {
return PLANTATION_CLEAR_OBSTACLE;
}
if (isSufficientHeight(plantableSoilPos) || !availablePlants.contains(plantableSoilPos.getCombination().getItem())) {
return PLANTATION_FARM;
}
}
return START_WORKING;
}
use of com.minecolonies.api.util.Tuple in project minecolonies by Minecolonies.
the class CitizenDataView method deserialize.
@Override
public void deserialize(@NotNull final PacketBuffer buf) {
name = buf.readUtf(32767);
female = buf.readBoolean();
entityId = buf.readInt();
paused = buf.readBoolean();
isChild = buf.readBoolean();
homeBuilding = buf.readBoolean() ? buf.readBlockPos() : null;
workBuilding = buf.readBoolean() ? buf.readBlockPos() : null;
// Attributes
health = buf.readFloat();
maxHealth = buf.readFloat();
saturation = buf.readDouble();
happiness = buf.readDouble();
citizenSkillHandler.read(buf.readNbt());
job = buf.readUtf(32767);
colonyId = buf.readInt();
final CompoundNBT compound = buf.readNbt();
inventory = new InventoryCitizen(this.name, true);
final ListNBT ListNBT = compound.getList("inventory", 10);
this.inventory.read(ListNBT);
this.inventory.setHeldItem(Hand.MAIN_HAND, compound.getInt(TAG_HELD_ITEM_SLOT));
this.inventory.setHeldItem(Hand.OFF_HAND, compound.getInt(TAG_OFFHAND_HELD_ITEM_SLOT));
position = buf.readBlockPos();
citizenChatOptions.clear();
final int size = buf.readInt();
for (int i = 0; i < size; i++) {
final CompoundNBT compoundNBT = buf.readNbt();
final ServerCitizenInteraction handler = (ServerCitizenInteraction) MinecoloniesAPIProxy.getInstance().getInteractionResponseHandlerDataManager().createFrom(this, compoundNBT);
citizenChatOptions.put(handler.getInquiry(), handler);
}
sortedInteractions = citizenChatOptions.values().stream().sorted(Comparator.comparingInt(e -> e.getPriority().getPriority())).collect(Collectors.toList());
citizenHappinessHandler.read(buf.readNbt());
int statusindex = buf.readInt();
statusIcon = statusindex >= 0 ? VisibleCitizenStatus.getForId(statusindex) : null;
if (buf.readBoolean()) {
final IColonyView colonyView = IColonyManager.getInstance().getColonyView(colonyId, Minecraft.getInstance().level.dimension());
jobView = IJobDataManager.getInstance().createViewFrom(colonyView, this, buf);
} else {
jobView = null;
}
children.clear();
siblings.clear();
partner = buf.readInt();
final int siblingsSize = buf.readInt();
for (int i = 0; i < siblingsSize; i++) {
siblings.add(buf.readInt());
}
final int childrenSize = buf.readInt();
for (int i = 0; i < childrenSize; i++) {
children.add(buf.readInt());
}
final String parentA = buf.readUtf();
final String parentB = buf.readUtf();
parents = new Tuple<>(parentA, parentB);
}
Aggregations