Skip to content
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

Fix getItemStackDisplayName on Servers #1701

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/main/java/gregtech/api/block/machines/MachineItemBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import gregtech.api.GregTechAPI;
import gregtech.api.metatileentity.ITieredMetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.util.LocalisationUtils;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
Expand Down Expand Up @@ -75,8 +75,8 @@ public void addInformation(ItemStack stack, @Nullable World worldIn, List<String

//item specific tooltip like: gregtech.machine.lathe.lv.tooltip
String tooltipLocale = metaTileEntity.getMetaName() + ".tooltip";
if (I18n.hasKey(tooltipLocale)) {
String[] lines = I18n.format(tooltipLocale).split("/n");
if (LocalisationUtils.hasKey(tooltipLocale)) {
String[] lines = LocalisationUtils.format(tooltipLocale).split("/n");
tooltip.addAll(Arrays.asList(lines));
}

Expand All @@ -85,8 +85,8 @@ public void addInformation(ItemStack stack, @Nullable World worldIn, List<String
String tierlessTooltipLocale = ((ITieredMetaTileEntity) metaTileEntity).getTierlessTooltipKey();
//only add tierless tooltip if it's key is not equal to normal tooltip key (i.e if machine name has dot in it's name)
//case when it's not true would be any machine extending from TieredMetaTileEntity but having only one tier
if (!tooltipLocale.equals(tierlessTooltipLocale) && I18n.hasKey(tierlessTooltipLocale)) {
String[] lines = I18n.format(tierlessTooltipLocale).split("/n");
if (!tooltipLocale.equals(tierlessTooltipLocale) && LocalisationUtils.hasKey(tierlessTooltipLocale)) {
String[] lines = LocalisationUtils.format(tierlessTooltipLocale).split("/n");
tooltip.addAll(Arrays.asList(lines));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gregtech/api/gui/widgets/ClickButtonWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import gregtech.api.gui.Widget;
import gregtech.api.gui.resources.SizedTextureArea;
import gregtech.api.gui.resources.TextureArea;
import gregtech.api.util.LocalisationUtils;
import gregtech.api.util.Position;
import gregtech.api.util.Size;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.network.PacketBuffer;
import org.lwjgl.input.Mouse;

Expand Down Expand Up @@ -50,7 +50,7 @@ public void drawInBackground(int mouseX, int mouseY, IRenderContext context) {
buttonTexture.drawSubArea(position.x, position.y, size.width, size.height, 0.0, 0.0, 1.0, 1.0);
}
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
String text = I18n.format(displayText);
String text = LocalisationUtils.format(displayText);
fontRenderer.drawString(text,
position.x + size.width / 2 - fontRenderer.getStringWidth(text) / 2,
position.y + size.height / 2 - fontRenderer.FONT_HEIGHT / 2, textColor);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/gregtech/api/gui/widgets/CycleButtonWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import gregtech.api.gui.resources.SizedTextureArea;
import gregtech.api.gui.resources.TextureArea;
import gregtech.api.util.GTUtility;
import gregtech.api.util.LocalisationUtils;
import gregtech.api.util.Position;
import gregtech.api.util.Size;
import gregtech.api.util.function.BooleanConsumer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.IStringSerializable;
Expand Down Expand Up @@ -85,7 +85,7 @@ public void drawInBackground(int mouseX, int mouseY, IRenderContext context) {
buttonTexture.drawSubArea(pos.x, pos.y, size.width, size.height, 0.0, 0.0, 1.0, 1.0);
}
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
String text = I18n.format(optionNames[currentOption]);
String text = LocalisationUtils.format(optionNames[currentOption]);
fontRenderer.drawString(text,
pos.x + size.width / 2 - fontRenderer.getStringWidth(text) / 2,
pos.y + size.height / 2 - fontRenderer.FONT_HEIGHT / 2 + 1, textColor);
Expand All @@ -105,7 +105,7 @@ public void drawInForeground(int mouseX, int mouseY) {
} else if (isHovered) {
long timeSinceHover = System.currentTimeMillis() - hoverStartTime;
if (timeSinceHover > 1000L && tooltipHoverString != null) {
List<String> hoverList = Arrays.asList(I18n.format(tooltipHoverString).split("/n"));
List<String> hoverList = Arrays.asList(LocalisationUtils.format(tooltipHoverString).split("/n"));
drawHoveringText(ItemStack.EMPTY, hoverList, 300, mouseX, mouseY);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gregtech/api/gui/widgets/LabelWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import gregtech.api.gui.IRenderContext;
import gregtech.api.gui.Widget;
import gregtech.api.util.LocalisationUtils;
import gregtech.api.util.Position;
import gregtech.api.util.Size;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

Expand Down Expand Up @@ -36,7 +36,7 @@ public LabelWidget(int xPosition, int yPosition, String text, int color, Object[
}

private String getResultText() {
return I18n.format(text, formatting);
return LocalisationUtils.format(text, formatting);
}

private void recomputeSize() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gregtech/api/gui/widgets/SimpleTextWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import gregtech.api.gui.IRenderContext;
import gregtech.api.gui.Widget;
import gregtech.api.util.LocalisationUtils;
import gregtech.api.util.Position;
import gregtech.api.util.Size;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.network.PacketBuffer;

import java.util.function.Supplier;
Expand Down Expand Up @@ -46,7 +46,7 @@ private void updateSize() {
@Override
public void drawInBackground(int mouseX, int mouseY, IRenderContext context) {
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
String text = formatLocale.isEmpty() ? (I18n.hasKey(lastText) ? I18n.format(lastText) : lastText) : I18n.format(formatLocale, lastText);
String text = formatLocale.isEmpty() ? (LocalisationUtils.hasKey(lastText) ? LocalisationUtils.format(lastText) : lastText) : LocalisationUtils.format(formatLocale, lastText);
Position position = getPosition();
fontRenderer.drawString(text,
position.x - fontRenderer.getStringWidth(text) / 2,
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gregtech/api/gui/widgets/SliderWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import gregtech.api.gui.IRenderContext;
import gregtech.api.gui.Widget;
import gregtech.api.gui.resources.TextureArea;
import gregtech.api.util.LocalisationUtils;
import gregtech.api.util.Position;
import gregtech.api.util.Size;
import gregtech.api.util.function.FloatConsumer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.MathHelper;

Expand All @@ -21,7 +21,7 @@

public class SliderWidget extends Widget {

public static final BiFunction<String, Float, String> DEFAULT_TEXT_SUPPLIER = (name, value) -> I18n.format(name, value.intValue());
public static final BiFunction<String, Float, String> DEFAULT_TEXT_SUPPLIER = (name, value) -> LocalisationUtils.format(name, value.intValue());

private int sliderWidth = 8;
private TextureArea backgroundArea = GuiTextures.SLIDER_BACKGROUND;
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/gregtech/api/gui/widgets/TankWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import gregtech.api.gui.resources.RenderUtil;
import gregtech.api.gui.resources.TextureArea;
import gregtech.api.util.FluidTooltipUtil;
import gregtech.api.util.LocalisationUtils;
import gregtech.api.util.Position;
import gregtech.api.util.Size;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
Expand Down Expand Up @@ -143,22 +143,22 @@ public void drawInForeground(int mouseX, int mouseY) {
if (formula != null && !formula.isEmpty())
tooltips.add(ChatFormatting.GRAY.toString() + formula);

tooltips.add(I18n.format("gregtech.fluid.amount", lastFluidInTank.amount, lastTankCapacity));
tooltips.add(I18n.format("gregtech.fluid.temperature", fluid.getTemperature(lastFluidInTank)));
tooltips.add(I18n.format(fluid.isGaseous(lastFluidInTank) ? "gregtech.fluid.state_gas" : "gregtech.fluid.state_liquid"));
tooltips.add(LocalisationUtils.format("gregtech.fluid.amount", lastFluidInTank.amount, lastTankCapacity));
tooltips.add(LocalisationUtils.format("gregtech.fluid.temperature", fluid.getTemperature(lastFluidInTank)));
tooltips.add(LocalisationUtils.format(fluid.isGaseous(lastFluidInTank) ? "gregtech.fluid.state_gas" : "gregtech.fluid.state_liquid"));
} else {
tooltips.add(I18n.format("gregtech.fluid.empty"));
tooltips.add(I18n.format("gregtech.fluid.amount", 0, lastTankCapacity));
tooltips.add(LocalisationUtils.format("gregtech.fluid.empty"));
tooltips.add(LocalisationUtils.format("gregtech.fluid.amount", 0, lastTankCapacity));
}
if (allowClickFilling) {
tooltips.add(""); //add empty line to separate things
tooltips.add(I18n.format("gregtech.fluid.click_to_fill"));
tooltips.add(I18n.format("gregtech.fluid.click_to_fill.shift"));
tooltips.add(LocalisationUtils.format("gregtech.fluid.click_to_fill"));
tooltips.add(LocalisationUtils.format("gregtech.fluid.click_to_fill.shift"));
}
if (allowClickEmptying) {
tooltips.add(""); //add empty line to separate things
tooltips.add(I18n.format("gregtech.fluid.click_to_empty"));
tooltips.add(I18n.format("gregtech.fluid.click_to_empty.shift"));
tooltips.add(LocalisationUtils.format("gregtech.fluid.click_to_empty"));
tooltips.add(LocalisationUtils.format("gregtech.fluid.click_to_empty.shift"));
}
drawHoveringText(ItemStack.EMPTY, tooltips, 300, mouseX, mouseY);
GlStateManager.color(1.0f, 1.0f, 1.0f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import gregtech.api.gui.Widget;
import gregtech.api.gui.resources.SizedTextureArea;
import gregtech.api.gui.resources.TextureArea;
import gregtech.api.util.LocalisationUtils;
import gregtech.api.util.Position;
import gregtech.api.util.Size;
import gregtech.api.util.function.BooleanConsumer;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.relauncher.Side;
Expand Down Expand Up @@ -69,7 +69,7 @@ public void drawInForeground(int mouseX, int mouseY) {
if(isMouseOverElement(mouseX, mouseY) && tooltipText != null) {
String postfix = isPressed ? ".enabled" : ".disabled";
String tooltipHoverString = tooltipText + postfix;
List<String> hoverList = Arrays.asList(I18n.format(tooltipHoverString).split("/n"));
List<String> hoverList = Arrays.asList(LocalisationUtils.format(tooltipHoverString).split("/n"));
drawHoveringText(ItemStack.EMPTY, hoverList, 300, mouseX, mouseY);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gregtech/api/gui/widgets/tab/ItemTabInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import com.google.common.collect.Lists;
import gregtech.api.gui.resources.TextureArea;
import gregtech.api.util.LocalisationUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.client.config.GuiUtils;

Expand All @@ -32,7 +32,7 @@ public void renderTab(TextureArea tabTexture, int posX, int posY, int xSize, int

@Override
public void renderHoverText(int posX, int posY, int xSize, int ySize, int guiWidth, int guiHeight, boolean isSelected, int mouseX, int mouseY) {
String localizedText = I18n.format(nameLocale);
String localizedText = LocalisationUtils.format(nameLocale);
Minecraft mc = Minecraft.getMinecraft();
ScaledResolution resolution = new ScaledResolution(mc);
GuiUtils.drawHoveringText(Lists.newArrayList(localizedText), mouseX, mouseY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ protected boolean canGenerate(OrePrefix orePrefix, Material material) {
}

@Override
@SideOnly(Side.CLIENT)
public String getItemStackDisplayName(ItemStack itemStack) {
if (itemStack.getItemDamage() < metaItemOffset) {
Material material = Material.MATERIAL_REGISTRY.getObjectById(itemStack.getItemDamage() % 1000);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gregtech/api/items/metaitem/ElectricStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import gregtech.api.items.metaitem.stats.IItemCapabilityProvider;
import gregtech.api.items.metaitem.stats.IItemMaxStackSizeProvider;
import gregtech.api.items.metaitem.stats.IItemComponent;
import net.minecraft.client.resources.I18n;
import gregtech.api.util.LocalisationUtils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
Expand Down Expand Up @@ -115,7 +115,7 @@ private static void setInDischargeMode(ItemStack itemStack, boolean isDischargeM
public void addInformation(ItemStack itemStack, List<String> lines) {
IElectricItem electricItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
if(electricItem != null && electricItem.canProvideChargeExternally()) {
lines.add(I18n.format("metaitem.electric.discharge_mode.tooltip"));
lines.add(LocalisationUtils.format("metaitem.electric.discharge_mode.tooltip"));
}
}

Expand Down
17 changes: 8 additions & 9 deletions src/main/java/gregtech/api/items/metaitem/MetaItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import gregtech.api.unification.material.type.Material;
import gregtech.api.unification.ore.OrePrefix;
import gregtech.api.unification.stack.ItemMaterialInfo;
import gregtech.api.util.LocalisationUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
Expand Down Expand Up @@ -471,7 +471,6 @@ public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStac
}

@Override
@SideOnly(Side.CLIENT)
public String getItemStackDisplayName(ItemStack stack) {
if (stack.getItemDamage() >= metaItemOffset) {
T item = getItem(stack);
Expand All @@ -486,9 +485,9 @@ public String getItemStackDisplayName(ItemStack stack) {
.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
if (fluidHandlerItem != null) {
FluidStack fluidInside = fluidHandlerItem.drain(Integer.MAX_VALUE, false);
return I18n.format(unlocalizedName, fluidInside == null ? I18n.format("metaitem.fluid_cell.empty") : fluidInside.getLocalizedName());
return LocalisationUtils.format(unlocalizedName, fluidInside == null ? LocalisationUtils.format("metaitem.fluid_cell.empty") : fluidInside.getLocalizedName());
}
return I18n.format(unlocalizedName);
return LocalisationUtils.format(unlocalizedName);
}
return super.getItemStackDisplayName(stack);
}
Expand All @@ -499,13 +498,13 @@ public void addInformation(ItemStack itemStack, @Nullable World worldIn, List<St
T item = getItem(itemStack);
if (item == null) return;
String unlocalizedTooltip = "metaitem." + item.unlocalizedName + ".tooltip";
if (I18n.hasKey(unlocalizedTooltip)) {
lines.addAll(Arrays.asList(I18n.format(unlocalizedTooltip).split("/n")));
if (LocalisationUtils.hasKey(unlocalizedTooltip)) {
lines.addAll(Arrays.asList(LocalisationUtils.format(unlocalizedTooltip).split("/n")));
}

IElectricItem electricItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
if (electricItem != null) {
lines.add(I18n.format("metaitem.generic.electric_item.tooltip",
lines.add(LocalisationUtils.format("metaitem.generic.electric_item.tooltip",
electricItem.getCharge(),
electricItem.getMaxCharge(),
GTValues.VN[electricItem.getTier()]));
Expand All @@ -517,11 +516,11 @@ public void addInformation(ItemStack itemStack, @Nullable World worldIn, List<St
IFluidTankProperties fluidTankProperties = fluidHandler.getTankProperties()[0];
FluidStack fluid = fluidTankProperties.getContents();
if (fluid != null) {
lines.add(I18n.format("metaitem.generic.fluid_container.tooltip",
lines.add(LocalisationUtils.format("metaitem.generic.fluid_container.tooltip",
fluid.amount,
fluidTankProperties.getCapacity(),
fluid.getLocalizedName()));
} else lines.add(I18n.format("metaitem.generic.fluid_container.tooltip_empty"));
} else lines.add(LocalisationUtils.format("metaitem.generic.fluid_container.tooltip_empty"));
}

for (IItemBehaviour behaviour : getBehaviours(itemStack)) {
Expand Down
Loading