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

Various changes to StructureTemplates, 1.20.5 branch. #13

Open
wants to merge 2 commits into
base: 1.20.5
Choose a base branch
from

Conversation

solonovamax
Copy link

@solonovamax solonovamax commented Jun 14, 2024

Changed several things to do with StructureTemplates:

  • Add support for structure block keys with a list of items (Fixes Support structure block keys with a list of items #7)
  • Add iterator to structure template
  • Add getters for structure template fields (I personally had a usecase where I wanted to access some of the fields)
  • Support pickblocking the block in the structure preview. (if a structure preview is active and you middle-click on a block, it will place it into your inventory if in creative, or take it from the items you have in your inventory if in survival)
  • Persist structure previews across world reloads (exiting then re-opening world)

@solonovamax solonovamax changed the title Add support for structure block keys with a list of items. 1.20.5 branch. Various changes to StructureTemplates, 1.20.5 branch. Jun 25, 2024
Copy link
Member

@gliscowo gliscowo left a comment

Choose a reason for hiding this comment

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

Alright, I've gone through and commented this version of the PR - the content applies to all the other ones. I would also like to mention that I will not merge any of them besides this one, 1.20 and 1.21 - we don't support the others anymore.

Overall, please please take a look at our Contributing Guidelines again and make sure your contribution follows the standards set therein.

As for the features, I'd be willing to merge the template parsing changes once they're cleaned up - for the rest, refer to my comments

Cheers

BlockStatePredicate predicate;
if (keys.containsKey(key)) {
predicate = keys.get(key);
private record StructureTemplateRenderView(@NotNull World world, @NotNull StructureTemplate template) implements BlockRenderView {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this a record now? It was doing perfectly fine as a local class

Copy link
Author

Choose a reason for hiding this comment

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

because intellij was yelling at me saying to make it a record lol

Copy link
Author

Choose a reason for hiding this comment

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

Why is this a record now? It was doing perfectly fine as a local class

I pulled it out as an inner class as I find local classes to be a bit of a codesmell.

Would you like me to revert this?

if (state.getBlock() != predicate.blockState().getBlock()) return Result.NO_MATCH;
@NotNull
@Override
public Iterator<Pair<BlockPos, BlockStatePredicate>> iterator() {
Copy link
Member

Choose a reason for hiding this comment

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

What precisely is the use case for this over the iteration methods? Having the entire iterator implementation below (which once again lays its fields out in a manner inconsistent with the rest of the codebase) seems like code I'd rather not have to maintain if there's not a good application

Copy link
Author

Choose a reason for hiding this comment

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

my specific usecase was:

iterate over all the blocks in a structure, exiting immediately when it finds the first block that matches some conditions.

the reason forEachPredicate wasn't appropriate for me, was it would not exit after the first match. what I wanted was something that a Stream is perfect for, for which implementing Iterable was needed.

however, with predicates being exposed, I can implement that in my own codebase. but, for posterity I contributed both changes.

Copy link
Author

Choose a reason for hiding this comment

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

Leaving this as unresolved while I wait for you to reply.

… in keys

Allow for arrays of strings in the keys of a structure template.
All the elements are parsed the same as they previously were,
this just allows for defining a list of possible blocks.

Also clean up code a decent amount to make it a tad more maintainable.

Signed-off-by: solonovamax <[email protected]>
- Implement Iterable<Pair<BlockPos, BlockStatePredicate>> for StructureTemplate
- Convert all fields to getters and introduce getters for more fields

Signed-off-by: solonovamax <[email protected]>
@solonovamax solonovamax force-pushed the structure-entries-list/1.20.5 branch from 6f6ee8c to 8ee713a Compare June 29, 2024 21:23
@solonovamax solonovamax requested a review from gliscowo June 29, 2024 21:26
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.

2 participants