Skip to content

Commit

Permalink
pull changes from upstream #1701
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Aug 15, 2021
1 parent 2bede3b commit fa1b388
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ protected boolean canGenerate(OrePrefix orePrefix, Material material) {
}

@Override
@SideOnly(Side.CLIENT)
public String getItemStackDisplayName(ItemStack itemStack) {
Material material = MaterialRegistry.MATERIAL_REGISTRY.getObjectById(itemStack.getItemDamage());
if (material == null || prefix == null) return "";
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/gregtech/api/items/metaitem/MetaItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import gregtech.api.unification.material.Material;
import gregtech.api.unification.ore.OrePrefix;
import gregtech.api.unification.stack.ItemMaterialInfo;
import gregtech.api.util.LocalizationUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
Expand Down Expand Up @@ -71,7 +72,6 @@
* {@code addItem(0, "test_item").addStats(new ElectricStats(10000, 1, false)) }
* This will add single-use (not rechargeable) LV battery with initial capacity 10000 EU
*/
@SuppressWarnings("deprecation")
public abstract class MetaItem<T extends MetaItem<?>.MetaValueItem> extends Item implements ItemUIFactory {

private static final List<MetaItem<?>> META_ITEMS = new ArrayList<>();
Expand Down Expand Up @@ -486,7 +486,6 @@ public boolean shouldCauseReequipAnimation(@Nonnull ItemStack oldStack, @Nonnull

@Nonnull
@Override
@SideOnly(Side.CLIENT)
public String getItemStackDisplayName(ItemStack stack) {
if (stack.getItemDamage() >= metaItemOffset) {
T item = getItem(stack);
Expand All @@ -501,9 +500,11 @@ 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 LocalizationUtils.format(unlocalizedName, fluidInside == null ?
LocalizationUtils.format("metaitem.fluid_cell.empty") :
fluidInside.getLocalizedName());
}
return I18n.format(unlocalizedName);
return LocalizationUtils.format(unlocalizedName);
}
return super.getItemStackDisplayName(stack);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gregtech/api/items/toolitem/ToolMetaItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import gregtech.api.unification.material.properties.ToolProperty;
import gregtech.api.util.GTLog;
import gregtech.api.util.GTUtility;
import gregtech.api.util.LocalizationUtils;
import gregtech.common.ConfigHolder;
import gregtech.common.tools.DamageValues;
import gregtech.common.tools.ToolWrench;
Expand Down Expand Up @@ -422,7 +423,6 @@ public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCom
}

@Override
@SideOnly(Side.CLIENT)
public String getItemStackDisplayName(ItemStack stack) {
if (stack.getItemDamage() >= metaItemOffset) {
T item = getItem(stack);
Expand All @@ -431,7 +431,7 @@ public String getItemStackDisplayName(ItemStack stack) {
}
Material primaryMaterial = getToolMaterial(stack);
String materialName = primaryMaterial == null ? "" : String.valueOf(primaryMaterial.getLocalizedName());
return I18n.format("metaitem." + item.unlocalizedName + ".name", materialName);
return LocalizationUtils.format("metaitem." + item.unlocalizedName + ".name", materialName);
}
return super.getItemStackDisplayName(stack);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import gregtech.api.pipenet.block.ItemBlockPipe;
import gregtech.api.unification.material.Material;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nonnull;

Expand All @@ -17,7 +15,6 @@ public ItemBlockMaterialPipe(BlockMaterialPipe<PipeType, NodeDataType, ?> block)
@Nonnull
@SuppressWarnings("unchecked")
@Override
@SideOnly(Side.CLIENT)
public String getItemStackDisplayName(@Nonnull ItemStack stack) {
PipeType pipeType = blockPipe.getItemPipeType(stack);
Material material = ((BlockMaterialPipe<PipeType, NodeDataType, ?>) blockPipe).getItemMaterial(stack);
Expand Down
11 changes: 2 additions & 9 deletions src/main/java/gregtech/api/recipes/RecipeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,11 @@
import gregtech.api.recipes.crafttweaker.CTRecipeBuilder;
import gregtech.api.unification.material.Material;
import gregtech.api.unification.ore.OrePrefix;
import gregtech.api.util.EnumValidationResult;
import gregtech.api.util.GTLog;
import gregtech.api.util.GTUtility;
import gregtech.api.util.ValidationResult;
import net.minecraft.client.resources.I18n;
import gregtech.api.util.*;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.Optional.Method;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandlerModifiable;
import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.*;
Expand Down Expand Up @@ -424,10 +418,9 @@ public List<CTRecipe> ccGetRecipeList() {
.collect(Collectors.toList());
}

@SideOnly(Side.CLIENT)
@ZenGetter("localizedName")
public String getLocalizedName() {
return I18n.format("recipemap." + unlocalizedName + ".name");
return LocalizationUtils.format("recipemap." + unlocalizedName + ".name");
}

@ZenGetter("unlocalizedName")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import gregtech.api.GTValues;
import gregtech.api.recipes.FluidKey;
import gregtech.api.recipes.recipes.FuelRecipe;
import net.minecraft.client.resources.I18n;
import gregtech.api.util.LocalizationUtils;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.Optional.Method;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMethod;
Expand Down Expand Up @@ -84,10 +82,9 @@ public List<FuelRecipe> getRecipeList() {
return Collections.unmodifiableList(recipeList);
}

@SideOnly(Side.CLIENT)
@ZenGetter("localizedName")
public String getLocalizedName() {
return I18n.format("recipemap." + unlocalizedName + ".name");
return LocalizationUtils.format("recipemap." + unlocalizedName + ".name");
}

@ZenGetter("unlocalizedName")
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/gregtech/api/unification/material/Material.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
import gregtech.api.unification.material.info.MaterialIconSet;
import gregtech.api.unification.material.properties.*;
import gregtech.api.unification.stack.MaterialStack;
import gregtech.api.util.LocalizationUtils;
import gregtech.api.util.SmallDigits;
import net.minecraft.client.resources.I18n;
import net.minecraft.enchantment.Enchantment;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import stanhebben.zenscript.annotations.OperatorType;
import stanhebben.zenscript.annotations.ZenOperator;

Expand Down Expand Up @@ -301,10 +299,9 @@ public String getUnlocalizedName() {
return "material." + materialInfo.name;
}

@SideOnly(Side.CLIENT)
//@ZenGetter("localizedName")
public String getLocalizedName() {
return I18n.format(getUnlocalizedName());
return LocalizationUtils.format(getUnlocalizedName());
}

@Override
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/gregtech/api/unification/ore/OrePrefix.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import gregtech.api.unification.material.properties.IMaterialProperty;
import gregtech.api.unification.material.properties.PropertyKey;
import gregtech.api.unification.stack.MaterialStack;
import gregtech.api.util.LocalizationUtils;
import gregtech.api.util.function.TriConsumer;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.Validate;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -546,13 +545,13 @@ private void runGeneratedMaterialHandlers() {
currentProcessingPrefix.set(null);
}

@SideOnly(Side.CLIENT) // todo clean this up
// todo clean this up
public String getLocalNameForItem(Material material) {
String specifiedUnlocalized = "item." + material.toString() + "." + this.name;
if (I18n.hasKey(specifiedUnlocalized)) return I18n.format(specifiedUnlocalized);
if (LocalizationUtils.hasKey(specifiedUnlocalized)) return I18n.format(specifiedUnlocalized);
String unlocalized = "item.material.oreprefix." + this.name;
String matLocalized = material.getLocalizedName();
String formatted = I18n.format(unlocalized, matLocalized);
String formatted = LocalizationUtils.format(unlocalized, matLocalized);
return formatted.equals(unlocalized) ? matLocalized : formatted;
}

Expand Down
49 changes: 49 additions & 0 deletions src/main/java/gregtech/api/util/LocalizationUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package gregtech.api.util;

import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;

@SuppressWarnings("deprecation")
public class LocalizationUtils {

/**
* This function calls `net.minecraft.client.resources.I18n.format` when called on client
* or `net.minecraft.util.text.translation.I18n.translateToLocalFormatted` when called on server.
* <ul>
* <li>It is intended that translations should be done using `I18n` on the client.</li>
* <li>For setting up translations on the server you should use `TextComponentTranslatable`.</li>
* <li>`LocalisationUtils` is only for cases where some kind of translation is required on the server and there is no client/player in context.</li>
* <li>`LocalisationUtils` is "best effort" and will probably only work properly with en-us.</li>
* </ul>
* @param localisationKey the localisation key passed to the underlying format function
* @param substitutions the substitutions passed to the underlying format function
* @return the localized string.
*/
public static String format(String localisationKey, Object... substitutions) {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
return net.minecraft.util.text.translation.I18n.translateToLocalFormatted(localisationKey, substitutions);
} else {
return net.minecraft.client.resources.I18n.format(localisationKey, substitutions);
}
}

/**
* This function calls `net.minecraft.client.resources.I18n.hasKey` when called on client
* or `net.minecraft.util.text.translation.I18n.canTranslate` when called on server.
* <ul>
* <li>It is intended that translations should be done using `I18n` on the client.</li>
* <li>For setting up translations on the server you should use `TextComponentTranslatable`.</li>
* <li>`LocalisationUtils` is only for cases where some kind of translation is required on the server and there is no client/player in context.</li>
* <li>`LocalisationUtils` is "best effort" and will probably only work properly with en-us.</li>
* </ul>
* @param localisationKey the localisation key passed to the underlying hasKey function
* @return a boolean indicating if the given localisation key has localisations
*/
public static boolean hasKey(String localisationKey) {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
return net.minecraft.util.text.translation.I18n.canTranslate(localisationKey);
} else {
return net.minecraft.client.resources.I18n.hasKey(localisationKey);
}
}
}
4 changes: 0 additions & 4 deletions src/main/java/gregtech/common/blocks/CompressedItemBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nonnull;

Expand All @@ -25,14 +23,12 @@ public int getMetadata(int damage) {
return damage;
}

@SuppressWarnings("deprecation")
public IBlockState getBlockState(ItemStack stack) {
return compressedBlock.getStateFromMeta(getMetadata(stack.getItemDamage()));
}

@Nonnull
@Override
@SideOnly(Side.CLIENT)
public String getItemStackDisplayName(@Nonnull ItemStack stack) {
Material material = getBlockState(stack).getValue(compressedBlock.variantProperty);
return OrePrefix.block.getLocalNameForItem(material);
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/gregtech/common/blocks/FrameItemBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nonnull;

Expand All @@ -31,7 +29,6 @@ public IBlockState getBlockState(ItemStack stack) {

@Nonnull
@Override
@SideOnly(Side.CLIENT)
public String getItemStackDisplayName(@Nonnull ItemStack stack) {
Material material = frameBlock.frameMaterial;
return OrePrefix.frameGt.getLocalNameForItem(material);
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/gregtech/common/blocks/OreItemBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nonnull;

Expand All @@ -32,18 +30,15 @@ public CreativeTabs[] getCreativeTabs() {
return new CreativeTabs[]{CreativeTabs.SEARCH, GregTechAPI.TAB_GREGTECH_ORES};
}

@SuppressWarnings("deprecation")
protected IBlockState getBlockState(ItemStack stack) {
return oreBlock.getStateFromMeta(getMetadata(stack.getItemDamage()));
}

@Nonnull
@Override
@SideOnly(Side.CLIENT)
public String getItemStackDisplayName(@Nonnull ItemStack stack) {
IBlockState blockState = getBlockState(stack);
StoneType stoneType = blockState.getValue(oreBlock.STONE_TYPE);
return stoneType.processingPrefix.getLocalNameForItem(oreBlock.material);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import gregtech.api.unification.material.MaterialRegistry;
import gregtech.api.unification.material.Materials;
import gregtech.api.unification.material.properties.PropertyKey;
import gregtech.api.util.LocalizationUtils;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.common.util.Constants.NBT;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.List;

Expand Down Expand Up @@ -65,10 +64,9 @@ public void setPartDamage(ItemStack itemStack, int rotorDamage) {
}

@Override
@SideOnly(Side.CLIENT)
public String getItemStackDisplayName(ItemStack itemStack, String unlocalizedName) {
Material material = getPartMaterial(itemStack);
return I18n.format(unlocalizedName, material.getLocalizedName());
return LocalizationUtils.format(unlocalizedName, material.getLocalizedName());
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gregtech/common/items/behaviors/FacadeItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.google.common.collect.ImmutableList;
import gregtech.api.items.metaitem.stats.IItemNameProvider;
import gregtech.api.items.metaitem.stats.ISubItemHandler;
import gregtech.api.util.LocalizationUtils;
import gregtech.common.ConfigHolder;
import gregtech.common.covers.facade.FacadeHelper;
import net.minecraft.client.resources.I18n;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
Expand All @@ -24,7 +24,7 @@ public class FacadeItem implements IItemNameProvider, ISubItemHandler {
public String getItemStackDisplayName(ItemStack itemStack, String unlocalizedName) {
ItemStack facadeStack = getFacadeStack(itemStack);
String name = facadeStack.getItem().getItemStackDisplayName(facadeStack);
return I18n.format(unlocalizedName, name);
return LocalizationUtils.format(unlocalizedName, name);
}

@Override
Expand Down

0 comments on commit fa1b388

Please sign in to comment.