mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
Working crafting :woohoo:
This commit is contained in:
23
src/network/mcpe/cache/CraftingDataCache.php
vendored
23
src/network/mcpe/cache/CraftingDataCache.php
vendored
@ -25,6 +25,8 @@ namespace pocketmine\network\mcpe\cache;
|
||||
|
||||
use pocketmine\crafting\CraftingManager;
|
||||
use pocketmine\crafting\FurnaceType;
|
||||
use pocketmine\crafting\ShapedRecipe;
|
||||
use pocketmine\crafting\ShapelessRecipe;
|
||||
use pocketmine\crafting\ShapelessRecipeType;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\network\mcpe\convert\ItemTranslator;
|
||||
@ -76,12 +78,12 @@ final class CraftingDataCache{
|
||||
private function buildCraftingDataCache(CraftingManager $manager) : CraftingDataPacket{
|
||||
Timings::$craftingDataCacheRebuild->startTiming();
|
||||
|
||||
$counter = 0;
|
||||
$nullUUID = Uuid::fromString(Uuid::NIL);
|
||||
$converter = TypeConverter::getInstance();
|
||||
$recipesWithTypeIds = [];
|
||||
foreach($manager->getShapelessRecipes() as $list){
|
||||
foreach($list as $recipe){
|
||||
|
||||
foreach($manager->getCraftingRecipeIndex() as $index => $recipe){
|
||||
if($recipe instanceof ShapelessRecipe){
|
||||
$typeTag = match($recipe->getType()->id()){
|
||||
ShapelessRecipeType::CRAFTING()->id() => CraftingRecipeBlockName::CRAFTING_TABLE,
|
||||
ShapelessRecipeType::STONECUTTER()->id() => CraftingRecipeBlockName::STONECUTTER,
|
||||
@ -89,7 +91,7 @@ final class CraftingDataCache{
|
||||
};
|
||||
$recipesWithTypeIds[] = new ProtocolShapelessRecipe(
|
||||
CraftingDataPacket::ENTRY_SHAPELESS,
|
||||
Binary::writeInt(++$counter),
|
||||
Binary::writeInt($index),
|
||||
array_map(function(Item $item) use ($converter) : RecipeIngredient{
|
||||
return $converter->coreItemStackToRecipeIngredient($item);
|
||||
}, $recipe->getIngredientList()),
|
||||
@ -99,12 +101,9 @@ final class CraftingDataCache{
|
||||
$nullUUID,
|
||||
$typeTag,
|
||||
50,
|
||||
$counter
|
||||
$index
|
||||
);
|
||||
}
|
||||
}
|
||||
foreach($manager->getShapedRecipes() as $list){
|
||||
foreach($list as $recipe){
|
||||
}elseif($recipe instanceof ShapedRecipe){
|
||||
$inputs = [];
|
||||
|
||||
for($row = 0, $height = $recipe->getHeight(); $row < $height; ++$row){
|
||||
@ -114,7 +113,7 @@ final class CraftingDataCache{
|
||||
}
|
||||
$recipesWithTypeIds[] = $r = new ProtocolShapedRecipe(
|
||||
CraftingDataPacket::ENTRY_SHAPED,
|
||||
Binary::writeInt(++$counter),
|
||||
Binary::writeInt($index),
|
||||
$inputs,
|
||||
array_map(function(Item $item) use ($converter) : ItemStack{
|
||||
return $converter->coreItemStackToNet($item);
|
||||
@ -122,8 +121,10 @@ final class CraftingDataCache{
|
||||
$nullUUID,
|
||||
CraftingRecipeBlockName::CRAFTING_TABLE,
|
||||
50,
|
||||
$counter
|
||||
$index
|
||||
);
|
||||
}else{
|
||||
//TODO: probably special recipe types
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user