下面列出了怎么用net.minecraft.util.registry.RegistryKey的API类实例代码及写法,或者点击链接到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);
}
@Override
public void register(T t, int id, RegistryKey<T> key, boolean sideEffects) {
for (int remapId = getNextId(); remapId > id; remapId--) {
T toRemap = indexedEntries.get(remapId - 1);
//noinspection unchecked
((IInt2ObjectBiMap<T>) indexedEntries).multiconnect_remove(toRemap);
indexedEntries.put(toRemap, remapId);
}
setNextId(getNextId() + 1);
set(id, key, t);
if (sideEffects)
registerListeners.forEach(listener -> listener.onUpdate(t, false));
}
@Override
public void registerInPlace(T t, int id, RegistryKey<T> key, boolean sideEffects) {
if (id == getNextId())
setNextId(id + 1);
set(id, key, t);
if (sideEffects)
registerListeners.forEach(listener -> listener.onUpdate(t, true));
}
@SuppressWarnings("unchecked")
@Override
public SimpleRegistry<T> copy() {
SimpleRegistry<T> newRegistry = new SimpleRegistry<>(getRegistryKey(), ((RegistryAccessor<T>) this).getLifecycle());
for (Map.Entry<RegistryKey<T>, T> entry : entriesByKey.entrySet()) {
newRegistry.set(indexedEntries.getId(entry.getValue()), entry.getKey(), entry.getValue());
}
return newRegistry;
}
default void register(T t, int id, RegistryKey<T> key) {
register(t, id, key, true);
}
default void registerInPlace(T t, int id, RegistryKey<T> key) {
registerInPlace(t, id, key, true);
}
private void mutateCustomStatRegistry(ISimpleRegistry<Identifier> registry) {
registry.register(JUNK_FISHED, registry.getNextId(), RegistryKey.of(registry.getRegistryKey(), JUNK_FISHED));
registry.register(TREASURE_FISHED, registry.getNextId(), RegistryKey.of(registry.getRegistryKey(), TREASURE_FISHED));
Stats.CUSTOM.getOrCreateStat(JUNK_FISHED, StatFormatter.DEFAULT);
Stats.CUSTOM.getOrCreateStat(TREASURE_FISHED, StatFormatter.DEFAULT);
}
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);
}
@Accessor("registryKey")
RegistryKey<Registry<T>> multiconnect_getRegistryKey();
@SuppressWarnings("unchecked")
@Override
public RegistryKey<Registry<T>> getRegistryKey() {
return ((RegistryAccessor<T>) this).multiconnect_getRegistryKey();
}
@Accessor
@Override
public abstract BiMap<RegistryKey, T> getEntriesByKey();
protected WorldMixin_RealTime(MutableWorldProperties mutableWorldProperties, RegistryKey<World> registryKey, RegistryKey<DimensionType> registryKey2, DimensionType dimensionType, Supplier<Profiler> profiler, boolean bl, boolean bl2, long l) {
super(mutableWorldProperties, registryKey, registryKey2, dimensionType, profiler, bl, bl2, l);
}
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);
}
RegistryKey<Registry<T>> getRegistryKey();
BiMap<RegistryKey, T> getEntriesByKey();
void register(T t, int id, RegistryKey<T> key, boolean sideEffects);
void registerInPlace(T t, int id, RegistryKey<T> key, boolean sideEffects);
@Shadow public abstract <V extends T> V set(int rawId, RegistryKey<T> id, V value);