-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properly implementing fluid tooltips #1581
base: master
Are you sure you want to change the base?
Changes from all commits
1beea21
7e15068
58558d6
ae5b173
ee49b94
2be90ff
7b7f43e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import codechicken.lib.texture.TextureUtils; | ||
import codechicken.lib.util.ItemNBTUtils; | ||
import codechicken.lib.util.ResourceUtils; | ||
import com.google.common.collect.Lists; | ||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; | ||
import com.mojang.realmsclient.gui.ChatFormatting; | ||
import gregtech.api.GTValues; | ||
|
@@ -56,10 +57,7 @@ | |
import java.io.InputStreamReader; | ||
import java.net.*; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import java.util.*; | ||
|
||
@SideOnly(Side.CLIENT) | ||
@Mod.EventBusSubscriber(Side.CLIENT) | ||
|
@@ -154,33 +152,33 @@ public static void addMaterialFormulaHandler(ItemTooltipEvent event) { | |
|
||
// Handles Item tooltips | ||
if (!(itemStack.getItem() instanceof ItemBlock)) { | ||
String chemicalFormula = null; | ||
List<String> chemicalFormula = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should change this to be 2 different methods of handling it, since our fluid tooltip is not just a chemical formula anymore, but a general fluid tooltip application |
||
|
||
// Test for Items | ||
UnificationEntry unificationEntry = OreDictUnifier.getUnificationEntry(itemStack); | ||
if (unificationEntry != null && unificationEntry.material != null) { | ||
chemicalFormula = unificationEntry.material.chemicalFormula; | ||
chemicalFormula = Lists.newArrayList(ChatFormatting.GRAY + unificationEntry.material.chemicalFormula); | ||
|
||
// Test for Fluids | ||
} else if (ItemNBTUtils.hasTag(itemStack)) { | ||
|
||
// Vanilla bucket | ||
chemicalFormula = FluidTooltipUtil.getFluidTooltip(ItemNBTUtils.getString(itemStack, "FluidName")); | ||
chemicalFormula = FluidTooltipUtil.getFluidTooltips(ItemNBTUtils.getString(itemStack, "FluidName")); | ||
|
||
// GTCE Cells, Forestry cans, some other containers | ||
if (chemicalFormula == null) { | ||
NBTTagCompound compound = itemStack.getTagCompound(); | ||
if (compound != null && compound.hasKey(FluidHandlerItemStack.FLUID_NBT_KEY, Constants.NBT.TAG_COMPOUND)) { | ||
chemicalFormula = FluidTooltipUtil.getFluidTooltip(FluidStack.loadFluidStackFromNBT(compound.getCompoundTag(FluidHandlerItemStack.FLUID_NBT_KEY))); | ||
chemicalFormula = FluidTooltipUtil.getFluidTooltips(FluidStack.loadFluidStackFromNBT(compound.getCompoundTag(FluidHandlerItemStack.FLUID_NBT_KEY))); | ||
} | ||
} | ||
|
||
// Water buckets have a separate registry name from other buckets | ||
} else if(itemStack.getItem().equals(Items.WATER_BUCKET)) { | ||
chemicalFormula = FluidTooltipUtil.getWaterTooltip(); | ||
chemicalFormula = Lists.newArrayList(FluidTooltipUtil.getWaterTooltip()); | ||
} | ||
if (chemicalFormula != null && !chemicalFormula.isEmpty()) | ||
event.getToolTip().add(1, ChatFormatting.GRAY.toString() + chemicalFormula); | ||
event.getToolTip().addAll(1, chemicalFormula); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package gregtech.common; | ||
|
||
import com.mojang.realmsclient.gui.ChatFormatting; | ||
import gregtech.api.GTValues; | ||
import gregtech.api.unification.material.Materials; | ||
import gregtech.api.unification.material.type.FluidMaterial; | ||
|
@@ -145,12 +146,12 @@ public static void init() { | |
int temperature = fluidMaterial.getFluidTemperature(); | ||
Fluid fluid = registerFluid(fluidMaterial, FluidType.NORMAL, temperature); | ||
fluidMaterial.setMaterialFluid(fluid); | ||
FluidTooltipUtil.registerTooltip(fluid, fluidMaterial.chemicalFormula); | ||
FluidTooltipUtil.registerTooltip(fluid, ChatFormatting.GRAY + fluidMaterial.chemicalFormula); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
} | ||
if (fluidMaterial.shouldGeneratePlasma() && fluidMaterial.getMaterialPlasma() == null) { | ||
Fluid fluid = registerFluid(fluidMaterial, FluidType.PLASMA, 30000); | ||
fluidMaterial.setMaterialPlasma(fluid); | ||
FluidTooltipUtil.registerTooltip(fluid, fluidMaterial.chemicalFormula); | ||
FluidTooltipUtil.registerTooltip(fluid, ChatFormatting.GRAY + fluidMaterial.chemicalFormula); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be
.get(0)
? From how we are registering it inregisterTooltip(Fluid, String)
, it does not appear to be skipping the 0 indexThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am too bit concerned why we are using sometimes 0, sometimes 1 when working with tooltips.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it is because when applying the tooltip to an ItemStack, the name of the Item is in index 0 in the list. For fluid tooltips, since I had to do it a bit more roundabout, index 0 of the registry will be put at index 1 of an ItemStack containing this fluid. Otherwise, when given to a FluidStack in JEI, it will just simply add to the end of the tooltip list rather than insert at an index.