Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Collision Boxes #258

Closed
Gjum opened this issue Dec 13, 2019 · 6 comments · Fixed by #264
Closed

Block Collision Boxes #258

Gjum opened this issue Dec 13, 2019 · 6 comments · Fixed by #264

Comments

@Gjum
Copy link
Member

Gjum commented Dec 13, 2019

Minecraft-Data should provide collision box data for each block.

A use case is implementing client physics or server entity pathfinding, for example PrismarineJS/mineflayer#228 or Gjum/Botlin#4.

This might go together with #52 and/or #83 but since the collision box data is so much it might be better to keep it in a separate file.

@Gjum
Copy link
Member Author

Gjum commented Dec 13, 2019

I've been playing around with extracting collision box data for 1.12.2, 1.14.4, and 1.15 and came up with this data format as a compromise between file size and consumer implementation simplicity:

{
  "blocks": {
    blockId: shapeId, // all block states have same shape -> just the shapeId
    blockId: [ shapeId, ... ], // at least one state's shape different from others
                               // -> different shapeIds, indexed by stateId
    ...
  },
  "shapes": {
    shapeId: [[xMin,yMin,zMin, xMax,yMax,zMax], ...], // e.g., the shape of a corner stair
    shapeId: [[xMin,yMin,zMin, xMax,yMax,zMax], ...], // e.g., the shape of an upside-down corner stair
    ...
  },
}

The extractor is based on Fabric client mod API and also includes a sample implementation of how to consume the JSON and provide a Shape getBlockShape(String blockId, int blockStateId) method (the returned Shape is a collection of cuboids).

@nickelpro
Copy link
Member

+1 for this, I'm consuming a lot of minecraft-data with mcd2c and having some sort of easily consumable model data is going to be next on my list. The proposed json format is simple enough to translate into to a binary mesh so it works for me.

@rom1504
Copy link
Member

rom1504 commented Dec 13, 2019

This seems pretty good indeed

@Gjum
Copy link
Member Author

Gjum commented Mar 24, 2020

Extracting 1.12.2 blocks was a bit tricky but it's done now (source), and personally I don't need any data older than that.

1.12.2 and older versions have the downside that collision boxes for a block of given (id:meta) additionally depend on adjacent blocks (e.g., cobblestone walls change their collision box if there's a solid block to N/S/E/W/above), so this dataset assumes the block is surrounded by air; this is the best that I can do without encoding the full logic for these special cases somehow.

If you consider this useful I can open a PR with the 1.12.2, 1.14.4, and 1.15 collision boxes as linked in the first comment. Do you need a schema to go with that?

@timmyRS
Copy link
Contributor

timmyRS commented Mar 24, 2020

A valid schema would be needed for the tests to succeed, but just providing the data would be nice, someone else can take care of the schema. ;P

@rom1504
Copy link
Member

rom1504 commented Mar 24, 2020

Yeah it would be useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants