Skip to content

Commit

Permalink
Fix glints on custom armor not rendering on all layers
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightMiner committed Feb 14, 2022
1 parent 39f7ebd commit 0c5e778
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.Model;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -61,6 +62,8 @@ public static Model getModel(ItemStack stack, EquipmentSlot slot, HumanoidModel<
private HumanoidModel<?> base;
private String material = "";
private boolean isLegs = false;
/** If true, applies the enchantment glint to extra layers */
private boolean hasGlint = false;
public PlateArmorModel() {
super(RenderType::entityCutoutNoCull);
}
Expand All @@ -70,7 +73,7 @@ public void renderToBuffer(PoseStack matrices, VertexConsumer bufferIn, int pack
if (this.base != null) {
base.renderToBuffer(matrices, bufferIn, packedLightIn, packedOverlayIn, red, green, blue, alpha);
if (!material.isEmpty() && ArmorModelHelper.buffer != null) {
VertexConsumer overlayBuffer = ArmorModelHelper.buffer.getBuffer(isLegs ? LEG_RENDER_CACHE.computeIfAbsent(material, LEG_GETTER) : ARMOR_RENDER_CACHE.computeIfAbsent(material, ARMOR_GETTER));
VertexConsumer overlayBuffer = ItemRenderer.getArmorFoilBuffer(ArmorModelHelper.buffer, isLegs ? LEG_RENDER_CACHE.computeIfAbsent(material, LEG_GETTER) : ARMOR_RENDER_CACHE.computeIfAbsent(material, ARMOR_GETTER), false, hasGlint);
base.renderToBuffer(matrices, overlayBuffer, packedLightIn, packedOverlayIn, red, green, blue, alpha);
}
}
Expand All @@ -84,5 +87,6 @@ private void setup(HumanoidModel<?> base, ItemStack stack, EquipmentSlot slot) {
material = ModifierUtil.getPersistentString(stack, TinkerModifiers.embellishment.getId());
}
isLegs = slot == EquipmentSlot.LEGS;
hasGlint = stack.hasFoil();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.client.model.Model;
import net.minecraft.client.model.geom.ModelLayers;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -54,6 +55,8 @@ public static Model getModel(LivingEntity living, ItemStack stack, HumanoidModel
private HumanoidModel<?> base;
/** Material name for rendering */
private String material = MaterialIds.enderslime.toString();
/** If true, applies the enchantment glint to extra layers */
private boolean hasGlint = false;

public SlimelytraArmorModel() {
super(RenderType::entityCutoutNoCull);
Expand All @@ -73,7 +76,7 @@ public void renderToBuffer(PoseStack matrixStackIn, VertexConsumer bufferIn, int
if (ArmorModelHelper.buffer != null) {
matrixStackIn.pushPose();
matrixStackIn.translate(0.0D, 0.0D, 0.125D);
VertexConsumer elytraBuffer = ArmorModelHelper.buffer.getBuffer(WING_RENDER_CACHE.computeIfAbsent(material, WING_GETTER));
VertexConsumer elytraBuffer = ItemRenderer.getArmorFoilBuffer(ArmorModelHelper.buffer, WING_RENDER_CACHE.computeIfAbsent(material, WING_GETTER), false, hasGlint);
getElytraModel().renderToBuffer(matrixStackIn, elytraBuffer, packedLightIn, packedOverlayIn, red, green, blue, alpha);
matrixStackIn.popPose();
}
Expand All @@ -87,5 +90,6 @@ private void setup(HumanoidModel<?> base, LivingEntity living, ItemStack stack)
elytraModel.setupAnim(living, 0, 0, 0, 0, 0);
ArmorModelHelper.copyProperties(base, elytraModel);
material = SlimesuitItem.getMaterial(stack);
hasGlint = stack.hasFoil();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.client.model.geom.EntityModelSet;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import slimeknights.mantle.data.ISafeManagerReloadListener;
Expand Down Expand Up @@ -52,6 +53,8 @@ public static Model getModel(ItemStack stack, HumanoidModel<?> baseModel) {
/** Texture for the head */
@Nullable
private SkullModelBase headModel;
/** If true, applies the enchantment glint to extra layers */
private boolean hasGlint = false;

private SlimeskullArmorModel() {
super(RenderType::entityCutoutNoCull);
Expand All @@ -67,7 +70,7 @@ public void renderToBuffer(PoseStack matrixStackIn, VertexConsumer vertexBuilder
matrixStackIn.popPose();

if (headModel != null && headTexture != null && ArmorModelHelper.buffer != null) {
VertexConsumer headBuilder = ArmorModelHelper.buffer.getBuffer(RenderType.entityCutoutNoCullZOffset(headTexture));
VertexConsumer headBuilder = ItemRenderer.getArmorFoilBuffer(ArmorModelHelper.buffer, RenderType.entityCutoutNoCullZOffset(headTexture), false, hasGlint);
boolean needsPush = base.young || base.crouching;
if (needsPush) {
matrixStackIn.pushPose();
Expand All @@ -91,6 +94,7 @@ public void renderToBuffer(PoseStack matrixStackIn, VertexConsumer vertexBuilder
/** Called before the model is rendered to set the base model and the tool stack data */
private void setup(HumanoidModel<?> base, ItemStack stack) {
this.base = base;
this.hasGlint = stack.hasFoil();
MaterialId materialId = MaterialIdNBT.from(stack).getMaterial(0).getId();
if (!materialId.equals(IMaterial.UNKNOWN_ID)) {
SkullModelBase model = getHeadModel(materialId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.Model;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -34,6 +35,8 @@ public static Model getModel(ItemStack stack, EquipmentSlot slot, HumanoidModel<
private HumanoidModel<?> base;
private int color = -1;
private boolean isLegs = false;
/** If true, applies the enchantment glint to extra layers */
private boolean hasGlint = false;
public TravelersGearModel() {
super(RenderType::entityCutoutNoCull);
}
Expand All @@ -46,7 +49,7 @@ public void renderToBuffer(PoseStack matrices, VertexConsumer bufferIn, int pack
float newRed = (float)(color >> 16 & 255) / 255.0F;
float newGreen = (float)(color >> 8 & 255) / 255.0F;
float newBlue = (float)(color & 255) / 255.0F;
VertexConsumer overlayBuffer = ArmorModelHelper.buffer.getBuffer(RenderType.entityCutoutNoCullZOffset(isLegs ? OVERLAY_LEGS : OVERLAY_ARMOR));
VertexConsumer overlayBuffer = ItemRenderer.getArmorFoilBuffer(ArmorModelHelper.buffer, RenderType.entityCutoutNoCullZOffset(isLegs ? OVERLAY_LEGS : OVERLAY_ARMOR), false, hasGlint);
base.renderToBuffer(matrices, overlayBuffer, packedLightIn, packedOverlayIn, red * newRed, green * newGreen, blue * newBlue, alpha);
}
}
Expand All @@ -56,5 +59,6 @@ private void setup(HumanoidModel<?> base, ItemStack stack, EquipmentSlot slot) {
this.base = base;
color = ModifierUtil.getPersistentInt(stack, TinkerModifiers.dyed.getId(), -1);
isLegs = slot == EquipmentSlot.LEGS;
hasGlint = stack.hasFoil();
}
}

0 comments on commit 0c5e778

Please sign in to comment.