generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Still not functional though, hence the dev branch
- Loading branch information
Showing
76 changed files
with
1,161 additions
and
986 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
Common/src/main/java/dev/dhyces/trimmed/api/TrimmedClientApi.java
This file was deleted.
Oops, something went wrong.
27 changes: 7 additions & 20 deletions
27
Common/src/main/java/dev/dhyces/trimmed/api/TrimmedClientMapApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,18 @@ | ||
package dev.dhyces.trimmed.api; | ||
|
||
import dev.dhyces.trimmed.api.maps.MapAccess; | ||
import dev.dhyces.trimmed.api.maps.MapHolder; | ||
import dev.dhyces.trimmed.api.maps.types.AdvancedMapType; | ||
import dev.dhyces.trimmed.impl.TrimmedClientMapApiImpl; | ||
import dev.dhyces.trimmed.api.maps.OptionalMapEntry; | ||
import com.mojang.serialization.Codec; | ||
import dev.dhyces.trimmed.impl.client.maps.ClientMapKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import dev.dhyces.trimmed.impl.client.maps.MapKey; | ||
|
||
import java.util.Map; | ||
|
||
public interface TrimmedClientMapApi { | ||
static TrimmedClientMapApi getInstance() { | ||
return TrimmedClientMapApiImpl.INSTANCE; | ||
} | ||
|
||
@ApiStatus.Experimental | ||
MapAccess<ResourceLocation, String> map(ClientMapKey clientMapKey); | ||
|
||
@ApiStatus.Experimental | ||
Stream<OptionalMapEntry<ResourceLocation, String>> mapStream(ClientMapKey clientMapKey); | ||
|
||
@ApiStatus.Experimental | ||
<K> MapAccess<K, String> map(ClientRegistryMapKey<K> clientRegistryMapKey); | ||
|
||
@Nullable | ||
String getUncheckedClientValue(ClientMapKey clientMapKey, ResourceLocation key); | ||
<K, V> MapHolder<K, V, Map<K, V>> getSimpleMap(MapKey<K, V> key); | ||
|
||
@Nullable | ||
<K> String getRegistryClientValue(ClientRegistryMapKey<K> clientRegistryMapKey, K key); | ||
<T> ClientMapKeyType<T> registerKeyLoader(ResourceLocation key, Codec<T> keyCodec); | ||
<K, V, M extends Map<K, V>> MapHolder<K, V, M> getAdvancedMap(MapKey<K, V> key, AdvancedMapType<K, V, M> mapType); | ||
} |
20 changes: 20 additions & 0 deletions
20
Common/src/main/java/dev/dhyces/trimmed/api/client/ClientMapKeyResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package dev.dhyces.trimmed.api.client; | ||
|
||
import com.mojang.serialization.Codec; | ||
import dev.dhyces.trimmed.api.maps.MapKeyResolver; | ||
import net.minecraft.network.RegistryFriendlyByteBuf; | ||
import net.minecraft.network.codec.StreamCodec; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public record ClientMapKeyResolver<T>(Codec<T> codec) implements MapKeyResolver<T> { | ||
|
||
@Override | ||
public Codec<T> getCodec() { | ||
return codec; | ||
} | ||
|
||
@Override | ||
public @Nullable StreamCodec<RegistryFriendlyByteBuf, T> getStreamCodec() { | ||
return null; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Common/src/main/java/dev/dhyces/trimmed/api/client/ClientMapKeyResolvers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package dev.dhyces.trimmed.api.client; | ||
|
||
import dev.dhyces.trimmed.api.maps.MapKeyResolver; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public final class ClientMapKeyResolvers { | ||
private ClientMapKeyResolvers() {} | ||
|
||
public static final MapKeyResolver<ResourceLocation> TRIM_MATERIAL_TEXTURES = new ClientMapKeyResolver<>(ResourceLocation.CODEC); | ||
} |
6 changes: 3 additions & 3 deletions
6
Common/src/main/java/dev/dhyces/trimmed/api/client/ClientMapKeys.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package dev.dhyces.trimmed.api.client; | ||
|
||
import dev.dhyces.trimmed.Trimmed; | ||
import dev.dhyces.trimmed.impl.client.maps.ClientMapKey; | ||
import dev.dhyces.trimmed.impl.client.maps.MapKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public class ClientMapKeys { | ||
public static final ClientMapKey<ResourceLocation, ResourceLocation> DARKER_TRIM_MATERIALS = ClientMapKey.of(ClientMapTypes.TRIM_MATERIAL_PERMUTATIONS, Trimmed.id("darker_trim_materials")); | ||
public static final ClientMapKey<ResourceLocation, ResourceLocation> TRIM_MATERIALS = ClientMapKey.of(ClientMapTypes.TRIM_MATERIAL_PERMUTATIONS, Trimmed.id("trim_materials")); | ||
public static final MapKey<ResourceLocation, ResourceLocation> TRIM_MATERIALS = MapKey.of(ClientMapTypes.TRIM_MATERIALS, Trimmed.id("material_suffixes")); | ||
public static final MapKey<ResourceLocation, ResourceLocation> DARKER_TRIM_MATERIALS = TRIM_MATERIALS.makeSubKey("darker_material_suffixes"); | ||
} |
13 changes: 9 additions & 4 deletions
13
Common/src/main/java/dev/dhyces/trimmed/api/client/ClientMapTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
package dev.dhyces.trimmed.api.client; | ||
|
||
import dev.dhyces.trimmed.api.maps.MapType; | ||
import dev.dhyces.trimmed.api.maps.MapKeyResolver; | ||
import dev.dhyces.trimmed.api.maps.types.MapType; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public class ClientMapTypes { | ||
// TODO: Figure out registration. Probably make it separate from instantiation. | ||
public static final MapType<ResourceLocation, ResourceLocation> TRIM_MATERIAL_PERMUTATIONS = MapType.builder(ResourceLocation.CODEC, ResourceLocation.CODEC).build(); | ||
// Map resolvers resolve the key object and directory. Map types hold the resolver for the key type and the value codec. | ||
// Map types can either be independent or "grouped" (under a named subdirectory, which then permits the "append" field). | ||
// | ||
public final class ClientMapTypes { | ||
private ClientMapTypes() {} | ||
|
||
public static final MapType<ResourceLocation, ResourceLocation> TRIM_MATERIALS = MapType.simpleBuilder(ClientMapKeyResolvers.TRIM_MATERIAL_TEXTURES, ResourceLocation.CODEC.fieldOf("texture")).build(); | ||
} |
6 changes: 4 additions & 2 deletions
6
...yces/trimmed/api/TrimmedRegistration.java → ...api/client/TrimmedClientRegistration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
...c/main/java/dev/dhyces/trimmed/api/client/override/provider/ItemOverrideProviderType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
.../dhyces/trimmed/api/client/override/provider/providers/ComponentItemOverrideProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package dev.dhyces.trimmed.api.client.override.provider.providers; | ||
|
||
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; | ||
import net.minecraft.client.resources.model.ModelResourceLocation; | ||
import net.minecraft.core.component.DataComponentPatch; | ||
import net.minecraft.core.component.DataComponentType; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.item.ItemStack; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
public final class ComponentItemOverrideProvider extends SimpleItemOverrideProvider { | ||
public static final MapCodec<ComponentItemOverrideProvider> CODEC = RecordCodecBuilder.mapCodec(instance -> | ||
instance.group( | ||
DataComponentPatch.CODEC.fieldOf("components").forGetter(componentItemOverrideProvider -> componentItemOverrideProvider.componentPatch), | ||
CodecUtil.MODEL_IDENTIFIER_CODEC.fieldOf("model").forGetter(componentItemOverrideProvider -> componentItemOverrideProvider.model) | ||
).apply(instance, ComponentItemOverrideProvider::new) | ||
); | ||
|
||
private final DataComponentPatch componentPatch; | ||
private final ModelResourceLocation model; | ||
|
||
public ComponentItemOverrideProvider(DataComponentPatch componentPatch, ModelResourceLocation modelId) { | ||
this.componentPatch = componentPatch; | ||
this.model = modelId; | ||
} | ||
|
||
@Override | ||
public Optional<ModelResourceLocation> getModelLocation(ItemStack itemStack, @Nullable ClientLevel world, @Nullable LivingEntity entity, int seed) { | ||
if (!itemStack.getComponentsPatch().isEmpty()) { | ||
DataComponentPatch stackPatch = itemStack.getComponentsPatch(); | ||
for (Map.Entry<DataComponentType<?>, Optional<?>> entry : componentPatch.entrySet()) { | ||
Optional<?> stackData = stackPatch.get(entry.getKey()); | ||
Optional<?> testData = componentPatch.get(entry.getKey()); | ||
if ((stackData == null) != (testData == null)) { | ||
return Optional.empty(); | ||
} | ||
if (stackData.isEmpty() != testData.isEmpty()) { | ||
return Optional.empty(); | ||
} | ||
if (stackData.isPresent() && testData.isPresent() && !stackData.get().equals(testData.get())) { | ||
return Optional.empty(); | ||
} | ||
} | ||
return Optional.of(model); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Stream<ModelResourceLocation> getModelsToBake() { | ||
return Stream.of(model); | ||
} | ||
|
||
@Override | ||
public ItemOverrideProviderType<?> getType() { | ||
return ItemOverrideProviderType.NBT; | ||
} | ||
} |
Oops, something went wrong.