Skip to content

Commit

Permalink
BedrockDataFiles: added constants for folders as well as files
Browse files Browse the repository at this point in the history
we probably should have it recurse too, but this is an easy win.
  • Loading branch information
dktapps committed Feb 16, 2025
1 parent 91ac647 commit 03e4b53
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion build/generate-bedrockdata-path-consts.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use function fclose;
use function fopen;
use function fwrite;
use function is_dir;
use function is_file;
use function scandir;
use function str_replace;
Expand Down Expand Up @@ -59,14 +60,15 @@ function constantify(string $permissionName) : string{
continue;
}
$path = Path::join(BEDROCK_DATA_PATH, $file);
if(!is_file($path)){
if(!is_file($path) && !is_dir($path)){
continue;
}

foreach([
'README.md',
'LICENSE',
'composer.json',
'.github'
] as $ignored){
if($file === $ignored){
continue 2;
Expand Down
3 changes: 2 additions & 1 deletion src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use pocketmine\crafting\CraftingManagerFromDataHelper;
use pocketmine\crash\CrashDump;
use pocketmine\crash\CrashDumpRenderer;
use pocketmine\data\bedrock\BedrockDataFiles;
use pocketmine\entity\EntityDataHelper;
use pocketmine\entity\Location;
use pocketmine\event\HandlerListManager;
Expand Down Expand Up @@ -1005,7 +1006,7 @@ public function __construct(

$this->commandMap = new SimpleCommandMap($this);

$this->craftingManager = CraftingManagerFromDataHelper::make(Path::join(\pocketmine\BEDROCK_DATA_PATH, "recipes"));
$this->craftingManager = CraftingManagerFromDataHelper::make(BedrockDataFiles::RECIPES);

$this->resourceManager = new ResourcePackManager(Path::join($this->dataPath, "resource_packs"), $this->logger);

Expand Down
3 changes: 3 additions & 0 deletions src/data/bedrock/BedrockDataFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ private function __construct(){
public const BLOCK_STATE_META_MAP_JSON = BEDROCK_DATA_PATH . '/block_state_meta_map.json';
public const CANONICAL_BLOCK_STATES_NBT = BEDROCK_DATA_PATH . '/canonical_block_states.nbt';
public const COMMAND_ARG_TYPES_JSON = BEDROCK_DATA_PATH . '/command_arg_types.json';
public const CREATIVE = BEDROCK_DATA_PATH . '/creative';
public const ENTITY_ID_MAP_JSON = BEDROCK_DATA_PATH . '/entity_id_map.json';
public const ENTITY_IDENTIFIERS_NBT = BEDROCK_DATA_PATH . '/entity_identifiers.nbt';
public const ENUMS = BEDROCK_DATA_PATH . '/enums';
public const ENUMS_PY = BEDROCK_DATA_PATH . '/enums.py';
public const ITEM_TAGS_JSON = BEDROCK_DATA_PATH . '/item_tags.json';
public const LEVEL_SOUND_ID_MAP_JSON = BEDROCK_DATA_PATH . '/level_sound_id_map.json';
public const PROTOCOL_INFO_JSON = BEDROCK_DATA_PATH . '/protocol_info.json';
public const R12_TO_CURRENT_BLOCK_MAP_BIN = BEDROCK_DATA_PATH . '/r12_to_current_block_map.bin';
public const R16_TO_CURRENT_ITEM_MAP_JSON = BEDROCK_DATA_PATH . '/r16_to_current_item_map.json';
public const RECIPES = BEDROCK_DATA_PATH . '/recipes';
public const REQUIRED_ITEM_LIST_JSON = BEDROCK_DATA_PATH . '/required_item_list.json';
}
3 changes: 2 additions & 1 deletion src/inventory/CreativeInventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace pocketmine\inventory;

use pocketmine\crafting\CraftingManagerFromDataHelper;
use pocketmine\data\bedrock\BedrockDataFiles;
use pocketmine\inventory\json\CreativeGroupData;
use pocketmine\item\Item;
use pocketmine\lang\Translatable;
Expand Down Expand Up @@ -57,7 +58,7 @@ private function __construct(){
"items" => CreativeCategory::ITEMS,
] as $categoryId => $categoryEnum){
$groups = CraftingManagerFromDataHelper::loadJsonArrayOfObjectsFile(
Path::join(\pocketmine\BEDROCK_DATA_PATH, "creative", $categoryId . ".json"),
Path::join(BedrockDataFiles::CREATIVE, $categoryId . ".json"),
CreativeGroupData::class
);

Expand Down

0 comments on commit 03e4b53

Please sign in to comment.