diff --git a/src/main/java/com/minecolonies/api/compatibility/CompatibilityManager.java b/src/main/java/com/minecolonies/api/compatibility/CompatibilityManager.java index 8b7d31ba345..568468247c8 100755 --- a/src/main/java/com/minecolonies/api/compatibility/CompatibilityManager.java +++ b/src/main/java/com/minecolonies/api/compatibility/CompatibilityManager.java @@ -112,14 +112,9 @@ public class CompatibilityManager implements ICompatibilityManager private ImmutableSet beekeeperflowers = ImmutableSet.of(); /** - * Set of all possible diseases. + * List of lucky oreBlocks which get dropped by the miner. */ - private final Map diseases = new HashMap<>(); - - /** - * List of diseases including the random factor. - */ - private final List diseaseList = new ArrayList<>(); + private final Map> luckyOres = new HashMap<>(); /** * The items and weights of the recruitment. @@ -170,8 +165,6 @@ private void clear() compostRecipes.clear(); recruitmentCostsWeights.clear(); - diseases.clear(); - diseaseList.clear(); monsters = ImmutableSet.of(); creativeModeTabMap.clear(); } @@ -188,7 +181,6 @@ public void discover(@NotNull final RecipeManager recipeManager, final Level lev discoverAllItems(level); discoverRecruitCosts(); - discoverDiseases(); discoverModCompat(); discoverCompostRecipes(recipeManager); @@ -243,7 +235,6 @@ public void deserialize(@NotNull final FriendlyByteBuf buf, final ClientLevel le // the below are loaded from config files, which have been synched already by this point discoverRecruitCosts(); - discoverDiseases(); discoverModCompat(); } @@ -460,24 +451,6 @@ public Set getImmutableFlowers() return beekeeperflowers; } - @Override - public String getRandomDisease() - { - return diseaseList.get(random.nextInt(diseaseList.size())); - } - - @Override - public Disease getDisease(final String disease) - { - return diseases.get(disease); - } - - @Override - public List getDiseases() - { - return new ArrayList<>(diseases.values()); - } - @Override public List> getRecruitmentCostsWeights() { @@ -802,57 +775,6 @@ private void discoverRecruitCosts() Log.getLogger().info("Finished discovering recruitment costs"); } - /** - * Go through the disease config and setup all possible diseases. - */ - private void discoverDiseases() - { - if (diseases.isEmpty()) - { - for (final String disease : MinecoloniesAPIProxy.getInstance().getConfig().getServer().diseases.get()) - { - final String[] split = disease.split(","); - if (split.length < 3) - { - Log.getLogger().warn("Wrongly configured disease: " + disease); - continue; - } - - try - { - final String name = split[0]; - final int rarity = Integer.parseInt(split[1]); - - final List cure = new ArrayList<>(); - - for (int i = 2; i < split.length; i++) - { - final String[] theItem = split[i].split(":"); - final Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(theItem[0], theItem[1])); - if (item == null || item == Items.AIR) - { - Log.getLogger().warn("Invalid cure item: " + disease); - continue; - } - - final ItemStack stack = new ItemStack(item, 1); - cure.add(stack); - } - diseases.put(name, new Disease(name, rarity, cure)); - for (int i = 0; i < rarity; i++) - { - diseaseList.add(name); - } - } - catch (final NumberFormatException e) - { - Log.getLogger().warn("Wrongly configured disease: " + disease); - } - } - } - Log.getLogger().info("Finished discovering diseases"); - } - private static CompoundTag writeLeafSaplingEntryToNBT(final BlockState state, final ItemStorage storage) { final CompoundTag compound = NbtUtils.writeBlockState(state); diff --git a/src/main/java/com/minecolonies/api/compatibility/ICompatibilityManager.java b/src/main/java/com/minecolonies/api/compatibility/ICompatibilityManager.java index 1f3604acdc3..2fcf7009685 100755 --- a/src/main/java/com/minecolonies/api/compatibility/ICompatibilityManager.java +++ b/src/main/java/com/minecolonies/api/compatibility/ICompatibilityManager.java @@ -3,7 +3,6 @@ import com.google.common.collect.ImmutableSet; import com.minecolonies.api.crafting.CompostRecipe; import com.minecolonies.api.crafting.ItemStorage; -import com.minecolonies.api.util.Disease; import com.minecolonies.api.util.Tuple; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.nbt.CompoundTag; @@ -139,28 +138,6 @@ public interface ICompatibilityManager */ ImmutableSet getAllMonsters(); - /** - * Get a random disease of the compat manager. - * - * @return a randomly chosen disease. - */ - String getRandomDisease(); - - /** - * Get a disease by the ID. - * - * @param disease the id. - * @return the disease. - */ - Disease getDisease(String disease); - - /** - * Get the list of diseases. - * - * @return a copy of the list. - */ - List getDiseases(); - /** * Gets the list of recruitment costs with weights * diff --git a/src/main/java/com/minecolonies/api/configuration/ServerConfiguration.java b/src/main/java/com/minecolonies/api/configuration/ServerConfiguration.java index f4dc578a01d..3d33f5ee439 100755 --- a/src/main/java/com/minecolonies/api/configuration/ServerConfiguration.java +++ b/src/main/java/com/minecolonies/api/configuration/ServerConfiguration.java @@ -97,7 +97,6 @@ public class ServerConfiguration extends AbstractConfiguration * -------------------------------------------------------------------------------- */ public final ForgeConfigSpec.ConfigValue> configListRecruitmentItems; - public final ForgeConfigSpec.ConfigValue> diseases; public final ForgeConfigSpec.BooleanValue auditCraftingTags; public final ForgeConfigSpec.BooleanValue debugInventories; public final ForgeConfigSpec.BooleanValue blueprintBuildMode; @@ -208,12 +207,6 @@ protected ServerConfiguration(final ForgeConfigSpec.Builder builder) "minecraft:quartz;3"), s -> s instanceof String); - diseases = defineList(builder, "diseases", - Arrays.asList("Influenza,100,minecraft:carrot,minecraft:potato", - "Measles,10,minecraft:dandelion,minecraft:kelp,minecraft:poppy", - "Smallpox,1,minecraft:honey_bottle,minecraft:golden_apple"), - s -> s instanceof String); - auditCraftingTags = defineBoolean(builder, "auditcraftingtags", false); debugInventories = defineBoolean(builder, "debuginventories", false); blueprintBuildMode = defineBoolean(builder, "blueprintbuildmode", false); 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 20a2815e97f..d8811f35aae 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,9 @@ package com.minecolonies.api.entity.citizen.citizenhandlers; +import com.minecolonies.core.datalistener.model.Disease; import com.minecolonies.api.colony.ICitizenData; import net.minecraft.nbt.CompoundTag; +import org.jetbrains.annotations.Nullable; /** * Citizen disease handler interface. @@ -35,11 +37,12 @@ public interface ICitizenDiseaseHandler void read(final CompoundTag compound); /** - * get the disease identifier. + * Get the current disease, if any. * - * @return the disease identifier. + * @return the disease instance. */ - String getDisease(); + @Nullable + Disease getDisease(); /** * Cure the citizen. @@ -70,7 +73,9 @@ public interface ICitizenDiseaseHandler /** * Set a disease on the citizen. + * * @param disease to set. + * @return true if they actually became sick. */ - void setDisease(String disease); + boolean setDisease(Disease disease); } diff --git a/src/main/java/com/minecolonies/api/inventory/container/ContainerCrafting.java b/src/main/java/com/minecolonies/api/inventory/container/ContainerCrafting.java index 2a67a2d5baa..60b42cffe10 100755 --- a/src/main/java/com/minecolonies/api/inventory/container/ContainerCrafting.java +++ b/src/main/java/com/minecolonies/api/inventory/container/ContainerCrafting.java @@ -416,7 +416,7 @@ public BlockPos getPos() } /** - * Get for the remaining items. + * Get for the remaining items. * @return */ public List getRemainingItems() diff --git a/src/main/java/com/minecolonies/api/util/Disease.java b/src/main/java/com/minecolonies/api/util/Disease.java deleted file mode 100755 index 19a6d5436f8..00000000000 --- a/src/main/java/com/minecolonies/api/util/Disease.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.minecolonies.api.util; - -import com.google.common.collect.ImmutableList; -import net.minecraft.world.item.ItemStack; - -import java.util.List; - -/** - * Disease storage class. - */ -public class Disease -{ - /** - * The name string. - */ - private final String name; - - /** - * The rarity modifier. - */ - private final int rarity; - - /** - * The cure. - */ - private final List cure; - - /** - * Create a disease. - * - * @param name the name of it. - * @param rarity its rarity. - * @param cure the cure. - */ - public Disease(final String name, final int rarity, final List cure) - { - this.name = name; - this.rarity = rarity; - this.cure = cure; - } - - /** - * Get the name of the disease. - * - * @return the name. - */ - public String getName() - { - return name; - } - - /** - * Get the rarity modifier of the disease. - * - * @return the rarity. - */ - public int getRarity() - { - return rarity; - } - - /** - * Get the cure list. - * - * @return the cure. - */ - public List getCure() - { - return ImmutableList.copyOf(cure); - } - - /** - * The Cure String. - * - * @return the cure string. - */ - public String getCureString() - { - StringBuilder cureString = new StringBuilder(); - for (final ItemStack cureStack : cure) - { - cureString.append(cureStack.getHoverName().getString()); - cureString.append("+"); - } - cureString.deleteCharAt(cureString.length() - 1); - return cureString.toString(); - } -} diff --git a/src/main/java/com/minecolonies/apiimp/initializer/InteractionValidatorInitializer.java b/src/main/java/com/minecolonies/apiimp/initializer/InteractionValidatorInitializer.java index 7900d7f2072..61b4d86329c 100755 --- a/src/main/java/com/minecolonies/apiimp/initializer/InteractionValidatorInitializer.java +++ b/src/main/java/com/minecolonies/apiimp/initializer/InteractionValidatorInitializer.java @@ -71,7 +71,7 @@ public static void init() citizen -> citizen.getColony() != null && citizen.getEntity().isPresent() && citizen.getCitizenDiseaseHandler().isSick() && citizen.getColony().getBuildingManager().getBestBuilding(citizen.getEntity().get(), BuildingHospital.class) == null); InteractionValidatorRegistry.registerStandardPredicate(Component.translatable(WAITING_FOR_CURE), - citizen -> citizen.getColony() != null && citizen.getEntity().isPresent() && !citizen.getCitizenDiseaseHandler().getDisease().isEmpty()); + citizen -> citizen.getColony() != null && citizen.getEntity().isPresent() && citizen.getCitizenDiseaseHandler().getDisease() != null); InteractionValidatorRegistry.registerPosBasedPredicate(Component.translatable(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL), (citizen, pos) -> 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 5996fd631eb..37b6ca4f4f2 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,11 +3,12 @@ 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.crafting.ItemStorage; import com.minecolonies.api.util.BlockPosUtil; -import com.minecolonies.api.util.Disease; 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; import net.minecraft.nbt.CompoundTag; @@ -196,35 +197,23 @@ public void removePatientFile(final Patient patient) public Map, Tuple> getRequiredItemsAndAmount() { final Map, Tuple> map = super.getRequiredItemsAndAmount(); - map.put(this::doesAnyPatientRequireStack, new Tuple<>(10, false)); + map.put(BuildingHospital::isCureItem, new Tuple<>(10, false)); return map; } /** - * Check if any patient requires this. + * Check if the given itemstack is a cure item. * * @param stack the stack to test. * @return true if so. */ - private boolean doesAnyPatientRequireStack(final ItemStack stack) + private static boolean isCureItem(final ItemStack stack) { - for (final Patient patient : patients.values()) + for (final Disease disease : DiseasesListener.getDiseases()) { - final ICitizenData data = colony.getCitizenManager().getCivilian(patient.getId()); - if (data != null && data.getEntity().isPresent() && data.getCitizenDiseaseHandler().isSick()) + for (final ItemStorage cureItem : disease.cureItems()) { - final String diseaseName = data.getCitizenDiseaseHandler().getDisease(); - if (!diseaseName.isEmpty()) - { - final Disease disease = IColonyManager.getInstance().getCompatibilityManager().getDisease(diseaseName); - for (final ItemStack cure : disease.getCure()) - { - if (ItemStack.isSameItem(cure, stack)) - { - return true; - } - } - } + return Disease.isCureItem(stack, cureItem); } } return false; @@ -297,8 +286,7 @@ else if (entry.getValue() != 0) { if (state.getValue(BedBlock.OCCUPIED)) { - if (!citizen.isAsleep() || !citizen.getEntity().isPresent() - || citizen.getEntity().get().blockPosition().distSqr(entry.getKey()) > 2.0) + if (!citizen.isAsleep() || citizen.getEntity().isEmpty() || citizen.getEntity().get().blockPosition().distSqr(entry.getKey()) > 2.0) { setBedOccupation(entry.getKey(), false); bedMap.put(entry.getKey(), 0); @@ -328,15 +316,9 @@ else if (entry.getValue() != 0) @Override public boolean canEat(final ItemStack stack) { - for (final Disease disease : IColonyManager.getInstance().getCompatibilityManager().getDiseases()) + if (isCureItem(stack)) { - for (final ItemStack cure : disease.getCure()) - { - if (ItemStack.isSameItem(cure, stack)) - { - return false; - } - } + return false; } return super.canEat(stack); diff --git a/src/main/java/com/minecolonies/core/datalistener/DiseasesListener.java b/src/main/java/com/minecolonies/core/datalistener/DiseasesListener.java new file mode 100644 index 00000000000..1610eef22ea --- /dev/null +++ b/src/main/java/com/minecolonies/core/datalistener/DiseasesListener.java @@ -0,0 +1,187 @@ +package com.minecolonies.core.datalistener; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.minecolonies.api.colony.requestsystem.StandardFactoryController; +import com.minecolonies.api.crafting.ItemStorage; +import com.minecolonies.core.Network; +import com.minecolonies.core.datalistener.model.Disease; +import com.minecolonies.core.network.messages.client.colony.GlobalDiseaseSyncMessage; +import io.netty.buffer.Unpooled; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener; +import net.minecraft.util.GsonHelper; +import net.minecraft.util.RandomSource; +import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.util.random.WeightedRandomList; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Loads and listens to diseases data. + */ +public class DiseasesListener extends SimpleJsonResourceReloadListener +{ + /** + * Gson instance + */ + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create(); + + /** + * Json constants + */ + private static final String KEY_NAME = "name"; + private static final String KEY_RARITY = "rarity"; + private static final String KEY_ITEMS = "items"; + + /** + * The map of diseases. + */ + private static WeightedRandomList DISEASES = WeightedRandomList.create(); + + /** + * Default constructor. + */ + public DiseasesListener() + { + super(GSON, "colony/diseases"); + } + + /** + * Sync to client. + * + * @param player to send it to. + */ + public static void sendGlobalDiseasesPackets(final ServerPlayer player) + { + final FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer()); + byteBuf.writeInt(DISEASES.unwrap().size()); + for (final Disease disease : DISEASES.unwrap()) + { + byteBuf.writeResourceLocation(disease.id()); + byteBuf.writeComponent(disease.name()); + byteBuf.writeInt(disease.rarity()); + for (final ItemStorage cureItem : disease.cureItems()) + { + StandardFactoryController.getInstance().serialize(byteBuf, cureItem); + } + } + Network.getNetwork().sendToPlayer(new GlobalDiseaseSyncMessage(byteBuf), player); + } + + /** + * Read the data from the packet and parse it. + * + * @param byteBuf pck. + */ + public static void readGlobalDiseasesPackets(final FriendlyByteBuf byteBuf) + { + final List newDiseases = new ArrayList<>(); + final int size = byteBuf.readInt(); + for (int i = 0; i < size; i++) + { + final ResourceLocation id = byteBuf.readResourceLocation(); + final Component name = byteBuf.readComponent(); + final int rarity = byteBuf.readInt(); + + final List cureItems = new ArrayList<>(); + final int itemCount = byteBuf.readInt(); + for (int j = 0; j < itemCount; j++) + { + cureItems.add(StandardFactoryController.getInstance().deserialize(byteBuf)); + } + + newDiseases.add(new Disease(id, name, rarity, cureItems)); + } + DISEASES = WeightedRandomList.create(newDiseases); + } + + /** + * Get a collection of all possible diseases. + * + * @return the collection of diseases. + */ + @NotNull + public static List getDiseases() + { + return DISEASES.unwrap(); + } + + /** + * Get a specific disease by id. + * + * @param id the disease id. + * @return the disease instance or null if it does not exist. + */ + @Nullable + public static Disease getDisease(final ResourceLocation id) + { + for (final Disease disease : DISEASES.unwrap()) + { + if (disease.id().equals(id)) + { + return disease; + } + } + return null; + } + + /** + * Get a random disease from the list of diseases. + * + * @param random the input random source. + * @return the random disease instance or null if no diseases exist. + */ + @Nullable + public static Disease getRandomDisease(final RandomSource random) + { + return DISEASES.getRandom(random).orElse(null); + } + + @Override + protected void apply( + final @NotNull Map jsonElementMap, + final @NotNull ResourceManager resourceManager, + final @NotNull ProfilerFiller profiler) + { + final List diseases = new ArrayList<>(); + for (final Map.Entry entry : jsonElementMap.entrySet()) + { + if (!entry.getValue().isJsonObject()) + { + return; + } + + final JsonObject object = entry.getValue().getAsJsonObject(); + final Component name = Component.translatable(GsonHelper.getAsString(object, KEY_NAME)); + final int rarity = GsonHelper.getAsInt(object, KEY_RARITY); + final List cureItems = new ArrayList<>(); + for (final JsonElement jsonElement : object.getAsJsonArray(KEY_ITEMS)) + { + if (!jsonElement.isJsonObject()) + { + continue; + } + + final ItemStorage cureItem = new ItemStorage(jsonElement.getAsJsonObject()); + // TODO: Apparently the healing doesn't fully work yet with multi-count cure items + // for the sake of compatibility for now, revert the count to 1 despite what's in the JSON. + cureItem.setAmount(1); + cureItems.add(cureItem); + } + + diseases.add(new Disease(entry.getKey(), name, rarity, cureItems)); + } + DISEASES = WeightedRandomList.create(diseases); + } +} 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..6a9868bf9b7 --- /dev/null +++ b/src/main/java/com/minecolonies/core/datalistener/model/Disease.java @@ -0,0 +1,75 @@ +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.util.random.Weight; +import net.minecraft.util.random.WeightedEntry; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; + +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) implements WeightedEntry +{ + /** + * 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; + } + + @Override + @NotNull + public Weight getWeight() + { + return Weight.of(rarity); + } +} 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 581ea8ff195..842246b6eed 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 @@ -2,21 +2,22 @@ import com.minecolonies.api.colony.ICitizenData; import com.minecolonies.api.colony.IColony; -import com.minecolonies.api.colony.IColonyManager; import com.minecolonies.api.colony.buildings.IBuilding; import com.minecolonies.api.colony.interactionhandling.ChatPriority; +import com.minecolonies.api.crafting.ItemStorage; import com.minecolonies.api.entity.ai.IStateAI; import com.minecolonies.api.entity.ai.statemachine.states.CitizenAIState; import com.minecolonies.api.entity.ai.statemachine.states.IState; import com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickingTransition; import com.minecolonies.api.entity.citizen.VisibleCitizenStatus; import com.minecolonies.api.util.BlockPosUtil; -import com.minecolonies.api.util.Disease; import com.minecolonies.api.util.InventoryUtils; import com.minecolonies.api.util.SoundUtils; import com.minecolonies.core.Network; 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.model.Disease; import com.minecolonies.core.entity.citizen.EntityCitizen; import com.minecolonies.core.network.messages.client.CircleParticleEffectMessage; import net.minecraft.core.BlockPos; @@ -245,10 +246,16 @@ private IState applyCure() return CHECK_FOR_CURE; } - final List list = IColonyManager.getInstance().getCompatibilityManager().getDisease(citizen.getCitizenData().getCitizenDiseaseHandler().getDisease()).getCure(); + final Disease disease = citizen.getCitizenData().getCitizenDiseaseHandler().getDisease(); + if (disease == null) + { + return CitizenAIState.IDLE; + } + + final List list = disease.cureItems(); if (!list.isEmpty()) { - citizen.setItemInHand(InteractionHand.MAIN_HAND, list.get(citizen.getRandom().nextInt(list.size()))); + citizen.setItemInHand(InteractionHand.MAIN_HAND, list.get(citizen.getRandom().nextInt(list.size())).getItemStack()); } citizen.swing(InteractionHand.MAIN_HAND); @@ -275,12 +282,12 @@ private IState applyCure() */ private void cure() { - final Disease disease = IColonyManager.getInstance().getCompatibilityManager().getDisease(citizen.getCitizenData().getCitizenDiseaseHandler().getDisease()); + final Disease disease = citizen.getCitizenData().getCitizenDiseaseHandler().getDisease(); if (disease != null) { - for (final ItemStack cure : disease.getCure()) + for (final ItemStorage cure : disease.cureItems()) { - final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(citizen, stack -> ItemStack.isSameItem(cure, stack)); + final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(citizen, Disease.hasCureItem(cure)); if (slot != -1) { citizenData.getInventory().extractItem(slot, 1, false); @@ -411,25 +418,23 @@ private IState goToHospital() private IState searchHospital() { final IColony colony = citizenData.getColony(); + final Disease disease = citizen.getCitizenData().getCitizenDiseaseHandler().getDisease(); placeToPath = colony.getBuildingManager().getBestBuilding(citizen, BuildingHospital.class); if (placeToPath == null) { - final String id = citizen.getCitizenData().getCitizenDiseaseHandler().getDisease(); - if (id.isEmpty()) + if (disease == null) { return CitizenAIState.IDLE; } - final Disease disease = IColonyManager.getInstance().getCompatibilityManager().getDisease(id); - citizenData.triggerInteraction(new StandardInteraction(Component.translatable(NO_HOSPITAL, disease.getName(), disease.getCureString()), + citizenData.triggerInteraction(new StandardInteraction(Component.translatable(NO_HOSPITAL, disease.name(), disease.getCureString()), Component.translatable(NO_HOSPITAL), ChatPriority.BLOCKING)); return WANDER; } - else if (!citizen.getCitizenData().getCitizenDiseaseHandler().getDisease().isEmpty()) + else if (disease != null) { - final Disease disease = IColonyManager.getInstance().getCompatibilityManager().getDisease(citizen.getCitizenData().getCitizenDiseaseHandler().getDisease()); - citizenData.triggerInteraction(new StandardInteraction(Component.translatable(WAITING_FOR_CURE, disease.getName(), disease.getCureString()), + citizenData.triggerInteraction(new StandardInteraction(Component.translatable(WAITING_FOR_CURE, disease.name(), disease.getCureString()), Component.translatable(WAITING_FOR_CURE), ChatPriority.BLOCKING)); } @@ -444,8 +449,8 @@ else if (!citizen.getCitizenData().getCitizenDiseaseHandler().getDisease().isEmp */ private IState checkForCure() { - final String id = citizen.getCitizenData().getCitizenDiseaseHandler().getDisease(); - if (id.isEmpty()) + final Disease disease = citizen.getCitizenData().getCitizenDiseaseHandler().getDisease(); + if (disease == null) { if (citizen.getHealth() > SEEK_DOCTOR_HEALTH) { @@ -454,10 +459,9 @@ private IState checkForCure() } return GO_TO_HUT; } - final Disease disease = IColonyManager.getInstance().getCompatibilityManager().getDisease(id); - for (final ItemStack cure : disease.getCure()) + for (final ItemStorage cure : disease.cureItems()) { - final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(citizen, stack -> ItemStack.isSameItem(cure, stack)); + final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(citizen, Disease.hasCureItem(cure)); if (slot == -1) { if (citizen.getCitizenData().getCitizenDiseaseHandler().isSick()) 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 50ed8f1f2e0..0528966f01b 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 @@ -3,10 +3,10 @@ import com.google.common.collect.ImmutableList; import com.google.common.reflect.TypeToken; import com.minecolonies.api.colony.ICitizenData; -import com.minecolonies.api.colony.IColonyManager; import com.minecolonies.api.colony.interactionhandling.ChatPriority; import com.minecolonies.api.colony.requestsystem.request.IRequest; import com.minecolonies.api.colony.requestsystem.requestable.Stack; +import com.minecolonies.api.crafting.ItemStorage; import com.minecolonies.api.entity.ai.statemachine.AITarget; import com.minecolonies.api.entity.ai.statemachine.states.IAIState; import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; @@ -15,19 +15,18 @@ 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.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.minecraft.world.item.ItemStack; import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import static com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState.*; import static com.minecolonies.api.util.constant.TranslationConstants.PATIENT_FULL_INVENTORY; @@ -124,8 +123,7 @@ private IAIState decide() continue; } final EntityCitizen citizen = (EntityCitizen) data.getEntity().get(); - final String diseaseName = citizen.getCitizenData().getCitizenDiseaseHandler().getDisease(); - @Nullable final Disease disease = diseaseName.isEmpty() ? null : IColonyManager.getInstance().getCompatibilityManager().getDisease(diseaseName); + final Disease disease = citizen.getCitizenData().getCitizenDiseaseHandler().getDisease(); if (patient.getState() == Patient.PatientState.NEW) { @@ -158,20 +156,20 @@ private IAIState decide() final ImmutableList> list = building.getOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(Stack.class)); final ImmutableList> completed = building.getCompletedRequestsOfType(worker.getCitizenData(), TypeToken.of(Stack.class)); - for (final ItemStack cure : IColonyManager.getInstance().getCompatibilityManager().getDisease(diseaseName).getCure()) + for (final ItemStorage cure : disease.cureItems()) { - if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), stack -> ItemStack.isSameItem(cure, stack))) + if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), Disease.hasCureItem(cure))) { if (InventoryUtils.getItemCountInItemHandler(building.getCapability(ForgeCapabilities.ITEM_HANDLER).orElseGet(null), - stack -> ItemStack.isSameItem(stack, cure)) >= cure.getCount()) + Disease.hasCureItem(cure)) >= cure.getAmount()) { - needsCurrently = new Tuple<>(stack -> ItemStack.isSameItem(stack, cure), cure.getCount()); + needsCurrently = new Tuple<>(Disease.hasCureItem(cure), cure.getAmount()); return GATHERING_REQUIRED_MATERIALS; } boolean hasCureRequested = false; for (final IRequest request : list) { - if (ItemStack.isSameItem(request.getRequest().getStack(), cure)) + if (Disease.isCureItem(request.getRequest().getStack(), cure)) { hasCureRequested = true; break; @@ -179,7 +177,7 @@ private IAIState decide() } for (final IRequest request : completed) { - if (ItemStack.isSameItem(request.getRequest().getStack(), cure)) + if (Disease.isCureItem(request.getRequest().getStack(), cure)) { hasCureRequested = true; break; @@ -259,8 +257,8 @@ private IAIState requestCure() return REQUEST_CURE; } - final String diseaseName = citizen.getCitizenData().getCitizenDiseaseHandler().getDisease(); - if (diseaseName.isEmpty()) + final Disease disease = citizen.getCitizenData().getCitizenDiseaseHandler().getDisease(); + if (disease == null) { currentPatient.setState(Patient.PatientState.REQUESTED); currentPatient = null; @@ -270,15 +268,15 @@ private IAIState requestCure() final ImmutableList> list = building.getOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(Stack.class)); final ImmutableList> completed = building.getCompletedRequestsOfType(worker.getCitizenData(), TypeToken.of(Stack.class)); - for (final ItemStack cure : IColonyManager.getInstance().getCompatibilityManager().getDisease(diseaseName).getCure()) + for (final ItemStorage cure : disease.cureItems()) { - if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), stack -> ItemStack.isSameItem(cure, stack)) - && !InventoryUtils.hasItemInItemHandler(building.getCapability(ForgeCapabilities.ITEM_HANDLER).orElseGet(null), stack -> ItemStack.isSameItem(cure, stack))) + 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 (ItemStack.isSameItem(request.getRequest().getStack(), cure)) + if (Disease.isCureItem(request.getRequest().getStack(), cure)) { hasRequest = true; break; @@ -286,7 +284,7 @@ private IAIState requestCure() } for (final IRequest request : completed) { - if (ItemStack.isSameItem(request.getRequest().getStack(), cure)) + if (Disease.isCureItem(request.getRequest().getStack(), cure)) { hasRequest = true; break; @@ -294,7 +292,7 @@ private IAIState requestCure() } if (!hasRequest) { - worker.getCitizenData().createRequestAsync(new Stack(cure, REQUEST_COUNT, 1)); + worker.getCitizenData().createRequestAsync(new Stack(cure)); } } } @@ -329,9 +327,8 @@ private IAIState cure() return CURE; } - final String diseaseName = citizen.getCitizenData().getCitizenDiseaseHandler().getDisease(); - final Disease disease = IColonyManager.getInstance().getCompatibilityManager().getDisease(diseaseName); - if (diseaseName.isEmpty()) + final Disease disease = citizen.getCitizenData().getCitizenDiseaseHandler().getDisease(); + if (disease == null) { currentPatient = null; citizen.heal(10); @@ -343,11 +340,11 @@ private IAIState cure() { if (hasCureInInventory(disease, building.getCapability(ForgeCapabilities.ITEM_HANDLER).orElseGet(null))) { - for (final ItemStack cure : disease.getCure()) + for (final ItemStorage cure : disease.cureItems()) { - if (InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), stack -> ItemStack.isSameItem(stack, cure)) < cure.getCount()) + if (InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), Disease.hasCureItem(cure)) < cure.getAmount()) { - needsCurrently = new Tuple<>(stack -> ItemStack.isSameItem(stack, cure), 1); + needsCurrently = new Tuple<>(Disease.hasCureItem(cure), 1); return GATHERING_REQUIRED_MATERIALS; } } @@ -358,9 +355,9 @@ private IAIState cure() if (!hasCureInInventory(disease, citizen.getInventoryCitizen())) { - for (final ItemStack cure : disease.getCure()) + for (final ItemStorage cure : disease.cureItems()) { - if (InventoryUtils.getItemCountInItemHandler(citizen.getInventoryCitizen(), stack -> ItemStack.isSameItem(stack, cure)) < cure.getCount()) + if (InventoryUtils.getItemCountInItemHandler(citizen.getInventoryCitizen(), Disease.hasCureItem(cure)) < cure.getAmount()) { if (InventoryUtils.isItemHandlerFull(citizen.getInventoryCitizen())) { @@ -370,8 +367,8 @@ private IAIState cure() } InventoryUtils.transferXOfFirstSlotInItemHandlerWithIntoNextFreeSlotInItemHandler( worker.getInventoryCitizen(), - stack -> ItemStack.isSameItem(cure, stack), - cure.getCount(), citizen.getInventoryCitizen() + Disease.hasCureItem(cure), + cure.getAmount(), citizen.getInventoryCitizen() ); } } @@ -518,9 +515,9 @@ private boolean testRandomCureChance() */ private boolean hasCureInInventory(final Disease disease, final IItemHandler handler) { - for (final ItemStack cure : disease.getCure()) + for (final ItemStorage cure : disease.cureItems()) { - if (InventoryUtils.getItemCountInItemHandler(handler, stack -> ItemStack.isSameItem(cure, stack)) < cure.getCount()) + if (InventoryUtils.getItemCountInItemHandler(handler, Disease.hasCureItem(cure)) < cure.getAmount()) { return false; } diff --git a/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java b/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java index d470d5d877e..a7525185e56 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java +++ b/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java @@ -49,6 +49,7 @@ import com.minecolonies.core.colony.jobs.JobKnight; import com.minecolonies.core.colony.jobs.JobNetherWorker; import com.minecolonies.core.colony.jobs.JobRanger; +import com.minecolonies.core.datalistener.DiseasesListener; import com.minecolonies.core.entity.ai.minimal.*; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIBasic; import com.minecolonies.core.entity.ai.workers.CitizenAI; @@ -487,13 +488,14 @@ private InteractionResult directPlayerInteraction(final Player player, final Int if (!level.isClientSide()) { - getCitizenData().getCitizenDiseaseHandler().setDisease(IColonyManager.getInstance().getCompatibilityManager().getRandomDisease()); - playSound(SoundEvents.VILLAGER_HURT, 1.0f, (float) SoundUtils.getRandomPitch(getRandom())); - getCitizenData().markDirty(20); + if (getCitizenData().getCitizenDiseaseHandler().setDisease(DiseasesListener.getRandomDisease(getRandom()))) { + playSound(SoundEvents.VILLAGER_HURT, 1.0f, (float) SoundUtils.getRandomPitch(getRandom())); + getCitizenData().markDirty(20); - MessageUtils.format(MESSAGE_INTERACTION_POISON, this.getCitizenData().getName()) - .withPriority(MessagePriority.DANGER) - .sendTo(player); + MessageUtils.format(MESSAGE_INTERACTION_POISON, this.getCitizenData().getName()) + .withPriority(MessagePriority.DANGER) + .sendTo(player); + } } interactionCooldown = 20 * 20; 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 f94bef8184b..bf054786668 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 @@ -3,15 +3,20 @@ import com.minecolonies.api.IMinecoloniesAPI; import com.minecolonies.api.colony.ICitizenData; import com.minecolonies.api.colony.IColony; -import com.minecolonies.api.colony.IColonyManager; 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.core.MineColonies; 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; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.RandomSource; +import org.jetbrains.annotations.Nullable; import static com.minecolonies.api.research.util.ResearchConstants.MASKS; import static com.minecolonies.api.research.util.ResearchConstants.VACCINES; @@ -52,7 +57,8 @@ public class CitizenDiseaseHandler implements ICitizenDiseaseHandler /** * The disease the citizen has, empty if none. */ - private String disease = ""; + @Nullable + private Disease disease; /** * Special immunity time after being cured. @@ -93,10 +99,11 @@ public void update(final int tickRate) final double citizenModifier = citizenData.getDiseaseModifier(); final int configModifier = MineColonies.getConfig().getServer().diseaseModifier.get(); - if (!IColonyManager.getInstance().getCompatibilityManager().getDiseases().isEmpty() && - citizenData.getRandom().nextInt(configModifier * DISEASE_FACTOR) < citizenModifier * 10) + // normally it's one in 5 x 10.000 + + if (citizenData.getRandom().nextInt(configModifier * DISEASE_FACTOR) < citizenModifier * 10) { - this.disease = IColonyManager.getInstance().getCompatibilityManager().getRandomDisease(); + this.disease = DiseasesListener.getRandomDisease(citizenData.getEntity().map(AbstractEntityCitizen::getRandom).orElse(RandomSource.create())); } } @@ -106,9 +113,15 @@ public void update(final int tickRate) } } - public void setDisease(final String disease) + @Override + public boolean setDisease(final @Nullable Disease disease) { - this.disease = disease; + if (canBecomeSick()) + { + this.disease = disease; + return true; + } + return false; } /** @@ -150,14 +163,17 @@ public boolean isHurt() @Override public boolean isSick() { - return !disease.isEmpty(); + return disease != null; } @Override public void write(final CompoundTag compound) { CompoundTag diseaseTag = new CompoundTag(); - diseaseTag.putString(TAG_DISEASE, disease); + if (disease != null) + { + diseaseTag.putString(TAG_DISEASE, disease.id().toString()); + } diseaseTag.putInt(TAG_IMMUNITY, immunityTicks); compound.put(TAG_DISEASE, diseaseTag); } @@ -165,20 +181,17 @@ public void write(final CompoundTag compound) @Override public void read(final CompoundTag compound) { - if (compound.contains(TAG_DISEASE)) + CompoundTag diseaseTag = compound.getCompound(TAG_DISEASE); + if (diseaseTag.contains(TAG_DISEASE)) { - CompoundTag diseaseTag = compound.getCompound(TAG_DISEASE); - // cure diseases that have been removed from the configuration file. - if (IColonyManager.getInstance().getCompatibilityManager().getDisease(diseaseTag.getString(TAG_DISEASE)) != null) - { - this.disease = diseaseTag.getString(TAG_DISEASE); - } - this.immunityTicks = diseaseTag.getInt(TAG_IMMUNITY); + this.disease = DiseasesListener.getDisease(new ResourceLocation(diseaseTag.getString(TAG_DISEASE))); } + this.immunityTicks = diseaseTag.getInt(TAG_IMMUNITY); } @Override - public String getDisease() + @Nullable + public Disease getDisease() { return this.disease; } @@ -186,7 +199,7 @@ public String getDisease() @Override public void cure() { - this.disease = ""; + this.disease = null; sleepsAtHospital = false; if (citizenData.isAsleep() && citizenData.getEntity().isPresent()) { diff --git a/src/main/java/com/minecolonies/core/event/DataPackSyncEventHandler.java b/src/main/java/com/minecolonies/core/event/DataPackSyncEventHandler.java index 6342a6085fd..d89f476aad8 100644 --- a/src/main/java/com/minecolonies/core/event/DataPackSyncEventHandler.java +++ b/src/main/java/com/minecolonies/core/event/DataPackSyncEventHandler.java @@ -6,6 +6,7 @@ import com.minecolonies.core.Network; import com.minecolonies.core.colony.crafting.CustomRecipeManager; import com.minecolonies.core.compatibility.CraftingTagAuditor; +import com.minecolonies.core.datalistener.DiseasesListener; import com.minecolonies.core.datalistener.QuestJsonListener; import com.minecolonies.core.network.messages.client.UpdateClientWithCompatibilityMessage; import com.minecolonies.core.util.FurnaceRecipes; @@ -69,6 +70,7 @@ private static void sendPackets(@NotNull final ServerPlayer player, CustomRecipeManager.getInstance().sendCustomRecipeManagerPackets(player); IGlobalResearchTree.getInstance().sendGlobalResearchTreePackets(player); QuestJsonListener.sendGlobalQuestPackets(player); + DiseasesListener.sendGlobalDiseasesPackets(player); } /** diff --git a/src/main/java/com/minecolonies/core/event/FMLEventHandler.java b/src/main/java/com/minecolonies/core/event/FMLEventHandler.java index d8b690cc43c..465511f88d5 100755 --- a/src/main/java/com/minecolonies/core/event/FMLEventHandler.java +++ b/src/main/java/com/minecolonies/core/event/FMLEventHandler.java @@ -52,6 +52,7 @@ public static void onAddReloadListenerEvent(@NotNull final AddReloadListenerEven event.addListener(new QuestJsonListener()); event.addListener(new ItemNbtListener()); event.addListener(new StudyItemListener()); + event.addListener(new DiseasesListener()); } @SubscribeEvent diff --git a/src/main/java/com/minecolonies/core/network/NetworkChannel.java b/src/main/java/com/minecolonies/core/network/NetworkChannel.java index 8290ad9700f..76759c65569 100755 --- a/src/main/java/com/minecolonies/core/network/NetworkChannel.java +++ b/src/main/java/com/minecolonies/core/network/NetworkChannel.java @@ -229,6 +229,7 @@ public void registerCommonMessages() registerMessage(++idx, OpenPlantationFieldBuildWindowMessage.class, OpenPlantationFieldBuildWindowMessage::new); registerMessage(++idx, SaveStructureNBTMessage.class, SaveStructureNBTMessage::new); registerMessage(++idx, GlobalQuestSyncMessage.class, GlobalQuestSyncMessage::new); + registerMessage(++idx, GlobalDiseaseSyncMessage.class, GlobalDiseaseSyncMessage::new); registerMessage(++idx, OpenColonyFoundingCovenantMessage.class, OpenColonyFoundingCovenantMessage::new); registerMessage(++idx, OpenBuildingUIMessage.class, OpenBuildingUIMessage::new); registerMessage(++idx, OpenCantFoundColonyWarningMessage.class, OpenCantFoundColonyWarningMessage::new); diff --git a/src/main/java/com/minecolonies/core/network/messages/client/colony/GlobalDiseaseSyncMessage.java b/src/main/java/com/minecolonies/core/network/messages/client/colony/GlobalDiseaseSyncMessage.java new file mode 100644 index 00000000000..760488c3e89 --- /dev/null +++ b/src/main/java/com/minecolonies/core/network/messages/client/colony/GlobalDiseaseSyncMessage.java @@ -0,0 +1,72 @@ +package com.minecolonies.core.network.messages.client.colony; + +import com.minecolonies.api.network.IMessage; +import com.minecolonies.core.datalistener.DiseasesListener; +import net.minecraft.client.Minecraft; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fml.LogicalSide; +import net.minecraftforge.network.NetworkEvent; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * The message used to synchronize global disease data from a server to a remote client. + */ +public class GlobalDiseaseSyncMessage implements IMessage +{ + /** + * The buffer with the data. + */ + private FriendlyByteBuf buffer; + + /** + * Empty constructor used when registering the message + */ + public GlobalDiseaseSyncMessage() + { + super(); + } + + /** + * Add or Update expedition type data on the client. + * + * @param buf the bytebuffer. + */ + public GlobalDiseaseSyncMessage(final FriendlyByteBuf buf) + { + this.buffer = new FriendlyByteBuf(buf.copy()); + } + + @Override + public void toBytes(@NotNull final FriendlyByteBuf buf) + { + buffer.resetReaderIndex(); + buf.writeBytes(buffer); + } + + @Override + public void fromBytes(@NotNull final FriendlyByteBuf buf) + { + buffer = new FriendlyByteBuf(buf.retain()); + } + + @Nullable + @Override + public LogicalSide getExecutionSide() + { + return LogicalSide.CLIENT; + } + + @OnlyIn(Dist.CLIENT) + @Override + public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) + { + if (Minecraft.getInstance().level != null) + { + DiseasesListener.readGlobalDiseasesPackets(buffer); + } + buffer.release(); + } +} diff --git a/src/main/resources/assets/minecolonies/lang/manual_en_us.json b/src/main/resources/assets/minecolonies/lang/manual_en_us.json index 368cf13ea8b..5f2e375f588 100644 --- a/src/main/resources/assets/minecolonies/lang/manual_en_us.json +++ b/src/main/resources/assets/minecolonies/lang/manual_en_us.json @@ -2734,5 +2734,9 @@ "com.minecolonies.coremod.setting.minecolonies:milk_item": "Milk Item:", "com.minecolonies.core.menu.title": "Menu", "com.minecolonies.core.food_list.title": "Food Options", - "com.minecolonies.core.menu.warning": "Select the Food Citizens will eat at this Restaurant" + "com.minecolonies.core.menu.warning": "Select the Food Citizens will eat at this Restaurant", + + "com.minecolonies.coremod.diseases.influenza": "Influenza", + "com.minecolonies.coremod.diseases.measles": "Measles", + "com.minecolonies.coremod.diseases.smallpox": "Smallpox" } diff --git a/src/main/resources/data/minecolonies/colony/diseases/influenza.json b/src/main/resources/data/minecolonies/colony/diseases/influenza.json new file mode 100644 index 00000000000..29b3fdfdd16 --- /dev/null +++ b/src/main/resources/data/minecolonies/colony/diseases/influenza.json @@ -0,0 +1,14 @@ +{ + "name": "com.minecolonies.coremod.diseases.influenza", + "rarity": 100, + "items": [ + { + "item": "minecraft:carrot", + "count": 1 + }, + { + "item": "minecraft:potato", + "count": 1 + } + ] +} diff --git a/src/main/resources/data/minecolonies/colony/diseases/measles.json b/src/main/resources/data/minecolonies/colony/diseases/measles.json new file mode 100644 index 00000000000..bccd625c97b --- /dev/null +++ b/src/main/resources/data/minecolonies/colony/diseases/measles.json @@ -0,0 +1,18 @@ +{ + "name": "com.minecolonies.coremod.diseases.measles", + "rarity": 10, + "items": [ + { + "item": "minecraft:poppy", + "count": 1 + }, + { + "item": "minecraft:dandelion", + "count": 1 + }, + { + "item": "minecraft:kelp", + "count": 1 + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/minecolonies/colony/diseases/smallpox.json b/src/main/resources/data/minecolonies/colony/diseases/smallpox.json new file mode 100644 index 00000000000..952048a1e15 --- /dev/null +++ b/src/main/resources/data/minecolonies/colony/diseases/smallpox.json @@ -0,0 +1,14 @@ +{ + "name": "com.minecolonies.coremod.diseases.smallpox", + "rarity": 1, + "items": [ + { + "item": "minecraft:honey_bottle", + "count": 1 + }, + { + "item": "minecraft:golden_apple", + "count": 1 + } + ] +} \ No newline at end of file