From 8177391f2335699c23740f9db714a6a03b71b787 Mon Sep 17 00:00:00 2001 From: Ray Neiheiser Date: Sun, 27 Oct 2024 16:57:26 +0100 Subject: [PATCH] Revert "thodor cherrypick this" This reverts commit 4015e79da4d66fa8f61f67a133fdf473ccfc7501. --- .../ICitizenDiseaseHandler.java | 4 +- .../api/util/constant/CitizenConstants.java | 5 --- .../util/constant/TranslationConstants.java | 4 +- .../workerbuildings/BuildingHospital.java | 17 +------ .../entity/ai/minimal/EntityAISickTask.java | 16 +++---- .../CitizenDiseaseHandler.java | 45 ++++--------------- 6 files changed, 21 insertions(+), 70 deletions(-) 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 5c47974e067..76bc1bb0f56 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,8 +1,6 @@ package com.minecolonies.api.entity.citizen.citizenhandlers; import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; -import com.minecolonies.core.colony.buildings.workerbuildings.BuildingHospital; -import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import org.jetbrains.annotations.NotNull; @@ -69,5 +67,5 @@ public interface ICitizenDiseaseHandler /** * Sets a flag that the citizen is now at the hospital. */ - void setSleepsAtHospital(final BuildingHospital buildingHospital); + void setSleepsAtHospital(final boolean isAtHospital); } diff --git a/src/main/java/com/minecolonies/api/util/constant/CitizenConstants.java b/src/main/java/com/minecolonies/api/util/constant/CitizenConstants.java index 2c393c42525..eedc5230d21 100755 --- a/src/main/java/com/minecolonies/api/util/constant/CitizenConstants.java +++ b/src/main/java/com/minecolonies/api/util/constant/CitizenConstants.java @@ -218,11 +218,6 @@ public final class CitizenConstants */ public static final String TAG_IMMUNITY = "immunity"; - /** - * Hospital pos tag - */ - public static final String TAG_HOSPITAL = "hospital"; - /** * Noon day time. */ diff --git a/src/main/java/com/minecolonies/api/util/constant/TranslationConstants.java b/src/main/java/com/minecolonies/api/util/constant/TranslationConstants.java index 04fea8a4853..cb29cae13c0 100755 --- a/src/main/java/com/minecolonies/api/util/constant/TranslationConstants.java +++ b/src/main/java/com/minecolonies/api/util/constant/TranslationConstants.java @@ -654,9 +654,9 @@ public final class TranslationConstants @NonNls public static final String FOOD_QUALITY_TOOLTIP = "com.minecolonies.core.gui.restaurant.foodquality"; @NonNls - public static final String FOOD_QUALITY = "foodquality"; + public static final String FOOD_QUALITY = ".foodquality"; @NonNls - public static final String FOOD_DIVERSITY = "fooddiversity"; + public static final String FOOD_DIVERSITY = ".fooddiversity"; @NonNls public static final String URGENT = ".urgent"; 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 43ae80cf535..96056c78ee6 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 @@ -1,19 +1,14 @@ package com.minecolonies.core.colony.buildings.workerbuildings; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; import com.google.common.collect.ImmutableList; import com.minecolonies.api.colony.ICitizenData; import com.minecolonies.api.colony.IColony; import com.minecolonies.api.colony.IColonyManager; -import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; import com.minecolonies.api.util.BlockPosUtil; import com.minecolonies.api.util.Disease; import com.minecolonies.api.util.constant.NbtTagConstants; -import com.minecolonies.core.colony.CitizenData; import com.minecolonies.core.colony.buildings.AbstractBuilding; import com.minecolonies.core.entity.ai.workers.util.Patient; -import com.minecolonies.core.entity.citizen.EntityCitizen; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; @@ -54,7 +49,7 @@ public class BuildingHospital extends AbstractBuilding * Map from beds to patients, 0 is empty. */ @NotNull - private final BiMap bedMap = HashBiMap.create(); + private final Map bedMap = new HashMap<>(); /** * Map of patients of this hospital. @@ -328,16 +323,6 @@ else if (entry.getValue() != 0) } } - /** - * Check if the citizen is actually in bed. - * @param citizen the entity to check. - * @return true if close to bed. - */ - public boolean isInBed(final AbstractEntityCitizen citizen) - { - return bedMap.inverse().getOrDefault(citizen.getCitizenData().getId(), BlockPos.ZERO).distManhattan(citizen.blockPosition()) < 10; - } - @Override public boolean canEat(final ItemStack stack) { 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 e85793d10ec..991d2301080 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 @@ -182,16 +182,16 @@ private DiseaseState findEmptyBed() final IColony colony = citizen.getCitizenColonyHandler().getColony(); final IBuilding hospital = colony.getBuildingManager().getBuilding(hospitalPos); - if (hospital instanceof BuildingHospital buildingHospital) + if (hospital instanceof BuildingHospital) { - if (usedBed != null && !buildingHospital.getBedList().contains(usedBed)) + if (usedBed != null && !((BuildingHospital) hospital).getBedList().contains(usedBed)) { usedBed = null; } if (usedBed == null) { - for (final BlockPos pos : buildingHospital.getBedList()) + for (final BlockPos pos : ((BuildingHospital) hospital).getBedList()) { final Level world = citizen.level; BlockState state = world.getBlockState(pos); @@ -200,9 +200,9 @@ private DiseaseState findEmptyBed() && state.getValue(BedBlock.PART).equals(BedPart.HEAD) && world.isEmptyBlock(pos.above())) { - citizen.getCitizenDiseaseHandler().setSleepsAtHospital(buildingHospital); + citizen.getCitizenDiseaseHandler().setSleepsAtHospital(true); usedBed = pos; - buildingHospital.registerPatient(usedBed, citizen.getCivilianID()); + ((BuildingHospital) hospital).registerPatient(usedBed, citizen.getCivilianID()); return FIND_EMPTY_BED; } } @@ -369,7 +369,7 @@ else if (state == CitizenAIState.IDLE) private IState goToHut() { final IBuilding buildingWorker = citizenData.getWorkBuilding(); - citizen.getCitizenDiseaseHandler().setSleepsAtHospital(null); + citizen.getCitizenDiseaseHandler().setSleepsAtHospital(false); if (buildingWorker == null) { @@ -390,7 +390,7 @@ private IState goToHut() */ private IState goToHospital() { - citizen.getCitizenDiseaseHandler().setSleepsAtHospital(null); + citizen.getCitizenDiseaseHandler().setSleepsAtHospital(false); if (placeToPath == null) { return SEARCH_HOSPITAL; @@ -482,7 +482,7 @@ private void reset() citizen.stopUsingItem(); citizen.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY); placeToPath = null; - citizen.getCitizenDiseaseHandler().setSleepsAtHospital(null); + citizen.getCitizenDiseaseHandler().setSleepsAtHospital(false); } // TODO: Citizen AI should set status icons 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 e4dc73ebd69..8d5f9ec68c8 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 @@ -6,9 +6,8 @@ import com.minecolonies.api.colony.buildings.IBuilding; import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; import com.minecolonies.api.entity.citizen.citizenhandlers.ICitizenDiseaseHandler; -import com.minecolonies.api.util.BlockPosUtil; import com.minecolonies.core.MineColonies; -import com.minecolonies.core.colony.buildings.workerbuildings.BuildingHospital; +import com.minecolonies.core.colony.buildings.workerbuildings.BuildingCook; import com.minecolonies.core.colony.jobs.AbstractJobGuard; import com.minecolonies.core.colony.jobs.JobHealer; import net.minecraft.core.BlockPos; @@ -62,9 +61,9 @@ public class CitizenDiseaseHandler implements ICitizenDiseaseHandler private int immunityTicks = 0; /** - * Pos of the hospital the citizen might be sleeping at (or null if not sleeping at a hospital). + * Whether the citizen sleeps at the hostpital */ - private BlockPos hospitalPos = null; + private boolean sleepsAtHospital = false; /** * The initial citizen count @@ -156,10 +155,6 @@ public void write(final CompoundTag compound) { compound.putString(TAG_DISEASE, disease); compound.putInt(TAG_IMMUNITY, immunityTicks); - if (hospitalPos != null) - { - BlockPosUtil.write(compound, TAG_HOSPITAL, hospitalPos); - } } @Override @@ -171,10 +166,6 @@ public void read(final CompoundTag compound) this.disease = compound.getString(TAG_DISEASE); } this.immunityTicks = compound.getInt(TAG_IMMUNITY); - if (compound.contains(TAG_HOSPITAL)) - { - hospitalPos = BlockPosUtil.read(compound, TAG_HOSPITAL); - } } @Override @@ -187,9 +178,11 @@ public String getDisease() public void cure() { this.disease = ""; + sleepsAtHospital = false; if (citizen.getCitizenSleepHandler().isAsleep()) { citizen.stopSleeping(); + final BlockPos hospitalPos = citizen.getCitizenColonyHandler().getColony().getBuildingManager().getBestBuilding(citizen, BuildingCook.class); final IColony colony = citizen.getCitizenColonyHandler().getColony(); final IBuilding hospital = colony.getBuildingManager().getBuilding(hospitalPos); if (hospital != null) @@ -208,39 +201,19 @@ public void cure() citizen.getCitizenColonyHandler().getColony().getStatisticsManager().increment(CITIZENS_HEALED, citizen.getCitizenColonyHandler().getColony().getDay()); } - hospitalPos = null; + citizen.markDirty(0); } @Override public boolean sleepsAtHospital() { - if (hospitalPos != null) - { - final IColony colony = citizen.getCitizenColonyHandler().getColony(); - if (colony != null) - { - final BuildingHospital hospital = colony.getBuildingManager().getBuilding(hospitalPos, BuildingHospital.class); - if (hospital != null) - { - return hospital.isInBed(citizen); - } - hospitalPos = null; - } - } - return hospitalPos != null; + return sleepsAtHospital; } @Override - public void setSleepsAtHospital(final BuildingHospital buildingHospital) + public void setSleepsAtHospital(final boolean isAtHospital) { - if (buildingHospital == null) - { - hospitalPos = null; - } - else - { - hospitalPos = buildingHospital.getPosition(); - } + sleepsAtHospital = isAtHospital; } }