1+ const rotationLookup = new Map ( [
2+ [ 'north' , [ 0.0 , 0.0 , 0.0 ] ] ,
3+ [ 'south' , [ 0.0 , 180.0 , 0.0 ] ] ,
4+ [ 'west' , [ 0.0 , 90.0 , 0.0 ] ] ,
5+ [ 'east' , [ 0.0 , - 90.0 , 0.0 ] ] ,
6+ ] ) ;
7+ const rotationLookupFlipped = new Map ( [
8+ [ 'north' , [ 0.0 , 180.0 , 0.0 ] ] ,
9+ [ 'south' , [ 0.0 , 0.0 , 0.0 ] ] ,
10+ [ 'west' , [ 0.0 , - 90.0 , 0.0 ] ] ,
11+ [ 'east' , [ 0.0 , 90.0 , 0.0 ] ] ,
12+ ] ) ;
113export default function defineComponent ( { name, template, schema } ) {
214 name ( 'bridge:rotate_y_on_place' )
315 schema ( {
@@ -9,58 +21,33 @@ export default function defineComponent({ name, template, schema }) {
921 } )
1022
1123 template ( ( { flip = false } , { create } ) => {
12- const rotationLookup = [
13- [ 0.0 , 0.0 , 0.0 ] ,
14- [ 0.0 , 180.0 , 0.0 ] ,
15- [ 0.0 , 90.0 , 0.0 ] ,
16- [ 0.0 , 270.0 , 0.0 ] ,
17- ]
18- const rotationLookupFlipped = [
19- [ 0.0 , 180.0 , 0.0 ] ,
20- [ 0.0 , 0.0 , 0.0 ] ,
21- [ 0.0 , 270.0 , 0.0 ] ,
22- [ 0.0 , 90.0 , 0.0 ] ,
23- ]
2424 create (
2525 {
26- 'bridge:block_rotation' : [ 2 , 3 , 4 , 5 ] ,
26+ 'minecraft:placement_direction' : {
27+ enabled_states : [
28+ 'minecraft:cardinal_direction'
29+ ] ,
30+ y_rotation_offset : 180 // Face towards player
31+ } ,
2732 } ,
28- 'minecraft:block/description/properties '
29- )
33+ 'minecraft:block/description/traits '
34+ ) ;
3035
3136 create (
3237 {
33- permutations : ( flip
38+ permutations : Array . from ( ( flip
3439 ? rotationLookupFlipped
3540 : rotationLookup
36- ) . map ( ( rotation , i ) => ( {
37- condition : `query.block_property('bridge:block_rotation ') == ${ i + 2 } ` ,
41+ ) . entries ) . map ( ( [ name , rotation ] ) => ( {
42+ condition : `q.block_state('minecraft:cardinal_direction ') == ' ${ name } ' ` ,
3843 components : {
39- 'minecraft:rotation' : rotation ,
44+ 'minecraft:transformation' : {
45+ rotation
46+ }
4047 } ,
4148 } ) ) ,
4249 } ,
4350 'minecraft:block'
4451 )
45-
46- create (
47- {
48- 'minecraft:on_player_placing' : {
49- event : 'bridge:update_rotation' ,
50- } ,
51- } ,
52- 'minecraft:block/components'
53- )
54-
55- create (
56- {
57- 'bridge:update_rotation' : {
58- set_block_property : {
59- 'bridge:block_rotation' : 'query.cardinal_facing_2d' ,
60- } ,
61- } ,
62- } ,
63- 'minecraft:block/events'
64- )
6552 } )
6653}
0 commit comments