下面列出了net.minecraft.util.registry.RegistryKey#of ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void mutateEntityTypeRegistry(ISimpleRegistry<EntityType<?>> registry) {
registry.unregister(EntityType.CAT);
int ocelotId = Registry.ENTITY_TYPE.getRawId(EntityType.OCELOT);
registry.unregister(EntityType.OCELOT);
RegistryKey<EntityType<?>> ocelotKey = RegistryKey.of(registry.getRegistryKey(), new Identifier("ocelot"));
registry.register(EntityType.CAT, ocelotId, ocelotKey);
registry.unregister(EntityType.FOX);
registry.unregister(EntityType.PANDA);
registry.unregister(EntityType.PILLAGER);
registry.unregister(EntityType.RAVAGER);
registry.unregister(EntityType.TRADER_LLAMA);
registry.unregister(EntityType.WANDERING_TRADER);
registry.unregister(EntityType.TRIDENT);
insertAfter(registry, EntityType.FISHING_BOBBER, EntityType.TRIDENT, "trident");
ENTITY_REGISTRY_1_13 = registry.copy();
}
@SuppressWarnings("unchecked")
public static <T> void insertAfter(ISimpleRegistry<T> registry, T element, T toInsert, String id, boolean inPlace) {
RegistryKey<T> key = RegistryKey.of(registry.getRegistryKey(), new Identifier(id));
int numericalId = ((SimpleRegistry<T>) registry).getRawId(element) + 1;
if (inPlace) {
registry.registerInPlace(toInsert, numericalId, key);
} else {
registry.register(toInsert, numericalId, key);
}
}
@SuppressWarnings("unchecked")
protected <T> void postMutateRegistry(Registry<T> registry) {
if (!(registry instanceof SimpleRegistry)) return;
if (registry instanceof DefaultedRegistry) return;
ISimpleRegistry<T> iregistry = (ISimpleRegistry<T>) registry;
DefaultRegistry<T> defaultRegistry = (DefaultRegistry<T>) DefaultRegistry.DEFAULT_REGISTRIES.get(registry);
if (defaultRegistry == null) return;
for (Map.Entry<Identifier, T> entry : defaultRegistry.defaultEntriesById.entrySet()) {
if (registry.getId(entry.getValue()) == null) {
RegistryKey<T> key = RegistryKey.of(iregistry.getRegistryKey(), entry.getKey());
iregistry.register(entry.getValue(), iregistry.getNextId(), key, false);
}
}
}
@SuppressWarnings("unchecked")
public static <T> void rename(ISimpleRegistry<T> registry, T value, String newName) {
int id = ((SimpleRegistry<T>) registry).getRawId(value);
registry.purge(value);
RegistryKey<T> key = RegistryKey.of(registry.getRegistryKey(), new Identifier(newName));
registry.registerInPlace(value, id, key);
}
private void mutateRecipeSerializerRegistry(ISimpleRegistry<RecipeSerializer<?>> registry) {
registry.unregister(RecipeSerializer.SUSPICIOUS_STEW);
registry.unregister(RecipeSerializer.BLASTING);
registry.unregister(RecipeSerializer.SMOKING);
registry.unregister(RecipeSerializer.CAMPFIRE_COOKING);
registry.unregister(RecipeSerializer.STONECUTTING);
RegistryKey<RecipeSerializer<?>> bannerAddPatternKey = RegistryKey.of(registry.getRegistryKey(), new Identifier("crafting_special_banneraddpattern"));
registry.register(AddBannerPatternRecipe.SERIALIZER, registry.getNextId(), bannerAddPatternKey);
}
private static void register(ISimpleRegistry<EntityType<?>> registry, EntityType<?> entity, int id, String name, String oldName) {
RegistryKey<EntityType<?>> key = RegistryKey.of(registry.getRegistryKey(), new Identifier(name));
registry.register(entity, id, key, false);
}
private static void register(ISimpleRegistry<ParticleType<?>> registry, ParticleType<?> particle, int id, String name) {
RegistryKey<ParticleType<?>> key = RegistryKey.of(registry.getRegistryKey(), new Identifier(name));
registry.register(particle, id, key, false);
}
private static void register(ISimpleRegistry<Block> registry, Block block, int id, String name) {
RegistryKey<Block> key = RegistryKey.of(registry.getRegistryKey(), new Identifier(name));
registry.registerInPlace(block, id, key, false);
}
private static void register(ISimpleRegistry<Enchantment> registry, Enchantment enchantment, int id, String name) {
RegistryKey<Enchantment> key = RegistryKey.of(registry.getRegistryKey(), new Identifier(name));
registry.register(enchantment, id, key, false);
}
private static void register(ISimpleRegistry<Item> registry, Item item, int id, String name) {
RegistryKey<Item> key = RegistryKey.of(registry.getRegistryKey(), new Identifier(name));
registry.registerInPlace(item, id, key, false);
}
private static void registerBlockItem(ISimpleRegistry<Item> registry, Block block) {
RegistryKey<Item> key = RegistryKey.of(registry.getRegistryKey(), Registry.BLOCK.getId(block));
registry.registerInPlace(Item.BLOCK_ITEMS.getOrDefault(block, AIR), Registry.BLOCK.getRawId(block), key, false);
}
public static void register() {
Registry.register(Registry.CHUNK_GENERATOR, new Identifier(Constants.MOD_ID, "moon"), MoonChunkGenerator.CODEC);
MOON = RegistryKey.of(Registry.DIMENSION, new Identifier(Constants.MOD_ID, "moon"));
FabricDimensions.registerDefaultPlacer(MOON, GalacticraftDimensions::placeEntity);
}