Voxelum / minecraft-launcher-core-node

Provide packages to install Minecraft, launch Minecraft and more to build launcher with NodeJs/Electron!
https://docs.xmcl.app/en/core/
MIT License
174 stars 25 forks source link

@xmcl/model giving an incorrect "block/cake" model #237

Closed John-Dean closed 1 year ago

John-Dean commented 2 years ago

Hi,

Managed to get @xmcl/model working (using @xmcl/resourcepack with the default minecraft resource pack) and I've run into an issue with cake.

To my knowledge this is the only block this happens to, but I get the following when pulling a model for block/cake: image

Other non-full blocks, such as block/oak_fence_gate have no issue: image

Here is a copy of cake.json, which looks correct to me (and was taken from the official client):

{
    "textures": {
        "particle": "block/cake_side",
        "bottom": "block/cake_bottom",
        "top": "block/cake_top",
        "side": "block/cake_side"
    },
    "elements": [
        {   "from": [ 1, 0, 1 ],
            "to": [ 15, 8, 15 ],
            "faces": {
                "down":  { "texture": "#bottom", "cullface": "down" },
                "up":    { "texture": "#top" },
                "north": { "texture": "#side" },
                "south": { "texture": "#side" },
                "west":  { "texture": "#side" },
                "east":  { "texture": "#side" }
            }
        }
    ]
}

Would anyone happen to know if this is an error on my part?

If needed I can provide code to replicate this.

Kind regards, John

ci010 commented 2 years ago

I'll investigate this issue this week

ci010 commented 2 years ago

I think this commit https://github.com/Voxelum/minecraft-launcher-core-node/commit/6917a7759731944af08c95b4e39a170fb07f9843 should fix the cake model issue (tested on my machine). If you have time, can you try to test other models? I'm not sure if there is issue on other models.

John-Dean commented 2 years ago

Thanks for this, I'll give this a test either today or tomorrow.

I've been writing a Minecraft world viewer using this repo to load the worlds/models and resource packs; I haven't run into this issue on any other model yet (including custom ones I've added).

I'll probably submit a PR with a couple of missing functions that I've had to add to get my use case working (for example you're missing a way to load the entities from the world files at the moment), and once I've cleaned up my code I'm going to make a repo of it available.

ci010 commented 2 years ago

Thanks for this, I'll give this a test either today or tomorrow.

I've been writing a Minecraft world viewer using this repo to load the worlds/models and resource packs; I haven't run into this issue on any other model yet (including custom ones I've added).

I'll probably submit a PR with a couple of missing functions that I've had to add to get my use case working (for example you're missing a way to load the entities from the world files at the moment), and once I've cleaned up my code I'm going to make a repo of it available.

I used to want to make a chunk renderer, but I don't have time recently. I think to render chunk, we need a new model vertices builder (with basic face culling) so the renderer can be more efficent.

Are you going to also render the entities in world? How can we deal with the entity model?

Anyway, PR is welcome.

John-Dean commented 2 years ago

I get this is getting a little way away from the original issue, but basically I ran into the following issues when I tried to make a chunk renderer:

The peformance issue I currently have solved by taking any default block (16x16x16 model with 6 faces) and running it through: https://github.com/joshmarinacci/voxeljs-next/blob/master/src/GreedyMesher.js to generate a mesh, and then running my own texture loader to load the textures for this. I need to re-look at this though, because while it works it's incompatible with things like stairs, half slabs and these will just have tanking performance; so this is actually super high on my list of things to sort out.

Item frames I solved by adding some additional functions to your library that load the entity file, which contain all the item frame info. I then scan this for item frames, pull out the block model from this and shove this into your model renderer. The problem with this is your model renderer only takes items in the "block" folder (from what I could tell) so I had to get a little creative with my resource pack layout to get it working. However, I have this working, and it allows you to take an item frame with a custom block model inside and render it as if it was a standard block.

The third (liquids) I haven't addressed yet.

I've sent you an invite to my repo I'm using to test this. I am planning on making this publically available when it's done, but it's really not in a clean state right now.

John-Dean commented 2 years ago

Added the aforementioned PR here: https://github.com/Voxelum/minecraft-launcher-core-node/pull/240

I haven't tested it (my current code just hacks the function into the compiled JavaScript file at the end), but it should be fine as I've just taken that code and converted it to TypeScript.

There is a 2nd PR I need to make regarding the resource pack only reading from models/blocks and not, for example, models/items (which is an issue in the case of item frames holding custom reskins of block models); but I need to write this one from scratch as my code currently just avoids this (as I've just changed my resource pack layout).

ci010 commented 2 years ago

Sounds good. Did you try the new version? If it works, we can close this issue. For futher discussion about rendering chunk, we can use discord (you can find the link in README.md).

John-Dean commented 1 year ago

Apologies for the very late reply.

I can confirm this is working for me: image

Thanks, John