Skip to content

Commit

Permalink
- Add feature processing
Browse files Browse the repository at this point in the history
- Setup item texture and terrain texture file type
  • Loading branch information
Xterionix committed Jul 3, 2024
1 parent 4c8f3d9 commit 1c17270
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 0 deletions.
148 changes: 148 additions & 0 deletions src/Lib/Internal/BehaviorPack/Feature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { FormatVersion } from "../Types/FormatVersion";

const features = [
'minecraft:weighted_random_feature',
'minecraft:aggregate_feature',
'minecraft:cave_carver_feature',
'minecraft:fossil_feature',
'minecraft:geode_feature',
'minecraft:growing_plant_feature',
'minecraft:multiface_feature',
'minecraft:nether_cave_carver_feature',
'minecraft:ore_feature',
'minecraft:partially_exposed_blob_feature',
'minecraft:scatter_feature',
'minecraft:search_feature',
'minecraft:sequence_feature',
'minecraft:single_block_feature',
'minecraft:snap_to_surface_feature',
'minecraft:structure_template_feature',
'minecraft:surface_relative_threshold_feature',
'minecraft:tree_feature',
'minecraft:underwater_cave_carver_feature',
'minecraft:vegetation_patch_feature'
]

/** */
export interface Feature extends Readonly<FormatVersion> {
/** */
format_version: string;
/** */
'minecraft:weighted_random_feature'?: {
description: {
identifier: string
}
},
'minecraft:aggregate_feature'?: {
description: {
identifier: string
}
},
'minecraft:cave_carver_feature'?: {
description: {
identifier: string
}
},
'minecraft:fossil_feature'?: {
description: {
identifier: string
}
},
'minecraft:geode_feature'?: {
description: {
identifier: string
}
},
'minecraft:growing_plant_feature'?: {
description: {
identifier: string
}
},
'minecraft:multiface_feature'?: {
description: {
identifier: string
}
},
'minecraft:nether_cave_carver_feature'?: {
description: {
identifier: string
}
},
'minecraft:ore_feature'?: {
description: {
identifier: string
}
},
'minecraft:partially_exposed_blob_feature'?: {
description: {
identifier: string
}
},
'minecraft:scatter_feature'?: {
description: {
identifier: string
}
},
'minecraft:search_feature'?: {
description: {
identifier: string
}
},
'minecraft:sequence_feature'?: {
description: {
identifier: string
}
},
'minecraft:single_block_feature'?: {
description: {
identifier: string
}
},
'minecraft:snap_to_surface_feature'?: {
description: {
identifier: string
}
},
'minecraft:structure_template_feature'?: {
description: {
identifier: string
}
},
'minecraft:surface_relative_threshold_feature'?: {
description: {
identifier: string
}
},
'minecraft:tree_feature'?: {
description: {
identifier: string
}
},
'minecraft:underwater_cave_carver_feature'?: {
description: {
identifier: string
}
},
'minecraft:vegetation_patch_feature'?: {
description: {
identifier: string
}
}
}

/** */
export namespace Feature {
/**
*
* @param value
* @returns
*/
export function is(value: any): value is Feature {
if (value && typeof value.format_version === "string" && typeof value === 'object') {
const keys = Object.keys(value)
const type = features.filter(feature => keys.includes(feature))[0]
if (type && typeof value[type].description === 'object' && typeof value[type].description.identifier === 'string') return true
}
return false;
}
}
8 changes: 8 additions & 0 deletions src/Lib/Project/BehaviorPack/BehaviorPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as AnimationController from "./AnimationController";
import * as Animation from "./Animation";
import * as Block from "./Block";
import * as Entity from "./Entity";
import * as Feature from "./Feature";
import * as Function from "./McFunction";
import * as Item from "./Item";
import * as LootTable from "./LootTable";
Expand Down Expand Up @@ -36,6 +37,8 @@ export class BehaviorPack implements Container, Pack {
readonly blocks: DataSet<Block.Block>;
/**The collection of entities*/
readonly entities: DataSet<Entity.Entity>;
/**The collection of features*/
readonly features: DataSet<Feature.Feature>;
/**The collection of mcfunctions*/
readonly functions: DataSet<Function.Function>;
/**The collection of items*/
Expand Down Expand Up @@ -64,6 +67,7 @@ export class BehaviorPack implements Container, Pack {
this.loot_tables = new DataSet();
this.structures = new DataSet();
this.trading = new DataSet();
this.features = new DataSet();
}

/**
Expand Down Expand Up @@ -102,6 +106,10 @@ export class BehaviorPack implements Container, Pack {

case FileType.trading:
return this.trading.set(Trading.Process(doc));

case FileType.feature:
return this.features.set(Feature.Process(doc))

}

return undefined;
Expand Down
4 changes: 4 additions & 0 deletions src/Lib/Project/BehaviorPack/Feature/Feature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Types } from "bc-minecraft-bedrock-types";

/** */
export interface Feature extends Types.BaseObject { }
32 changes: 32 additions & 0 deletions src/Lib/Project/BehaviorPack/Feature/Process.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as internal from "../../../Internal/BehaviorPack/Feature";
import { Json } from "../../../Internal/Json";
import { Molang } from "bc-minecraft-molang";
import { Types } from "bc-minecraft-bedrock-types";
import { Documentation } from "../../../Types/Documentation";
import { TextDocument } from "../../../Types/TextDocument";
import { Feature } from "./Feature";

/**
*
* @param doc
* @returns
*/
export function Process(doc: TextDocument): Feature | undefined {
const uri = doc.uri;
const content = doc.getText();
const imp = Json.To<internal.Feature>(doc);

if (!internal.Feature.is(imp)) return undefined;

//@ts-ignore
const container = imp[Object.keys(imp).filter(x => !x.startsWith('format_version'))[0]]
const id = container.description.identifier;

const out: Feature = {
id: id,
location: Types.Location.create(uri, content.indexOf(id)),
documentation: Documentation.getDoc(doc, () => `Feature: ${id}`),
};

return out;
}
4 changes: 4 additions & 0 deletions src/Lib/Project/BehaviorPack/Feature/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Auto generated */

export * from "./Feature";
export * from "./Process";
9 changes: 9 additions & 0 deletions src/Lib/Project/BehaviorPack/FileType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export enum FileType {
/***/
entity,
/***/
feature,
/***/
function,
/***/
item,
Expand All @@ -25,6 +27,10 @@ export enum FileType {
/***/
trading,
/***/
terrain_texture,
/***/
item_texture,
/***/
unknown,
}

Expand All @@ -44,13 +50,16 @@ export namespace FileType {
if (/[\\\/]spawn_rules[\\\/]/.test(uri)) return FileType.spawn_rule;
if (/[\\\/]structures[\\\/]/.test(uri)) return FileType.structure;
if (/[\\\/]trading[\\\/]/.test(uri)) return FileType.trading;
if (/[\\\/]features[\\\/]/.test(uri)) return FileType.feature;
//These can also be subfolders
if (/[\\\/]blocks[\\\/]/.test(uri)) return FileType.block;
if (/[\\\/]entities[\\\/]/.test(uri)) return FileType.entity;
if (/[\\\/]items[\\\/]/.test(uri)) return FileType.item;

//Files
if (uri.endsWith("manifest.json")) return FileType.manifest;
if (uri.endsWith("terrain_texture.json")) return FileType.terrain_texture;
if (uri.endsWith("item_texture.json")) return FileType.item_texture;

return FileType.unknown;
}
Expand Down

0 comments on commit 1c17270

Please sign in to comment.