Skip to content

Commit

Permalink
streamlined 3d skin layer support and dropped 1.20.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Traben-0 committed Dec 8, 2023
1 parent b47be64 commit 9760879
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 218 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,18 @@
import dev.tr7zw.skinlayers.accessor.PlayerEntityModelAccessor;
import dev.tr7zw.skinlayers.accessor.PlayerSettings;
import dev.tr7zw.skinlayers.api.Mesh;
import dev.tr7zw.skinlayers.renderlayers.BodyLayerFeatureRenderer;
import dev.tr7zw.skinlayers.renderlayers.HeadLayerFeatureRenderer;
import net.minecraft.client.model.ModelPart;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.entity.PlayerEntityRenderer;
import net.minecraft.client.render.entity.PlayerModelPart;
import net.minecraft.client.render.entity.feature.FeatureRenderer;
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
import net.minecraft.client.render.entity.model.PlayerEntityModel;
import net.minecraft.client.util.math.MatrixStack;
import traben.entity_texture_features.utils.ETFUtils2;

// compatibility class for the wonderful 3D skin layers mod by @tr9zw to utilise ETF skin features
public abstract class ETF3DSkinLayersUtil {
// method is called from MixinLivingEntityRenderer as a super of the playerEntityRenderer
//
// method is handled in this class separately to prevent any loading attempt of 3D skin layer mod classes without the mod being present
//
// this appears to be the easiest way to add to the 3D skin layer mod's featureRenderers while also utilising
// the mods code to do all the setup required for correct rendering
//
// this method is future-proof only with the expectation that the 2 ETF3D featureRenderer's inheritance remains valid

// checks whether the provided featureRenderer is one of the 3D skin layer feature renderers
public static boolean canReplace(FeatureRenderer<?, ?> feature) {
return feature instanceof BodyLayerFeatureRenderer || feature instanceof HeadLayerFeatureRenderer;
}

// returns a replacement ETF child featureRenderer of the 3D skin layer featureRenderer
public static FeatureRenderer<?, ?> getReplacement(FeatureRenderer<?, ?> feature, FeatureRendererContext<?, ?> context) {
try {
if (feature instanceof HeadLayerFeatureRenderer) {
//noinspection unchecked
return new ETF3DHeadLayerFeatureRenderer((FeatureRendererContext<AbstractClientPlayerEntity, PlayerEntityModel<AbstractClientPlayerEntity>>) context);
} else if (feature instanceof BodyLayerFeatureRenderer) {
//noinspection unchecked
return new ETF3DBodyLayerFeatureRenderer((FeatureRendererContext<AbstractClientPlayerEntity, PlayerEntityModel<AbstractClientPlayerEntity>>) context);
}
} catch (Exception e) {
ETFUtils2.logWarn("Exception with ETF's 3D skin layers mod compatibility: " + e);
}
ETFUtils2.logError("Failed in ETF's 3D skin layers mod compatibility.");
return feature;
}

// todo ensure rendering method is kept up to date with how 3D skin layers mod does it
// copy of 3D skin layers hand rendering code as ETF needs to be able to render it at will with a custom VertexConsumer
Expand Down Expand Up @@ -105,12 +71,4 @@ public static void renderHand(PlayerEntityRenderer instance, MatrixStack poseSta
}


// initial testing method
// public static void tryRenderWithETFFeatures(FeatureRendererContext<AbstractClientPlayerEntity, PlayerEntityModel<AbstractClientPlayerEntity>> context, FeatureRenderer featureRenderer, AbstractClientPlayerEntity entity, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, float k, float m, float l, float n, float o) {
// if (featureRenderer instanceof HeadLayerFeatureRenderer) {
// new ETF3DHeadLayerFeatureRenderer<LivingEntity, EntityModel<T>>(context).render(matrixStack, vertexConsumerProvider, i, entity, o, n, g, l, k, m);
// } else if (featureRenderer instanceof BodyLayerFeatureRenderer) {
// new ETF3DBodyLayerFeatureRenderer(context).render(matrixStack, vertexConsumerProvider, i, entity, o, n, g, l, k, m);
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
import traben.entity_texture_features.ETFClientCommon;
import traben.entity_texture_features.features.ETFManager;
import traben.entity_texture_features.features.ETFRenderContext;
import traben.entity_texture_features.mixin.mods.MixinModelPartSodium;

/**
* this method figures out if a {@link ModelPart} is the top level of the children tree being rendered,
* then applies overlay rendering like emissives and enchanted pixels.
* <p>
* this is copied in {@link MixinModelPartSodium} for sodium's alternative model part render method.
* <p>
* the priority is required so this method will never mixin before sodium.
* the priority is set so this method will never run before sodium cancels the vanilla rendering code.
*/
@Mixin(value = ModelPart.class, priority = 99999999)
@Mixin(value = ModelPart.class, priority = 2000)
public abstract class MixinModelPart {
@Shadow
public abstract void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.LivingEntityRenderer;
import net.minecraft.client.render.entity.feature.FeatureRenderer;
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.util.math.MatrixStack;
Expand All @@ -13,15 +12,9 @@
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.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import traben.entity_texture_features.ETFClientCommon;
import traben.entity_texture_features.compat.ETF3DSkinLayersUtil;
import traben.entity_texture_features.features.ETFRenderContext;
import traben.entity_texture_features.utils.ETFEntity;
import traben.entity_texture_features.utils.ETFUtils2;

import static traben.entity_texture_features.ETFClientCommon.ETFConfigData;


@Mixin(LivingEntityRenderer.class)
Expand Down Expand Up @@ -59,28 +52,6 @@ protected MixinLivingEntityRenderer(EntityRendererFactory.Context ctx) {
ETFRenderContext.setRenderingFeatures(false);
}

@ModifyArg(method = "addFeature", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z"), index = 0)
private Object etf$3dSkinLayerCompat(Object featureRenderer) {
// replace 3d skin layers mod feature renderers with ETF's child versions

try {
// handler class is only ever accessed if the mod is present
// prevents NoClassDefFoundError
if (ETFClientCommon.SKIN_LAYERS_DETECTED
&& ETFConfigData.use3DSkinLayerPatch
&& ETF3DSkinLayersUtil.canReplace((FeatureRenderer<?, ?>) featureRenderer)) {
return ETF3DSkinLayersUtil.getReplacement((FeatureRenderer<?, ?>) featureRenderer, this);
}
} catch (Exception e) {
ETFUtils2.logWarn("Exception with ETF's 3D skin layers mod compatibility: " + e);
} catch (NoClassDefFoundError error) {
// Should never be thrown
// unless a significant change in 3d skin layers mod
ETFUtils2.logError("Error with ETF's 3D skin layers mod compatibility: " + error);
}

return featureRenderer;
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import traben.entity_texture_features.ETFClientCommon;
import traben.entity_texture_features.ETFVersionDifferenceHandler;
import traben.entity_texture_features.compat.ETF3DSkinLayersUtil;
import traben.entity_texture_features.features.ETFManager;
import traben.entity_texture_features.features.ETFRenderContext;
Expand Down Expand Up @@ -57,20 +56,20 @@ public MixinPlayerEntityRenderer(EntityRendererFactory.Context ctx, PlayerEntity
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/model/PlayerEntityModel;setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
shift = At.Shift.AFTER), cancellable = true)
private void etf$redirectNicely(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, AbstractClientPlayerEntity player, ModelPart arm, ModelPart sleeve, CallbackInfo ci) {
arm.pitch = 0.0F;
sleeve.pitch = 0.0F;

if (ETFConfigData.skinFeaturesEnabled) {
ETFPlayerTexture thisETFPlayerTexture = ETFManager.getInstance().getPlayerTexture(player, player.getSkinTextures().texture());
if (thisETFPlayerTexture != null) {
if (thisETFPlayerTexture != null && thisETFPlayerTexture.hasFeatures) {
Identifier etfTexture = thisETFPlayerTexture.getBaseTextureIdentifierOrNullForVanilla(player);
if (etfTexture != null) {
ETFRenderContext.preventRenderLayerTextureModify();

arm.pitch = 0.0F;
sleeve.pitch = 0.0F;

VertexConsumer vc1 = vertexConsumers.getBuffer(RenderLayer.getEntityTranslucent(etfTexture));
arm.render(matrices, vc1, light, OverlayTexture.DEFAULT_UV);
sleeve.render(matrices, vc1, light, OverlayTexture.DEFAULT_UV);
if (ETFVersionDifferenceHandler.isThisModLoaded("skinlayers") || ETFVersionDifferenceHandler.isThisModLoaded("skinlayers3d")) {
if (ETFClientCommon.SKIN_LAYERS_DETECTED) {
try {
// handler class is only ever accessed if the mod is present
// prevents NoClassDefFoundError
Expand All @@ -92,7 +91,7 @@ public MixinPlayerEntityRenderer(EntityRendererFactory.Context ctx, PlayerEntity
arm.render(matrices, vc2, ETFClientCommon.EMISSIVE_FEATURE_LIGHT_VALUE, OverlayTexture.DEFAULT_UV);
sleeve.render(matrices, vc2, ETFClientCommon.EMISSIVE_FEATURE_LIGHT_VALUE, OverlayTexture.DEFAULT_UV);
ETFRenderContext.endSpecialRenderOverlayPhase();
if (ETFVersionDifferenceHandler.isThisModLoaded("skinlayers") || ETFVersionDifferenceHandler.isThisModLoaded("skinlayers3d")) {
if (ETFClientCommon.SKIN_LAYERS_DETECTED) {
try {
// handler class is only ever accessed if the mod is present
// prevents NoClassDefFoundError
Expand All @@ -112,7 +111,7 @@ public MixinPlayerEntityRenderer(EntityRendererFactory.Context ctx, PlayerEntity
VertexConsumer vc3 = ItemRenderer.getArmorGlintConsumer(vertexConsumers, RenderLayer.getArmorCutoutNoCull(thisETFPlayerTexture.baseEnchantIdentifier), false, true);
arm.render(matrices, vc3, light, OverlayTexture.DEFAULT_UV);
sleeve.render(matrices, vc3, light, OverlayTexture.DEFAULT_UV);
if (ETFVersionDifferenceHandler.isThisModLoaded("skinlayers") || ETFVersionDifferenceHandler.isThisModLoaded("skinlayers3d")) {
if (ETFClientCommon.SKIN_LAYERS_DETECTED) {
try {
// handler class is only ever accessed if the mod is present
// prevents NoClassDefFoundError
Expand Down
Loading

0 comments on commit 9760879

Please sign in to comment.