-
Notifications
You must be signed in to change notification settings - Fork 383
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
Extend Data Attachment API to ProtoChunk #3548
Extend Data Attachment API to ProtoChunk #3548
Conversation
- moved interfaceInjection from WorldChunk to Chunk - dataAttachment saving on ProtoChunks in ChunkSerializer - copy attachment from ProtoChunk to WorldChunk on creation. - make WrapperProtoChunk wrap attachment calls to WorldChunk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good so far. I don't know too much about how worldgen and chunk code works, so I'm unsure about the design decisions to make. I'd have someone else weigh in on this.
For propagateToWrapped
, if that field is named intuitively, it would make sense to always attach the data to the ProtoChunk, and also attach it to the wrapped chunk depending on the flag.
I don't exactly know what EMPTY
ProtoChunks correspond to, but I'd suggest simply emitting a warning when trying to use a persistent attachment. An exception is overkill, and manually saving such chunks feels like an intrusive change for no reason.
...ttachment-api-v1/src/main/java/net/fabricmc/fabric/impl/attachment/AttachmentTargetImpl.java
Outdated
Show resolved
Hide resolved
To elaborate further on the 2 open questions: The There are basically 2 use cases for writing attachments to ProtoChunks: The first use case is writing to the currently generating chunk during worldgen. For this case, neither of the 2 open questions matter, as we never deal with WrapperProtoChunks, nor with chunk status EMPTY. Maybe you'd want to write to neighboring chunks, but even then you The second use case is saving to chunks at arbitrary positions, i.e. writing something like: overworld.getChunkManager().getChunk(x, z, ChunkStatus.EMPTY, true).setAttached(...); If we want to support this use case (and I could very well live with a "no" to this questions), then the questions become more relevant:
|
I've extended the testmod to include a direct test of writing to protochunks during worldgen, which is the main use case of this PR. |
That sounds like a decent solution, please document it in AttachmentTarget in an extra section. Don't forget to also update the references to WorldChunk that are already present. |
...ta-attachment-api-v1/src/main/java/net/fabricmc/fabric/api/attachment/v1/AttachmentType.java
Outdated
Show resolved
Hide resolved
* allow data-attachment on ProtoChunks - moved interfaceInjection from WorldChunk to Chunk - dataAttachment saving on ProtoChunks in ChunkSerializer - copy attachment from ProtoChunk to WorldChunk on creation. - make WrapperProtoChunk wrap attachment calls to WorldChunk * add test for data-attachment on ProtoChunks, and extend testmod. * code style and license headers * fix typos in javadoc * extend testmod to test setting attachment during worldgen. * code formatting * fix testmod: don't crash when feature isn't placed (i.e. on GameTest server) * add warning when adding persistent attachment to chunk with status EMPTY. * update javadoc * update javadoc to reference ServerLivingEntityEvents#MOB_CONVERSION (cherry picked from commit 32782cf)
* allow data-attachment on ProtoChunks - moved interfaceInjection from WorldChunk to Chunk - dataAttachment saving on ProtoChunks in ChunkSerializer - copy attachment from ProtoChunk to WorldChunk on creation. - make WrapperProtoChunk wrap attachment calls to WorldChunk * add test for data-attachment on ProtoChunks, and extend testmod. * code style and license headers * fix typos in javadoc * extend testmod to test setting attachment during worldgen. * code formatting * fix testmod: don't crash when feature isn't placed (i.e. on GameTest server) * add warning when adding persistent attachment to chunk with status EMPTY. * update javadoc * update javadoc to reference ServerLivingEntityEvents#MOB_CONVERSION
* allow data-attachment on ProtoChunks - moved interfaceInjection from WorldChunk to Chunk - dataAttachment saving on ProtoChunks in ChunkSerializer - copy attachment from ProtoChunk to WorldChunk on creation. - make WrapperProtoChunk wrap attachment calls to WorldChunk * add test for data-attachment on ProtoChunks, and extend testmod. * code style and license headers * fix typos in javadoc * extend testmod to test setting attachment during worldgen. * code formatting * fix testmod: don't crash when feature isn't placed (i.e. on GameTest server) * add warning when adding persistent attachment to chunk with status EMPTY. * update javadoc * update javadoc to reference ServerLivingEntityEvents#MOB_CONVERSION Backport persistent state code
* allow data-attachment on ProtoChunks - moved interfaceInjection from WorldChunk to Chunk - dataAttachment saving on ProtoChunks in ChunkSerializer - copy attachment from ProtoChunk to WorldChunk on creation. - make WrapperProtoChunk wrap attachment calls to WorldChunk * add test for data-attachment on ProtoChunks, and extend testmod. * code style and license headers * fix typos in javadoc * extend testmod to test setting attachment during worldgen. * code formatting * fix testmod: don't crash when feature isn't placed (i.e. on GameTest server) * add warning when adding persistent attachment to chunk with status EMPTY. * update javadoc * update javadoc to reference ServerLivingEntityEvents#MOB_CONVERSION Backport persistent state code
This PR extends the Data Attachment API to allow data attachments on
ProtoChunk
s, rather than justWorldChunk
s. Data on aProtoChunk
is kept when it is converted to aWorldChunk
. This allows storing custom data during worldgen and reading it during gameplay.Individual changes:
WorldChunk
toChunk
.ProtoChunk
to aWorldChunk
in theWorldChunk
constructor.copyOnRespawn
helper method for that and renamed it totransfer
to better match its extended use.WrapperProtoChunk
that simply forwards the calls to the wrappedWorldChunk
.What still needs to be decided:
WrapperProtoChunk.setAttached
adhere to thepropagateToWrapped
flag? -> We ignore the flag and always write to theWorldChunk
.ProtoChunk
with chunk statusEMPTY
? Since those aren't saved, the attachment would get lost too. Options are:Save emptyProtoChunks
when an attachment is present. (I would still need to investigate how to do that.)Throw an exception when trying to attach a persistent attachment (but allow non-persistent attachments).-> We log a warning. The javadoc documents this behavior.
Tests:
I've extended the testmod to test saving data to a
ProtoChunk
s.ProtoChunk
if it is in the [0, 0] chunk, then testing whether the attachment is present in the WorldChunk after world-load. This tests both writing toProtoChunk
s and theWorldChunk
conversion.ProtoChunk
s, I'm adding an attachment to a far chunk. This requires this chunk to not be generated beforehand.