23
23
import net .minecraft .sound .SoundEvents ;
24
24
import net .minecraft .text .LiteralText ;
25
25
import net .minecraft .text .Text ;
26
+ import net .minecraft .util .ActionResult ;
26
27
import net .minecraft .util .Formatting ;
28
+ import net .minecraft .util .Pair ;
27
29
import net .minecraft .util .math .BlockPos ;
28
30
import net .minecraft .util .math .MathHelper ;
29
31
import net .minecraft .util .math .Vec3d ;
30
32
import net .minecraft .world .GameMode ;
31
33
import xyz .nucleoid .plasmid .game .GameWorld ;
32
- import xyz .nucleoid .plasmid .game .event .GameCloseListener ;
33
- import xyz .nucleoid .plasmid .game .event .GameOpenListener ;
34
- import xyz .nucleoid .plasmid .game .event .GameTickListener ;
35
- import xyz .nucleoid .plasmid .game .event .OfferPlayerListener ;
36
- import xyz .nucleoid .plasmid .game .event .PlayerAddListener ;
37
- import xyz .nucleoid .plasmid .game .event .PlayerDamageListener ;
38
- import xyz .nucleoid .plasmid .game .event .PlayerDeathListener ;
39
- import xyz .nucleoid .plasmid .game .event .PlayerRemoveListener ;
34
+ import xyz .nucleoid .plasmid .game .event .*;
40
35
import xyz .nucleoid .plasmid .game .player .JoinResult ;
41
36
import xyz .nucleoid .plasmid .game .rule .GameRule ;
42
37
import xyz .nucleoid .plasmid .game .rule .RuleResult ;
43
38
import xyz .nucleoid .plasmid .util .ItemStackBuilder ;
44
39
45
40
import javax .annotation .Nullable ;
46
- import java .util .ArrayList ;
47
- import java .util .Iterator ;
48
- import java .util .List ;
49
- import java .util .Map ;
50
- import java .util .Set ;
41
+ import java .util .*;
42
+
51
43
52
44
public final class LoopDeLoopActive {
53
45
private final GameWorld gameWorld ;
@@ -56,10 +48,12 @@ public final class LoopDeLoopActive {
56
48
private final List <LoopDeLoopWinner > finished ;
57
49
private final LoopDeLoopSpawnLogic spawnLogic ;
58
50
private final LoopDeLoopTimerBar timerBar = new LoopDeLoopTimerBar ();
51
+ private LoopDeLoopScoreboard scoreboard ;
59
52
// Only stores flying players, i.e non-completed players
60
53
private final Object2ObjectMap <ServerPlayerEntity , LoopDeLoopPlayer > player_states ;
61
54
@ Nullable
62
55
private ServerPlayerEntity lastCompleter ;
56
+ private final List <Pair <ServerPlayerEntity , LoopDeLoopPlayer >> topPlayers ;
63
57
@ Nullable
64
58
Team team ;
65
59
private long closeTime = -1 ;
@@ -73,6 +67,7 @@ private LoopDeLoopActive(GameWorld gameWorld, LoopDeLoopMap map, LoopDeLoopConfi
73
67
this .finished = new ArrayList <>();
74
68
this .spawnLogic = new LoopDeLoopSpawnLogic (gameWorld , map );
75
69
this .player_states = new Object2ObjectOpenHashMap <>();
70
+ this .topPlayers = new ArrayList <>();
76
71
77
72
for (ServerPlayerEntity player : participants ) {
78
73
this .player_states .put (player , new LoopDeLoopPlayer ());
@@ -125,11 +120,17 @@ private void onOpen() {
125
120
long time = world .getTime ();
126
121
this .startTime = time - (time % 20 ) + (4 * 20 ) + 19 ;
127
122
this .finishTime = this .startTime + (this .config .timeLimit * 20 );
123
+ this .scoreboard = new LoopDeLoopScoreboard (
124
+ this .gameWorld .getWorld ().getScoreboard (),
125
+ this .config .loops
126
+ );
127
+ this .scoreboard .render (this .topPlayers );
128
128
}
129
129
130
130
private void onClose () {
131
131
this .gameWorld .getWorld ().getScoreboard ().removeTeam (this .team );
132
132
this .timerBar .close ();
133
+ this .scoreboard .close ();
133
134
}
134
135
135
136
private void addPlayer (ServerPlayerEntity player ) {
@@ -247,47 +248,65 @@ private void tickPlayers(long time) {
247
248
248
249
LoopDeLoopHoop hoop = this .map .hoops .get (nextHoop );
249
250
250
- int lastHoopZ ;
251
- int lastHoopX ;
251
+ double lastHoopZ ;
252
+ double lastHoopX ;
253
+ int lastHoopRadius ;
252
254
if (state .lastHoop == -1 ) {
253
255
lastHoopZ = -5 ;
254
256
lastHoopX = 0 ;
257
+ lastHoopRadius = 10 ;
255
258
} else {
256
- BlockPos last = this .map .hoops .get (state .lastHoop ).centre ;
257
- lastHoopZ = last .getZ ();
258
- lastHoopX = last .getX ();
259
+ LoopDeLoopHoop last = this .map .hoops .get (state .lastHoop );
260
+ lastHoopZ = Vec3d .ofCenter (last .centre ).getZ ();
261
+ lastHoopX = Vec3d .ofCenter (last .centre ).getX ();
262
+ lastHoopRadius = last .radius ;
259
263
}
260
264
261
265
BlockPos centre = hoop .centre ;
262
266
263
- double yMax = ((double ) this .config .maxYVariation / 2 ) + 30 ;
267
+ double yMax = ((double ) this .config .yVarMax / 2 ) + 30 ;
264
268
boolean outOfBounds = Math .floor (player .getZ ()) > centre .getZ () ||
265
269
player .getZ () < lastHoopZ - 10 ||
266
- player .getY () < 75 - yMax ||
267
- player .getY () > 75 + yMax ||
270
+ player .getY () < 128 - yMax ||
271
+ player .getY () > 128 + yMax ||
268
272
player .getY () < 0 ||
269
- player .getX () > Math .max (centre .getX (), lastHoopX ) + 30 ||
270
- player .getX () < Math .min (centre .getX (), lastHoopX ) - 30 ;
273
+ player .getX () > Math .max (centre .getX () + hoop . radius , lastHoopX + lastHoopRadius ) + 30 ||
274
+ player .getX () < Math .min (centre .getX () + hoop . radius , lastHoopX + lastHoopRadius ) - 30 ;
271
275
272
276
if (hoop .intersectsSegment (state .lastPos , player .getPos ())) {
273
277
player .playSound (SoundEvents .ENTITY_EXPERIENCE_ORB_PICKUP , SoundCategory .PLAYERS , 1.0F , 1.0F );
274
278
giveRocket (player , 1 );
275
279
state .lastHoop += 1 ;
280
+ state .previousFails = 0 ;
281
+ state .lastFailOrSuccess = time ;
282
+
283
+ if (this .topPlayers .stream ().noneMatch (i -> i .getLeft ().getUuid () == player .getUuid ())) {
284
+ this .topPlayers .add (new Pair <>(player , state ));
285
+ }
286
+
287
+ this .topPlayers .sort (Comparator .comparing (i -> i .getRight ().lastHoop ));
288
+
289
+ if (this .topPlayers .size () > 5 ) {
290
+ this .topPlayers .remove (5 );
291
+ }
292
+
293
+ this .scoreboard .render (this .topPlayers );
276
294
} else if (outOfBounds ) {
277
- this .failHoop (player , state , time );
295
+ this .failHoop (player , state , time );
278
296
}
279
297
280
298
state .lastPos = player .getPos ();
281
299
}
282
300
}
283
301
284
302
private void failHoop (ServerPlayerEntity player , LoopDeLoopPlayer state , long time ) {
285
- if (time - state .lastFailTp < 20 ) {
303
+ if (time - state .lastFailOrSuccess < 10 ) {
286
304
return ;
287
305
}
288
306
289
- state .lastFailTp = time ;
290
- giveRocket (player , 1 );
307
+ state .previousFails += 1 ;
308
+ state .lastFailOrSuccess = time ;
309
+ giveRocket (player , Math .min (state .previousFails , 3 ));
291
310
292
311
ServerWorld world = this .gameWorld .getWorld ();
293
312
List <FireworkRocketEntity > rockets = world .getEntitiesByType (
@@ -321,7 +340,7 @@ private void broadcastWin() {
321
340
StringBuilder message_builder = new StringBuilder ();
322
341
message_builder .append ("The game has ended!\n " );
323
342
324
- for (int i = 0 ; i < 3 && i < this .finished .size (); i ++) {
343
+ for (int i = 0 ; i < 5 && i < this .finished .size (); i ++) {
325
344
LoopDeLoopWinner player = this .finished .get (i );
326
345
message_builder .append (String .format (
327
346
" %s place - %s in %.2fs\n " ,
@@ -345,10 +364,10 @@ private boolean onPlayerDamage(ServerPlayerEntity player, DamageSource source, f
345
364
return true ;
346
365
}
347
366
348
- private boolean onPlayerDeath (ServerPlayerEntity player , DamageSource source ) {
367
+ private ActionResult onPlayerDeath (ServerPlayerEntity player , DamageSource source ) {
349
368
long time = this .gameWorld .getWorld ().getTime ();
350
369
this .failHoop (player , this .player_states .get (player ), time );
351
- return true ;
370
+ return ActionResult . FAIL ;
352
371
}
353
372
354
373
private void spawnParticipant (ServerPlayerEntity player ) {
@@ -382,7 +401,7 @@ private void broadcastMessage(Text message) {
382
401
383
402
private void broadcastTitle (Text message ) {
384
403
for (ServerPlayerEntity player : this .gameWorld .getPlayers ()) {
385
- TitleS2CPacket packet = new TitleS2CPacket (TitleS2CPacket .Action .TITLE , message , 1 , 5 , 3 );
404
+ TitleS2CPacket packet = new TitleS2CPacket (TitleS2CPacket .Action .TITLE , message , 1 , 5 , 3 );
386
405
player .networkHandler .sendPacket (packet );
387
406
}
388
407
}
0 commit comments