sapdon 3.0.2 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/build.d.ts +7 -0
- package/dist/cli/build.js +234 -0
- package/dist/cli/dev-server/client.d.ts +2 -0
- package/dist/cli/dev-server/client.js +21 -0
- package/dist/cli/dev-server/config.d.ts +3 -0
- package/dist/cli/dev-server/config.js +3 -0
- package/dist/cli/dev-server/handles.d.ts +4 -0
- package/dist/cli/dev-server/handles.js +5 -0
- package/dist/cli/dev-server/hmr.d.ts +1 -0
- package/dist/cli/dev-server/hmr.js +13 -0
- package/dist/cli/dev-server/index.d.ts +4 -0
- package/dist/cli/dev-server/index.js +17 -0
- package/dist/cli/dev-server/server.d.ts +14 -0
- package/dist/cli/dev-server/server.js +59 -0
- package/dist/cli/dev-server/syncFiles.d.ts +3 -0
- package/dist/cli/dev-server/syncFiles.js +37 -0
- package/dist/cli/index.d.ts +23 -0
- package/dist/cli/index.js +1 -0
- package/dist/cli/init.d.ts +9 -0
- package/dist/cli/init.js +80 -0
- package/dist/cli/load.d.ts +3 -0
- package/dist/cli/load.js +94 -0
- package/dist/cli/start.d.ts +2 -0
- package/dist/cli/start.js +2 -0
- package/dist/cli/tools/textureSet.d.ts +13 -0
- package/dist/cli/tools/textureSet.js +103 -0
- package/dist/cli/utils.d.ts +13 -0
- package/dist/cli/utils.js +89 -0
- package/dist/core/addon/biome.d.ts +22 -0
- package/dist/core/addon/biome.js +27 -0
- package/dist/core/addon/block/block.d.ts +41 -0
- package/dist/core/addon/block/block.js +46 -0
- package/dist/core/addon/controllers/animationController.d.ts +43 -0
- package/dist/core/addon/controllers/animationController.js +73 -0
- package/dist/core/addon/entity/clientEntity.d.ts +107 -0
- package/dist/core/addon/entity/clientEntity.js +149 -0
- package/dist/core/addon/entity/entity.d.ts +42 -0
- package/dist/core/addon/entity/entity.js +50 -0
- package/dist/core/addon/feature/oreFeature.d.ts +19 -0
- package/dist/core/addon/feature/oreFeature.js +24 -0
- package/dist/core/addon/featureRule.d.ts +20 -0
- package/dist/core/addon/featureRule.js +25 -0
- package/dist/core/addon/item/attachable.d.ts +94 -0
- package/dist/core/addon/item/attachable.js +134 -0
- package/dist/core/addon/item/item.d.ts +19 -0
- package/dist/core/addon/item/item.js +26 -0
- package/dist/core/addon/manifest.d.ts +49 -0
- package/dist/core/addon/manifest.js +65 -0
- package/dist/core/addon/menuCategory.d.ts +6 -0
- package/dist/core/addon/menuCategory.js +7 -0
- package/dist/core/addon/recipe/baseRecipe.d.ts +12 -0
- package/dist/core/addon/recipe/baseRecipe.js +23 -0
- package/dist/core/addon/recipe/data.d.ts +66 -0
- package/dist/core/addon/recipe/data.js +74 -0
- package/dist/core/addon/recipe/furnace.d.ts +17 -0
- package/dist/core/addon/recipe/furnace.js +43 -0
- package/dist/core/addon/recipe/shaped.d.ts +26 -0
- package/dist/core/addon/recipe/shaped.js +53 -0
- package/dist/core/addon/recipe/shapeless.d.ts +18 -0
- package/dist/core/addon/recipe/shapeless.js +36 -0
- package/dist/core/biome/biome.d.ts +14 -0
- package/dist/core/biome/biome.js +23 -0
- package/dist/core/biome/biomeComponent.d.ts +46 -0
- package/dist/core/biome/biomeComponent.js +77 -0
- package/dist/core/block/basicBlock.d.ts +48 -0
- package/dist/core/block/basicBlock.js +105 -0
- package/dist/core/block/block.d.ts +32 -0
- package/dist/core/block/block.js +92 -0
- package/dist/core/block/blockComponent.d.ts +187 -0
- package/dist/core/block/blockComponent.js +500 -0
- package/dist/core/block/cropBlock.d.ts +4 -0
- package/dist/core/block/cropBlock.js +27 -0
- package/dist/core/block/geometryBlock.d.ts +12 -0
- package/dist/core/block/geometryBlock.js +16 -0
- package/dist/core/block/oreBlock.d.ts +9 -0
- package/dist/core/block/oreBlock.js +25 -0
- package/dist/core/block/rotatableBlock.d.ts +27 -0
- package/dist/core/block/rotatableBlock.js +107 -0
- package/dist/core/block/tileBlock.d.ts +17 -0
- package/dist/core/block/tileBlock.js +125 -0
- package/dist/core/entity/basicEntity.d.ts +111 -0
- package/dist/core/entity/basicEntity.js +170 -0
- package/dist/core/entity/behavior/followMob.d.ts +12 -0
- package/dist/core/entity/behavior/followMob.js +35 -0
- package/dist/core/entity/behavior/followParent.d.ts +7 -0
- package/dist/core/entity/behavior/followParent.js +15 -0
- package/dist/core/entity/behavior/randomStroll.d.ts +31 -0
- package/dist/core/entity/behavior/randomStroll.js +63 -0
- package/dist/core/entity/behavior/tempt.d.ts +73 -0
- package/dist/core/entity/behavior/tempt.js +134 -0
- package/dist/core/entity/bundles/basicBundle.d.ts +13 -0
- package/dist/core/entity/bundles/basicBundle.js +45 -0
- package/dist/core/entity/clientEntity.d.ts +20 -0
- package/dist/core/entity/clientEntity.js +37 -0
- package/dist/core/entity/componets/entityComponet.d.ts +202 -0
- package/dist/core/entity/componets/entityComponet.js +347 -0
- package/dist/core/entity/data/nativeEntityData.d.ts +9 -0
- package/dist/core/entity/data/nativeEntityData.js +38 -0
- package/dist/core/entity/entity.d.ts +15 -0
- package/dist/core/entity/entity.js +18 -0
- package/dist/core/entity/nativeEntity.d.ts +8 -0
- package/dist/core/entity/nativeEntity.js +28 -0
- package/dist/core/entity/navigation/walk.d.ts +23 -0
- package/dist/core/entity/navigation/walk.js +56 -0
- package/dist/core/entity/projectile.d.ts +3 -0
- package/dist/core/entity/projectile.js +7 -0
- package/dist/core/factory/biomeFactory.d.ts +4 -0
- package/dist/core/factory/biomeFactory.js +13 -0
- package/dist/core/factory/blockFactory.d.ts +34 -0
- package/dist/core/factory/blockFactory.js +143 -0
- package/dist/core/factory/entityFactory.d.ts +17 -0
- package/dist/core/factory/entityFactory.js +75 -0
- package/dist/core/factory/featureFactory.d.ts +6 -0
- package/dist/core/factory/featureFactory.js +23 -0
- package/dist/core/factory/itemExtra.d.ts +8 -0
- package/dist/core/factory/itemExtra.js +9 -0
- package/dist/core/factory/itemFactory.d.ts +27 -0
- package/dist/core/factory/itemFactory.js +112 -0
- package/dist/core/factory/recipeFactory.d.ts +18 -0
- package/dist/core/factory/recipeFactory.js +39 -0
- package/dist/core/factory/uiFactory.d.ts +12 -0
- package/dist/core/factory/uiFactory.js +32 -0
- package/dist/core/feature/oreFeature.d.ts +10 -0
- package/dist/core/feature/oreFeature.js +11 -0
- package/dist/core/feature-rule/condition/biomeFilter.d.ts +26 -0
- package/dist/core/feature-rule/condition/biomeFilter.js +36 -0
- package/dist/core/feature-rule/condition/featureConditions.d.ts +27 -0
- package/dist/core/feature-rule/condition/featureConditions.js +37 -0
- package/dist/core/feature-rule/distribution/coordinateDistribution.d.ts +17 -0
- package/dist/core/feature-rule/distribution/coordinateDistribution.js +23 -0
- package/dist/core/feature-rule/distribution/featureDistribution.d.ts +31 -0
- package/dist/core/feature-rule/distribution/featureDistribution.js +41 -0
- package/dist/core/feature-rule/featureRule.d.ts +17 -0
- package/dist/core/feature-rule/featureRule.js +26 -0
- package/dist/core/index.d.ts +2062 -0
- package/dist/core/index.js +1 -0
- package/dist/core/item/armor.d.ts +21 -0
- package/dist/core/item/armor.js +90 -0
- package/dist/core/item/attachable.d.ts +6 -0
- package/dist/core/item/attachable.js +26 -0
- package/dist/core/item/food.d.ts +24 -0
- package/dist/core/item/food.js +38 -0
- package/dist/core/item/item.d.ts +36 -0
- package/dist/core/item/item.js +69 -0
- package/dist/core/item/itemComponents.d.ts +113 -0
- package/dist/core/item/itemComponents.js +225 -0
- package/dist/core/registry.d.ts +12 -0
- package/dist/core/registry.js +16 -0
- package/dist/core/texture.d.ts +18 -0
- package/dist/core/texture.js +38 -0
- package/dist/core/ui/buttonMapping.d.ts +97 -0
- package/dist/core/ui/buttonMapping.js +132 -0
- package/dist/core/ui/dataBindingObject.d.ts +97 -0
- package/dist/core/ui/dataBindingObject.js +134 -0
- package/dist/core/ui/elements/button.d.ts +21 -0
- package/dist/core/ui/elements/button.js +101 -0
- package/dist/core/ui/elements/collectionPanel.d.ts +12 -0
- package/dist/core/ui/elements/collectionPanel.js +53 -0
- package/dist/core/ui/elements/grid.d.ts +8 -0
- package/dist/core/ui/elements/grid.js +33 -0
- package/dist/core/ui/elements/image.d.ts +13 -0
- package/dist/core/ui/elements/image.js +55 -0
- package/dist/core/ui/elements/label.d.ts +14 -0
- package/dist/core/ui/elements/label.js +61 -0
- package/dist/core/ui/elements/panel.d.ts +11 -0
- package/dist/core/ui/elements/panel.js +49 -0
- package/dist/core/ui/elements/scrollingPanel.d.ts +14 -0
- package/dist/core/ui/elements/scrollingPanel.js +59 -0
- package/dist/core/ui/elements/stackPanel.d.ts +14 -0
- package/dist/core/ui/elements/stackPanel.js +37 -0
- package/dist/core/ui/elements/uiElement.d.ts +53 -0
- package/dist/core/ui/elements/uiElement.js +129 -0
- package/dist/core/ui/properties/control.d.ts +214 -0
- package/dist/core/ui/properties/control.js +286 -0
- package/dist/core/ui/properties/dataBinding.d.ts +6 -0
- package/dist/core/ui/properties/dataBinding.js +16 -0
- package/dist/core/ui/properties/factory.d.ts +37 -0
- package/dist/core/ui/properties/factory.js +62 -0
- package/dist/core/ui/properties/gridProp.d.ts +65 -0
- package/dist/core/ui/properties/gridProp.js +90 -0
- package/dist/core/ui/properties/input.d.ts +97 -0
- package/dist/core/ui/properties/input.js +134 -0
- package/dist/core/ui/properties/layout.d.ts +105 -0
- package/dist/core/ui/properties/layout.js +145 -0
- package/dist/core/ui/properties/scrollView.d.ts +105 -0
- package/dist/core/ui/properties/scrollView.js +145 -0
- package/dist/core/ui/properties/sound.d.ts +47 -0
- package/dist/core/ui/properties/sound.js +66 -0
- package/dist/core/ui/properties/sprite.d.ts +161 -0
- package/dist/core/ui/properties/sprite.js +222 -0
- package/dist/core/ui/properties/text.d.ts +135 -0
- package/dist/core/ui/properties/text.js +187 -0
- package/dist/core/ui/registry/uiSystemRegistry.d.ts +8 -0
- package/dist/core/ui/registry/uiSystemRegistry.js +26 -0
- package/dist/core/ui/systems/chest.d.ts +5 -0
- package/dist/core/ui/systems/chest.js +21 -0
- package/dist/core/ui/systems/containerUISystem.d.ts +67 -0
- package/dist/core/ui/systems/containerUISystem.js +214 -0
- package/dist/core/ui/systems/guidebook.d.ts +9 -0
- package/dist/core/ui/systems/guidebook.js +206 -0
- package/dist/core/ui/systems/serverForm.d.ts +13 -0
- package/dist/core/ui/systems/serverForm.js +116 -0
- package/dist/core/ui/systems/system.d.ts +16 -0
- package/dist/core/ui/systems/system.js +37 -0
- package/dist/oc/index.d.ts +142 -0
- package/dist/oc/index.js +1 -0
- package/doc/sapdon-ts.md +35 -1
- package/package.json +6 -8
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export class BiomeComponent {
|
|
2
|
+
/**
|
|
3
|
+
* 将多个组件集合合并为一个。
|
|
4
|
+
* @param {...Map} componentMaps - 多个组件集合。
|
|
5
|
+
* @returns {Map} - 合并后的组件集合。
|
|
6
|
+
*/
|
|
7
|
+
static combineComponents(...componentMaps) {
|
|
8
|
+
return new Map(componentMaps.flatMap(map => [...map]));
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 设置生物群系的气候参数
|
|
12
|
+
* @param {number} downfall - 降水量(范围通常为 0 到 1)
|
|
13
|
+
* @param {number} snow_accumulation - 积雪量(范围通常为 0 到 1)
|
|
14
|
+
* @param {number} temperature - 温度(范围通常为 0 到 1)
|
|
15
|
+
* @returns {Map} 返回一个包含气候参数的 Map 对象,键为 "minecraft:climate"
|
|
16
|
+
*/
|
|
17
|
+
static setClimate(downfall, snow_accumulation, temperature) {
|
|
18
|
+
return new Map([
|
|
19
|
+
["minecraft:climate", {
|
|
20
|
+
downfall: downfall,
|
|
21
|
+
snow_accumulation: snow_accumulation,
|
|
22
|
+
temperature: temperature
|
|
23
|
+
}]
|
|
24
|
+
]);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 设置生物群系的世界高度参数(通常用于生成地形)
|
|
28
|
+
* @param {Object} noise_params - 噪声参数,用于控制地形生成
|
|
29
|
+
* @returns {Map} 返回一个包含高度参数的 Map 对象,键为 "minecraft:overworld_height"
|
|
30
|
+
*/
|
|
31
|
+
static setOverworldHeight(noise_params) {
|
|
32
|
+
return new Map([
|
|
33
|
+
["minecraft:overworld_height", {
|
|
34
|
+
noise_params: noise_params
|
|
35
|
+
}]
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 设置生物群系的表面参数(如地表材料、海底材料等)
|
|
40
|
+
* @param {Object} params - 表面参数对象,包含以下属性:
|
|
41
|
+
* @param {number} params.sea_floor_depth - 海底深度
|
|
42
|
+
* @param {string} params.sea_floor_material - 海底材料(如 "minecraft:sand")
|
|
43
|
+
* @param {string} params.foundation_material - 基础材料(如 "minecraft:stone")
|
|
44
|
+
* @param {string} params.mid_material - 中间层材料(如 "minecraft:dirt")
|
|
45
|
+
* @param {string} params.top_material - 顶层材料(如 "minecraft:grass_block")
|
|
46
|
+
* @param {string} params.sea_material - 海洋材料(如 "minecraft:water")
|
|
47
|
+
* @returns {Map} 返回一个包含表面参数的 Map 对象,键为 "minecraft:surface_parameters"
|
|
48
|
+
*/
|
|
49
|
+
static setSurfaceParameters(params) {
|
|
50
|
+
const { sea_floor_depth, sea_floor_material, foundation_material, mid_material, top_material, sea_material } = params;
|
|
51
|
+
return new Map([
|
|
52
|
+
["minecraft:surface_parameters", {
|
|
53
|
+
sea_floor_depth: sea_floor_depth,
|
|
54
|
+
sea_floor_material: sea_floor_material,
|
|
55
|
+
foundation_material: foundation_material,
|
|
56
|
+
mid_material: mid_material,
|
|
57
|
+
top_material: top_material,
|
|
58
|
+
sea_material: sea_material
|
|
59
|
+
}]
|
|
60
|
+
]);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 设置生物群系在生成时的规则(如适用于哪些气候类型)
|
|
64
|
+
* @returns {Map} 返回一个包含生成规则的 Map 对象,键为 "minecraft:overworld_generation_rules"
|
|
65
|
+
*/
|
|
66
|
+
static setOverworldGenerationRules(medium_weight, warm_weight, cold_weight) {
|
|
67
|
+
return new Map([
|
|
68
|
+
["minecraft:overworld_generation_rules", {
|
|
69
|
+
"generate_for_climates": [
|
|
70
|
+
["medium", medium_weight], // 适用于中等气候,权重为 100
|
|
71
|
+
["warm", warm_weight], // 适用于温暖气候,权重为 100
|
|
72
|
+
["cold", cold_weight] // 适用于寒冷气候,权重为 100
|
|
73
|
+
]
|
|
74
|
+
}]
|
|
75
|
+
]);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export class BasicBlock {
|
|
2
|
+
/**
|
|
3
|
+
* 基础方块类
|
|
4
|
+
* @param {string} identifier 方块唯一标识符
|
|
5
|
+
* @param {string} category 菜单栏分类 可选:"construction", "nature", "equipment", "items", and "none"
|
|
6
|
+
* @param {Array} textures_arr 纹理数组 [上,下,东,西,南,北]
|
|
7
|
+
* @param {Object} options 可选参数
|
|
8
|
+
* @param {string} options.group 分组,默认为 "construction"
|
|
9
|
+
* @param {boolean} options.hide_in_command 是否在命令中隐藏,默认为 false
|
|
10
|
+
*/
|
|
11
|
+
constructor(identifier: string, category: string, textures_arr: any[], options?: {
|
|
12
|
+
group: string;
|
|
13
|
+
hide_in_command: boolean;
|
|
14
|
+
});
|
|
15
|
+
identifier: string;
|
|
16
|
+
category: string;
|
|
17
|
+
textures: any[];
|
|
18
|
+
group: string;
|
|
19
|
+
hide_in_command: boolean;
|
|
20
|
+
traits: Map<any, any>;
|
|
21
|
+
states: Map<any, any>;
|
|
22
|
+
components: Map<any, any>;
|
|
23
|
+
permutations: any[];
|
|
24
|
+
getId(): string;
|
|
25
|
+
registerTrait(key: any, value: any): this;
|
|
26
|
+
registerState(key: any, value: any): this;
|
|
27
|
+
/**
|
|
28
|
+
* 添加组件
|
|
29
|
+
* @param {Map} componentMap 组件 Map
|
|
30
|
+
*/
|
|
31
|
+
addComponent(componentMap: Map<any, any>): this;
|
|
32
|
+
/**
|
|
33
|
+
* 移除组件
|
|
34
|
+
* @param {string} key 组件名称
|
|
35
|
+
*/
|
|
36
|
+
removeComponent(key: string): this;
|
|
37
|
+
/**
|
|
38
|
+
* 添加方块变体
|
|
39
|
+
* @param {string} condition 变体条件
|
|
40
|
+
* @param {Map} componentMap 组件 Map
|
|
41
|
+
*/
|
|
42
|
+
addPermutation(condition: string, componentMap: Map<any, any>): this;
|
|
43
|
+
/**
|
|
44
|
+
* 将方块对象转换为 JSON 格式
|
|
45
|
+
* @returns {Object} JSON 格式的方块对象
|
|
46
|
+
*/
|
|
47
|
+
toJson(): Object;
|
|
48
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { AddonBlock, AddonBlockDefinition, AddonBlockDescription } from "../addon/block/block.js";
|
|
2
|
+
import { AddonMenuCategory } from "../addon/menuCategory.js";
|
|
3
|
+
export class BasicBlock {
|
|
4
|
+
/**
|
|
5
|
+
* 基础方块类
|
|
6
|
+
* @param {string} identifier 方块唯一标识符
|
|
7
|
+
* @param {string} category 菜单栏分类 可选:"construction", "nature", "equipment", "items", and "none"
|
|
8
|
+
* @param {Array} textures_arr 纹理数组 [上,下,东,西,南,北]
|
|
9
|
+
* @param {Object} options 可选参数
|
|
10
|
+
* @param {string} options.group 分组,默认为 "construction"
|
|
11
|
+
* @param {boolean} options.hide_in_command 是否在命令中隐藏,默认为 false
|
|
12
|
+
*/
|
|
13
|
+
constructor(identifier, category, textures_arr, options = {}) {
|
|
14
|
+
// 参数校验
|
|
15
|
+
if (!identifier || typeof identifier !== "string") {
|
|
16
|
+
throw new Error("identifier is required and must be a string");
|
|
17
|
+
}
|
|
18
|
+
if (!category || typeof category !== "string") {
|
|
19
|
+
throw new Error("category is required and must be a string");
|
|
20
|
+
}
|
|
21
|
+
if (!Array.isArray(textures_arr)) {
|
|
22
|
+
throw new Error("textures_arr must be an array ");
|
|
23
|
+
}
|
|
24
|
+
if (textures_arr.length !== 6) {
|
|
25
|
+
for (let i = textures_arr.length; i < 6; i++) {
|
|
26
|
+
textures_arr.push(textures_arr[0]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const { hide_in_command = false } = options;
|
|
30
|
+
this.identifier = identifier;
|
|
31
|
+
this.category = category;
|
|
32
|
+
this.textures = textures_arr;
|
|
33
|
+
this.group = options.group;
|
|
34
|
+
this.hide_in_command = hide_in_command;
|
|
35
|
+
this.traits = new Map();
|
|
36
|
+
this.states = new Map();
|
|
37
|
+
this.components = new Map();
|
|
38
|
+
this.permutations = [];
|
|
39
|
+
}
|
|
40
|
+
getId() {
|
|
41
|
+
return this.identifier;
|
|
42
|
+
}
|
|
43
|
+
registerTrait(key, value) {
|
|
44
|
+
this.traits.set(key, value);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
registerState(key, value) {
|
|
48
|
+
this.states.set(key, value);
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 添加组件
|
|
53
|
+
* @param {Map} componentMap 组件 Map
|
|
54
|
+
*/
|
|
55
|
+
addComponent(componentMap) {
|
|
56
|
+
if (!componentMap || !(componentMap instanceof Map)) {
|
|
57
|
+
throw new Error("componentMap is required and must be a Map");
|
|
58
|
+
}
|
|
59
|
+
for (const [key, value] of componentMap.entries()) {
|
|
60
|
+
this.components.set(key, value);
|
|
61
|
+
}
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 移除组件
|
|
66
|
+
* @param {string} key 组件名称
|
|
67
|
+
*/
|
|
68
|
+
removeComponent(key) {
|
|
69
|
+
if (!key || typeof key !== "string") {
|
|
70
|
+
throw new Error("key is required and must be a string");
|
|
71
|
+
}
|
|
72
|
+
this.components.delete(key);
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 添加方块变体
|
|
77
|
+
* @param {string} condition 变体条件
|
|
78
|
+
* @param {Map} componentMap 组件 Map
|
|
79
|
+
*/
|
|
80
|
+
addPermutation(condition, componentMap) {
|
|
81
|
+
if (!condition || typeof condition !== "string") {
|
|
82
|
+
throw new Error("condition is required and must be a string");
|
|
83
|
+
}
|
|
84
|
+
if (!componentMap || !(componentMap instanceof Map)) {
|
|
85
|
+
throw new Error("componentMap is required and must be a Map");
|
|
86
|
+
}
|
|
87
|
+
this.permutations.push({
|
|
88
|
+
condition: condition,
|
|
89
|
+
components: Object.fromEntries(componentMap)
|
|
90
|
+
});
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 将方块对象转换为 JSON 格式
|
|
95
|
+
* @returns {Object} JSON 格式的方块对象
|
|
96
|
+
*/
|
|
97
|
+
toJson() {
|
|
98
|
+
const block = new AddonBlock("1.21.50", // 格式版本
|
|
99
|
+
new AddonBlockDefinition(new AddonBlockDescription(this.identifier, Object.fromEntries(this.traits), // 将 Map 转换为普通对象
|
|
100
|
+
Object.fromEntries(this.states), // 将 Map 转换为普通对象
|
|
101
|
+
new AddonMenuCategory(this.category, this.group, this.hide_in_command)), Object.fromEntries(this.components), // 将 Map 转换为普通对象
|
|
102
|
+
this.permutations));
|
|
103
|
+
return block.toJson();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export class Block extends BasicBlock {
|
|
2
|
+
/**
|
|
3
|
+
* 方块类
|
|
4
|
+
* @param {string} identifier 方块的唯一标识符
|
|
5
|
+
* @param {string} category 方块的分类 "construction", "nature", "equipment", "items", and "none"
|
|
6
|
+
* @param {Array} variantDatas 方块的变体数据,包含每个变体的状态标签和纹理
|
|
7
|
+
* @param {Object} options 可选参数
|
|
8
|
+
* @param {string} options.group 分组,默认为 "construction"
|
|
9
|
+
* @param {boolean} options.hide_in_command 是否在命令中隐藏,默认为 false
|
|
10
|
+
* @param {boolean} options.ambient_occlusion 是否应用环境光遮蔽,默认为 false
|
|
11
|
+
* @param {boolean} options.face_dimming 是否根据面的方向进行亮度调整,默认为 false
|
|
12
|
+
* @param {string} options.render_method 渲染方法,默认为 "alpha_test"
|
|
13
|
+
*/
|
|
14
|
+
constructor(identifier: string, category: string, variantDatas: any[], options?: {
|
|
15
|
+
group: string;
|
|
16
|
+
hide_in_command: boolean;
|
|
17
|
+
ambient_occlusion: boolean;
|
|
18
|
+
face_dimming: boolean;
|
|
19
|
+
render_method: string;
|
|
20
|
+
});
|
|
21
|
+
options: {
|
|
22
|
+
group: string;
|
|
23
|
+
hide_in_command: boolean;
|
|
24
|
+
ambient_occlusion: boolean;
|
|
25
|
+
face_dimming: boolean;
|
|
26
|
+
render_method: string;
|
|
27
|
+
};
|
|
28
|
+
variantDatas: any[];
|
|
29
|
+
addVariantComponent(variantIndex: any, componentMap: any): this;
|
|
30
|
+
#private;
|
|
31
|
+
}
|
|
32
|
+
import { BasicBlock } from "./basicBlock.js";
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { BasicBlock } from "./basicBlock.js";
|
|
2
|
+
import { BlockComponent } from "./blockComponent.js";
|
|
3
|
+
export class Block extends BasicBlock {
|
|
4
|
+
/**
|
|
5
|
+
* 方块类
|
|
6
|
+
* @param {string} identifier 方块的唯一标识符
|
|
7
|
+
* @param {string} category 方块的分类 "construction", "nature", "equipment", "items", and "none"
|
|
8
|
+
* @param {Array} variantDatas 方块的变体数据,包含每个变体的状态标签和纹理
|
|
9
|
+
* @param {Object} options 可选参数
|
|
10
|
+
* @param {string} options.group 分组,默认为 "construction"
|
|
11
|
+
* @param {boolean} options.hide_in_command 是否在命令中隐藏,默认为 false
|
|
12
|
+
* @param {boolean} options.ambient_occlusion 是否应用环境光遮蔽,默认为 false
|
|
13
|
+
* @param {boolean} options.face_dimming 是否根据面的方向进行亮度调整,默认为 false
|
|
14
|
+
* @param {string} options.render_method 渲染方法,默认为 "alpha_test"
|
|
15
|
+
*/
|
|
16
|
+
constructor(identifier, category, variantDatas, options = {}) {
|
|
17
|
+
console.log("options:", options);
|
|
18
|
+
// 检查 variantDatas 是否有效
|
|
19
|
+
if (!Array.isArray(variantDatas) || variantDatas.length === 0) {
|
|
20
|
+
throw new Error('variantDatas 必须是一个非空数组');
|
|
21
|
+
}
|
|
22
|
+
// 调用父类构造函数
|
|
23
|
+
super(identifier, category, variantDatas[0]["textures"], options);
|
|
24
|
+
this.options = options;
|
|
25
|
+
this.variantDatas = variantDatas;
|
|
26
|
+
// 初始化方块
|
|
27
|
+
this.#init();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 初始化方块(私有方法)
|
|
31
|
+
* @param {Array} variantDatas 方块的变体数据
|
|
32
|
+
* @param {Object} options 材质属性
|
|
33
|
+
*/
|
|
34
|
+
#init() {
|
|
35
|
+
// 注册方块状态
|
|
36
|
+
this.registerState("sapdon:block_variant_tag", {
|
|
37
|
+
values: {
|
|
38
|
+
min: 0,
|
|
39
|
+
max: this.variantDatas.length > 1 ? this.variantDatas.length - 1 : 1
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
// 为每个变体创建材质实例
|
|
43
|
+
this.variantDatas.forEach((variant, index) => {
|
|
44
|
+
const material_instances = this.#createMaterialInstances(variant.textures, this.options);
|
|
45
|
+
const condition = `q.block_state('sapdon:block_variant_tag') == ${index}`;
|
|
46
|
+
// 添加材质实例组件
|
|
47
|
+
this.addPermutation(condition, BlockComponent.setMaterialInstances(material_instances));
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 创建材质实例(私有方法)
|
|
52
|
+
* @param {Array} textures 纹理数组
|
|
53
|
+
* @param {Object} options 材质属性
|
|
54
|
+
* @returns {Object} 材质实例对象
|
|
55
|
+
*/
|
|
56
|
+
#createMaterialInstances(textures) {
|
|
57
|
+
const material_instances = {};
|
|
58
|
+
const sides = ["*", "up", "down", "north", "south", "east", "west"];
|
|
59
|
+
textures.forEach((texture, index) => {
|
|
60
|
+
material_instances[sides[index]] = {
|
|
61
|
+
texture: texture,
|
|
62
|
+
ambient_occlusion: this.options.ambient_occlusion || true,
|
|
63
|
+
face_dimming: this.options.face_dimming || true,
|
|
64
|
+
render_method: this.options.render_method || "alpha_test"
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
return material_instances;
|
|
68
|
+
}
|
|
69
|
+
addVariantComponent(variantIndex, componentMap) {
|
|
70
|
+
if (variantIndex < 0 || variantIndex >= this.variantDatas.length) {
|
|
71
|
+
throw new Error('variantIndex 必须在 0 到 variantDatas.length-1 之间');
|
|
72
|
+
}
|
|
73
|
+
const condition = `q.block_state('sapdon:block_variant_tag') == ${variantIndex}`;
|
|
74
|
+
this.addPermutation(condition, componentMap);
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/*
|
|
79
|
+
// 示例用法
|
|
80
|
+
const block = new Block("sapdon:block", "construction", [
|
|
81
|
+
{ stateTag: 1, textures: ["garlic_stage_0"] },
|
|
82
|
+
{ stateTag: 2, textures: ["garlic_stage_1"] },
|
|
83
|
+
{ stateTag: 3, textures: ["garlic_stage_2"] },
|
|
84
|
+
{ stateTag: 4, textures: ["garlic_stage_3"] },
|
|
85
|
+
], {
|
|
86
|
+
ambient_occlusion: false,
|
|
87
|
+
face_dimming: false,
|
|
88
|
+
render_method: "blend"
|
|
89
|
+
});
|
|
90
|
+
console.log(block);
|
|
91
|
+
debugger
|
|
92
|
+
*/
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
export class BlockComponent {
|
|
2
|
+
static setTick(interval_range: any, looping: any): Map<any, any>;
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {Array} custom_components
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
static setCustomComponents(custom_components: any[]): Map<any, any>;
|
|
9
|
+
/**
|
|
10
|
+
* 创建一个用于 Minecraft 方块的变换对象,并返回一个 Map。
|
|
11
|
+
* @param {number[]} [translation=[0, 0, 0]] - 平移向量 [x, y, z]。
|
|
12
|
+
* @param {number[]} [scale=[1, 1, 1]] - 缩放向量 [x, y, z]。
|
|
13
|
+
* @param {number[]} [scale_pivot=[0, 0, 0]] - 缩放的枢轴点 [x, y, z]。
|
|
14
|
+
* @param {number[]} [rotation=[0, 0, 0]] - 旋转向量(角度)[x, y, z]。
|
|
15
|
+
* @param {number[]} [rotation_pivot=[0, 0, 0]] - 旋转的枢轴点 [x, y, z]。
|
|
16
|
+
* @returns {Map} - 一个包含变换数据的 Map 对象。
|
|
17
|
+
* @throws {Error} - 如果任何参数无效,则抛出错误。
|
|
18
|
+
*/
|
|
19
|
+
static setTransformation(translation?: number[], scale?: number[], scale_pivot?: number[], rotation?: number[], rotation_pivot?: number[]): Map<any, any>;
|
|
20
|
+
/**
|
|
21
|
+
* 设置方块的呼吸行为。
|
|
22
|
+
* @param {String} value - 呼吸行为,可选值为 "solid" 或 "air"。
|
|
23
|
+
* @returns {Map} - 新的组件集合。
|
|
24
|
+
*/
|
|
25
|
+
static setBreathability(value: string): Map<any, any>;
|
|
26
|
+
/**
|
|
27
|
+
* 启用或禁用方块的碰撞箱。
|
|
28
|
+
* @param {Boolean} enabled - 是否启用碰撞箱。
|
|
29
|
+
* @returns {Map} - 新的组件集合。
|
|
30
|
+
*/
|
|
31
|
+
static setCollisionBoxEnabled(enabled: boolean): Map<any, any>;
|
|
32
|
+
/**
|
|
33
|
+
* 设置自定义的碰撞箱。
|
|
34
|
+
* @param {Array} origin - 碰撞箱的起点坐标 [x, y, z]。
|
|
35
|
+
* @param {Array} size - 碰撞箱的大小 [width, height, depth]。
|
|
36
|
+
* @returns {Map} - 新的组件集合。
|
|
37
|
+
*/
|
|
38
|
+
static setCollisionBoxCustom(origin: any[], size: any[]): Map<any, any>;
|
|
39
|
+
/**
|
|
40
|
+
* 设置方块的合成台属性。
|
|
41
|
+
* @param {Array} craftingTags - 合成标签。
|
|
42
|
+
* @param {String} tableName - 合成台名称。
|
|
43
|
+
* @returns {Map} - 新的组件集合。
|
|
44
|
+
*/
|
|
45
|
+
static setCraftingTable(craftingTags: any[], tableName: string): Map<any, any>;
|
|
46
|
+
/**
|
|
47
|
+
* 启用或禁用方块的爆炸抗性。
|
|
48
|
+
* @param {Boolean} enabled - 是否启用爆炸抗性。
|
|
49
|
+
* @returns {Map} - 新的组件集合。
|
|
50
|
+
*/
|
|
51
|
+
static setDestructibleByExplosionEnabled(enabled: boolean): Map<any, any>;
|
|
52
|
+
/**
|
|
53
|
+
* 设置自定义的爆炸抗性。
|
|
54
|
+
* @param {Number} explosionResistance - 爆炸抗性值。
|
|
55
|
+
* @returns {Map} - 新的组件集合。
|
|
56
|
+
*/
|
|
57
|
+
static setDestructibleByExplosionCustom(explosionResistance: number): Map<any, any>;
|
|
58
|
+
/**
|
|
59
|
+
* 启用或禁用方块的挖掘抗性。
|
|
60
|
+
* @param {Boolean} enabled - 是否启用挖掘抗性。
|
|
61
|
+
* @returns {Map} - 新的组件集合。
|
|
62
|
+
*/
|
|
63
|
+
static setDestructibleByMiningEnabled(enabled: boolean): Map<any, any>;
|
|
64
|
+
/**
|
|
65
|
+
* 设置自定义的挖掘抗性。
|
|
66
|
+
* @param {Number} secondsToDestroy - 破坏所需时间(秒)。
|
|
67
|
+
* @param {Array} itemSpecificSpeeds - 特定工具的挖掘速度。
|
|
68
|
+
* @returns {Map} - 新的组件集合。
|
|
69
|
+
*/
|
|
70
|
+
static setDestructibleByMiningCustom(secondsToDestroy: number, itemSpecificSpeeds: any[]): Map<any, any>;
|
|
71
|
+
/**
|
|
72
|
+
* 设置方块的显示名称。
|
|
73
|
+
* @param {String} displayName - 显示名称。
|
|
74
|
+
* @returns {Map} - 新的组件集合。
|
|
75
|
+
*/
|
|
76
|
+
static setDisplayName(displayName: string): Map<any, any>;
|
|
77
|
+
/**
|
|
78
|
+
* 启用或禁用方块的易燃性。
|
|
79
|
+
* @param {Boolean} enabled - 是否启用易燃性。
|
|
80
|
+
* @returns {Map} - 新的组件集合。
|
|
81
|
+
*/
|
|
82
|
+
static setFlammableEnabled(enabled: boolean): Map<any, any>;
|
|
83
|
+
/**
|
|
84
|
+
* 设置自定义的易燃性。
|
|
85
|
+
* @param {Number} catchChanceModifier - 着火概率。
|
|
86
|
+
* @param {Number} destroyChanceModifier - 被火焰摧毁的概率。
|
|
87
|
+
* @returns {Map} - 新的组件集合。
|
|
88
|
+
*/
|
|
89
|
+
static setFlammableCustom(catchChanceModifier: number, destroyChanceModifier: number): Map<any, any>;
|
|
90
|
+
/**
|
|
91
|
+
* 设置方块的摩擦力。
|
|
92
|
+
* @param {Number} value - 摩擦力值,范围为 0.0 到 0.9。
|
|
93
|
+
* @returns {Map} - 新的组件集合。
|
|
94
|
+
*/
|
|
95
|
+
static setFriction(value: number): Map<any, any>;
|
|
96
|
+
/**
|
|
97
|
+
* 设置方块的几何模型。
|
|
98
|
+
* @param {String} identifier - 几何模型标识符。
|
|
99
|
+
* @param {Object} bone_visibility - 骨骼可见性配置。
|
|
100
|
+
* @returns {Map} - 新的组件集合。
|
|
101
|
+
*/
|
|
102
|
+
static setGeometry(identifier: string, bone_visibility: Object): Map<any, any>;
|
|
103
|
+
/**
|
|
104
|
+
* 设置方块的物品视觉属性。
|
|
105
|
+
* @param {String} geometry - 几何模型标识符。
|
|
106
|
+
* @param {Object} materialInstances - 材质实例配置。
|
|
107
|
+
* @returns {Map} - 新的组件集合。
|
|
108
|
+
*/
|
|
109
|
+
static setItemVisual(geometry: string, materialInstances: Object): Map<any, any>;
|
|
110
|
+
/**
|
|
111
|
+
* 设置方块的光衰减值。
|
|
112
|
+
* @param {Number} value - 光的衰减值,范围为 0 到 15。
|
|
113
|
+
* @returns {Map} - 新的组件集合。
|
|
114
|
+
*/
|
|
115
|
+
static setLightDampening(value: number): Map<any, any>;
|
|
116
|
+
/**
|
|
117
|
+
* 设置方块的光照强度。
|
|
118
|
+
* @param {Number} value - 光照强度,范围为 0 到 15。
|
|
119
|
+
* @returns {Map} - 新的组件集合。
|
|
120
|
+
*/
|
|
121
|
+
static setLightEmission(value: number): Map<any, any>;
|
|
122
|
+
/**
|
|
123
|
+
* 设置方块的液体检测属性。
|
|
124
|
+
* @param {Boolean} canContainLiquid - 是否可以包含液体。
|
|
125
|
+
* @param {String} liquidType - 液体类型。
|
|
126
|
+
* @param {String} onLiquidTouches - 对液体的反应方式。
|
|
127
|
+
* @param {Array} stopsLiquidFlowingFromDirection - 阻止液体流动的方向。
|
|
128
|
+
* @returns {Map} - 新的组件集合。
|
|
129
|
+
*/
|
|
130
|
+
static setLiquidDetection(canContainLiquid: boolean, liquidType: string, onLiquidTouches: string, stopsLiquidFlowingFromDirection: any[]): Map<any, any>;
|
|
131
|
+
/**
|
|
132
|
+
* 设置方块的战利品表路径。
|
|
133
|
+
* @param {String} path - 战利品表路径。
|
|
134
|
+
* @returns {Map} - 新的组件集合。
|
|
135
|
+
*/
|
|
136
|
+
static setLoot(path: string): Map<any, any>;
|
|
137
|
+
/**
|
|
138
|
+
* 设置方块的地图颜色。
|
|
139
|
+
* @param {String|Array} value - 地图颜色,可以是十六进制字符串或 RGB 数组。
|
|
140
|
+
* @returns {Map} - 新的组件集合。
|
|
141
|
+
*/
|
|
142
|
+
static setMapColor(value: string | any[]): Map<any, any>;
|
|
143
|
+
/**
|
|
144
|
+
* 设置方块的材质实例。
|
|
145
|
+
* @param {Object} instances - 材质实例配置。
|
|
146
|
+
* @returns {Map} - 新的组件集合。
|
|
147
|
+
*/
|
|
148
|
+
static setMaterialInstances(instances: Object): Map<any, any>;
|
|
149
|
+
/**
|
|
150
|
+
* 设置方块的放置过滤条件。
|
|
151
|
+
* @param {Array} conditions - 放置条件列表。
|
|
152
|
+
* @returns {Map} - 新的组件集合。
|
|
153
|
+
*/
|
|
154
|
+
static setPlacementFilter(conditions: any[]): Map<any, any>;
|
|
155
|
+
/**
|
|
156
|
+
* 设置方块的红石导电性。
|
|
157
|
+
* @param {Boolean} allowsWireToStepDown - 是否允许红石线向下阶梯连接。
|
|
158
|
+
* @param {Boolean} redstoneConductor - 方块是否可以被红石信号激活。
|
|
159
|
+
* @returns {Map} - 新的组件集合。
|
|
160
|
+
*/
|
|
161
|
+
static setRedstoneConductivity(allowsWireToStepDown: boolean, redstoneConductor: boolean): Map<any, any>;
|
|
162
|
+
/**
|
|
163
|
+
* 启用或禁用方块的选择框。
|
|
164
|
+
* @param {Boolean} enabled - 是否启用选择框。
|
|
165
|
+
* @returns {Map} - 新的组件集合。
|
|
166
|
+
*/
|
|
167
|
+
static setSelectionBoxEnabled(enabled: boolean): Map<any, any>;
|
|
168
|
+
/**
|
|
169
|
+
* 设置自定义的选择框。
|
|
170
|
+
* @param {Array} origin - 选择框的起点坐标 [x, y, z]。
|
|
171
|
+
* @param {Array} size - 选择框的大小 [width, height, depth]。
|
|
172
|
+
* @returns {Map} - 新的组件集合。
|
|
173
|
+
*/
|
|
174
|
+
static setSelectionBoxCustom(origin: any[], size: any[]): Map<any, any>;
|
|
175
|
+
/**
|
|
176
|
+
* 将多个组件集合合并为一个。
|
|
177
|
+
* @param {...Map} componentMaps - 多个组件集合。
|
|
178
|
+
* @returns {Map} - 合并后的组件集合。
|
|
179
|
+
*/
|
|
180
|
+
static combineComponents(...componentMaps: Map<any, any>[]): Map<any, any>;
|
|
181
|
+
/**
|
|
182
|
+
* 获取当前组件的 JSON 表示。
|
|
183
|
+
* @param {Map} components - 组件集合。
|
|
184
|
+
* @returns {Object} - 组件的 JSON 对象。
|
|
185
|
+
*/
|
|
186
|
+
static toJSON(components: Map<any, any>): Object;
|
|
187
|
+
}
|