1- import { VECTOR3_UP , VECTOR3_ZERO } from "@minecraft/math" ;
2- import { Dimension , StartupEvent , VanillaEntityIdentifier , world , World } from "@minecraft/server" ;
1+ import { VECTOR3_DOWN , VECTOR3_UP , VECTOR3_ZERO } from "@minecraft/math" ;
2+ import { BlockCustomComponent , Dimension , StartupEvent , system , VanillaEntityIdentifier , world , World } from "@minecraft/server" ;
33import { V3 } from "../../math/vectorUtils" ;
44import { ActionFormData } from "@minecraft/server-ui" ;
55
66const MichaelDimID = "whynot:michael_dimension"
77let michaelDim : Dimension
88export function main ( ) {
99 michaelDim = world . getDimension ( MichaelDimID )
10- world . structureManager . place ( "whynot:michael_structure" , michaelDim , V3 . make ( - 1 , 0 , - 4 ) )
11- michaelDim . getEntities ( { type : "whynot:michael_zombie" } ) . forEach ( entity => entity . remove ( ) )
12- michaelDim . spawnEntity ( "whynot:michael_zombie" as VanillaEntityIdentifier , V3 . make ( 22 , 1 , 0 ) )
10+ world . tickingAreaManager . createTickingArea ( "whynot:michael_ticking" , { dimension : michaelDim , from : V3 . make ( 19 , 0 , 0 ) , to : V3 . make ( 21 , 2 , 0 ) } )
11+
1312 world . afterEvents . playerInteractWithBlock . subscribe ( ev => {
13+ if ( ev . player . dimension == michaelDim ) return
1414 if ( ev . block . typeId != "whynot:gravestone" ) return
15- const form = new ActionFormData ( )
16- form . title ( "Gravestone" )
17- form . body ( "Here lies the king of pop, do you accept his challenge?" )
18- form . button ( "Yes" )
19- form . button ( "Yes" )
20- form . show ( ev . player ) . finally ( ( ) => {
21- ev . player . teleport ( VECTOR3_UP , { dimension : michaelDim } )
22- } )
15+
2316 } )
2417
18+
19+ system . runInterval ( tick , 1 )
20+
21+ }
22+ let battleStarted = false
23+ function tick ( ) {
24+ let michael = michaelDim . getEntities ( { type : "whynot:michael_zombie" } ) [ 0 ]
25+ if ( ! michael ) return
26+ let playerNear = michaelDim . getPlayers ( { maxDistance : 4 , location : michael . location , closest : 1 } ) . length > 0
27+ if ( playerNear && ! battleStarted ) {
28+ michael . applyImpulse ( V3 . make ( 0 , 1 , 0 ) )
29+ battleStarted = true
30+ }
31+ if ( battleStarted && ! michael . isOnGround && michael . getVelocity ( ) . y < 0.0 ) {
32+ michaelDim . setBlockType ( V3 . add ( michael . location , VECTOR3_DOWN ) , "minecraft:stone" )
33+ }
2534}
2635export function startup ( ev : StartupEvent ) {
2736 ev . dimensionRegistry . registerCustomDimension ( MichaelDimID ) ;
37+ ev . blockComponentRegistry . registerCustomComponent ( "whynot:gravestone_component" , {
38+ onPlayerInteract ( ev ) {
39+ if ( ! ev . player ) return
40+ if ( ev . dimension == michaelDim ) return
41+ world . structureManager . place ( "whynot:michael_structure" , michaelDim , V3 . make ( - 1 , 0 , - 4 ) )
42+
43+ michaelDim . getEntities ( { type : "whynot:michael_zombie" } ) . forEach ( entity => entity . remove ( ) )
44+ system . runTimeout ( ( ) => {
45+ michaelDim . spawnEntity ( "whynot:michael_zombie" as VanillaEntityIdentifier , V3 . make ( 20.5 , 1.0 , 0.5 ) )
46+ } , 25 )
47+
48+ const form = new ActionFormData ( )
49+ form . title ( "Gravestone" )
50+ form . body ( "Here lies the king of pop, do you accept his challenge?" )
51+ form . button ( "Yes" )
52+ form . button ( "Yes" )
53+ form . show ( ev . player ) . finally ( ( ) => {
54+ ev . player ?. teleport ( V3 . make ( 0.5 , 1.0 , 0.5 ) , { dimension : michaelDim } )
55+ } )
56+ } ,
57+ onTick ( ev ) {
58+ if ( ev . dimension != michaelDim ) return
59+ michaelDim . spawnEntity ( "whynot:dancer_zombie" as VanillaEntityIdentifier , ev . block . location )
60+ }
61+ } )
2862}
0 commit comments