99import net .minecraft .world .item .ItemStack ;
1010import net .minecraft .world .level .Level ;
1111import net .minecraft .core .component .DataComponentType ;
12+ import net .minecraft .world .item .TooltipFlag ;
1213import net .roboxgamer .modernutils .data .KillData ;
1314import net .roboxgamer .modernutils .item .ModCustomDataComponents ;
1415
1516import java .util .ArrayList ;
17+ import java .util .List ;
1618
1719public class KillRecorderItem extends Item {
1820 public KillRecorderItem (Properties properties ) {
@@ -26,16 +28,67 @@ public InteractionResultHolder<ItemStack> use(Level level, Player player, Intera
2628
2729 if (player .isShiftKeyDown ()) {
2830 DataComponentType <KillData > killDataType = ModCustomDataComponents .KILL_DATA .get ();
29- KillData currentData = stack .getOrDefault (killDataType , new KillData ( new ArrayList <>(), false , 0 ));
31+ KillData currentData = stack .getOrDefault (killDataType , KillData . createEmpty ( ));
3032
31- // Toggle recording state
32- KillData newData = new KillData (currentData .kills (), !currentData .isRecording (), currentData .totalXp ());
33- stack .set (killDataType , newData );
34-
35- player .displayClientMessage (Component .literal ("Kill Recording: " +
36- (newData .isRecording () ? "Enabled" : "Disabled" )), true );
33+ if (!currentData .isRecording ()) {
34+ // Start recording - clear previous data and start fresh
35+ long currentTime = System .currentTimeMillis ();
36+ stack .update (
37+ killDataType ,
38+ currentData ,
39+ data -> new KillData (new ArrayList <>(), true , 0 , currentTime , 0L )
40+ );
41+ player .displayClientMessage (Component .literal ("Kill Recording: Enabled (Data Cleared)" ), true );
42+ } else {
43+ // Stop recording
44+ long currentTime = System .currentTimeMillis ();
45+ stack .update (
46+ killDataType ,
47+ currentData ,
48+ data -> new KillData (data .kills (), false , data .totalXp (), data .recordingStart (), currentTime )
49+ );
50+ player .displayClientMessage (Component .literal ("Kill Recording: Disabled" ), true );
51+ }
3752 }
3853 }
3954 return super .use (level , player , hand );
4055 }
56+ @ Override
57+ public void appendHoverText (ItemStack stack , TooltipContext context , List <Component > tooltipComponents ,
58+ TooltipFlag tooltipFlag ) {
59+ super .appendHoverText (stack , context , tooltipComponents , tooltipFlag );
60+
61+ DataComponentType <KillData > killDataType = ModCustomDataComponents .KILL_DATA .get ();
62+ KillData data = stack .getOrDefault (killDataType , KillData .createEmpty ());
63+
64+ // Recording Status
65+ tooltipComponents .add (Component .literal ("§6Status: " + (data .isRecording () ? "§aRecording" : "§cNot Recording" )));
66+
67+ // Kills Count
68+ tooltipComponents .add (Component .literal ("§6Total Kills: §f" + data .kills ().size ()));
69+
70+ // Total XP
71+ tooltipComponents .add (Component .literal ("§6Total XP: §f" + data .totalXp ()));
72+
73+ // Recording Duration
74+ if (data .recordingStart () > 0 ) {
75+ long duration ;
76+ if (data .isRecording ()) {
77+ duration = System .currentTimeMillis () - data .recordingStart ();
78+ } else if (data .recordingEnd () > 0 ) {
79+ duration = data .recordingEnd () - data .recordingStart ();
80+ } else {
81+ duration = 0 ;
82+ }
83+
84+ long seconds = duration / 1000 ;
85+ long minutes = seconds / 60 ;
86+ seconds = seconds % 60 ;
87+ tooltipComponents .add (Component .literal (String .format ("§6Duration: §f%02d:%02d" , minutes , seconds )));
88+ }
89+
90+ // Instructions
91+ tooltipComponents .add (Component .literal ("" ));
92+ tooltipComponents .add (Component .literal ("§7Shift + Right Click to toggle recording" ));
93+ }
4194}
0 commit comments