Reformated
This commit is contained in:
parent
fc1da134e7
commit
60e8008cb7
416 changed files with 5772 additions and 4573 deletions
|
@ -21,19 +21,21 @@
|
|||
|
||||
package shadow.fabric.api.client.rendering.v1;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.model.HumanoidModel;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import shadow.fabric.impl.client.rendering.ArmorRenderingRegistryImpl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A class for registering custom armor models and textures for {@link Item}, to be provided by a {@link ModelProvider} or {@link TextureProvider}.
|
||||
|
@ -49,121 +51,147 @@ import java.util.Arrays;
|
|||
*/
|
||||
@Environment(EnvType.CLIENT)
|
||||
public final class ArmorRenderingRegistry {
|
||||
private ArmorRenderingRegistry() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a provider for custom armor models for an item.
|
||||
*
|
||||
* @param provider the provider for the model
|
||||
* @param items the items to be registered for
|
||||
*/
|
||||
public static void registerModel(@Nullable ModelProvider provider, Item... items) {
|
||||
registerModel(provider, Arrays.asList(items));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a provider for custom armor models for an item.
|
||||
*
|
||||
* @param provider the provider for the model
|
||||
* @param items the items to be registered for
|
||||
*/
|
||||
public static void registerModel(@Nullable ModelProvider provider, Iterable<Item> items) {
|
||||
ArmorRenderingRegistryImpl.registerModel(provider, items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a provider for custom texture models for an item.
|
||||
*
|
||||
* @param provider the provider for the texture
|
||||
* @param items the items to be registered for
|
||||
*/
|
||||
public static void registerTexture(@Nullable TextureProvider provider, Item... items) {
|
||||
registerTexture(provider, Arrays.asList(items));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a provider for custom texture models for an item.
|
||||
*
|
||||
* @param provider the provider for the texture
|
||||
* @param items the items to be registered for
|
||||
*/
|
||||
public static void registerTexture(@Nullable TextureProvider provider, Iterable<Item> items) {
|
||||
ArmorRenderingRegistryImpl.registerTexture(provider, items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register simple armor items to use the vanilla armor file name under the mods namespace.
|
||||
*
|
||||
* @param identifier The namespace + path to use for the armor texture location.
|
||||
* @param items the items to be registered
|
||||
*/
|
||||
public static void registerSimpleTexture(ResourceLocation identifier, Item... items) {
|
||||
registerTexture((entity, stack, slot, secondLayer, suffix, defaultTexture) -> {
|
||||
return new ResourceLocation(
|
||||
identifier.getNamespace(),
|
||||
"textures/models/armor/" + identifier.getPath() + "_layer_" + (secondLayer ? 2 : 1) + (suffix == null ? "" : "_" + suffix) + ".png"
|
||||
);
|
||||
}, items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the model of the armor piece.
|
||||
*
|
||||
* @param entity The entity equipping the armor
|
||||
* @param stack The item stack of the armor
|
||||
* @param slot The slot which the armor is in
|
||||
* @param defaultModel The default model that vanilla provides
|
||||
* @return The model of the armor piece.
|
||||
*/
|
||||
@NotNull
|
||||
public static HumanoidModel<LivingEntity> getArmorModel(LivingEntity entity, ItemStack stack, EquipmentSlot slot, HumanoidModel<LivingEntity> defaultModel) {
|
||||
return ArmorRenderingRegistryImpl.getArmorModel(entity, stack, slot, defaultModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the armor texture {@link net.minecraft.resources.ResourceLocation}.
|
||||
*
|
||||
* @param entity The entity equipping the armor
|
||||
* @param stack The item stack of the armor
|
||||
* @param slot The slot which the armor is in
|
||||
* @param secondLayer True if using the second texture layer
|
||||
* @param suffix The texture suffix, used in vanilla by {@link net.minecraft.world.item.DyeableArmorItem}
|
||||
* @param defaultTexture The default vanilla texture identifier
|
||||
* @return the custom armor texture identifier, return null to use the vanilla ones. Defaulted to the item's registry id.
|
||||
*/
|
||||
@NotNull
|
||||
public static ResourceLocation getArmorTexture(LivingEntity entity, ItemStack stack, EquipmentSlot slot, boolean secondLayer, @Nullable String suffix, ResourceLocation defaultTexture) {
|
||||
return ArmorRenderingRegistryImpl.getArmorTexture(entity, stack, slot, secondLayer, suffix, defaultTexture);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
@Environment(EnvType.CLIENT)
|
||||
public interface ModelProvider {
|
||||
/**
|
||||
* Gets the model of the armor piece.
|
||||
*
|
||||
* @param entity The entity equipping the armor
|
||||
* @param stack The item stack of the armor
|
||||
* @param slot The slot which the armor is in
|
||||
* @param defaultModel The default vanilla armor model
|
||||
* @return The model of the armor piece. Should never be null.
|
||||
*/
|
||||
@NotNull HumanoidModel<LivingEntity> getArmorModel(LivingEntity entity, ItemStack stack, EquipmentSlot slot, HumanoidModel<LivingEntity> defaultModel);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
@Environment(EnvType.CLIENT)
|
||||
public interface TextureProvider {
|
||||
/**
|
||||
* Gets the armor texture {@link net.minecraft.resources.ResourceLocation}.
|
||||
*
|
||||
* @param entity The entity equipping the armor
|
||||
* @param stack The item stack of the armor
|
||||
* @param slot The slot which the armor is in
|
||||
* @param defaultTexture The default vanilla texture identifier
|
||||
* @return the custom armor texture identifier. Should never be null.
|
||||
*/
|
||||
@NotNull ResourceLocation getArmorTexture(LivingEntity entity, ItemStack stack, EquipmentSlot slot, boolean secondLayer, @Nullable String suffix, ResourceLocation defaultTexture);
|
||||
}
|
||||
private ArmorRenderingRegistry() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a provider for custom armor models for an item.
|
||||
*
|
||||
* @param provider the provider for the model
|
||||
* @param items the items to be registered for
|
||||
*/
|
||||
public static void registerModel(@Nullable ModelProvider provider, Item... items) {
|
||||
registerModel(provider, Arrays.asList(items));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a provider for custom armor models for an item.
|
||||
*
|
||||
* @param provider the provider for the model
|
||||
* @param items the items to be registered for
|
||||
*/
|
||||
public static void registerModel(@Nullable ModelProvider provider, Iterable<Item> items) {
|
||||
ArmorRenderingRegistryImpl.registerModel(provider, items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a provider for custom texture models for an item.
|
||||
*
|
||||
* @param provider the provider for the texture
|
||||
* @param items the items to be registered for
|
||||
*/
|
||||
public static void registerTexture(@Nullable TextureProvider provider, Item... items) {
|
||||
registerTexture(provider, Arrays.asList(items));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a provider for custom texture models for an item.
|
||||
*
|
||||
* @param provider the provider for the texture
|
||||
* @param items the items to be registered for
|
||||
*/
|
||||
public static void registerTexture(@Nullable TextureProvider provider, Iterable<Item> items) {
|
||||
ArmorRenderingRegistryImpl.registerTexture(provider, items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register simple armor items to use the vanilla armor file name under the mods namespace.
|
||||
*
|
||||
* @param identifier The namespace + path to use for the armor texture location.
|
||||
* @param items the items to be registered
|
||||
*/
|
||||
public static void registerSimpleTexture(ResourceLocation identifier, Item... items) {
|
||||
registerTexture((entity, stack, slot, secondLayer, suffix, defaultTexture) -> {
|
||||
return new ResourceLocation(
|
||||
identifier.getNamespace(),
|
||||
"textures/models/armor/" + identifier.getPath() + "_layer_" + (secondLayer
|
||||
? 2
|
||||
: 1) + (suffix == null ? "" : "_" + suffix) + ".png"
|
||||
);
|
||||
}, items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the model of the armor piece.
|
||||
*
|
||||
* @param entity The entity equipping the armor
|
||||
* @param stack The item stack of the armor
|
||||
* @param slot The slot which the armor is in
|
||||
* @param defaultModel The default model that vanilla provides
|
||||
* @return The model of the armor piece.
|
||||
*/
|
||||
@NotNull
|
||||
public static HumanoidModel<LivingEntity> getArmorModel(
|
||||
LivingEntity entity,
|
||||
ItemStack stack,
|
||||
EquipmentSlot slot,
|
||||
HumanoidModel<LivingEntity> defaultModel
|
||||
) {
|
||||
return ArmorRenderingRegistryImpl.getArmorModel(entity, stack, slot, defaultModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the armor texture {@link net.minecraft.resources.ResourceLocation}.
|
||||
*
|
||||
* @param entity The entity equipping the armor
|
||||
* @param stack The item stack of the armor
|
||||
* @param slot The slot which the armor is in
|
||||
* @param secondLayer True if using the second texture layer
|
||||
* @param suffix The texture suffix, used in vanilla by {@link net.minecraft.world.item.DyeableArmorItem}
|
||||
* @param defaultTexture The default vanilla texture identifier
|
||||
* @return the custom armor texture identifier, return null to use the vanilla ones. Defaulted to the item's registry id.
|
||||
*/
|
||||
@NotNull
|
||||
public static ResourceLocation getArmorTexture(
|
||||
LivingEntity entity,
|
||||
ItemStack stack,
|
||||
EquipmentSlot slot,
|
||||
boolean secondLayer,
|
||||
@Nullable String suffix,
|
||||
ResourceLocation defaultTexture
|
||||
) {
|
||||
return ArmorRenderingRegistryImpl.getArmorTexture(entity, stack, slot, secondLayer, suffix, defaultTexture);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
@Environment(EnvType.CLIENT)
|
||||
public interface ModelProvider {
|
||||
/**
|
||||
* Gets the model of the armor piece.
|
||||
*
|
||||
* @param entity The entity equipping the armor
|
||||
* @param stack The item stack of the armor
|
||||
* @param slot The slot which the armor is in
|
||||
* @param defaultModel The default vanilla armor model
|
||||
* @return The model of the armor piece. Should never be null.
|
||||
*/
|
||||
@NotNull HumanoidModel<LivingEntity> getArmorModel(
|
||||
LivingEntity entity,
|
||||
ItemStack stack,
|
||||
EquipmentSlot slot,
|
||||
HumanoidModel<LivingEntity> defaultModel
|
||||
);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
@Environment(EnvType.CLIENT)
|
||||
public interface TextureProvider {
|
||||
/**
|
||||
* Gets the armor texture {@link net.minecraft.resources.ResourceLocation}.
|
||||
*
|
||||
* @param entity The entity equipping the armor
|
||||
* @param stack The item stack of the armor
|
||||
* @param slot The slot which the armor is in
|
||||
* @param defaultTexture The default vanilla texture identifier
|
||||
* @return the custom armor texture identifier. Should never be null.
|
||||
*/
|
||||
@NotNull ResourceLocation getArmorTexture(
|
||||
LivingEntity entity,
|
||||
ItemStack stack,
|
||||
EquipmentSlot slot,
|
||||
boolean secondLayer,
|
||||
@Nullable String suffix,
|
||||
ResourceLocation defaultTexture
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,15 +21,16 @@
|
|||
|
||||
package shadow.fabric.impl.client.rendering;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import shadow.fabric.api.client.rendering.v1.ArmorRenderingRegistry;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface ArmorProviderExtensions {
|
||||
@Nullable ArmorRenderingRegistry.ModelProvider fabric_getArmorModelProvider();
|
||||
|
||||
@Nullable ArmorRenderingRegistry.TextureProvider fabric_getArmorTextureProvider();
|
||||
|
||||
void fabric_setArmorModelProvider(@Nullable ArmorRenderingRegistry.ModelProvider provider);
|
||||
|
||||
void fabric_setArmorTextureProvider(@Nullable ArmorRenderingRegistry.TextureProvider provider);
|
||||
@Nullable ArmorRenderingRegistry.ModelProvider fabric_getArmorModelProvider();
|
||||
|
||||
@Nullable ArmorRenderingRegistry.TextureProvider fabric_getArmorTextureProvider();
|
||||
|
||||
void fabric_setArmorModelProvider(@Nullable ArmorRenderingRegistry.ModelProvider provider);
|
||||
|
||||
void fabric_setArmorTextureProvider(@Nullable ArmorRenderingRegistry.TextureProvider provider);
|
||||
}
|
||||
|
|
|
@ -27,56 +27,69 @@ import net.minecraft.world.entity.EquipmentSlot;
|
|||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import shadow.fabric.api.client.rendering.v1.ArmorRenderingRegistry;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class ArmorRenderingRegistryImpl {
|
||||
private ArmorRenderingRegistryImpl() {
|
||||
}
|
||||
|
||||
public static void registerModel(ArmorRenderingRegistry.ModelProvider provider, Iterable<Item> items) {
|
||||
Objects.requireNonNull(items);
|
||||
|
||||
for (Item item : items) {
|
||||
Objects.requireNonNull(item);
|
||||
|
||||
((ArmorProviderExtensions) item).fabric_setArmorModelProvider(provider);
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerTexture(ArmorRenderingRegistry.TextureProvider provider, Iterable<Item> items) {
|
||||
Objects.requireNonNull(items);
|
||||
|
||||
for (Item item : items) {
|
||||
Objects.requireNonNull(item);
|
||||
|
||||
((ArmorProviderExtensions) item).fabric_setArmorTextureProvider(provider);
|
||||
}
|
||||
}
|
||||
|
||||
public static HumanoidModel<LivingEntity> getArmorModel(LivingEntity entity, ItemStack stack, EquipmentSlot slot, HumanoidModel<LivingEntity> defaultModel) {
|
||||
if (!stack.isEmpty()) {
|
||||
ArmorRenderingRegistry.ModelProvider provider = ((ArmorProviderExtensions) stack.getItem()).fabric_getArmorModelProvider();
|
||||
|
||||
if (provider != null) {
|
||||
return provider.getArmorModel(entity, stack, slot, defaultModel);
|
||||
}
|
||||
}
|
||||
|
||||
return defaultModel;
|
||||
}
|
||||
|
||||
public static ResourceLocation getArmorTexture(LivingEntity entity, ItemStack stack, EquipmentSlot slot, boolean secondLayer, @Nullable String suffix, ResourceLocation defaultTexture) {
|
||||
if (!stack.isEmpty()) {
|
||||
ArmorRenderingRegistry.TextureProvider provider = ((ArmorProviderExtensions) stack.getItem()).fabric_getArmorTextureProvider();
|
||||
|
||||
if (provider != null) {
|
||||
return provider.getArmorTexture(entity, stack, slot, secondLayer, suffix, defaultTexture);
|
||||
}
|
||||
}
|
||||
|
||||
return defaultTexture;
|
||||
}
|
||||
private ArmorRenderingRegistryImpl() {
|
||||
}
|
||||
|
||||
public static void registerModel(ArmorRenderingRegistry.ModelProvider provider, Iterable<Item> items) {
|
||||
Objects.requireNonNull(items);
|
||||
|
||||
for (Item item : items) {
|
||||
Objects.requireNonNull(item);
|
||||
|
||||
((ArmorProviderExtensions) item).fabric_setArmorModelProvider(provider);
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerTexture(ArmorRenderingRegistry.TextureProvider provider, Iterable<Item> items) {
|
||||
Objects.requireNonNull(items);
|
||||
|
||||
for (Item item : items) {
|
||||
Objects.requireNonNull(item);
|
||||
|
||||
((ArmorProviderExtensions) item).fabric_setArmorTextureProvider(provider);
|
||||
}
|
||||
}
|
||||
|
||||
public static HumanoidModel<LivingEntity> getArmorModel(
|
||||
LivingEntity entity,
|
||||
ItemStack stack,
|
||||
EquipmentSlot slot,
|
||||
HumanoidModel<LivingEntity> defaultModel
|
||||
) {
|
||||
if (!stack.isEmpty()) {
|
||||
ArmorRenderingRegistry.ModelProvider provider = ((ArmorProviderExtensions) stack.getItem()).fabric_getArmorModelProvider();
|
||||
|
||||
if (provider != null) {
|
||||
return provider.getArmorModel(entity, stack, slot, defaultModel);
|
||||
}
|
||||
}
|
||||
|
||||
return defaultModel;
|
||||
}
|
||||
|
||||
public static ResourceLocation getArmorTexture(
|
||||
LivingEntity entity,
|
||||
ItemStack stack,
|
||||
EquipmentSlot slot,
|
||||
boolean secondLayer,
|
||||
@Nullable String suffix,
|
||||
ResourceLocation defaultTexture
|
||||
) {
|
||||
if (!stack.isEmpty()) {
|
||||
ArmorRenderingRegistry.TextureProvider provider = ((ArmorProviderExtensions) stack.getItem()).fabric_getArmorTextureProvider();
|
||||
|
||||
if (provider != null) {
|
||||
return provider.getArmorTexture(entity, stack, slot, secondLayer, suffix, defaultTexture);
|
||||
}
|
||||
}
|
||||
|
||||
return defaultTexture;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,8 +22,6 @@
|
|||
package shadow.fabric.mixin.client.rendering;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.model.HumanoidModel;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.entity.RenderLayerParent;
|
||||
|
@ -34,6 +32,10 @@ import net.minecraft.world.entity.EquipmentSlot;
|
|||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ArmorItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
@ -51,69 +53,107 @@ import java.util.Objects;
|
|||
@Mixin(HumanoidArmorLayer.class)
|
||||
@Environment(EnvType.CLIENT)
|
||||
public abstract class MixinArmorFeatureRenderer extends RenderLayer {
|
||||
@Shadow
|
||||
@Final
|
||||
private static Map<String, ResourceLocation> ARMOR_LOCATION_CACHE;
|
||||
|
||||
public MixinArmorFeatureRenderer(RenderLayerParent context) {
|
||||
super(context);
|
||||
|
||||
}
|
||||
|
||||
@Unique
|
||||
private LivingEntity storedEntity;
|
||||
@Unique
|
||||
private EquipmentSlot storedSlot;
|
||||
|
||||
@Inject(method = "render", at = @At("HEAD"))
|
||||
private void storeEntity(PoseStack matrixStack, MultiBufferSource vertexConsumerProvider, int i, LivingEntity livingEntity, float f, float g, float h, float j, float k, float l, CallbackInfo ci) {
|
||||
// We store the living entity wearing the armor before we render
|
||||
this.storedEntity = livingEntity;
|
||||
}
|
||||
|
||||
@Inject(method = "renderArmorPiece", at = @At("HEAD"))
|
||||
private void storeSlot(PoseStack matrices, MultiBufferSource vertexConsumers, LivingEntity livingEntity, EquipmentSlot slot, int i, HumanoidModel bipedEntityModel, CallbackInfo ci) {
|
||||
// We store the current armor slot that is rendering before we render each armor piece
|
||||
this.storedSlot = slot;
|
||||
}
|
||||
|
||||
@Inject(method = "render", at = @At("RETURN"))
|
||||
private void removeStored(PoseStack matrixStack, MultiBufferSource vertexConsumerProvider, int i, LivingEntity livingEntity, float f, float g, float h, float j, float k, float l, CallbackInfo ci) {
|
||||
// We remove the stored data after we render
|
||||
this.storedEntity = null;
|
||||
this.storedSlot = null;
|
||||
}
|
||||
|
||||
@Inject(method = "getArmorModel", at = @At("RETURN"), cancellable = true)
|
||||
private void selectArmorModel(EquipmentSlot slot, CallbackInfoReturnable<HumanoidModel<LivingEntity>> cir) {
|
||||
ItemStack stack = storedEntity.getItemBySlot(slot);
|
||||
|
||||
HumanoidModel<LivingEntity> defaultModel = cir.getReturnValue();
|
||||
HumanoidModel<LivingEntity> model = ArmorRenderingRegistry.getArmorModel(
|
||||
storedEntity,
|
||||
stack,
|
||||
slot,
|
||||
defaultModel
|
||||
);
|
||||
|
||||
if (model != defaultModel) {
|
||||
cir.setReturnValue(model);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "getArmorLocation", at = @At(value = "INVOKE", target = "Ljava/util/Map;computeIfAbsent(Ljava/lang/Object;Ljava/util/function/Function;)Ljava/lang/Object;"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
private void getArmorTexture(ArmorItem armorItem, boolean secondLayer, /* @Nullable */ String suffix, CallbackInfoReturnable<ResourceLocation> cir, String vanillaIdentifier) {
|
||||
String texture = ArmorRenderingRegistry.getArmorTexture(
|
||||
storedEntity,
|
||||
storedEntity.getItemBySlot(storedSlot),
|
||||
storedSlot,
|
||||
secondLayer,
|
||||
suffix,
|
||||
new ResourceLocation(vanillaIdentifier)
|
||||
).toString();
|
||||
|
||||
if (!Objects.equals(texture, vanillaIdentifier)) {
|
||||
cir.setReturnValue(ARMOR_LOCATION_CACHE.computeIfAbsent(texture, ResourceLocation::new));
|
||||
}
|
||||
}
|
||||
@Shadow
|
||||
@Final
|
||||
private static Map<String, ResourceLocation> ARMOR_LOCATION_CACHE;
|
||||
|
||||
public MixinArmorFeatureRenderer(RenderLayerParent context) {
|
||||
super(context);
|
||||
|
||||
}
|
||||
|
||||
@Unique
|
||||
private LivingEntity storedEntity;
|
||||
@Unique
|
||||
private EquipmentSlot storedSlot;
|
||||
|
||||
@Inject(method = "render", at = @At("HEAD"))
|
||||
private void storeEntity(
|
||||
PoseStack matrixStack,
|
||||
MultiBufferSource vertexConsumerProvider,
|
||||
int i,
|
||||
LivingEntity livingEntity,
|
||||
float f,
|
||||
float g,
|
||||
float h,
|
||||
float j,
|
||||
float k,
|
||||
float l,
|
||||
CallbackInfo ci
|
||||
) {
|
||||
// We store the living entity wearing the armor before we render
|
||||
this.storedEntity = livingEntity;
|
||||
}
|
||||
|
||||
@Inject(method = "renderArmorPiece", at = @At("HEAD"))
|
||||
private void storeSlot(
|
||||
PoseStack matrices,
|
||||
MultiBufferSource vertexConsumers,
|
||||
LivingEntity livingEntity,
|
||||
EquipmentSlot slot,
|
||||
int i,
|
||||
HumanoidModel bipedEntityModel,
|
||||
CallbackInfo ci
|
||||
) {
|
||||
// We store the current armor slot that is rendering before we render each armor piece
|
||||
this.storedSlot = slot;
|
||||
}
|
||||
|
||||
@Inject(method = "render", at = @At("RETURN"))
|
||||
private void removeStored(
|
||||
PoseStack matrixStack,
|
||||
MultiBufferSource vertexConsumerProvider,
|
||||
int i,
|
||||
LivingEntity livingEntity,
|
||||
float f,
|
||||
float g,
|
||||
float h,
|
||||
float j,
|
||||
float k,
|
||||
float l,
|
||||
CallbackInfo ci
|
||||
) {
|
||||
// We remove the stored data after we render
|
||||
this.storedEntity = null;
|
||||
this.storedSlot = null;
|
||||
}
|
||||
|
||||
@Inject(method = "getArmorModel", at = @At("RETURN"), cancellable = true)
|
||||
private void selectArmorModel(EquipmentSlot slot, CallbackInfoReturnable<HumanoidModel<LivingEntity>> cir) {
|
||||
ItemStack stack = storedEntity.getItemBySlot(slot);
|
||||
|
||||
HumanoidModel<LivingEntity> defaultModel = cir.getReturnValue();
|
||||
HumanoidModel<LivingEntity> model = ArmorRenderingRegistry.getArmorModel(
|
||||
storedEntity,
|
||||
stack,
|
||||
slot,
|
||||
defaultModel
|
||||
);
|
||||
|
||||
if (model != defaultModel) {
|
||||
cir.setReturnValue(model);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "getArmorLocation", at = @At(value = "INVOKE", target = "Ljava/util/Map;computeIfAbsent(Ljava/lang/Object;Ljava/util/function/Function;)Ljava/lang/Object;"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
private void getArmorTexture(
|
||||
ArmorItem armorItem,
|
||||
boolean secondLayer, /* @Nullable */
|
||||
String suffix,
|
||||
CallbackInfoReturnable<ResourceLocation> cir,
|
||||
String vanillaIdentifier
|
||||
) {
|
||||
String texture = ArmorRenderingRegistry.getArmorTexture(
|
||||
storedEntity,
|
||||
storedEntity.getItemBySlot(storedSlot),
|
||||
storedSlot,
|
||||
secondLayer,
|
||||
suffix,
|
||||
new ResourceLocation(vanillaIdentifier)
|
||||
).toString();
|
||||
|
||||
if (!Objects.equals(texture, vanillaIdentifier)) {
|
||||
cir.setReturnValue(ARMOR_LOCATION_CACHE.computeIfAbsent(texture, ResourceLocation::new));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ package shadow.fabric.mixin.client.rendering;
|
|||
|
||||
|
||||
import net.minecraft.world.item.Item;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import shadow.fabric.api.client.rendering.v1.ArmorRenderingRegistry;
|
||||
|
@ -30,28 +31,28 @@ import shadow.fabric.impl.client.rendering.ArmorProviderExtensions;
|
|||
|
||||
@Mixin(Item.class)
|
||||
public class MixinItem implements ArmorProviderExtensions {
|
||||
@Unique
|
||||
private ArmorRenderingRegistry.ModelProvider armorModelProvider;
|
||||
@Unique
|
||||
private ArmorRenderingRegistry.TextureProvider armorTextureProvider;
|
||||
|
||||
@Override
|
||||
public ArmorRenderingRegistry.ModelProvider fabric_getArmorModelProvider() {
|
||||
return armorModelProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArmorRenderingRegistry.TextureProvider fabric_getArmorTextureProvider() {
|
||||
return armorTextureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fabric_setArmorModelProvider(ArmorRenderingRegistry.ModelProvider provider) {
|
||||
armorModelProvider = provider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fabric_setArmorTextureProvider(ArmorRenderingRegistry.TextureProvider provider) {
|
||||
armorTextureProvider = provider;
|
||||
}
|
||||
@Unique
|
||||
private ArmorRenderingRegistry.ModelProvider armorModelProvider;
|
||||
@Unique
|
||||
private ArmorRenderingRegistry.TextureProvider armorTextureProvider;
|
||||
|
||||
@Override
|
||||
public ArmorRenderingRegistry.ModelProvider fabric_getArmorModelProvider() {
|
||||
return armorModelProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArmorRenderingRegistry.TextureProvider fabric_getArmorTextureProvider() {
|
||||
return armorTextureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fabric_setArmorModelProvider(ArmorRenderingRegistry.ModelProvider provider) {
|
||||
armorModelProvider = provider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fabric_setArmorTextureProvider(ArmorRenderingRegistry.TextureProvider provider) {
|
||||
armorTextureProvider = provider;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue