Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions plugins/BlockRotationV2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Simple Block Rotation

Simple Block Rotation automates common behaviour for rotating blocks.

## Installation

Simply install the extension to your project from bridge.'s extension library.

## Usage

Add either the `bridge:log_rotate_on_place`, `bridge:rotate_on_place`, or `bridge:rotate_y_on_place` block components to your block.
69 changes: 33 additions & 36 deletions plugins/BlockRotationV2/components/block/logRotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,49 @@ export default function defineComponent({ name, template, schema }) {
})

template(({ rotation_from = 'player' }, { create }) => {
const rotationLookup = [
[0.0, 0.0, 0.0],
[90.0, 0.0, 0.0],
[0.0, 90.0, -90.0],
]
create(
{
'bridge:block_rotation': [0, 1, 2],
},
'minecraft:block/description/properties'
)
const state = rotation_from === 'player'
? 'cardinal_facing'
: 'block_face';

create(
{
permutations: rotationLookup.map((rotation, i) => ({
condition: `query.block_property('bridge:block_rotation') == ${i}`,
components: {
'minecraft:rotation': rotation,
},
})),
},
'minecraft:block'
)

create(
{
'minecraft:on_player_placing': {
event: 'bridge:update_rotation',
'minecraft:placement_direction': {
enabled_states: [
`minecraft:${state}`
],
...(state === 'cardinal_direction' ? { y_rotation_offset: 180 } : {})
},
},
'minecraft:block/components'
)
'minecraft:block/description/traits'
);

create(
{
'bridge:update_rotation': {
set_block_property: {
'bridge:block_rotation': `math.floor(${
rotation_from === 'player'
? 'query.cardinal_facing'
: 'query.block_face'
} / 2.0)`,
permutations: [
// X axis
{
condition: `q.block_state('minecraft:${state}') == 'west' || q.block_state('minecraft:${state}') == 'east'`,
components: {
"minecraft:transformation": { rotation: [0, 0, 90] }
}
},
},
// Y axis
{
condition: `q.block_state('minecraft:${state}') == 'down' || q.block_state('minecraft:${state}') == 'up'`,
components: {
"minecraft:transformation": { rotation: [0, 0, 0] }
}
},
// Z axis
{
condition: `q.block_state('minecraft:${state}') == 'north' || q.block_state('minecraft:${state}') == 'south'`,
components: {
"minecraft:transformation": { rotation: [90, 0, 0] }
}
}
]
},
'minecraft:block/events'
'minecraft:block'
)
})
}
63 changes: 26 additions & 37 deletions plugins/BlockRotationV2/components/block/rotate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const rotationLookup = new Map([
['down', [-90.0, 0.0, 0.0]],
['up', [90.0, 0.0, 0.0]],
['north', [0.0, 0.0, 0.0]],
['west', [0.0, 90.0, 0.0]],
['south', [0.0, 180.0, 0.0]],
['east', [0.0, -90.0, 0.0]],
]);
export default function defineComponent({ name, template, schema }) {
name('bridge:rotate_on_place')
schema({
Expand All @@ -10,53 +18,34 @@ export default function defineComponent({ name, template, schema }) {
})

template(({ rotation_from = 'player' }, { create }) => {
const rotationLookup = [
[0.0, 0.0, 0.0],
[0.0, 0.0, 180.0],
[90.0, 0.0, 0.0],
[-90.0, 0.0, 0.0],
[0.0, 0.0, -90.0],
]
const state = rotation_from === 'player'
? 'cardinal_direction'
: 'block_face';

create(
{
'bridge:block_rotation': [0, 1, 2, 3, 4, 5],
'minecraft:placement_direction': {
enabled_states: [
`minecraft:${state}`
],
...(state === 'cardinal_direction' ? { y_rotation_offset: 180 } : {})
},
},
'minecraft:block/description/properties'
)
'minecraft:block/description/traits'
);

create(
{
permutations: rotationLookup.map((rotation, i) => ({
condition: `query.block_property('bridge:block_rotation') == ${i}`,
permutations: Array.from(rotationLookup.entries()).map(([name, rotation]) => ({
condition: `q.block_state('minecraft:${state}') == '${name}'`,
components: {
'minecraft:rotation': rotation,
'minecraft:transformation': {
rotation,
},
},
})),
},
'minecraft:block'
)

create(
{
'minecraft:on_player_placing': {
event: 'bridge:update_rotation',
},
},
'minecraft:block/components'
)

create(
{
'bridge:update_rotation': {
set_block_property: {
'bridge:block_rotation':
rotation_from === 'player'
? 'query.cardinal_facing'
: 'query.block_face',
},
},
},
'minecraft:block/events'
)
);
})
}
65 changes: 26 additions & 39 deletions plugins/BlockRotationV2/components/block/rotateY.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
const rotationLookup = new Map([
['north', [0.0, 0.0, 0.0]],
['south', [0.0, 180.0, 0.0]],
['west', [0.0, 90.0, 0.0]],
['east', [0.0, -90.0, 0.0]],
]);
const rotationLookupFlipped = new Map([
['north', [0.0, 180.0, 0.0]],
['south', [0.0, 0.0, 0.0]],
['west', [0.0, -90.0, 0.0]],
['east', [0.0, 90.0, 0.0]],
]);
export default function defineComponent({ name, template, schema }) {
name('bridge:rotate_y_on_place')
schema({
Expand All @@ -9,58 +21,33 @@ export default function defineComponent({ name, template, schema }) {
})

template(({ flip = false }, { create }) => {
const rotationLookup = [
[0.0, 0.0, 0.0],
[0.0, 180.0, 0.0],
[0.0, 90.0, 0.0],
[0.0, 270.0, 0.0],
]
const rotationLookupFlipped = [
[0.0, 180.0, 0.0],
[0.0, 0.0, 0.0],
[0.0, 270.0, 0.0],
[0.0, 90.0, 0.0],
]
create(
{
'bridge:block_rotation': [2, 3, 4, 5],
'minecraft:placement_direction': {
enabled_states: [
'minecraft:cardinal_direction'
],
y_rotation_offset: 180 // Face towards player
},
},
'minecraft:block/description/properties'
)
'minecraft:block/description/traits'
);

create(
{
permutations: (flip
permutations: Array.from((flip
? rotationLookupFlipped
: rotationLookup
).map((rotation, i) => ({
condition: `query.block_property('bridge:block_rotation') == ${i + 2}`,
).entries).map(([name, rotation]) => ({
condition: `q.block_state('minecraft:cardinal_direction') == '${name}'`,
components: {
'minecraft:rotation': rotation,
'minecraft:transformation': {
rotation
}
},
})),
},
'minecraft:block'
)

create(
{
'minecraft:on_player_placing': {
event: 'bridge:update_rotation',
},
},
'minecraft:block/components'
)

create(
{
'bridge:update_rotation': {
set_block_property: {
'bridge:block_rotation': 'query.cardinal_facing_2d',
},
},
},
'minecraft:block/events'
)
})
}
4 changes: 2 additions & 2 deletions plugins/BlockRotationV2/manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"author": "Joel ant 05",
"name": "Simple Block Rotation",
"version": "1.0.3",
"version": "1.0.4",
"id": "b05592ed-cc3e-437c-ae7c-3f51353051bd",
"description": "Adding rotation to blocks is as easy as it should be: Adding a single component! (Deprecated in MC 1.21.20)",
"description": "Adding rotation to blocks is as easy as it should be: Adding a single component!",
"api_version": 2,
"target": "v2",
"tags": [
Expand Down
Binary file modified plugins/BlockRotationV2/plugin.zip
Binary file not shown.
15 changes: 15 additions & 0 deletions plugins/ConnectableBlock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Connectable Block

Connectable Block automates common behaviour for connectable blocks.

## Installation

After installing the plugin from bridge.'s extension store, import the script to your main scripting entry point:

```js
import * as Connectable from 'scripts/connectable.js'
```

## Usage

Add the `bridge:connectable` block component to a block. Specify settings within the component. Your block should now connect.
Loading
Loading