From 07225df936e061b3779d8a82164aeb83b21b465f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 31 May 2023 21:48:06 +0100 Subject: [PATCH] Block: fixed tile-stored properties sticking to the item in asItem() this was enabling duplication of items, since the dropped item object would contain a Block which still referenced the framed Item. --- src/block/Block.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/block/Block.php b/src/block/Block.php index 21781d170..f838ca450 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -73,7 +73,8 @@ class Block{ private int $requiredBlockItemStateDataBits; private int $requiredBlockOnlyStateDataBits; - private int $defaultBlockOnlyStateData; + + private Block $defaultState; /** * @param string $name English name of the block type (TODO: implement translations) @@ -92,7 +93,7 @@ class Block{ $this->describeBlockOnlyState($calculator); $this->requiredBlockOnlyStateDataBits = $calculator->getBitsUsed(); - $this->defaultBlockOnlyStateData = $this->encodeBlockOnlyState(); + $this->defaultState = clone $this; } public function __clone(){ @@ -193,10 +194,11 @@ class Block{ * Returns the block as an item. * Block-only state such as facing, powered/unpowered, open/closed, etc., is discarded. * Block-item state such as colour, wood type, etc. is preserved. + * Complex state properties stored in the tile data (e.g. inventory) are discarded. */ public function asItem() : Item{ - $normalized = clone $this; - $normalized->decodeBlockOnlyState($this->defaultBlockOnlyStateData); + $normalized = clone $this->defaultState; + $normalized->decodeBlockItemState($this->encodeBlockItemState()); return new ItemBlock($normalized); }