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 SerializableDataHolder#rawData() method #2463

Open
wants to merge 1 commit into
base: api-10
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ static Builder builder() {
*
*
* @return The copied container of the block entity
* @deprecated Use unified {@link BlockEntityArchetype#rawData()}
*/
DataContainer blockEntityData();
@Deprecated
default DataContainer blockEntityData() {
return rawData();
}

/**
* Sets the raw data for the desired {@link BlockEntity}. Note that position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@
*/
public interface SerializableDataHolder extends DataSerializable, CopyableDataHolder {

/**
* Returns the raw extra data of this {@link SerializableDataHolder}.
*
* <p>The format of the {@link DataView}'s contained data is dependent on the type
* of {@link DataHolder.Mutable} this is. In some cases, the format is specified
* based on a more specific type, such as for {@link EntityType}s, or
* {@link ItemType}s.</p>
* <p>The data can be modified and set back using
* {@link Mutable#setRawData(DataView)} or {@link Immutable#withRawData(DataView)}
* methods.</p>
* <p><b>Warning:</b> Be aware of the safety mode of the returned container.
* The container may contain mutable values, such as arrays, that may not be
* cloned, and thus changing them may inadvertently change the internal state
* of the {@link DataHolder}.</p>
*
* @return The raw data
*/
DataContainer rawData();

/**
* Validates the container with known data required to set the raw data to
* this {@link SerializableDataHolder}. If the container is incomplete or contains
Expand All @@ -58,12 +77,11 @@ interface Mutable extends SerializableDataHolder, DataHolder.Mutable {

/**
* Attempts to set all data of this {@link DataHolder} according to the
* {@link DataView}'s held information. Using this to modify known to be
* {@link Key}s provided dynamically through {@link DataProvider}s is
* unsupported. The format of the {@link DataView}'s contained data is
* dependent on the type of {@link DataHolder.Mutable} this is. In some cases, the
* format is specified based on a more specific type, such as for
* {@link EntityType}s, or {@link ItemType}s.
* {@link DataView}'s held information. Using this to modify unknown data
* that is not supported by Data API. The format of the {@link DataView}'s
* contained data is dependent on the type of {@link DataHolder.Mutable}
* this is. In some cases, the format is specified based on a more specific
* type, such as for {@link EntityType}s, or {@link ItemType}s.
*
* <p>This setter is used to provide setting custom data that is not
* represented by the Data API, including forge mods and other
Expand All @@ -77,6 +95,7 @@ interface Mutable extends SerializableDataHolder, DataHolder.Mutable {
* data holder
* @throws InvalidDataException If the container is missing or has invalid
* data that this holder will refuse
* @see SerializableDataHolder#rawData()
*/
void setRawData(DataView container) throws InvalidDataException;

Expand All @@ -88,12 +107,11 @@ interface Immutable<I extends Immutable<I>> extends SerializableDataHolder, Data

/**
* Attempts to set all data of this {@link DataHolder} according to the
* {@link DataView}'s held information. Using this to modify known to be
* {@link Key}s provided dynamically through {@link DataProvider}s is
* unsupported. The format of the {@link DataView}'s contained data is
* dependent on the type of {@link DataHolder.Mutable} this is. In some cases, the
* format is specified based on a more specific type, such as for
* {@link EntityType}s, or {@link ItemType}s.
* {@link DataView}'s held information. Using this to modify unknown data
* that is not supported by Data API. The format of the {@link DataView}'s
* contained data is dependent on the type of {@link DataHolder.Immutable}
* this is. In some cases, the format is specified based on a more specific
* type, such as for {@link EntityType}s, or {@link ItemType}s.
*
* <p>This setter is used to provide setting custom data that is not
* represented by the Data API, including forge mods and other
Expand All @@ -108,6 +126,7 @@ interface Immutable<I extends Immutable<I>> extends SerializableDataHolder, Data
* @return The new immutable data holder containing the raw data
* @throws InvalidDataException If the container is missing or has invalid
* data that this holder will refuse
* @see SerializableDataHolder#rawData()
*/
I withRawData(DataView container) throws InvalidDataException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ static EntityArchetype of(EntityType<?> type) {
* </p>
*
* @return The copied container of the entity
* @deprecated Use unified {@link EntityArchetype#rawData()}
*/
DataContainer entityData();
@Deprecated
default DataContainer entityData() {
return rawData();
}

@Override
void setRawData(DataView container) throws InvalidDataException;
Expand Down