Remove hacks around RegistryEntry (#144)

This commit is contained in:
shedaniel
2021-12-11 19:05:13 +08:00
parent 7857615bfc
commit ebbc2a6490
6 changed files with 97 additions and 55 deletions

View File

@@ -19,8 +19,41 @@
package dev.architectury.core;
import com.google.common.reflect.TypeToken;
import dev.architectury.injectables.annotations.PlatformOnly;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
/**
* An entry in registries, will extend {@code ForgeRegistryEntry} on forge.
* An entry in registries, will implement methods from {@code IForgeRegistryEntry}.
*/
public class RegistryEntry<T> {
private final TypeToken<T> token = new TypeToken<T>(getClass()) {
};
private ResourceLocation registryName = null;
@ApiStatus.Internal
@PlatformOnly(PlatformOnly.FORGE)
public T setRegistryName(ResourceLocation name) {
if (registryName != null) {
throw new IllegalStateException("Tried to override registry name from previous " + registryName + " to " + name);
}
registryName = name;
return (T) this;
}
@Nullable
@ApiStatus.Internal
@PlatformOnly(PlatformOnly.FORGE)
public ResourceLocation getRegistryName() {
return registryName;
}
@ApiStatus.Internal
@PlatformOnly(PlatformOnly.FORGE)
public Class<T> getRegistryType() {
return (Class<T>) token.getRawType();
}
}