Skip to content

Commit 816be72

Browse files
committed
sound plays onFlipReceive and Bestflip Key doesn't queue inputs when held anymore
1 parent 9e97a95 commit 816be72

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

src/client/java/com/coflnet/CoflModClient.java

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.gson.GsonBuilder;
2121
import com.google.gson.JsonObject;
2222
import com.mojang.brigadier.arguments.StringArgumentType;
23+
import com.sun.jna.internal.ReflectionUtils;
2324
import net.fabricmc.api.ClientModInitializer;
2425
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
2526
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
@@ -28,16 +29,24 @@
2829
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
2930
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
3031
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
32+
import net.fabricmc.fabric.api.client.screen.v1.ScreenKeyboardEvents;
3133
import net.fabricmc.loader.api.FabricLoader;
3234
import net.minecraft.client.MinecraftClient;
3335
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
3436
import net.minecraft.client.option.KeyBinding;
3537
import 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;
3642
import net.minecraft.text.Text;
43+
import net.minecraft.util.math.BlockPos;
44+
import org.apache.logging.log4j.core.util.ReflectionUtil;
3745
import org.greenrobot.eventbus.EventBus;
3846
import org.greenrobot.eventbus.Subscribe;
3947
import org.lwjgl.glfw.GLFW;
4048

49+
import java.lang.reflect.Field;
4150
import java.nio.file.Path;
4251
import java.time.LocalDateTime;
4352
import java.util.Arrays;
@@ -49,7 +58,8 @@
4958
import static com.coflnet.Utils.ChatComponent;
5059

5160
public 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

Comments
 (0)