2020import com .google .gson .GsonBuilder ;
2121import com .google .gson .JsonObject ;
2222import com .mojang .brigadier .arguments .StringArgumentType ;
23+ import com .sun .jna .internal .ReflectionUtils ;
2324import net .fabricmc .api .ClientModInitializer ;
2425import net .fabricmc .fabric .api .client .command .v2 .ClientCommandManager ;
2526import net .fabricmc .fabric .api .client .command .v2 .ClientCommandRegistrationCallback ;
2829import net .fabricmc .fabric .api .client .keybinding .v1 .KeyBindingHelper ;
2930import net .fabricmc .fabric .api .client .networking .v1 .ClientPlayConnectionEvents ;
3031import net .fabricmc .fabric .api .client .screen .v1 .ScreenEvents ;
32+ import net .fabricmc .fabric .api .client .screen .v1 .ScreenKeyboardEvents ;
3133import net .fabricmc .loader .api .FabricLoader ;
3234import net .minecraft .client .MinecraftClient ;
3335import net .minecraft .client .gui .screen .ingame .GenericContainerScreen ;
3436import net .minecraft .client .option .KeyBinding ;
3537import net .minecraft .client .util .InputUtil ;
38+ import net .minecraft .entity .player .PlayerEntity ;
39+ import net .minecraft .sound .SoundCategory ;
40+ import net .minecraft .sound .SoundEvent ;
41+ import net .minecraft .sound .SoundEvents ;
3642import net .minecraft .text .Text ;
43+ import net .minecraft .util .math .BlockPos ;
44+ import org .apache .logging .log4j .core .util .ReflectionUtil ;
3745import org .greenrobot .eventbus .EventBus ;
3846import org .greenrobot .eventbus .Subscribe ;
3947import org .lwjgl .glfw .GLFW ;
4048
49+ import java .lang .reflect .Field ;
4150import java .nio .file .Path ;
4251import java .time .LocalDateTime ;
4352import java .util .Arrays ;
4958import static com .coflnet .Utils .ChatComponent ;
5059
5160public class CoflModClient implements ClientModInitializer {
52- private KeyBinding bestflipsKeyBinding ;
61+ private KeyBinding bestflipsKeyBinding ;
62+ private boolean keyPressed = false ;
5363
5464 private String username = "" ;
5565 private static FlipData flipData = null ;
@@ -74,11 +84,13 @@ public void onInitializeClient() {
7484 ));
7585
7686 ClientTickEvents .END_CLIENT_TICK .register (client -> {
77- if (bestflipsKeyBinding .wasPressed ()) {
87+ if (! keyPressed && bestflipsKeyBinding .isPressed ()) {
7888 EventRegistry .onOpenBestFlip (username , true );
79- }
89+ } else keyPressed = false ;
8090 });
8191
92+
93+
8294 ClientPlayConnectionEvents .JOIN .register ((handler , sender , server ) -> {
8395 if (MinecraftClient .getInstance () != null && MinecraftClient .getInstance ().getCurrentServerEntry () != null && MinecraftClient .getInstance ().getCurrentServerEntry ().address .contains ("hypixel.net" )){
8496 System .out .println ("Connected to Hypixel" );
@@ -172,6 +184,9 @@ public void onFlipReceive(OnFlipReceive event){
172184 ),
173185 f .getRender ()
174186 ));
187+
188+ PlayerEntity player = MinecraftClient .getInstance ().player ;
189+ player .getWorld ().playSound (player , player .getBlockPos (), findByName (f .getSound ().getSoundName ()), SoundCategory .MASTER , 1f , f .getSound ().getSoundPitch () == null ? 1f : (float ) f .getSound ().getSoundPitch ());
175190 }
176191
177192 @ Subscribe
@@ -182,6 +197,22 @@ public void onReceiveCommand(ReceiveCommand event){
182197 }
183198 }
184199
200+ public static SoundEvent findByName (String name ) {
201+ SoundEvent result = SoundEvents .BLOCK_NOTE_BLOCK_BELL .value ();
202+
203+ for (Field f : SoundEvents .class .getDeclaredFields ()) {
204+ if (f .getName ().equalsIgnoreCase (name )) {
205+ try {
206+ result = (SoundEvent ) f .get (SoundEvents .class );
207+ } catch (IllegalAccessException e ) {
208+ System .out .println ("SoundEvent inaccessible. This shouldn't happen" );
209+ }
210+ break ;
211+ }
212+ }
213+ return result ;
214+ }
215+
185216 public static Flip jsonObjToFlip (JsonObject jsonObj ){
186217 JsonObject [] chatMessagesObj = gson .fromJson (jsonObj .get ("messages" ), JsonObject [].class );
187218 ChatMessage [] chatMessages = Arrays .stream (chatMessagesObj ).map (jsonObject -> new ChatMessage (
0 commit comments