88import it .unimi .dsi .fastutil .objects .Object2ObjectMap ;
99import it .unimi .dsi .fastutil .objects .Object2ObjectOpenHashMap ;
1010import net .minecraft .block .Blocks ;
11+ import net .minecraft .component .DataComponentTypes ;
12+ import net .minecraft .component .type .FireworkExplosionComponent ;
13+ import net .minecraft .component .type .FireworksComponent ;
1114import net .minecraft .entity .Entity ;
1215import net .minecraft .entity .EntityType ;
1316import net .minecraft .entity .EquipmentSlot ;
1417import net .minecraft .entity .damage .DamageSource ;
1518import net .minecraft .entity .player .ItemCooldownManager ;
1619import net .minecraft .entity .projectile .FireworkRocketEntity ;
17- import net .minecraft .item .FireworkRocketItem ;
1820import net .minecraft .item .ItemStack ;
1921import net .minecraft .item .Items ;
2022import net .minecraft .nbt .NbtCompound ;
21- import net .minecraft .nbt .NbtElement ;
22- import net .minecraft .nbt .NbtInt ;
2323import net .minecraft .network .packet .s2c .play .EntityVelocityUpdateS2CPacket ;
2424import net .minecraft .scoreboard .AbstractTeam ;
2525import net .minecraft .server .network .ServerPlayerEntity ;
3232import net .minecraft .util .ActionResult ;
3333import net .minecraft .util .Formatting ;
3434import net .minecraft .util .Hand ;
35- import net .minecraft .util .TypedActionResult ;
3635import net .minecraft .util .math .BlockPos ;
3736import net .minecraft .util .math .MathHelper ;
3837import net .minecraft .util .math .Vec3d ;
3938import net .minecraft .util .math .random .Random ;
4039import net .minecraft .world .GameMode ;
4140import org .jetbrains .annotations .Nullable ;
42- import xyz .nucleoid .plasmid .game .GameCloseReason ;
43- import xyz .nucleoid .plasmid .game .GameSpace ;
44- import xyz .nucleoid .plasmid .game .common .GlobalWidgets ;
45- import xyz .nucleoid .plasmid .game .common .team .GameTeam ;
46- import xyz .nucleoid .plasmid .game .common .team .GameTeamConfig ;
47- import xyz .nucleoid .plasmid .game .common .team .GameTeamKey ;
48- import xyz .nucleoid .plasmid .game .common .team .TeamManager ;
49- import xyz .nucleoid .plasmid .game .event .GameActivityEvents ;
50- import xyz .nucleoid .plasmid .game .event .GamePlayerEvents ;
51- import xyz .nucleoid .plasmid .game .player .PlayerOffer ;
52- import xyz .nucleoid .plasmid .game .player .PlayerOfferResult ;
53- import xyz .nucleoid .plasmid .game .rule .GameRuleType ;
54- import xyz .nucleoid .plasmid .game .stats .StatisticKey ;
55- import xyz .nucleoid .plasmid .game .stats .StatisticKeys ;
56- import xyz .nucleoid .plasmid .util .ItemStackBuilder ;
41+ import xyz .nucleoid .plasmid .api .game .GameCloseReason ;
42+ import xyz .nucleoid .plasmid .api .game .GameSpace ;
43+ import xyz .nucleoid .plasmid .api .game .common .GlobalWidgets ;
44+ import xyz .nucleoid .plasmid .api .game .common .team .GameTeam ;
45+ import xyz .nucleoid .plasmid .api .game .common .team .GameTeamConfig ;
46+ import xyz .nucleoid .plasmid .api .game .common .team .GameTeamKey ;
47+ import xyz .nucleoid .plasmid .api .game .common .team .TeamManager ;
48+ import xyz .nucleoid .plasmid .api .game .event .GameActivityEvents ;
49+ import xyz .nucleoid .plasmid .api .game .event .GamePlayerEvents ;
50+ import xyz .nucleoid .plasmid .api .game .player .JoinAcceptor ;
51+ import xyz .nucleoid .plasmid .api .game .player .JoinAcceptorResult ;
52+ import xyz .nucleoid .plasmid .api .game .player .JoinOffer ;
53+ import xyz .nucleoid .plasmid .api .game .rule .GameRuleType ;
54+ import xyz .nucleoid .plasmid .api .game .stats .StatisticKeys ;
55+ import xyz .nucleoid .plasmid .api .util .ItemStackBuilder ;
56+ import xyz .nucleoid .stimuli .event .EventResult ;
5757import xyz .nucleoid .stimuli .event .item .ItemUseEvent ;
5858import xyz .nucleoid .stimuli .event .player .PlayerDamageEvent ;
5959import xyz .nucleoid .stimuli .event .player .PlayerDeathEvent ;
@@ -142,7 +142,8 @@ public static void open(ServerWorld world, GameSpace gameSpace, LoopDeLoopMap ma
142142
143143 activity .listen (GameActivityEvents .ENABLE , active ::onOpen );
144144
145- activity .listen (GamePlayerEvents .OFFER , active ::offerPlayer );
145+ activity .listen (GamePlayerEvents .OFFER , JoinOffer ::acceptSpectators );
146+ activity .listen (GamePlayerEvents .ACCEPT , active ::acceptPlayer );
146147 activity .listen (GamePlayerEvents .REMOVE , active ::removePlayer );
147148
148149 activity .listen (GameActivityEvents .TICK , active ::tick );
@@ -154,34 +155,35 @@ public static void open(ServerWorld world, GameSpace gameSpace, LoopDeLoopMap ma
154155 });
155156 }
156157
157- private TypedActionResult < ItemStack > onUseItem (ServerPlayerEntity player , Hand hand ) {
158+ private ActionResult onUseItem (ServerPlayerEntity player , Hand hand ) {
158159 ItemStack heldStack = player .getStackInHand (hand );
159160
160161 LoopDeLoopPlayer state = this .playerStates .get (player );
161162 if (state != null ) {
162163 if (heldStack .getItem () == Items .FEATHER ) {
163164 ItemCooldownManager cooldown = player .getItemCooldownManager ();
164- if (!cooldown .isCoolingDown (heldStack . getItem () )) {
165+ if (!cooldown .isCoolingDown (heldStack )) {
165166 Vec3d rotationVec = player .getRotationVec (1.0F );
166167 player .setVelocity (rotationVec .multiply (LEAP_VELOCITY ));
167168 Vec3d oldVel = player .getVelocity ();
168169 player .setVelocity (oldVel .x , oldVel .y + 0.5f , oldVel .z );
169170 player .networkHandler .sendPacket (new EntityVelocityUpdateS2CPacket (player ));
170171
171- player .playSound (SoundEvents .ENTITY_HORSE_SADDLE , SoundCategory .PLAYERS , 1.0F , 1.0F );
172- cooldown .set (heldStack . getItem () , LEAP_INTERVAL_TICKS );
172+ player .playSoundToPlayer (SoundEvents .ENTITY_HORSE_SADDLE , SoundCategory .PLAYERS , 1.0F , 1.0F );
173+ cooldown .set (heldStack , LEAP_INTERVAL_TICKS );
173174
174175 state .boostUsed ++;
176+ return ActionResult .SUCCESS_SERVER ;
175177 }
176178 } else if (heldStack .getItem () == Items .FIREWORK_ROCKET ) {
177179 ItemCooldownManager cooldown = player .getItemCooldownManager ();
178- if (!cooldown .isCoolingDown (heldStack . getItem () )) {
180+ if (!cooldown .isCoolingDown (heldStack )) {
179181 state .boostUsed ++;
180182 }
181183 }
182184 }
183185
184- return TypedActionResult . pass ( ItemStack . EMPTY ) ;
186+ return ActionResult . PASS ;
185187 }
186188
187189 private void onOpen () {
@@ -218,7 +220,7 @@ private void onOpen() {
218220 this .sidebar .render (this .buildLeaderboard ());
219221 }
220222
221- private PlayerOfferResult offerPlayer ( PlayerOffer offer ) {
223+ private JoinAcceptorResult acceptPlayer ( JoinAcceptor offer ) {
222224 return this .spawnLogic .acceptPlayer (offer , GameMode .SPECTATOR );
223225 }
224226
@@ -292,7 +294,7 @@ private void tickPlayers(long time) {
292294
293295 private boolean tickPlayer (ServerPlayerEntity player , LoopDeLoopPlayer state , long time ) {
294296 if (time < this .fallFlyingTime ) {
295- player .startFallFlying ();
297+ player .startGliding ();
296298 }
297299
298300 int nextHoopIdx = state .lastHoop + 1 ;
@@ -314,7 +316,7 @@ private boolean tickPlayer(ServerPlayerEntity player, LoopDeLoopPlayer state, lo
314316 state .lastPos = currentPos ;
315317
316318 if (nextHoop .intersectsSegment (lastPos , currentPos )) {
317- player .playSound (SoundEvents .ENTITY_EXPERIENCE_ORB_PICKUP , SoundCategory .PLAYERS , 1.0F , 1.0F );
319+ player .playSoundToPlayer (SoundEvents .ENTITY_EXPERIENCE_ORB_PICKUP , SoundCategory .PLAYERS , 1.0F , 1.0F );
318320
319321 if (!this .config .flappyMode ()) {
320322 giveRocket (player , 1 , this .config .rocketPower ());
@@ -387,7 +389,7 @@ private void onPlayerFinish(ServerPlayerEntity player, LoopDeLoopPlayer state, l
387389 .append (" place!" );
388390
389391 player .sendMessage (message , true );
390- player .playSound (SoundEvents .ENTITY_PLAYER_LEVELUP , SoundCategory .PLAYERS , 1.0F , 1.0F );
392+ player .playSoundToPlayer (SoundEvents .ENTITY_PLAYER_LEVELUP , SoundCategory .PLAYERS , 1.0F , 1.0F );
391393 player .changeGameMode (GameMode .SPECTATOR );
392394 if (this .finished .size () == 1 && (long ) playerStates .entrySet ().size () > 1 ) isFirst = true ;
393395 this .publishPlayerStatistics (player , state , time , isFirst );
@@ -442,7 +444,7 @@ private void failHoop(ServerPlayerEntity player, LoopDeLoopPlayer state, long ti
442444 );
443445 }
444446
445- player .playSound (SoundEvents .ENTITY_VILLAGER_NO , SoundCategory .PLAYERS , 1.0F , 1.0F );
447+ player .playSoundToPlayer (SoundEvents .ENTITY_VILLAGER_NO , SoundCategory .PLAYERS , 1.0F , 1.0F );
446448 }
447449
448450 private void broadcastWin () {
@@ -471,16 +473,16 @@ private void broadcastWin() {
471473 this .broadcastSound (SoundEvents .ENTITY_VILLAGER_YES );
472474 }
473475
474- private ActionResult onPlayerDamage (ServerPlayerEntity player , DamageSource source , float amount ) {
476+ private EventResult onPlayerDamage (ServerPlayerEntity player , DamageSource source , float amount ) {
475477 long time = this .world .getTime ();
476478 this .failHoop (player , this .playerStates .get (player ), time );
477- return ActionResult . FAIL ;
479+ return EventResult . DENY ;
478480 }
479481
480- private ActionResult onPlayerDeath (ServerPlayerEntity player , DamageSource source ) {
482+ private EventResult onPlayerDeath (ServerPlayerEntity player , DamageSource source ) {
481483 long time = this .world .getTime ();
482484 this .failHoop (player , this .playerStates .get (player ), time );
483- return ActionResult . FAIL ;
485+ return EventResult . DENY ;
484486 }
485487
486488 private void spawnParticipant (ServerPlayerEntity player ) {
@@ -504,9 +506,7 @@ private void spawnParticipant(ServerPlayerEntity player) {
504506
505507 private static void giveRocket (ServerPlayerEntity player , int n , int flightPower ) {
506508 ItemStack rockets = new ItemStack (Items .FIREWORK_ROCKET , n );
507- NbtCompound rocketPowered = new NbtCompound ();
508- rocketPowered .putInt ("Flight" , flightPower );
509- rockets .getOrCreateNbt ().put ("Fireworks" , rocketPowered );
509+ rockets .set (DataComponentTypes .FIREWORKS , new FireworksComponent (flightPower , List .of ()));
510510 player .getInventory ().insertStack (rockets );
511511 }
512512
@@ -515,7 +515,7 @@ private void broadcastSound(SoundEvent sound, float pitch) {
515515 if (player .equals (this .lastCompleter )) {
516516 continue ;
517517 }
518- player .playSound (sound , SoundCategory .PLAYERS , 1.0F , pitch );
518+ player .playSoundToPlayer (sound , SoundCategory .PLAYERS , 1.0F , pitch );
519519 }
520520 }
521521
0 commit comments