Files
MinecraftForge/src/main/java/net/minecraftforge/registries/MissingMappingsEvent.java
T
4ed9117799 Forge 1.19
* Bump pack.mcmeta formats
* 1.19 biome modifiers
* Mark ClientPlayerNetworkEvent.LoggedOutEvent's getters as nullable
* Add docs and package-info to client extension interfaces package
* Move RenderBlockOverlayEvent hooks to ForgeHooksClient
* Add package-infos to client events package
* Rename SoundLoadEvent to SoundEngineLoadEvent

This reduces confusion from consumers which may think the
name SoundLoadEvent refers to an individual sound being loaded rather
than the sound engine.
* Document and change SoundLoadEvent to fire on mod bus

Previously, it fired on both the mod bus and the Forge bus, which is
confusing for consumers.
* Delete SoundSetupEvent

Looking at its original implementation shows that there isn't an
appropriate place in the new sound code to reinsert the event, and the
place of 'sound engine/manager initialization event' is taken already by SoundLoadEvent.
* Perform some cleanup on client events

 - Removed nullable annotations from ClientPlayerNetworkEvent
 - Renamed #getPartialTicks methods to #getPartialTick, to be consistent
  with vanilla's naming of the partial tick
 - Cleanup documentation to remove line breaks, use the
  spelling 'cancelled' over
  'canceled', and improve docs on existing and
   new methods.
* Remove EntityEvent.CanUpdate

Closes MinecraftForge/MinecraftForge#6394
* Switch to Jetbrains nullability annotations
* New PlayLevelSoundEvent; replaces old PlaySoundAtEntityEvent
* Remove ForgeWorldPresetScreens
* Remove IForgeRegistryEntry
* Remove use of List<Throwable> in FML's CompletableFutures
* Add docs to mod loading stages, stages, and phases
* Gradle 7.4.2
* Use SLF4J in FMLLoader and other subprojects
* Switch dynamic versions in subprojects to pinned ones
* Switch ForgeRoot and MDK to FG plugin markers
* Configure Forge javadoc task

The task now uses a custom stylesheet with MCForge elements, and
configured to combine the generation from the four FML subprojects
(fmlloader, fmlcore, javafmllanguage, mclanguage) and the Forge project
into the javadoc output.
* Update docs/md files, for 1.19 update and the move away from IRC to Discord.
* Make "Potentially dangerous alternative prefix" a debug warning, not info.

Co-authored-by: Curle <curle@gemwire.uk>
Co-authored-by: sciwhiz12 <arnoldnunag12@gmail.com>
Signed-off-by: SizableShrimp <sizableshrimp@sizableshrimp.me>
2022-06-07 15:31:26 -05:00

181 lines
5.0 KiB
Java

/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.registries;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.eventbus.api.Event;
import org.apache.commons.lang3.Validate;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
/**
* Fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS forge bus}.
*/
public class MissingMappingsEvent extends Event
{
private final ResourceKey<? extends Registry<?>> key;
private final IForgeRegistry<?> registry;
private final List<Mapping<?>> mappings;
public MissingMappingsEvent(ResourceKey<? extends Registry<?>> key, IForgeRegistry<?> registry, Collection<Mapping<?>> missed)
{
this.key = key;
this.registry = registry;
this.mappings = List.copyOf(missed);
}
public ResourceKey<? extends Registry<?>> getKey()
{
return this.key;
}
public IForgeRegistry<?> getRegistry()
{
return this.registry;
}
/**
* @return An immutable list of missing mappings for the given namespace.
* Empty if the registry key doesn't match {@link #getKey()}.
*/
@SuppressWarnings("unchecked")
public <T> List<Mapping<T>> getMappings(ResourceKey<? extends Registry<T>> registryKey, String namespace)
{
return registryKey == this.key
? (List<Mapping<T>>) (List<?>) this.mappings.stream().filter(e -> e.key.getNamespace().equals(namespace)).toList()
: List.of();
}
/**
* @return An immutable list of all missing mappings.
* Empty if the registry key doesn't match {@link #getKey()}.
*/
@SuppressWarnings("unchecked")
public <T> List<Mapping<T>> getAllMappings(ResourceKey<? extends Registry<T>> registryKey)
{
return registryKey == this.key ? (List<Mapping<T>>) (List<?>) this.mappings : List.of();
}
/**
* Actions you can take with this missing mapping.
* <ul>
* <li>{@link #IGNORE} means this missing mapping will be ignored.
* <li>{@link #WARN} means this missing mapping will generate a warning.
* <li>{@link #FAIL} means this missing mapping will prevent the world from loading.
* </ul>
*/
public enum Action
{
/**
* Take the default action
*/
DEFAULT,
/**
* Ignore this missing mapping. This means the mapping will be abandoned
*/
IGNORE,
/**
* Generate a warning but allow loading to continue
*/
WARN,
/**
* Fail to load
*/
FAIL,
/**
* Remap this name to a new name (add a migration mapping)
*/
REMAP
}
public static class Mapping<T> implements Comparable<Mapping<T>>
{
private final IForgeRegistry<T> registry;
private final IForgeRegistry<T> pool;
final ResourceLocation key;
final int id;
Action action = Action.DEFAULT;
T target;
public Mapping(IForgeRegistry<T> registry, IForgeRegistry<T> pool, ResourceLocation key, int id)
{
this.registry = registry;
this.pool = pool;
this.key = key;
this.id = id;
}
/**
* Ignore the missing item.
*/
public void ignore()
{
action = Action.IGNORE;
}
/**
* Warn the user about the missing item.
*/
public void warn()
{
action = Action.WARN;
}
/**
* Prevent the world from loading due to the missing item.
*/
public void fail()
{
action = Action.FAIL;
}
/**
* Remap the missing entry to the specified object.
* <p>
* Use this if you have renamed an entry.
* Existing references using the old name will point to the new one.
*
* @param target Entry to remap to.
*/
public void remap(T target)
{
Validate.notNull(target, "Remap target can not be null");
Validate.isTrue(pool.getKey(target) != null,
String.format(Locale.ENGLISH, "The specified entry %s hasn't been registered in registry yet.", target));
action = Action.REMAP;
this.target = target;
}
public IForgeRegistry<T> getRegistry()
{
return this.registry;
}
public ResourceLocation getKey()
{
return key;
}
public int getId()
{
return this.id;
}
@Override
public int compareTo(Mapping<T> o)
{
int ret = this.registry.getRegistryName().compareNamespaced(o.registry.getRegistryName());
if (ret == 0)
ret = this.key.compareNamespaced(o.key);
return ret;
}
}
}