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

Introduce Item Lock API mainly for Client-Side inventory action prevention #5333

Open
wants to merge 15 commits into
base: minor-next
Choose a base branch
from
Prev Previous commit
Next Next commit
define constants that was hardcoded value before
yuyaprgrm committed Oct 14, 2022
commit e763e22d51b87eaef52a2e3c010701172a8f585a
17 changes: 10 additions & 7 deletions src/item/Item.php
Original file line number Diff line number Diff line change
@@ -64,10 +64,14 @@ class Item implements \JsonSerializable{
public const TAG_ENCH = "ench";
public const TAG_DISPLAY = "display";
public const TAG_BLOCK_ENTITY_TAG = "BlockEntityTag";
public const TAG_ITEM_LOCK = "minecraft:item_lock";

public const TAG_DISPLAY_NAME = "Name";
public const TAG_DISPLAY_LORE = "Lore";

public const VALUE_ITEM_LOCK_IN_SLOT = 1;
public const VALUE_ITEM_LOCK_IN_INVENTORY = 2;

private ItemIdentifier $identifier;
private CompoundTag $nbt;

@@ -334,10 +338,9 @@ protected function deserializeCompoundTag(CompoundTag $tag) : void{
$this->canDestroy[$entry->getValue()] = $entry->getValue();
}
}
//TODO: define hardcoded value in BedrockProtocol or BedrockData?
$this->lockMode = match($tag->getByte("minecraft:item_lock", 0)){
1 => ItemLockMode::SLOT(),
2 => ItemLockMode::INVENTORY(),
$this->lockMode = match($tag->getByte(self::TAG_ITEM_LOCK, 0)){
self::VALUE_ITEM_LOCK_IN_SLOT => ItemLockMode::SLOT(),
self::VALUE_ITEM_LOCK_IN_INVENTORY => ItemLockMode::INVENTORY(),
default => null
};
}
@@ -398,9 +401,9 @@ protected function serializeCompoundTag(CompoundTag $tag) : void{
$tag->removeTag("CanDestroy");
}
if($this->lockMode !== null){
$tag->setByte("minecraft:item_lock", match($this->lockMode->id()){
ItemLockMode::SLOT()->id() => 1,
ItemLockMode::INVENTORY()->id() => 2,
$tag->setByte(self::TAG_ITEM_LOCK, match($this->lockMode->id()){
ItemLockMode::SLOT()->id() => self::VALUE_ITEM_LOCK_IN_SLOT,
ItemLockMode::INVENTORY()->id() => self::VALUE_ITEM_LOCK_IN_INVENTORY,
default => throw new AssumptionFailedError("Unknown lock mode")
});
}else{