net.minecraft.util.registry.DefaultedRegistry Java Examples
The following examples show how to use
net.minecraft.util.registry.DefaultedRegistry.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Identifiers.java From patchwork-api with GNU Lesser General Public License v2.1 | 6 votes |
/** * Gets the current {@link Identifier} for the object in the registry if it exists. If the object does not exist in * the provided registry, {@code fallback} will be returned instead. * * @param registry the registry to query. Must NOT be an instance of {@link DefaultedRegistry}, or else this method * will throw an {@link IllegalArgumentException}. * @return an {@link Identifier} if the instance is registered or if the fallback is non null, otherwise null */ @Nullable public static <T> Identifier getOrFallback(Registry<T> registry, T instance, @Nullable Identifier fallback) { if (registry instanceof DefaultedRegistry) { // While we could just cast here, I want to catch these cases where they come up and fix them in the mixin. throw new IllegalArgumentException("Used the non-defaulted getOrFallback method with a DefaultedRegistry"); } Identifier current = registry.getId(instance); if (current == null) { return fallback; } else { return current; } }
Example #2
Source File: AbstractProtocol.java From multiconnect with MIT License | 5 votes |
@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); } } }
Example #3
Source File: ForgeRegistry.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
@Override public Identifier getDefaultKey() { if (vanilla instanceof DefaultedRegistry) { return ((DefaultedRegistry<V>) vanilla).getDefaultId(); } return null; }
Example #4
Source File: Identifiers.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
/** * Gets the current {@link Identifier} for the object in the registry if it exists. If the object does not exist in * the provided registry, {@code fallback} will be returned instead. * * @param registry the registry to query. Must be an instance of {@link DefaultedRegistry}. * @return an {@link Identifier} if the instance is registered or if the fallback is non null, otherwise null */ @Nullable public static <T> Identifier getOrFallback(DefaultedRegistry<T> registry, T instance, @Nullable Identifier fallback) { Identifier current = registry.getId(instance); if (current.equals(registry.getDefaultId())) { return fallback; } else { return current; } }
Example #5
Source File: NpcClothingFeature.java From MineLittlePony with MIT License | 5 votes |
public <K> VillagerResourceMetadata.HatType getHatType(Object2ObjectMap<K, HatType> cache, String type, DefaultedRegistry<K> registry, K key) { if (cache.containsKey(key)) { return cache.get(key); // People often complain that villagers cause lag, // so let's do better than Mojang and rather NOT go // through all the lambda generations if we can avoid it. } return loadHatType(cache, type, registry, key); }
Example #6
Source File: NpcClothingFeature.java From MineLittlePony with MIT License | 5 votes |
private <K> VillagerResourceMetadata.HatType loadHatType(Map<K, HatType> cache, String type, DefaultedRegistry<K> registry, K key) { return cache.computeIfAbsent(key, k -> { try (Resource res = resourceManager.getResource(findTexture(type, registry.getId(k)))) { VillagerResourceMetadata meta = res.getMetadata(VillagerResourceMetadata.READER); if (meta != null) { return meta.getHatType(); } } catch (IOException e) { } return HatType.NONE; }); }
Example #7
Source File: TypeAwareBuyForOneEmeraldFactoryMixin.java From Galacticraft-Rewoven with MIT License | 4 votes |
@SuppressWarnings("UnnecessaryQualifiedMemberReference") @Redirect(method = "Lnet/minecraft/village/TradeOffers$TypeAwareBuyForOneEmeraldFactory;<init>(IIILjava/util/Map;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/registry/DefaultedRegistry;stream()Ljava/util/stream/Stream;")) private Stream<VillagerType> skipCheck(DefaultedRegistry<VillagerType> defaultedRegistry) { return Stream.empty(); //skip check }