Skip to content

Fix CraftStructureTransformer from deleting generated entities#10122

Closed
Machine-Maker wants to merge 1 commit into
PaperMC:masterfrom
Machine-Maker:fix/entity-structure-transformer
Closed

Fix CraftStructureTransformer from deleting generated entities#10122
Machine-Maker wants to merge 1 commit into
PaperMC:masterfrom
Machine-Maker:fix/entity-structure-transformer

Conversation

@Machine-Maker
Copy link
Copy Markdown
Member

CraftLimitedRegion loads and stores entities in the protochunk and doesn't parse the entities from NBT each time. This requires that a new instance of CraftLimitedRegion is created each time before passing it to an api consumer and then saving/clearing it afterwards.

CraftStructureTransformer was creating a single instance for an entire structure place which was causing entities to be deleted so no structures would spawn entities.

Demo to cause the issue. Just add this listener and teleport around to newly generated villages.

@EventHandler
public void onEvent(AsyncStructureGenerateEvent event) {
    event.setEntityTransformer(new NamespacedKey(this, "test"), (region, x, y, z, entity, allowedToSpawn) -> {
        System.out.println(region.getEntities());
        return true;
    });
}

@Machine-Maker Machine-Maker requested a review from a team as a code owner January 3, 2024 23:34
CraftLimitedRegion loads and stores entities in the protochunk and doesn't
parse the entities from NBT each time. This *requires* that a new one
instance of CraftLimitedRegion is created each time before passing it
to an api consumer and then saving/clearing it afterwards.

CraftStructureTransformer was creating a single instance for an entire structure place which
was causing entities to be deleted so no structures would spawn entities.
@Machine-Maker Machine-Maker force-pushed the fix/entity-structure-transformer branch from bf37016 to 78e9607 Compare March 3, 2024 21:22
@Machine-Maker
Copy link
Copy Markdown
Member Author

Alternative fix would be to add the entity to the list stored in CraftLimitedRegion if the entities were loaded. That way you can re-use the instances and they will stay up-to-date.

@Warriorrrr Warriorrrr moved this from Awaiting review to Waiting For Author in Paper PR Queue Mar 5, 2025
@kennytv kennytv added the pre-softspoon: never rebased Pre-hardfork pull requests that were not re-opened with the new main branch label Mar 23, 2025
@kennytv kennytv deleted the branch PaperMC:master March 23, 2025 19:15
@kennytv kennytv closed this Mar 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pre-softspoon: never rebased Pre-hardfork pull requests that were not re-opened with the new main branch pre-softspoon

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants