mirror of
https://github.com/FabricMC/fabric.git
synced 2025-03-27 23:29:58 -04:00
Fixed some generics
This commit is contained in:
parent
e5def8e7eb
commit
1e30c89370
3 changed files with 18 additions and 19 deletions
fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric
api/event/registry
impl/registry/sync
mixin/registry/sync
|
@ -24,14 +24,15 @@ import net.fabricmc.fabric.api.event.Event;
|
|||
import net.fabricmc.fabric.impl.registry.sync.DynamicRegistryEvents;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface DynamicRegistryEntryAddedCallback {
|
||||
void onEntryAdded(int rawId, RegistryKey<?> key, Object object, MutableRegistry<?> registry);
|
||||
public interface DynamicRegistryEntryAddedCallback<T> {
|
||||
void onEntryAdded(int rawId, RegistryKey<T> key, T object, MutableRegistry<T> registry);
|
||||
|
||||
static Event<DynamicRegistryEntryAddedCallback> event(RegistryKey<? extends Registry<?>> registryKey) {
|
||||
@SuppressWarnings("unchecked")
|
||||
static <T> Event<DynamicRegistryEntryAddedCallback<T>> event(RegistryKey<? extends Registry<T>> registryKey) {
|
||||
if (!DynamicRegistryEvents.ADD_ENTRY_EVENTS.containsKey(registryKey)) {
|
||||
throw new IllegalArgumentException("Unsupported registry: " + registryKey);
|
||||
}
|
||||
|
||||
return DynamicRegistryEvents.ADD_ENTRY_EVENTS.get(registryKey);
|
||||
return (Event<DynamicRegistryEntryAddedCallback<T>>) DynamicRegistryEvents.ADD_ENTRY_EVENTS.get(registryKey);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,24 +28,22 @@ import net.fabricmc.fabric.api.event.EventFactory;
|
|||
import net.fabricmc.fabric.api.event.registry.DynamicRegistryEntryAddedCallback;
|
||||
import net.fabricmc.fabric.mixin.registry.sync.DynamicRegistryManagerAccessor;
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public final class DynamicRegistryEvents {
|
||||
public static Map<RegistryKey<? extends Registry<?>>, Event<DynamicRegistryEntryAddedCallback>> ADD_ENTRY_EVENTS;
|
||||
|
||||
private DynamicRegistryEvents() {
|
||||
}
|
||||
public static final Map<RegistryKey<? extends Registry<?>>, Event<?>> ADD_ENTRY_EVENTS;
|
||||
|
||||
static {
|
||||
ADD_ENTRY_EVENTS = Maps.newLinkedHashMap();
|
||||
|
||||
for (RegistryKey<? extends Registry<?>> registryKey : DynamicRegistryManagerAccessor.getInfos().keySet()) {
|
||||
ADD_ENTRY_EVENTS.put(registryKey,
|
||||
EventFactory.createArrayBacked(
|
||||
DynamicRegistryEntryAddedCallback.class,
|
||||
callbacks -> (rawId, key, object, registry) -> {
|
||||
for (DynamicRegistryEntryAddedCallback callback : callbacks) {
|
||||
callback.onEntryAdded(rawId, key, object, registry);
|
||||
}
|
||||
}));
|
||||
ADD_ENTRY_EVENTS.put(registryKey, EventFactory.createArrayBacked(DynamicRegistryEntryAddedCallback.class,
|
||||
callbacks -> (rawId, key, object, registry) -> {
|
||||
for (DynamicRegistryEntryAddedCallback callback : callbacks) {
|
||||
callback.onEntryAdded(rawId, key, object, registry);
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private DynamicRegistryEvents() { }
|
||||
}
|
||||
|
|
|
@ -35,14 +35,14 @@ import net.fabricmc.fabric.impl.registry.sync.DynamicRegistryEvents;
|
|||
|
||||
@Mixin(DynamicRegistryManager.class)
|
||||
public class DynamicRegistryManagerMixin {
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Inject(method = "create", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/dynamic/RegistryOps$class_5506$class_5507;<init>()V"), locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
private static void onCreateImpl(CallbackInfoReturnable<DynamicRegistryManager.Impl> cir, DynamicRegistryManager.Impl registryManager) {
|
||||
for (Map.Entry<RegistryKey<? extends Registry<?>>, Event<DynamicRegistryEntryAddedCallback>> event : DynamicRegistryEvents.ADD_ENTRY_EVENTS.entrySet()) {
|
||||
//noinspection unchecked
|
||||
for (Map.Entry<RegistryKey<? extends Registry<?>>, Event<?>> event : DynamicRegistryEvents.ADD_ENTRY_EVENTS.entrySet()) {
|
||||
RegistryKey<? extends Registry<Object>> registryKey = (RegistryKey<? extends Registry<Object>>) event.getKey();
|
||||
RegistryEntryAddedCallback.event(registryManager.get(registryKey)).register((rawId, id, object) -> {
|
||||
RegistryKey<?> key = RegistryKey.of(registryKey, id);
|
||||
event.getValue().invoker().onEntryAdded(rawId, key, object, registryManager.get(registryKey));
|
||||
((DynamicRegistryEntryAddedCallback) event.getValue().invoker()).onEntryAdded(rawId, key, object, registryManager.get(registryKey));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue