Проблема рендера предмета в слое

Версия Minecraft
1.12+
API
Forge
106
3
7
Все ок если не держать ничего в руках или держать обычный предмет, но если держать предмет с кастомной TEISR то возникает такой баг.

Код слоя:
Код:
public class LayerMask implements LayerRenderer<EntityPlayer> {

    @Override
    public void doRenderLayer(EntityPlayer player, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale) {

        PersonStats stats = EventsHandler.getCapaMP(player).personStats();

        Item mask = stats.getInventory().getStackInSlot(0).getItem();

        if (mask != Items.AIR) {

            RenderPlayer renderPlayer = Minecraft.getMinecraft().getRenderManager().getSkinMap().get(((AbstractClientPlayer)player).getSkinType());
            GlStateManager.pushMatrix();
            GlStateManager.disableLighting();

            renderPlayer.getMainModel().bipedHead.postRender(0.0625F);

            GlStateManager.translate(0, (player.isSneaking() ? 0.2F : 0.0F) + 0.1875F, -0.045F);
            GlStateManager.rotate(180, 0, 0, 0);
            GlStateManager.scale(0.5F, 0.5F, 0.5F);

            Minecraft.getMinecraft().getRenderItem().renderItem(new ItemStack(mask), player, ItemCameraTransforms.TransformType.HEAD, true);

            GlStateManager.popMatrix();

        }
    }

    @Override
    public boolean shouldCombineTextures() {
        return true;
    }
}

shouldCombineTextures пробовал менять но это ни на что не влияет
 

Вложения

  • 2022-02-04_13.54.53.png
    2022-02-04_13.54.53.png
    51.8 KB · Просмотры: 22
  • 2022-02-04_13.55.01.png
    2022-02-04_13.55.01.png
    53.4 KB · Просмотры: 22
7,099
324
1,510
Скинь код TEIST, он задает какое-то состояние, которое сохраняется до рендера слоя и которое нужно восстановить
 
106
3
7
У меня он от геколиб работает
Код:
public abstract class GeoItemRenderer<T extends Item & IAnimatable> extends TileEntityItemStackRenderer implements IGeoRenderer<T>
{
   // Register a model fetcher for this renderer
   static
   {
      AnimationController.addModelFetcher((IAnimatable object) ->
      {
         if (object instanceof Item)
         {
            Item item = (Item) object;
            TileEntityItemStackRenderer renderer = item.getTileEntityItemStackRenderer();
            if (renderer instanceof GeoItemRenderer)
            {
               return (IAnimatableModel<Object>) ((GeoItemRenderer<?>) renderer).getGeoModelProvider();
            }
         }
         return null;
      });
   }

   protected AnimatedGeoModel<T> modelProvider;
   protected ItemStack currentItemStack;
   public GeoItemRenderer(AnimatedGeoModel<T> modelProvider)
   {
      this.modelProvider = modelProvider;
   }

   public void setModel(AnimatedGeoModel<T> model)
   {
      this.modelProvider = model;
   }

   @Override
   public AnimatedGeoModel<T> getGeoModelProvider()
   {
      return modelProvider;
   }

   @Override
   public void renderByItem(ItemStack itemStack, float partialTicks)
   {
      this.render((T) itemStack.getItem(), itemStack);
   }

   public void render(T animatable, ItemStack itemStack)
   {
      this.currentItemStack = itemStack;
      GeoModel model = modelProvider.getModel(modelProvider.getModelLocation(animatable));
      AnimationEvent itemEvent = new AnimationEvent(animatable, 0, 0, Minecraft.getMinecraft().getRenderPartialTicks(), false, Collections.singletonList(itemStack));
      modelProvider.setLivingAnimations(animatable, this.getUniqueID(animatable), itemEvent);
      GlStateManager.pushMatrix();
      GlStateManager.translate(0, 0.01f, 0);
      GlStateManager.translate(0.5, 0.5, 0.5);

      Minecraft.getMinecraft().renderEngine.bindTexture(getTextureLocation(animatable));
      Color renderColor = getRenderColor(animatable, 0f);
      render(model, animatable, 0f, (float) renderColor.getRed() / 255f, (float) renderColor.getGreen() / 255f, (float) renderColor.getBlue() / 255f, (float) renderColor.getAlpha() / 255);
      GlStateManager.popMatrix();
   }

   @Override
   public ResourceLocation getTextureLocation(T instance)
   {
      return this.modelProvider.getTextureLocation(instance);
   }

   @Override
   public Integer getUniqueID(T animatable)
   {
      return Objects.hash(currentItemStack.getItem(), currentItemStack.getCount(), currentItemStack.hasTagCompound() ? currentItemStack.getTagCompound().toString() : 1);
   }
}

Регистр:
Код:
ModelLoader.setCustomModelResourceLocation(InitItems.HK33, 0, new ModelResourceLocation(Reference.MODID + ":assault_rifle_hk33.item", "inventory"));
InitItems.HK33.setTileEntityItemStackRenderer(new HK33Render());

Мой класс рендера
Код:
public class HK33Render extends GeoItemRenderer<HK33Item>
{
    public HK33Render()
    {
        super(new HK33Model());
    }
}

Есть еще мысль что возможно виноват метод рендера предмета, потому что в ванилле по другому это работает
 
7,099
324
1,510
106
3
7
Где эта функция? Скинь ее
Код:
default void render(GeoModel model, T animatable, float partialTicks, float red, float green, float blue, float alpha)
{
   GlStateManager.disableCull();
   GlStateManager.enableRescaleNormal();
   renderEarly(animatable, partialTicks, red, green, blue, alpha);

   renderLate(animatable, partialTicks, red, green, blue, alpha);

   BufferBuilder builder = Tessellator.getInstance().getBuffer();

   builder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR_NORMAL);

   //Render all top level bones
   for (GeoBone group : model.topLevelBones)
   {
      renderRecursively(builder, group, red, green, blue, alpha);
   }

   Tessellator.getInstance().draw();

   renderAfter(animatable, partialTicks, red, green, blue, alpha);
   GlStateManager.disableRescaleNormal();
   GlStateManager.enableCull();
}
 
106
3
7
Где эта функция? Скинь ее
Вот еще весь интерфейс оттуда с этой функцией:
Код:
public interface IGeoRenderer<T>
{
   public static MatrixStack MATRIX_STACK = new MatrixStack();

   default void render(GeoModel model, T animatable, float partialTicks, float red, float green, float blue, float alpha)
   {
      GlStateManager.disableCull();
      GlStateManager.enableRescaleNormal();
      renderEarly(animatable, partialTicks, red, green, blue, alpha);

      renderLate(animatable, partialTicks, red, green, blue, alpha);

      BufferBuilder builder = Tessellator.getInstance().getBuffer();

      builder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR_NORMAL);

      //Render all top level bones
      for (GeoBone group : model.topLevelBones)
      {
         renderRecursively(builder, group, red, green, blue, alpha);
      }

      Tessellator.getInstance().draw();

      renderAfter(animatable, partialTicks, red, green, blue, alpha);
      GlStateManager.disableRescaleNormal();
      GlStateManager.enableCull();
   }

   default void renderRecursively(BufferBuilder builder, GeoBone bone, float red, float green, float blue, float alpha)
   {
      MATRIX_STACK.push();

      MATRIX_STACK.translate(bone);
      MATRIX_STACK.moveToPivot(bone);
      MATRIX_STACK.rotate(bone);
      MATRIX_STACK.scale(bone);
      MATRIX_STACK.moveBackFromPivot(bone);

      if (!bone.isHidden)
      {
         for (GeoCube cube : bone.childCubes)
         {
            MATRIX_STACK.push();
            GlStateManager.pushMatrix();
            renderCube(builder, cube, red, green, blue, alpha);
            GlStateManager.popMatrix();
            MATRIX_STACK.pop();
         }
         for (GeoBone childBone : bone.childBones)
         {
            renderRecursively(builder, childBone, red, green, blue, alpha);
         }
      }

      MATRIX_STACK.pop();
   }

   default void renderCube(BufferBuilder builder, GeoCube cube, float red, float green, float blue, float alpha)
   {
      MATRIX_STACK.moveToPivot(cube);
      MATRIX_STACK.rotate(cube);
      MATRIX_STACK.moveBackFromPivot(cube);

      for (GeoQuad quad : cube.quads)
      {
         Vector3f normal = new Vector3f(quad.normal.getX(), quad.normal.getY(), quad.normal.getZ());

         MATRIX_STACK.getNormalMatrix().transform(normal);

         /* Fix shading dark shading for flat cubes + compatibility wish Optifine shaders */
         if ((cube.size.y == 0 || cube.size.z == 0) && normal.getX() < 0)
         {
            normal.x *= -1;
         }
         if ((cube.size.x == 0 || cube.size.z == 0) && normal.getY() < 0)
         {
            normal.y *= -1;
         }
         if ((cube.size.x == 0 || cube.size.y == 0) && normal.getZ() < 0)
         {
            normal.z *= -1;
         }

         for (GeoVertex vertex : quad.vertices)
         {
            Vector4f vector4f = new Vector4f(vertex.position.getX(), vertex.position.getY(), vertex.position.getZ(), 1.0F);

            MATRIX_STACK.getModelMatrix().transform(vector4f);

            builder.pos(vector4f.getX(), vector4f.getY(), vector4f.getZ()).tex(vertex.textureU, vertex.textureV).color(red, green, blue, alpha).normal(normal.getX(), normal.getY(), normal.getZ()).endVertex();
         }
      }
   }

   GeoModelProvider getGeoModelProvider();

   ResourceLocation getTextureLocation(T instance);

   default void renderEarly(T animatable, float ticks, float red, float green, float blue, float partialTicks)
   {
   }

   default void renderLate(T animatable, float ticks, float red, float green, float blue, float partialTicks)
   {
   }

   default void renderAfter(T animatable, float ticks, float red, float green, float blue, float partialTicks)
   {
   }

   default Color getRenderColor(T animatable, float partialTicks)
   {
      return new Color(255, 255, 255, 255);
   }

   default Integer getUniqueID(T animatable)
   {
      return animatable.hashCode();
   }
}

и MatrixStack
Код:
public class MatrixStack
{
   private Stack<Matrix4f> model = new Stack<Matrix4f>();
   private Stack<Matrix3f> normal = new Stack<Matrix3f>();

   private Matrix4f tempModelMatrix = new Matrix4f();
   private Matrix3f tempNormalMatrix = new Matrix3f();
   private float[] tempArray = new float[16];

   public MatrixStack()
   {
      Matrix4f model = new Matrix4f();
      Matrix3f normal = new Matrix3f();

      model.setIdentity();
      normal.setIdentity();

      this.model.add(model);
      this.normal.add(normal);
   }

   public Matrix4f getModelMatrix()
   {
      return this.model.peek();
   }

   public Matrix3f getNormalMatrix()
   {
      return this.normal.peek();
   }

   public void push()
   {
      this.model.add(new Matrix4f(this.model.peek()));
      this.normal.add(new Matrix3f(this.normal.peek()));
   }

   public void pop()
   {
      if (this.model.size() == 1)
      {
         throw new IllegalStateException("A one level stack can't be popped!");
      }

      this.model.pop();
      this.normal.pop();
   }

   /* Translate */

   public void translate(float x, float y, float z)
   {
      this.translate(new Vector3f(x, y, z));
   }

   public void translate(Vector3f vec)
   {
      this.tempModelMatrix.setIdentity();
      this.tempModelMatrix.setTranslation(vec);

      this.model.peek().mul(this.tempModelMatrix);
   }

   public void moveToPivot(GeoCube cube)
   {
      Vector3f pivot = cube.pivot;
      this.translate(pivot.getX() / 16, pivot.getY() / 16, pivot.getZ() / 16);
   }

   public void moveBackFromPivot(GeoCube cube)
   {
      Vector3f pivot = cube.pivot;
      this.translate(-pivot.getX() / 16, -pivot.getY() / 16, -pivot.getZ() / 16);
   }

   public void moveToPivot(GeoBone bone)
   {
      this.translate(bone.rotationPointX / 16, bone.rotationPointY / 16, bone.rotationPointZ / 16);
   }

   public void moveBackFromPivot(GeoBone bone)
   {
      this.translate(-bone.rotationPointX / 16, -bone.rotationPointY / 16, -bone.rotationPointZ / 16);
   }

   public void translate(GeoBone bone)
   {
      this.translate(-bone.getPositionX() / 16, bone.getPositionY() / 16, bone.getPositionZ() / 16);
   }

   /* Scale */

   public void scale(float x, float y, float z)
   {
      this.tempModelMatrix.setIdentity();
      this.tempModelMatrix.setM00(x);
      this.tempModelMatrix.setM11(y);
      this.tempModelMatrix.setM22(z);

      this.model.peek().mul(this.tempModelMatrix);

      if (x < 0 || y < 0 || z < 0)
      {
         this.tempNormalMatrix.setIdentity();
         this.tempNormalMatrix.setM00(x < 0 ? -1 : 1);
         this.tempNormalMatrix.setM11(y < 0 ? -1 : 1);
         this.tempNormalMatrix.setM22(z < 0 ? -1 : 1);

         this.normal.peek().mul(this.tempNormalMatrix);
      }
   }

   public void scale(GeoBone bone)
   {
      this.scale(bone.getScaleX(), bone.getScaleY(), bone.getScaleZ());
   }

   /* Rotate */

   public void rotateX(float radian)
   {
      this.tempModelMatrix.setIdentity();
      this.tempModelMatrix.rotX(radian);

      this.tempNormalMatrix.setIdentity();
      this.tempNormalMatrix.rotX(radian);

      this.model.peek().mul(this.tempModelMatrix);
      this.normal.peek().mul(this.tempNormalMatrix);
   }

   public void rotateY(float radian)
   {
      this.tempModelMatrix.setIdentity();
      this.tempModelMatrix.rotY(radian);

      this.tempNormalMatrix.setIdentity();
      this.tempNormalMatrix.rotY(radian);

      this.model.peek().mul(this.tempModelMatrix);
      this.normal.peek().mul(this.tempNormalMatrix);
   }

   public void rotateZ(float radian)
   {
      this.tempModelMatrix.setIdentity();
      this.tempModelMatrix.rotZ(radian);

      this.tempNormalMatrix.setIdentity();
      this.tempNormalMatrix.rotZ(radian);

      this.model.peek().mul(this.tempModelMatrix);
      this.normal.peek().mul(this.tempNormalMatrix);
   }

   public void rotate(GeoBone bone)
   {
      if (bone.getRotationZ() != 0.0F)
      {
         this.rotateZ(bone.getRotationZ());
      }

      if (bone.getRotationY() != 0.0F)
      {
         this.rotateY(bone.getRotationY());
      }

      if (bone.getRotationX() != 0.0F)
      {
         this.rotateX(bone.getRotationX());
      }
   }

   public void rotate(GeoCube bone)
   {
      Vector3f rotation = bone.rotation;
      Matrix4f matrix4f = new Matrix4f();
      Matrix3f matrix3f = new Matrix3f();

      this.tempModelMatrix.setIdentity();
      matrix4f.rotZ(rotation.getZ());
      this.tempModelMatrix.mul(matrix4f);

      matrix4f.rotY(rotation.getY());
      this.tempModelMatrix.mul(matrix4f);

      matrix4f.rotX(rotation.getX());
      this.tempModelMatrix.mul(matrix4f);

      this.tempNormalMatrix.setIdentity();
      matrix3f.rotZ(rotation.getZ());
      this.tempNormalMatrix.mul(matrix3f);

      matrix3f.rotY(rotation.getY());
      this.tempNormalMatrix.mul(matrix3f);

      matrix3f.rotX(rotation.getX());
      this.tempNormalMatrix.mul(matrix3f);

      this.model.peek().mul(this.tempModelMatrix);
      this.normal.peek().mul(this.tempNormalMatrix);
   }

   private Quaternion fromAngles(float x, float y, float z)
   {
      float sx = (float) Math.sin(0.5F * x);
      float cx = (float) Math.cos(0.5F * x);
      float sy = (float) Math.sin(0.5F * y);
      float cy = (float) Math.cos(0.5F * y);
      float sz = (float) Math.sin(0.5F * z);
      float cz = (float) Math.cos(0.5F * z);

      float ox = sx * cy * cz + cx * sy * sz;
      float oy = cx * sy * cz - sx * cy * sz;
      float oz = sx * sy * cz + cx * cy * sz;
      float ow = cx * cy * cz - sx * sy * sz;

      return new Quaternion(ox, oy, oz, ow);
   }
}
 
106
3
7
Где эта функция? Скинь ее
оказывается что проблема исчезает если сначала регистрировать слой с маской а потом слой с использованием geckolib (у меня есть еще слой из за которого так багуется), но я не знаю как изменить порядок регистрации LayerHeldItem в котором рендерится предмет из geckolib который багует слой с маской
 
Сверху