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

new data #291

Open
wants to merge 10 commits into
base: revised-data
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
update (not finished)
vp817 committed Aug 5, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 5baf7a3d204da4cc99c5f372b0e2e1187b91cea6
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ memory_dumps/*
resource_packs/
server.lock
/phpstan.neon
start_dev.sh

# Common IDEs
.idea/*
@@ -40,6 +41,7 @@ Desktop.ini

# Composer
vendor/*
pm_composer.sh

# Travis files
test_data/*
@@ -54,3 +56,5 @@ Documentation/*
/.php_cs.cache
/.php-cs-fixer.cache

# Vscode
/.vscode
2 changes: 1 addition & 1 deletion src/pocketmine/Player.php
Original file line number Diff line number Diff line change
@@ -3373,7 +3373,7 @@ public function handlePlayerAction(PlayerActionPacket $packet) : bool{
break;
case PlayerActionPacket::ACTION_CRACK_BREAK:
$block = $this->level->getBlock($pos);
$this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_PARTICLE_PUNCH_BLOCK, $block->getRuntimeId() | ($packet->face << 24));
$this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_PARTICLE_PUNCH_BLOCK, $block->getNetworkId() | ($packet->face << 24));
//TODO: destroy-progress level event
break;
case PlayerActionPacket::ACTION_START_SWIMMING:
2 changes: 2 additions & 0 deletions src/pocketmine/Server.php
Original file line number Diff line number Diff line change
@@ -73,6 +73,7 @@
use pocketmine\nbt\tag\StringTag;
use pocketmine\network\AdvancedSourceInterface;
use pocketmine\network\CompressBatchedTask;
use pocketmine\network\mcpe\convert\NetworkBlockMapping;
use pocketmine\network\mcpe\encryption\EncryptionContext;
use pocketmine\network\mcpe\protocol\BatchPacket;
use pocketmine\network\mcpe\protocol\DataPacket;
@@ -1606,6 +1607,7 @@ public function __construct(\ClassLoader $autoloader, \AttachableThreadedLogger

Entity::init();
Tile::init();
NetworkBlockMapping::init(); // TEMP FOR DEV USE
BlockFactory::init();
Enchantment::init();
ItemFactory::init();
6 changes: 3 additions & 3 deletions src/pocketmine/block/Block.php
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@
use pocketmine\math\Vector3;
use pocketmine\metadata\Metadatable;
use pocketmine\metadata\MetadataValue;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\convert\NetworkBlockMapping;
use pocketmine\Player;
use pocketmine\plugin\Plugin;
use function array_merge;
@@ -104,8 +104,8 @@ public function getItemId() : int{
/**
* @internal
*/
public function getRuntimeId() : int{
return RuntimeBlockMapping::toStaticRuntimeId($this->getId(), $this->getDamage());
public function getNetworkId() : int{
return NetworkBlockMapping::toStaticNetworkId($this->getId(), $this->getDamage());
}

final public function getDamage() : int{
19 changes: 0 additions & 19 deletions src/pocketmine/block/BlockFactory.php
Original file line number Diff line number Diff line change
@@ -26,7 +26,6 @@
use InvalidArgumentException;
use pocketmine\item\Item;
use pocketmine\level\Position;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use RuntimeException;
use SplFixedArray;
use function min;
@@ -431,22 +430,4 @@ public static function isRegistered(int $id) : bool{
$b = self::$fullList[$id << 4];
return $b !== null and !($b instanceof UnknownBlock);
}

/**
* @internal
* @deprecated
*/
public static function toStaticRuntimeId(int $id, int $meta = 0) : int{
return RuntimeBlockMapping::toStaticRuntimeId($id, $meta);
}

/**
* @return int[] [id, meta]
* @internal
*
* @deprecated
*/
public static function fromStaticRuntimeId(int $runtimeId) : array{
return RuntimeBlockMapping::fromStaticRuntimeId($runtimeId);
}
}
2 changes: 1 addition & 1 deletion src/pocketmine/block/Cauldron.php
Original file line number Diff line number Diff line change
@@ -373,7 +373,7 @@ private function updateLiquid() : void{
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$pk->blockRuntimeId = $this->getRuntimeId();
$pk->blockNetworkId = $this->getNetworkId();
$pk->dataLayerId = UpdateBlockPacket::DATA_LAYER_LIQUID;
$pk->flags = UpdateBlockPacket::FLAG_ALL_PRIORITY;

2 changes: 1 addition & 1 deletion src/pocketmine/entity/object/FallingBlock.php
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ protected function initEntity() : void{

$this->block = BlockFactory::get($blockId, $damage);

$this->propertyManager->setInt(self::DATA_VARIANT, $this->block->getRuntimeId());
$this->propertyManager->setInt(self::DATA_VARIANT, $this->block->getNetworkId());
}

public function canCollideWith(Entity $entity) : bool{
71 changes: 36 additions & 35 deletions src/pocketmine/inventory/CraftingManager.php
Original file line number Diff line number Diff line change
@@ -56,41 +56,42 @@ public function __construct(){
}

public function init() : void{
$recipes = json_decode(file_get_contents(RESOURCE_PATH . "vanilla" . DIRECTORY_SEPARATOR . "recipes.json"), true);
if(!is_array($recipes)){
throw new AssumptionFailedError("recipes.json root should contain a map of recipe types");
}

$itemDeserializerFunc = Closure::fromCallable([Item::class, 'jsonDeserialize']);

foreach($recipes["shapeless"] as $recipe){
if($recipe["block"] !== "crafting_table"){ //TODO: filter others out for now to avoid breaking economics
continue;
}
$this->registerShapelessRecipe(new ShapelessRecipe(
array_map($itemDeserializerFunc, $recipe["input"]),
array_map($itemDeserializerFunc, $recipe["output"])
));
}
foreach($recipes["shaped"] as $recipe){
if($recipe["block"] !== "crafting_table"){ //TODO: filter others out for now to avoid breaking economics
continue;
}
$this->registerShapedRecipe(new ShapedRecipe(
$recipe["shape"],
array_map($itemDeserializerFunc, $recipe["input"]),
array_map($itemDeserializerFunc, $recipe["output"])
));
}
foreach($recipes["smelting"] as $recipe){
if($recipe["block"] !== "furnace"){ //TODO: filter others out for now to avoid breaking economics
continue;
}
$this->registerFurnaceRecipe(new FurnaceRecipe(
Item::jsonDeserialize($recipe["output"]),
Item::jsonDeserialize($recipe["input"]))
);
}
// TODO
// $recipes = json_decode(file_get_contents(RESOURCE_PATH . "vanilla" . DIRECTORY_SEPARATOR . "recipes.json"), true);
// if(!is_array($recipes)){
// throw new AssumptionFailedError("recipes.json root should contain a map of recipe types");
// }

// $itemDeserializerFunc = Closure::fromCallable([Item::class, 'jsonDeserialize']);

// foreach($recipes["shapeless"] as $recipe){
// if($recipe["block"] !== "crafting_table"){ //TODO: filter others out for now to avoid breaking economics
// continue;
// }
// $this->registerShapelessRecipe(new ShapelessRecipe(
// array_map($itemDeserializerFunc, $recipe["input"]),
// array_map($itemDeserializerFunc, $recipe["output"])
// ));
// }
// foreach($recipes["shaped"] as $recipe){
// if($recipe["block"] !== "crafting_table"){ //TODO: filter others out for now to avoid breaking economics
// continue;
// }
// $this->registerShapedRecipe(new ShapedRecipe(
// $recipe["shape"],
// array_map($itemDeserializerFunc, $recipe["input"]),
// array_map($itemDeserializerFunc, $recipe["output"])
// ));
// }
// foreach($recipes["smelting"] as $recipe){
// if($recipe["block"] !== "furnace"){ //TODO: filter others out for now to avoid breaking economics
// continue;
// }
// $this->registerFurnaceRecipe(new FurnaceRecipe(
// Item::jsonDeserialize($recipe["output"]),
// Item::jsonDeserialize($recipe["input"]))
// );
// }

$this->buildCraftingDataCache();
}
35 changes: 22 additions & 13 deletions src/pocketmine/item/Item.php
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@
use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\enchantment\EnchantmentInstance;
use pocketmine\math\Vector3;
use pocketmine\nbt\BigEndianNBTStream;
use pocketmine\nbt\LittleEndianNBTStream;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\ByteTag;
@@ -45,6 +46,9 @@
use pocketmine\nbt\tag\NamedTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\network\mcpe\convert\ItemTypeDictionary;
use pocketmine\network\mcpe\convert\NetworkBlockMapping;
use pocketmine\network\mcpe\NetworkBinaryStream;
use pocketmine\Player;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\Binary;
@@ -128,11 +132,13 @@ public static function fromString(string $str, bool $multiple = false){
public static function initCreativeItems(){
self::clearCreativeItems();

$creativeItems = json_decode(file_get_contents(RESOURCE_PATH . "vanilla" . DIRECTORY_SEPARATOR . "creativeitems.json"), true);

foreach($creativeItems as $data){
$creativeItems = json_decode(file_get_contents(RESOURCE_PATH . "vanilla/creative_items.json"), true)["items"] ?? [];
foreach ($creativeItems as $data) {
$item = Item::jsonDeserialize($data);
if($item->getName() === "Unknown"){
if ($item === null) {
continue;
}
if ($item->getName() === "Unknown") {
continue;
}
self::addCreativeItem($item);
@@ -837,21 +843,24 @@ final public function jsonSerialize() : array{
* nbt_b64?: string
* } $data
*/
final public static function jsonDeserialize(array $data) : Item{
final public static function jsonDeserialize(array $data) : ?Item{
$id = ItemTypeDictionary::getInstance()->fromStringId($data["id"]);

$nbt = "";

//Backwards compatibility
if(isset($data["nbt"])){
$nbt = $data["nbt"];
}elseif(isset($data["nbt_hex"])){
$nbt = hex2bin($data["nbt_hex"]);
}elseif(isset($data["nbt_b64"])){
if(isset($data["nbt_b64"])){
$nbt = base64_decode($data["nbt_b64"], true);
}
if (isset($data["block_state_b64"])) {
$nbt_stream = new NetworkBinaryStream(base64_decode($data["block_state_b64"], true));
$nbt_root = $nbt_stream->getNbtCompoundRoot(new LittleEndianNBTStream);
$id = $nbt_root->getInt("block_id");
}

return ItemFactory::get(
(int) $data["id"],
(int) $id,
(int) ($data["damage"] ?? 0),
(int) ($data["count"] ?? 1),
(int) 1,
(string) $nbt
);
}
12 changes: 6 additions & 6 deletions src/pocketmine/level/Level.php
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@
use pocketmine\metadata\MetadataValue;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\convert\NetworkBlockMapping;
use pocketmine\network\mcpe\protocol\AddActorPacket;
use pocketmine\network\mcpe\protocol\BatchPacket;
use pocketmine\network\mcpe\protocol\DataPacket;
@@ -1071,10 +1071,10 @@ public function sendBlocks(array $target, array $blocks, int $flags = UpdateBloc
$pk->z = $b->z;

if($b instanceof Block){
$pk->blockRuntimeId = $b->getRuntimeId();
$pk->blockNetworkId = $b->getNetworkId();
}else{
$fullBlock = $this->getFullBlock($b->x, $b->y, $b->z);
$pk->blockRuntimeId = RuntimeBlockMapping::toStaticRuntimeId($fullBlock >> 4, $fullBlock & 0xf);
$pk->blockNetworkId = NetworkBlockMapping::toStaticNetworkId($fullBlock >> 4, $fullBlock & 0xf);
}

$pk->flags = $first ? $flags : UpdateBlockPacket::FLAG_NONE;
@@ -1093,10 +1093,10 @@ public function sendBlocks(array $target, array $blocks, int $flags = UpdateBloc
$pk->z = $b->z;

if($b instanceof Block){
$pk->blockRuntimeId = $b->getRuntimeId();
$pk->blockNetworkId = $b->getNetworkId();
}else{
$fullBlock = $this->getFullBlock($b->x, $b->y, $b->z);
$pk->blockRuntimeId = RuntimeBlockMapping::toStaticRuntimeId($fullBlock >> 4, $fullBlock & 0xf);
$pk->blockNetworkId = NetworkBlockMapping::toStaticNetworkId($fullBlock >> 4, $fullBlock & 0xf);
}

$pk->flags = $flags;
@@ -2109,7 +2109,7 @@ public function useItemOn(Vector3 $vector, Item &$item, int $face, Vector3 $clic
}

if($playSound){
$this->broadcastLevelSoundEvent($hand, LevelSoundEventPacket::SOUND_PLACE, $hand->getRuntimeId());
$this->broadcastLevelSoundEvent($hand, LevelSoundEventPacket::SOUND_PLACE, $hand->getNetworkId());
}

$item->pop();
2 changes: 1 addition & 1 deletion src/pocketmine/level/format/Chunk.php
Original file line number Diff line number Diff line change
@@ -914,7 +914,7 @@ private function networkSerializeBiomesAsPalette() : string{
/** @var string[]|null $biomeIdMap */
static $biomeIdMap = null;
if($biomeIdMap === null){
$biomeIdMapRaw = file_get_contents(RESOURCE_PATH . '/vanilla/biome_id_map.json');
$biomeIdMapRaw = file_get_contents(RESOURCE_PATH . '/vanilla_OLD/biome_id_map.json'); // TODO: DO LATER
if($biomeIdMapRaw === false) throw new AssumptionFailedError();
$biomeIdMapDecoded = json_decode($biomeIdMapRaw, true);
if(!is_array($biomeIdMapDecoded)) throw new AssumptionFailedError();
2 changes: 1 addition & 1 deletion src/pocketmine/level/particle/DestroyBlockParticle.php
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ class DestroyBlockParticle extends Particle{

public function __construct(Vector3 $pos, Block $b){
parent::__construct($pos->x, $pos->y, $pos->z);
$this->data = $b->getRuntimeId();
$this->data = $b->getNetworkId();
}

public function encode(){
4 changes: 2 additions & 2 deletions src/pocketmine/level/particle/FloatingTextParticle.php
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
use pocketmine\entity\Entity;
use pocketmine\entity\EntityIds;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\convert\NetworkBlockMapping;
use pocketmine\network\mcpe\protocol\AddActorPacket;
use pocketmine\network\mcpe\protocol\RemoveActorPacket;
use pocketmine\network\mcpe\protocol\types\entityProperty\EntityProperties;
@@ -99,7 +99,7 @@ public function encode(){
Entity::DATA_BOUNDING_BOX_WIDTH => [Entity::DATA_TYPE_FLOAT, 0.0],
Entity::DATA_BOUNDING_BOX_HEIGHT => [Entity::DATA_TYPE_FLOAT, 0.0],
Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, $name],
Entity::DATA_VARIANT =>[Entity::DATA_TYPE_INT, RuntimeBlockMapping::toStaticRuntimeId(BlockIds::AIR)],
Entity::DATA_VARIANT =>[Entity::DATA_TYPE_INT, NetworkBlockMapping::toStaticNetworkId(BlockIds::AIR)],
Entity::DATA_ALWAYS_SHOW_NAMETAG => [Entity::DATA_TYPE_BYTE, 1],
];

2 changes: 1 addition & 1 deletion src/pocketmine/level/particle/TerrainParticle.php
Original file line number Diff line number Diff line change
@@ -28,6 +28,6 @@

class TerrainParticle extends GenericParticle{
public function __construct(Vector3 $pos, Block $b){
parent::__construct($pos, Particle::TYPE_TERRAIN, $b->getRuntimeId());
parent::__construct($pos, Particle::TYPE_TERRAIN, $b->getNetworkId());
}
}
Loading