mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 19:15:32 +00:00
[1.18.2] Fix tags for custom forge registries. (#8495)
Tag-enabled registries must now be registered to vanilla's root registry. See RegistryBuilder#hasTags. Modded tag-enabled registries have to use the format `data/<namespace>/tags/<registrynamespace>/<registryname>/<tag>.json` This format is to prevent conflicts for registries with the same path but different namespaces EX: Registry name `examplemod:shoe`, tag name `blue_shoes` would be `data/<namespace>/tags/examplemod/shoe/blue_shoes.json` RegistryEvent.NewRegistry has been moved and renamed to NewRegistryEvent. RegistryBuilder#create has been made private. See NewRegistryEvent#create Created new ITagManager system for looking up Forge tags. See IForgeRegistry#tags. Add lookup methods for Holders from forge registries. See IForgeRegistry#getHolder.
This commit is contained in:
1 parent
30f3a7dbba
commit
ad75cb8644
51 files changed
+1621
-531
No files matched your search
@@ -5,8 +5,11 @@
|
||||
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -37,14 +40,15 @@ public class DeferredRegistryTest {
|
||||
|
||||
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
|
||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
|
||||
private static final DeferredRegister<Custom> CUSTOMS = DeferredRegister.create(Custom.class, MODID);
|
||||
private static final DeferredRegister<Custom> CUSTOMS = DeferredRegister.create(new ResourceLocation(MODID, "test_registry"), MODID);
|
||||
|
||||
private static final RegistryObject<Block> BLOCK = BLOCKS.register("test", () -> new Block(Block.Properties.of(Material.STONE)));
|
||||
private static final RegistryObject<Item> ITEM = ITEMS .register("test", () -> new BlockItem(BLOCK.get(), new Item.Properties().tab(CreativeModeTab.TAB_BUILDING_BLOCKS)));
|
||||
private static final RegistryObject<Custom> CUSTOM = CUSTOMS.register("test", () -> new Custom(){});
|
||||
|
||||
private static final Supplier<IForgeRegistry<Custom>> CUSTOM_REG = CUSTOMS.makeRegistry("test_registry", () ->
|
||||
new RegistryBuilder<Custom>().disableSaving().setMaxID(Integer.MAX_VALUE - 1)
|
||||
private static final TagKey<Custom> CUSTOM_TAG_KEY = CUSTOMS.createOptionalTagKey("test_tag", Set.of(CUSTOM));
|
||||
private static final Supplier<IForgeRegistry<Custom>> CUSTOM_REG = CUSTOMS.makeRegistry(Custom.class, () ->
|
||||
new RegistryBuilder<Custom>().disableSaving().setMaxID(Integer.MAX_VALUE - 1).hasTags()
|
||||
.onAdd((owner, stage, id, obj, old) -> LOGGER.info("Custom Added: " + id + " " + obj.foo()))
|
||||
);
|
||||
|
||||
|
||||
@@ -7,20 +7,19 @@ package net.minecraftforge.debug;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraftforge.common.ForgeTagHandler;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.Tags;
|
||||
import net.minecraftforge.event.server.ServerStartedEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Tests that the values for defaulted optional tags defined in multiple places are combined.
|
||||
@@ -41,46 +40,35 @@ public class DuplicateOptionalTagTest
|
||||
private static final Set<Supplier<Block>> TAG_A_DEFAULTS = Set.of(Blocks.BEDROCK.delegate);
|
||||
private static final Set<Supplier<Block>> TAG_B_DEFAULTS = Set.of(Blocks.WHITE_WOOL.delegate);
|
||||
|
||||
// TODO-PATCHING: fix or remove this accordingly with optional tags feature (specifically, default values for opt. tags)
|
||||
// private static final Tags.IOptionalNamedTag<Block> TAG_A = ForgeTagHandler.createOptionalTag(ForgeRegistries.BLOCKS, TAG_NAME,
|
||||
// TAG_A_DEFAULTS);
|
||||
// private static final Tags.IOptionalNamedTag<Block> TAG_B = ForgeTagHandler.createOptionalTag(ForgeRegistries.BLOCKS, TAG_NAME,
|
||||
// TAG_B_DEFAULTS);
|
||||
private static final TagKey<Block> TAG_A = ForgeRegistries.BLOCKS.tags().createOptionalTagKey(TAG_NAME, TAG_A_DEFAULTS);
|
||||
private static final TagKey<Block> TAG_B = ForgeRegistries.BLOCKS.tags().createOptionalTagKey(TAG_NAME, TAG_B_DEFAULTS);
|
||||
|
||||
public DuplicateOptionalTagTest()
|
||||
{
|
||||
// MinecraftForge.EVENT_BUS.addListener(this::onServerStarted);
|
||||
MinecraftForge.EVENT_BUS.addListener(this::onServerStarted);
|
||||
}
|
||||
|
||||
// private void onServerStarted(ServerStartedEvent event)
|
||||
// {
|
||||
// if (!TAG_A.isDefaulted())
|
||||
// {
|
||||
// LOGGER.warn("First instance of optional tag is not defaulted!");
|
||||
// }
|
||||
//
|
||||
// if (!TAG_B.isDefaulted())
|
||||
// {
|
||||
// LOGGER.warn("Second instance of optional tag is not defaulted!");
|
||||
// }
|
||||
//
|
||||
// if (!TAG_A.getValues().equals(TAG_B.getValues()))
|
||||
// {
|
||||
// LOGGER.error("Values of both optional tag instances are not the same: first instance: {}, second instance: {}",
|
||||
// TAG_A.getValues(), TAG_B.getValues());
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// final List<Block> expected = Sets.union(TAG_A_DEFAULTS, TAG_B_DEFAULTS).stream()
|
||||
// .map(Supplier::get)
|
||||
// .toList();
|
||||
// if (!TAG_A.getValues().equals(expected))
|
||||
// {
|
||||
// LOGGER.error("Values of the optional tag do not match the expected union of their defaults: expected {}, got {}",
|
||||
// expected, TAG_A.getValues());
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// LOGGER.info("Optional tag instances match each other and the expected union of their defaults");
|
||||
// }
|
||||
private void onServerStarted(ServerStartedEvent event)
|
||||
{
|
||||
Set<Block> tagAValues = ForgeRegistries.BLOCKS.tags().getTag(TAG_A).stream().collect(Collectors.toUnmodifiableSet());
|
||||
Set<Block> tagBValues = ForgeRegistries.BLOCKS.tags().getTag(TAG_B).stream().collect(Collectors.toUnmodifiableSet());
|
||||
|
||||
if (!tagAValues.equals(tagBValues))
|
||||
{
|
||||
LOGGER.error("Values of both optional tag instances are not the same: first instance: {}, second instance: {}", tagAValues, tagBValues);
|
||||
return;
|
||||
}
|
||||
|
||||
final Set<Block> expected = Sets.union(TAG_A_DEFAULTS, TAG_B_DEFAULTS).stream()
|
||||
.map(Supplier::get)
|
||||
.collect(Collectors.toUnmodifiableSet());
|
||||
if (!tagAValues.equals(expected))
|
||||
{
|
||||
IllegalStateException e = new IllegalStateException("Optional tag values do not match!");
|
||||
LOGGER.error("Values of the optional tag do not match the expected union of their defaults: expected {}, got {}", expected, tagAValues, e);
|
||||
return;
|
||||
}
|
||||
|
||||
LOGGER.info("Optional tag instances match each other and the expected union of their defaults");
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,6 @@ public class RegistryObjectTest
|
||||
public void commonSetup(FMLCommonSetupEvent event)
|
||||
{
|
||||
LOGGER.info("Stone 1: {}", RegistryObject.of(new ResourceLocation("minecraft", "stone"), ForgeRegistries.BLOCKS).get());
|
||||
LOGGER.info("Stone 2: {}", RegistryObject.of(new ResourceLocation("minecraft", "stone"), Block.class, MODID).get());
|
||||
LOGGER.info("Stone 2: {}", RegistryObject.of(new ResourceLocation("minecraft", "stone"), ForgeRegistries.BLOCKS.getRegistryKey(), MODID).get());
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.world.entity.ai.attributes.Attribute;
|
||||
import net.minecraft.world.entity.ai.attributes.RangedAttribute;
|
||||
import net.minecraftforge.event.entity.EntityAttributeModificationEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
@@ -17,7 +18,7 @@ import net.minecraftforge.registries.DeferredRegister;
|
||||
@Mod("add_entity_attribute_test")
|
||||
public class AddEntityAttributeTest {
|
||||
public static final boolean ENABLE = true;
|
||||
private static final DeferredRegister<Attribute> ATTRIBUTES = DeferredRegister.create(Attribute.class, "add_entity_attribute_test");
|
||||
private static final DeferredRegister<Attribute> ATTRIBUTES = DeferredRegister.create(ForgeRegistries.ATTRIBUTES, "add_entity_attribute_test");
|
||||
public static final RegistryObject<Attribute> TEST_ATTR = ATTRIBUTES.register("test_attr", () -> new RangedAttribute("forge.test_attr", 1.0D, 0.0D, 1024.0D).setSyncable(true));
|
||||
|
||||
public AddEntityAttributeTest() {
|
||||
|
||||
@@ -66,7 +66,7 @@ public class GlobalLootModifiersTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static final DeferredRegister<GlobalLootModifierSerializer<?>> GLM = DeferredRegister.create(ForgeRegistries.LOOT_MODIFIER_SERIALIZERS, MODID);
|
||||
private static final DeferredRegister<GlobalLootModifierSerializer<?>> GLM = DeferredRegister.create(ForgeRegistries.Keys.LOOT_MODIFIER_SERIALIZERS, MODID);
|
||||
private static final DeferredRegister<Enchantment> ENCHANTS = DeferredRegister.create(ForgeRegistries.ENCHANTMENTS, MODID);
|
||||
|
||||
private static final RegistryObject<DungeonLootEnhancerModifier.Serializer> DUNGEON_LOOT = GLM.register("dungeon_loot", DungeonLootEnhancerModifier.Serializer::new);
|
||||
|
||||
@@ -17,13 +17,14 @@ import net.minecraftforge.common.ToolAction;
|
||||
import net.minecraftforge.common.ToolActions;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
|
||||
@Mod("custom_shield_test")
|
||||
public class CustomShieldTest
|
||||
{
|
||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(Item.class, "custom_shield_test");
|
||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, "custom_shield_test");
|
||||
|
||||
private static final RegistryObject<CustomShieldItem> CUSTOM_SHIELD_ITEM = ITEMS.register("custom_shield",
|
||||
() -> new CustomShieldItem((new Item.Properties()).durability(336).tab(CreativeModeTab.TAB_COMBAT)));
|
||||
|
||||
Reference in new issue
Block a user