Java源码示例:net.minecraft.util.registry.SimpleRegistry
示例1
public static void setupGlobal() {
Set<String> supportedMods = Sets.newHashSet("minecraft", "sandbox", "sandboxapi", "fabricloader");
Sandbox.unsupportedModsLoaded = FabricLoader.getInstance().getAllMods().stream()
.map(ModContainer::getMetadata)
.map(ModMetadata::getId)
.anyMatch(((Predicate<String>) supportedMods::contains).negate());
Policy.setPolicy(new AddonSecurityPolicy());
Registry.REGISTRIES.add(new Identifier("sandbox", "container"), SandboxRegistries.CONTAINER_FACTORIES);
((SandboxInternal.Registry) Registry.BLOCK).set(new BasicRegistry<>(Registry.BLOCK, Block.class, WrappingUtil::convert, WrappingUtil::convert));
((SandboxInternal.Registry) Registry.ITEM).set(new BasicRegistry<>(Registry.ITEM, Item.class, WrappingUtil::convert, WrappingUtil::convert));
((SandboxInternal.Registry) Registry.ENCHANTMENT).set(new BasicRegistry<>((SimpleRegistry<net.minecraft.enchantment.Enchantment>) Registry.ENCHANTMENT, Enchantment.class, WrappingUtil::convert, b -> (Enchantment) b));
((SandboxInternal.Registry) Registry.FLUID).set(new BasicRegistry<>(Registry.FLUID, Fluid.class, WrappingUtil::convert, WrappingUtil::convert));
((SandboxInternal.Registry) Registry.ENTITY_TYPE).set(new BasicRegistry<>(Registry.ENTITY_TYPE, Entity.Type.class, WrappingUtil::convert, WrappingUtil::convert));
((SandboxInternal.Registry) Registry.BLOCK_ENTITY).set(new BasicRegistry((SimpleRegistry) Registry.BLOCK_ENTITY, BlockEntity.Type.class, (Function<BlockEntity.Type, BlockEntityType>) WrappingUtil::convert, (Function<BlockEntityType, BlockEntity.Type>) WrappingUtil::convert, true)); // DONT TOUCH THIS FOR HEAVENS SAKE PLEASE GOD NO
((SandboxInternal.Registry) SandboxRegistries.CONTAINER_FACTORIES).set(new BasicRegistry<>(SandboxRegistries.CONTAINER_FACTORIES, ContainerFactory.class, a -> a, a -> a));
}
示例2
@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);
}
}
示例3
@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);
}
}
}
示例4
@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);
}
示例5
@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;
}
示例6
@SuppressWarnings("unchecked")
public static <T> void restore(Registry<?> registry, DefaultRegistry<?> defaultRegistry) {
((DefaultRegistry<T>) defaultRegistry).restore((SimpleRegistry<T>) registry);
}
示例7
public BasicRegistry(SimpleRegistry<B> vanilla, Class<A> type, Function<A, B> convertAB, Function<B, A> convertBA) {
this.convertAB = convertAB;
this.convertBA = convertBA;
this.vanilla = vanilla;
this.type = type;
}
示例8
public BasicRegistry(SimpleRegistry vanilla, Class type, Function convertAB, Function convertBA, boolean fuck) {
this.convertAB = convertAB;
this.convertBA = convertBA;
this.vanilla = vanilla;
this.type = type;
}
示例9
SimpleRegistry<T> copy();