Add patches to enable MobEffects with IDs > 255 (#8380)

This commit is contained in:
Take Weiland authored and GitHub committed 2022-03-21 23:10:33 -07:00
1 parent 7f23b3b525
commit 415cdd0588
7 files changed
+218 -10

No files matched your search

@@ -25,6 +25,7 @@ import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.common.base.Strings;
import com.google.common.base.Suppliers;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
@@ -45,10 +46,12 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import it.unimi.dsi.fastutil.longs.LongSet;
import net.minecraft.ResourceLocationException;
import net.minecraft.advancements.Advancement;
import net.minecraft.core.*;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
@@ -1401,4 +1404,32 @@ public class ForgeHooks
LOGGER.error(WORLDPERSISTENCE, buf.toString());
}
}
public static void saveMobEffect(CompoundTag nbt, String key, MobEffect effect)
{
var registryName = effect.getRegistryName();
if (registryName != null)
{
nbt.putString(key, registryName.toString());
}
}
@Nullable
public static MobEffect loadMobEffect(CompoundTag nbt, String key, @Nullable MobEffect fallback)
{
var registryName = nbt.getString(key);
if (Strings.isNullOrEmpty(registryName))
{
return fallback;
}
try
{
return ForgeRegistries.MOB_EFFECTS.getValue(new ResourceLocation(registryName));
}
catch (ResourceLocationException e)
{
return fallback;
}
}
}