Skip to content

Commit 91d2119

Browse files
committed
docs: update the outdate doc
1 parent 64ca586 commit 91d2119

File tree

5 files changed

+56
-40
lines changed

5 files changed

+56
-40
lines changed

CONTRIBUTE.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ After you cloned the project, you can just install it like normal node project b
1313

1414
The code are splited into seperated projects, which layed in under `packages` folder. Most of them are really simple (only one `index.ts` file or few files).
1515

16-
If you want to write some code for specific module, the command `npm run dev` might help you.
16+
The simplest way to run the code is write a test and then run it.
1717

18-
For example, you want to add a functions to parse minecraft chunk data, you can add some code in `packages/world/index.ts`. You might also want to add some test related to your new features, just add sth. in `packages/world/test.ts`.
18+
And, the simplest way to run a test is `npx jest packages/<the-package>/<the-test-file.test.ts>`.
19+
20+
Also you can use the command `npm run dev`.
21+
22+
For example, you want to add a functions to parse minecraft chunk data, you can add some code in `packages/world/index.ts`. You might also want to add some test related to your new features, just add somthing in `packages/world/test.ts`.
1923

2024
During this process, you can first run `npm run dev world`, and it will start to auto compile & test the code for world module. You can see the result immediately.
2125

26+
**Please make sure you clean all built js files before you run your test! The test will fail if there are built js file! You can run `npm run build:clean` to clean all js!**
27+
2228
**Highly recommended to add test for the features,** ~~which I always lazy to add.~~
2329

2430
### Before Submit PR
@@ -49,15 +55,15 @@ The features like login, fetch user info/textures goes here:
4955

5056
- @xmcl/user
5157

52-
In node, it will use `got` as requester.
58+
In node, it will use nodejs http/https module as requester.
5359
In browser, it will use `fetch` as requester.
5460

5561
### General Gaming Features (Node/Electron/Browser)
5662

5763
The features like parsing game setting, parsing forge mod metadata, NBT parsing, game saves parsing, they don't really have any strong connection.
5864

5965
- @xmcl/nbt
60-
- @xmcl/forge
66+
- @xmcl/mod-parser
6167
- @xmcl/gamesetting
6268
- @xmcl/text-component
6369
- @xmcl/system

packages/gamesetting/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Provide function to parse Minecraft game settings
1010

11-
### Usage
11+
## Usage
1212

1313
### Parse GameSetting (options.txt)
1414

packages/installer/diagnose.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,21 @@ export interface Issue {
2727
*/
2828
hint: string;
2929
/**
30-
* The expected checksum of the file
30+
* The expected checksum of the file. Can be an empty string if this file is missing or not check checksum at all!
3131
*/
3232
expectedChecksum: string;
3333
/**
34-
* The actual checksum of the file
34+
* The actual checksum of the file. Can be an empty string if this file is missing or not check checksum at all!
3535
*/
3636
receivedChecksum: string;
3737
}
3838

3939
export type MinecraftIssues = LibraryIssue | MinecraftJarIssue | VersionJsonIssue | AssetIssue | AssetIndexIssue;
4040
export type InstallIssues = ProcessorIssue | LibraryIssue;
4141

42+
/**
43+
* The processor issue
44+
*/
4245
export interface ProcessorIssue extends Issue {
4346
role: "processor";
4447

@@ -48,6 +51,10 @@ export interface ProcessorIssue extends Issue {
4851
processor: Processor;
4952
}
5053

54+
/**
55+
* The library issue represents a corrupted or missing lib.
56+
* You can use `Installer.installResolvedLibraries` to fix this.
57+
*/
5158
export interface LibraryIssue extends Issue {
5259
role: "library";
5360

@@ -56,6 +63,10 @@ export interface LibraryIssue extends Issue {
5663
*/
5764
library: ResolvedLibrary;
5865
}
66+
/**
67+
* The minecraft jar issue represents a corrupted or missing minecraft jar.
68+
* You can use `Installer.installVersion` to fix this.
69+
*/
5970
export interface MinecraftJarIssue extends Issue {
6071
role: "minecraftJar";
6172

@@ -64,6 +75,15 @@ export interface MinecraftJarIssue extends Issue {
6475
*/
6576
version: string;
6677
}
78+
/**
79+
* The minecraft jar issue represents a corrupted or missing version jar.
80+
*
81+
* This means your version is totally broken, and you should reinstall this version.
82+
*
83+
* - If this is just a Minecraft version, you will need to use `Installer.install` to re-install Minecraft.
84+
* - If this is a Forge version, you will need to use `ForgeInstaller.install` to re-install.
85+
* - Others are the same, just re-install
86+
*/
6787
export interface VersionJsonIssue extends Issue {
6888
role: "versionJson";
6989

@@ -72,6 +92,10 @@ export interface VersionJsonIssue extends Issue {
7292
*/
7393
version: string;
7494
}
95+
/**
96+
* The asset issue represents a corrupted or missing minecraft asset file.
97+
* You can use `Installer.installResolvedAssets` to fix this.
98+
*/
7599
export interface AssetIssue extends Issue {
76100
role: "asset";
77101

@@ -80,6 +104,10 @@ export interface AssetIssue extends Issue {
80104
*/
81105
asset: { name: string; hash: string; size: number; };
82106
}
107+
/**
108+
* The asset index issue represents a corrupted or missing minecraft asset index file.
109+
* You can use `Installer.installAssets` to fix this.
110+
*/
83111
export interface AssetIndexIssue extends Issue {
84112
role: "assetIndex";
85113

packages/resource-manager/README.md

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,27 @@
1010

1111
### Load Minecraft Resource
1212

13+
*Notice that these API are not stable. May changed in future*
14+
1315
You can use this module in nodejs/electron:
1416

1517
```ts
18+
import { ResourcePack, Resource } from "@xmcl/resourcepack";
1619
import { ResourceManager, ResourceLocation } from "@xmcl/resource-manager"
17-
const manager: ResourceManager<Buffer> = new ResourceManager();
20+
const manager: ResourceManager = new ResourceManager();
1821

1922
// add a resource source which load resource from file
20-
await manager.addResourceSource(new MyFileSystemResourceSource('/base/path'));
23+
await manager.addResourcePack(new ResourcePack(await System.openFileSystem('/base/path')));
2124

2225
// load grass block model resource; it will load file at `assets/${location.domain}/${location.path}`
2326
// which is '/base/path/assets/minecraft/models/block/grass.json'
2427
// same logic with minecraft
2528
const resource = await manager.load(ResourceLocation.ofModelPath('block/grass'));
2629

27-
const url: string = resource.url; // your resource url which is file:///base/path/assets/minecraft/models/block/grass.json
2830
const content: Buffer = resource.content; // your resource content
2931
const modelJSON = JSON.parse(content.toString());
3032
```
3133

32-
You can also use this module in browser:
33-
34-
```ts
35-
import { ResourceManager, ResourceLocation } from "@xmcl/resource-manager"
36-
const manager: ResourceManager<string> = new ResourceManager();
37-
38-
// add a resource source which load resource from an remote url
39-
await manager.addResourceSource(new MyRemoteWhateverResourceSource('https://my-domain/xxx'));
40-
41-
// load grass block model resource; it will load file at `assets/${location.domain}/${location.path}`
42-
// which is 'https://my-domain/xxx/assets/minecraft/models/block/grass.json'
43-
// same logic with minecraft
44-
const resource = await manager.load(ResourceLocation.ofModelPath('block/grass'));
45-
46-
const url: string = resource.url; // your resource url which is https://my-domain/xxx/assets/minecraft/models/block/grass.json
47-
const content: string = resource.content; // your resource content string
48-
const modelJSON = JSON.parse(content);
49-
```
50-
51-
Please notice that in the sample above, all the `ResourceSource` should be implemented by yourself.
52-
5334
The resource manager will do the simplest cache for same resource location.
5435

5536
You can clear the cache by:
@@ -60,24 +41,26 @@ manager.clearCache();
6041

6142
### Load Minecraft Block Model
6243

63-
You can use this to load Minecraft block model and texture.
44+
You can use this to load Minecraft block model and texture just like Minecraft.
6445

6546
```ts
66-
import { ResourceManager, ModelLoader, TextureRegistry, ModelRegistry } from "@xmcl/resource-manager";
67-
import { BlockModel } from "@xmcl/system";
47+
import { ResourcePack, Resource, BlockModel } from "@xmcl/resourcepack";
48+
import { ResourceManager, ModelLoader } from "@xmcl/resource-manager";
49+
import { System } from "@xmcl/system";
6850

6951
const man = new ResourceManager();
70-
// setup resource manager
71-
man.addResourceSource(new YourCustomizedResourceSource());
52+
const resourcePack = new ResourcePack(await System.openFileSystem("/path/to/resource-pack.zip"));
53+
// setup resource pack
54+
man.addResourcePack(resourcePack);
7255

7356
const loader = new ModelLoader(man);
7457

7558
await loader.loadModel("block/grass"); // load grass model
7659
await loader.loadModel("block/stone"); // load stone model
7760
// ... load whatever you want model
7861

79-
const textures: TextureRegistry = loader.textures;
80-
const models: ModelRegistry = loader.models;
62+
const textures: Record<string, Resource> = loader.textures;
63+
const models: Record<string, BlockModel.Resolved> = loader.models;
8164

8265
const resolvedModel: BlockModel.Resolved = models["block/grass"];
8366
```

packages/resource-manager/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ interface ResourceSourceWrapper {
77
}
88

99
/**
10-
* The resource manager. Design to be able to use in both nodejs and browser environment.
11-
* @template T The type of the resource content. If you use this in node, it's probably `Buffer`. If you are in browser, it might be `string`. Just align this with your `ResourceSource`
10+
* The resource manager just like Minecraft. Design to be able to use in both nodejs and browser environment.
1211
*/
1312
export class ResourceManager {
1413
get allResourcePacks() { return this.list.map((l) => l.info); }

0 commit comments

Comments
 (0)