|
2 | 2 |
|
3 | 3 | import net.fabricmc.api.EnvType; |
4 | 4 | import net.fabricmc.api.Environment; |
5 | | -import net.minecraft.client.gui.hud.HudIngame; |
| 5 | +import net.minecraft.client.gui.Gui; |
6 | 6 | import net.minecraft.client.render.texture.stitcher.TextureRegistry; |
7 | 7 | import net.minecraft.core.entity.player.Player; |
8 | 8 |
|
9 | 9 | @Environment(EnvType.CLIENT) |
10 | 10 | public class HeartContainer { |
11 | | - public enum HeartGlyphVariant { |
12 | | - NONE(""), |
13 | | - HARDCORE("hardcore"), |
14 | | - PREVIEW("preview"), |
15 | | - OVERHEAL("overheal"); |
16 | | - |
17 | | - private final String name; |
18 | | - |
19 | | - HeartGlyphVariant(String colorName) { |
20 | | - this.name = colorName; |
21 | | - } |
22 | | - |
23 | | - public String getName() { |
24 | | - return name; |
25 | | - } |
26 | | - } |
27 | | - |
28 | | - public enum HeartGlyphType { |
29 | | - FULL("full"), |
30 | | - HALF("half"), |
31 | | - HALF_RIGHT("half_right"), |
32 | | - CONTAINER("container"); |
33 | | - |
34 | | - private final String name; |
35 | | - |
36 | | - HeartGlyphType(String colorName) { |
37 | | - this.name = colorName; |
38 | | - } |
39 | | - |
40 | | - public String getName() { |
41 | | - return name; |
42 | | - } |
43 | | - } |
44 | | - |
45 | | - protected final Player player; |
46 | | - |
47 | | - public HeartContainer(Player player) { |
48 | | - this.player = player; |
49 | | - } |
50 | | - |
51 | | - public String getBasePath() { |
52 | | - return "minecraft:gui/hud/heart/"; |
53 | | - } |
54 | | - |
55 | | - public String getPathForGlyph(HeartGlyphVariant glyphVariant, HeartGlyphType glyphType) { |
56 | | - if (glyphType == HeartGlyphType.CONTAINER) { |
57 | | - return getBasePath() + glyphType.name + (isHeartFlashing() ? "_blinking" : ""); |
58 | | - } |
59 | | - |
60 | | - String prefix = (glyphVariant != HeartGlyphVariant.NONE ? glyphVariant.name + "_" : ""); |
61 | | - return getBasePath() + prefix + glyphType.name + (isHeartFlashing() ? "_blinking" : ""); |
62 | | - } |
63 | | - |
64 | | - public void drawHeart(HeartGlyphVariant variant, HeartGlyphType glyphType, int x, int y, HudIngame hud) { |
65 | | - hud.drawGuiIcon(x, y, 9, 9, TextureRegistry.getTexture(getPathForGlyph(variant, glyphType))); |
66 | | - } |
67 | | - |
68 | | - public boolean isHeartFlashing() { |
69 | | - boolean heartsFlash = player.heartsFlashTime / 3 % 2 == 1; |
70 | | - if (player.heartsFlashTime < 10) { |
71 | | - heartsFlash = false; |
72 | | - } |
73 | | - |
74 | | - return heartsFlash; |
75 | | - } |
76 | | - |
77 | | - public boolean shouldShake() { |
78 | | - return player.getHealth() < 4 || isHeartFlashing(); |
79 | | - } |
| 11 | + public enum HeartGlyphVariant { |
| 12 | + NONE(""), |
| 13 | + HARDCORE("hardcore"), |
| 14 | + PREVIEW("preview"), |
| 15 | + OVERHEAL("overheal"); |
| 16 | + |
| 17 | + private final String name; |
| 18 | + |
| 19 | + HeartGlyphVariant(String colorName) { |
| 20 | + this.name = colorName; |
| 21 | + } |
| 22 | + |
| 23 | + public String getName() { |
| 24 | + return name; |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + public enum HeartGlyphType { |
| 29 | + FULL("full"), |
| 30 | + HALF("half"), |
| 31 | + HALF_RIGHT("half_right"), |
| 32 | + CONTAINER("container"); |
| 33 | + |
| 34 | + private final String name; |
| 35 | + |
| 36 | + HeartGlyphType(String colorName) { |
| 37 | + this.name = colorName; |
| 38 | + } |
| 39 | + |
| 40 | + public String getName() { |
| 41 | + return name; |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + protected final Player player; |
| 46 | + |
| 47 | + public HeartContainer(Player player) { |
| 48 | + this.player = player; |
| 49 | + } |
| 50 | + |
| 51 | + public String getBasePath() { |
| 52 | + return "minecraft:gui/hud/heart/"; |
| 53 | + } |
| 54 | + |
| 55 | + public String getPathForGlyph(HeartGlyphVariant glyphVariant, HeartGlyphType glyphType) { |
| 56 | + if (glyphType == HeartGlyphType.CONTAINER) { |
| 57 | + return getBasePath() + glyphType.name + (isHeartFlashing() ? "_blinking" : ""); |
| 58 | + } |
| 59 | + |
| 60 | + String prefix = (glyphVariant != HeartGlyphVariant.NONE ? glyphVariant.name + "_" : ""); |
| 61 | + return getBasePath() + prefix + glyphType.name + (isHeartFlashing() ? "_blinking" : ""); |
| 62 | + } |
| 63 | + |
| 64 | + public void drawHeart(HeartGlyphVariant variant, HeartGlyphType glyphType, int x, int y, Gui hud) { |
| 65 | + hud.drawGuiIcon(x, y, 9, 9, TextureRegistry.getTexture(getPathForGlyph(variant, glyphType))); |
| 66 | + } |
| 67 | + |
| 68 | + public boolean isHeartFlashing() { |
| 69 | + boolean heartsFlash = player.heartsFlashTime / 3 % 2 == 1; |
| 70 | + if (player.heartsFlashTime < 10) { |
| 71 | + heartsFlash = false; |
| 72 | + } |
| 73 | + |
| 74 | + return heartsFlash; |
| 75 | + } |
| 76 | + |
| 77 | + public boolean shouldShake() { |
| 78 | + return player.getHealth() < 4 || isHeartFlashing(); |
| 79 | + } |
80 | 80 |
|
81 | 81 | } |
82 | 82 |
|
0 commit comments