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

Structure and Feature placement callbacks #2520

Open
octylFractal opened this issue Jun 18, 2024 · 2 comments
Open

Structure and Feature placement callbacks #2520

octylFractal opened this issue Jun 18, 2024 · 2 comments
Labels
status: needs triage This label is automatically applied to new issues and pull requests to indicate they require triage

Comments

@octylFractal
Copy link
Contributor

Major SpongeAPI version

12

Is this likely to be a breaking change?

No

What are you requesting?

Currently, Structure and Feature have boolean place(ServerWorld, Vector3i), which does not allow a mod like WorldEdit to capture or modify the changes. It would be nice if we could get a callback for each block/entity so that WorldEdit may place it, rather than placing it directly into the world. This allows undo, masking, and better control of block placement than using Minecraft's code directly.

@octylFractal octylFractal added the status: needs triage This label is automatically applied to new issues and pull requests to indicate they require triage label Jun 18, 2024
@Yeregorix
Copy link
Member

I think the proper way to do it would be:

try (CauseStackManager.StackFrame frame = Sponge.server().causeStackManager().pushCauseFrame()) {
  frame.addContext(MY_CONTEXT_KEY, "hello");
  Features.TREES_PLAINS.get().place(location);
}

and

@Listener
public void onBlockChange(ChangeBlockEvent e) {
  if (e.context().get(MY_CONTEXT_KEY).isPresent()) {
    // filter blocks
  }
}

However I tested that a few days ago and it didn't work so there is likely a bug in the implementation currently.
The implementation needs to be fixed, but I don't think the API needs any additions for that.

@aromaa
Copy link
Member

aromaa commented Feb 1, 2025

I have fixed the implementation for the suggested and recommended approach mentioned above in the commit SpongePowered/Sponge@49fe76a. This should unblock any scenarios where you would want to modify or record the block changes.

I will leave this open however because we most likely would like to still implement some improvements around this where you only want to record the outcome. Something along the lines of 63edbff#diff-18baa7adfaf0c306829fb40fb9aeccd21a7885830d19064a07504aaf3d0d361fR106. We have introduced CompositeEvent in API 14 which seems to be the perfect candidate here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This label is automatically applied to new issues and pull requests to indicate they require triage
Projects
None yet
Development

No branches or pull requests

3 participants