mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
refactor TypeToken to TypeKey
This commit is contained in:
@@ -21,7 +21,7 @@ import com.dfsek.terra.api.addon.annotations.Version;
|
||||
import com.dfsek.terra.api.event.EventListener;
|
||||
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.util.TypeToken;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.util.seeded.SeededBuilder;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.biome.generation.pipeline.BiomeSource;
|
||||
@@ -35,8 +35,8 @@ public class BiomePipelineAddon extends TerraAddon implements EventListener {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
public static final TypeToken<SeededBuilder<BiomeProvider>> BIOME_PROVIDER_BUILDER_TOKEN = new TypeToken<>(){};
|
||||
public static final TypeToken<SeededBuilder<BiomeSource>> BIOME_SOURCE_BUILDER_TOKEN = new TypeToken<>(){};
|
||||
public static final TypeKey<SeededBuilder<BiomeProvider>> BIOME_PROVIDER_BUILDER_TOKEN = new TypeKey<>(){};
|
||||
public static final TypeKey<SeededBuilder<BiomeSource>> BIOME_SOURCE_BUILDER_TOKEN = new TypeKey<>(){};
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.util.TypeToken;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.util.seeded.SeededTerraBiome;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
@@ -16,7 +16,7 @@ public class BiomeConfigType implements ConfigType<BiomeTemplate, SeededTerraBio
|
||||
private final ConfigPack pack;
|
||||
private final BiomeFactory factory;
|
||||
|
||||
public static final TypeToken<SeededTerraBiome> BIOME_TYPE_TOKEN = new TypeToken<>() {};
|
||||
public static final TypeKey<SeededTerraBiome> BIOME_TYPE_TOKEN = new TypeKey<>() {};
|
||||
|
||||
public BiomeConfigType(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
@@ -34,7 +34,7 @@ public class BiomeConfigType implements ConfigType<BiomeTemplate, SeededTerraBio
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeToken<SeededTerraBiome> getTypeClass() {
|
||||
public TypeKey<SeededTerraBiome> getTypeClass() {
|
||||
return BIOME_TYPE_TOKEN;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.util.TypeToken;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.world.Flora;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
@@ -14,7 +14,7 @@ public class FloraConfigType implements ConfigType<FloraTemplate, Flora> {
|
||||
private final FloraFactory factory = new FloraFactory();
|
||||
private final ConfigPack pack;
|
||||
|
||||
public static final TypeToken<Flora> FLORA_TYPE_TOKEN = new TypeToken<>(){};
|
||||
public static final TypeKey<Flora> FLORA_TYPE_TOKEN = new TypeKey<>(){};
|
||||
|
||||
public FloraConfigType(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
@@ -31,7 +31,7 @@ public class FloraConfigType implements ConfigType<FloraTemplate, Flora> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeToken<Flora> getTypeClass() {
|
||||
public TypeKey<Flora> getTypeClass() {
|
||||
return FLORA_TYPE_TOKEN;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ import com.dfsek.terra.api.event.EventListener;
|
||||
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.util.TypeToken;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.util.seeded.SeededNoiseSampler;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -49,7 +49,7 @@ public class NoiseAddon extends TerraAddon implements EventListener {
|
||||
@Inject
|
||||
private TerraPlugin plugin;
|
||||
|
||||
public static final TypeToken<Supplier<ObjectTemplate<SeededNoiseSampler>>> NOISE_SAMPLER_TOKEN = new TypeToken<>() {};
|
||||
public static final TypeKey<Supplier<ObjectTemplate<SeededNoiseSampler>>> NOISE_SAMPLER_TOKEN = new TypeKey<>() {};
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
||||
@@ -6,14 +6,14 @@ import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.util.TypeToken;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class OreConfigType implements ConfigType<OreTemplate, Ore> {
|
||||
private final OreFactory factory = new OreFactory();
|
||||
private final ConfigPack pack;
|
||||
public static final TypeToken<Ore> ORE_TYPE_TOKEN = new TypeToken<>(){};
|
||||
public static final TypeKey<Ore> ORE_TYPE_TOKEN = new TypeKey<>(){};
|
||||
|
||||
public OreConfigType(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
@@ -30,7 +30,7 @@ public class OreConfigType implements ConfigType<OreTemplate, Ore> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeToken<Ore> getTypeClass() {
|
||||
public TypeKey<Ore> getTypeClass() {
|
||||
return ORE_TYPE_TOKEN;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.util.TypeToken;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
@@ -18,7 +18,7 @@ public class PaletteConfigType implements ConfigType<PaletteTemplate, Palette> {
|
||||
private final ConfigPack pack;
|
||||
private final TerraPlugin main;
|
||||
|
||||
public static final TypeToken<Palette> PALETTE_TYPE_TOKEN = new TypeToken<>(){};
|
||||
public static final TypeKey<Palette> PALETTE_TYPE_TOKEN = new TypeKey<>(){};
|
||||
|
||||
public PaletteConfigType(ConfigPack pack, TerraPlugin main) {
|
||||
this.pack = pack;
|
||||
@@ -36,7 +36,7 @@ public class PaletteConfigType implements ConfigType<PaletteTemplate, Palette> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeToken<Palette> getTypeClass() {
|
||||
public TypeKey<Palette> getTypeClass() {
|
||||
return PALETTE_TYPE_TOKEN;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.util.TypeToken;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.world.Tree;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
@@ -14,7 +14,7 @@ public class TreeConfigType implements ConfigType<TreeTemplate, Tree> {
|
||||
private final TreeFactory factory = new TreeFactory();
|
||||
private final ConfigPack pack;
|
||||
|
||||
public static final TypeToken<Tree> TREE_TYPE_TOKEN = new TypeToken<>(){};
|
||||
public static final TypeKey<Tree> TREE_TYPE_TOKEN = new TypeKey<>(){};
|
||||
public TreeConfigType(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public class TreeConfigType implements ConfigType<TreeTemplate, Tree> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeToken<Tree> getTypeClass() {
|
||||
public TypeKey<Tree> getTypeClass() {
|
||||
return TREE_TYPE_TOKEN;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.dfsek.terra.api.registry.meta.RegistryFactory;
|
||||
import com.dfsek.terra.api.registry.meta.RegistryHolder;
|
||||
import com.dfsek.terra.api.tectonic.LoaderHolder;
|
||||
import com.dfsek.terra.api.tectonic.LoaderRegistrar;
|
||||
import com.dfsek.terra.api.util.TypeToken;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.util.seeded.SeededBuilder;
|
||||
import com.dfsek.terra.api.world.TerraWorld;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
@@ -26,7 +26,7 @@ public interface ConfigPack extends LoaderRegistrar, LoaderHolder, RegistryHolde
|
||||
return getOrCreateRegistry((Type) clazz);
|
||||
}
|
||||
|
||||
default <T> CheckedRegistry<T> getOrCreateRegistry(TypeToken<T> type) {
|
||||
default <T> CheckedRegistry<T> getOrCreateRegistry(TypeKey<T> type) {
|
||||
return getOrCreateRegistry(type.getType());
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.dfsek.terra.api.config;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.util.TypeToken;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -11,7 +11,7 @@ public interface ConfigType<T extends AbstractableTemplate, R> {
|
||||
|
||||
ConfigFactory<T, R> getFactory();
|
||||
|
||||
TypeToken<R> getTypeClass();
|
||||
TypeKey<R> getTypeClass();
|
||||
|
||||
Supplier<OpenRegistry<R>> registrySupplier();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.dfsek.terra.api.registry.meta;
|
||||
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.util.TypeToken;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
@@ -11,7 +11,7 @@ public interface RegistryHolder {
|
||||
return getRegistry((Type) clazz);
|
||||
}
|
||||
|
||||
default <T> Registry<T> getRegistry(TypeToken<T> type) {
|
||||
default <T> Registry<T> getRegistry(TypeKey<T> type) {
|
||||
return getRegistry(type.getType());
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public interface RegistryHolder {
|
||||
return getCheckedRegistry((Type) clazz);
|
||||
}
|
||||
|
||||
default <T> CheckedRegistry<T> getCheckedRegistry(TypeToken<T> type) throws IllegalStateException {
|
||||
default <T> CheckedRegistry<T> getCheckedRegistry(TypeKey<T> type) throws IllegalStateException {
|
||||
return getCheckedRegistry(type.getType());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package com.dfsek.terra.api.util;
|
||||
package com.dfsek.terra.api.util.reflection;
|
||||
|
||||
import com.dfsek.terra.api.util.ReflectionUtil;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
public class TypeToken<T> {
|
||||
public class TypeKey<T> {
|
||||
final Class<? super T> rawType;
|
||||
final Type type;
|
||||
final int hashCode;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected TypeToken() {
|
||||
protected TypeKey() {
|
||||
this.type = getSuperclassTypeParameter(getClass());
|
||||
this.rawType = (Class<? super T>) ReflectionUtil.getRawType(type);
|
||||
this.hashCode = type.hashCode();
|
||||
@@ -47,8 +49,8 @@ public class TypeToken<T> {
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object o) {
|
||||
return o instanceof TypeToken<?>
|
||||
&& equals(type, ((TypeToken<?>) o).type);
|
||||
return o instanceof TypeKey<?>
|
||||
&& equals(type, ((TypeKey<?>) o).type);
|
||||
}
|
||||
|
||||
@Override
|
||||
Reference in New Issue
Block a user