Skip to content

Commit

Permalink
Start trying to ship api separate from main
Browse files Browse the repository at this point in the history
  • Loading branch information
dhyces committed Nov 12, 2024
1 parent 3fede90 commit 647b889
Show file tree
Hide file tree
Showing 97 changed files with 272 additions and 182 deletions.
6 changes: 5 additions & 1 deletion buildSrc/src/main/groovy/consumer.conventions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ configurations {
}

dependencies {
compileOnly project(":common")
compileOnly(project(":common")) {
capabilities {
requireCapability("dev.dhyces.trimmed:common:api")
}
}
commonJava project(path: ":common", configuration: "commonJava")
commonResources project(path: ":common", configuration: "commonResources")
}
Expand Down
26 changes: 18 additions & 8 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ modsDotGroovy {
}
}

sourceSets {
api {
compileClasspath += main.compileClasspath
}
main {
compileClasspath += api.compileClasspath + api.output
runtimeClasspath += api.runtimeClasspath + api.output
resources.srcDir 'src/generated/resources'
}
}

configurations {
commonJava {
canBeResolved = false
Expand All @@ -51,6 +62,12 @@ neoForge {
}
}

java {
registerFeature("api") {
usingSourceSet(sourceSets.api)
}
}

dependencies {
compileOnly libs.mixin
annotationProcessor libs.mixinextras.common
Expand All @@ -59,15 +76,8 @@ dependencies {

artifacts {
commonJava sourceSets.main.java.sourceDirectories.singleFile
commonJava sourceSets.api.java.sourceDirectories.singleFile
sourceSets.main.resources.sourceDirectories.forEach {
commonResources it
}
}

sourceSets.main.resources.srcDir 'src/generated/resources'

idea {
module {
inheritOutputDirs = false
}
}
14 changes: 14 additions & 0 deletions common/src/api/java/dev/dhyces/trimmed/api/TrimmedReference.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.dhyces.trimmed.api;

import net.minecraft.resources.ResourceLocation;

public final class TrimmedReference {
private TrimmedReference() {}

public static final String MODID = "trimmed";
public static ResourceLocation id(String id) {
return ResourceLocation.fromNamespaceAndPath(MODID, id);
}

public static final String OVERRIDES_DIRECTORY = "trimmed/item_model_overrides";
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package dev.dhyces.trimmed.api.client;

import dev.dhyces.trimmed.api.KeyResolver;
import dev.dhyces.trimmed.impl.client.TrimmedClientApiImpl;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;

public interface TrimmedClientApi {
static TrimmedClientApi getInstance() {
return TrimmedClientApiImpl.INSTANCE;
throw new AssertionError("Implemented with Mixin");
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.dhyces.trimmed.api.client;

import com.mojang.serialization.MapCodec;
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.KeyResolver;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -21,7 +21,7 @@ interface TrimmedClientRegistration {
* @param id Id for this override type, ie "trimmed:nbt"
* @param providerType Your item override provider type, ie () -> MyItemOverrideProvider.CODEC
*/
<T extends ItemOverrideProvider> ItemOverrideProviderType<T> registerItemOverrideType(ResourceLocation id, ItemOverrideProviderType<T> providerType);
<T extends ItemOverrideProvider> MapCodec<T> registerItemOverrideType(ResourceLocation id, MapCodec<T> providerType);

/**
* If this already
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import dev.dhyces.trimmed.api.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;
Expand All @@ -15,7 +14,7 @@

public interface TrimmedClientMapApi {
static TrimmedClientMapApi getInstance() {
return TrimmedClientMapApiImpl.INSTANCE;
throw new AssertionError("Implemented with Mixin");
}

<K, V> MapHolder<K, V> getSimpleMap(MapKey<K, V> key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import com.mojang.serialization.Codec;
import dev.dhyces.trimmed.api.client.tag.TagHolder;
import dev.dhyces.trimmed.api.KeyResolver;
import dev.dhyces.trimmed.impl.client.TrimmedClientTagApiImpl;
import dev.dhyces.trimmed.api.client.tag.ClientTagKey;

public interface TrimmedClientTagApi {
static TrimmedClientTagApi getInstance() {
return TrimmedClientTagApiImpl.INSTANCE;
throw new AssertionError("Implemented with Mixin");
}

<T> TagHolder<T> getTag(ClientTagKey<T> clientTagKey);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package dev.dhyces.trimmed.api.client.map;

import dev.dhyces.trimmed.Trimmed;
import dev.dhyces.trimmed.api.TrimmedReference;
import dev.dhyces.trimmed.api.maps.MapKey;
import net.minecraft.resources.ResourceLocation;

public class ClientMapKeys {
public static final MapKey<ResourceLocation, String> MATERIAL_SUFFIXES = MapKey.baseKeyOf(ClientMapTypes.TEXTURE_SUFFIX, Trimmed.id("material_suffixes"));
public static final MapKey<ResourceLocation, String> DARKER_MATERIAL_SUFFIXES = MATERIAL_SUFFIXES.makeSubKey(Trimmed.id("darker_material_suffixes"));
public static final MapKey<ResourceLocation, String> MATERIAL_SUFFIXES = MapKey.baseKeyOf(ClientMapTypes.TEXTURE_SUFFIX, TrimmedReference.id("material_suffixes"));
public static final MapKey<ResourceLocation, String> DARKER_MATERIAL_SUFFIXES = MATERIAL_SUFFIXES.makeSubKey(TrimmedReference.id("darker_material_suffixes"));

public static final MapKey<ResourceLocation, ResourceLocation> TRIM_MATERIAL_OVERRIDES = MapKey.baseKeyOf(ClientMapTypes.TEXTURE_MAPPING, Trimmed.id("trim_material_overrides"));
public static final MapKey<ResourceLocation, ResourceLocation> IRON_MATERIAL_OVERRIDES = TRIM_MATERIAL_OVERRIDES.makeSubKey(Trimmed.id("iron"));
public static final MapKey<ResourceLocation, ResourceLocation> GOLD_MATERIAL_OVERRIDES = TRIM_MATERIAL_OVERRIDES.makeSubKey(Trimmed.id("gold"));
public static final MapKey<ResourceLocation, ResourceLocation> DIAMOND_MATERIAL_OVERRIDES = TRIM_MATERIAL_OVERRIDES.makeSubKey(Trimmed.id("diamond"));
public static final MapKey<ResourceLocation, ResourceLocation> NETHERITE_MATERIAL_OVERRIDES = TRIM_MATERIAL_OVERRIDES.makeSubKey(Trimmed.id("netherite"));
public static final MapKey<ResourceLocation, ResourceLocation> TRIM_MATERIAL_OVERRIDES = MapKey.baseKeyOf(ClientMapTypes.TEXTURE_MAPPING, TrimmedReference.id("trim_material_overrides"));
public static final MapKey<ResourceLocation, ResourceLocation> IRON_MATERIAL_OVERRIDES = TRIM_MATERIAL_OVERRIDES.makeSubKey(TrimmedReference.id("iron"));
public static final MapKey<ResourceLocation, ResourceLocation> GOLD_MATERIAL_OVERRIDES = TRIM_MATERIAL_OVERRIDES.makeSubKey(TrimmedReference.id("gold"));
public static final MapKey<ResourceLocation, ResourceLocation> DIAMOND_MATERIAL_OVERRIDES = TRIM_MATERIAL_OVERRIDES.makeSubKey(TrimmedReference.id("diamond"));
public static final MapKey<ResourceLocation, ResourceLocation> NETHERITE_MATERIAL_OVERRIDES = TRIM_MATERIAL_OVERRIDES.makeSubKey(TrimmedReference.id("netherite"));

public static final MapKey<ResourceLocation, ResourceLocation> TRIM_OVERLAYS = MapKey.baseKeyOf(ClientMapTypes.TEXTURE_MAPPING, Trimmed.id("trim_overlays"));
public static final MapKey<ResourceLocation, ResourceLocation> IRON_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey(Trimmed.id("iron"));
public static final MapKey<ResourceLocation, ResourceLocation> GOLD_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey(Trimmed.id("gold"));
public static final MapKey<ResourceLocation, ResourceLocation> DIAMOND_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey(Trimmed.id("diamond"));
public static final MapKey<ResourceLocation, ResourceLocation> NETHERITE_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey(Trimmed.id("netherite"));
public static final MapKey<ResourceLocation, ResourceLocation> LEATHER_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey(Trimmed.id("leather"));
public static final MapKey<ResourceLocation, ResourceLocation> CHAINMAIL_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey(Trimmed.id("chainmail"));
public static final MapKey<ResourceLocation, ResourceLocation> TURTLE_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey(Trimmed.id("turtle"));
public static final MapKey<ResourceLocation, ResourceLocation> TRIM_OVERLAYS = MapKey.baseKeyOf(ClientMapTypes.TEXTURE_MAPPING, TrimmedReference.id("trim_overlays"));
public static final MapKey<ResourceLocation, ResourceLocation> IRON_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey(TrimmedReference.id("iron"));
public static final MapKey<ResourceLocation, ResourceLocation> GOLD_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey(TrimmedReference.id("gold"));
public static final MapKey<ResourceLocation, ResourceLocation> DIAMOND_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey(TrimmedReference.id("diamond"));
public static final MapKey<ResourceLocation, ResourceLocation> NETHERITE_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey(TrimmedReference.id("netherite"));
public static final MapKey<ResourceLocation, ResourceLocation> LEATHER_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey(TrimmedReference.id("leather"));
public static final MapKey<ResourceLocation, ResourceLocation> CHAINMAIL_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey(TrimmedReference.id("chainmail"));
public static final MapKey<ResourceLocation, ResourceLocation> TURTLE_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey(TrimmedReference.id("turtle"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.mojang.serialization.Codec;
import dev.dhyces.trimmed.Trimmed;
import dev.dhyces.trimmed.api.TrimmedReference;
import dev.dhyces.trimmed.api.client.ClientKeyResolvers;
import dev.dhyces.trimmed.api.maps.types.MapType;
import dev.dhyces.trimmed.api.util.CodecUtil;
Expand All @@ -27,6 +27,6 @@ public static <K, V> MapType<K, V> registerType(ResourceLocation id, MapType<K,
return mapType;
}

public static final MapType<ResourceLocation, String> TEXTURE_SUFFIX = registerType(Trimmed.id("texture_suffix"), MapType.simpleBuilder(ClientKeyResolvers.TEXTURE, Codec.STRING).build());
public static final MapType<ResourceLocation, ResourceLocation> TEXTURE_MAPPING = registerType(Trimmed.id("texture_mapping"), MapType.simpleBuilder(ClientKeyResolvers.TEXTURE, ResourceLocation.CODEC).build());
public static final MapType<ResourceLocation, String> TEXTURE_SUFFIX = registerType(TrimmedReference.id("texture_suffix"), MapType.simpleBuilder(ClientKeyResolvers.TEXTURE, Codec.STRING).build());
public static final MapType<ResourceLocation, ResourceLocation> TEXTURE_MAPPING = registerType(TrimmedReference.id("texture_mapping"), MapType.simpleBuilder(ClientKeyResolvers.TEXTURE, ResourceLocation.CODEC).build());
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.dhyces.trimmed.impl.client.models.template;
package dev.dhyces.trimmed.api.client.models.template;

import com.mojang.serialization.Codec;
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
Expand All @@ -11,7 +11,6 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class StringTemplate {
public static final Codec<StringTemplate> CODEC = Codec.STRING.xmap(StringTemplate::of, StringTemplate::asOriginalString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import dev.dhyces.trimmed.api.util.CodecUtil;
import dev.dhyces.trimmed.impl.client.models.override.provider.ItemOverrideProviderRegistry;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.world.entity.LivingEntity;
Expand All @@ -12,13 +11,17 @@

import java.util.Optional;
import java.util.Set;
import java.util.function.Function;

public interface ItemOverrideProvider {
Codec<ItemOverrideProvider> CODEC = ItemOverrideProviderRegistry.CODEC.dispatch(ItemOverrideProvider::getType, ItemOverrideProviderType::getCodec);
static Codec<MapCodec<? extends ItemOverrideProvider>> getRegistryCodec() {
throw new AssertionError("Implemented via Mixin");
}
Codec<ItemOverrideProvider> CODEC = getRegistryCodec().dispatch(ItemOverrideProvider::getCodec, Function.identity());
MapCodec<Set<ItemOverrideProvider>> SET_MAP_CODEC = CodecUtil.setOf(CODEC).fieldOf("values");
Codec<Set<ItemOverrideProvider>> SET_MAP_CODEC_CODEC = SET_MAP_CODEC.codec();

Optional<BakedModel> getModel(ItemStack itemStack, @Nullable ClientLevel world, @Nullable LivingEntity entity, int seed);

ItemOverrideProviderType<?> getType();
MapCodec<? extends ItemOverrideProvider> getCodec();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.dhyces.trimmed.api.client.override.provider;

import dev.dhyces.trimmed.modhelper.services.Services;
import dev.dhyces.trimmed.api.services.ApiServices;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.resources.model.BakedModel;
Expand All @@ -18,7 +18,7 @@ public Optional<BakedModel> getModel(ItemStack itemStack, @Nullable ClientLevel
ModelPair pair = getModelLocation(itemStack, world, entity, seed);
return pair.getTopLevelModelId().map(Minecraft.getInstance().getModelManager()::getModel)
.filter(model -> model != Minecraft.getInstance().getModelManager().getMissingModel())
.or(() -> pair.getResourceId().map(Services.CLIENT_HELPER::getModel));
.or(() -> pair.getResourceId().map(ApiServices.MODEL_HELPER::getModel));
}

public abstract ModelPair getModelLocation(ItemStack itemStack, @Nullable ClientLevel world, @Nullable LivingEntity entity, int seed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.dhyces.trimmed.api.client.override.provider.ItemOverrideProviderType;
import dev.dhyces.trimmed.api.client.override.provider.SimpleItemOverrideProvider;
import dev.dhyces.trimmed.impl.client.models.template.StringTemplate;
import dev.dhyces.trimmed.api.client.models.template.StringTemplate;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.core.component.DataComponents;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.equipment.trim.ArmorTrim;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -63,8 +61,8 @@ public ModelPair getModelLocation(ItemStack itemStack, @Nullable ClientLevel wor
}

@Override
public ItemOverrideProviderType<?> getType() {
return ItemOverrideProviderType.ANY_TRIM;
public MapCodec<AnyTrimItemOverrideProvider> getCodec() {
return CODEC;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.dhyces.trimmed.api.client.override.provider.ItemOverrideProviderType;
import dev.dhyces.trimmed.api.client.override.provider.SimpleItemOverrideProvider;
import dev.dhyces.trimmed.api.util.CodecUtil;
import net.minecraft.client.multiplayer.ClientLevel;
Expand Down Expand Up @@ -56,8 +55,8 @@ public ModelPair getModelLocation(ItemStack itemStack, @Nullable ClientLevel wor
}

@Override
public ItemOverrideProviderType<?> getType() {
return ItemOverrideProviderType.COMPONENT;
public MapCodec<ComponentItemOverrideProvider> getCodec() {
return CODEC;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import com.google.gson.JsonElement;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.JsonOps;
import dev.dhyces.trimmed.api.TrimmedReference;
import dev.dhyces.trimmed.api.client.models.template.StringTemplate;
import dev.dhyces.trimmed.api.client.override.provider.ItemOverrideProvider;
import dev.dhyces.trimmed.api.client.override.provider.providers.AnyTrimItemOverrideProvider;
import dev.dhyces.trimmed.api.client.override.provider.providers.ComponentItemOverrideProvider;
import dev.dhyces.trimmed.api.data.model.override.ItemOverrideFile;
import dev.dhyces.trimmed.impl.client.models.override.ItemOverrideReloadListener;
import dev.dhyces.trimmed.impl.client.models.template.StringTemplate;
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
import net.minecraft.client.resources.model.ModelResourceLocation;
Expand All @@ -20,7 +20,8 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.ItemLike;

import java.util.*;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.function.UnaryOperator;

Expand All @@ -32,7 +33,7 @@ public abstract class ItemOverrideDataProvider implements DataProvider {

public ItemOverrideDataProvider(PackOutput output, String modid) {
this.dataOutput = output;
this.pathResolver = output.createPathProvider(PackOutput.Target.RESOURCE_PACK, ItemOverrideReloadListener.OVERRIDES_DIRECTORY);
this.pathResolver = output.createPathProvider(PackOutput.Target.RESOURCE_PACK, TrimmedReference.OVERRIDES_DIRECTORY);
this.modid = modid;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.dhyces.trimmed.api.KeyResolver;
import dev.dhyces.trimmed.api.util.CodecUtil;

import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.dhyces.trimmed.api.data.map;

import dev.dhyces.trimmed.api.KeyResolver;
import dev.dhyces.trimmed.api.maps.MapKey;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import net.minecraft.data.DataProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.dhyces.trimmed.api.util.CodecUtil;
import net.minecraft.resources.ResourceLocation;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.dhyces.trimmed.impl.client.maps;
package dev.dhyces.trimmed.api.maps;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.dhyces.trimmed.Trimmed;
import dev.dhyces.trimmed.api.TrimmedReference;
import dev.dhyces.trimmed.api.client.map.ClientMapTypes;
import dev.dhyces.trimmed.api.maps.types.MapType;
import dev.dhyces.trimmed.api.util.CodecUtil;
Expand Down Expand Up @@ -56,7 +56,7 @@ public static <K, V> MapKey<K, V> of(MapType<K, V> mapType, ResourceLocation id)
ResourceLocation baseKey;
ResourceLocation subKey;
if (secondSlashIndex == -1) {
baseKey = Trimmed.id(id.getPath().substring(0, firstSlashIndex));
baseKey = TrimmedReference.id(id.getPath().substring(0, firstSlashIndex));
subKey = id.withPath(s -> s.substring(firstSlashIndex+1));
} else {
baseKey = ResourceLocation.fromNamespaceAndPath(id.getPath().substring(0, firstSlashIndex), id.getPath().substring(firstSlashIndex+1, secondSlashIndex));
Expand Down
Loading

0 comments on commit 647b889

Please sign in to comment.