Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework diseases to become datapacks #10361

Merged
merged 13 commits into from
Dec 1, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,6 @@ public class CompatibilityManager implements ICompatibilityManager
*/
private ImmutableSet<ItemStorage> beekeeperflowers = ImmutableSet.of();

/**
* Set of all possible diseases.
*/
private final Map<String, Disease> diseases = new HashMap<>();

/**
* List of diseases including the random factor.
*/
private final List<String> diseaseList = new ArrayList<>();

/**
* List of lucky oreBlocks which get dropped by the miner.
*/
Expand Down Expand Up @@ -177,8 +167,6 @@ private void clear()

luckyOres.clear();
recruitmentCostsWeights.clear();
diseases.clear();
diseaseList.clear();
monsters = ImmutableSet.of();
creativeModeTabMap.clear();
}
Expand All @@ -196,7 +184,6 @@ public void discover(@NotNull final RecipeManager recipeManager, final Level lev

discoverLuckyOres();
discoverRecruitCosts();
discoverDiseases();
discoverModCompat();

discoverCompostRecipes(recipeManager);
Expand Down Expand Up @@ -252,7 +239,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
discoverLuckyOres();
discoverRecruitCosts();
discoverDiseases();
discoverModCompat();
}

Expand Down Expand Up @@ -469,24 +455,6 @@ public Set<ItemStorage> 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<Disease> getDiseases()
{
return new ArrayList<>(diseases.values());
}

@Override
public List<Tuple<Item, Integer>> getRecruitmentCostsWeights()
{
Expand Down Expand Up @@ -897,57 +865,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<ItemStack> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -139,28 +138,6 @@ public interface ICompatibilityManager
*/
ImmutableSet<ResourceLocation> 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<Disease> getDiseases();

/**
* Gets the list of recruitment costs with weights
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public class ServerConfiguration extends AbstractConfiguration
public final ForgeConfigSpec.ConfigValue<List<? extends String>> configListStudyItems;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> configListRecruitmentItems;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> luckyOres;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> diseases;
public final ForgeConfigSpec.BooleanValue auditCraftingTags;
public final ForgeConfigSpec.BooleanValue debugInventories;
public final ForgeConfigSpec.BooleanValue blueprintBuildMode;
Expand Down Expand Up @@ -227,12 +226,6 @@ protected ServerConfiguration(final ForgeConfigSpec.Builder builder)
"minecraft:emerald_ore!1"),
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.minecolonies.api.entity.citizen.citizenhandlers;

import com.minecolonies.api.entity.citizen.AbstractEntityCitizen;
import com.minecolonies.core.datalistener.model.Disease;
import net.minecraft.nbt.CompoundTag;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Citizen disease handler interface.
Expand Down Expand Up @@ -36,11 +38,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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public BlockPos getPos()
}

/**
* Get for the remaining items.
* Get for the remaining items.
* @return
*/
public List<ItemStack> getRemainingItems()
Expand Down
88 changes: 0 additions & 88 deletions src/main/java/com/minecolonies/api/util/Disease.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static void init()
citizen -> citizen.getColony() != null && citizen.getEntity().isPresent() && citizen.getEntity().get().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.getEntity().get().getCitizenDiseaseHandler().getDisease().isEmpty());
citizen -> citizen.getColony() != null && citizen.getEntity().isPresent() && citizen.getEntity().get().getCitizenDiseaseHandler().getDisease() != null);

InteractionValidatorRegistry.registerPosBasedPredicate(Component.translatable(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL),
(citizen, pos) ->
Expand Down
Loading