5
5
import com .mojang .brigadier .arguments .IntegerArgumentType ;
6
6
import dev .doublekekse .area_lib .Area ;
7
7
import dev .doublekekse .area_lib .command .argument .AreaArgument ;
8
+ import net .minecraft .ChatFormatting ;
8
9
import net .minecraft .commands .CommandBuildContext ;
9
10
import net .minecraft .commands .CommandSourceStack ;
10
11
import net .minecraft .commands .Commands ;
11
12
import net .minecraft .commands .arguments .ResourceLocationArgument ;
12
13
import net .minecraft .commands .synchronization .SuggestionProviders ;
13
14
import net .minecraft .core .Holder ;
15
+ import net .minecraft .network .chat .Component ;
16
+ import net .minecraft .network .chat .MutableComponent ;
14
17
import net .minecraft .resources .ResourceLocation ;
15
18
import net .minecraft .server .MinecraftServer ;
16
19
import net .minecraft .sounds .Music ;
17
20
import net .minecraft .sounds .SoundEvent ;
18
21
22
+ import java .util .function .Consumer ;
23
+
19
24
import static net .minecraft .commands .Commands .argument ;
20
25
import static net .minecraft .commands .Commands .literal ;
21
26
22
27
public class MeretCommands {
23
- private static int setMusic (MinecraftServer server , Area area , ResourceLocation sound , int minDelay , int maxDelay , boolean replaceCurrentMusic ) {
28
+ private static MutableComponent feedback (ChatFormatting bodyFormatting , Component ... siblings ) {
29
+ MutableComponent prefix = Component .literal ("" ).append (Component .literal ("[Meret] " ).withStyle (ChatFormatting .DARK_RED ));
30
+ for (Component sibling : siblings ) {
31
+ prefix = prefix .append (sibling .getStyle ().getColor () == null ? sibling .copy ().withStyle (bodyFormatting ) : sibling );
32
+ }
33
+ return prefix ;
34
+ }
35
+
36
+ private static int setMusic (Consumer <Component > feedback , MinecraftServer server , Area area , ResourceLocation sound , int minDelay , int maxDelay , boolean replaceCurrentMusic ) {
24
37
SoundEvent soundEvent = SoundEvent .createVariableRangeEvent ((sound ));
25
38
Music music = new Music (Holder .direct (soundEvent ), minDelay , maxDelay , replaceCurrentMusic );
26
39
area .put (server , Meret .AREA_MUSIC_DATA_COMPONENT , new AreaMusicComponent (music ));
40
+ feedback .accept (feedback (ChatFormatting .GREEN ,
41
+ Component .literal ("music override for " ),
42
+ Component .literal (area .getId ().toString ()).withStyle (ChatFormatting .WHITE ),
43
+ Component .literal (" set to " ),
44
+ Component .literal (sound .toString ()).withStyle (ChatFormatting .WHITE )
45
+ ));
27
46
return 1 ;
28
47
}
29
48
30
- private static int clearMusic (MinecraftServer server , Area area ) {
31
- area .remove (server , Meret .AREA_MUSIC_DATA_COMPONENT );
49
+ private static int clearMusic (Consumer <Component > feedback , MinecraftServer server , Area area ) {
50
+ if (!area .has (Meret .AREA_MUSIC_DATA_COMPONENT )) {
51
+ feedback .accept (feedback (ChatFormatting .YELLOW ,
52
+ Component .literal ("no music was set in " ),
53
+ Component .literal (area .getId ().toString ()).withStyle (ChatFormatting .WHITE )
54
+ ));
55
+ }
56
+ feedback .accept (feedback (ChatFormatting .GREEN ,
57
+ Component .literal ("music override cleared for " ),
58
+ Component .literal (area .getId ().toString ()).withStyle (ChatFormatting .WHITE )
59
+ ));
32
60
return 1 ;
33
61
}
34
62
@@ -43,6 +71,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, Co
43
71
.then (argument ("maxDelay" , IntegerArgumentType .integer (0 ))
44
72
.then (argument ("replaceCurrent" , BoolArgumentType .bool ())
45
73
.executes (c -> setMusic (
74
+ c .getSource ()::sendSystemMessage ,
46
75
c .getSource ().getServer (),
47
76
AreaArgument .getArea (c , "area" ),
48
77
ResourceLocationArgument .getId (c , "sound" ),
@@ -59,6 +88,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, Co
59
88
.then (literal ("clear" )
60
89
.then (argument ("area" , AreaArgument .area ())
61
90
.executes (c -> clearMusic (
91
+ c .getSource ()::sendSystemMessage ,
62
92
c .getSource ().getServer (),
63
93
AreaArgument .getArea (c , "area" )
64
94
))
0 commit comments