Skip to content

Commit

Permalink
Pushed update
Browse files Browse the repository at this point in the history
So this is no longer ArmorModelPredicate, because it doesn't change the model. It is now ArmorRenderLib because it is a small bit of reusable code that extends the FabricAPI ArmorRenderer to allow the dynamic changing of textures and colors of any armor item. Still in beta because while I could technically add support for predicates at this point (such as item tags), I have no need yet so I'm choosing to reduce bloat.
  • Loading branch information
CleverNucleus committed Jul 27, 2022
1 parent 9e51687 commit 4b27632
Show file tree
Hide file tree
Showing 26 changed files with 303 additions and 195 deletions.
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
# ArmorModelPredicate
Adds the armor model predicates to Minecraft using Fabric Mixins.
<img src="img/logo.png" alt="Armor Render Lib" height="100" />
<hr />

[![GitHub license](https://img.shields.io/github/license/CleverNucleus/ArmorRenderLib?style=flat-square)](https://github.com/CleverNucleus/ArmorRenderLib/blob/main/LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/CleverNucleus/ArmorRenderLib?style=flat-square)](https://github.com/CleverNucleus/ArmorRenderLib/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/CleverNucleus/ArmorRenderLib?style=flat-square)](https://github.com/CleverNucleus/ArmorRenderLib/network)
[![GitHub issues](https://img.shields.io/github/issues/CleverNucleus/ArmorRenderLib?style=flat-square)](https://github.com/CleverNucleus/ArmorRenderLib/issues)

Armor Render Lib is a lightweight extension library to Fabric API's fabric-rendering-v1 [ArmorRenderer](https://github.com/FabricMC/fabric/tree/1.18.2/fabric-rendering-v1). Since the Fabric API implementation is quite abstract, a more targeted implementation is needed for some specific use cases. These use cases are present across more than one of my mods, so in the spirit of code reuse this library was created. It is robust, using only a few very targeted mixins and is fully compatible with Cosmetic Armor and GeckoLib.

### Use

Armor Render Lib adds armor render layers. These are objects containing a dynamic texture location, color and glint boolean that render armor for an item (or items). They are roughly equivalent to Fabric API's [ArmorRenderer#renderPart](https://github.com/FabricMC/fabric/blob/f14603e8624d4cb192846321c429cc00c9ef6f55/fabric-rendering-v1/src/main/java/net/fabricmc/fabric/api/client/rendering/v1/ArmorRenderer.java#L69), but the texture, color and glint can be dynamically specified based on the `ItemStack`, `LivingEntity` and `EquipmentSlot`.

They should be registered like so:

```java
public class ExampleMod implements ClientModInitializer {
private static ArmorRenderProvider render(ItemStack stack, LivingEntity entity, EquipmentSlot slot) {
// Dynamic texture path
String texture = "examplemod:textures/model/armor/example_chestplate.png";

// Dynamic color
int color = 0xFF00FF;

return data -> data.accept(texture, color, stack.hasGlint());
}

@Override
public void onInitializeClient() {
ArmorRenderLib.register(ExampleMod::render, Items.IRON_CHESTPLATE);
}
}
```

### Notes

- An item can have multiple different armor render layers registered to it.
- Multiple items can have the same armor render layer registered to them.
- Registering a render layer to a vanilla item (or other armor item) overrides the default armor rendering.
- This means that the texture, color and/or enchantment glint of vanilla armor can be modified.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.11-SNAPSHOT'
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'maven-publish'
}

Expand All @@ -18,6 +18,7 @@ dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
}

processResources {
Expand Down Expand Up @@ -48,8 +49,8 @@ publishing {
from components.java
}
}

repositories {
}
}
19 changes: 7 additions & 12 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.18.1
yarn_mappings=1.18.1+build.22
loader_version=0.12.12
minecraft_version=1.18.2
yarn_mappings=1.18.2+build.3
loader_version=0.14.6

# Mod Properties
mod_version = 0.1.0
maven_group = com.github.clevernucleus
archives_base_name = armor-model-predicate
mod_version = 0.1.1
maven_group = com.github.clevernucleus
archives_base_name = armorrenderlib

# Dependencies

fabric_version=0.55.1+1.18.2
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Binary file added img/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed specification.zip
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.github.clevernucleus.armorrenderlib.api;

@FunctionalInterface
public interface ArmorRenderData {

/**
*
* @param texturePath
* @param color
* @param hasGlint
*/
void accept(final String texturePath, final int color, final boolean hasGlint);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.clevernucleus.armorrenderlib.api;

import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;

@FunctionalInterface
public interface ArmorRenderLayer {

/**
*
* @param itemStack
* @param livingEntity
* @param slot
* @return
*/
ArmorRenderProvider render(final ItemStack itemStack, final LivingEntity livingEntity, final EquipmentSlot slot);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.clevernucleus.armorrenderlib.api;

import net.minecraft.item.ItemConvertible;

/**
* Use this to register armor render layers!
*
* @author CleverNucleus
*
*/
public interface ArmorRenderLib {
/**
* <p>
* Registers an armor render layer for the input item(s). The same armor render layer can be registered for multiple items. The same item(s) can have multiple armor render layers. The armor render layer specifies what armor texture should be used, what color should be applied (if any) and whether it has a glint.
* </p>
* <p>
* This is an extension of {@link net.fabricmc.fabric.api.client.rendering.v1.ArmorRenderer#render(net.minecraft.client.util.math.MatrixStack, net.minecraft.client.render.VertexConsumerProvider, net.minecraft.item.ItemStack, net.minecraft.entity.LivingEntity, net.minecraft.entity.EquipmentSlot, int, net.minecraft.client.render.entity.model.BipedEntityModel)}.
* </p>
*
* @param layer
* @param items
*/
static void register(ArmorRenderLayer layer, ItemConvertible ... items) {
com.github.clevernucleus.armorrenderlib.impl.ArmorRenderLibImpl.register(layer, items);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.github.clevernucleus.armorrenderlib.api;

@FunctionalInterface
public interface ArmorRenderProvider {

/**
*
* @param data
*/
void from(final ArmorRenderData data);
}
Loading

0 comments on commit 4b27632

Please sign in to comment.