diff --git a/plugins/ConnectableBlock/components/block/connectable.ts b/plugins/ConnectableBlock/components/block/connectable.ts index fe37c209..ff6d8ce3 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`]: [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' ) }) }) 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 +}