[Change] Use Fabric ArmorRenderer for Crystalite Armor

This commit is contained in:
Frank 2023-06-10 22:33:38 +02:00
parent 634be67361
commit c36a68d158
10 changed files with 76 additions and 660 deletions

View file

@ -1,97 +0,0 @@
package org.betterx.betterend.item.model;
import org.betterx.betterend.item.CrystaliteArmor;
import org.betterx.betterend.registry.EndItems;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.player.AbstractClientPlayer;
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 net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import com.google.common.collect.Lists;
import shadow.fabric.api.client.rendering.v1.ArmorRenderingRegistry;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@Environment(EnvType.CLIENT)
public class CrystaliteArmorProvider implements ArmorRenderingRegistry.ModelProvider, ArmorRenderingRegistry.TextureProvider {
//TODO: find new registry
private final static ResourceLocation FIRST_LAYER = new ResourceLocation(
"textures/models/armor/crystalite_layer_1.png");
private final static ResourceLocation SECOND_LAYER = new ResourceLocation(
"textures/models/armor/crystalite_layer_2.png");
private final static CrystaliteHelmetModel HELMET_MODEL = CrystaliteHelmetModel.createModel(null);
private final static CrystaliteChestplateModel CHEST_MODEL = CrystaliteChestplateModel.createRegularModel(null);
private final static CrystaliteChestplateModel CHEST_MODEL_SLIM = CrystaliteChestplateModel.createThinModel(null);
private final static CrystaliteLeggingsModel LEGGINGS_MODEL = CrystaliteLeggingsModel.createModel(null);
private final static CrystaliteBootsModel BOOTS_MODEL = CrystaliteBootsModel.createModel(null);
//@Override
public @NotNull ResourceLocation getArmorTexture(
LivingEntity entity,
ItemStack stack,
EquipmentSlot slot,
boolean secondLayer,
@Nullable String suffix,
ResourceLocation defaultTexture
) {
if (!isStackValid(stack)) return defaultTexture;
if (secondLayer) return SECOND_LAYER;
return FIRST_LAYER;
}
//@Override
public @NotNull HumanoidModel<LivingEntity> getArmorModel(
LivingEntity entity,
ItemStack stack,
EquipmentSlot slot,
HumanoidModel<LivingEntity> defaultModel
) {
if (!isStackValid(stack)) return defaultModel;
switch (slot) {
case HEAD: {
return HELMET_MODEL;
}
case CHEST: {
if (entity instanceof AbstractClientPlayer && ((AbstractClientPlayer) entity).getModelName()
.equals("slim")) {
CHEST_MODEL_SLIM.copyPropertiesTo(defaultModel);
return CHEST_MODEL_SLIM;
}
CHEST_MODEL.copyPropertiesTo(defaultModel);
return CHEST_MODEL;
}
case LEGS: {
return LEGGINGS_MODEL;
}
case FEET: {
BOOTS_MODEL.copyPropertiesTo(defaultModel);
return BOOTS_MODEL;
}
default: {
return defaultModel;
}
}
}
public Iterable<Item> getRenderedItems() {
return Lists.newArrayList(
EndItems.CRYSTALITE_HELMET,
EndItems.CRYSTALITE_CHESTPLATE,
EndItems.CRYSTALITE_ELYTRA,
EndItems.CRYSTALITE_LEGGINGS,
EndItems.CRYSTALITE_BOOTS
);
}
private boolean isStackValid(ItemStack stack) {
return stack.getItem() instanceof CrystaliteArmor;
}
}

View file

@ -0,0 +1,65 @@
package org.betterx.betterend.item.model;
import org.betterx.bclib.client.render.HumanoidArmorRenderer;
import org.betterx.betterend.registry.EndItems;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.rendering.v1.ArmorRenderer;
import org.jetbrains.annotations.NotNull;
@Environment(EnvType.CLIENT)
public class CrystaliteArmorRenderer extends HumanoidArmorRenderer {
private final static ResourceLocation FIRST_LAYER = new ResourceLocation(
"textures/models/armor/crystalite_layer_1.png");
private final static ResourceLocation SECOND_LAYER = new ResourceLocation(
"textures/models/armor/crystalite_layer_2.png");
private final static CrystaliteHelmetModel HELMET_MODEL = CrystaliteHelmetModel.createModel(null);
private final static CrystaliteChestplateModel CHEST_MODEL = CrystaliteChestplateModel.createRegularModel(null);
private final static CrystaliteChestplateModel CHEST_MODEL_SLIM = CrystaliteChestplateModel.createThinModel(null);
private final static CrystaliteLeggingsModel LEGGINGS_MODEL = CrystaliteLeggingsModel.createModel(null);
private final static CrystaliteBootsModel BOOTS_MODEL = CrystaliteBootsModel.createModel(null);
private static CrystaliteArmorRenderer INSTANCE = null;
public static void register() {
if (INSTANCE == null) {
INSTANCE = new CrystaliteArmorRenderer();
ArmorRenderer.register(
INSTANCE,
EndItems.CRYSTALITE_HELMET,
EndItems.CRYSTALITE_CHESTPLATE,
EndItems.CRYSTALITE_ELYTRA,
EndItems.CRYSTALITE_LEGGINGS,
EndItems.CRYSTALITE_BOOTS
);
}
}
@NotNull
@Override
protected ResourceLocation getTextureForSlot(EquipmentSlot slot, boolean innerLayer) {
return innerLayer ? SECOND_LAYER : FIRST_LAYER;
}
@Override
protected HumanoidModel<LivingEntity> getModelForSlot(LivingEntity entity, EquipmentSlot slot) {
if (slot == EquipmentSlot.HEAD) return HELMET_MODEL;
if (slot == EquipmentSlot.LEGS) return LEGGINGS_MODEL;
if (slot == EquipmentSlot.FEET) return BOOTS_MODEL;
if (slot == EquipmentSlot.CHEST) {
if (entity instanceof AbstractClientPlayer acp && acp.getModelName().equals("slim")) {
return CHEST_MODEL_SLIM;
} else {
return CHEST_MODEL;
}
}
return null;
}
}

View file

@ -1,5 +1,6 @@
package org.betterx.betterend.item.model; package org.betterx.betterend.item.model;
import org.betterx.bclib.client.render.HumanoidArmorRenderer;
import org.betterx.betterend.registry.EndEntitiesRenders; import org.betterx.betterend.registry.EndEntitiesRenders;
import net.minecraft.client.model.HumanoidModel; import net.minecraft.client.model.HumanoidModel;
@ -14,7 +15,7 @@ import com.google.common.collect.Lists;
import java.util.Collections; import java.util.Collections;
public class CrystaliteBootsModel extends HumanoidModel<LivingEntity> { public class CrystaliteBootsModel extends HumanoidModel<LivingEntity> implements HumanoidArmorRenderer.CopyExtraState {
public ModelPart leftBoot; public ModelPart leftBoot;
public ModelPart rightBoot; public ModelPart rightBoot;
@ -66,8 +67,7 @@ public class CrystaliteBootsModel extends HumanoidModel<LivingEntity> {
} }
@Override @Override
public void copyPropertiesTo(HumanoidModel<LivingEntity> bipedEntityModel) { public void copyPropertiesFrom(HumanoidModel<LivingEntity> bipedEntityModel) {
super.copyPropertiesTo(bipedEntityModel);
this.leftBoot.copyFrom(leftLeg); this.leftBoot.copyFrom(leftLeg);
this.rightBoot.copyFrom(rightLeg); this.rightBoot.copyFrom(rightLeg);
} }

View file

@ -1,5 +1,6 @@
package org.betterx.betterend.item.model; package org.betterx.betterend.item.model;
import org.betterx.bclib.client.render.HumanoidArmorRenderer;
import org.betterx.betterend.registry.EndEntitiesRenders; import org.betterx.betterend.registry.EndEntitiesRenders;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
@ -17,7 +18,7 @@ import com.google.common.collect.Lists;
import java.util.Collections; import java.util.Collections;
public class CrystaliteChestplateModel extends HumanoidModel<LivingEntity> { public class CrystaliteChestplateModel extends HumanoidModel<LivingEntity> implements HumanoidArmorRenderer.CopyExtraState {
public ModelPart leftShoulder; public ModelPart leftShoulder;
public ModelPart rightShoulder; public ModelPart rightShoulder;
@ -119,13 +120,13 @@ public class CrystaliteChestplateModel extends HumanoidModel<LivingEntity> {
super(modelPart, RenderType::entityTranslucent); super(modelPart, RenderType::entityTranslucent);
this.thinArms = thinArms; this.thinArms = thinArms;
localBody = modelPart.getChild(PartNames.BODY); localBody = modelPart.getChild(PartNames.BODY);
leftShoulder = modelPart.getChild("leftShoulder"); this.leftShoulder = modelPart.getChild("leftShoulder");
rightShoulder = modelPart.getChild("rightShoulder"); this.rightShoulder = modelPart.getChild("rightShoulder");
} }
@Override @Override
public void copyPropertiesTo(HumanoidModel<LivingEntity> bipedEntityModel) { public void copyPropertiesFrom(HumanoidModel<LivingEntity> parentModel) {
super.copyPropertiesTo(bipedEntityModel);
this.leftShoulder.copyFrom(leftArm); this.leftShoulder.copyFrom(leftArm);
this.rightShoulder.copyFrom(rightArm); this.rightShoulder.copyFrom(rightArm);
} }

View file

@ -1,19 +1,13 @@
package org.betterx.betterend.registry; package org.betterx.betterend.registry;
import org.betterx.betterend.item.model.CrystaliteArmorProvider; import org.betterx.betterend.item.model.CrystaliteArmorRenderer;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import shadow.fabric.api.client.rendering.v1.ArmorRenderingRegistry;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class EndModelProviders { public class EndModelProviders {
public final static CrystaliteArmorProvider CRYSTALITE_PROVIDER = new CrystaliteArmorProvider();
public final static void register() { public final static void register() {
ArmorRenderingRegistry.registerModel(CRYSTALITE_PROVIDER, CRYSTALITE_PROVIDER.getRenderedItems()); CrystaliteArmorRenderer.register();
ArmorRenderingRegistry.registerTexture(CRYSTALITE_PROVIDER, CRYSTALITE_PROVIDER.getRenderedItems());
} }
} }

View file

@ -1,197 +0,0 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
This file is a refactor from fabric-api, based on the work of shedaniel.
*/
package shadow.fabric.api.client.rendering.v1;
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 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}.
*
* <p>This can be used to replace existing vanilla armor models and textures conditionally, however each {@link Item}
* instance can only allow one {@link ModelProvider} or {@link TextureProvider} respectively, causing potential conflicts
* with other mods if you replace the model or texture for vanilla items. Consider using a separate item instead.</p>
*
* <p>A custom model would probably also require a custom texture to go along it, the model will use the vanilla texture if it is undefined.</p>
*
* <p>Since armor textures identifier in vanilla is hardcoded to be in the {@code minecraft} namespace, this registry can also be
* used to use a custom namespace if desired.</p>
*/
@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
);
}
}

View file

@ -1,36 +0,0 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
This file is a refactor from fabric-api, based on the work of shedaniel.
*/
package shadow.fabric.impl.client.rendering;
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);
}

View file

@ -1,95 +0,0 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
This file is a refactor from fabric-api, based on the work of shedaniel.
*/
package shadow.fabric.impl.client.rendering;
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 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;
}
}

View file

@ -1,161 +0,0 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
This file is a refactor from fabric-api, based on the work of shedaniel.
*/
package shadow.fabric.mixin.client.rendering;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.RenderLayerParent;
import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer;
import net.minecraft.client.renderer.entity.layers.RenderLayer;
import net.minecraft.resources.ResourceLocation;
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;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import shadow.fabric.api.client.rendering.v1.ArmorRenderingRegistry;
import java.util.Map;
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 be_storedEntity;
@Unique
private EquipmentSlot be_storedSlot;
@Inject(method = "render", at = @At("HEAD"))
private void be_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.be_storedEntity = livingEntity;
}
@Inject(method = "renderArmorPiece", at = @At("HEAD"))
private void be_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.be_storedSlot = slot;
}
@Inject(method = "render", at = @At("RETURN"))
private void be_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.be_storedEntity = null;
this.be_storedSlot = null;
}
@Inject(method = "getArmorModel", at = @At("RETURN"), cancellable = true)
private void be_selectArmorModel(EquipmentSlot slot, CallbackInfoReturnable<HumanoidModel<LivingEntity>> cir) {
if (be_storedEntity != null) {
ItemStack stack = be_storedEntity.getItemBySlot(slot);
HumanoidModel<LivingEntity> defaultModel = cir.getReturnValue();
HumanoidModel<LivingEntity> model = ArmorRenderingRegistry.getArmorModel(
be_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 be_getArmorTexture(
ArmorItem armorItem,
boolean secondLayer, /* @Nullable */
String suffix,
CallbackInfoReturnable<ResourceLocation> cir,
String vanillaIdentifier
) {
String texture = ArmorRenderingRegistry.getArmorTexture(
be_storedEntity,
be_storedEntity.getItemBySlot(be_storedSlot),
be_storedSlot,
secondLayer,
suffix,
new ResourceLocation(vanillaIdentifier)
).toString();
if (!Objects.equals(texture, vanillaIdentifier)) {
cir.setReturnValue(ARMOR_LOCATION_CACHE.computeIfAbsent(texture, ResourceLocation::new));
}
}
}

View file

@ -1,58 +0,0 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
This file is a refactor from fabric-api, based on the work of shedaniel.
*/
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;
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;
}
}