-
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.
- Added the `custom_name` module - Fixed the `parameters` block being mandatory on modules with only optional parameters. - Fixed items with no variant using the fallback model instead of the vanilla one.
- Loading branch information
Showing
10 changed files
with
111 additions
and
37 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
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
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
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
51 changes: 51 additions & 0 deletions
51
src/main/java/fr/estecka/variantscit/modules/CustomNameModule.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,51 @@ | ||
package fr.estecka.variantscit.modules; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.MapCodec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import fr.estecka.variantscit.api.ISimpleCitModule; | ||
import net.minecraft.component.DataComponentTypes; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class CustomNameModule | ||
implements ISimpleCitModule | ||
{ | ||
static public record CustomNameConfig(boolean caseSensitive, Map<String, Identifier> specialNames) {} | ||
|
||
static public final MapCodec<CustomNameConfig> CODEC = RecordCodecBuilder.mapCodec(builder->builder | ||
.group( | ||
Codec.BOOL.fieldOf("caseSensitive").orElse(false).forGetter(p->p.caseSensitive), | ||
Codec.unboundedMap(Codec.STRING, Identifier.CODEC).fieldOf("specialNames").orElse(Map.of()).forGetter(p->p.specialNames) | ||
) | ||
.apply(builder, CustomNameConfig::new) | ||
); | ||
|
||
private final boolean caseSensitive; | ||
private final Map<String,Identifier> specialNames = new HashMap<>(); | ||
|
||
public CustomNameModule(CustomNameConfig params){ | ||
this.caseSensitive = params.caseSensitive; | ||
if (caseSensitive) | ||
this.specialNames.putAll(params.specialNames); | ||
else for (var e : params.specialNames.entrySet()) | ||
this.specialNames.put(e.getKey().toLowerCase(), e.getValue()); | ||
} | ||
|
||
@Override | ||
public Identifier GetItemVariant(ItemStack stack){ | ||
Text component = stack.get(DataComponentTypes.CUSTOM_NAME); | ||
if (component == null) | ||
return null; | ||
|
||
String name = component.getString(); | ||
if (!caseSensitive) | ||
name = name.toLowerCase(); | ||
|
||
Identifier variant = specialNames.get(name); | ||
return (variant != null) ? variant : Identifier.tryParse(name); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.