Skip to content

Add raw byte block state serialization#9830

Closed
TrollyLoki wants to merge 4 commits into
PaperMC:masterfrom
TrollyLoki:block-serialization
Closed

Add raw byte block state serialization#9830
TrollyLoki wants to merge 4 commits into
PaperMC:masterfrom
TrollyLoki:block-serialization

Conversation

@TrollyLoki
Copy link
Copy Markdown
Contributor

@TrollyLoki TrollyLoki commented Oct 12, 2023

Adds two methods for (de)serialization of block states similar to the existing methods for (de)serialization of entities and item stacks.

I decided on serializing block states rather than blocks themselves because it allows plugins to examine the properties of deserialized data via the existing APIs before actually placing them in the world by using the update() method.

Example Usage:

private byte[] blockBytes;

@EventHandler
public void onBlockBreak(@NotNull BlockBreakEvent event) {
    // serialize block when it's broken
    BlockState state = event.getBlock().getState();
    blockBytes = Bukkit.getUnsafe().serializeBlock(state);
}

@EventHandler
public void onInteract(@NotNull PlayerInteractEvent event) {
    if (blockBytes == null)
        return;
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
        return;
    if (event.getItem() == null || event.getItem().getType() != Material.BLAZE_ROD)
        return;

    // deserialize block at another location using a blaze rod
    Block block = event.getClickedBlock().getRelative(event.getBlockFace());
    BlockState state = Bukkit.getUnsafe().deserializeBlock(blockBytes, block);
    state.update(true);
}

@TrollyLoki TrollyLoki force-pushed the block-serialization branch 2 times, most recently from 9d58a42 to fa4d579 Compare October 12, 2023 20:14
@TrollyLoki TrollyLoki marked this pull request as ready for review October 12, 2023 20:16
@TrollyLoki TrollyLoki requested a review from a team as a code owner October 12, 2023 20:16
Comment thread patches/server/1040-Add-raw-byte-block-state-serialization.patch
@TrollyLoki TrollyLoki force-pushed the block-serialization branch 3 times, most recently from 1364c46 to 57c2c2a Compare October 29, 2023 23:35
@TrollyLoki TrollyLoki requested a review from lynxplay December 4, 2023 18:57
@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.

5 participants