Skip to content

Commit

Permalink
Merge pull request #144 from Miniontoby/patch-1
Browse files Browse the repository at this point in the history
Updated connectable.ts to 1.20.60 and added stuff
  • Loading branch information
outercloudstudio authored May 17, 2024
2 parents c880ed5 + db2bc84 commit bd00cb3
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 33 deletions.
120 changes: 89 additions & 31 deletions plugins/ConnectableBlock/components/block/connectable.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -17,14 +18,18 @@ export default defineComponent(({ name, template, schema }) => {
type: 'array',
items: {
type: 'string',
enum: [ 'north', 'east', 'south', 'west', 'up', 'down' ]
enum: directions
}
},
parts: {
description: 'The part_visiblity method | Defines when to hide specific parts of the geometry. Not compatible with the "geometries" method.',
type: 'array',
items: {
type: 'object',
anyOf: [
{ required: ['name', 'directions'] },
{ required: ['name', 'direction_combinations'] }
],
properties: {
name: {
description: 'Name of the bone.',
Expand All @@ -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'
}
}
}
Expand All @@ -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.',
Expand All @@ -51,61 +78,92 @@ 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'
}
}
}
}
}
})

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'
)
})
}

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
Expand All @@ -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'
}
Expand All @@ -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'
)
})
})
Expand Down
4 changes: 2 additions & 2 deletions plugins/ConnectableBlock/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -17,4 +17,4 @@
}
},
"releaseTimestamp": 1632821021507
}
}

0 comments on commit bd00cb3

Please sign in to comment.