本文整理汇总了PHP中pocketmine\nbt\NBT::read方法的典型用法代码示例。如果您正苦于以下问题:PHP NBT::read方法的具体用法?PHP NBT::read怎么用?PHP NBT::read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\nbt\NBT
的用法示例。
在下文中一共展示了NBT::read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseCompoundTag
private static function parseCompoundTag(string $tag) : CompoundTag
{
if (self::$cachedParser === null) {
self::$cachedParser = new NBT(NBT::LITTLE_ENDIAN);
}
self::$cachedParser->read($tag);
return self::$cachedParser->getData();
}
示例2: __construct
public function __construct(Level $level, $path)
{
$this->level = $level;
$this->path = $path;
if (!file_exists($this->path)) {
mkdir($this->path, 0777, true);
}
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$nbt->read(substr(file_get_contents($this->getPath() . "level.dat"), 8));
$levelData = $nbt->getData();
if ($levelData instanceof CompoundTag) {
$this->levelData = $levelData;
if (!isset($this->levelData["GameRules"])) {
$this->levelData["GameRules"] = (new GameRules())->getRules();
}
} else {
throw new LevelException("Invalid level.dat");
}
if (!isset($this->levelData->generatorName)) {
$this->levelData->generatorName = new StringTag("generatorName", Generator::getGenerator("DEFAULT"));
}
if (!isset($this->levelData->generatorOptions)) {
$this->levelData->generatorOptions = new StringTag("generatorOptions", "");
}
$this->db = new \LevelDB($this->path . "db", ["compression" => LEVELDB_ZLIB_COMPRESSION]);
}
示例3: readMacro
public function readMacro($name)
{
if (!is_file($path = $this->getFile($name))) {
return null;
}
$string = file_get_contents($path);
$nbt = new NBT();
$type = ord(substr($string, 0, 1));
$string = substr($string, 1);
if ($type === 0) {
$nbt->read($string);
} else {
$nbt->readCompressed($string, $type);
}
$tag = $nbt->getData();
$author = $tag["author"];
$description = $tag["description"];
/** @var tag\Enum $tags */
$tags = $tag["ops"];
$ops = [];
/** @var tag\Compound $t */
foreach ($tags as $t) {
$type = $tag["type"];
if ($type === 1) {
$ops[] = new MacroOperation($t["delta"]);
} else {
$vectors = $t["vectors"];
/** @noinspection PhpParamsInspection */
$ops[] = new MacroOperation(new Vector3($vectors[0], $vectors[1], $vectors[2]), Block::get($t["blockID"], $t["blockDamage"]));
}
}
return new Macro(false, $ops, $author, $description);
}
示例4: fromFastBinary
/**
* @param string $data
* @param LevelProvider $provider
*
* @return Chunk
*/
public static function fromFastBinary($data, LevelProvider $provider = \null)
{
$nbt = new NBT(NBT::BIG_ENDIAN);
try {
$nbt->read($data);
$chunk = $nbt->getData();
if (!isset($chunk->Level) or !$chunk->Level instanceof Compound) {
return \null;
}
return new Chunk($provider instanceof LevelProvider ? $provider : Anvil::class, $chunk->Level);
} catch (\Exception $e) {
return \null;
}
}
示例5: fromBinary
/**
* @param string $data
* @param LevelProvider $provider
*
* @return Chunk
*/
public static function fromBinary($data, LevelProvider $provider = null)
{
try {
$chunkX = PHP_INT_SIZE === 8 ? unpack("V", substr($data, 0, 4))[1] << 32 >> 32 : unpack("V", substr($data, 0, 4))[1];
$chunkZ = PHP_INT_SIZE === 8 ? unpack("V", substr($data, 4, 4))[1] << 32 >> 32 : unpack("V", substr($data, 4, 4))[1];
$chunkData = substr($data, 8, -1);
$flags = ord(substr($data, -1));
$entities = null;
$tiles = null;
if ($provider instanceof LevelDB) {
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$entityData = $provider->getDatabase()->get(substr($data, 0, 8) . "2");
if ($entityData !== false and strlen($entityData) > 0) {
$nbt->read($entityData, true);
$entities = $nbt->getData();
if (!is_array($entities)) {
$entities = [$entities];
}
}
$tileData = $provider->getDatabase()->get(substr($data, 0, 8) . "1");
if ($tileData !== false and strlen($tileData) > 0) {
$nbt->read($tileData, true);
$tiles = $nbt->getData();
if (!is_array($tiles)) {
$tiles = [$tiles];
}
}
}
$chunk = new Chunk($provider instanceof LevelProvider ? $provider : LevelDB::class, $chunkX, $chunkZ, $chunkData, $entities, $tiles);
if ($flags & 0x1) {
$chunk->setGenerated();
}
if ($flags & 0x2) {
$chunk->setPopulated();
}
return $chunk;
} catch (\Exception $e) {
return null;
}
}
示例6: serverToInterface
//.........这里部分代码省略.........
$pk->windowID = $packet->windowid;
return $pk;
case Info::CONTAINER_SET_SLOT_PACKET:
echo "ContainerSetSlotPacket: 0x".bin2hex(chr($packet->windowid))."\n";
$pk = new SetSlotPacket();
$pk->windowID = $packet->windowid;
if($pk->windowID === 0x00){
$pk->slot = $packet->slot + 36;
}elseif($pk->windowID === 0x78){
$pk->windowID = 0;
$pk->slot = $packet->slot + 5;
}else{
$pk->slot = $packet->slot;
}
$pk->item = $packet->item;
return $pk;
case Info::CONTAINER_SET_CONTENT_PACKET://Bug
echo "ContainerSetContentPacket: 0x".bin2hex(chr($packet->windowid))."\n";
if($packet->windowid !== 0x79 and $packet->windowid !== 0x78){
$pk = new WindowItemsPacket();
$pk->windowID = 0;
for($i = 0; $i < 5; ++$i){
$pk->items[] = Item::get(Item::AIR, 0, 0);
}
$pk->items[] = $player->getInventory()->getHelmet();
$pk->items[] = $player->getInventory()->getChestplate();
$pk->items[] = $player->getInventory()->getLeggings();
$pk->items[] = $player->getInventory()->getBoots();
if($player->getGamemode() === 0){
for($i = 9; $i < 36; ++$i){
$pk->items[] = $player->getInventory()->getItem($i);
}
}else{
for($i = 0; $i < 27; ++$i){
$pk->items[] = Item::get(Item::AIR, 0, 0);
}
}
for($i = 0; $i < 9; ++$i){
$pk->items[] = $player->getInventory()->getItem($i);
}
return $pk;
}
return null;*/
case Info::CRAFTING_DATA_PACKET:
$player->setSetting(["Recipes" => $packet->entries, "cleanRecipes" => $packet->cleanRecipes]);
return null;
case Info::BLOCK_ENTITY_DATA_PACKET:
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$nbt->read($packet->namedtag);
$nbt = $nbt->getData();
if ($nbt["id"] !== Tile::SIGN) {
return null;
} else {
$index = Level::chunkHash($packet->x >> 4, $packet->z >> 4);
if (isset($player->usedChunks[$index]) and $player->usedChunks[$index]) {
$pk = new UpdateSignPacket();
$pk->x = $packet->x;
$pk->y = $packet->y;
$pk->z = $packet->z;
$pk->line1 = TextFormat::toJSON($nbt["Text1"]);
$pk->line2 = TextFormat::toJSON($nbt["Text2"]);
$pk->line3 = TextFormat::toJSON($nbt["Text3"]);
$pk->line4 = TextFormat::toJSON($nbt["Text4"]);
return $pk;
}
}
return null;
case Info::SET_DIFFICULTY_PACKET:
$pk = new ServerDifficultyPacket();
$pk->difficulty = $packet->difficulty;
return $pk;
case Info::SET_PLAYER_GAMETYPE_PACKET:
$packets = [];
$pk = new PlayerAbilitiesPacket();
$pk->flyingSpeed = 0.05;
$pk->walkingSpeed = 0.1;
$pk->canFly = ($player->getGamemode() & 0x1) > 0;
$pk->damageDisabled = ($player->getGamemode() & 0x1) > 0;
$pk->isFlying = false;
$pk->isCreative = ($player->getGamemode() & 0x1) > 0;
$packets[] = $pk;
$pk = new ChangeGameStatePacket();
$pk->reason = 3;
$pk->value = $player->getGamemode();
$packets[] = $pk;
return $packets;
case Info::PLAY_STATUS_PACKET:
case Info::PLAYER_LIST_PACKET:
case Info::ADVENTURE_SETTINGS_PACKET:
case Info::FULL_CHUNK_DATA_PACKET:
case Info::BATCH_PACKET:
return null;
default:
echo "[Send] 0x" . bin2hex(chr($packet->pid())) . "\n";
return null;
}
}
示例7: loadChunk
public function loadChunk($X, $Z)
{
if ($this->isChunkLoaded($X, $Z)) {
return true;
}
$index = self::getIndex($X, $Z);
$path = $this->getChunkPath($X, $Z);
if (!file_exists($path)) {
if ($this->generateChunk($X, $Z) === false) {
return false;
}
if ($this->isGenerating === 0) {
$this->populateChunk($X, $Z);
}
return true;
}
$chunk = file_get_contents($path);
if ($chunk === false) {
return false;
}
$chunk = zlib_decode($chunk);
$offset = 0;
$this->chunkInfo[$index] = [0 => ord($chunk[0]), 1 => Binary::readInt(substr($chunk, 1, 4))];
$offset += 5;
$len = Binary::readInt(substr($chunk, $offset, 4));
$offset += 4;
$nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->read(substr($chunk, $offset, $len));
$this->chunkInfo[$index][2] = $nbt->getData();
$offset += $len;
$this->chunks[$index] = [];
$this->chunkChange[$index] = [-1 => false];
$this->chunkInfo[$index][3] = substr($chunk, $offset, 256);
//Biome data
$offset += 256;
for ($Y = 0; $Y < 8; ++$Y) {
if (($this->chunkInfo[$index][0] & 1 << $Y) !== 0) {
// 4096 + 2048 + 2048, Block Data, Meta, Light
if (strlen($this->chunks[$index][$Y] = substr($chunk, $offset, 8192)) < 8192) {
MainLogger::getLogger()->notice("Empty corrupt chunk detected [{$X},{$Z},:{$Y}], recovering contents");
$this->fillMiniChunk($X, $Z, $Y);
}
$offset += 8192;
} else {
$this->chunks[$index][$Y] = false;
}
}
if ($this->isGenerating === 0 and !$this->isPopulated($X, $Z)) {
$this->populateChunk($X, $Z);
}
return true;
}
示例8: handleDataPacket
//.........这里部分代码省略.........
foreach ($used as $slot => $count) {
if ($count === 0) {
continue;
}
$item = $this->inventory->getItem($slot);
if ($item->getCount() > $count) {
$newItem = clone $item;
$newItem->setCount($item->getCount() - $count);
} else {
$newItem = Item::get(Item::AIR, 0, 0);
}
$this->inventory->setItem($slot, $newItem);
}
$extraItem = $this->inventory->addItem($recipe->getResult());
if (count($extraItem) > 0) {
foreach ($extraItem as $item) {
$this->level->dropItem($this, $item);
}
}
switch ($recipe->getResult()->getId()) {
case Item::WORKBENCH:
$this->awardAchievement("buildWorkBench");
break;
case Item::WOODEN_PICKAXE:
$this->awardAchievement("buildPickaxe");
break;
case Item::FURNACE:
$this->awardAchievement("buildFurnace");
break;
case Item::WOODEN_HOE:
$this->awardAchievement("buildHoe");
break;
case Item::BREAD:
$this->awardAchievement("makeBread");
break;
case Item::CAKE:
//TODO: detect complex recipes like cake that leave remains
$this->awardAchievement("bakeCake");
$this->inventory->addItem(Item::get(Item::BUCKET, 0, 3));
break;
case Item::STONE_PICKAXE:
case Item::GOLD_PICKAXE:
case Item::IRON_PICKAXE:
case Item::DIAMOND_PICKAXE:
$this->awardAchievement("buildBetterPickaxe");
break;
case Item::WOODEN_SWORD:
$this->awardAchievement("buildSword");
break;
case Item::DIAMOND:
$this->awardAchievement("diamond");
break;
}
break;
case ProtocolInfo::CONTAINER_SET_SLOT_PACKET:
if ($this->spawned === false or $this->blocked === true or !$this->isAlive()) {
break;
}
if ($packet->slot < 0) {
break;
}
if ($packet->windowid === 0) {
//Our inventory
if ($packet->slot >= $this->inventory->getSize()) {
break;
}
示例9: handleDataPacket
//.........这里部分代码省略.........
foreach ($this->currentTransaction->getTransactions() as $ts) {
$inv = $ts->getInventory();
if ($inv instanceof FurnaceInventory) {
if ($ts->getSlot() === 2) {
switch ($inv->getResult()->getId()) {
case Item::IRON_INGOT:
$this->awardAchievement("acquireIron");
break;
}
}
}
}
$this->currentTransaction = null;
} elseif ($packet->windowid == 0) {
//Try crafting
$craftingGroup = new CraftingTransactionGroup($this->currentTransaction);
if ($craftingGroup->canExecute()) {
//We can craft!
$recipe = $craftingGroup->getMatchingRecipe();
if ($recipe instanceof BigShapelessRecipe and $this->craftingType !== 1) {
break;
} elseif ($recipe instanceof StonecutterShapelessRecipe and $this->craftingType !== 2) {
break;
}
if ($craftingGroup->execute()) {
switch ($craftingGroup->getResult()->getId()) {
case Item::WORKBENCH:
$this->awardAchievement("buildWorkBench");
break;
case Item::WOODEN_PICKAXE:
$this->awardAchievement("buildPickaxe");
break;
case Item::FURNACE:
$this->awardAchievement("buildFurnace");
break;
case Item::WOODEN_HOE:
$this->awardAchievement("buildHoe");
break;
case Item::BREAD:
$this->awardAchievement("makeBread");
break;
case Item::CAKE:
//TODO: detect complex recipes like cake that leave remains
$this->awardAchievement("bakeCake");
$this->inventory->addItem(Item::get(Item::BUCKET, 0, 3), $this);
break;
case Item::STONE_PICKAXE:
case Item::GOLD_PICKAXE:
case Item::IRON_PICKAXE:
case Item::DIAMOND_PICKAXE:
$this->awardAchievement("buildBetterPickaxe");
break;
case Item::WOODEN_SWORD:
$this->awardAchievement("buildSword");
break;
case Item::DIAMOND:
$this->awardAchievement("diamond");
break;
}
}
$this->currentTransaction = null;
}
}
break;
case ProtocolInfo::SEND_INVENTORY_PACKET:
//TODO, Mojang, enable this ´^_^`
if ($this->spawned === false) {
break;
}
break;
case ProtocolInfo::ENTITY_DATA_PACKET:
if ($this->spawned === false or $this->blocked === true or $this->dead === true) {
break;
}
$this->craftingType = 0;
$t = $this->level->getTile(new Vector3($packet->x, $packet->y, $packet->z));
if ($t instanceof Sign) {
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$nbt->read($packet->namedtag);
$nbt = $nbt->getData();
if ($nbt["id"] !== Tile::SIGN) {
$t->spawnTo($this);
} else {
$ev = new SignChangeEvent($t->getBlock(), $this, [$nbt["Text1"], $nbt["Text2"], $nbt["Text3"], $nbt["Text4"]]);
if (!isset($t->namedtag->Creator) or $t->namedtag["Creator"] !== $this->username) {
$ev->setCancelled(true);
}
$this->server->getPluginManager()->callEvent($ev);
if (!$ev->isCancelled()) {
$t->setText($ev->getLine(0), $ev->getLine(1), $ev->getLine(2), $ev->getLine(3));
} else {
$t->spawnTo($this);
}
}
}
break;
default:
break;
}
}
示例10: handleDataPacket
//.........这里部分代码省略.........
continue;
}
$item = $this->inventory->getItem($slot);
if ($item->getCount() > $count) {
$newItem = clone $item;
$newItem->setCount($item->getCount() - $count);
} else {
$newItem = Item::get(Item::AIR, 0, 0);
}
$this->inventory->setItem($slot, $newItem);
}
$extraItem = $this->inventory->addItem($recipe->getResult());
if (count($extraItem) > 0 and !$this->isCreative()) {
//Could not add all the items to our inventory (not enough space)
foreach ($extraItem as $item) {
$this->level->dropItem($this, $item);
}
}
}
switch ($recipe->getResult()->getId()) {
case Item::WORKBENCH:
$this->awardAchievement("buildWorkBench");
break;
case Item::WOODEN_PICKAXE:
$this->awardAchievement("buildPickaxe");
break;
case Item::FURNACE:
$this->awardAchievement("buildFurnace");
break;
case Item::WOODEN_HOE:
$this->awardAchievement("buildHoe");
break;
case Item::BREAD:
$this->awardAchievement("makeBread");
break;
case Item::CAKE:
//TODO: detect complex recipes like cake that leave remains
$this->awardAchievement("bakeCake");
$this->inventory->addItem(Item::get(Item::BUCKET, 0, 3));
break;
case Item::STONE_PICKAXE:
case Item::GOLD_PICKAXE:
case Item::IRON_PICKAXE:
case Item::DIAMOND_PICKAXE:
$this->awardAchievement("buildBetterPickaxe");
break;
case Item::WOODEN_SWORD:
$this->awardAchievement("buildSword");
break;
case Item::DIAMOND:
$this->awardAchievement("diamond");
break;
}
break;
case ProtocolInfo::CONTAINER_SET_SLOT_PACKET:
if ($this->spawned === false or $this->blocked === true or !$this->isAlive()) {
break;
}
if ($packet->slot < 0) {
break;
}
if ($packet->windowid === 0) {
//Our inventory
if ($packet->slot >= $this->inventory->getSize()) {
break;
}
示例11: fromBinary
/**
* @param string $data
* @param LevelProvider $provider
*
* @return Chunk
*/
public static function fromBinary($data, LevelProvider $provider = \null)
{
try {
$chunkX = \unpack("V", \substr($data, 0, 4))[1];
$chunkZ = \unpack("V", \substr($data, 4, 4))[1];
$chunkData = \substr($data, 8, -1);
$flags = \ord(\substr($data, -1));
$entities = \null;
$tiles = \null;
$extraData = [];
if ($provider instanceof LevelDB) {
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$entityData = $provider->getDatabase()->get(\substr($data, 0, 8) . LevelDB::ENTRY_ENTITIES);
if ($entityData !== \false and \strlen($entityData) > 0) {
$nbt->read($entityData, \true);
$entities = $nbt->getData();
if (!\is_array($entities)) {
$entities = [$entities];
}
}
$tileData = $provider->getDatabase()->get(\substr($data, 0, 8) . LevelDB::ENTRY_TILES);
if ($tileData !== \false and \strlen($tileData) > 0) {
$nbt->read($tileData, \true);
$tiles = $nbt->getData();
if (!\is_array($tiles)) {
$tiles = [$tiles];
}
}
$tileData = $provider->getDatabase()->get(\substr($data, 0, 8) . LevelDB::ENTRY_EXTRA_DATA);
if ($tileData !== \false and \strlen($tileData) > 0) {
$stream = new BinaryStream($tileData);
$count = $stream->getInt();
for ($i = 0; $i < $count; ++$i) {
$key = $stream->getInt();
$value = $stream->getShort(\false);
$extraData[$key] = $value;
}
}
}
$chunk = new Chunk($provider instanceof LevelProvider ? $provider : LevelDB::class, $chunkX, $chunkZ, $chunkData, $entities, $tiles);
if ($flags & 0x1) {
$chunk->setGenerated();
}
if ($flags & 0x2) {
$chunk->setPopulated();
}
if ($flags & 0x4) {
$chunk->setLightPopulated();
}
return $chunk;
} catch (\Exception $e) {
return \null;
}
}
示例12: handleDataPacket
//.........这里部分代码省略.........
foreach ($used as $slot => $count) {
if ($count === 0) {
continue;
}
$item = $this->inventory->getItem($slot);
if ($item->getCount() > $count) {
$newItem = clone $item;
$newItem->setCount($item->getCount() - $count);
} else {
$newItem = Item::get(Item::AIR, 0, 0);
}
$this->inventory->setItem($slot, $newItem);
}
$extraItem = $this->inventory->addItem($recipe->getResult());
if (count($extraItem) > 0) {
foreach ($extraItem as $item) {
$this->level->dropItem($this, $item);
}
}
switch ($recipe->getResult()->getId()) {
case Item::WORKBENCH:
$this->awardAchievement("buildWorkBench");
break;
case Item::WOODEN_PICKAXE:
$this->awardAchievement("buildPickaxe");
break;
case Item::FURNACE:
$this->awardAchievement("buildFurnace");
break;
case Item::WOODEN_HOE:
$this->awardAchievement("buildHoe");
break;
case Item::BREAD:
$this->awardAchievement("makeBread");
break;
case Item::CAKE:
//TODO: detect complex recipes like cake that leave remains
$this->awardAchievement("bakeCake");
$this->inventory->addItem(Item::get(Item::BUCKET, 0, 3));
break;
case Item::STONE_PICKAXE:
case Item::GOLD_PICKAXE:
case Item::IRON_PICKAXE:
case Item::DIAMOND_PICKAXE:
$this->awardAchievement("buildBetterPickaxe");
break;
case Item::WOODEN_SWORD:
$this->awardAchievement("buildSword");
break;
case Item::DIAMOND:
$this->awardAchievement("diamond");
break;
}
break;
case ProtocolInfo::CONTAINER_SET_SLOT_PACKET:
if ($this->spawned === false or $this->blocked === true or !$this->isAlive()) {
break;
}
if ($packet->slot < 0) {
break;
}
if ($packet->windowid === 0) {
//Our inventory
if ($packet->slot >= $this->inventory->getSize()) {
break;
}
示例13: handleDataPacket
//.........这里部分代码省略.........
if ($this->currentTransaction->execute()) {
foreach ($this->currentTransaction->getTransactions() as $ts) {
$inv = $ts->getInventory();
if ($inv instanceof FurnaceInventory) {
if ($ts->getSlot() === 2) {
switch ($inv->getResult()->getId()) {
case Item::IRON_INGOT:
$this->awardAchievement("acquireIron");
break;
}
}
}
}
}
$this->currentTransaction = null;
} elseif ($packet->windowid == 0) {
//Try crafting
$craftingGroup = new CraftingTransactionGroup($this->currentTransaction);
if ($craftingGroup->canExecute()) {
//We can craft!
$recipe = $craftingGroup->getMatchingRecipe();
if ($recipe instanceof BigShapelessRecipe and $this->craftingType !== 1) {
break;
} elseif ($recipe instanceof StonecutterShapelessRecipe and $this->craftingType !== 2) {
break;
}
if ($craftingGroup->execute()) {
switch ($craftingGroup->getResult()->getId()) {
case Item::WORKBENCH:
$this->awardAchievement("buildWorkBench");
break;
case Item::WOODEN_PICKAXE:
$this->awardAchievement("buildPickaxe");
break;
case Item::FURNACE:
$this->awardAchievement("buildFurnace");
break;
case Item::WOODEN_HOE:
$this->awardAchievement("buildHoe");
break;
case Item::BREAD:
$this->awardAchievement("makeBread");
break;
case Item::CAKE:
//TODO: detect complex recipes like cake that leave remains
$this->awardAchievement("bakeCake");
$this->inventory->addItem(Item::get(Item::BUCKET, 0, 3));
break;
case Item::STONE_PICKAXE:
case Item::GOLD_PICKAXE:
case Item::IRON_PICKAXE:
case Item::DIAMOND_PICKAXE:
$this->awardAchievement("buildBetterPickaxe");
break;
case Item::WOODEN_SWORD:
$this->awardAchievement("buildSword");
break;
case Item::DIAMOND:
$this->awardAchievement("diamond");
break;
}
}
$this->currentTransaction = null;
}
}
break;
case ProtocolInfo::TILE_ENTITY_DATA_PACKET:
if ($this->spawned === false or $this->blocked === true or $this->dead === true) {
break;
}
$this->craftingType = 0;
$pos = new Vector3($packet->x, $packet->y, $packet->z);
if ($pos->distanceSquared($this) > 10000) {
break;
}
$t = $this->level->getTile($pos);
if ($t instanceof Sign) {
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$nbt->read($packet->namedtag);
$nbt = $nbt->getData();
if ($nbt["id"] !== Tile::SIGN) {
$t->spawnTo($this);
} else {
$ev = new SignChangeEvent($t->getBlock(), $this, [TextFormat::clean($nbt["Text1"], $this->removeFormat), TextFormat::clean($nbt["Text2"], $this->removeFormat), TextFormat::clean($nbt["Text3"], $this->removeFormat), TextFormat::clean($nbt["Text4"], $this->removeFormat)]);
if (!isset($t->namedtag->Creator) or $t->namedtag["Creator"] !== $this->username) {
$ev->setCancelled(true);
}
$this->server->getPluginManager()->callEvent($ev);
if (!$ev->isCancelled()) {
$t->setText($ev->getLine(0), $ev->getLine(1), $ev->getLine(2), $ev->getLine(3));
} else {
$t->spawnTo($this);
}
}
}
break;
default:
break;
}
}
示例14: import
public function import()
{
if (file_exists($this->path . "tileEntities.dat")) {
//OldPM
$level = unserialize(file_get_contents($this->path . "level.dat"));
MainLogger::getLogger()->info("Importing OldPM level \"" . $level["LevelName"] . "\" to PMF format");
$entities = new Config($this->path . "entities.yml", Config::YAML, unserialize(file_get_contents($this->path . "entities.dat")));
$entities->save();
$tiles = new Config($this->path . "tiles.yml", Config::YAML, unserialize(file_get_contents($this->path . "tileEntities.dat")));
$tiles->save();
} elseif (file_exists($this->path . "chunks.dat") and file_exists($this->path . "level.dat")) {
//Pocket
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$nbt->read(substr(file_get_contents($this->path . "level.dat"), 8));
$level = $nbt->getData();
if ($level["LevelName"] == "") {
$level["LevelName"] = "world" . time();
}
MainLogger::getLogger()->info("Importing Pocket level \"" . $level->LevelName . "\" to PMF format");
unset($level->Player);
$nbt->read(substr(file_get_contents($this->path . "entities.dat"), 12));
$entities = $nbt->getData();
if (!isset($entities->TileEntities)) {
$entities->TileEntities = [];
}
$tiles = $entities->TileEntities;
$entities = $entities->Entities;
$entities = new Config($this->path . "entities.yml", Config::YAML, $entities);
$entities->save();
$tiles = new Config($this->path . "tiles.yml", Config::YAML, $tiles);
$tiles->save();
} else {
return false;
}
$pmf = new LevelFormat($this->path . "level.pmf", ["name" => $level->LevelName, "seed" => $level->RandomSeed, "time" => $level->Time, "spawnX" => $level->SpawnX, "spawnY" => $level->SpawnY, "spawnZ" => $level->SpawnZ, "height" => 8, "generator" => "default", "generatorSettings" => "", "extra" => ""]);
$chunks = new PocketChunkParser();
$chunks->loadFile($this->path . "chunks.dat");
$chunks->loadMap();
for ($Z = 0; $Z < 16; ++$Z) {
for ($X = 0; $X < 16; ++$X) {
$chunk = [0 => "", 1 => "", 2 => "", 3 => "", 4 => "", 5 => "", 6 => "", 7 => ""];
$pmf->initCleanChunk($X, $Z);
for ($z = 0; $z < 16; ++$z) {
for ($x = 0; $x < 16; ++$x) {
$block = $chunks->getChunkColumn($X, $Z, $x, $z, 0);
$meta = $chunks->getChunkColumn($X, $Z, $x, $z, 1);
for ($Y = 0; $Y < 8; ++$Y) {
$chunk[$Y] .= substr($block, $Y << 4, 16);
$chunk[$Y] .= substr($meta, $Y << 3, 8);
$chunk[$Y] .= "";
}
}
}
foreach ($chunk as $Y => $data) {
$pmf->setMiniChunk($X, $Z, $Y, $data);
}
$pmf->setPopulated($X, $Z);
$pmf->saveChunk($X, $Z);
}
MainLogger::getLogger()->notice("Importing level " . ceil(($Z + 1) / 0.16) . "%");
}
$chunks->map = null;
$chunks = null;
@unlink($this->path . "level.dat");
@unlink($this->path . "level.dat_old");
@unlink($this->path . "player.dat");
@unlink($this->path . "entities.dat");
@unlink($this->path . "chunks.dat");
@unlink($this->path . "chunks.dat.gz");
@unlink($this->path . "tiles.dat");
unset($chunks, $level, $entities, $tiles, $nbt);
return true;
}
示例15: handleDataPacket
//.........这里部分代码省略.........
foreach ($used as $slot => $count) {
if ($count === 0) {
continue;
}
$item = $this->inventory->getItem($slot);
if ($item->getCount() > $count) {
$newItem = clone $item;
$newItem->setCount($item->getCount() - $count);
} else {
$newItem = Item::get(Item::AIR, 0, 0);
}
$this->inventory->setItem($slot, $newItem);
}
$extraItem = $this->inventory->addItem($recipe->getResult());
if (count($extraItem) > 0) {
foreach ($extraItem as $item) {
$this->level->dropItem($this, $item);
}
}
switch ($recipe->getResult()->getId()) {
case Item::WORKBENCH:
$this->awardAchievement("buildWorkBench");
break;
case Item::WOODEN_PICKAXE:
$this->awardAchievement("buildPickaxe");
break;
case Item::FURNACE:
$this->awardAchievement("buildFurnace");
break;
case Item::WOODEN_HOE:
$this->awardAchievement("buildHoe");
break;
case Item::BREAD:
$this->awardAchievement("makeBread");
break;
case Item::CAKE:
//TODO: detect complex recipes like cake that leave remains
$this->awardAchievement("bakeCake");
$this->inventory->addItem(Item::get(Item::BUCKET, 0, 3));
break;
case Item::STONE_PICKAXE:
case Item::GOLD_PICKAXE:
case Item::IRON_PICKAXE:
case Item::DIAMOND_PICKAXE:
$this->awardAchievement("buildBetterPickaxe");
break;
case Item::WOODEN_SWORD:
$this->awardAchievement("buildSword");
break;
case Item::DIAMOND:
$this->awardAchievement("diamond");
break;
}
break;
case ProtocolInfo::CONTAINER_SET_SLOT_PACKET:
if ($this->spawned === false or $this->blocked === true or !$this->isAlive()) {
break;
}
if ($packet->slot < 0) {
break;
}
if ($packet->windowid === 0) {
//Our inventory
if ($packet->slot >= $this->inventory->getSize()) {
break;
}