11package com .coflnet ;
22
33import CoflCore .CoflCore ;
4- import CoflCore .classes .AuctionItem ;
5- import CoflCore .classes .ChatMessage ;
4+ import CoflCore .classes .*;
65import CoflCore .CoflSkyCommand ;
7- import CoflCore .classes .Flip ;
8- import CoflCore .classes .Sound ;
96import CoflCore .commands .CommandType ;
10- import CoflCore .commands .JsonStringCommand ;
117import CoflCore .commands .models .ChatMessageData ;
128import CoflCore .commands .models .FlipData ;
139import CoflCore .commands .models .SoundData ;
2016import com .google .gson .GsonBuilder ;
2117import com .google .gson .JsonObject ;
2218import com .mojang .brigadier .arguments .StringArgumentType ;
23- import com .sun .jna . internal . ReflectionUtils ;
19+ import com .sun .java . accessibility . util . AWTEventMonitor ;
2420import net .fabricmc .api .ClientModInitializer ;
2521import net .fabricmc .fabric .api .client .command .v2 .ClientCommandManager ;
2622import net .fabricmc .fabric .api .client .command .v2 .ClientCommandRegistrationCallback ;
2723import net .fabricmc .fabric .api .client .event .lifecycle .v1 .ClientLifecycleEvents ;
2824import net .fabricmc .fabric .api .client .event .lifecycle .v1 .ClientTickEvents ;
2925import net .fabricmc .fabric .api .client .keybinding .v1 .KeyBindingHelper ;
3026import net .fabricmc .fabric .api .client .networking .v1 .ClientPlayConnectionEvents ;
27+ import net .fabricmc .fabric .api .client .rendering .v1 .HudRenderCallback ;
3128import net .fabricmc .fabric .api .client .screen .v1 .ScreenEvents ;
3229import net .fabricmc .fabric .api .client .screen .v1 .ScreenKeyboardEvents ;
30+ import net .fabricmc .fabric .impl .client .event .lifecycle .ClientLifecycleEventsImpl ;
3331import net .fabricmc .loader .api .FabricLoader ;
3432import net .minecraft .client .MinecraftClient ;
33+ import net .minecraft .client .font .TextRenderer ;
3534import net .minecraft .client .gui .screen .ingame .GenericContainerScreen ;
3635import net .minecraft .client .option .KeyBinding ;
3736import net .minecraft .client .util .InputUtil ;
3837import net .minecraft .entity .player .PlayerEntity ;
38+ import net .minecraft .registry .entry .RegistryEntry ;
3939import net .minecraft .sound .SoundCategory ;
4040import net .minecraft .sound .SoundEvent ;
4141import net .minecraft .sound .SoundEvents ;
4242import net .minecraft .text .Text ;
43- import net .minecraft .util .math .BlockPos ;
44- import org .apache .logging .log4j .core .util .ReflectionUtil ;
43+ import net .minecraft .world .timer .TimerCallbackSerializer ;
4544import org .greenrobot .eventbus .EventBus ;
4645import org .greenrobot .eventbus .Subscribe ;
4746import org .lwjgl .glfw .GLFW ;
4847
48+ import javax .swing .*;
49+ import java .awt .*;
50+ import java .awt .event .KeyEvent ;
51+ import java .awt .event .KeyListener ;
52+ import java .lang .ref .Reference ;
4953import java .lang .reflect .Field ;
5054import java .nio .file .Path ;
51- import java .time .LocalDateTime ;
5255import java .util .Arrays ;
53- import java .util .concurrent .ExecutorService ;
54- import java .util .concurrent .Executors ;
55- import java .util .concurrent .LinkedBlockingQueue ;
56- import java .util .regex .Pattern ;
56+ import java .util .Timer ;
57+ import java .util .TimerTask ;
5758
5859import static com .coflnet .Utils .ChatComponent ;
5960
6061public class CoflModClient implements ClientModInitializer {
6162 private KeyBinding bestflipsKeyBinding ;
6263 private boolean keyPressed = false ;
64+ private int counter = 0 ;
6365
6466 private String username = "" ;
6567 private static FlipData flipData = null ;
6668 private static Gson gson = new GsonBuilder ().excludeFieldsWithoutExposeAnnotation ().create ();
69+ private static Countdown countdownData = null ;
70+ private static float countdown = 0.0f ;
71+ private static boolean showCountdown = false ;
72+ private static Timer timer = new Timer ();
73+ private static TimerTask task = new TimerTask () {
74+ @ Override
75+ public void run () {
76+ countdown -= 0.1f ;
77+ if (countdown < 0.0 ) {
78+ showCountdown = false ;
79+ timer .cancel ();
80+ }
81+ }
82+ };
6783 @ Override
6884 public void onInitializeClient () {
6985 username = MinecraftClient .getInstance ().getSession ().getUsername ();
@@ -84,13 +100,19 @@ public void onInitializeClient() {
84100 ));
85101
86102 ClientTickEvents .END_CLIENT_TICK .register (client -> {
87- if (!keyPressed && bestflipsKeyBinding .isPressed ()) {
88- EventRegistry .onOpenBestFlip (username , true );
89- } else keyPressed = false ;
103+ if (bestflipsKeyBinding .isPressed ()) {
104+ if (counter == 0 ){
105+ // PlayerEntity player = MinecraftClient.getInstance().player;
106+ // player.getWorld().playSound(player, player.getBlockPos(), findByName("BLOCK_ANVIL_PLACE"), SoundCategory.MASTER, 1f, 1f);
107+ EventRegistry .onOpenBestFlip (username , true );
108+ }
109+ if (counter < 2 ) counter ++;
110+ } else {
111+ counter = 0 ;
112+ }
90113 });
91114
92115
93-
94116 ClientPlayConnectionEvents .JOIN .register ((handler , sender , server ) -> {
95117 if (MinecraftClient .getInstance () != null && MinecraftClient .getInstance ().getCurrentServerEntry () != null && MinecraftClient .getInstance ().getCurrentServerEntry ().address .contains ("hypixel.net" )){
96118 System .out .println ("Connected to Hypixel" );
@@ -129,6 +151,22 @@ public void onInitializeClient() {
129151 }
130152 }
131153 });
154+
155+ HudRenderCallback .EVENT .register ((drawContext , tickCounter ) -> {
156+ if (showCountdown && countdownData != null ){
157+ //RenderUtils.drawString(drawContext, "New flips in: "+String.format("%.1f", countdown), 10, 10, 0xFFFFFFFF);
158+ MinecraftClient .getInstance ().textRenderer .draw (
159+ countdownData .getPrefix ()+String .format ("New flips in: %.1f" , countdown ),
160+ MinecraftClient .getInstance ().getWindow ().getWidth ()/countdownData .getWidthPercentage (),
161+ MinecraftClient .getInstance ().getWindow ().getHeight ()/countdownData .getHeightPercentage (),
162+ 0xFFFFFFFF , false ,
163+ drawContext .getMatrices ().peek ().getPositionMatrix (),
164+ drawContext .getVertexConsumers (),
165+ TextRenderer .TextLayerType .NORMAL ,
166+ 0x00FFFFFF , 100
167+ );
168+ }
169+ });
132170 }
133171
134172 public static FlipData popFlipData (){
@@ -156,7 +194,32 @@ public void onModChatMessage(OnModChatMessage event){
156194
157195 @ Subscribe
158196 public void onCountdownReceive (OnCountdownReceive event ){
159- //MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Text.of("COUNTDOWN RECEIVED: "+event.CountdownData.getDuration()));
197+ MinecraftClient .getInstance ().inGameHud .getChatHud ().addMessage (Text .of ("COUNTDOWN RECEIVED: " +event .CountdownData .getDuration ()));
198+ countdown = event .CountdownData .getDuration ();
199+ countdownData = event .CountdownData ;
200+ showCountdown = true ;
201+
202+ System .out .println ("COUNTDOWNDATA:" );
203+ System .out .println ("w%: " +countdownData .getWidthPercentage ());
204+ System .out .println ("ww: " +MinecraftClient .getInstance ().getWindow ().getWidth ());
205+ System .out .println ("w% of ww: " +MinecraftClient .getInstance ().getWindow ().getWidth ()/countdownData .getWidthPercentage ());
206+ System .out .println ("h%: " +countdownData .getHeightPercentage ());
207+ System .out .println ("wh: " +MinecraftClient .getInstance ().getWindow ().getHeight ());
208+ System .out .println ("h% of wh: " +MinecraftClient .getInstance ().getWindow ().getHeight ()/countdownData .getHeightPercentage ());
209+ System .out .println ("prefix: " +countdownData .getPrefix ());
210+ System .out .println ("scale: " +countdownData .getScale ());
211+
212+ timer = new Timer ();
213+ timer .scheduleAtFixedRate (new TimerTask () {
214+ @ Override
215+ public void run () {
216+ countdown -= 0.1f ;
217+ if (countdown < 0.0 ) {
218+ showCountdown = false ;
219+ timer .cancel ();
220+ }
221+ }
222+ }, 1 , 100 );
160223 }
161224
162225 @ Subscribe
@@ -168,25 +231,30 @@ public void onOpenAuctionGUI(OnOpenAuctionGUI event){
168231 @ Subscribe
169232 public void onFlipReceive (OnFlipReceive event ){
170233 Flip f = event .FlipData ;
171- EventBus .getDefault ().post (new OnChatMessageReceive (f .getMessages ()));
172- CoflCore .flipHandler .fds .Insert (new FlipData (
234+ FlipData fd = new FlipData (
173235 Arrays .stream (f .getMessages ())
174- .map (cm -> new ChatMessageData (
175- cm .getText (),
176- cm .getOnClick (),
177- cm .getHover ())
178- ).toArray (ChatMessageData []::new ),
236+ .map (cm -> new ChatMessageData (
237+ cm .getText (),
238+ cm .getOnClick (),
239+ cm .getHover ())
240+ ).toArray (ChatMessageData []::new ),
179241 f .getId (),
180242 f .getWorth (),
181243 new SoundData (
182244 f .getSound ().getSoundName (),
183245 f .getSound ().getSoundPitch () == null ? 0 : f .getSound ().getSoundPitch ()
184246 ),
185247 f .getRender ()
186- )) ;
248+ );
187249
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 ());
250+ if (bestflipsKeyBinding .isPressed ()) {
251+ EventBus .getDefault ().post (new OnOpenAuctionGUI ("/viewauction " +fd .Id , fd ));
252+ return ;
253+ }
254+
255+ EventBus .getDefault ().post (new OnChatMessageReceive (f .getMessages ()));
256+ EventBus .getDefault ().post (new OnPlaySoundReceive (f .getSound ()));
257+ CoflCore .flipHandler .fds .Insert (fd );
190258 }
191259
192260 @ Subscribe
@@ -197,13 +265,45 @@ public void onReceiveCommand(ReceiveCommand event){
197265 }
198266 }
199267
268+ @ Subscribe
269+ public void onPlaySoundReceive (OnPlaySoundReceive event ){
270+ if (event .Sound == null || event .Sound .getSoundName () == null ) return ;
271+
272+ String soundName = "" ;
273+ switch (event .Sound .getSoundName ()){
274+ case "note.bass" -> soundName = "BLOCK_NOTE_BLOCK_BASS" ;
275+ case "note.pling" -> soundName = "BLOCK_NOTE_BLOCK_PLING" ;
276+ case "note.hat" -> soundName = "BLOCK_NOTE_BLOCK_HAT" ;
277+ case "random.orb" -> soundName = "ENTITY_EXPERIENCE_ORB_PICKUP" ;
278+ default -> soundName = "" ;
279+ }
280+
281+ PlayerEntity player = MinecraftClient .getInstance ().player ;
282+ player .getWorld ().playSound (
283+ player , player .getBlockPos (),
284+ findByName (soundName ),
285+ SoundCategory .MASTER , 1f ,
286+ event .Sound .getSoundPitch () == null ? 1f : (float ) event .Sound .getSoundPitch ()
287+ );
288+ }
289+
290+ @ Subscribe
291+ public void onExecuteCommand (OnExecuteCommand event ){
292+ System .out .println ("ON EXEC COMMAND:" +event .Error );
293+ }
294+
200295 public static SoundEvent findByName (String name ) {
201296 SoundEvent result = SoundEvents .BLOCK_NOTE_BLOCK_BELL .value ();
202297
203298 for (Field f : SoundEvents .class .getDeclaredFields ()) {
204299 if (f .getName ().equalsIgnoreCase (name )) {
205300 try {
206- result = (SoundEvent ) f .get (SoundEvents .class );
301+ SoundEvents .BLOCK_NOTE_BLOCK_PLING .value ();
302+ try {
303+ result = (SoundEvent ) f .get (SoundEvent .class );
304+ } catch (ClassCastException e ){
305+ result = (SoundEvent ) ((RegistryEntry .Reference ) f .get (RegistryEntry .Reference .class )).value ();
306+ }
207307 } catch (IllegalAccessException e ) {
208308 System .out .println ("SoundEvent inaccessible. This shouldn't happen" );
209309 }
0 commit comments