Skip to content

Commit

Permalink
Basic model gen
Browse files Browse the repository at this point in the history
This still creates models for all of the vanilla stuff too, so need to prevent that in some way
  • Loading branch information
dhyces committed May 27, 2024
1 parent a36203d commit 1b3a8e2
Show file tree
Hide file tree
Showing 47 changed files with 697 additions and 122 deletions.
12 changes: 10 additions & 2 deletions common/src/main/java/dev/dhyces/trimmed/TrimmedClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import dev.dhyces.trimmed.api.client.ClientMapKeyResolvers;
import dev.dhyces.trimmed.api.client.ClientMapKeys;
import dev.dhyces.trimmed.api.client.ClientMapTypes;
import dev.dhyces.trimmed.impl.client.atlas.TrimmedSpriteSourceTypes;
import dev.dhyces.trimmed.impl.client.maps.MapKeyResolvers;
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.ModelSourceRegistry;
import dev.dhyces.trimmed.impl.client.models.source.replacement.StringReplacementManager;
import dev.dhyces.trimmed.impl.client.tags.manager.ClientTagManager;
import dev.dhyces.trimmed.impl.mixin.client.ReloadableResourceManagerImplAccessor;
import dev.dhyces.trimmed.impl.client.maps.manager.ClientMapManager;
Expand All @@ -27,11 +30,16 @@ public class TrimmedClient {
// });

public static void init() {
MapKeyResolvers.register(Trimmed.id("texture"), ClientMapKeyResolvers.TEXTURE);
ClientMapTypes.init();
ClientMapManager.registerBaseKey(ClientMapKeys.MATERIAL_SUFFIXES);
ClientMapManager.registerBaseKey(ClientMapKeys.TRIM_MATERIAL_OVERRIDES);
ClientMapManager.registerBaseKey(ClientMapKeys.TRIM_OVERLAYS);
StringReplacementManager.init();
ModelSourceRegistry.init();
TrimmedSpriteSourceTypes.bootstrap();
// ModelTemplateManager.init();
ItemOverrideProviderRegistry.init();
MapKeyResolvers.register(Trimmed.id("texture"), ClientMapKeyResolvers.TEXTURE);
ClientMapManager.registerBaseKey(ClientMapKeys.MATERIAL_SUFFIXES);
}

public static void registerClientReloadListener(BiConsumer<String, PreparableReloadListener> eventConsumer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package dev.dhyces.trimmed.api;

import com.mojang.serialization.Codec;
import dev.dhyces.trimmed.api.maps.MapHolder;
import dev.dhyces.trimmed.api.maps.types.AdvancedMapType;
import dev.dhyces.trimmed.api.maps.types.MapType;
import dev.dhyces.trimmed.impl.TrimmedClientMapApiImpl;
import dev.dhyces.trimmed.impl.client.maps.MapKey;

Expand All @@ -14,5 +16,7 @@ static TrimmedClientMapApi getInstance() {

<K, V> MapHolder<K, V> getSimpleMap(MapKey<K, V> key);

<K, V> Codec<MapHolder<K, V>> simpleCodec(MapType<K, V> mapType);

<K, V, M extends Map<K, V>> MapHolder.Typed<K, V, M> getAdvancedMap(MapKey<K, V> key, AdvancedMapType<K, V, M> mapType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ public class ClientMapKeys {
public static final MapKey<ResourceLocation, ResourceLocation> GOLD_MATERIAL_OVERRIDES = TRIM_MATERIAL_OVERRIDES.makeSubKey("gold");
public static final MapKey<ResourceLocation, ResourceLocation> DIAMOND_MATERIAL_OVERRIDES = TRIM_MATERIAL_OVERRIDES.makeSubKey("diamond");
public static final MapKey<ResourceLocation, ResourceLocation> NETHERITE_MATERIAL_OVERRIDES = TRIM_MATERIAL_OVERRIDES.makeSubKey("netherite");

public static final MapKey<ResourceLocation, ResourceLocation> TRIM_OVERLAYS = MapKey.of(ClientMapTypes.TEXTURE_MAPPING, Trimmed.id("trim_overlays"));
public static final MapKey<ResourceLocation, ResourceLocation> IRON_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey("iron");
public static final MapKey<ResourceLocation, ResourceLocation> GOLD_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey("gold");
public static final MapKey<ResourceLocation, ResourceLocation> DIAMOND_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey("diamond");
public static final MapKey<ResourceLocation, ResourceLocation> NETHERITE_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey("netherite");
public static final MapKey<ResourceLocation, ResourceLocation> LEATHER_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey("leather");
public static final MapKey<ResourceLocation, ResourceLocation> CHAINMAIL_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey("chainmail");
public static final MapKey<ResourceLocation, ResourceLocation> TURTLE_ARMOR_OVERLAYS = TRIM_OVERLAYS.makeSubKey("turtle");
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

public final class ClientMapTypes {
private ClientMapTypes() {}
public static void init() {}

private static final BiMap<ResourceLocation, MapType<?, ?>> REGISTERED_TYPES = HashBiMap.create();
public static final Codec<MapType<?, ?>> CODEC = CodecUtil.TRIMMED_IDENTIFIER.xmap(REGISTERED_TYPES::get, REGISTERED_TYPES.inverse()::get);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package dev.dhyces.trimmed.impl;

import com.mojang.serialization.Codec;
import dev.dhyces.trimmed.api.TrimmedClientMapApi;
import dev.dhyces.trimmed.api.maps.MapHolder;
import dev.dhyces.trimmed.api.maps.types.AdvancedMapType;
import dev.dhyces.trimmed.api.maps.types.MapType;
import dev.dhyces.trimmed.impl.client.maps.MapKey;
import dev.dhyces.trimmed.impl.client.maps.manager.ClientMapManager;

Expand All @@ -16,6 +18,11 @@ public <K, V> MapHolder<K, V> getSimpleMap(MapKey<K, V> key) {
return ClientMapManager.getHolder(key);
}

@Override
public <K, V> Codec<MapHolder<K, V>> simpleCodec(MapType<K, V> mapType) {
return MapKey.codec(mapType).xmap(ClientMapManager::getHolder, MapHolder::unwrapKeyOrThrow);
}

@Override
public <K, V, M extends Map<K, V>> MapHolder.Typed<K, V, M> getAdvancedMap(MapKey<K, V> key, AdvancedMapType<K, V, M> mapType) {
return (MapHolder.Typed<K, V, M>) ClientMapManager.getHolder(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class OpenPalettedPermutations implements SpriteSource {
public static final MapCodec<OpenPalettedPermutations> CODEC = RecordCodecBuilder.mapCodec(instance ->
instance.group(
ResourceLocation.CODEC.fieldOf("palette_key").forGetter(openPalettedPermutations -> openPalettedPermutations.paletteKey),
MapKey.codec(ClientMapTypes.MATERIAL_SUFFIXES).fieldOf("permutation_map").forGetter(openPalettedPermutations -> openPalettedPermutations.permutations.unwrapKeyOrThrow()),
MapKey.codec(ClientMapTypes.TEXTURE_SUFFIX).fieldOf("permutation_map").forGetter(openPalettedPermutations -> openPalettedPermutations.permutations.unwrapKeyOrThrow()),
ClientTagKey.CODEC.fieldOf("texture_set").forGetter(openPalettedPermutations -> openPalettedPermutations.textures)
).apply(instance, OpenPalettedPermutations::new)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ public static <K, V> Codec<MapKey<K, V>> codec(MapType<K, V> mapType) {

private final MapType<K, V> type;
private final ResourceLocation id;
private final boolean isSubKey;

private MapKey(MapType<K, V> mapType, ResourceLocation id) {
this.type = mapType;
this.id = id;
this.isSubKey = id.getPath().contains("/");
}

@SuppressWarnings("unchecked")
Expand All @@ -54,6 +56,18 @@ public MapKey<K, V> makeSubKeyFromPath(ResourceLocation subId) {
return makeSubKey(subId.getPath().replace(id.getPath(), ""));
}

public MapKey<K, V> getParentKey() {
return of(type, id.withPath(s -> s.substring(0, s.lastIndexOf("/"))));
}

public MapKey<K, V> getBaseKey() {
return of(type, id.withPath(s -> s.substring(0, s.indexOf("/"))));
}

public boolean isSubKey() {
return isSubKey;
}

@Override
public String toString() {
return "MapKey[type: "+ type + ", id: " + id + "]";
Expand Down
Loading

0 comments on commit 1b3a8e2

Please sign in to comment.