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

addTimings || Добавление таймингов в ядро #1050

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion src/pocketmine/item/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ private static function writeCompound(Compound $tag){
const CLOCK = 347;
const GLOWSTONE_DUST = 348;
const RAW_FISH = 349;
const COOKED_FISH = 350;
const COOKED_FISH = 350;
const DYE = 351;
const BONE = 352;
const SUGAR = 353;
Expand Down Expand Up @@ -504,6 +504,7 @@ private static function writeCompound(Compound $tag){
const PRISMARINE_SHARD = 409;
const HOPPER = 410;
const RAW_RABBIT = 411;

const COOKED_RABBIT = 412;
const RABBIT_STEW = 413;
const RABBIT_FOOT = 414;
Expand Down Expand Up @@ -822,6 +823,7 @@ private static function writeCompound(Compound $tag){
348 => "Glowstone Dust",
349 => "Raw Fish",
350 => "Cooked Fish",

351 => "Dye",
352 => "Bone",
353 => "Sugar",
Expand Down
281 changes: 281 additions & 0 deletions src/pocketmine/item/ItemNew.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
<?php

namespace pocketmine\item;

class ItemNew {

const NEW_IRON_SHOVEL = 296;
const NEW_IRON_PICKAXE = 297;
const NEW_IRON_AXE = 298;
const NEW_FLINT_AND_STEEL = 299;
const NEW_APPLE = 257;
const NEW_BOW = 300;
const NEW_ARROW = 301;
const NEW_COAL = 302;
const NEW_DIAMOND = 304;
const NEW_IRON_INGOT = 305;
const NEW_GOLD_INGOT = 306;
const NEW_IRON_SWORD = 307;
const NEW_WOODEN_SWORD = 308;
const NEW_WOODEN_SHOVEL = 309;
const NEW_WOODEN_PICKAXE = 310;
const WOODEN_AXE = 311;

const NEW_STONE_SWORD = 312;
const NEW_STONE_SHOVEL = 313;
const NEW_STONE_PICKAXE = 314;
const NEW_STONE_AXE = 315;
const NEW_DIAMOND_SWORD = 316;
const NEW_DIAMOND_SHOVEL = 317;
const NEW_DIAMOND_PICKAXE = 318;
const NEW_DIAMOND_AXE = 319;
const NEW_STICK = 320;
const NEW_STICKS = 320;
const NEW_BOWL = 321;
const NEW_MUSHROOM_STEW = 260;
const NEW_GOLDEN_SWORD = 322;
const NEW_GOLDEN_SHOVEL = 323;
const NEW_GOLDEN_PICKAXE = 324;
const NEW_GOLDEN_AXE = 325;
const NEW_STRING = 326;
const NEW_FEATHER = 327;
const NEW_GUNPOWDER = 328;
const NEW_WOODEN_HOE = 329;
const NEW_STONE_HOE = 330;
const NEW_IRON_HOE = 331;
const NEW_DIAMOND_HOE = 332;
const NEW_GOLDEN_HOE = 333;
const NEW_WHEAT_SEEDS = 291;
const NEW_WHEAT = 334;
const NEW_BREAD = 261;
const NEW_LEATHER_CAP = 335;
const NEW_LEATHER_TUNIC = 336;
const NEW_LEATHER_PANTS = 337;
const NEW_LEATHER_BOOTS = 338;
const NEW_CHAIN_HELMET = 339;
const NEW_CHAIN_CHESTPLATE = 340;
const NEW_CHAIN_LEGGINGS = 341;
const NEW_CHAIN_BOOTS = 342;
const NEW_IRON_HELMET = 343;
const NEW_IRON_CHESTPLATE = 344;
const NEW_IRON_LEGGINGS = 345;
const NEW_IRON_BOOTS = 346;
const NEW_DIAMOND_HELMET = 347;
const NEW_DIAMOND_CHESTPLATE = 348;
const NEW_DIAMOND_LEGGINGS = 349;
const NEW_DIAMOND_BOOTS = 350;
const NEW_GOLD_HELMET = 351;
const NEW_GOLD_CHESTPLATE = 352;
const NEW_GOLD_LEGGINGS = 353;
const NEW_GOLD_BOOTS = 354;
const NEW_FLINT = 356;
const NEW_RAW_PORKCHOP = 262;
const NEW_COOKED_PORKCHOP = 263;
const NEW_PAINTING = 357;
const NEW_GOLDEN_APPLE = 258;
const NEW_WOODEN_DOOR = 359;
const NEW_BUCKET = 360;
const NEW_MINECART = 368;
const NEW_SADDLE = 369;
const NEW_IRON_DOOR = 370;
const NEW_REDSTONE_DUST = 371;
const NEW_SNOWBALL = 372;
const NEW_BOAT = 612;
const NEW_LEATHER = 379;
const NEW_BRICK = 381;
const NEW_CLAY = 382;
const NEW_PAPER = 384;
const NEW_BOOK = 385;
const NEW_SLIMEBALL = 386;
const NEW_MINECART_WITH_CHEST = 387;
const NEW_EGG = 388;
const NEW_COMPASS = 389;
const NEW_FISHING_ROD = 390;
const NEW_CLOCK = 391;
const NEW_GLOWSTONE_DUST = 392;
const NEW_DYE = 613;
const NEW_BLACK_DYE = 393; //meta 16
const NEW_RED_DYE = 394; // meta 1
const NEW_GREEN_DYE = 395; // meta 2
const NEW_BROWN_DYE = 396; //meta 17
const NEW_BLUE_DYE = 397; // meta 18
const NEW_PURPLE_DYE = 398; //meta 5
const NEW_CYAN_DYE = 399; //meta 6
const NEW_LIGHT_GRAY_DYE = 400; //meta 7
const NEW_GRAY_DYE = 401; //meta 8
const NEW_PINK_DYE = 402; // meta 9
const NEW_LIME_DYE = 403; // meta 10
const NEW_YELLOW_DYE = 404; // meta 11
const NEW_LIGHT_BLUE_DYE = 405; // meta 12
const NEW_MAGENTA_DYE = 406; // meta 13
const NEW_ORANGE_DYE = 407; // meta 14
const NEW_WHITE_DYE = 408; // meta 19
const NEW_BONE_MEAL = 409; //meta 15
const NEW_COCOA_BEANS = 410; //meta 3
const NEW_INC_SAC = 411; // meta 11
const NEW_LAPIS_LAZULI = 412; // meta 4
const NEW_BONE = 413;
const NEW_SUGAR = 414;
const NEW_CAKE = 415;
const NEW_BED = 416;
const NEW_REDSTONE_REPEATER = 417;
const NEW_COOKIE = 271;
const NEW_SHEARS = 419;
const NEW_PUMPKIN_SEEDS = 292;
const NEW_MELON_SEEDS = 293;
const NEW_RAW_BEEF = 273;
const NEW_COOKED_BEEF = 274;
const NEW_RAW_CHICKEN = 275;
const NEW_COOKED_CHICKEN = 276;
const NEW_ROTTEN_FLESH = 277;
const NEW_ENDER_PERL = 420;
const NEW_BLAZE_ROD = 421;
const NEW_GHAST_TEAR = 422;
const NEW_GOLDEN_NUGGET = 423;
const NEW_NETHER_WART = 294;
const NEW_POTION = 424;
const NEW_GLASS_BOTTLE = 425;
const NEW_SPIDER_EYE = 278;
const NEW_FERMENTED_SPIDER_EYE = 426;
const NEW_BLAZE_POWDER = 427;
const NEW_MAGMA_CREAM = 428;
const NEW_BREWING_STAND = 429;
const NEW_CAULDRON = 430;
const NEW_EYE_OF_ENDER = 431;
const NEW_SPAWN_EGG = 615;
const NEW_BOTTLE_ENCHANTING = 498;
const NEW_WRITABLE_BOOK = 500;
const NEW_WRITTEN_BOOK = 501;
const NEW_EMERALD = 502;
const NEW_ITEM_FRAME = 503;
const NEW_FLOWER_POT = 504;
const NEW_CARROTS = 279;
const NEW_POTATOES = 280;
const NEW_BAKED_POTATOES = 281;
const NEW_POISONOUS_POTATO = 282;
const NEW_GOLDEN_CARROT = 283;
const NEW_MOB_HEAD = 506;
const NEW_PUMPKIN_PIE = 284;
const NEW_ENCHANTING_BOOK = 511;
const NEW_REDSTONE_COMPARATOR = 512;
const NEW_NETHER_BRICK = 513;
const NEW_NETHER_QUARTZ = 514;
const NEW_MINECART_WITH_TNT = 515;
const NEW_MINECART_WITH_HOPPER = 516;
const NEW_PRISMARINE_SHARD = 555;
const NEW_HOPPER = 517;
const NEW_RAW_RABBIT = 288;
const NEW_COOKED_RABBIT = 289;
const NEW_RABBIT_STEW = 290;
const NEW_RABBIT_FOOT = 518;
const NEW_RABBIT_HIDE = 519;
const NEW_LEAD = 537;
const NEW_NAME_TAG = 538;
const NEW_PRISMARINE_CRYSTAL = 539;
const NEW_END_CRYSTAL = 616;
const NEW_SPRUCE_DOOR = 543;
const NEW_BIRCH_DOOR = 544;
const NEW_JUNGLE_DOOR = 545;
const NEW_ACACIA_DOOR = 546;
const NEW_DARK_OAK_DOOR = 547;
const NEW_CHORUS_FRUIT = 548;
const NEW_DRAGONS_BREATH = 550;
const NEW_SPLASH_POTION = 551;
const NEW_LINGERING_POTION = 552;
const NEW_ELYTRA = 554;
const NEW_SHULKER_SHELL = 556;
const NEW_IRON_NUGGET = 559;
const NEW_BEETROOT = 285;
const NEW_BEETROOT_SEED = 295;
const NEW_BEETROOT_SOUP = 286;
const NEW_RAW_SALMON = 265;
const NEW_PUFFERFISH = 267;
const NEW_COOKED_SALMON = 269;
const NEW_CAMERA = 583;
const NEW_SIGN = 358;
const NEW_SUGAR_CANES = 83;
const NEW_RAW_FISH = 264;
const NEW_COOKED_FISH = 268;
const NEW_MELON_SLICE = 272;
const NEW_EMPTY_MAP = 505;
const NEW_CARROT_ON_STICK = 507;
const NEW_LEATHER_HORSE_ARMOR = 520;
const NEW_IRON_HORSE_ARMOR = 521;
const NEW_GOLDEN_HORSE_ARMOR = 522;
const NEW_DIAMOND_HORSE_ARMOR = 523;
const NEW_RAW_MUTTON = 540;
const NEW_COOKED_MUTTON = 541;
const NEW_CLOWNFISH = 266;
const NEW_ENCHANTED_GOLDEN_APPLE = 259;
const NEW_GLISTERING_MELON = 432;
const NEW_OAK_WOOD_STAIRS = 53;
const NEW_FILLED_MAP = 418;
const NEW_NETHER_STAR = 508;

const DYE_ARRAY = [
self::NEW_INC_SAC,
self::NEW_RED_DYE,
self::NEW_GREEN_DYE,
self::NEW_COCOA_BEANS,
self::NEW_LAPIS_LAZULI,
self::NEW_PURPLE_DYE,
self::NEW_CYAN_DYE,
self::NEW_LIGHT_GRAY_DYE,
self::NEW_GRAY_DYE,
self::NEW_PINK_DYE,
self::NEW_LIME_DYE,
self::NEW_YELLOW_DYE,
self::NEW_LIGHT_BLUE_DYE,
self::NEW_MAGENTA_DYE,
self::NEW_ORANGE_DYE,
self::NEW_BONE_MEAL,
self::NEW_BLACK_DYE,
self::NEW_BROWN_DYE,
self::NEW_BLUE_DYE,
self::NEW_WHITE_DYE,
];

static public function getOldByNew($id) {
if ($id < 256) {
return $id;
}
if (in_array($id, self::DYE_ARRAY)) {
return Item::DYE;
}
$oClass = new \ReflectionClass(__CLASS__);
$new = $oClass->getConstants();
$oClass = new \ReflectionClass('pocketmine\item\Item');
$old = $oClass->getConstants();

$key = array_search($id, $new);
$key = explode('_', $key)[1];
return $old[$key]??$id;
}

static public function getDyeMeta($id) {
return array_search($id, self::DYE_ARRAY[$id]);
}



static public function getNewByOld($id, $meta) {
if ($id < 256) {
return $id;
}
if ($id == Item::DYE) {
return self::DYE_ARRAY[$meta];
}
$oClass = new \ReflectionClass(__CLASS__);
$new = $oClass->getConstants();
$oClass = new \ReflectionClass('pocketmine\item\Item');
$old = $oClass->getConstants();
$key = array_search($id, $old);
if ($key) {
$key = 'NEW_' . $key;
return $new[$key]??$id;
} else {
return $id;
}

}
}
42 changes: 34 additions & 8 deletions src/pocketmine/network/protocol/CraftingDataPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use pocketmine\inventory\ShapelessRecipe;
use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\enchantment\EnchantmentList;
use pocketmine\item\ItemNew;
use pocketmine\utils\BinaryStream;

class CraftingDataPacket extends PEPacket{
Expand Down Expand Up @@ -70,9 +71,17 @@ private static function writeShapelessRecipe(ShapelessRecipe $recipe, BinaryStre
$stream->putVarInt($recipe->getIngredientCount());
foreach($recipe->getIngredientList() as $item){
if ($playerProtocol >= Info::PROTOCOL_360) {
$stream->putSignedVarInt($item->getId());
$itemId = $item->getId();
if ($playerProtocol >= Info::PROTOCOL_419) {
$itemId = ItemNew::getNewByOld($item->getId(), $item->getDamage());
}
$stream->putSignedVarInt($itemId);
if ($item->getId() !== 0) {
$stream->putSignedVarInt($item->getDamage());
$meta = $item->getDamage();
if ($playerProtocol >= Info::PROTOCOL_419 && in_array($itemId, ItemNew::DYE_ARRAY)) {
$meta = 0;
}
$stream->putSignedVarInt($meta);
$stream->putSignedVarInt($item->getCount());
}
} else {
Expand Down Expand Up @@ -106,10 +115,18 @@ private static function writeShapedRecipe(ShapedRecipe $recipe, BinaryStream $st
for($z = 0; $z < $recipe->getWidth(); ++$z){
for($x = 0; $x < $recipe->getHeight(); ++$x){
$slot = $recipe->getIngredient($x, $z);
$itemId = $slot->getId();
if ($playerProtocol >= Info::PROTOCOL_419) {
$itemId = ItemNew::getNewByOld($slot->getId(), $slot->getDamage());
}
if ($playerProtocol >= Info::PROTOCOL_360) {
$stream->putSignedVarInt($slot->getId());
$stream->putSignedVarInt($itemId);
if ($slot->getId() !== 0) {
$stream->putSignedVarInt($slot->getDamage());
$meta = $slot->getDamage();
if ($playerProtocol >= Info::PROTOCOL_419 && in_array($itemId, ItemNew::DYE_ARRAY)) {
$meta = 0;
}
$stream->putSignedVarInt($meta);
$stream->putSignedVarInt($slot->getCount());
}
} else {
Expand All @@ -136,16 +153,25 @@ private static function writeShapedRecipe(ShapedRecipe $recipe, BinaryStream $st
}

private static function writeFurnaceRecipe(FurnaceRecipe $recipe, BinaryStream $stream, $playerProtocol){
if($recipe->getInput()->getDamage() !== 0){ //Data recipe
$stream->putSignedVarInt($recipe->getInput()->getId());
$stream->putSignedVarInt($recipe->getInput()->getDamage());
$item = $recipe->getInput();
$itemId = $item->getId();
if ($playerProtocol >= Info::PROTOCOL_419) {
$itemId = ItemNew::getNewByOld($item->getId(), $item->getDamage());
}
$meta = $item->getDamage();
if ($playerProtocol >= Info::PROTOCOL_419 && in_array($itemId, ItemNew::DYE_ARRAY)) {
$meta = 0;
}
if($meta !== 0){ //Data recipe
$stream->putSignedVarInt($itemId);
$stream->putSignedVarInt($meta);
$stream->putSlot($recipe->getResult(), $playerProtocol);
if ($playerProtocol >= Info::PROTOCOL_350) {
$stream->putString(self::RECIPE_TAG_FURNACE);
}
return CraftingDataPacket::ENTRY_FURNACE_DATA;
}else{
$stream->putSignedVarInt($recipe->getInput()->getId());
$stream->putSignedVarInt($itemId);
$stream->putSlot($recipe->getResult(), $playerProtocol);
if ($playerProtocol >= Info::PROTOCOL_350) {
$stream->putString(self::RECIPE_TAG_FURNACE);
Expand Down
Loading