Cleanup Tag Loading, this migrates thins to more of a vanilla style. (#7898)

This commit is contained in:
Cyborgmas authored and GitHub committed 2021-08-30 14:58:30 -07:00
1 parent a336e443f7
commit d17f10d80c
27 files changed
+178 -590

No files matched your search

@@ -19,12 +19,12 @@
package net.minecraftforge.debug.misc;
import com.google.common.collect.Sets;
import java.util.Set;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import net.minecraft.core.Registry;
import net.minecraft.data.DataGenerator;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
@@ -68,10 +68,11 @@ public class CustomTagTypesTest
private static final ResourceLocation customRegistryName = new ResourceLocation(MODID, "custom_type_registry");
private static final DeferredRegister<Custom> CUSTOMS = DeferredRegister.create(Custom.class, MODID);
private static final RegistryObject<Custom> CUSTOM = CUSTOMS.register("custom", Custom::new);
private static final ResourceKey<? extends Registry<Custom>> CUSTOM_KEY = ResourceKey.createRegistryKey(customRegistryName);
private static final Supplier<IForgeRegistry<Custom>> CUSTOM_REG = CUSTOMS.makeRegistry(customRegistryName.getPath(),
() -> new RegistryBuilder<Custom>().tagFolder(MODID + "/custom_types"));
private static final Tag.Named<Custom> TESTS = ForgeTagHandler.createOptionalTag(customRegistryName, new ResourceLocation(MODID, "tests"), Sets.newHashSet(CUSTOM));
private static final Tag.Named<Item> OPTIONAL_TEST = ItemTags.createOptional(new ResourceLocation(MODID, "optional_test"), Sets.newHashSet(() -> Items.BONE));
private static final Tag.Named<Custom> TESTS = ForgeTagHandler.createOptionalTag(customRegistryName, new ResourceLocation(MODID, "tests"), Set.of(CUSTOM));
private static final Tag.Named<Item> OPTIONAL_TEST = ItemTags.createOptional(new ResourceLocation(MODID, "optional_test"), Set.of(() -> Items.BONE));
private static final Tag.Named<Enchantment> FIRE = ForgeTagHandler.createOptionalTag(ForgeRegistries.ENCHANTMENTS, new ResourceLocation(MODID, "fire"));
private static final Tag.Named<Potion> DAMAGE = ForgeTagHandler.createOptionalTag(ForgeRegistries.POTIONS, new ResourceLocation(MODID, "damage"));
private static final Tag.Named<BlockEntityType<?>> STORAGE = ForgeTagHandler.createOptionalTag(ForgeRegistries.BLOCK_ENTITIES, new ResourceLocation(MODID, "storage"));
@@ -103,6 +104,7 @@ public class CustomTagTypesTest
if (!itemStack.isEmpty())
{
LOGGER.info("{} {} {}", Items.BONE.getTags(), OPTIONAL_TEST.getValues().size(), SerializationTags.getInstance().getOrEmpty(Registry.ITEM_REGISTRY).getTag(new ResourceLocation(MODID, "optional_test")));
LOGGER.info("{} {}", CUSTOM.get().getTags(), TESTS.getValues().size());
EnchantmentHelper.getEnchantments(itemStack).forEach((enchantment, level) -> logTagsIfPresent(enchantment.getTags()));
if (itemStack.getItem() instanceof PotionItem) logTagsIfPresent(PotionUtils.getPotion(itemStack).getTags());
BlockEntity blockEntity = event.getWorld().getBlockEntity(event.getPos());
@@ -120,17 +122,12 @@ public class CustomTagTypesTest
public static class Custom extends ForgeRegistryEntry<Custom>
{
private final ReverseTagWrapper<Custom> reverseTags = new ReverseTagWrapper<>(this, () -> SerializationTags.getInstance().getCustomTypeCollection(CUSTOM_REG.get()));
private final ReverseTagWrapper<Custom> reverseTags = new ReverseTagWrapper<>(this, () -> SerializationTags.getInstance().getOrEmpty(CUSTOM_KEY));
public Set<ResourceLocation> getTags()
{
return reverseTags.getTagNames();
}
public boolean isIn(Tag<Custom> tag)
{
return tag.contains(this);
}
}
public static class CustomRegistryTags extends ForgeRegistryTagsProvider<Custom>
@@ -203,13 +200,13 @@ public class CustomTagTypesTest
@Override
protected void addTags()
{
tag(STORAGE).add(BlockEntityType.BARREL, BlockEntityType.CHEST, BlockEntityType.ENDER_CHEST);
tag(STORAGE).add(BlockEntityType.BARREL, BlockEntityType.CHEST, BlockEntityType.ENDER_CHEST, BlockEntityType.TRAPPED_CHEST);
}
@Override
public String getName()
{
return "Tile Entity Type Tags";
return "Block Entity Type Tags";
}
}
}