11/*
22 * This class is distributed as part of the Psi Mod.
3- * Get the Source Code in github :
3+ * Get the Source Code in GitHub :
44 * https://github.com/Vazkii/Psi
55 *
66 * Psi is Open Source and distributed under the
4646
4747import java .util .regex .Pattern ;
4848
49- @ EventBusSubscriber (modid = LibMisc .MOD_ID )
49+ @ EventBusSubscriber (modid = LibMisc .MOD_ID , value = Dist . CLIENT )
5050public final class HUDHandler {
5151
5252 public static final LayeredDraw .Layer SOCKETABLE_EQUIPPED_NAME = (graphics , deltatracker ) -> {
@@ -88,21 +88,22 @@ public static void register(RegisterGuiLayersEvent event) {
8888 }
8989
9090 public static void tick () {
91-
92- if (remainingTime > 0 ) {
93- --remainingTime ;
91+ if (remainingTime < 0 ) {
92+ return ;
9493 }
94+
95+ --remainingTime ;
9596 }
9697
9798 private static boolean showsBar (PlayerData data , ItemStack stack ) {
9899 if (stack .isEmpty ()) {
99100 return false ;
100- } else {
101- IPsiBarDisplay display = stack .getCapability (PsiAPI .PSI_BAR_DISPLAY_CAPABILITY );
102- if (display != null )
103- return display .shouldShow (data );
104- return false ;
105101 }
102+
103+ IPsiBarDisplay display = stack .getCapability (PsiAPI .PSI_BAR_DISPLAY_CAPABILITY );
104+ if (display != null )
105+ return display .shouldShow (data );
106+ return false ;
106107 }
107108
108109 @ OnlyIn (Dist .CLIENT )
@@ -250,99 +251,104 @@ public static void drawPsiBar(GuiGraphics graphics, DeltaTracker deltatracker) {
250251 @ OnlyIn (Dist .CLIENT )
251252 private static void renderSocketableEquippedName (GuiGraphics graphics , DeltaTracker deltatracker ) {
252253 Minecraft mc = Minecraft .getInstance ();
254+ if (mc .player == null || mc .gui .toolHighlightTimer - 10 <= 0 ) {
255+ return ;
256+ }
257+
253258 ItemStack stack = mc .player .getItemInHand (InteractionHand .MAIN_HAND );
254259 if (!ISocketable .isSocketable (stack )) {
255260 return ;
256261 }
262+
257263 String name = ISocketable .getSocketedItemName (stack , "" ).getString ();
258264 if (stack .isEmpty () || name .trim ().isEmpty ()) {
259265 return ;
260266 }
261267
262- int ticks = mc .gui .toolHighlightTimer ;
263- ticks -= 10 ;
268+ ISocketable socketable = ISocketable .socketable (stack );
269+ ItemStack bullet = socketable .getSelectedBullet ();
270+
271+ int ticks = mc .gui .toolHighlightTimer - 10 ;
272+ int alpha = Math .min (255 , (int ) ((ticks - deltatracker .getGameTimeDeltaPartialTick (false )) * 256.0F / 10.0F ));
273+ int color = ICADColorizer .DEFAULT_SPELL_COLOR + (alpha << 24 );
274+ int x = graphics .guiWidth () / 2 - mc .font .width (name ) / 2 ;
275+ int y = graphics .guiHeight () - 71 ;
276+ int w = mc .font .width (name );
277+ if (mc .player .isCreative ()) {
278+ y += 14 ;
279+ }
264280
265- if (ticks > 0 ) {
266- ISocketable socketable = ISocketable .socketable (stack );
267- ItemStack bullet = socketable .getSelectedBullet ();
281+ graphics .drawString (mc .font , name , x , y , color , true );
282+ graphics .pose ().pushPose ();
283+ graphics .pose ().translate (x + w , y - 6 , 0 );
284+ graphics .pose ().scale (alpha / 255F , 1F , 1 );
285+ graphics .renderFakeItem (bullet , 0 , 0 );
286+ graphics .pose ().popPose ();
287+ }
268288
269- int alpha = Math .min (255 , (int ) ((ticks - deltatracker .getGameTimeDeltaPartialTick (false )) * 256.0F / 10.0F ));
270- int color = ICADColorizer .DEFAULT_SPELL_COLOR + (alpha << 24 );
289+ @ OnlyIn (Dist .CLIENT )
290+ private static void renderRemainingItems (GuiGraphics graphics , DeltaTracker deltatracker ) {
291+ if (remainingTime <= 0 || remainingDisplayStack .isEmpty ()) {
292+ return ;
293+ }
271294
272- int x = graphics . guiWidth () / 2 - mc . font . width ( name ) / 2 ;
273- int y = graphics . guiHeight () - 71 ;
274- if ( mc . player . isCreative ()) {
275- y += 14 ;
276- }
295+ int pos = maxRemainingTicks - remainingTime ;
296+ Minecraft mc = Minecraft . getInstance () ;
297+ int remainingLeaveTicks = 20 ;
298+ int x = graphics . guiWidth () / 2 + 10 + Math . max ( 0 , pos - remainingLeaveTicks ) ;
299+ int y = graphics . guiHeight () / 2 ;
277300
278- graphics .drawString (mc .font , name , x , y , color , true );
301+ int start = maxRemainingTicks - remainingLeaveTicks ;
302+ float alpha = remainingTime + deltatracker .getGameTimeDeltaPartialTick (false ) > start ? 1F : (remainingTime + deltatracker .getGameTimeDeltaPartialTick (false )) / start ;
279303
280- int w = mc .font .width (name );
281- graphics .pose ().pushPose ();
282- graphics .pose ().translate (x + w , y - 6 , 0 );
283- graphics .pose ().scale (alpha / 255F , 1F , 1 );
284- graphics .renderFakeItem (bullet , 0 , 0 );
285- graphics .pose ().popPose ();
286- }
287- }
304+ RenderSystem .setShaderColor (1F , 1F , 1F , alpha );
305+ int xp = x + (int ) (16F * (1F - alpha ));
306+ graphics .pose ().pushPose ();
307+ graphics .pose ().translate (xp , y , 0F );
308+ graphics .pose ().scale (alpha , 1F , 1F );
309+ graphics .renderFakeItem (remainingDisplayStack , 0 , 0 );
310+ graphics .pose ().scale (1F / alpha , 1F , 1F );
311+ graphics .pose ().translate (-xp , -y , 0F );
312+ RenderSystem .setShaderColor (1F , 1F , 1F , 1F );
288313
289- @ OnlyIn (Dist .CLIENT )
290- private static void renderRemainingItems (GuiGraphics graphics , DeltaTracker deltatracker ) {
291- if (remainingTime > 0 && !remainingDisplayStack .isEmpty ()) {
292- int pos = maxRemainingTicks - remainingTime ;
293- Minecraft mc = Minecraft .getInstance ();
294- int remainingLeaveTicks = 20 ;
295- int x = graphics .guiWidth () / 2 + 10 + Math .max (0 , pos - remainingLeaveTicks );
296- int y = graphics .guiHeight () / 2 ;
297-
298- int start = maxRemainingTicks - remainingLeaveTicks ;
299- float alpha = remainingTime + deltatracker .getGameTimeDeltaPartialTick (false ) > start ? 1F : (remainingTime + deltatracker .getGameTimeDeltaPartialTick (false )) / start ;
300-
301- RenderSystem .setShaderColor (1F , 1F , 1F , alpha );
302- int xp = x + (int ) (16F * (1F - alpha ));
303- graphics .pose ().pushPose ();
304- graphics .pose ().translate (xp , y , 0F );
305- graphics .pose ().scale (alpha , 1F , 1F );
306- graphics .renderFakeItem (remainingDisplayStack , 0 , 0 );
307- graphics .pose ().scale (1F / alpha , 1F , 1F );
308- graphics .pose ().translate (-xp , -y , 0F );
309- RenderSystem .setShaderColor (1F , 1F , 1F , 1F );
310-
311- String text = remainingDisplayStack .getHoverName ().plainCopy ().withStyle (ChatFormatting .GREEN ).getString ();
312- if (remainingCount >= 0 ) {
313- int max = remainingDisplayStack .getMaxStackSize ();
314- int stacks = remainingCount / max ;
315- int rem = remainingCount % max ;
316-
317- if (stacks == 0 ) {
318- text = "" + remainingCount ;
319- } else {
320- text = remainingCount + " (" + ChatFormatting .AQUA + stacks + ChatFormatting .RESET + "*"
321- + ChatFormatting .GRAY + max + ChatFormatting .RESET + "+" + ChatFormatting .YELLOW + rem
322- + ChatFormatting .RESET + ")" ;
323- }
324- } else if (remainingCount == -1 ) {
325- text = "∞" ;
314+ String text = remainingDisplayStack .getHoverName ().plainCopy ().withStyle (ChatFormatting .GREEN ).getString ();
315+ if (remainingCount >= 0 ) {
316+ int max = remainingDisplayStack .getMaxStackSize ();
317+ int stacks = remainingCount / max ;
318+ int rem = remainingCount % max ;
319+
320+ if (stacks == 0 ) {
321+ text = "" + remainingCount ;
322+ } else {
323+ text = remainingCount + " (" + ChatFormatting .AQUA + stacks + ChatFormatting .RESET + "*"
324+ + ChatFormatting .GRAY + max + ChatFormatting .RESET + "+" + ChatFormatting .YELLOW + rem
325+ + ChatFormatting .RESET + ")" ;
326326 }
327+ } else if (remainingCount == -1 ) {
328+ text = "∞" ;
329+ }
327330
328- int color = 0x00FFFFFF | (int ) (alpha * 0xFF ) << 24 ;
329- graphics .drawString (mc .font , text , x + 20 , y + 6 , color , true );
331+ int color = 0x00FFFFFF | (int ) (alpha * 0xFF ) << 24 ;
330332
331- graphics .pose (). popPose ( );
332- }
333+ graphics .drawString ( mc . font , text , x + 20 , y + 6 , color , true );
334+ graphics . pose (). popPose ();
333335 }
334336
335337 @ OnlyIn (Dist .CLIENT )
336338 private static void renderHUDItem (GuiGraphics graphics , DeltaTracker deltatracker ) {
337339 Minecraft mc = Minecraft .getInstance ();
340+ if (mc .player == null ) {
341+ return ;
342+ }
343+
338344 ItemStack stack = mc .player .getMainHandItem ();
339- if (!stack .isEmpty () && stack .getItem () instanceof IHUDItem ) {
340- (( IHUDItem ) stack . getItem ()) .drawHUD (graphics , deltatracker .getGameTimeDeltaPartialTick (false ), graphics .guiWidth (), graphics .guiHeight (), stack );
345+ if (!stack .isEmpty () && stack .getItem () instanceof IHUDItem hudItem ) {
346+ hudItem .drawHUD (graphics , deltatracker .getGameTimeDeltaPartialTick (false ), graphics .guiWidth (), graphics .guiHeight (), stack );
341347 }
342348
343349 stack = mc .player .getOffhandItem ();
344- if (!stack .isEmpty () && stack .getItem () instanceof IHUDItem ) {
345- (( IHUDItem ) stack . getItem ()) .drawHUD (graphics , deltatracker .getGameTimeDeltaPartialTick (false ), graphics .guiWidth (), graphics .guiHeight (), stack );
350+ if (!stack .isEmpty () && stack .getItem () instanceof IHUDItem hudItem ) {
351+ hudItem .drawHUD (graphics , deltatracker .getGameTimeDeltaPartialTick (false ), graphics .guiWidth (), graphics .guiHeight (), stack );
346352 }
347353 }
348354
@@ -356,7 +362,11 @@ public static void setRemaining(Player player, ItemStack displayStack, Pattern p
356362 int count = 0 ;
357363 for (int i = 0 ; i < player .getInventory ().getContainerSize (); i ++) {
358364 ItemStack stack = player .getInventory ().getItem (i );
359- if (!stack .isEmpty () && (pattern == null ? ItemStack .isSameItem (displayStack , stack ) : pattern .matcher (stack .getDescriptionId ()).find ())) {
365+ if (stack .isEmpty ()) {
366+ continue ;
367+ }
368+
369+ if (pattern == null ? ItemStack .isSameItem (displayStack , stack ) : pattern .matcher (stack .getDescriptionId ()).find ()) {
360370 count += stack .getCount ();
361371 }
362372 }
0 commit comments