SuperMartijn642 / Rechiseled

12 stars 13 forks source link

[Bug] Chisels & Bits incompatability #9

Closed MattB70 closed 1 year ago

MattB70 commented 2 years ago

Version Info

Description of the Bug Using Chisels and Bits on a Rechiseled block now creates a texture bug. This issue is caused by the update to Chisels and Bits, but only occurs to blocks provided by this mod. This issue has halted progress on my projects. This should be reproducible.

Steps to Reproduce Install: image Use Chisels and Bits on a Rechiseled block.

Screenshots image

marchermans commented 2 years ago

Hit me up when you want to look into this, and we will check it out together. @SuperMartijn642

SuperMartijn642 commented 2 years ago

I am currently busy with exams, so might be a bit before I have time to properly fix things.

From an initial look, the issue seems to come from ChiseledBlockBakedModel in Chisels & Bits assuming that a quad always uses the full texture. This can be confirmed by using a model which uses only a part of the texture. For example, create a resource pack with the following model for models/block/cobblestone.json:

{
  "parent": "block/block",
  "textures": {
    "particle": "#all",
    "all": "minecraft:block/cobblestone"
  },
  "elements": [
    {   "from": [ 0, 0, 0 ],
      "to": [ 16, 16, 16 ],
      "faces": {
        "down":  { "uv": [ 0, 0, 8, 8 ], "texture": "#all", "cullface": "down" },
        "up":    { "uv": [ 0, 0, 8, 8 ], "texture": "#all", "cullface": "up" },
        "north": { "uv": [ 0, 0, 8, 8 ], "texture": "#all", "cullface": "north" },
        "south": { "uv": [ 0, 0, 8, 8 ], "texture": "#all", "cullface": "south" },
        "west":  { "uv": [ 0, 0, 8, 8 ], "texture": "#all", "cullface": "west" },
        "east":  { "uv": [ 0, 0, 8, 8 ], "texture": "#all", "cullface": "east" }
      }
    }
  ]
}

Note the uv part for the faces to make it so the cobble only uses 1/4th of its texture. This leads to following visuals in game: image On the left is a regular cobblestone block and on the right is a cobblestone block with one bit missing. As you can see the right block has the same issue as the blocks from Rechiseled. This example occurs with just Chisels & Bits installed.

The assumption made by Chisels & Bits is most easily visible in BitBlockBakedModel. The getFaceUvs method always returns values 7 and 8.

private float[] getFaceUvs(final Direction face)
{
        ...
        final int from_x = 7;
        final int from_y = 7;
        final int from_z = 7;

        final int to_x = 8;
        final int to_y = 8;
        final int to_z = 8;
        ...
}

These values are then directly used by the following line in its constructor as the uv values for the texture.

generic.add(faceBakery.bakeQuad(toB, fromB, bpf, quadLayer.getSprite(), myFace, mr, null, false, new ResourceLocation(Constants.MOD_ID, "bit")));

Here the uv values from the original quad are ignored. Basically, it will always take 7/16th and 8/16th of the entire texture instead of 7/16th and 8/16th of the uv values specified by the original quad.

ChiseledBlockBakedModel has the same issue, where it ignores the uv values from the original quad.

marchermans commented 2 years ago

I am currently busy with exams, so might be a bit before I have time to properly fix things.

From an initial look, the issue seems to come from ChiseledBlockBakedModel in Chisels & Bits assuming that a quad always uses the full texture. This can be confirmed by using a model which uses only a part of the texture. For example, create a resource pack with the following model for models/block/cobblestone.json:

{
  "parent": "block/block",
  "textures": {
    "particle": "#all",
    "all": "minecraft:block/cobblestone"
  },
  "elements": [
    {   "from": [ 0, 0, 0 ],
      "to": [ 16, 16, 16 ],
      "faces": {
        "down":  { "uv": [ 0, 0, 8, 8 ], "texture": "#all", "cullface": "down" },
        "up":    { "uv": [ 0, 0, 8, 8 ], "texture": "#all", "cullface": "up" },
        "north": { "uv": [ 0, 0, 8, 8 ], "texture": "#all", "cullface": "north" },
        "south": { "uv": [ 0, 0, 8, 8 ], "texture": "#all", "cullface": "south" },
        "west":  { "uv": [ 0, 0, 8, 8 ], "texture": "#all", "cullface": "west" },
        "east":  { "uv": [ 0, 0, 8, 8 ], "texture": "#all", "cullface": "east" }
      }
    }
  ]
}

Note the uv part for the faces to make it so the cobble only uses 1/4th of its texture. This leads to following visuals in game: image On the left is a regular cobblestone block and on the right is a cobblestone block with one bit missing. As you can see the right block has the same issue as the blocks from Rechiseled. This example occurs with just Chisels & Bits installed.

The assumption made by Chisels & Bits is most easily visible in BitBlockBakedModel. The getFaceUvs method always returns values 7 and 8.

private float[] getFaceUvs(final Direction face)
{
        ...
        final int from_x = 7;
        final int from_y = 7;
        final int from_z = 7;

        final int to_x = 8;
        final int to_y = 8;
        final int to_z = 8;
        ...
}

These values are then directly used by the following line in its constructor as the uv values for the texture.

generic.add(faceBakery.bakeQuad(toB, fromB, bpf, quadLayer.getSprite(), myFace, mr, null, false, new ResourceLocation(Constants.MOD_ID, "bit")));

Here the uv values from the original quad are ignored. Basically, it will always take 7/16th and 8/16th of the entire texture instead of 7/16th and 8/16th of the uv values specified by the original quad.

ChiseledBlockBakedModel has the same issue, where it ignores the uv values from the original quad.

That is a weird behaviour... Cause i extract the UVs from the BakedQuad and then interpolate. I will investigate....

marchermans commented 2 years ago

Found the bug. I payed attention to not make that assumption, but still did in one particular case.... Sadface panda.

Will push an update.

SuperMartijn642 commented 2 years ago

I payed attention to not make that assumption, but still did in one particular case.... Sadface panda.

I can definitely relate to that feeling xD

Also, not entirely sure if this is the reason it broke with Rechiseled, since the effect did look a bit different. Might still just be some jank with Rechiseled's baked model, but I guess I'll have to see.

marchermans commented 2 years ago

No clue, the effect happens because it fails to properly interpolate. @MattB70 Can you retest with the latest version of C&B so we could potentially close this issue?

MattB70 commented 2 years ago

Fixed!

I also noticed the reduced quads being drawn on the inside of blocks. Awesome changes, thanks :)

MattB70 commented 2 years ago

I spoke too soon.

It still happens but much less frequently. Now it seems to only occur on 1/4 sized blocks or smaller. Attached are some examples.

1/4 sized blocks are bugged, also note how some of them are not in the flickering state but are distorted such as the textures towards the bottom of the image. image

Again, some render distorted while others render with flickering banding. image

Here you can see how any block with 1/4 or smaller sized faces are distorted, such as the raised floor beneath this table. image

marchermans commented 2 years ago
{
  "parent": "block/block",
  "textures": {
    "particle": "#all",
    "all": "minecraft:block/cobblestone"
  },
  "elements": [
    {   "from": [ 0, 0, 0 ],
      "to": [ 16, 16, 16 ],
      "faces": {
        "down":  { "uv": [ 0, 0, 8, 8 ], "texture": "#all", "cullface": "down" },
        "up":    { "uv": [ 0, 0, 8, 8 ], "texture": "#all", "cullface": "up" },
        "north": { "uv": [ 0, 0, 8, 8 ], "texture": "#all", "cullface": "north" },
        "south": { "uv": [ 0, 0, 8, 8 ], "texture": "#all", "cullface": "south" },
        "west":  { "uv": [ 0, 0, 8, 8 ], "texture": "#all", "cullface": "west" },
        "east":  { "uv": [ 0, 0, 8, 8 ], "texture": "#all", "cullface": "east" }
      }
    }
  ]
}

I can't reproduce this anymore on my side: image

These are the 1/4, 1/8 and single bits, with the model from @SuperMartijn642 from above, as you can see no visual artifacts are visible.

Not sure what the cause here is then now.

That artifact which you see occurs if C&B is not able to properly detect the corners of the texture and then assigns two vertexes of a face the same value. But I am not sure what the cause is now.

MattB70 commented 2 years ago

My environment (forge 40.1.54): image

Result: image

The behavior here makes me think it may be related to the new culling of hidden faces, but I can't be sure. I'm also not sure why it seems to not happen for you. Is there a version mismatch somewhere in my environment?

SuperMartijn642 commented 2 years ago

Note that OrionDevelopment was talking about the vannilla example now working correctly. The issues you're experiencing still, MattB70, are specifically Rechiseled. Probably just something weird caused by Rechiseled's baked models, but I'll have to look into it when I have more time.

SuperMartijn642 commented 2 years ago

@OrionDevelopment still seems to be some weirdness going on with the vanilla example when removing certain bits. Although not entirely sure what problem is this time from looking at the code.

https://user-images.githubusercontent.com/12382965/177758953-1c887277-e906-4b2a-a82f-686991002763.mp4

marchermans commented 2 years ago

Okey.... More I need to debug there still seems to be a corner case where UVs are not properly extracted from their source and interpolated properly.