mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 20:28:31 +00:00
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.
This commit is contained in:
parent
4f4dca7fc0
commit
07225df936
@ -73,7 +73,8 @@ class Block{
|
|||||||
|
|
||||||
private int $requiredBlockItemStateDataBits;
|
private int $requiredBlockItemStateDataBits;
|
||||||
private int $requiredBlockOnlyStateDataBits;
|
private int $requiredBlockOnlyStateDataBits;
|
||||||
private int $defaultBlockOnlyStateData;
|
|
||||||
|
private Block $defaultState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name English name of the block type (TODO: implement translations)
|
* @param string $name English name of the block type (TODO: implement translations)
|
||||||
@ -92,7 +93,7 @@ class Block{
|
|||||||
$this->describeBlockOnlyState($calculator);
|
$this->describeBlockOnlyState($calculator);
|
||||||
$this->requiredBlockOnlyStateDataBits = $calculator->getBitsUsed();
|
$this->requiredBlockOnlyStateDataBits = $calculator->getBitsUsed();
|
||||||
|
|
||||||
$this->defaultBlockOnlyStateData = $this->encodeBlockOnlyState();
|
$this->defaultState = clone $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __clone(){
|
public function __clone(){
|
||||||
@ -193,10 +194,11 @@ class Block{
|
|||||||
* Returns the block as an item.
|
* Returns the block as an item.
|
||||||
* Block-only state such as facing, powered/unpowered, open/closed, etc., is discarded.
|
* Block-only state such as facing, powered/unpowered, open/closed, etc., is discarded.
|
||||||
* Block-item state such as colour, wood type, etc. is preserved.
|
* 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{
|
public function asItem() : Item{
|
||||||
$normalized = clone $this;
|
$normalized = clone $this->defaultState;
|
||||||
$normalized->decodeBlockOnlyState($this->defaultBlockOnlyStateData);
|
$normalized->decodeBlockItemState($this->encodeBlockItemState());
|
||||||
return new ItemBlock($normalized);
|
return new ItemBlock($normalized);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user