调整渲染方式,但还是有问题

This commit is contained in:
17146 2025-05-16 20:28:13 +08:00 committed by Light_Quanta
parent a4ed82306e
commit 9953409288
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959

View file

@ -6,10 +6,12 @@ import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.world.item.Item;
import org.joml.Matrix4f;
import software.bernie.geckolib.animatable.GeoAnimatable;
import software.bernie.geckolib.cache.object.GeoBone;
import software.bernie.geckolib.model.GeoModel;
import software.bernie.geckolib.renderer.GeoItemRenderer;
import software.bernie.geckolib.util.RenderUtil;
public class CustomRenderer<T extends Item & GeoAnimatable> extends GeoItemRenderer<T> {
@ -18,17 +20,33 @@ public class CustomRenderer<T extends Item & GeoAnimatable> extends GeoItemRende
}
@Override
public void renderChildBones(PoseStack poseStack, T animatable, GeoBone bone, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, boolean isReRender, float partialTick, int packedLight, int packedOverlay, int color) {
if (bone.isHidingChildren())
return;
public void renderRecursively(PoseStack poseStack, T animatable, GeoBone bone, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, boolean isReRender, float partialTick, int packedLight, int packedOverlay, int color) {
if (bone.isTrackingMatrices()) {
Matrix4f poseState = new Matrix4f(poseStack.last().pose());
for (GeoBone childBone : bone.getChildBones()) {
if (childBone.getName().endsWith("_illuminated")) {
var type = ModRenderTypes.GUN_ILLUMINATED.apply(this.getTextureLocation(animatable));
renderRecursively(poseStack, animatable, childBone, type, bufferSource, bufferSource.getBuffer(type), isReRender, partialTick, packedLight, OverlayTexture.NO_OVERLAY, 0xFFFFFFFF);
} else {
renderRecursively(poseStack, animatable, childBone, renderType, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, color);
}
bone.setModelSpaceMatrix(RenderUtil.invertAndMultiplyMatrices(poseState, this.modelRenderTranslations));
bone.setLocalSpaceMatrix(RenderUtil.invertAndMultiplyMatrices(poseState, this.itemRenderTranslations));
}
poseStack.pushPose();
RenderUtil.prepMatrixForBone(poseStack, bone);
// TODO 为什么会出现全部发光
// 我感觉这个地方已经查明了对于指定后缀名group的全部cube并且传入一个魔改后的buffer来实现发光渲染后续用的buffer都是之前的内容理论上不会影响递归调用啊
var bf = buffer;
var overlay = packedOverlay;
if (bone.getName().endsWith("_illuminated")) {
bf = bufferSource.getBuffer(ModRenderTypes.GUN_ILLUMINATED.apply(this.getTextureLocation(animatable)));
overlay = OverlayTexture.NO_OVERLAY;
}
renderCubesOfBone(poseStack, bone, bf, packedLight, overlay, color);
if (!isReRender) {
applyRenderLayersForBone(poseStack, animatable, bone, renderType, bufferSource, buffer, partialTick, packedLight, packedOverlay);
}
renderChildBones(poseStack, animatable, bone, renderType, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, color);
poseStack.popPose();
}
}