Threadsafe biome add

This commit is contained in:
Frank 2023-06-08 09:39:41 +02:00
parent 2a6f62a0b9
commit a95843d051

View file

@ -98,19 +98,21 @@ public class TagRegistry<T> {
*/
public void add(TagKey<Biome> tagID, ResourceKey<Biome>... elements) {
if (isFrozen) WorldsTogether.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
Set<TagEntry> set = getSetForTag(tagID);
for (ResourceKey<Biome> element : elements) {
ResourceLocation id = element.location();
synchronized (this) {
Set<TagEntry> set = getSetForTag(tagID);
for (ResourceKey<Biome> element : elements) {
ResourceLocation id = element.location();
//only add if the set doesn't already contain the element
for (TagEntry tagEntry : set) {
if (!tagEntry.elementOrTag().tag() && tagEntry.elementOrTag().id().equals(id)) {
id = null;
break;
//only add if the set doesn't already contain the element
for (TagEntry tagEntry : set) {
if (!tagEntry.elementOrTag().tag() && tagEntry.elementOrTag().id().equals(id)) {
id = null;
break;
}
}
if (id != null) {
set.add(TagEntry.element(id));
}
}
if (id != null) {
set.add(TagEntry.element(id));
}
}
}