From 9674cb06ce8b245565651fffb72cf09764c7371b Mon Sep 17 00:00:00 2001 From: dhyces <10985914+dhyces@users.noreply.github.com> Date: Tue, 28 May 2024 21:23:04 -0700 Subject: [PATCH] Rename MapKeyResolver to KeyResolver --- .../dev/dhyces/trimmed/TrimmedClient.java | 7 +- .../client/TrimmedClientApiEntrypoint.java | 6 +- .../api/client/TrimmedClientMapApi.java | 5 +- ...eyResolver.java => ClientKeyResolver.java} | 4 +- .../api/client/map/ClientKeyResolvers.java | 10 + .../api/client/map/ClientMapKeyResolvers.java | 10 - .../api/client/map/ClientMapTypes.java | 4 +- .../{MapKeyResolver.java => KeyResolver.java} | 4 +- .../api/maps/types/AdvancedMapType.java | 17 +- .../trimmed/api/maps/types/MapType.java | 18 +- .../trimmed/api/maps/types/SimpleMapType.java | 16 +- .../impl/client/TrimmedClientMapApiImpl.java | 8 +- .../client/TrimmedClientRegistrationImpl.java | 18 +- .../impl/client/maps/KeyResolvers.java | 214 ++++++++++++++++ .../impl/client/maps/MapKeyResolvers.java | 234 ------------------ .../client/maps/manager/ClientMapManager.java | 8 +- 16 files changed, 280 insertions(+), 303 deletions(-) rename common/src/main/java/dev/dhyces/trimmed/api/client/map/{ClientMapKeyResolver.java => ClientKeyResolver.java} (75%) create mode 100644 common/src/main/java/dev/dhyces/trimmed/api/client/map/ClientKeyResolvers.java delete mode 100644 common/src/main/java/dev/dhyces/trimmed/api/client/map/ClientMapKeyResolvers.java rename common/src/main/java/dev/dhyces/trimmed/api/maps/{MapKeyResolver.java => KeyResolver.java} (85%) create mode 100644 common/src/main/java/dev/dhyces/trimmed/impl/client/maps/KeyResolvers.java delete mode 100644 common/src/main/java/dev/dhyces/trimmed/impl/client/maps/MapKeyResolvers.java diff --git a/common/src/main/java/dev/dhyces/trimmed/TrimmedClient.java b/common/src/main/java/dev/dhyces/trimmed/TrimmedClient.java index 2deb464f..73f44ffe 100644 --- a/common/src/main/java/dev/dhyces/trimmed/TrimmedClient.java +++ b/common/src/main/java/dev/dhyces/trimmed/TrimmedClient.java @@ -1,13 +1,13 @@ package dev.dhyces.trimmed; import dev.dhyces.trimmed.api.client.TrimmedClientApiEntrypoint; -import dev.dhyces.trimmed.api.client.map.ClientMapKeyResolvers; +import dev.dhyces.trimmed.api.client.map.ClientKeyResolvers; import dev.dhyces.trimmed.api.client.map.ClientMapKeys; import dev.dhyces.trimmed.api.client.map.ClientMapTypes; import dev.dhyces.trimmed.impl.ModApiConsumer; import dev.dhyces.trimmed.impl.client.TrimmedClientRegistrationImpl; import dev.dhyces.trimmed.impl.client.atlas.TrimmedSpriteSourceTypes; -import dev.dhyces.trimmed.impl.client.maps.MapKeyResolvers; +import dev.dhyces.trimmed.impl.client.maps.KeyResolvers; import dev.dhyces.trimmed.impl.client.models.override.ItemOverrideReloadListener; import dev.dhyces.trimmed.impl.client.models.override.provider.ItemOverrideProviderRegistry; import dev.dhyces.trimmed.impl.client.models.source.ModelSourceLoader; @@ -24,7 +24,6 @@ import net.minecraft.server.packs.resources.ResourceManager; import java.util.Collection; -import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.function.BiConsumer; @@ -32,7 +31,7 @@ public class TrimmedClient { public static void init() { - MapKeyResolvers.register(Trimmed.id("texture"), ClientMapKeyResolvers.TEXTURE); + KeyResolvers.register(Trimmed.id("texture"), ClientKeyResolvers.TEXTURE); ClientMapTypes.init(); ClientMapManager.registerBaseKey(ClientMapKeys.MATERIAL_SUFFIXES); ClientMapManager.registerBaseKey(ClientMapKeys.TRIM_MATERIAL_OVERRIDES); diff --git a/common/src/main/java/dev/dhyces/trimmed/api/client/TrimmedClientApiEntrypoint.java b/common/src/main/java/dev/dhyces/trimmed/api/client/TrimmedClientApiEntrypoint.java index 2956d98d..8a300649 100644 --- a/common/src/main/java/dev/dhyces/trimmed/api/client/TrimmedClientApiEntrypoint.java +++ b/common/src/main/java/dev/dhyces/trimmed/api/client/TrimmedClientApiEntrypoint.java @@ -3,7 +3,7 @@ import dev.dhyces.trimmed.api.client.override.provider.ItemOverrideProvider; import dev.dhyces.trimmed.api.client.override.provider.ItemOverrideProviderType; import dev.dhyces.trimmed.api.maps.MapKey; -import dev.dhyces.trimmed.api.maps.MapKeyResolver; +import dev.dhyces.trimmed.api.maps.KeyResolver; import net.minecraft.resources.ResourceLocation; import java.util.function.Supplier; @@ -30,9 +30,9 @@ interface TrimmedClientRegistration { * @return * @param */ - MapKeyResolver getOrRegisterMapKeyResolver(ResourceLocation id, Supplier> resolverSupplier); + KeyResolver getOrRegisterKeyResolver(ResourceLocation id, Supplier> resolverSupplier); - MapKeyResolver registerMapKeyResolver(ResourceLocation id, MapKeyResolver resolver); + KeyResolver registerKeyResolver(ResourceLocation id, KeyResolver resolver); MapKey registerBaseMapKey(MapKey mapKey); } diff --git a/common/src/main/java/dev/dhyces/trimmed/api/client/TrimmedClientMapApi.java b/common/src/main/java/dev/dhyces/trimmed/api/client/TrimmedClientMapApi.java index fd903ea0..f8d3dbe7 100644 --- a/common/src/main/java/dev/dhyces/trimmed/api/client/TrimmedClientMapApi.java +++ b/common/src/main/java/dev/dhyces/trimmed/api/client/TrimmedClientMapApi.java @@ -2,14 +2,13 @@ import com.mojang.serialization.Codec; import dev.dhyces.trimmed.api.maps.MapHolder; -import dev.dhyces.trimmed.api.maps.MapKeyResolver; +import dev.dhyces.trimmed.api.maps.KeyResolver; import dev.dhyces.trimmed.api.maps.types.AdvancedMapType; import dev.dhyces.trimmed.api.maps.types.MapType; import dev.dhyces.trimmed.impl.client.TrimmedClientMapApiImpl; import dev.dhyces.trimmed.api.maps.MapKey; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.Nullable; import java.util.Map; @@ -28,5 +27,5 @@ static TrimmedClientMapApi getInstance() { > Codec> advancedCodec(AdvancedMapType mapType); @Nullable - MapKeyResolver getRegistryMapKeyResolver(ResourceKey> id); + KeyResolver getRegistryKeyResolver(ResourceKey> id); } diff --git a/common/src/main/java/dev/dhyces/trimmed/api/client/map/ClientMapKeyResolver.java b/common/src/main/java/dev/dhyces/trimmed/api/client/map/ClientKeyResolver.java similarity index 75% rename from common/src/main/java/dev/dhyces/trimmed/api/client/map/ClientMapKeyResolver.java rename to common/src/main/java/dev/dhyces/trimmed/api/client/map/ClientKeyResolver.java index 1450fac0..8a3c213e 100644 --- a/common/src/main/java/dev/dhyces/trimmed/api/client/map/ClientMapKeyResolver.java +++ b/common/src/main/java/dev/dhyces/trimmed/api/client/map/ClientKeyResolver.java @@ -1,12 +1,12 @@ package dev.dhyces.trimmed.api.client.map; import com.mojang.serialization.Codec; -import dev.dhyces.trimmed.api.maps.MapKeyResolver; +import dev.dhyces.trimmed.api.maps.KeyResolver; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; import org.jetbrains.annotations.Nullable; -public record ClientMapKeyResolver(Codec codec) implements MapKeyResolver { +public record ClientKeyResolver(Codec codec) implements KeyResolver { @Override public Codec getCodec() { diff --git a/common/src/main/java/dev/dhyces/trimmed/api/client/map/ClientKeyResolvers.java b/common/src/main/java/dev/dhyces/trimmed/api/client/map/ClientKeyResolvers.java new file mode 100644 index 00000000..6b44f4c4 --- /dev/null +++ b/common/src/main/java/dev/dhyces/trimmed/api/client/map/ClientKeyResolvers.java @@ -0,0 +1,10 @@ +package dev.dhyces.trimmed.api.client.map; + +import dev.dhyces.trimmed.api.maps.KeyResolver; +import net.minecraft.resources.ResourceLocation; + +public final class ClientKeyResolvers { + private ClientKeyResolvers() {} + + public static final KeyResolver TEXTURE = new ClientKeyResolver<>(ResourceLocation.CODEC); +} diff --git a/common/src/main/java/dev/dhyces/trimmed/api/client/map/ClientMapKeyResolvers.java b/common/src/main/java/dev/dhyces/trimmed/api/client/map/ClientMapKeyResolvers.java deleted file mode 100644 index 335fb966..00000000 --- a/common/src/main/java/dev/dhyces/trimmed/api/client/map/ClientMapKeyResolvers.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.dhyces.trimmed.api.client.map; - -import dev.dhyces.trimmed.api.maps.MapKeyResolver; -import net.minecraft.resources.ResourceLocation; - -public final class ClientMapKeyResolvers { - private ClientMapKeyResolvers() {} - - public static final MapKeyResolver TEXTURE = new ClientMapKeyResolver<>(ResourceLocation.CODEC); -} diff --git a/common/src/main/java/dev/dhyces/trimmed/api/client/map/ClientMapTypes.java b/common/src/main/java/dev/dhyces/trimmed/api/client/map/ClientMapTypes.java index 4f38fd2c..25c55e42 100644 --- a/common/src/main/java/dev/dhyces/trimmed/api/client/map/ClientMapTypes.java +++ b/common/src/main/java/dev/dhyces/trimmed/api/client/map/ClientMapTypes.java @@ -26,6 +26,6 @@ public static MapType registerType(ResourceLocation id, MapType TEXTURE_SUFFIX = registerType(Trimmed.id("texture_suffix"), MapType.simpleBuilder(ClientMapKeyResolvers.TEXTURE, Codec.STRING).build()); - public static final MapType TEXTURE_MAPPING = registerType(Trimmed.id("texture_mapping"), MapType.simpleBuilder(ClientMapKeyResolvers.TEXTURE, ResourceLocation.CODEC).build()); + public static final MapType TEXTURE_SUFFIX = registerType(Trimmed.id("texture_suffix"), MapType.simpleBuilder(ClientKeyResolvers.TEXTURE, Codec.STRING).build()); + public static final MapType TEXTURE_MAPPING = registerType(Trimmed.id("texture_mapping"), MapType.simpleBuilder(ClientKeyResolvers.TEXTURE, ResourceLocation.CODEC).build()); } diff --git a/common/src/main/java/dev/dhyces/trimmed/api/maps/MapKeyResolver.java b/common/src/main/java/dev/dhyces/trimmed/api/maps/KeyResolver.java similarity index 85% rename from common/src/main/java/dev/dhyces/trimmed/api/maps/MapKeyResolver.java rename to common/src/main/java/dev/dhyces/trimmed/api/maps/KeyResolver.java index 13c6b05e..3a605d47 100644 --- a/common/src/main/java/dev/dhyces/trimmed/api/maps/MapKeyResolver.java +++ b/common/src/main/java/dev/dhyces/trimmed/api/maps/KeyResolver.java @@ -7,12 +7,12 @@ import net.minecraft.network.codec.StreamCodec; import org.jetbrains.annotations.Nullable; -public interface MapKeyResolver { +public interface KeyResolver { Codec getCodec(); @Nullable StreamCodec getStreamCodec(); - record RegistryWrapper(Registry registry) implements MapKeyResolver { + record RegistryWrapper(Registry registry) implements KeyResolver { @Override public Codec getCodec() { diff --git a/common/src/main/java/dev/dhyces/trimmed/api/maps/types/AdvancedMapType.java b/common/src/main/java/dev/dhyces/trimmed/api/maps/types/AdvancedMapType.java index 61afedd2..809b7ad8 100644 --- a/common/src/main/java/dev/dhyces/trimmed/api/maps/types/AdvancedMapType.java +++ b/common/src/main/java/dev/dhyces/trimmed/api/maps/types/AdvancedMapType.java @@ -1,9 +1,8 @@ package dev.dhyces.trimmed.api.maps.types; import com.mojang.serialization.Codec; -import com.mojang.serialization.MapCodec; -import dev.dhyces.trimmed.api.maps.MapKeyResolver; -import dev.dhyces.trimmed.impl.client.maps.MapKeyResolvers; +import dev.dhyces.trimmed.api.maps.KeyResolver; +import dev.dhyces.trimmed.impl.client.maps.KeyResolvers; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.ResourceLocation; @@ -14,14 +13,14 @@ import java.util.function.Supplier; public final class AdvancedMapType> implements MapType { - private final MapKeyResolver keyResolver; + private final KeyResolver keyResolver; private final Codec valueCodec; @Nullable private final StreamCodec valueStreamCodec; private final boolean dataPackSynced; private final Supplier mapSupplier; - AdvancedMapType(MapKeyResolver keyResolver, Codec valueCodec, @Nullable StreamCodec valueStreamCodec, boolean dataPackSynced, @Nullable Supplier mapSupplier) { + AdvancedMapType(KeyResolver keyResolver, Codec valueCodec, @Nullable StreamCodec valueStreamCodec, boolean dataPackSynced, @Nullable Supplier mapSupplier) { this.keyResolver = keyResolver; this.valueCodec = valueCodec; this.valueStreamCodec = valueStreamCodec; @@ -29,12 +28,12 @@ public final class AdvancedMapType> implements MapType this.mapSupplier = mapSupplier; } - public static > Builder builder(MapKeyResolver keyResolver, Codec valueCodec) { + public static > Builder builder(KeyResolver keyResolver, Codec valueCodec) { return new Builder<>(keyResolver, valueCodec); } @Override - public MapKeyResolver getKeyResolver() { + public KeyResolver getKeyResolver() { return keyResolver; } @@ -76,13 +75,13 @@ public int hashCode() { @Override public String toString() { - ResourceLocation resolverId = MapKeyResolvers.getId(keyResolver); + ResourceLocation resolverId = KeyResolvers.getId(keyResolver); return "AdvancedMapType[map_key_resolver: " + (resolverId == null ? "unregistered" : resolverId) + "]"; } public static class Builder> extends BaseBuilder { private Supplier mapSupplier; - protected Builder(MapKeyResolver keyResolver, Codec valueCodec) { + protected Builder(KeyResolver keyResolver, Codec valueCodec) { super(keyResolver, valueCodec); } diff --git a/common/src/main/java/dev/dhyces/trimmed/api/maps/types/MapType.java b/common/src/main/java/dev/dhyces/trimmed/api/maps/types/MapType.java index 98bb51f6..30751985 100644 --- a/common/src/main/java/dev/dhyces/trimmed/api/maps/types/MapType.java +++ b/common/src/main/java/dev/dhyces/trimmed/api/maps/types/MapType.java @@ -1,7 +1,7 @@ package dev.dhyces.trimmed.api.maps.types; import com.mojang.serialization.Codec; -import dev.dhyces.trimmed.api.maps.MapKeyResolver; +import dev.dhyces.trimmed.api.maps.KeyResolver; import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.Reference2ObjectLinkedOpenHashMap; import net.minecraft.network.RegistryFriendlyByteBuf; @@ -14,44 +14,44 @@ // TODO: Add optional validator public sealed interface MapType permits SimpleMapType, AdvancedMapType { - MapKeyResolver getKeyResolver(); + KeyResolver getKeyResolver(); Codec getValueCodec(); @Nullable StreamCodec getValueStreamCodec(); boolean isDataPackSynced(); default Map createMap() { - if (getKeyResolver() instanceof MapKeyResolver.RegistryWrapper) { + if (getKeyResolver() instanceof KeyResolver.RegistryWrapper) { return new Reference2ObjectLinkedOpenHashMap<>(); } else { return new Object2ObjectLinkedOpenHashMap<>(); } } - static SimpleMapType simple(MapKeyResolver keyResolver, Codec valueCodec) { + static SimpleMapType simple(KeyResolver keyResolver, Codec valueCodec) { return new SimpleMapType<>(keyResolver, valueCodec, null, false); } - static SimpleMapType.Builder simpleBuilder(MapKeyResolver keyResolver, Codec valueCodec) { + static SimpleMapType.Builder simpleBuilder(KeyResolver keyResolver, Codec valueCodec) { return SimpleMapType.builder(keyResolver, valueCodec); } - static > AdvancedMapType advancedCollection(MapKeyResolver keyResolver, Codec valueCodec, Supplier mapSupplier) { + static > AdvancedMapType advancedCollection(KeyResolver keyResolver, Codec valueCodec, Supplier mapSupplier) { return new AdvancedMapType<>(keyResolver, valueCodec, null, false, mapSupplier); } - static > AdvancedMapType.Builder advancedBuilder(MapKeyResolver keyResolver, Codec valueCodec) { + static > AdvancedMapType.Builder advancedBuilder(KeyResolver keyResolver, Codec valueCodec) { return AdvancedMapType.builder(keyResolver, valueCodec); } abstract class BaseBuilder { - protected final MapKeyResolver keyResolver; + protected final KeyResolver keyResolver; protected final Codec valueCodec; @Nullable protected StreamCodec valueStreamCodec; protected boolean dataPackSynced = false; - protected BaseBuilder(MapKeyResolver keyResolver, Codec valueCodec) { + protected BaseBuilder(KeyResolver keyResolver, Codec valueCodec) { this.keyResolver = keyResolver; this.valueCodec = valueCodec; } diff --git a/common/src/main/java/dev/dhyces/trimmed/api/maps/types/SimpleMapType.java b/common/src/main/java/dev/dhyces/trimmed/api/maps/types/SimpleMapType.java index 25507c3c..baa73e33 100644 --- a/common/src/main/java/dev/dhyces/trimmed/api/maps/types/SimpleMapType.java +++ b/common/src/main/java/dev/dhyces/trimmed/api/maps/types/SimpleMapType.java @@ -1,8 +1,8 @@ package dev.dhyces.trimmed.api.maps.types; import com.mojang.serialization.Codec; -import dev.dhyces.trimmed.api.maps.MapKeyResolver; -import dev.dhyces.trimmed.impl.client.maps.MapKeyResolvers; +import dev.dhyces.trimmed.api.maps.KeyResolver; +import dev.dhyces.trimmed.impl.client.maps.KeyResolvers; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.ResourceLocation; @@ -11,25 +11,25 @@ import java.util.Objects; public final class SimpleMapType implements MapType { - private final MapKeyResolver keyResolver; + private final KeyResolver keyResolver; private final Codec valueCodec; @Nullable private final StreamCodec valueStreamCodec; private final boolean dataPackSynced; - SimpleMapType(MapKeyResolver keyResolver, Codec valueCodec, @Nullable StreamCodec valueStreamCodec, boolean dataPackSynced) { + SimpleMapType(KeyResolver keyResolver, Codec valueCodec, @Nullable StreamCodec valueStreamCodec, boolean dataPackSynced) { this.keyResolver = keyResolver; this.valueCodec = valueCodec; this.valueStreamCodec = valueStreamCodec; this.dataPackSynced = dataPackSynced; } - public static SimpleMapType.Builder builder(MapKeyResolver keyResolver, Codec valueCodec) { + public static SimpleMapType.Builder builder(KeyResolver keyResolver, Codec valueCodec) { return new SimpleMapType.Builder<>(keyResolver, valueCodec); } @Override - public MapKeyResolver getKeyResolver() { + public KeyResolver getKeyResolver() { return keyResolver; } @@ -63,12 +63,12 @@ public int hashCode() { @Override public String toString() { - ResourceLocation resolverId = MapKeyResolvers.getId(keyResolver); + ResourceLocation resolverId = KeyResolvers.getId(keyResolver); return "SimpleMapType[map_key_resolver: " + (resolverId == null ? "unregistered" : resolverId) + "]"; } public static class Builder extends BaseBuilder { - protected Builder(MapKeyResolver keyResolver, Codec valueCodec) { + protected Builder(KeyResolver keyResolver, Codec valueCodec) { super(keyResolver, valueCodec); } diff --git a/common/src/main/java/dev/dhyces/trimmed/impl/client/TrimmedClientMapApiImpl.java b/common/src/main/java/dev/dhyces/trimmed/impl/client/TrimmedClientMapApiImpl.java index f553c400..1066ba53 100644 --- a/common/src/main/java/dev/dhyces/trimmed/impl/client/TrimmedClientMapApiImpl.java +++ b/common/src/main/java/dev/dhyces/trimmed/impl/client/TrimmedClientMapApiImpl.java @@ -3,11 +3,11 @@ import com.mojang.serialization.Codec; import dev.dhyces.trimmed.api.client.TrimmedClientMapApi; import dev.dhyces.trimmed.api.maps.MapHolder; -import dev.dhyces.trimmed.api.maps.MapKeyResolver; +import dev.dhyces.trimmed.api.maps.KeyResolver; import dev.dhyces.trimmed.api.maps.types.AdvancedMapType; import dev.dhyces.trimmed.api.maps.types.MapType; import dev.dhyces.trimmed.api.maps.MapKey; -import dev.dhyces.trimmed.impl.client.maps.MapKeyResolvers; +import dev.dhyces.trimmed.impl.client.maps.KeyResolvers; import dev.dhyces.trimmed.impl.client.maps.manager.ClientMapManager; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; @@ -40,7 +40,7 @@ public > Codec> advancedCodec } @Override - public @Nullable MapKeyResolver getRegistryMapKeyResolver(ResourceKey> id) { - return MapKeyResolvers.getResolver(id.location()); + public @Nullable KeyResolver getRegistryKeyResolver(ResourceKey> id) { + return KeyResolvers.getResolver(id.location()); } } diff --git a/common/src/main/java/dev/dhyces/trimmed/impl/client/TrimmedClientRegistrationImpl.java b/common/src/main/java/dev/dhyces/trimmed/impl/client/TrimmedClientRegistrationImpl.java index 8fe32657..5cf7c4ec 100644 --- a/common/src/main/java/dev/dhyces/trimmed/impl/client/TrimmedClientRegistrationImpl.java +++ b/common/src/main/java/dev/dhyces/trimmed/impl/client/TrimmedClientRegistrationImpl.java @@ -4,8 +4,8 @@ import dev.dhyces.trimmed.api.client.override.provider.ItemOverrideProvider; import dev.dhyces.trimmed.api.client.override.provider.ItemOverrideProviderType; import dev.dhyces.trimmed.api.maps.MapKey; -import dev.dhyces.trimmed.api.maps.MapKeyResolver; -import dev.dhyces.trimmed.impl.client.maps.MapKeyResolvers; +import dev.dhyces.trimmed.api.maps.KeyResolver; +import dev.dhyces.trimmed.impl.client.maps.KeyResolvers; import dev.dhyces.trimmed.impl.client.maps.manager.ClientMapManager; import dev.dhyces.trimmed.impl.client.models.override.provider.ItemOverrideProviderRegistry; import net.minecraft.resources.ResourceLocation; @@ -20,23 +20,23 @@ public ItemOverrideProviderType registerItem } @Override - public MapKeyResolver getOrRegisterMapKeyResolver(ResourceLocation id, Supplier> resolverSupplier) { - MapKeyResolver resolver; + public KeyResolver getOrRegisterKeyResolver(ResourceLocation id, Supplier> resolverSupplier) { + KeyResolver resolver; try { - resolver = MapKeyResolvers.getResolver(id); + resolver = KeyResolvers.getResolver(id); } catch (ClassCastException e) { - throw new IllegalArgumentException("Tried to cast " + MapKeyResolvers.getResolver(id) + " for the ID " + id); + throw new IllegalArgumentException("Tried to cast " + KeyResolvers.getResolver(id) + " for the ID " + id); } if (resolver == null) { resolver = resolverSupplier.get(); - MapKeyResolvers.register(id, resolver); + KeyResolvers.register(id, resolver); } return resolver; } @Override - public MapKeyResolver registerMapKeyResolver(ResourceLocation id, MapKeyResolver resolver) { - MapKeyResolvers.register(id, resolver); + public KeyResolver registerKeyResolver(ResourceLocation id, KeyResolver resolver) { + KeyResolvers.register(id, resolver); return resolver; } diff --git a/common/src/main/java/dev/dhyces/trimmed/impl/client/maps/KeyResolvers.java b/common/src/main/java/dev/dhyces/trimmed/impl/client/maps/KeyResolvers.java new file mode 100644 index 00000000..d6baf1d5 --- /dev/null +++ b/common/src/main/java/dev/dhyces/trimmed/impl/client/maps/KeyResolvers.java @@ -0,0 +1,214 @@ +package dev.dhyces.trimmed.impl.client.maps; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import com.mojang.serialization.MapCodec; +import dev.dhyces.trimmed.api.maps.KeyResolver; +import net.minecraft.advancements.CriterionTrigger; +import net.minecraft.advancements.critereon.EntitySubPredicate; +import net.minecraft.advancements.critereon.ItemSubPredicate; +import net.minecraft.commands.synchronization.ArgumentTypeInfo; +import net.minecraft.core.Registry; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.core.particles.ParticleType; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.network.chat.numbers.NumberFormatType; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.stats.StatType; +import net.minecraft.util.valueproviders.FloatProviderType; +import net.minecraft.util.valueproviders.IntProviderType; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.ai.attributes.Attribute; +import net.minecraft.world.entity.ai.memory.MemoryModuleType; +import net.minecraft.world.entity.ai.sensing.SensorType; +import net.minecraft.world.entity.ai.village.poi.PoiType; +import net.minecraft.world.entity.animal.CatVariant; +import net.minecraft.world.entity.animal.FrogVariant; +import net.minecraft.world.entity.decoration.PaintingVariant; +import net.minecraft.world.entity.npc.VillagerProfession; +import net.minecraft.world.entity.npc.VillagerType; +import net.minecraft.world.entity.schedule.Activity; +import net.minecraft.world.entity.schedule.Schedule; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ArmorMaterial; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Instrument; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.alchemy.Potion; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.biome.BiomeSource; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.chunk.status.ChunkStatus; +import net.minecraft.world.level.dimension.LevelStem; +import net.minecraft.world.level.gameevent.GameEvent; +import net.minecraft.world.level.gameevent.PositionSourceType; +import net.minecraft.world.level.levelgen.DensityFunction; +import net.minecraft.world.level.levelgen.SurfaceRules; +import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicateType; +import net.minecraft.world.level.levelgen.carver.WorldCarver; +import net.minecraft.world.level.levelgen.feature.Feature; +import net.minecraft.world.level.levelgen.feature.featuresize.FeatureSizeType; +import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacerType; +import net.minecraft.world.level.levelgen.feature.rootplacers.RootPlacerType; +import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProviderType; +import net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecoratorType; +import net.minecraft.world.level.levelgen.feature.trunkplacers.TrunkPlacerType; +import net.minecraft.world.level.levelgen.heightproviders.HeightProviderType; +import net.minecraft.world.level.levelgen.placement.PlacementModifierType; +import net.minecraft.world.level.levelgen.structure.StructureType; +import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType; +import net.minecraft.world.level.levelgen.structure.placement.StructurePlacementType; +import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElementType; +import net.minecraft.world.level.levelgen.structure.pools.alias.PoolAliasBinding; +import net.minecraft.world.level.levelgen.structure.templatesystem.PosRuleTestType; +import net.minecraft.world.level.levelgen.structure.templatesystem.RuleTestType; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorType; +import net.minecraft.world.level.levelgen.structure.templatesystem.rule.blockentity.RuleBlockEntityModifierType; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.saveddata.maps.MapDecorationType; +import net.minecraft.world.level.storage.loot.LootTable; +import net.minecraft.world.level.storage.loot.entries.LootPoolEntryType; +import net.minecraft.world.level.storage.loot.functions.LootItemFunction; +import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType; +import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; +import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType; +import net.minecraft.world.level.storage.loot.providers.nbt.LootNbtProviderType; +import net.minecraft.world.level.storage.loot.providers.number.LootNumberProviderType; +import net.minecraft.world.level.storage.loot.providers.score.LootScoreProviderType; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; + +public final class KeyResolvers { + private static final BiMap> CUSTOM_RESOLVERS = HashBiMap.create(); + static { + // TODO: Add data pack registry resolvers + for (Registry registry : BuiltInRegistries.REGISTRY) { + CUSTOM_RESOLVERS.put(registry.key().location(), new KeyResolver.RegistryWrapper<>(registry)); + } + } + + public static final KeyResolver ACTIVITY = getResolver(Registries.ACTIVITY.location()); + public static final KeyResolver ATTRIBUTE = getResolver(Registries.ATTRIBUTE.location()); +// public static final KeyResolver BANNER_PATTERN = getResolver(Registries.BANNER_PATTERN.location()); + public static final KeyResolver> BIOME_SOURCE = getResolver(Registries.BIOME_SOURCE.location()); + public static final KeyResolver BLOCK = getResolver(Registries.BLOCK.location()); + public static final KeyResolver> BLOCK_TYPE = getResolver(Registries.BLOCK_TYPE.location()); + public static final KeyResolver> BLOCK_ENTITY_TYPE = getResolver(Registries.BLOCK_ENTITY_TYPE.location()); + public static final KeyResolver> BLOCK_PREDICATE_TYPE = getResolver(Registries.BLOCK_PREDICATE_TYPE.location()); + public static final KeyResolver> BLOCK_STATE_PROVIDER_TYPE = getResolver(Registries.BLOCK_STATE_PROVIDER_TYPE.location()); + public static final KeyResolver> CARVER = getResolver(Registries.CARVER.location()); + public static final KeyResolver CAT_VARIANT = getResolver(Registries.CAT_VARIANT.location()); +// public static final KeyResolver WOLF_VARIANT = getResolver(Registries.WOLF_VARIANT.location()); + public static final KeyResolver> CHUNK_GENERATOR = getResolver(Registries.CHUNK_GENERATOR.location()); + public static final KeyResolver CHUNK_STATUS = getResolver(Registries.CHUNK_STATUS.location()); + public static final KeyResolver> COMMAND_ARGUMENT_TYPE = getResolver(Registries.COMMAND_ARGUMENT_TYPE.location()); + public static final KeyResolver CREATIVE_MODE_TAB = getResolver(Registries.CREATIVE_MODE_TAB.location()); + public static final KeyResolver CUSTOM_STAT = getResolver(Registries.CUSTOM_STAT.location()); +// public static final KeyResolver DAMAGE_TYPE = getResolver(Registries.DAMAGE_TYPE.location()); + public static final KeyResolver> DENSITY_FUNCTION_TYPE = getResolver(Registries.DENSITY_FUNCTION_TYPE.location()); + public static final KeyResolver ENCHANTMENT = getResolver(Registries.ENCHANTMENT.location()); + public static final KeyResolver> ENTITY_TYPE = getResolver(Registries.ENTITY_TYPE.location()); + public static final KeyResolver> FEATURE = getResolver(Registries.FEATURE.location()); + public static final KeyResolver> FEATURE_SIZE_TYPE = getResolver(Registries.FEATURE_SIZE_TYPE.location()); + public static final KeyResolver> FLOAT_PROVIDER_TYPE = getResolver(Registries.FLOAT_PROVIDER_TYPE.location()); + public static final KeyResolver FLUID = getResolver(Registries.FLUID.location()); + public static final KeyResolver> FOLIAGE_PLACER_TYPE = getResolver(Registries.FOLIAGE_PLACER_TYPE.location()); + public static final KeyResolver FROG_VARIANT = getResolver(Registries.FROG_VARIANT.location()); + public static final KeyResolver GAME_EVENT = getResolver(Registries.GAME_EVENT.location()); + public static final KeyResolver> HEIGHT_PROVIDER_TYPE = getResolver(Registries.HEIGHT_PROVIDER_TYPE.location()); + public static final KeyResolver INSTRUMENT = getResolver(Registries.INSTRUMENT.location()); + public static final KeyResolver> INT_PROVIDER_TYPE = getResolver(Registries.INT_PROVIDER_TYPE.location()); + public static final KeyResolver ITEM = getResolver(Registries.ITEM.location()); + public static final KeyResolver LOOT_CONDITION_TYPE = getResolver(Registries.LOOT_CONDITION_TYPE.location()); + public static final KeyResolver> LOOT_FUNCTION_TYPE = getResolver(Registries.LOOT_FUNCTION_TYPE.location()); + public static final KeyResolver LOOT_NBT_PROVIDER_TYPE = getResolver(Registries.LOOT_NBT_PROVIDER_TYPE.location()); + public static final KeyResolver LOOT_NUMBER_PROVIDER_TYPE = getResolver(Registries.LOOT_NUMBER_PROVIDER_TYPE.location()); + public static final KeyResolver LOOT_POOL_ENTRY_TYPE = getResolver(Registries.LOOT_POOL_ENTRY_TYPE.location()); + public static final KeyResolver LOOT_SCORE_PROVIDER_TYPE = getResolver(Registries.LOOT_SCORE_PROVIDER_TYPE.location()); + public static final KeyResolver> MATERIAL_CONDITION = getResolver(Registries.MATERIAL_CONDITION.location()); + public static final KeyResolver> MATERIAL_RULE = getResolver(Registries.MATERIAL_RULE.location()); + public static final KeyResolver> MEMORY_MODULE_TYPE = getResolver(Registries.MEMORY_MODULE_TYPE.location()); + public static final KeyResolver> MENU = getResolver(Registries.MENU.location()); + public static final KeyResolver MOB_EFFECT = getResolver(Registries.MOB_EFFECT.location()); + public static final KeyResolver PAINTING_VARIANT = getResolver(Registries.PAINTING_VARIANT.location()); + public static final KeyResolver> PARTICLE_TYPE = getResolver(Registries.PARTICLE_TYPE.location()); + public static final KeyResolver> PLACEMENT_MODIFIER_TYPE = getResolver(Registries.PLACEMENT_MODIFIER_TYPE.location()); + public static final KeyResolver POINT_OF_INTEREST_TYPE = getResolver(Registries.POINT_OF_INTEREST_TYPE.location()); + public static final KeyResolver> POSITION_SOURCE_TYPE = getResolver(Registries.POSITION_SOURCE_TYPE.location()); + public static final KeyResolver> POS_RULE_TEST = getResolver(Registries.POS_RULE_TEST.location()); + public static final KeyResolver POTION = getResolver(Registries.POTION.location()); + public static final KeyResolver> RECIPE_SERIALIZER = getResolver(Registries.RECIPE_SERIALIZER.location()); + public static final KeyResolver> RECIPE_TYPE = getResolver(Registries.RECIPE_TYPE.location()); + public static final KeyResolver> ROOT_PLACER_TYPE = getResolver(Registries.ROOT_PLACER_TYPE.location()); + public static final KeyResolver> RULE_TEST = getResolver(Registries.RULE_TEST.location()); + public static final KeyResolver> RULE_BLOCK_ENTITY_MODIFIER = getResolver(Registries.RULE_BLOCK_ENTITY_MODIFIER.location()); + public static final KeyResolver SCHEDULE = getResolver(Registries.SCHEDULE.location()); + public static final KeyResolver> SENSOR_TYPE = getResolver(Registries.SENSOR_TYPE.location()); + public static final KeyResolver SOUND_EVENT = getResolver(Registries.SOUND_EVENT.location()); + public static final KeyResolver> STAT_TYPE = getResolver(Registries.STAT_TYPE.location()); + public static final KeyResolver STRUCTURE_PIECE = getResolver(Registries.STRUCTURE_PIECE.location()); + public static final KeyResolver> STRUCTURE_PLACEMENT = getResolver(Registries.STRUCTURE_PLACEMENT.location()); + public static final KeyResolver> STRUCTURE_POOL_ELEMENT = getResolver(Registries.STRUCTURE_POOL_ELEMENT.location()); + public static final KeyResolver> POOL_ALIAS_BINDING = getResolver(Registries.POOL_ALIAS_BINDING.location()); + public static final KeyResolver> STRUCTURE_PROCESSOR = getResolver(Registries.STRUCTURE_PROCESSOR.location()); + public static final KeyResolver> STRUCTURE_TYPE = getResolver(Registries.STRUCTURE_TYPE.location()); + public static final KeyResolver> TREE_DECORATOR_TYPE = getResolver(Registries.TREE_DECORATOR_TYPE.location()); + public static final KeyResolver> TRUNK_PLACER_TYPE = getResolver(Registries.TRUNK_PLACER_TYPE.location()); + public static final KeyResolver VILLAGER_PROFESSION = getResolver(Registries.VILLAGER_PROFESSION.location()); + public static final KeyResolver VILLAGER_TYPE = getResolver(Registries.VILLAGER_TYPE.location()); + public static final KeyResolver DECORATED_POT_PATTERNS = getResolver(Registries.DECORATED_POT_PATTERNS.location()); + public static final KeyResolver> NUMBER_FORMAT_TYPE = getResolver(Registries.NUMBER_FORMAT_TYPE.location()); + public static final KeyResolver ARMOR_MATERIAL = getResolver(Registries.ARMOR_MATERIAL.location()); + public static final KeyResolver> DATA_COMPONENT_TYPE = getResolver(Registries.DATA_COMPONENT_TYPE.location()); + public static final KeyResolver> ENTITY_SUB_PREDICATE_TYPE = getResolver(Registries.ENTITY_SUB_PREDICATE_TYPE.location()); + public static final KeyResolver> ITEM_SUB_PREDICATE_TYPE = getResolver(Registries.ITEM_SUB_PREDICATE_TYPE.location()); + public static final KeyResolver MAP_DECORATION_TYPE = getResolver(Registries.MAP_DECORATION_TYPE.location()); +// public static final KeyResolver BIOME = getResolver(Registries.BIOME.location()); +// public static final KeyResolver CHAT_TYPE = getResolver(Registries.CHAT_TYPE.location()); +// public static final KeyResolver> CONFIGURED_CARVER = getResolver(Registries.CONFIGURED_CARVER.location()); +// public static final KeyResolver> CONFIGURED_FEATURE = getResolver(Registries.CONFIGURED_FEATURE.location()); +// public static final KeyResolver DENSITY_FUNCTION = getResolver(Registries.DENSITY_FUNCTION.location()); +// public static final KeyResolver DIMENSION_TYPE = getResolver(Registries.DIMENSION_TYPE.location()); +// public static final KeyResolver FLAT_LEVEL_GENERATOR_PRESET = getResolver(Registries.FLAT_LEVEL_GENERATOR_PRESET.location()); +// public static final KeyResolver NOISE_SETTINGS = getResolver(Registries.NOISE_SETTINGS.location()); +// public static final KeyResolver NOISE = getResolver(Registries.NOISE.location()); +// public static final KeyResolver PLACED_FEATURE = getResolver(Registries.PLACED_FEATURE.location()); +// public static final KeyResolver STRUCTURE = getResolver(Registries.STRUCTURE.location()); +// public static final KeyResolver PROCESSOR_LIST = getResolver(Registries.PROCESSOR_LIST.location()); +// public static final KeyResolver STRUCTURE_SET = getResolver(Registries.STRUCTURE_SET.location()); +// public static final KeyResolver TEMPLATE_POOL = getResolver(Registries.TEMPLATE_POOL.location()); + public static final KeyResolver> TRIGGER_TYPE = getResolver(Registries.TRIGGER_TYPE.location()); +// public static final KeyResolver TRIM_MATERIAL = getResolver(Registries.TRIM_MATERIAL.location()); +// public static final KeyResolver TRIM_PATTERN = getResolver(Registries.TRIM_PATTERN.location()); +// public static final KeyResolver WORLD_PRESET = getResolver(Registries.WORLD_PRESET.location()); +// public static final KeyResolver MULTI_NOISE_BIOME_SOURCE_PARAMETER_LIST = getResolver(Registries.MULTI_NOISE_BIOME_SOURCE_PARAMETER_LIST.location()); + public static final KeyResolver DIMENSION = getResolver(Registries.DIMENSION.location()); + public static final KeyResolver LEVEL_STEM = getResolver(Registries.LEVEL_STEM.location()); + public static final KeyResolver LOOT_TABLE = getResolver(Registries.LOOT_TABLE.location()); + public static final KeyResolver ITEM_MODIFIER = getResolver(Registries.ITEM_MODIFIER.location()); + public static final KeyResolver PREDICATE = getResolver(Registries.PREDICATE.location()); + + @ApiStatus.Internal + public static void register(ResourceLocation key, KeyResolver resolver) { + if (CUSTOM_RESOLVERS.putIfAbsent(key, resolver) != null) { + throw new IllegalArgumentException("Mapping already registered for %s".formatted(key)); + } + } + + @Nullable + public static KeyResolver getResolver(ResourceLocation key) { + return (KeyResolver) CUSTOM_RESOLVERS.get(key); + } + + public static ResourceLocation getId(KeyResolver key) { + return CUSTOM_RESOLVERS.inverse().get(key); + } +} diff --git a/common/src/main/java/dev/dhyces/trimmed/impl/client/maps/MapKeyResolvers.java b/common/src/main/java/dev/dhyces/trimmed/impl/client/maps/MapKeyResolvers.java deleted file mode 100644 index 2f12f355..00000000 --- a/common/src/main/java/dev/dhyces/trimmed/impl/client/maps/MapKeyResolvers.java +++ /dev/null @@ -1,234 +0,0 @@ -package dev.dhyces.trimmed.impl.client.maps; - -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; -import com.mojang.serialization.MapCodec; -import dev.dhyces.trimmed.api.maps.MapKeyResolver; -import net.minecraft.advancements.CriterionTrigger; -import net.minecraft.advancements.critereon.EntitySubPredicate; -import net.minecraft.advancements.critereon.ItemSubPredicate; -import net.minecraft.commands.synchronization.ArgumentTypeInfo; -import net.minecraft.core.Registry; -import net.minecraft.core.component.DataComponentType; -import net.minecraft.core.particles.ParticleType; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.core.registries.Registries; -import net.minecraft.network.chat.ChatType; -import net.minecraft.network.chat.numbers.NumberFormatType; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.stats.StatType; -import net.minecraft.util.valueproviders.FloatProviderType; -import net.minecraft.util.valueproviders.IntProviderType; -import net.minecraft.world.damagesource.DamageType; -import net.minecraft.world.effect.MobEffect; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.ai.attributes.Attribute; -import net.minecraft.world.entity.ai.memory.MemoryModuleType; -import net.minecraft.world.entity.ai.sensing.SensorType; -import net.minecraft.world.entity.ai.village.poi.PoiType; -import net.minecraft.world.entity.animal.CatVariant; -import net.minecraft.world.entity.animal.FrogVariant; -import net.minecraft.world.entity.animal.WolfVariant; -import net.minecraft.world.entity.decoration.PaintingVariant; -import net.minecraft.world.entity.npc.VillagerProfession; -import net.minecraft.world.entity.npc.VillagerType; -import net.minecraft.world.entity.schedule.Activity; -import net.minecraft.world.entity.schedule.Schedule; -import net.minecraft.world.inventory.MenuType; -import net.minecraft.world.item.ArmorMaterial; -import net.minecraft.world.item.CreativeModeTab; -import net.minecraft.world.item.Instrument; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.alchemy.Potion; -import net.minecraft.world.item.armortrim.TrimMaterial; -import net.minecraft.world.item.armortrim.TrimPattern; -import net.minecraft.world.item.crafting.RecipeSerializer; -import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.world.item.enchantment.Enchantment; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.BiomeSource; -import net.minecraft.world.level.biome.MultiNoiseBiomeSourceParameterList; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.BannerPattern; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.chunk.status.ChunkStatus; -import net.minecraft.world.level.dimension.DimensionType; -import net.minecraft.world.level.dimension.LevelStem; -import net.minecraft.world.level.gameevent.GameEvent; -import net.minecraft.world.level.gameevent.PositionSourceType; -import net.minecraft.world.level.levelgen.DensityFunction; -import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; -import net.minecraft.world.level.levelgen.SurfaceRules; -import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicateType; -import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; -import net.minecraft.world.level.levelgen.carver.WorldCarver; -import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; -import net.minecraft.world.level.levelgen.feature.Feature; -import net.minecraft.world.level.levelgen.feature.featuresize.FeatureSizeType; -import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacerType; -import net.minecraft.world.level.levelgen.feature.rootplacers.RootPlacerType; -import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProviderType; -import net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecoratorType; -import net.minecraft.world.level.levelgen.feature.trunkplacers.TrunkPlacerType; -import net.minecraft.world.level.levelgen.flat.FlatLevelGeneratorPreset; -import net.minecraft.world.level.levelgen.heightproviders.HeightProviderType; -import net.minecraft.world.level.levelgen.placement.PlacedFeature; -import net.minecraft.world.level.levelgen.placement.PlacementModifierType; -import net.minecraft.world.level.levelgen.presets.WorldPreset; -import net.minecraft.world.level.levelgen.structure.Structure; -import net.minecraft.world.level.levelgen.structure.StructureSet; -import net.minecraft.world.level.levelgen.structure.StructureType; -import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType; -import net.minecraft.world.level.levelgen.structure.placement.StructurePlacementType; -import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElementType; -import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool; -import net.minecraft.world.level.levelgen.structure.pools.alias.PoolAliasBinding; -import net.minecraft.world.level.levelgen.structure.templatesystem.PosRuleTestType; -import net.minecraft.world.level.levelgen.structure.templatesystem.RuleTestType; -import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorList; -import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorType; -import net.minecraft.world.level.levelgen.structure.templatesystem.rule.blockentity.RuleBlockEntityModifierType; -import net.minecraft.world.level.levelgen.synth.NormalNoise; -import net.minecraft.world.level.material.Fluid; -import net.minecraft.world.level.saveddata.maps.MapDecorationType; -import net.minecraft.world.level.storage.loot.LootTable; -import net.minecraft.world.level.storage.loot.entries.LootPoolEntryType; -import net.minecraft.world.level.storage.loot.functions.LootItemFunction; -import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType; -import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; -import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType; -import net.minecraft.world.level.storage.loot.providers.nbt.LootNbtProviderType; -import net.minecraft.world.level.storage.loot.providers.number.LootNumberProviderType; -import net.minecraft.world.level.storage.loot.providers.score.LootScoreProviderType; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.Nullable; - -public final class MapKeyResolvers { - private static final BiMap> CUSTOM_RESOLVERS = HashBiMap.create(); - static { - // TODO: Add data pack registry resolvers - for (Registry registry : BuiltInRegistries.REGISTRY) { - CUSTOM_RESOLVERS.put(registry.key().location(), new MapKeyResolver.RegistryWrapper<>(registry)); - } - } - - public static final MapKeyResolver ACTIVITY = getResolver(Registries.ACTIVITY.location()); - public static final MapKeyResolver ATTRIBUTE = getResolver(Registries.ATTRIBUTE.location()); -// public static final MapKeyResolver BANNER_PATTERN = getResolver(Registries.BANNER_PATTERN.location()); - public static final MapKeyResolver> BIOME_SOURCE = getResolver(Registries.BIOME_SOURCE.location()); - public static final MapKeyResolver BLOCK = getResolver(Registries.BLOCK.location()); - public static final MapKeyResolver> BLOCK_TYPE = getResolver(Registries.BLOCK_TYPE.location()); - public static final MapKeyResolver> BLOCK_ENTITY_TYPE = getResolver(Registries.BLOCK_ENTITY_TYPE.location()); - public static final MapKeyResolver> BLOCK_PREDICATE_TYPE = getResolver(Registries.BLOCK_PREDICATE_TYPE.location()); - public static final MapKeyResolver> BLOCK_STATE_PROVIDER_TYPE = getResolver(Registries.BLOCK_STATE_PROVIDER_TYPE.location()); - public static final MapKeyResolver> CARVER = getResolver(Registries.CARVER.location()); - public static final MapKeyResolver CAT_VARIANT = getResolver(Registries.CAT_VARIANT.location()); -// public static final MapKeyResolver WOLF_VARIANT = getResolver(Registries.WOLF_VARIANT.location()); - public static final MapKeyResolver> CHUNK_GENERATOR = getResolver(Registries.CHUNK_GENERATOR.location()); - public static final MapKeyResolver CHUNK_STATUS = getResolver(Registries.CHUNK_STATUS.location()); - public static final MapKeyResolver> COMMAND_ARGUMENT_TYPE = getResolver(Registries.COMMAND_ARGUMENT_TYPE.location()); - public static final MapKeyResolver CREATIVE_MODE_TAB = getResolver(Registries.CREATIVE_MODE_TAB.location()); - public static final MapKeyResolver CUSTOM_STAT = getResolver(Registries.CUSTOM_STAT.location()); -// public static final MapKeyResolver DAMAGE_TYPE = getResolver(Registries.DAMAGE_TYPE.location()); - public static final MapKeyResolver> DENSITY_FUNCTION_TYPE = getResolver(Registries.DENSITY_FUNCTION_TYPE.location()); - public static final MapKeyResolver ENCHANTMENT = getResolver(Registries.ENCHANTMENT.location()); - public static final MapKeyResolver> ENTITY_TYPE = getResolver(Registries.ENTITY_TYPE.location()); - public static final MapKeyResolver> FEATURE = getResolver(Registries.FEATURE.location()); - public static final MapKeyResolver> FEATURE_SIZE_TYPE = getResolver(Registries.FEATURE_SIZE_TYPE.location()); - public static final MapKeyResolver> FLOAT_PROVIDER_TYPE = getResolver(Registries.FLOAT_PROVIDER_TYPE.location()); - public static final MapKeyResolver FLUID = getResolver(Registries.FLUID.location()); - public static final MapKeyResolver> FOLIAGE_PLACER_TYPE = getResolver(Registries.FOLIAGE_PLACER_TYPE.location()); - public static final MapKeyResolver FROG_VARIANT = getResolver(Registries.FROG_VARIANT.location()); - public static final MapKeyResolver GAME_EVENT = getResolver(Registries.GAME_EVENT.location()); - public static final MapKeyResolver> HEIGHT_PROVIDER_TYPE = getResolver(Registries.HEIGHT_PROVIDER_TYPE.location()); - public static final MapKeyResolver INSTRUMENT = getResolver(Registries.INSTRUMENT.location()); - public static final MapKeyResolver> INT_PROVIDER_TYPE = getResolver(Registries.INT_PROVIDER_TYPE.location()); - public static final MapKeyResolver ITEM = getResolver(Registries.ITEM.location()); - public static final MapKeyResolver LOOT_CONDITION_TYPE = getResolver(Registries.LOOT_CONDITION_TYPE.location()); - public static final MapKeyResolver> LOOT_FUNCTION_TYPE = getResolver(Registries.LOOT_FUNCTION_TYPE.location()); - public static final MapKeyResolver LOOT_NBT_PROVIDER_TYPE = getResolver(Registries.LOOT_NBT_PROVIDER_TYPE.location()); - public static final MapKeyResolver LOOT_NUMBER_PROVIDER_TYPE = getResolver(Registries.LOOT_NUMBER_PROVIDER_TYPE.location()); - public static final MapKeyResolver LOOT_POOL_ENTRY_TYPE = getResolver(Registries.LOOT_POOL_ENTRY_TYPE.location()); - public static final MapKeyResolver LOOT_SCORE_PROVIDER_TYPE = getResolver(Registries.LOOT_SCORE_PROVIDER_TYPE.location()); - public static final MapKeyResolver> MATERIAL_CONDITION = getResolver(Registries.MATERIAL_CONDITION.location()); - public static final MapKeyResolver> MATERIAL_RULE = getResolver(Registries.MATERIAL_RULE.location()); - public static final MapKeyResolver> MEMORY_MODULE_TYPE = getResolver(Registries.MEMORY_MODULE_TYPE.location()); - public static final MapKeyResolver> MENU = getResolver(Registries.MENU.location()); - public static final MapKeyResolver MOB_EFFECT = getResolver(Registries.MOB_EFFECT.location()); - public static final MapKeyResolver PAINTING_VARIANT = getResolver(Registries.PAINTING_VARIANT.location()); - public static final MapKeyResolver> PARTICLE_TYPE = getResolver(Registries.PARTICLE_TYPE.location()); - public static final MapKeyResolver> PLACEMENT_MODIFIER_TYPE = getResolver(Registries.PLACEMENT_MODIFIER_TYPE.location()); - public static final MapKeyResolver POINT_OF_INTEREST_TYPE = getResolver(Registries.POINT_OF_INTEREST_TYPE.location()); - public static final MapKeyResolver> POSITION_SOURCE_TYPE = getResolver(Registries.POSITION_SOURCE_TYPE.location()); - public static final MapKeyResolver> POS_RULE_TEST = getResolver(Registries.POS_RULE_TEST.location()); - public static final MapKeyResolver POTION = getResolver(Registries.POTION.location()); - public static final MapKeyResolver> RECIPE_SERIALIZER = getResolver(Registries.RECIPE_SERIALIZER.location()); - public static final MapKeyResolver> RECIPE_TYPE = getResolver(Registries.RECIPE_TYPE.location()); - public static final MapKeyResolver> ROOT_PLACER_TYPE = getResolver(Registries.ROOT_PLACER_TYPE.location()); - public static final MapKeyResolver> RULE_TEST = getResolver(Registries.RULE_TEST.location()); - public static final MapKeyResolver> RULE_BLOCK_ENTITY_MODIFIER = getResolver(Registries.RULE_BLOCK_ENTITY_MODIFIER.location()); - public static final MapKeyResolver SCHEDULE = getResolver(Registries.SCHEDULE.location()); - public static final MapKeyResolver> SENSOR_TYPE = getResolver(Registries.SENSOR_TYPE.location()); - public static final MapKeyResolver SOUND_EVENT = getResolver(Registries.SOUND_EVENT.location()); - public static final MapKeyResolver> STAT_TYPE = getResolver(Registries.STAT_TYPE.location()); - public static final MapKeyResolver STRUCTURE_PIECE = getResolver(Registries.STRUCTURE_PIECE.location()); - public static final MapKeyResolver> STRUCTURE_PLACEMENT = getResolver(Registries.STRUCTURE_PLACEMENT.location()); - public static final MapKeyResolver> STRUCTURE_POOL_ELEMENT = getResolver(Registries.STRUCTURE_POOL_ELEMENT.location()); - public static final MapKeyResolver> POOL_ALIAS_BINDING = getResolver(Registries.POOL_ALIAS_BINDING.location()); - public static final MapKeyResolver> STRUCTURE_PROCESSOR = getResolver(Registries.STRUCTURE_PROCESSOR.location()); - public static final MapKeyResolver> STRUCTURE_TYPE = getResolver(Registries.STRUCTURE_TYPE.location()); - public static final MapKeyResolver> TREE_DECORATOR_TYPE = getResolver(Registries.TREE_DECORATOR_TYPE.location()); - public static final MapKeyResolver> TRUNK_PLACER_TYPE = getResolver(Registries.TRUNK_PLACER_TYPE.location()); - public static final MapKeyResolver VILLAGER_PROFESSION = getResolver(Registries.VILLAGER_PROFESSION.location()); - public static final MapKeyResolver VILLAGER_TYPE = getResolver(Registries.VILLAGER_TYPE.location()); - public static final MapKeyResolver DECORATED_POT_PATTERNS = getResolver(Registries.DECORATED_POT_PATTERNS.location()); - public static final MapKeyResolver> NUMBER_FORMAT_TYPE = getResolver(Registries.NUMBER_FORMAT_TYPE.location()); - public static final MapKeyResolver ARMOR_MATERIAL = getResolver(Registries.ARMOR_MATERIAL.location()); - public static final MapKeyResolver> DATA_COMPONENT_TYPE = getResolver(Registries.DATA_COMPONENT_TYPE.location()); - public static final MapKeyResolver> ENTITY_SUB_PREDICATE_TYPE = getResolver(Registries.ENTITY_SUB_PREDICATE_TYPE.location()); - public static final MapKeyResolver> ITEM_SUB_PREDICATE_TYPE = getResolver(Registries.ITEM_SUB_PREDICATE_TYPE.location()); - public static final MapKeyResolver MAP_DECORATION_TYPE = getResolver(Registries.MAP_DECORATION_TYPE.location()); -// public static final MapKeyResolver BIOME = getResolver(Registries.BIOME.location()); -// public static final MapKeyResolver CHAT_TYPE = getResolver(Registries.CHAT_TYPE.location()); -// public static final MapKeyResolver> CONFIGURED_CARVER = getResolver(Registries.CONFIGURED_CARVER.location()); -// public static final MapKeyResolver> CONFIGURED_FEATURE = getResolver(Registries.CONFIGURED_FEATURE.location()); -// public static final MapKeyResolver DENSITY_FUNCTION = getResolver(Registries.DENSITY_FUNCTION.location()); -// public static final MapKeyResolver DIMENSION_TYPE = getResolver(Registries.DIMENSION_TYPE.location()); -// public static final MapKeyResolver FLAT_LEVEL_GENERATOR_PRESET = getResolver(Registries.FLAT_LEVEL_GENERATOR_PRESET.location()); -// public static final MapKeyResolver NOISE_SETTINGS = getResolver(Registries.NOISE_SETTINGS.location()); -// public static final MapKeyResolver NOISE = getResolver(Registries.NOISE.location()); -// public static final MapKeyResolver PLACED_FEATURE = getResolver(Registries.PLACED_FEATURE.location()); -// public static final MapKeyResolver STRUCTURE = getResolver(Registries.STRUCTURE.location()); -// public static final MapKeyResolver PROCESSOR_LIST = getResolver(Registries.PROCESSOR_LIST.location()); -// public static final MapKeyResolver STRUCTURE_SET = getResolver(Registries.STRUCTURE_SET.location()); -// public static final MapKeyResolver TEMPLATE_POOL = getResolver(Registries.TEMPLATE_POOL.location()); - public static final MapKeyResolver> TRIGGER_TYPE = getResolver(Registries.TRIGGER_TYPE.location()); -// public static final MapKeyResolver TRIM_MATERIAL = getResolver(Registries.TRIM_MATERIAL.location()); -// public static final MapKeyResolver TRIM_PATTERN = getResolver(Registries.TRIM_PATTERN.location()); -// public static final MapKeyResolver WORLD_PRESET = getResolver(Registries.WORLD_PRESET.location()); -// public static final MapKeyResolver MULTI_NOISE_BIOME_SOURCE_PARAMETER_LIST = getResolver(Registries.MULTI_NOISE_BIOME_SOURCE_PARAMETER_LIST.location()); - public static final MapKeyResolver DIMENSION = getResolver(Registries.DIMENSION.location()); - public static final MapKeyResolver LEVEL_STEM = getResolver(Registries.LEVEL_STEM.location()); - public static final MapKeyResolver LOOT_TABLE = getResolver(Registries.LOOT_TABLE.location()); - public static final MapKeyResolver ITEM_MODIFIER = getResolver(Registries.ITEM_MODIFIER.location()); - public static final MapKeyResolver PREDICATE = getResolver(Registries.PREDICATE.location()); - - @ApiStatus.Internal - public static void register(ResourceLocation key, MapKeyResolver resolver) { - if (CUSTOM_RESOLVERS.putIfAbsent(key, resolver) != null) { - throw new IllegalArgumentException("Mapping already registered for %s".formatted(key)); - } - } - - @Nullable - public static MapKeyResolver getResolver(ResourceLocation key) { - return (MapKeyResolver) CUSTOM_RESOLVERS.get(key); - } - - public static ResourceLocation getId(MapKeyResolver key) { - return CUSTOM_RESOLVERS.inverse().get(key); - } -} diff --git a/common/src/main/java/dev/dhyces/trimmed/impl/client/maps/manager/ClientMapManager.java b/common/src/main/java/dev/dhyces/trimmed/impl/client/maps/manager/ClientMapManager.java index 3b3daffd..4c1e3481 100644 --- a/common/src/main/java/dev/dhyces/trimmed/impl/client/maps/manager/ClientMapManager.java +++ b/common/src/main/java/dev/dhyces/trimmed/impl/client/maps/manager/ClientMapManager.java @@ -4,7 +4,7 @@ import dev.dhyces.trimmed.api.maps.MapHolder; import dev.dhyces.trimmed.api.util.Utils; import dev.dhyces.trimmed.api.maps.MapKey; -import dev.dhyces.trimmed.impl.client.maps.MapKeyResolvers; +import dev.dhyces.trimmed.impl.client.maps.KeyResolvers; import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; import net.minecraft.resources.FileToIdConverter; import net.minecraft.resources.ResourceLocation; @@ -28,8 +28,8 @@ public static void registerBaseKey(MapKey key) { if (key.isSubKey()) { throw new IllegalArgumentException("Illegal id {%s}. Id cannot contain sub-paths \"/\".".formatted(key)); } - if (MapKeyResolvers.getId(key.getType().getKeyResolver()) == null) { - throw new IllegalArgumentException("MapKeyResolver for %s is not registered".formatted(key)); + if (KeyResolvers.getId(key.getType().getKeyResolver()) == null) { + throw new IllegalArgumentException("KeyResolver for %s is not registered".formatted(key)); } if (REGISTRY.containsKey(key)) { throw new IllegalArgumentException("Base MapKey already registered for " + key); @@ -60,7 +60,7 @@ private CompletableFuture load(ResourceManager resourceManager) { REGISTRY.values().forEach(MapHandler::clear); for (Map.Entry, MapHandler> entry : REGISTRY.entrySet()) { - ResourceLocation resolverPath = entry.getKey().getMapId().withPrefix("trimmed/maps/" + Utils.namespacedPath(MapKeyResolvers.getId(entry.getKey().getType().getKeyResolver()), '/') + "/"); + ResourceLocation resolverPath = entry.getKey().getMapId().withPrefix("trimmed/maps/" + Utils.namespacedPath(KeyResolvers.getId(entry.getKey().getType().getKeyResolver()), '/') + "/"); FileToIdConverter converter = FileToIdConverter.json(resolverPath.getPath()); try {