-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add type-safe Block State matching #97
Comments
Manually adding this for all existing blocks would be insane, and generating typings is a difficult task. Not saying this is impossible, but its not easy. |
Please take a look at this repository: https://github.com/Articdive/ArticData function block(id: string, state?: {[name: string]: string | number}) {
if (state) {
id += "[" + Object.entries(state).map(([name, val]) => `${name}=${val}`).join(",") + "]";
}
return id;
} And then the overloads for blocks with states could be added to make it type-safe. The file "1_17_1_blocks.json" from the above mentioned repo is a list of all blocks and a list of their possible state names (eg. grass => ["SNOWY"]) and "1_17_1_block_properties.json" enumerates the possible values. |
A data source is not the problem because the community is well aware of several repositories of exported game data. Neither is the problem stringifying the states, that is fairly straightforward. The problem is the last part, because of having to make a sustainable & stable complex type generator. It's not simply a list of string literals. |
Couldn't this be repeated for every block that has a state? function block(id: "minecraft:sandstone_slab", state?: {type?: "top"|"bottom"|"double"; waterlogged?: boolean}); Maybe I forgot something, but I don't see the complexity of writing a generator for this. I might try that tomorrow. |
I implemented this function in my sandstone-resourcepacks library. Here's a working example of the function: Sources: |
@ColinTimBarndt this can be added in a future release, and you can be the one to add it to the upcoming generation script. |
@MulverineX how and where should code generation and loading the game data be handled? Downloading gama data could for example be done in a separate package as it does not depend on any Sandstone code. |
@ColinTimBarndt we will be using https://github.com/misode/mcmeta to source all game data. Currently code generation is not fully setup, here's the WIP script: https://github.com/sandstone-mc/sandstone/blob/ast/scripts/generateLists.js Once #184 is merged you can start work on the block state piece of this. |
I've taken a look, but there seems to be no data on block data/the block palette. This can be exported by running the client/server jar with specific arguments, but the output seems to not be included here. I need this information in order to generate the types. Also, which version/branch is going to be used? Always picking the latest snapshot doesn't seem like a good idea because Sanstone projects targeting an older version of the game may no longer work. It would be good to let the user pick a target game version. |
As an example, I need something equivalent to the following data:
|
Here's the full data on blocks: https://github.com/misode/mcmeta/blob/summary/blocks/data.json As for game versions, I think a sandstone-cli command to generate those files for a specific version would be great. In the sandstone source though it will be up to date. For now let's just get it working for the latest snapshot though. |
Now that |
Some blocks have block states. A
minecraft:sandstone_slab
can for example be waterlogged and has a type (top, bottom, double). In mcfunction this can be done everywhere a block is placed or compared. There is currently no type-safe block-aware way to do this in Sandstone.Using typescript it could be checked whether a block has the states that are specified. There is for example no type=bottom variant of a grass block.
The text was updated successfully, but these errors were encountered: