From 6b1baee6e445230d7e380f8a8c56961bc040677f Mon Sep 17 00:00:00 2001 From: Miniontoby <47940064+Miniontoby@users.noreply.github.com> Date: Mon, 6 May 2024 19:16:21 +0200 Subject: [PATCH 1/3] Updated connectable.ts to 1.20.60 and added stuff Updated connectable.ts to 1.20.60 and added stuff Stuff added: - `direction_combinations` for making OR's possible between multiple collections of AND directions - UP and DOWN variants of the North, East, South, West directions. - Made the schema better with require statements - Fixed the typescript issues --- .../components/block/connectable.ts | 120 +++++++++++++----- 1 file changed, 89 insertions(+), 31 deletions(-) diff --git a/plugins/ConnectableBlock/components/block/connectable.ts b/plugins/ConnectableBlock/components/block/connectable.ts index fe37c209..b28bd3b1 100644 --- a/plugins/ConnectableBlock/components/block/connectable.ts +++ b/plugins/ConnectableBlock/components/block/connectable.ts @@ -1,11 +1,12 @@ +const directions = ['north', 'east', 'south', 'west', 'up', 'down', 'north_up', 'east_up', 'south_up', 'west_up', 'north_down', 'east_down', 'south_down', 'west_down']; export default defineComponent(({ name, template, schema }) => { name('bridge:connectable') schema({ - description: 'Allows the block to connect to neighboring blocks.', + description: 'Allows the block to connect to neighboring blocks. Note: Requires format_version to be 1.20.60!', type: 'object', anyOf: [ - { required: [ 'tag', 'directions', 'parts' ] }, - { required: [ 'tag', 'directions', 'geometries' ] } + { required: ['tag', 'directions', 'parts'] }, + { required: ['tag', 'directions', 'geometries'] } ], properties: { tag: { @@ -17,7 +18,7 @@ export default defineComponent(({ name, template, schema }) => { type: 'array', items: { type: 'string', - enum: [ 'north', 'east', 'south', 'west', 'up', 'down' ] + enum: directions } }, parts: { @@ -25,6 +26,10 @@ export default defineComponent(({ name, template, schema }) => { type: 'array', items: { type: 'object', + anyOf: [ + { required: ['name', 'directions'] }, + { required: ['name', 'direction_combinations'] } + ], properties: { name: { description: 'Name of the bone.', @@ -33,7 +38,25 @@ export default defineComponent(({ name, template, schema }) => { directions: { description: 'Specifies when to show the part. Multiple directions can be passed.', type: 'array', - items: { enum: [ 'north', 'east', 'south', 'west', 'up', 'down' ] } + items: { + type: 'string', + enum: directions + } + }, + direction_combinations: { + description: 'Specifies when to show the part. Multiple directions combinations can be passed. Does an AND between the directions in inside of the array and an OR between the arrays', + type: 'array', + items: { + type: 'array', + items: { + type: 'string', + enum: directions + } + } + }, + inverted: { + description: 'Specifies to invert the check', + type: 'boolean' } } } @@ -43,6 +66,10 @@ export default defineComponent(({ name, template, schema }) => { type: 'array', items: { type: 'object', + anyOf: [ + { required: ['name', 'directions', 'material_instances'] }, + { required: ['name', 'direction_combinations', 'material_instances'] } + ], properties: { name: { description: 'Definition name of the geometry.', @@ -51,10 +78,25 @@ export default defineComponent(({ name, template, schema }) => { directions: { description: 'Specifies when to show the geometry. Multiple directions can be passed.', type: 'array', - items: { enum: [ 'north', 'east', 'south', 'west', 'up', 'down' ] } + items: { + type: 'string', + enum: directions + } + }, + direction_combinations: { + description: 'Specifies when to show the geometry. Multiple directions can be passed. Does an AND between the directions in inside of the array and an OR between the arrays', + type: 'array', + items: { + type: 'string', + enum: directions + } }, material_instances: { $ref: '/data/packages/minecraftBedrock/schema/block/v1.16.100/components/material_instances.json' + }, + inverted: { + description: 'Specifies to invert the check', + type: 'boolean' } } } @@ -62,37 +104,57 @@ export default defineComponent(({ name, template, schema }) => { } }) - template(({ tag, directions, parts = [], geometries = [] }:{ tag: string, directions: string[], parts: any, geometries: any }, { create }) => { - + template(({ tag, directions, parts = [], geometries = [] }: { tag: string, directions: string[], parts: any, geometries: any }, { create, sourceBlock }) => { const positions = new Map([ - [ 'north', [ 0, 0, -1 ] ], - [ 'east', [ 1, 0, 0 ] ], - [ 'south', [ 0, 0, 1 ] ], - [ 'west', [ -1, 0, 0 ] ], - [ 'up', [ 0, 1, 0 ] ], - [ 'down', [ 0, -1, 0 ] ] + ['north', [0, 0, -1]], + ['east', [1, 0, 0]], + ['south', [0, 0, 1]], + ['west', [-1, 0, 0]], + ['up', [0, 1, 0]], + ['down', [0, -1, 0]], + ['north_up', [0, 1, -1]], + ['east_up', [1, 1, 0]], + ['south_up', [0, 1, 1]], + ['west_up', [-1, 1, 0]], + ['north_down', [0, -1, -1]], + ['east_down', [1, -1, 0]], + ['south_down', [0, -1, 1]], + ['west_down', [-1, -1, 0]], ]) directions.map((dir: string) => { create( { - [`bridge:${dir}_neighbor`]: [ false, true ] + [`bridge:${dir}_neighbor`]: { "values": [false, true] } }, - 'minecraft:block/description/properties' + 'minecraft:block/description/states' ) }) + function getQueryStringForPartOrGeometry(part_or_geo: { directions: string[] | undefined, direction_combinations: string[][] | undefined, inverted: boolean | undefined }) { + return (part_or_geo.inverted ? "!(" : "") + ( + part_or_geo.directions ? ( + part_or_geo.directions.length === 1 ? + `q.block_state('bridge:${part_or_geo.directions}_neighbor')==true` + : + `${part_or_geo.directions.map((dir: string) => `q.block_state('bridge:${dir}_neighbor')==true`).join('&&')}` + ) + : + ( + part_or_geo.direction_combinations.length === 1 ? + `${part_or_geo.direction_combinations[0].map((dir: string) => `q.block_state('bridge:${dir}_neighbor')==true`)}` + : + `${part_or_geo.direction_combinations.map((dirs: string[]) => dirs.map((dir: string) => `q.block_state('bridge:${dir}_neighbor')==true`).join('&&')).join('||')}` + ) + ) + (part_or_geo.inverted ? ")" : "") + } if (parts) { - parts.map(part => { + parts.map((part: { name: string, directions: string[] | undefined, direction_combinations: string[][] | undefined, inverted: boolean | undefined }) => { create( { - ...(part.directions.length === 1 ? { - [part.name]: `q.block_property('bridge:${part.directions}_neighbor')` - } : { - [part.name]: `${part.directions.map((dir: string) => `q.block_property('bridge:${dir}_neighbor')`).join('&&')}` - }) + [part.name]: getQueryStringForPartOrGeometry(part) }, - 'minecraft:block/components/minecraft:part_visibility/conditions' + 'minecraft:block/components/minecraft:geometry/bone_visibility' ) }) } @@ -100,12 +162,8 @@ export default defineComponent(({ name, template, schema }) => { if (geometries) { create( { - permutations: geometries.map(geo => ({ - ...(geo.directions.length === 1 ? { - condition: `q.block_property('bridge:${geo.directions}_neighbor')` - } : { - condition: `${geo.directions.map((dir: string) => `q.block_property('bridge:${dir}_neighbor')`).join('&&')}` - }), + permutations: geometries.map((geo: { name: string, directions: string[] | undefined, direction_combinations: string[][] | undefined, material_instances: any, inverted: boolean | undefined }) => ({ + condition: getQueryStringForPartOrGeometry(geo), components: { 'minecraft:geometry': geo.name, 'minecraft:material_instances': geo.material_instances @@ -120,7 +178,7 @@ export default defineComponent(({ name, template, schema }) => { { 'minecraft:queued_ticking': { looping: true, - interval_range: [ 0, 0 ], + interval_range: [0, 0], on_tick: { event: 'e:update.neighbors' } @@ -134,7 +192,7 @@ export default defineComponent(({ name, template, schema }) => { { [`bridge:${dir}_neighbor`]: `q.block_neighbor_has_any_tag(${positions.get(dir)}, '${tag}') ? true : false` }, - 'minecraft:block/events/e:update.neighbors/set_block_property' + 'minecraft:block/events/e:update.neighbors/set_block_state' ) }) }) From 0828eb1ca62ee1715efa9b6aa6d77b56a7902af1 Mon Sep 17 00:00:00 2001 From: Miniontoby <47940064+Miniontoby@users.noreply.github.com> Date: Mon, 6 May 2024 19:18:28 +0200 Subject: [PATCH 2/3] Update ConnectableBlock to 1.1.3 --- plugins/ConnectableBlock/manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/ConnectableBlock/manifest.json b/plugins/ConnectableBlock/manifest.json index f3d4b672..0dd40425 100644 --- a/plugins/ConnectableBlock/manifest.json +++ b/plugins/ConnectableBlock/manifest.json @@ -2,7 +2,7 @@ "icon": "mdi-cube-outline", "author": "Arexon", "name": "Connectable Block", - "version": "1.1.2", + "version": "1.1.3", "id": "8e362b9e-7c63-4495-b0ab-111fd31de00d", "description": "Easily make your block connect with neighboring blocks by using part_visibity or geometries.", "api_version": 2, @@ -17,4 +17,4 @@ } }, "releaseTimestamp": 1632821021507 -} \ No newline at end of file +} From db2bc841c04477e243c97ec631d32460d69466f7 Mon Sep 17 00:00:00 2001 From: Miniontoby <47940064+Miniontoby@users.noreply.github.com> Date: Tue, 7 May 2024 13:48:28 +0200 Subject: [PATCH 3/3] "values": {} wasn't needed --- plugins/ConnectableBlock/components/block/connectable.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ConnectableBlock/components/block/connectable.ts b/plugins/ConnectableBlock/components/block/connectable.ts index b28bd3b1..ff6d8ce3 100644 --- a/plugins/ConnectableBlock/components/block/connectable.ts +++ b/plugins/ConnectableBlock/components/block/connectable.ts @@ -125,7 +125,7 @@ export default defineComponent(({ name, template, schema }) => { directions.map((dir: string) => { create( { - [`bridge:${dir}_neighbor`]: { "values": [false, true] } + [`bridge:${dir}_neighbor`]: [false, true] }, 'minecraft:block/description/states' )