66import net .fabricmc .fabric .api .client .command .v2 .ClientCommandRegistrationCallback ;
77import net .fabricmc .fabric .api .client .event .lifecycle .v1 .ClientTickEvents ;
88import net .fabricmc .fabric .api .client .networking .v1 .ClientPlayConnectionEvents ;
9+ import net .fabricmc .fabric .api .client .rendering .v1 .hud .HudElementRegistry ;
10+ import net .fabricmc .fabric .api .client .rendering .v1 .hud .VanillaHudElements ;
911import net .fabricmc .fabric .api .client .rendering .v1 .world .WorldRenderEvents ;
1012import net .fabricmc .fabric .api .event .player .AttackBlockCallback ;
13+ import net .fabricmc .fabric .api .event .player .PlayerBlockBreakEvents ;
1114import net .minecraft .ChatFormatting ;
1215import net .minecraft .client .Minecraft ;
1316import net .minecraft .core .BlockPos ;
1417import net .minecraft .network .chat .*;
18+ import net .minecraft .network .chat .Component ;
1519import net .minecraft .resources .Identifier ;
1620import net .minecraft .sounds .SoundEvent ;
1721import net .minecraft .world .InteractionResult ;
1822import net .minecraft .world .phys .shapes .VoxelShape ;
23+ import pom .v1 .PomConfig .PomConfig ;
1924import pom .v1 .commands .pomCommands ;
25+ import pom .v1 .events .blockHitEvent ;
26+ import pom .v1 .gui .PomScreen ;
2027import pom .v1 .pomGetter .PomBlockData ;
2128import pom .v1 .pomGetter .PomStats ;
2229import pom .v1 .pomGetter .SpeedCalc ;
@@ -39,6 +46,8 @@ public class PingOffsetMinerClient implements ClientModInitializer {
3946 public static PomTPS POM_TPS = new PomTPS ();
4047 public static PomBlockData POM_BLOCK_DATA = new PomBlockData ();
4148 public static PomBlockData .PomBlock POM_BLOCK = new PomBlockData .PomBlock ();
49+ public static PomCalc POM_CALC = new PomCalc ();
50+ public static PomEfficiency POM_EFF = new PomEfficiency ();
4251
4352 // Initialize variables
4453 BlockPos currentBlock ;
@@ -49,8 +58,7 @@ public class PingOffsetMinerClient implements ClientModInitializer {
4958
5059 @ Override
5160 public void onInitializeClient () {
52- pom .v1 .PomConfig .PomConfig .init ();
53-
61+ PomConfig .init ();
5462
5563 EVENT_BUS .registerLambdaFactory ("pom.v1" , (lookupInMethod , klass ) -> {
5664 try {
@@ -66,34 +74,41 @@ public void onInitializeClient() {
6674 EVENT_BUS .subscribe (POM_PING );
6775 EVENT_BUS .subscribe (POM_TPS );
6876 EVENT_BUS .subscribe (POM_BLOCK_DATA );
77+ EVENT_BUS .subscribe (PomScreen .class );
78+ EVENT_BUS .subscribe (POM_CALC );
79+ EVENT_BUS .subscribe (POM_EFF );
6980 PomRendering POM_RENDER = new PomRendering ();
7081
7182
83+ HudElementRegistry .attachElementAfter (
84+ VanillaHudElements .CROSSHAIR ,
85+ Identifier .fromNamespaceAndPath (MOD_ID , "text_test" ),
86+ PomScreen ::render
87+ );
7288
73- WorldRenderEvents .BEFORE_TRANSLUCENT .register (event -> {
89+ WorldRenderEvents .END_MAIN .register (event -> {
7490 Minecraft client = Minecraft .getInstance ();
7591 long time = System .currentTimeMillis ();
7692
7793 POM_BLOCK .setBlock (client );
7894
7995 if (
80- !Config ().active ||
96+ !Config ().active . get () ||
8197 !Util .getIsland () ||
8298 POM_BLOCK .isEmpty () ||
8399 client .player == null ||
84100 client .level == null ||
85101 !TOOL_STATS .isActive ()
86102 )
87103 {
88- log ("Config is: " + Config ().active , time );
104+ log ("Config is: " + Config ().active . get () , time );
89105 log ("Block: " + POM_BLOCK .getName (), time );
90106 log ("Tool is: " + TOOL_STATS .isActive (), time );
91107 log ("Island is: " + Util .getIsland (), time );
92- log ("Debug is: " + Config ().debug , time );
108+ log ("Debug is: " + Config ().debug . get () , time );
93109 timeoutExceeded = false ;
94- ticksNeeded = -1 ;
95- startServerTick = -1 ;
96110 currentBlock = null ;
111+ POM_CALC .reset ();
97112 return ;
98113 }
99114
@@ -103,63 +118,44 @@ public void onInitializeClient() {
103118 if (!Objects .equals (currentBlock , blockPos ) || !client .options .keyAttack .isDown ()) {
104119 sound = false ;
105120 currentBlock = blockPos ;
106- startServerTick = client . player . tickCount ;
121+ POM_CALC . reset () ;
107122 log ("Reset block breaking" , time );
108123 }
109124
110- double debugSpeed = Config ().debug ? Config ().speed : TOOL_STATS .getSpeed ();
111- double extra = Config ().extra ? Config ().extraVal : 0 ;
112-
113- if (POM_BLOCK .getName ().contains ("gem" )) {
114- debugSpeed = debugSpeed + extra ;
115- }
116-
117- ticksNeeded = SpeedCalc .getTicksToBreak ((int ) POM_BLOCK .getHardness (), debugSpeed );
118-
119125
120- if (sound && timeoutExceeded && Config ().sound && client .options .keyAttack .isDown ()) {
126+ if (sound && timeoutExceeded && Config ().sound . get () && client .options .keyAttack .isDown ()) {
121127 sound = false ;
122- SoundEvent useSound = SoundEvent .createVariableRangeEvent (Identifier .parse (String .valueOf (Config ().soundpath )));
128+ SoundEvent useSound = SoundEvent .createVariableRangeEvent (Identifier .parse (String .valueOf (Config ().soundpath . get () )));
123129 client .player .playSound (useSound );
124130 }
125- if (!sound && !timeoutExceeded ) sound = true ;
131+ if (!sound && !POM_CALC . timeoutExceeded () ) sound = true ;
126132
127133 if (shouldRender ()) {
134+
128135 POM_RENDER .extractAndDraw (
129136 event ,
130137 client ,
131138 blockPos ,
132139 blockShape ,
133- timeoutExceeded
140+ POM_CALC . timeoutExceeded ()
134141 );
135142 }
136143
137- Util .log ("Mining speed: " + debugSpeed , time );
138- Util .log ("Ticks needed: " + ticksNeeded , time );
144+ Util .log ("Mining speed: " + POM_CALC . getSpeed () , time );
145+ Util .log ("Ticks needed: " + POM_CALC . getTicksNeeded () , time );
139146 Util .log ("Should render: " + shouldRender (), time );
140147 });
141148
142149 ClientTickEvents .END_CLIENT_TICK .register (event -> {
143- if (event .player == null || POM_BLOCK .isEmpty ()) return ;
144- int ticksElapsed = event .player .tickCount - startServerTick ;
145-
146- double debugTps = Config ().debug ? 20.0 : getTPS ();
147- double pingSec = Config ().debug ? Config ().ping / 1000.0 : getPing () / 1000.0 ;
148-
149- double pingMath = debugTps * pingSec ;
150150
151- double pingOffset = ticksNeeded - pingMath > pingMath
152- ? ticksNeeded - pingMath
153- : ticksNeeded ;
154- timeoutExceeded = ticksNeeded > 0 && ticksElapsed >= pingOffset && event .options .keyAttack .isDown ();
155151 });
156152
157153 WorldRenderEvents .BEFORE_BLOCK_OUTLINE .register ((context , outline ) -> {
158- if (!POM_BLOCK .isEmpty () || ! getIsland ()) {
154+ if (!POM_BLOCK .isEmpty () && getIsland ()) {
159155
160- if (Config ().debug && Config ().line .active ) return false ;
156+ if (Config ().debug . get () && Config ().line .active . get () ) return false ;
161157
162- if (Config ().active && Config ().line .active ) return !shouldRender ();
158+ if (Config ().active . get () && Config ().line .active . get () ) return !shouldRender ();
163159
164160 }
165161 return true ;
@@ -174,7 +170,11 @@ public void onInitializeClient() {
174170
175171 AttackBlockCallback .EVENT .register ((player , level , hand , blockpos , hr ) -> {
176172
177- if (!Util .foundSpeed () && !Config ().debug && Config ().active && Util .getIsland () && Config ().shouldWarn ) {
173+
174+ blockHitEvent event = new blockHitEvent (blockpos , POM_BLOCK .getName ());
175+ EVENT_BUS .post (event );
176+
177+ if (!Util .foundSpeed () && !Config ().debug .get () && Config ().active .get () && Util .getIsland () && Config ().shouldWarn .get ()) {
178178 Util .sendMsg (Component .literal ("Mining Speed not found! Please enable in tab widget" ).withStyle (ChatFormatting .RED ));
179179 Util .sendMsg (Component .literal ("To enable: /tab -> Stats Widget -> Shown Stats -> Mining Speed" ).withStyle (ChatFormatting .RED ));
180180 Util .sendMsg (Component .literal ("Make sure that the mining speed stat is visible in your tab menu" ).withStyle (ChatFormatting .RED ));
@@ -190,9 +190,11 @@ public void onInitializeClient() {
190190 }
191191
192192 public static double getTPS () {
193+ if (Config ().debug .get ()) {return Config ().tps .get ();}
193194 return POM_TPS .getAverageLatency ();
194195 }
195- public static long getPing () {
196+ public static double getPing () {
197+ if (Config ().debug .get ()) {return Config ().ping .get ();}
196198 return POM_PING .getAverageLatency ();
197199 }
198200}
0 commit comments