mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 05:55:33 +00:00
Changed NBT representation in JSON to hex, fix encoding problems with UTF-8
This commit is contained in:
parent
71e354cf1d
commit
e4a5cb6021
@ -57,22 +57,22 @@ class CraftingManager{
|
|||||||
case 0:
|
case 0:
|
||||||
// TODO: handle multiple result items
|
// TODO: handle multiple result items
|
||||||
$first = $recipe["output"][0];
|
$first = $recipe["output"][0];
|
||||||
$result = new ShapelessRecipe(Item::get($first["id"], $first["damage"], $first["count"], $first["nbt"]));
|
$result = new ShapelessRecipe(Item::jsonDeserialize($first));
|
||||||
|
|
||||||
foreach($recipe["input"] as $ingredient){
|
foreach($recipe["input"] as $ingredient){
|
||||||
$result->addIngredient(Item::get($ingredient["id"], $ingredient["damage"], $ingredient["count"], $first["nbt"]));
|
$result->addIngredient(Item::jsonDeserialize($ingredient));
|
||||||
}
|
}
|
||||||
$this->registerRecipe($result);
|
$this->registerRecipe($result);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
// TODO: handle multiple result items
|
// TODO: handle multiple result items
|
||||||
$first = $recipe["output"][0];
|
$first = $recipe["output"][0];
|
||||||
$result = new ShapedRecipe(Item::get($first["id"], $first["damage"], $first["count"], $first["nbt"]), $recipe["height"], $recipe["width"]);
|
$result = new ShapedRecipe(Item::jsonDeserialize($first), $recipe["height"], $recipe["width"]);
|
||||||
|
|
||||||
$shape = array_chunk($recipe["input"], $recipe["width"]);
|
$shape = array_chunk($recipe["input"], $recipe["width"]);
|
||||||
foreach($shape as $y => $row){
|
foreach($shape as $y => $row){
|
||||||
foreach($row as $x => $ingredient){
|
foreach($row as $x => $ingredient){
|
||||||
$result->addIngredient($x, $y, Item::get($ingredient["id"], ($ingredient["damage"] < 0 ? -1 : $ingredient["damage"]), $ingredient["count"], $ingredient["nbt"]));
|
$result->addIngredient($x, $y, Item::jsonDeserialize($ingredient));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->registerRecipe($result);
|
$this->registerRecipe($result);
|
||||||
@ -80,7 +80,7 @@ class CraftingManager{
|
|||||||
case 2:
|
case 2:
|
||||||
case 3:
|
case 3:
|
||||||
$result = $recipe["output"];
|
$result = $recipe["output"];
|
||||||
$resultItem = Item::get($result["id"], $result["damage"], $result["count"], $result["nbt"]);
|
$resultItem = Item::jsonDeserialize($result);
|
||||||
$this->registerRecipe(new FurnaceRecipe($resultItem, Item::get($recipe["inputId"], $recipe["inputDamage"] ?? -1, 1)));
|
$this->registerRecipe(new FurnaceRecipe($resultItem, Item::get($recipe["inputId"], $recipe["inputDamage"] ?? -1, 1)));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -259,7 +259,7 @@ class Item implements ItemIds, \JsonSerializable{
|
|||||||
$creativeItems = new Config(Server::getInstance()->getFilePath() . "src/pocketmine/resources/creativeitems.json", Config::JSON, []);
|
$creativeItems = new Config(Server::getInstance()->getFilePath() . "src/pocketmine/resources/creativeitems.json", Config::JSON, []);
|
||||||
|
|
||||||
foreach($creativeItems->getAll() as $data){
|
foreach($creativeItems->getAll() as $data){
|
||||||
$item = Item::get($data["id"], $data["damage"], $data["count"], $data["nbt"]);
|
$item = Item::jsonDeserialize($data);
|
||||||
if($item->getName() === "Unknown"){
|
if($item->getName() === "Unknown"){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1053,13 +1053,28 @@ class Item implements ItemIds, \JsonSerializable{
|
|||||||
*/
|
*/
|
||||||
final public function jsonSerialize(){
|
final public function jsonSerialize(){
|
||||||
return [
|
return [
|
||||||
"id" => $this->id,
|
"id" => $this->getId(),
|
||||||
"damage" => $this->meta,
|
"damage" => $this->getDamage(),
|
||||||
"count" => $this->count, //TODO: separate items and stacks
|
"count" => $this->getCount(),
|
||||||
"nbt" => $this->tags
|
"nbt_hex" => bin2hex($this->getCompoundTag())
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an Item from properties created in an array by {@link Item#jsonSerialize}
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return Item
|
||||||
|
*/
|
||||||
|
final public static function jsonDeserialize(array $data) : Item{
|
||||||
|
return Item::get(
|
||||||
|
(int) $data["id"],
|
||||||
|
(int) $data["damage"],
|
||||||
|
(int) $data["count"],
|
||||||
|
(string) ($data["nbt"] ?? hex2bin($data["nbt_hex"])) //`nbt` key might contain old raw data
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serializes the item to an NBT CompoundTag
|
* Serializes the item to an NBT CompoundTag
|
||||||
*
|
*
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user