Skip to content

Commit

Permalink
Rename some classes
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed Apr 24, 2024
1 parent d949960 commit 395e372
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
import net.minecraft.class_2929;
import net.minecraft.util.registry.SimpleRegistry;

import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistryHolder;
import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry;
import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder;
import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable;
import net.legacyfabric.fabric.api.util.Identifier;

@Mixin(SimpleRegistry.class)
public abstract class SimpleRegistryMixin<K, V> implements SyncedRegistryHolder<V>, SyncedRegistrable<V> {
public abstract class SimpleRegistryMixin<K, V> implements SyncedRegistry<V>, SyncedRegistrable<V> {
// 1.8+
@Shadow
public abstract void add(int id, K identifier, V object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,32 @@

import java.util.function.Function;

import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder;
import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry;
import net.legacyfabric.fabric.api.util.Identifier;
import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation;

public class RegistryHelper {
public static <T> void register(RegistryHolder<T> registry, Identifier identifier, T value) {
public static <T> void register(Registry<T> registry, Identifier identifier, T value) {
RegistryHelperImplementation.register(registry, identifier, value);
}

public static <T> void register(Identifier registryId, Identifier identifier, T value) {
register(RegistryHelperImplementation.getRegistry(registryId), identifier, value);
}

public static <T> T register(RegistryHolder<T> registry, Identifier identifier, Function<Integer, T> valueConstructor) {
public static <T> T register(Registry<T> registry, Identifier identifier, Function<Integer, T> valueConstructor) {
return RegistryHelperImplementation.register(registry, identifier, valueConstructor);
}

public static <T> T register(Identifier registryId, Identifier identifier, Function<Integer, T> valueConstructor) {
return register(RegistryHelperImplementation.<T>getRegistry(registryId), identifier, valueConstructor);
}

public static void addRegistry(Identifier identifier, RegistryHolder<?> registryHolder) {
RegistryHelperImplementation.registerRegistry(identifier, registryHolder);
public static void addRegistry(Identifier identifier, Registry<?> registry) {
RegistryHelperImplementation.registerRegistry(identifier, registry);
}

public static <T> RegistryHolder<T> getRegistry(Identifier identifier) {
public static <T> Registry<T> getRegistry(Identifier identifier) {
return RegistryHelperImplementation.getRegistry(identifier);
}

Expand All @@ -53,7 +53,7 @@ public static <T> T getValue(Identifier registryId, Identifier identifier) {
.fabric$getValue(identifier);
}

public static <T> T getValue(RegistryHolder<T> registry, Identifier identifier) {
public static <T> T getValue(Registry<T> registry, Identifier identifier) {
return registry.fabric$getValue(identifier);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package net.legacyfabric.fabric.api.registry.v2.event;

import net.legacyfabric.fabric.api.event.Event;
import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder;
import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry;
import net.legacyfabric.fabric.api.util.Identifier;
import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation;

Expand All @@ -30,7 +30,7 @@ static <T> Event<RegistryBeforeAddCallback<T>> event(Identifier registryId) {
return event(RegistryHelperImplementation.getRegistry(registryId));
}

static <T> Event<RegistryBeforeAddCallback<T>> event(RegistryHolder<T> registry) {
static <T> Event<RegistryBeforeAddCallback<T>> event(Registry<T> registry) {
return registry.fabric$getBeforeAddedCallback();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package net.legacyfabric.fabric.api.registry.v2.event;

import net.legacyfabric.fabric.api.event.Event;
import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder;
import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry;
import net.legacyfabric.fabric.api.util.Identifier;
import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation;

Expand All @@ -30,7 +30,7 @@ static <T> Event<RegistryEntryAddedCallback<T>> event(Identifier registryId) {
return event(RegistryHelperImplementation.getRegistry(registryId));
}

static <T> Event<RegistryEntryAddedCallback<T>> event(RegistryHolder<T> registry) {
static <T> Event<RegistryEntryAddedCallback<T>> event(Registry<T> registry) {
return registry.fabric$getEntryAddedCallback();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package net.legacyfabric.fabric.api.registry.v2.event;

import net.legacyfabric.fabric.api.event.Event;
import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder;
import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry;
import net.legacyfabric.fabric.api.util.Identifier;
import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation;

Expand All @@ -27,7 +27,7 @@
*/
@FunctionalInterface
public interface RegistryInitializedEvent {
<T> void initialized(RegistryHolder<T> registry);
<T> void initialized(Registry<T> registry);

static Event<RegistryInitializedEvent> event(Identifier registryId) {
return RegistryHelperImplementation.getInitializationEvent(registryId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

package net.legacyfabric.fabric.api.registry.v2.registry;

import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistryHolder;
import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable;

public interface SyncedRegistry<T> extends SyncedRegistryHolder<T>, SyncedRegistrable<T> {
public interface SyncedRegistry<T> extends net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry<T>, SyncedRegistrable<T> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback;
import net.legacyfabric.fabric.api.util.Identifier;

public interface RegistryHolder<T> extends Iterable<T> {
public interface Registry<T> extends Iterable<T> {
Identifier fabric$getId();
Event<RegistryEntryAddedCallback<T>> fabric$getEntryAddedCallback();
Event<RegistryBeforeAddCallback<T>> fabric$getBeforeAddedCallback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import net.legacyfabric.fabric.api.util.Identifier;

public interface SyncedRegistryHolder<T> extends RegistryHolder<T> {
public interface SyncedRegistry<T> extends Registry<T> {
int fabric$getRawId(T value);
default int fabric$getRawId(Identifier identifier) {
T value = fabric$getValue(identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import net.legacyfabric.fabric.api.event.Event;
import net.legacyfabric.fabric.api.event.EventFactory;
import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent;
import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder;
import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry;
import net.legacyfabric.fabric.api.registry.v2.registry.registrable.Registrable;
import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable;
import net.legacyfabric.fabric.api.util.Identifier;
Expand All @@ -34,7 +34,7 @@
public class RegistryHelperImplementation {
public static final boolean hasFlatteningBegun = VersionUtils.matches(">=1.8 <=1.12.2");
public static final Map<Identifier, Event<RegistryInitializedEvent>> INITIALIZATION_EVENTS = new HashMap<>();
private static final Map<Identifier, RegistryHolder<?>> REGISTRIES = new HashMap<>();
private static final Map<Identifier, Registry<?>> REGISTRIES = new HashMap<>();

public static Event<RegistryInitializedEvent> getInitializationEvent(Identifier registryId) {
Event<RegistryInitializedEvent> event;
Expand All @@ -45,7 +45,7 @@ public static Event<RegistryInitializedEvent> getInitializationEvent(Identifier
event = EventFactory.createArrayBacked(RegistryInitializedEvent.class,
(callbacks) -> new RegistryInitializedEvent() {
@Override
public <T> void initialized(RegistryHolder<T> registry) {
public <T> void initialized(Registry<T> registry) {
for (RegistryInitializedEvent callback : callbacks) {
callback.initialized(registry);
}
Expand All @@ -58,18 +58,18 @@ public <T> void initialized(RegistryHolder<T> registry) {
return event;
}

public static <T> RegistryHolder<T> getRegistry(Identifier identifier) {
return (RegistryHolder<T>) REGISTRIES.get(identifier);
public static <T> Registry<T> getRegistry(Identifier identifier) {
return (Registry<T>) REGISTRIES.get(identifier);
}

public static void registerRegistry(Identifier identifier, RegistryHolder<?> holder) {
public static void registerRegistry(Identifier identifier, Registry<?> holder) {
if (REGISTRIES.containsKey(identifier)) throw new IllegalArgumentException("Attempted to register registry " + identifier.toString() + " twices!");
REGISTRIES.put(identifier, holder);

if (holder instanceof RegistryIdSetter) ((RegistryIdSetter) holder).fabric$setId(identifier);
}

public static <T> void register(RegistryHolder<T> registry, Identifier identifier, T value) {
public static <T> void register(Registry<T> registry, Identifier identifier, T value) {
if (!(registry instanceof Registrable)) throw new IllegalArgumentException("Can't register object to non registrable registry " + registry.fabric$getId());

Registrable<T> registrable = (Registrable<T>) registry;
Expand All @@ -82,7 +82,7 @@ public static <T> void register(RegistryHolder<T> registry, Identifier identifie
registrable.fabric$register(computedId, identifier, value);
}

public static <T> T register(RegistryHolder<T> registry, Identifier identifier, Function<Integer, T> valueConstructor) {
public static <T> T register(Registry<T> registry, Identifier identifier, Function<Integer, T> valueConstructor) {
if (!(registry instanceof SyncedRegistrable)) throw new IllegalArgumentException("Can't register object to non registrable registry " + registry.fabric$getId());

SyncedRegistrable<T> registrable = (SyncedRegistrable<T>) registry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
import net.legacyfabric.fabric.api.event.EventFactory;
import net.legacyfabric.fabric.api.registry.v2.event.RegistryBeforeAddCallback;
import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback;
import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder;
import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry;
import net.legacyfabric.fabric.api.registry.v2.registry.registrable.Registrable;
import net.legacyfabric.fabric.api.util.Identifier;
import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation;
import net.legacyfabric.fabric.impl.registry.accessor.RegistryIdSetter;

@Mixin(MutableRegistry.class)
public abstract class MutableRegistryMixin<K, V> implements RegistryHolder<V>, RegistryIdSetter, Registrable<V> {
public abstract class MutableRegistryMixin<K, V> implements Registry<V>, RegistryIdSetter, Registrable<V> {
@Shadow
public abstract void put(Object key, Object value);

Expand Down

0 comments on commit 395e372

Please sign in to comment.