diff --git a/src/main/java/com/minecolonies/api/crafting/ItemStorage.java b/src/main/java/com/minecolonies/api/crafting/ItemStorage.java index 4b2fe881023..770b0095585 100755 --- a/src/main/java/com/minecolonies/api/crafting/ItemStorage.java +++ b/src/main/java/com/minecolonies/api/crafting/ItemStorage.java @@ -17,18 +17,21 @@ */ public class ItemStorage { + /** + * The stack to store. + */ + private final ItemStack stack; + /** * Set this to ignore the damage value in comparisons. */ protected final boolean shouldIgnoreDamageValue; + /** * Set this to ignore the damage value in comparisons. */ protected final boolean shouldIgnoreNBTValue; - /** - * The stack to store. - */ - private final ItemStack stack; + /** * Amount of the storage. */ @@ -119,7 +122,7 @@ public ItemStorage(@NotNull final Item item) /** * Creates an instance of the storage from JSON - * + * * @param jObject the JSON Object to parse */ public ItemStorage(@NotNull final JsonObject jObject) @@ -127,7 +130,7 @@ public ItemStorage(@NotNull final JsonObject jObject) if (jObject.has(ITEM_PROP)) { final ItemStack parsedStack = ItemStackUtils.idToItemStack(jObject.get(ITEM_PROP).getAsString()); - if (jObject.has(COUNT_PROP)) + if(jObject.has(COUNT_PROP)) { parsedStack.setCount(jObject.get(COUNT_PROP).getAsInt()); this.amount = jObject.get(COUNT_PROP).getAsInt(); @@ -137,16 +140,23 @@ public ItemStorage(@NotNull final JsonObject jObject) this.amount = parsedStack.getCount(); } this.stack = parsedStack; - if (jObject.has(MATCHTYPE_PROP)) + if(jObject.has(MATCHTYPE_PROP)) { String matchType = jObject.get(MATCHTYPE_PROP).getAsString(); - this.shouldIgnoreNBTValue = matchType.equals(MATCH_NBTIGNORE); + if(matchType.equals(MATCH_NBTIGNORE)) + { + this.shouldIgnoreNBTValue = true; + } + else // includes "exact" + { + this.shouldIgnoreNBTValue = false; + } } else { this.shouldIgnoreNBTValue = false; } - this.shouldIgnoreDamageValue = true; + this.shouldIgnoreDamageValue= true; } else { @@ -226,6 +236,14 @@ public boolean ignoreNBT() return shouldIgnoreNBTValue; } + @Override + public String toString() + { + final ItemStack stack = this.stack.copy(); + stack.setCount(this.amount); + return stack.toString(); + } + @Override public int hashCode() { @@ -246,30 +264,18 @@ public boolean equals(final Object o) } final ItemStorage that = (ItemStorage) o; - return ItemStackUtils.compareItemStacksIgnoreStackSize(that.getItemStack(), - this.getItemStack(), - !(this.shouldIgnoreDamageValue || that.shouldIgnoreDamageValue), - !(this.shouldIgnoreNBTValue || that.shouldIgnoreNBTValue)); - } - - @Override - public String toString() - { - final ItemStack stack = this.stack.copy(); - stack.setCount(this.amount); - return stack.toString(); + return ItemStackUtils.compareItemStacksIgnoreStackSize(that.getItemStack(), this.getItemStack(), !(this.shouldIgnoreDamageValue || that.shouldIgnoreDamageValue), !(this.shouldIgnoreNBTValue || that.shouldIgnoreNBTValue)); } /** * Ensure that two ItemStorage have the same comparison defintion - * * @param that the item to compare to * @return true if the comparisons match */ public boolean matchDefinitionEquals(ItemStorage that) { - return this.shouldIgnoreDamageValue == that.shouldIgnoreDamageValue - && this.shouldIgnoreNBTValue == that.shouldIgnoreNBTValue; + return this.shouldIgnoreDamageValue == that.shouldIgnoreDamageValue + && this.shouldIgnoreNBTValue == that.shouldIgnoreNBTValue; } /** @@ -305,7 +311,7 @@ public int getRemainingDurablityValue() /** * Is this an empty ItemStorage - * + * * @return true if empty */ public boolean isEmpty() @@ -315,7 +321,6 @@ public boolean isEmpty() /** * Make a copy of the ItemStorage - * * @return a copy */ public ItemStorage copy() @@ -323,11 +328,10 @@ public ItemStorage copy() ItemStorage newInstance = new ItemStorage(stack.copy(), shouldIgnoreDamageValue, shouldIgnoreNBTValue); newInstance.setAmount(amount); return newInstance; - } + } /** * Get an immutable version of this item storage - * * @return immutable wrapper */ public ImmutableItemStorage toImmutable() diff --git a/src/main/java/com/minecolonies/api/entity/citizen/citizenhandlers/ICitizenDiseaseHandler.java b/src/main/java/com/minecolonies/api/entity/citizen/citizenhandlers/ICitizenDiseaseHandler.java index 581b0acc2b1..5091f824578 100755 --- a/src/main/java/com/minecolonies/api/entity/citizen/citizenhandlers/ICitizenDiseaseHandler.java +++ b/src/main/java/com/minecolonies/api/entity/citizen/citizenhandlers/ICitizenDiseaseHandler.java @@ -1,7 +1,7 @@ package com.minecolonies.api.entity.citizen.citizenhandlers; import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; -import com.minecolonies.core.datalistener.DiseasesListener; +import com.minecolonies.core.datalistener.model.Disease; import net.minecraft.nbt.CompoundTag; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -43,7 +43,7 @@ public interface ICitizenDiseaseHandler * @return the disease instance. */ @Nullable - DiseasesListener.Disease getDisease(); + Disease getDisease(); /** * Cure the citizen. diff --git a/src/main/java/com/minecolonies/core/colony/buildings/workerbuildings/BuildingHospital.java b/src/main/java/com/minecolonies/core/colony/buildings/workerbuildings/BuildingHospital.java index 31f3776901f..b628b114a42 100755 --- a/src/main/java/com/minecolonies/core/colony/buildings/workerbuildings/BuildingHospital.java +++ b/src/main/java/com/minecolonies/core/colony/buildings/workerbuildings/BuildingHospital.java @@ -3,10 +3,11 @@ import com.google.common.collect.ImmutableList; import com.minecolonies.api.colony.ICitizenData; import com.minecolonies.api.colony.IColony; +import com.minecolonies.api.crafting.ItemStorage; import com.minecolonies.api.util.BlockPosUtil; -import com.minecolonies.api.util.ItemStackUtils; import com.minecolonies.api.util.constant.NbtTagConstants; import com.minecolonies.core.colony.buildings.AbstractBuilding; +import com.minecolonies.core.datalistener.model.Disease; import com.minecolonies.core.datalistener.DiseasesListener; import com.minecolonies.core.entity.ai.workers.util.Patient; import net.minecraft.core.BlockPos; @@ -206,9 +207,14 @@ public Map, Tuple> getRequiredItemsAndAmo */ private static boolean isCureItem(final ItemStack stack) { - return DiseasesListener.getDiseases().stream() - .flatMap(m -> m.cureItems().stream()) - .anyMatch(f -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, f.getItemStack(), !f.ignoreDamageValue(), !f.ignoreNBT())); + for (final Disease disease : DiseasesListener.getDiseases()) + { + for (final ItemStorage cureItem : disease.cureItems()) + { + return Disease.isCureItem(stack, cureItem); + } + } + return false; } /** diff --git a/src/main/java/com/minecolonies/core/datalistener/DiseasesListener.java b/src/main/java/com/minecolonies/core/datalistener/DiseasesListener.java index 6fc2d1dd9cb..7b5b32ad325 100644 --- a/src/main/java/com/minecolonies/core/datalistener/DiseasesListener.java +++ b/src/main/java/com/minecolonies/core/datalistener/DiseasesListener.java @@ -6,14 +6,13 @@ import com.google.gson.JsonObject; import com.minecolonies.api.colony.requestsystem.StandardFactoryController; import com.minecolonies.api.crafting.ItemStorage; -import com.minecolonies.api.util.ItemStackUtils; import com.minecolonies.core.Network; +import com.minecolonies.core.datalistener.model.Disease; import com.minecolonies.core.network.messages.client.colony.GlobalDiseaseSyncMessage; import com.minecolonies.core.util.RandomCollection; import io.netty.buffer.Unpooled; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.packs.resources.ResourceManager; @@ -21,7 +20,6 @@ import net.minecraft.util.GsonHelper; import net.minecraft.util.RandomSource; import net.minecraft.util.profiling.ProfilerFiller; -import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -29,7 +27,6 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.function.Predicate; /** * Loads and listens to diseases data. @@ -53,37 +50,6 @@ public class DiseasesListener extends SimpleJsonResourceReloadListener */ private static RandomCollection DISEASES = new RandomCollection<>(); - /** - * A possible disease. - * - * @param id the id of the disease. - * @param name the name of the disease. - * @param rarity the rarity of the disease. - * @param cureItems the list of items needed to heal. - */ - public record Disease(ResourceLocation id, Component name, int rarity, List cureItems) - { - /** - * Get the cure string containing all items required for the cure. - * - * @return the cure string. - */ - public Component getCureString() - { - final MutableComponent cureString = Component.literal(""); - for (int i = 0; i < cureItems.size(); i++) - { - final ItemStorage cureStack = cureItems.get(i); - cureString.append(String.valueOf(cureStack.getItemStack().getCount())).append(" ").append(cureStack.getItemStack().getHoverName()); - if (i != cureItems.size() - 1) - { - cureString.append(" + "); - } - } - return cureString; - } - } - /** * Default constructor. */ @@ -103,10 +69,10 @@ public static void sendGlobalDiseasesPackets(final ServerPlayer player) byteBuf.writeInt(DISEASES.getAll().size()); for (final Disease disease : DISEASES.getAll()) { - byteBuf.writeResourceLocation(disease.id); - byteBuf.writeComponent(disease.name); - byteBuf.writeInt(disease.rarity); - for (final ItemStorage cureItem : disease.cureItems) + byteBuf.writeResourceLocation(disease.id()); + byteBuf.writeComponent(disease.name()); + byteBuf.writeInt(disease.rarity()); + for (final ItemStorage cureItem : disease.cureItems()) { StandardFactoryController.getInstance().serialize(byteBuf, cureItem); } @@ -176,29 +142,6 @@ public static Disease getRandomDisease(final RandomSource random) return DISEASES.next(random); } - /** - * Predicate for the different usages to check if inventory contains a cure. - * - * @param cure the expected cure item. - * @return the predicate for checking if the cure exists. - */ - public static Predicate hasCureItem(final ItemStorage cure) - { - return stack -> isCureItem(stack, cure); - } - - /** - * Check if the given item is a cure item. - * - * @param stack the input stack. - * @param cure the cure item. - * @return true if so. - */ - public static boolean isCureItem(final ItemStack stack, final ItemStorage cure) - { - return ItemStackUtils.compareItemStacksIgnoreStackSize(stack, cure.getItemStack(), !cure.ignoreDamageValue(), !cure.ignoreNBT()); - } - @Override protected void apply( final @NotNull Map jsonElementMap, diff --git a/src/main/java/com/minecolonies/core/datalistener/model/Disease.java b/src/main/java/com/minecolonies/core/datalistener/model/Disease.java new file mode 100644 index 00000000000..c0755071bb3 --- /dev/null +++ b/src/main/java/com/minecolonies/core/datalistener/model/Disease.java @@ -0,0 +1,65 @@ +package com.minecolonies.core.datalistener.model; + +import com.minecolonies.api.crafting.ItemStorage; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; + +import java.util.List; +import java.util.Objects; +import java.util.function.Predicate; + +/** + * A possible disease. + * + * @param id the id of the disease. + * @param name the name of the disease. + * @param rarity the rarity of the disease. + * @param cureItems the list of items needed to heal. + */ +public record Disease(ResourceLocation id, Component name, int rarity, List cureItems) +{ + /** + * Predicate for the different usages to check if inventory contains a cure. + * + * @param cure the expected cure item. + * @return the predicate for checking if the cure exists. + */ + public static Predicate hasCureItem(final ItemStorage cure) + { + return stack -> isCureItem(stack, cure); + } + + /** + * Check if the given item is a cure item. + * + * @param stack the input stack. + * @param cure the cure item. + * @return true if so. + */ + public static boolean isCureItem(final ItemStack stack, final ItemStorage cure) + { + return Objects.equals(new ItemStorage(stack), cure); + } + + /** + * Get the cure string containing all items required for the cure. + * + * @return the cure string. + */ + public Component getCureString() + { + final MutableComponent cureString = Component.literal(""); + for (int i = 0; i < cureItems.size(); i++) + { + final ItemStorage cureStack = cureItems.get(i); + cureString.append(String.valueOf(cureStack.getItemStack().getCount())).append(" ").append(cureStack.getItemStack().getHoverName()); + if (i != cureItems.size() - 1) + { + cureString.append(" + "); + } + } + return cureString; + } +} diff --git a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISickTask.java b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISickTask.java index 5e698ccae7a..3d797fff7f7 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISickTask.java +++ b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISickTask.java @@ -17,7 +17,7 @@ import com.minecolonies.core.colony.buildings.workerbuildings.BuildingHospital; import com.minecolonies.core.colony.interactionhandling.StandardInteraction; import com.minecolonies.core.datalistener.DiseasesListener; -import com.minecolonies.core.datalistener.DiseasesListener.Disease; +import com.minecolonies.core.datalistener.model.Disease; import com.minecolonies.core.entity.citizen.EntityCitizen; import com.minecolonies.core.network.messages.client.CircleParticleEffectMessage; import net.minecraft.core.BlockPos; @@ -78,23 +78,42 @@ public class EntityAISickTask implements IStateAI /** * Citizen data. */ - private final ICitizenData citizenData; - /** - * The citizen assigned to this task. - */ - private final EntityCitizen citizen; + private final ICitizenData citizenData; + /** * The waiting ticks. */ - private int waitingTicks = 0; + private int waitingTicks = 0; + /** * The bed the citizen is sleeping in. */ - private BlockPos usedBed; + private BlockPos usedBed; + + /** + * The different types of AIStates related to eating. + */ + public enum DiseaseState implements IState + { + CHECK_FOR_CURE, + GO_TO_HUT, + SEARCH_HOSPITAL, + GO_TO_HOSPITAL, + WAIT_FOR_CURE, + FIND_EMPTY_BED, + APPLY_CURE, + WANDER + } + + /** + * The citizen assigned to this task. + */ + private final EntityCitizen citizen; + /** * Restaurant to which the citizen should path. */ - private BlockPos placeToPath; + private BlockPos placeToPath; /** * Instantiates this task. @@ -227,12 +246,13 @@ private IState applyCure() return CHECK_FOR_CURE; } - if (citizen.getCitizenDiseaseHandler().getDisease() == null) + final Disease disease = citizen.getCitizenDiseaseHandler().getDisease(); + if (disease == null) { return CitizenAIState.IDLE; } - final List list = citizen.getCitizenDiseaseHandler().getDisease().cureItems(); + final List list = disease.cureItems(); if (!list.isEmpty()) { citizen.setItemInHand(InteractionHand.MAIN_HAND, list.get(citizen.getRandom().nextInt(list.size())).getItemStack()); @@ -267,7 +287,7 @@ private void cure() { for (final ItemStorage cure : disease.cureItems()) { - final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(citizen, DiseasesListener.hasCureItem(cure)); + final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(citizen, Disease.hasCureItem(cure)); if (slot != -1) { citizenData.getInventory().extractItem(slot, 1, false); @@ -397,23 +417,22 @@ private IState goToHospital() */ private IState searchHospital() { - final Disease disease = citizen.getCitizenDiseaseHandler().getDisease(); - if (disease == null) - { - return CitizenAIState.IDLE; - } - final IColony colony = citizenData.getColony(); + final Disease disease = citizen.getCitizenDiseaseHandler().getDisease(); placeToPath = colony.getBuildingManager().getBestBuilding(citizen, BuildingHospital.class); if (placeToPath == null) { + if (disease == null) + { + return CitizenAIState.IDLE; + } citizenData.triggerInteraction(new StandardInteraction(Component.translatable(NO_HOSPITAL, disease.name(), disease.getCureString()), Component.translatable(NO_HOSPITAL), ChatPriority.BLOCKING)); return WANDER; } - else + else if (disease != null) { citizenData.triggerInteraction(new StandardInteraction(Component.translatable(WAITING_FOR_CURE, disease.name(), disease.getCureString()), Component.translatable(WAITING_FOR_CURE), @@ -440,10 +459,9 @@ private IState checkForCure() } return GO_TO_HUT; } - for (final ItemStorage cure : disease.cureItems()) { - final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(citizen, DiseasesListener.hasCureItem(cure)); + final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(citizen, Disease.hasCureItem(cure)); if (slot == -1) { if (citizen.getCitizenDiseaseHandler().isSick()) @@ -476,19 +494,4 @@ public void start() { citizen.getCitizenData().setVisibleStatus(VisibleCitizenStatus.SICK); } - - /** - * The different types of AIStates related to eating. - */ - public enum DiseaseState implements IState - { - CHECK_FOR_CURE, - GO_TO_HUT, - SEARCH_HOSPITAL, - GO_TO_HOSPITAL, - WAIT_FOR_CURE, - FIND_EMPTY_BED, - APPLY_CURE, - WANDER - } } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkHealer.java b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkHealer.java index ff7f60b8d90..b83ede64a6e 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkHealer.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkHealer.java @@ -10,25 +10,22 @@ import com.minecolonies.api.entity.ai.statemachine.AITarget; import com.minecolonies.api.entity.ai.statemachine.states.IAIState; import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; -import com.minecolonies.api.util.BlockPosUtil; -import com.minecolonies.api.util.InventoryUtils; -import com.minecolonies.api.util.Tuple; -import com.minecolonies.api.util.WorldUtil; +import com.minecolonies.api.util.*; import com.minecolonies.core.Network; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingHospital; import com.minecolonies.core.colony.interactionhandling.StandardInteraction; import com.minecolonies.core.colony.jobs.JobHealer; -import com.minecolonies.core.datalistener.DiseasesListener; -import com.minecolonies.core.datalistener.DiseasesListener.Disease; +import com.minecolonies.core.datalistener.model.Disease; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract; import com.minecolonies.core.entity.ai.workers.util.Patient; import com.minecolonies.core.entity.citizen.EntityCitizen; import com.minecolonies.core.network.messages.client.CircleParticleEffectMessage; import com.minecolonies.core.network.messages.client.StreamParticleEffectMessage; +import net.minecraft.world.entity.player.Player; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Player; -import net.minecraftforge.common.capabilities.ICapabilityProvider; +import net.minecraftforge.common.capabilities.ForgeCapabilities; +import net.minecraftforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; import static com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState.*; @@ -47,23 +44,27 @@ public class EntityAIWorkHealer extends AbstractEntityAIInteract> completed = building.getCompletedRequestsOfType(worker.getCitizenData(), TypeToken.of(Stack.class)); for (final ItemStorage cure : disease.cureItems()) { - if (!InventoryUtils.hasItemInProvider(worker, DiseasesListener.hasCureItem(cure))) + if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), Disease.hasCureItem(cure))) { - if (InventoryUtils.getItemCountInProvider(building, DiseasesListener.hasCureItem(cure)) >= cure.getAmount()) + if (InventoryUtils.getItemCountInItemHandler(building.getCapability(ForgeCapabilities.ITEM_HANDLER).orElseGet(null), + Disease.hasCureItem(cure)) >= cure.getAmount()) { - needsCurrently = new Tuple<>(DiseasesListener.hasCureItem(cure), cure.getAmount()); + needsCurrently = new Tuple<>(Disease.hasCureItem(cure), cure.getAmount()); return GATHERING_REQUIRED_MATERIALS; } boolean hasCureRequested = false; for (final IRequest request : list) { - if (DiseasesListener.isCureItem(request.getRequest().getStack(), cure)) + if (Disease.isCureItem(request.getRequest().getStack(), cure)) { hasCureRequested = true; break; @@ -174,7 +177,7 @@ private IAIState decide() } for (final IRequest request : completed) { - if (DiseasesListener.isCureItem(request.getRequest().getStack(), cure)) + if (Disease.isCureItem(request.getRequest().getStack(), cure)) { hasCureRequested = true; break; @@ -202,7 +205,7 @@ private IAIState decide() return CURE; } - if (!hasCureInInventory(disease, citizen)) + if (!hasCureInInventory(disease, citizen.getInventoryCitizen())) { patient.setState(Patient.PatientState.NEW); return DECIDE; @@ -221,7 +224,7 @@ private IAIState decide() final ICitizenData data = building.getColony().getCitizenManager().getRandomCitizen(); if (data.getEntity().isPresent() && data.getEntity().get().getHealth() < 10.0 - && BlockPosUtil.getDistance2D(data.getEntity().get().blockPosition(), building.getPosition()) < building.getBuildingLevel() * 40L) + && BlockPosUtil.getDistance2D(data.getEntity().get().blockPosition(), building.getPosition()) < building.getBuildingLevel() * 40) { remotePatient = data; return WANDER; @@ -242,7 +245,7 @@ private IAIState requestCure() } final ICitizenData data = building.getColony().getCitizenManager().getCivilian(currentPatient.getId()); - if (data == null || data.getEntity().isEmpty() || !data.getEntity().get().getCitizenDiseaseHandler().isSick()) + if (data == null || !data.getEntity().isPresent() || !data.getEntity().get().getCitizenDiseaseHandler().isSick()) { currentPatient = null; return DECIDE; @@ -267,12 +270,13 @@ private IAIState requestCure() for (final ItemStorage cure : disease.cureItems()) { - if (!InventoryUtils.hasItemInProvider(worker, DiseasesListener.hasCureItem(cure)) && !InventoryUtils.hasItemInProvider(building, DiseasesListener.hasCureItem(cure))) + if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), Disease.hasCureItem(cure)) + && !InventoryUtils.hasItemInItemHandler(building.getCapability(ForgeCapabilities.ITEM_HANDLER).orElseGet(null), Disease.hasCureItem(cure))) { boolean hasRequest = false; for (final IRequest request : list) { - if (DiseasesListener.isCureItem(request.getRequest().getStack(), cure)) + if (Disease.isCureItem(request.getRequest().getStack(), cure)) { hasRequest = true; break; @@ -280,7 +284,7 @@ private IAIState requestCure() } for (final IRequest request : completed) { - if (DiseasesListener.isCureItem(request.getRequest().getStack(), cure)) + if (Disease.isCureItem(request.getRequest().getStack(), cure)) { hasRequest = true; break; @@ -311,7 +315,7 @@ private IAIState cure() } final ICitizenData data = building.getColony().getCitizenManager().getCivilian(currentPatient.getId()); - if (data == null || data.getEntity().isEmpty() || !data.getEntity().get().getCitizenDiseaseHandler().isSick()) + if (data == null || !data.getEntity().isPresent() || !data.getEntity().get().getCitizenDiseaseHandler().isSick()) { currentPatient = null; return DECIDE; @@ -332,15 +336,15 @@ private IAIState cure() return DECIDE; } - if (!hasCureInInventory(disease, worker)) + if (!hasCureInInventory(disease, worker.getInventoryCitizen())) { - if (hasCureInInventory(disease, building)) + if (hasCureInInventory(disease, building.getCapability(ForgeCapabilities.ITEM_HANDLER).orElseGet(null))) { for (final ItemStorage cure : disease.cureItems()) { - if (InventoryUtils.getItemCountInProvider(worker, DiseasesListener.hasCureItem(cure)) < cure.getAmount()) + if (InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), Disease.hasCureItem(cure)) < cure.getAmount()) { - needsCurrently = new Tuple<>(DiseasesListener.hasCureItem(cure), 1); + needsCurrently = new Tuple<>(Disease.hasCureItem(cure), 1); return GATHERING_REQUIRED_MATERIALS; } } @@ -349,19 +353,23 @@ private IAIState cure() return DECIDE; } - if (!hasCureInInventory(disease, citizen)) + if (!hasCureInInventory(disease, citizen.getInventoryCitizen())) { for (final ItemStorage cure : disease.cureItems()) { - if (InventoryUtils.getItemCountInProvider(citizen, DiseasesListener.hasCureItem(cure)) < cure.getAmount()) + if (InventoryUtils.getItemCountInItemHandler(citizen.getInventoryCitizen(), Disease.hasCureItem(cure)) < cure.getAmount()) { - if (InventoryUtils.isProviderFull(citizen)) + if (InventoryUtils.isItemHandlerFull(citizen.getInventoryCitizen())) { data.triggerInteraction(new StandardInteraction(Component.translatable(PATIENT_FULL_INVENTORY), ChatPriority.BLOCKING)); currentPatient = null; return DECIDE; } - InventoryUtils.transferXOfFirstSlotInProviderWithIntoNextFreeSlotInProvider(worker, DiseasesListener.hasCureItem(cure), cure.getAmount(), citizen); + InventoryUtils.transferXOfFirstSlotInItemHandlerWithIntoNextFreeSlotInItemHandler( + worker.getInventoryCitizen(), + Disease.hasCureItem(cure), + cure.getAmount(), citizen.getInventoryCitizen() + ); } } } @@ -385,7 +393,7 @@ private IAIState freeCure() } final ICitizenData data = building.getColony().getCitizenManager().getCivilian(currentPatient.getId()); - if (data == null || data.getEntity().isEmpty() || !data.getEntity().get().getCitizenDiseaseHandler().isSick()) + if (data == null || !data.getEntity().isPresent() || !data.getEntity().get().getCitizenDiseaseHandler().isSick()) { currentPatient = null; return DECIDE; @@ -455,12 +463,6 @@ public IAIState getStateAfterPickUp() return CURE; } - @Override - public Class getExpectedBuildingClass() - { - return BuildingHospital.class; - } - /** * Wander around in the colony from citizen to citizen. * @@ -468,7 +470,7 @@ public Class getExpectedBuildingClass() */ private IAIState wander() { - if (remotePatient == null || remotePatient.getEntity().isEmpty()) + if (remotePatient == null || !remotePatient.getEntity().isPresent()) { return DECIDE; } @@ -507,19 +509,25 @@ private boolean testRandomCureChance() /** * Check if the cure for a certain illness is in the inv. * - * @param disease the disease to check. - * @param capabilityProvider the capability provider to check. + * @param disease the disease to check. + * @param handler the inventory to check. * @return true if so. */ - private boolean hasCureInInventory(final Disease disease, final ICapabilityProvider capabilityProvider) + private boolean hasCureInInventory(final Disease disease, final IItemHandler handler) { for (final ItemStorage cure : disease.cureItems()) { - if (InventoryUtils.getItemCountInProvider(capabilityProvider, DiseasesListener.hasCureItem(cure)) < cure.getAmount()) + if (InventoryUtils.getItemCountInItemHandler(handler, Disease.hasCureItem(cure)) < cure.getAmount()) { return false; } } return true; } + + @Override + public Class getExpectedBuildingClass() + { + return BuildingHospital.class; + } } diff --git a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenDiseaseHandler.java b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenDiseaseHandler.java index c72b236be6c..bace9c30863 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenDiseaseHandler.java +++ b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenDiseaseHandler.java @@ -9,6 +9,7 @@ import com.minecolonies.core.colony.buildings.workerbuildings.BuildingCook; import com.minecolonies.core.colony.jobs.AbstractJobGuard; import com.minecolonies.core.colony.jobs.JobHealer; +import com.minecolonies.core.datalistener.model.Disease; import com.minecolonies.core.datalistener.DiseasesListener; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -56,7 +57,7 @@ public class CitizenDiseaseHandler implements ICitizenDiseaseHandler * The disease the citizen has, empty if none. */ @Nullable - private DiseasesListener.Disease disease; + private Disease disease; /** * Special immunity time after being cured. @@ -174,7 +175,7 @@ public void read(final CompoundTag compound) @Override @Nullable - public DiseasesListener.Disease getDisease() + public Disease getDisease() { return this.disease; }