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

Add parsing support for block NBT #2173

Merged
merged 6 commits into from
Oct 8, 2023
Merged

Add parsing support for block NBT #2173

merged 6 commits into from
Oct 8, 2023

Conversation

me4502
Copy link
Member

@me4502 me4502 commented Aug 15, 2022

Adds block NBT parsing support.

Test with //set chest{'Lock':'cake'}, then notice you can only open the chest with an item named cake

Test with //set oak_sign[rotation=12]{'is_waxed':1,'front_text':{'messages':['{"text":"a"}','{"text":"a"}','{"text":"a"}','{"text":"a","color":"red"}']}} for a waxed sign with 'a' on every line where the last line is red

@codecov
Copy link

codecov bot commented Aug 28, 2022

Codecov Report

Merging #2173 (c5d327f) into master (856aaa6) will increase coverage by 0.31%.
Report is 52 commits behind head on master.
The diff coverage is 0.00%.

❗ Current head c5d327f differs from pull request most recent head c000572. Consider uploading reports for the commit c000572 to get more accurate results

@@             Coverage Diff             @@
##             master   #2173      +/-   ##
===========================================
+ Coverage      8.88%   9.20%   +0.31%     
+ Complexity     1095    1038      -57     
===========================================
  Files           886     871      -15     
  Lines         46452   43683    -2769     
  Branches       5189    4881     -308     
===========================================
- Hits           4129    4019     -110     
+ Misses        42130   39483    -2647     
+ Partials        193     181      -12     
Files Changed Coverage Δ
...t/extension/factory/parser/DefaultBlockParser.java 1.31% <0.00%> (-0.08%) ⬇️
...it/extension/factory/parser/DefaultItemParser.java 3.57% <0.00%> (ø)
...k89q/worldedit/internal/wna/WorldNativeAccess.java 0.00% <0.00%> (ø)
...ava/com/sk89q/worldedit/world/block/BaseBlock.java 26.66% <0.00%> (-0.61%) ⬇️

... and 89 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@me4502 me4502 marked this pull request as ready for review September 21, 2022 12:29
@me4502 me4502 requested a review from a team September 21, 2022 12:29
@me4502 me4502 force-pushed the feature/block-nbt-parsing branch 3 times, most recently from 640b0ff to c5d327f Compare December 27, 2022 12:41
}

String stateString = null;
if (stateStart != -1) {
if (stateStart + 1 >= blockAndExtraData[0].length()) {
throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.hanging-lbracket", TextComponent.of(stateStart)));
}
int stateEnd = blockAndExtraData[0].lastIndexOf(']');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check behavior for this test case: chest[double={whoops:"nbt ]"}; it might pass, or fail with a weird error.

I suspect we might need to be a little more strict in what is accepted here. It might be worth writing an ANTLR grammar for this instead, since it's getting quite complex.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State is missing trailing ']' is the error we get here, which appears to be the correct error

if (nbtStart + 1 >= blockAndExtraData[0].length()) {
throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.hanging-lbrace", TextComponent.of(nbtStart)));
}
int nbtEnd = blockAndExtraData[0].lastIndexOf('}');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here, we might cut off NBT early if there's } in an NBT string, and someone doesn't put one at the end, resulting in a weird error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will result in an invalid NBT error

@octylFractal
Copy link
Member

Closes #2375

@octylFractal octylFractal linked an issue Jul 31, 2023 that may be closed by this pull request
@me4502 me4502 merged commit 8915e30 into master Oct 8, 2023
7 checks passed
@me4502 me4502 deleted the feature/block-nbt-parsing branch October 8, 2023 11:44
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 this pull request may close these issues.

Allow for setting blocks with nbt data
2 participants