Skip to content

Commit

Permalink
Relax generics on IGenericLoader
Browse files Browse the repository at this point in the history
Was not used anywhere, and gives me the ability to simplify another task elsewhere
  • Loading branch information
KnightMiner committed Mar 20, 2024
1 parent 019b092 commit 0c6bd56
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.gson.JsonObject;
import net.minecraft.network.FriendlyByteBuf;
import slimeknights.mantle.data.registry.GenericLoaderRegistry.IGenericLoader;
import slimeknights.mantle.data.registry.GenericLoaderRegistry.IHaveLoader;
import slimeknights.mantle.util.JsonHelper;

import java.util.Locale;
Expand All @@ -14,7 +13,7 @@
* @param <O> Object type
* @param <T> Loader type
*/
public record EnumLoader<O extends IHaveLoader<?>, T extends Enum<T>>(
public record EnumLoader<O, T extends Enum<T>>(
String key,
Class<T> enumClass,
Function<T,O> constructor,
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/slimeknights/mantle/data/loader/IntLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.util.GsonHelper;
import slimeknights.mantle.data.registry.GenericLoaderRegistry.IGenericLoader;
import slimeknights.mantle.data.registry.GenericLoaderRegistry.IHaveLoader;

import java.util.function.IntFunction;
import java.util.function.ToIntFunction;

/** Generic serializer for classes that just have a single int value. */
@RequiredArgsConstructor
public class IntLoader<T extends IHaveLoader<?>> implements IGenericLoader<T> {
public class IntLoader<T> implements IGenericLoader<T> {
private final String key;
private final IntFunction<T> constructor;
private final ToIntFunction<T> getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @param <T> Object being loaded
* @param <N> Nested object type
*/
public record NestedLoader<T extends IHaveLoader<?>, N extends IHaveLoader<N>>(
public record NestedLoader<T,N extends IHaveLoader<N>>(
String typeKey,
GenericLoaderRegistry<N> nestedLoader,
Function<N, T> constructor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.registries.IForgeRegistry;
import slimeknights.mantle.data.registry.GenericLoaderRegistry.IGenericLoader;
import slimeknights.mantle.data.registry.GenericLoaderRegistry.IHaveLoader;
import slimeknights.mantle.util.JsonHelper;

import java.util.Objects;
Expand All @@ -16,7 +15,7 @@
* @param <V> Registry entry type
* @see RegistrySetLoader
*/
public record RegistryEntryLoader<O extends IHaveLoader<?>,V>(
public record RegistryEntryLoader<O,V>(
String key,
IForgeRegistry<V> registry,
Function<V,O> constructor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.registries.IForgeRegistry;
import slimeknights.mantle.data.registry.GenericLoaderRegistry.IGenericLoader;
import slimeknights.mantle.data.registry.GenericLoaderRegistry.IHaveLoader;
import slimeknights.mantle.util.JsonHelper;

import java.util.Objects;
Expand All @@ -21,7 +20,7 @@
* @param <T> Loader object type
* @see RegistryEntryLoader
*/
public record RegistrySetLoader<R, T extends IHaveLoader<?>>(
public record RegistrySetLoader<R,T>(
String key,
IForgeRegistry<R> registry,
Function<Set<R>, T> constructor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import slimeknights.mantle.data.registry.GenericLoaderRegistry.IGenericLoader;
import slimeknights.mantle.data.registry.GenericLoaderRegistry.IHaveLoader;
import slimeknights.mantle.util.JsonHelper;

import java.util.function.Function;
Expand All @@ -13,7 +12,7 @@
* Loader for an object with a resource location
* @param <O> Object type
*/
public record ResourceLocationLoader<O extends IHaveLoader<?>>(
public record ResourceLocationLoader<O>(
String key,
Function<ResourceLocation,O> constructor,
Function<O,ResourceLocation> getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.util.GsonHelper;
import slimeknights.mantle.data.registry.GenericLoaderRegistry.IGenericLoader;
import slimeknights.mantle.data.registry.GenericLoaderRegistry.IHaveLoader;

import java.util.function.Function;

/**
* Loader for a string value
* @param <O>
*/
public record StringLoader<O extends IHaveLoader<?>>(
public record StringLoader<O>(
String key,
Function<String,O> constructor,
Function<O,String> getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public T fromNetwork(FriendlyByteBuf buffer) {
}

/** Interface for a loader */
public interface IGenericLoader<T extends IHaveLoader<?>> {
public interface IGenericLoader<T> {
/** Deserializes the object from json */
T deserialize(JsonObject json);

Expand All @@ -199,7 +199,7 @@ public interface IHaveLoader<T> {

/** Loader instance for an object with only a single implementation */
@RequiredArgsConstructor
public static class SingletonLoader<T extends IHaveLoader<?>> implements IGenericLoader<T> {
public static class SingletonLoader<T> implements IGenericLoader<T> {
@Getter
private final T instance;

Expand All @@ -225,7 +225,7 @@ public void serialize(T object, JsonObject json) {}
public void toNetwork(T object, FriendlyByteBuf buffer) {}

/** Helper to create a singleton object as an anonymous class */
public static <T extends IHaveLoader<?>> T singleton(Function<IGenericLoader<T>,T> instance) {
public static <T> T singleton(Function<IGenericLoader<T>,T> instance) {
return new SingletonLoader<>(instance).getInstance();
}
}
Expand Down

0 comments on commit 0c6bd56

Please sign in to comment.