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

Methods in TheEndBiomeData that query the intended type. #2369

Open
wants to merge 13 commits into
base: 1.19
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,49 @@ public static void addMidlandsBiome(RegistryKey<Biome> highlands, RegistryKey<Bi
public static void addBarrensBiome(RegistryKey<Biome> highlands, RegistryKey<Biome> barrens, double weight) {
TheEndBiomeData.addEndBarrensReplacement(highlands, barrens, weight);
}

/**
* Returns true if the given biome was added as a main end Biome in the end, considering the Vanilla end biomes,
* and any biomes added to the End by mods.
* @param biome The biome to search for
*/
public static boolean canGenerateAsMainIslandBiome(RegistryKey<Biome> biome){
return TheEndBiomeData.canGenerateAsEndBiomeIn(BiomeKeys.THE_END, biome);
}

/**
* Returns true if the given biome was added as a small end islands Biome in the end, considering the Vanilla end biomes,
* and any biomes added to the End by mods.
* @param biome The biome to search for
*/
public static boolean canGenerateAsSmallIslandsBiome(RegistryKey<Biome> biome){
return TheEndBiomeData.canGenerateAsEndBiomeIn(BiomeKeys.SMALL_END_ISLANDS, biome);
}

/**
* Returns true if the given biome was added as a Highland Biome in the end, considering the Vanilla end biomes,
* and any biomes added to the End by mods.
* @param biome The biome to search for
*/
public static boolean canGenerateAsHighlandsBiome(RegistryKey<Biome> biome){
return TheEndBiomeData.canGenerateAsEndBiomeIn(BiomeKeys.END_HIGHLANDS, biome);
}

/**
* Returns true if the given biome was added as midland biome in the end, considering the Vanilla end biomes,
* and any biomes added to the End as midland biome by mods.
* @param biome The biome to search for
*/
public static boolean canGenerateAsEndMidlands(RegistryKey<Biome> biome){
return TheEndBiomeData.canGenerateAsEndMidlands(biome);
}

/**
* Returns true if the given biome was added as barrens biome in the end, considering the Vanilla end biomes,
* and any biomes added to the End as barrens biome by mods.
* @param biome The biome to search for
*/
public static boolean canGenerateAsEndBarrens(RegistryKey<Biome> biome){
return TheEndBiomeData.canGenerateAsEndBarrens(biome);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,38 @@ public static void addEndBarrensReplacement(RegistryKey<Biome> highlands, Regist
ADDED_BIOMES.add(barrens);
}

private static boolean containsValue(Map<RegistryKey<Biome>, WeightedPicker<RegistryKey<Biome>>> map, RegistryKey<Biome> biome){
return map.values().stream().anyMatch(w->w.getAny(biome).isPresent());
}

/**
* Returns true if the given biome was added for the specified keyBiome in the end, considering the Vanilla end biomes,
* and any biomes added to the End by mods.
*
* @param keyBiome The parent biome type
* @param biome The biome you are looking for
*/
public static boolean canGenerateAsEndBiomeIn(RegistryKey<Biome> keyBiome, RegistryKey<Biome> biome){
WeightedPicker<RegistryKey<Biome>> highlandBiomes = END_BIOMES_MAP.get(keyBiome);
return highlandBiomes!=null && highlandBiomes.getAny(biome).isPresent();
}

/**
* Returns true if the given biome was added as midland biome in the end, considering the Vanilla end biomes,
* and any biomes added to the End as midland biome by mods.
*/
public static boolean canGenerateAsEndMidlands(RegistryKey<Biome> biome){
return containsValue(END_MIDLANDS_MAP, biome);
}

/**
* Returns true if the given biome was added as barrens biome in the end, considering the Vanilla end biomes,
* and any biomes added to the End as barrens biome by mods.
*/
public static boolean canGenerateAsEndBarrens(RegistryKey<Biome> biome){
return containsValue(END_BARRENS_MAP, biome);
}

public static Overrides createOverrides(Registry<Biome> biomeRegistry) {
return new Overrides(biomeRegistry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;

import com.google.common.base.Preconditions;
Expand Down Expand Up @@ -100,6 +101,16 @@ WeightedEntry<T> search(final double target) {
return entries.get(low);
}

/**
* Returns any {@link WeightedEntry} that contains the passed element.
*
* @param element The Element you are looking for
* @return The result of the search
*/
Optional<WeightedEntry<T>> getAny(T element){
return entries.stream().filter(w -> w.entry==element).findAny();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this, you might want to look into changing TheEndBiomeData#ADDED_BIOMES into a Map<RegistryKey<Biome>, RegistryKey<Biome>> instead, with vanilla biome as its value. Then you can check if the value is equal to the vanilla biome.

Patch file

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that is much cleaner. I'll include the suggested patch...


/**
* Represents a modded entry in a list, and its corresponding weight.
*
Expand Down