Skip to content

Commit

Permalink
Merge tag '2.8.0+1.21.1' into 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Estecka committed Jan 3, 2025
2 parents b9ed856 + f3cdd2a commit f10ec29
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
- Fixed rendering of trident in hand.
## 2.7
### 2.7.0
- Added the option `levelSeparator` to the module `stored_enchantment`
- Added the option `levelSeparator` to the module `stored_enchantment`.
### 2.7.1
- `custom_data` and siblings will now accept numeric data
## 2.8
- Added the modules `trim`, `trim_pattern` and `trim_material`.

5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ A streamlined CIT format for items with standardized variants.
This mod isn't as flexible as optifine, but excels in scenarios where one item has many variants based on the same piece of data. It yields better performances when extreme amounts of CITs are available, and uses a resource format that is less redundant, requiring only a short file to configure all possible variants at once.

## Supported Components
The mod can handle **Axolotl Buckets**, **Enchantments**, **Music Discs**, **Goat Horns**, **Painting Variants**, and **Potions**. More may be added as needed, and other mods can easily create add logic to it.
There are also more generic modules that can identify a variant from the `custom_data` or `custom_name` component of an item.
Specialized modules are available for **Axolotl Buckets**, **Enchantments**, **Goat Horns**, **Music Discs**, **Painting Variants**, **Potions**, and **Trims**. More may be added as needed, and other mods can easily create add logic to it.

If Mojang ever makes these items data-driven, you can expect Banner Patterns, Trim Templates, and Pottery Sherds to become supported in the future.
There are also more generic modules that can identify a variant from the `custom_data`, `custom_name`, and various `entity_data` components.

## Resource Pack Format
This is an overview, please see the [wiki](/~https://github.com/Estecka/mc-Variants-CIT/wiki) for a complete guide.
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ org.gradle.parallel=true
# check these on https://fabricmc.net/develop
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.2
loader_version=0.16.7
loader_version=0.16.9

# Fabric API
fabric_version=0.106.1+1.21.3
fabric_version=0.114.0+1.21.3

# Mod Properties
mod_version=2.7.1
mod_version=2.8.0
maven_group=fr.estecka.variantscit
archives_base_name=variants-cit
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/fr/estecka/variantscit/VariantsCitMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public void onInitializeClient(){
LOGGER.warn("Module name `stored_enchantments` (plural) is being deprecated. use `stored_enchantment` (singular) instead.");
return new EnchantedBookModule();
}));
ModuleRegistry.Register(Identifier.ofVanilla("trim"), new TrimModule());
ModuleRegistry.Register(Identifier.ofVanilla("trim_pattern"), new TrimPatternModule());
ModuleRegistry.Register(Identifier.ofVanilla("trim_material"), new TrimPatternModule());

ModelPredicateProviderRegistry.register(Identifier.ofVanilla("bucket_entity_age"), new BucketAgePredicate());
ModelPredicateProviderRegistry.register(Items.ENCHANTED_BOOK, Identifier.ofVanilla("level"), new EnchantedBookLevelPredicate());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package fr.estecka.variantscit.modules;

import java.util.WeakHashMap;
import java.util.function.Predicate;
import org.jetbrains.annotations.Nullable;
import fr.estecka.variantscit.VariantsCitMod;
import fr.estecka.variantscit.api.ISimpleCitModule;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;

abstract class ASimpleItemCachingModule
implements ISimpleCitModule
{
final WeakHashMap<ItemStack, CacheEntry> cache = new WeakHashMap<>();

protected record CacheEntry(@Nullable Identifier variant, Predicate<ItemStack> isDirty) {}

@Override
public final Identifier GetItemVariant(ItemStack stack){
CacheEntry entry = this.cache.get(stack);

if (entry == null || entry.isDirty.test(stack)){
entry = new CacheEntry(this.RecomputeItemVariant(stack), this.GetValidator(stack));
cache.put(stack, entry);
VariantsCitMod.LOGGER.warn("Item Cache: [{}] {}", cache.size(), entry.variant);
}

return entry.variant;
}

/**
* Returns a predicate that checks whether the cache for this stack should
* be invalidated.
*/
public abstract Predicate<ItemStack> GetValidator(ItemStack stack);

public abstract @Nullable Identifier RecomputeItemVariant(ItemStack stack);
}
66 changes: 66 additions & 0 deletions src/main/java/fr/estecka/variantscit/modules/TrimFormatModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package fr.estecka.variantscit.modules;

import java.util.function.Predicate;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.item.ItemStack;
import net.minecraft.item.equipment.trim.ArmorTrim;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import static net.minecraft.component.DataComponentTypes.TRIM;

/**
* TODO: An option to choose the namespace of the variant.
* TODO: The name of the item is probably unnecessary.
*/
@Deprecated
public class TrimFormatModule
extends ASimpleItemCachingModule
{
static public final MapCodec<TrimFormatModule> CODEC = RecordCodecBuilder.mapCodec(builder->builder
.group(
Codec.STRING.fieldOf("variantFormat").orElse("${item}/${pattern}.${material}").forGetter(p->p.format)
)
.apply(builder, TrimFormatModule::new)
);

private final String format;

private TrimFormatModule(String format)
throws IllegalStateException
{
this.format = format;

if (!Identifier.isPathValid(this.Substitute("a","b","c")))
throw new IllegalStateException("Invalid path format: "+format);
}


@Override
public Predicate<ItemStack> GetValidator(ItemStack stack){
ArmorTrim trim = stack.get(TRIM);
return (futureStack) -> futureStack.get(TRIM) != trim;
}

@Override
public Identifier RecomputeItemVariant(ItemStack stack){
ArmorTrim trim = stack.get(TRIM);
if (trim == null)
return null;

Identifier type = Registries.ITEM.getEntry(stack.getItem()).getKey().get().getValue();
Identifier pattern = trim.pattern().getKey().get().getValue();
String material = trim.material().value().assetName();

return pattern.withPath( this.Substitute(type.getPath(), pattern.getPath(), material));
}

private String Substitute(String itemType, String pattern, String material){
return this.format
.replace("${item}", itemType)
.replace("${pattern}", pattern)
.replace("${material}", material)
;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fr.estecka.variantscit.modules;

import fr.estecka.variantscit.api.ISimpleCitModule;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.ItemStack;
import net.minecraft.item.equipment.trim.ArmorTrim;
import net.minecraft.util.Identifier;

public class TrimMaterialModule
implements ISimpleCitModule
{
@Override
public Identifier GetItemVariant(ItemStack stack){
ArmorTrim trim = stack.get(DataComponentTypes.TRIM);
if (trim == null)
return null;

return trim.material().getKey().get().getValue();
}
}
24 changes: 24 additions & 0 deletions src/main/java/fr/estecka/variantscit/modules/TrimModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fr.estecka.variantscit.modules;

import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.equipment.trim.ArmorTrim;
import net.minecraft.util.Identifier;

public class TrimModule
extends ASimpleComponentCachingModule<ArmorTrim>
{
public TrimModule(){
super(DataComponentTypes.TRIM);
}

@Override
public Identifier GetVariantForComponent(ArmorTrim trim){
if (trim == null)
return null;

Identifier pattern = trim.pattern().getKey().get().getValue();
Identifier material = trim.material().getKey().get().getValue();

return pattern.withSuffixedPath("_" + material.getPath());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fr.estecka.variantscit.modules;

import fr.estecka.variantscit.api.ISimpleCitModule;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.ItemStack;
import net.minecraft.item.equipment.trim.ArmorTrim;
import net.minecraft.util.Identifier;

public class TrimPatternModule
implements ISimpleCitModule
{
@Override
public Identifier GetItemVariant(ItemStack stack){
ArmorTrim trim = stack.get(DataComponentTypes.TRIM);
if (trim == null)
return null;

return trim.pattern().getKey().get().getValue();
}
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
],
"depends": {
"minecraft": ">=1.21.2 <1.21.4",
"fabricloader": ">=0.16.7",
"fabricloader": ">=0.16.9",
"fabric-api": ">=0.106.1",
"java": ">=21"
}
Expand Down

0 comments on commit f10ec29

Please sign in to comment.