-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathFluidTooltipUtil.java
More file actions
126 lines (105 loc) · 3.66 KB
/
FluidTooltipUtil.java
File metadata and controls
126 lines (105 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package gregtech.api.util;
import com.google.common.collect.Lists;
import com.mojang.realmsclient.gui.ChatFormatting;
import gregtech.api.unification.material.Materials;
import gregtech.api.unification.stack.MaterialStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class FluidTooltipUtil {
/**
* Registry Mapping of <Fluid, Tooltip>
*/
private static final Map<Fluid, List<String>> tooltips = new HashMap<>();
/**
* Used to register a tooltip to a Fluid. A Fluid can only have one tooltip, on one line.
*
* Ignores a tooltip applied for Water, so that it will be handled correctly for the chemical formula.
*
* @param fluid The fluid to register a tooltip for.
* @param tooltips The tooltip.
* @return False if either parameter is null or if tooltip is empty, true otherwise.
*/
public static boolean registerTooltip(Fluid fluid, List<String> tooltips) {
if (fluid != null && tooltips != null && !tooltips.isEmpty()) {
for (String tooltip : tooltips) {
registerTooltip(fluid, tooltip);
}
}
return false;
}
public static boolean registerTooltip(Fluid fluid, String tooltip) {
if (fluid != null && tooltip != null && !tooltip.trim().isEmpty()) {
if(tooltips.containsKey(fluid)) {
tooltips.get(fluid).add(tooltip);
} else {
tooltips.put(fluid, Lists.newArrayList(tooltip));
}
return true;
}
return false;
}
/**
* Used to get a Fluid's tooltip.
*
* @param fluid The Fluid to get the tooltip of.
* @return The tooltip.
*/
public static List<String> getFluidTooltips(Fluid fluid) {
if (fluid == null)
return null;
return tooltips.get(fluid);
}
@Deprecated
public static String getFluidTooltip(Fluid fluid) {
if (fluid == null)
return null;
return tooltips.get(fluid).get(1);
}
/**
* Used to get a Fluid's tooltip.
*
* @param stack A FluidStack, containing the Fluid to get the tooltip of.
* @return The tooltip.
*/
public static List<String> getFluidTooltips(FluidStack stack) {
if (stack == null)
return null;
return getFluidTooltips(stack.getFluid());
}
@Deprecated
public static String getFluidTooltip(FluidStack stack) {
if (stack == null)
return null;
return getFluidTooltip(stack.getFluid());
}
/**
* Used to get a Fluid's tooltip.
*
* @param fluidName A String representing a Fluid to get the tooltip of.
* @return The tooltip.
*/
public static List<String> getFluidTooltips(String fluidName) {
if (fluidName == null || fluidName.isEmpty())
return null;
return getFluidTooltips(FluidRegistry.getFluid(fluidName));
}
@Deprecated
public static String getFluidTooltip(String fluidName) {
if (fluidName == null || fluidName.isEmpty())
return null;
return getFluidTooltip(FluidRegistry.getFluid(fluidName));
}
/**
* A simple helper method to get the tooltip for Water, since it is an edge case of fluids.
*
* @return "H₂O"
*/
public static String getWaterTooltip() {
// Done like this to not return parenthesis around the tooltip
return (ChatFormatting.GRAY + (new MaterialStack(Materials.Hydrogen, 2)).toString() + "O");
}
}