Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

Commit 917abbb

Browse files
authored
Add feature rule processing (#239)
* - Added feature rule processing * - Remove random line * - Update distribution
1 parent fa37268 commit 917abbb

9 files changed

Lines changed: 119 additions & 7 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { FormatVersion } from "../types/format-version";
2+
3+
interface Fraction {
4+
numerator: number,
5+
denominator: number
6+
}
7+
8+
interface DistributionObject {
9+
distribution: "uniform" | "fixed_grid" | "jittered_grid" | "gaussian" | "inverse_gaussian" | "triangle",
10+
extent: [number, number]
11+
}
12+
13+
/** */
14+
export interface FeatureRule extends Readonly<FormatVersion> {
15+
/** */
16+
format_version: string;
17+
/** */
18+
"minecraft:feature_rules": {
19+
description: {
20+
identifier: string,
21+
places_feature: string
22+
},
23+
conditions: {
24+
placement_pass: string,
25+
"minecraft:biome_filter": object
26+
},
27+
distribution: {
28+
iterations: number | string,
29+
x: string | Fraction | DistributionObject,
30+
y: string | Fraction | DistributionObject,
31+
z: string | Fraction | DistributionObject
32+
}
33+
}
34+
}
35+
36+
/** */
37+
export namespace FeatureRule {
38+
/**
39+
*
40+
* @param value
41+
* @returns
42+
*/
43+
export function is(value: any): value is FeatureRule {
44+
if (value && typeof value.format_version === "string" && typeof value === 'object') {
45+
const rule = value['minecraft:feature_rules']
46+
if (!rule || typeof rule != 'object') return false;
47+
const description = rule.description
48+
if (typeof description == 'object' && typeof description.identifier == 'string' && typeof description.places_feature == 'string') return true;
49+
}
50+
return false;
51+
}
52+
}

src/internal/behavior-pack/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from "./block";
66
export * from "./entity";
77
export * from "./item";
88
export * from "./feature";
9+
export * from "./feature_rule"

src/project/behavior-pack/behavior-pack-collection.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import * as Animation from "./animation";
77
import * as AnimationController from "./animation-controller";
88
import * as Block from "./block";
99
import * as Entity from "./entity";
10-
import * as Feature from "./feature"
10+
import * as Feature from "./feature";
11+
import * as FeatureRule from "./feature_rule";
1112
import * as Item from "./item";
1213
import * as LootTable from "./loot-table";
1314
import * as Function from "./mcfunction";
@@ -26,6 +27,8 @@ export class BehaviorPackCollection extends PackCollection<BehaviorPack> {
2627
readonly entities: DataSetConnector<Entity.Entity, BehaviorPack>;
2728
/**The collection of features*/
2829
readonly features: DataSetConnector<Feature.Feature, BehaviorPack>;
30+
/**The collection of features rules*/
31+
readonly features_rules: DataSetConnector<FeatureRule.FeatureRule, BehaviorPack>;
2932
/**The collection of mcfunctions*/
3033
readonly functions: DataSetConnector<Function.Function, BehaviorPack>;
3134
/**The collection of items*/
@@ -51,6 +54,7 @@ export class BehaviorPackCollection extends PackCollection<BehaviorPack> {
5154
this.structures = new DataSetConnector(this, (pack) => pack.structures);
5255
this.trading = new DataSetConnector(this, (pack) => pack.trading);
5356
this.features = new DataSetConnector(this, (pack) => pack.features);
57+
this.features_rules = new DataSetConnector(this, (pack) => pack.features_rules);
5458
}
5559

5660
/**

src/project/behavior-pack/behavior-pack.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as AnimationController from "./animation-controller";
99
import * as Block from "./block";
1010
import * as Entity from "./entity";
1111
import * as Feature from "./feature";
12+
import * as FeatureRule from "./feature_rule";
1213
import * as Item from "./item";
1314
import * as LootTable from "./loot-table";
1415
import * as Function from "./mcfunction";
@@ -42,6 +43,8 @@ export class BehaviorPack implements Container, Pack {
4243
readonly entities: DataSet<Entity.Entity>;
4344
/**The collection of features*/
4445
readonly features: DataSet<Feature.Feature>;
46+
/**The collection of features*/
47+
readonly features_rules: DataSet<FeatureRule.FeatureRule>;
4548
/**The collection of mcfunctions*/
4649
readonly functions: DataSet<Function.Function>;
4750
/**The collection of items*/
@@ -71,6 +74,7 @@ export class BehaviorPack implements Container, Pack {
7174
this.structures = new DataSet();
7275
this.trading = new DataSet();
7376
this.features = new DataSet();
77+
this.features_rules = new DataSet()
7478
}
7579

7680
/**
@@ -112,6 +116,9 @@ export class BehaviorPack implements Container, Pack {
112116

113117
case FileType.feature:
114118
return this.features.set(Feature.Process(doc));
119+
120+
case FileType.feature_rule:
121+
return this.features_rules.set(FeatureRule.Process(doc))
115122
}
116123

117124
return undefined;
@@ -140,6 +147,9 @@ export class BehaviorPack implements Container, Pack {
140147

141148
case FileType.feature:
142149
return this.features;
150+
151+
case FileType.feature_rule:
152+
return this.features_rules;
143153

144154
case FileType.function:
145155
return this.functions;
@@ -174,6 +184,7 @@ export class BehaviorPack implements Container, Pack {
174184
out = this.blocks.deleteFile(uri) || out;
175185
out = this.entities.deleteFile(uri) || out;
176186
out = this.features.deleteFile(uri) || out;
187+
out = this.features_rules.deleteFile(uri) || out;
177188
out = this.functions.deleteFile(uri) || out;
178189
out = this.items.deleteFile(uri) || out;
179190
out = this.loot_tables.deleteFile(uri) || out;
@@ -195,6 +206,7 @@ export class BehaviorPack implements Container, Pack {
195206
out = this.blocks.deleteFolder(uri) || out;
196207
out = this.entities.deleteFolder(uri) || out;
197208
out = this.features.deleteFolder(uri) || out;
209+
out = this.features_rules.deleteFolder(uri) || out;
198210
out = this.functions.deleteFolder(uri) || out;
199211
out = this.items.deleteFolder(uri) || out;
200212
out = this.loot_tables.deleteFolder(uri) || out;
@@ -217,6 +229,7 @@ export class BehaviorPack implements Container, Pack {
217229
if ((value = this.blocks.find(predicate))) return value;
218230
if ((value = this.entities.find(predicate))) return value;
219231
if ((value = this.features.find(predicate))) return value;
232+
if ((value = this.features_rules.find(predicate))) return value;
220233
if ((value = this.functions.find(predicate))) return value;
221234
if ((value = this.items.find(predicate))) return value;
222235
if ((value = this.loot_tables.find(predicate))) return value;
@@ -237,6 +250,7 @@ export class BehaviorPack implements Container, Pack {
237250
this.blocks.forEach(callbackfn);
238251
this.entities.forEach(callbackfn);
239252
this.features.forEach(callbackfn);
253+
this.features_rules.forEach(callbackfn);
240254
this.functions.forEach(callbackfn);
241255
this.items.forEach(callbackfn);
242256
this.loot_tables.forEach(callbackfn);
@@ -269,6 +283,7 @@ export namespace BehaviorPack {
269283
if (typeof temp.blocks !== "object") return false;
270284
if (typeof temp.entities !== "object") return false;
271285
if (typeof temp.features !== "object") return false;
286+
if (typeof temp.features_rules !== "object") return false;
272287

273288
if (typeof temp.context !== "object") return false;
274289
if (typeof temp.folder !== "string") return false;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* eslint-disable @typescript-eslint/no-empty-object-type */
2+
import { Types } from "bc-minecraft-bedrock-types";
3+
4+
/** */
5+
export interface FeatureRule extends Types.BaseObject {
6+
feature_used: string
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* Auto generated */
2+
3+
export * from "./feature_rule";
4+
export * from "./process";
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Types } from "bc-minecraft-bedrock-types";
2+
import * as Internal from "../../../internal/behavior-pack/feature_rule";
3+
import { Json } from "../../../internal/json";
4+
import { Documentation, TextDocument } from "../../../types";
5+
import { FeatureRule } from "./feature_rule";
6+
7+
/**
8+
*
9+
* @param doc
10+
* @returns
11+
*/
12+
export function Process(doc: TextDocument): FeatureRule | undefined {
13+
const uri = doc.uri;
14+
const content = doc.getText();
15+
const imp = Json.To<Internal.FeatureRule>(doc);
16+
17+
if (!Internal.FeatureRule.is(imp)) return undefined;
18+
19+
const description = imp['minecraft:feature_rules'].description
20+
const id = description.identifier
21+
const feature_used = description.places_feature
22+
23+
const out: FeatureRule = {
24+
id: id,
25+
location: Types.Location.create(uri, content.indexOf(id)),
26+
documentation: Documentation.getDoc(doc, () => `Feature Rule: ${id}`),
27+
feature_used: feature_used
28+
};
29+
30+
return out;
31+
}

src/project/behavior-pack/file-type.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export enum FileType {
1111
/***/
1212
feature,
1313
/***/
14+
feature_rule,
15+
/***/
1416
function,
1517
/***/
1618
item,
@@ -27,10 +29,6 @@ export enum FileType {
2729
/***/
2830
trading,
2931
/***/
30-
terrain_texture,
31-
/***/
32-
item_texture,
33-
/***/
3432
unknown,
3533
}
3634

@@ -58,8 +56,6 @@ export namespace FileType {
5856

5957
//Files
6058
if (uri.endsWith("manifest.json")) return FileType.manifest;
61-
if (uri.endsWith("terrain_texture.json")) return FileType.terrain_texture;
62-
if (uri.endsWith("item_texture.json")) return FileType.item_texture;
6359

6460
return FileType.unknown;
6561
}

src/project/behavior-pack/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ export * as Animation from "./animation";
33
export * as AnimationController from "./animation-controller";
44
export * as Block from "./block";
55
export * as Entity from "./entity";
6+
export * as Feature from "./feature"
7+
export * as FeatureRule from "./feature_rule"
68
export * as Item from "./item";
79
export * as LootTable from "./loot-table";
810
export * as McFunction from "./mcfunction";

0 commit comments

Comments
 (0)