Skip to content

Commit fa1b388

Browse files
committed
pull changes from upstream GregTechCEu#1701
1 parent 2bede3b commit fa1b388

File tree

14 files changed

+70
-52
lines changed

14 files changed

+70
-52
lines changed

src/main/java/gregtech/api/items/materialitem/MetaPrefixItem.java

-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ protected boolean canGenerate(OrePrefix orePrefix, Material material) {
9797
}
9898

9999
@Override
100-
@SideOnly(Side.CLIENT)
101100
public String getItemStackDisplayName(ItemStack itemStack) {
102101
Material material = MaterialRegistry.MATERIAL_REGISTRY.getObjectById(itemStack.getItemDamage());
103102
if (material == null || prefix == null) return "";

src/main/java/gregtech/api/items/metaitem/MetaItem.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import gregtech.api.unification.material.Material;
2323
import gregtech.api.unification.ore.OrePrefix;
2424
import gregtech.api.unification.stack.ItemMaterialInfo;
25+
import gregtech.api.util.LocalizationUtils;
2526
import net.minecraft.client.Minecraft;
2627
import net.minecraft.client.renderer.block.model.ModelBakery;
2728
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
@@ -71,7 +72,6 @@
7172
* {@code addItem(0, "test_item").addStats(new ElectricStats(10000, 1, false)) }
7273
* This will add single-use (not rechargeable) LV battery with initial capacity 10000 EU
7374
*/
74-
@SuppressWarnings("deprecation")
7575
public abstract class MetaItem<T extends MetaItem<?>.MetaValueItem> extends Item implements ItemUIFactory {
7676

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

487487
@Nonnull
488488
@Override
489-
@SideOnly(Side.CLIENT)
490489
public String getItemStackDisplayName(ItemStack stack) {
491490
if (stack.getItemDamage() >= metaItemOffset) {
492491
T item = getItem(stack);
@@ -501,9 +500,11 @@ public String getItemStackDisplayName(ItemStack stack) {
501500
.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
502501
if (fluidHandlerItem != null) {
503502
FluidStack fluidInside = fluidHandlerItem.drain(Integer.MAX_VALUE, false);
504-
return I18n.format(unlocalizedName, fluidInside == null ? I18n.format("metaitem.fluid_cell.empty") : fluidInside.getLocalizedName());
503+
return LocalizationUtils.format(unlocalizedName, fluidInside == null ?
504+
LocalizationUtils.format("metaitem.fluid_cell.empty") :
505+
fluidInside.getLocalizedName());
505506
}
506-
return I18n.format(unlocalizedName);
507+
return LocalizationUtils.format(unlocalizedName);
507508
}
508509
return super.getItemStackDisplayName(stack);
509510
}

src/main/java/gregtech/api/items/toolitem/ToolMetaItem.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import gregtech.api.unification.material.properties.ToolProperty;
2626
import gregtech.api.util.GTLog;
2727
import gregtech.api.util.GTUtility;
28+
import gregtech.api.util.LocalizationUtils;
2829
import gregtech.common.ConfigHolder;
2930
import gregtech.common.tools.DamageValues;
3031
import gregtech.common.tools.ToolWrench;
@@ -422,7 +423,6 @@ public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCom
422423
}
423424

424425
@Override
425-
@SideOnly(Side.CLIENT)
426426
public String getItemStackDisplayName(ItemStack stack) {
427427
if (stack.getItemDamage() >= metaItemOffset) {
428428
T item = getItem(stack);
@@ -431,7 +431,7 @@ public String getItemStackDisplayName(ItemStack stack) {
431431
}
432432
Material primaryMaterial = getToolMaterial(stack);
433433
String materialName = primaryMaterial == null ? "" : String.valueOf(primaryMaterial.getLocalizedName());
434-
return I18n.format("metaitem." + item.unlocalizedName + ".name", materialName);
434+
return LocalizationUtils.format("metaitem." + item.unlocalizedName + ".name", materialName);
435435
}
436436
return super.getItemStackDisplayName(stack);
437437
}

src/main/java/gregtech/api/pipenet/block/material/ItemBlockMaterialPipe.java

-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import gregtech.api.pipenet.block.ItemBlockPipe;
44
import gregtech.api.unification.material.Material;
55
import net.minecraft.item.ItemStack;
6-
import net.minecraftforge.fml.relauncher.Side;
7-
import net.minecraftforge.fml.relauncher.SideOnly;
86

97
import javax.annotation.Nonnull;
108

@@ -17,7 +15,6 @@ public ItemBlockMaterialPipe(BlockMaterialPipe<PipeType, NodeDataType, ?> block)
1715
@Nonnull
1816
@SuppressWarnings("unchecked")
1917
@Override
20-
@SideOnly(Side.CLIENT)
2118
public String getItemStackDisplayName(@Nonnull ItemStack stack) {
2219
PipeType pipeType = blockPipe.getItemPipeType(stack);
2320
Material material = ((BlockMaterialPipe<PipeType, NodeDataType, ?>) blockPipe).getItemMaterial(stack);

src/main/java/gregtech/api/recipes/RecipeMap.java

+2-9
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,11 @@
2222
import gregtech.api.recipes.crafttweaker.CTRecipeBuilder;
2323
import gregtech.api.unification.material.Material;
2424
import gregtech.api.unification.ore.OrePrefix;
25-
import gregtech.api.util.EnumValidationResult;
26-
import gregtech.api.util.GTLog;
27-
import gregtech.api.util.GTUtility;
28-
import gregtech.api.util.ValidationResult;
29-
import net.minecraft.client.resources.I18n;
25+
import gregtech.api.util.*;
3026
import net.minecraft.item.ItemStack;
3127
import net.minecraftforge.fluids.Fluid;
3228
import net.minecraftforge.fluids.FluidStack;
3329
import net.minecraftforge.fml.common.Optional.Method;
34-
import net.minecraftforge.fml.relauncher.Side;
35-
import net.minecraftforge.fml.relauncher.SideOnly;
3630
import net.minecraftforge.items.IItemHandlerModifiable;
3731
import stanhebben.zenscript.annotations.Optional;
3832
import stanhebben.zenscript.annotations.*;
@@ -424,10 +418,9 @@ public List<CTRecipe> ccGetRecipeList() {
424418
.collect(Collectors.toList());
425419
}
426420

427-
@SideOnly(Side.CLIENT)
428421
@ZenGetter("localizedName")
429422
public String getLocalizedName() {
430-
return I18n.format("recipemap." + unlocalizedName + ".name");
423+
return LocalizationUtils.format("recipemap." + unlocalizedName + ".name");
431424
}
432425

433426
@ZenGetter("unlocalizedName")

src/main/java/gregtech/api/recipes/machines/FuelRecipeMap.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
import gregtech.api.GTValues;
77
import gregtech.api.recipes.FluidKey;
88
import gregtech.api.recipes.recipes.FuelRecipe;
9-
import net.minecraft.client.resources.I18n;
9+
import gregtech.api.util.LocalizationUtils;
1010
import net.minecraftforge.fluids.FluidStack;
1111
import net.minecraftforge.fml.common.Optional.Method;
12-
import net.minecraftforge.fml.relauncher.Side;
13-
import net.minecraftforge.fml.relauncher.SideOnly;
1412
import stanhebben.zenscript.annotations.ZenClass;
1513
import stanhebben.zenscript.annotations.ZenGetter;
1614
import stanhebben.zenscript.annotations.ZenMethod;
@@ -84,10 +82,9 @@ public List<FuelRecipe> getRecipeList() {
8482
return Collections.unmodifiableList(recipeList);
8583
}
8684

87-
@SideOnly(Side.CLIENT)
8885
@ZenGetter("localizedName")
8986
public String getLocalizedName() {
90-
return I18n.format("recipemap." + unlocalizedName + ".name");
87+
return LocalizationUtils.format("recipemap." + unlocalizedName + ".name");
9188
}
9289

9390
@ZenGetter("unlocalizedName")

src/main/java/gregtech/api/unification/material/Material.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
import gregtech.api.unification.material.info.MaterialIconSet;
1111
import gregtech.api.unification.material.properties.*;
1212
import gregtech.api.unification.stack.MaterialStack;
13+
import gregtech.api.util.LocalizationUtils;
1314
import gregtech.api.util.SmallDigits;
14-
import net.minecraft.client.resources.I18n;
1515
import net.minecraft.enchantment.Enchantment;
1616
import net.minecraftforge.fluids.Fluid;
1717
import net.minecraftforge.fluids.FluidStack;
18-
import net.minecraftforge.fml.relauncher.Side;
19-
import net.minecraftforge.fml.relauncher.SideOnly;
2018
import stanhebben.zenscript.annotations.OperatorType;
2119
import stanhebben.zenscript.annotations.ZenOperator;
2220

@@ -301,10 +299,9 @@ public String getUnlocalizedName() {
301299
return "material." + materialInfo.name;
302300
}
303301

304-
@SideOnly(Side.CLIENT)
305302
//@ZenGetter("localizedName")
306303
public String getLocalizedName() {
307-
return I18n.format(getUnlocalizedName());
304+
return LocalizationUtils.format(getUnlocalizedName());
308305
}
309306

310307
@Override

src/main/java/gregtech/api/unification/ore/OrePrefix.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
import gregtech.api.unification.material.properties.IMaterialProperty;
99
import gregtech.api.unification.material.properties.PropertyKey;
1010
import gregtech.api.unification.stack.MaterialStack;
11+
import gregtech.api.util.LocalizationUtils;
1112
import gregtech.api.util.function.TriConsumer;
1213
import net.minecraft.client.resources.I18n;
13-
import net.minecraftforge.fml.relauncher.Side;
14-
import net.minecraftforge.fml.relauncher.SideOnly;
1514
import org.apache.commons.lang3.Validate;
1615

1716
import javax.annotation.Nullable;
@@ -546,13 +545,13 @@ private void runGeneratedMaterialHandlers() {
546545
currentProcessingPrefix.set(null);
547546
}
548547

549-
@SideOnly(Side.CLIENT) // todo clean this up
548+
// todo clean this up
550549
public String getLocalNameForItem(Material material) {
551550
String specifiedUnlocalized = "item." + material.toString() + "." + this.name;
552-
if (I18n.hasKey(specifiedUnlocalized)) return I18n.format(specifiedUnlocalized);
551+
if (LocalizationUtils.hasKey(specifiedUnlocalized)) return I18n.format(specifiedUnlocalized);
553552
String unlocalized = "item.material.oreprefix." + this.name;
554553
String matLocalized = material.getLocalizedName();
555-
String formatted = I18n.format(unlocalized, matLocalized);
554+
String formatted = LocalizationUtils.format(unlocalized, matLocalized);
556555
return formatted.equals(unlocalized) ? matLocalized : formatted;
557556
}
558557

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package gregtech.api.util;
2+
3+
import net.minecraftforge.fml.common.FMLCommonHandler;
4+
import net.minecraftforge.fml.relauncher.Side;
5+
6+
@SuppressWarnings("deprecation")
7+
public class LocalizationUtils {
8+
9+
/**
10+
* This function calls `net.minecraft.client.resources.I18n.format` when called on client
11+
* or `net.minecraft.util.text.translation.I18n.translateToLocalFormatted` when called on server.
12+
* <ul>
13+
* <li>It is intended that translations should be done using `I18n` on the client.</li>
14+
* <li>For setting up translations on the server you should use `TextComponentTranslatable`.</li>
15+
* <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>
16+
* <li>`LocalisationUtils` is "best effort" and will probably only work properly with en-us.</li>
17+
* </ul>
18+
* @param localisationKey the localisation key passed to the underlying format function
19+
* @param substitutions the substitutions passed to the underlying format function
20+
* @return the localized string.
21+
*/
22+
public static String format(String localisationKey, Object... substitutions) {
23+
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
24+
return net.minecraft.util.text.translation.I18n.translateToLocalFormatted(localisationKey, substitutions);
25+
} else {
26+
return net.minecraft.client.resources.I18n.format(localisationKey, substitutions);
27+
}
28+
}
29+
30+
/**
31+
* This function calls `net.minecraft.client.resources.I18n.hasKey` when called on client
32+
* or `net.minecraft.util.text.translation.I18n.canTranslate` when called on server.
33+
* <ul>
34+
* <li>It is intended that translations should be done using `I18n` on the client.</li>
35+
* <li>For setting up translations on the server you should use `TextComponentTranslatable`.</li>
36+
* <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>
37+
* <li>`LocalisationUtils` is "best effort" and will probably only work properly with en-us.</li>
38+
* </ul>
39+
* @param localisationKey the localisation key passed to the underlying hasKey function
40+
* @return a boolean indicating if the given localisation key has localisations
41+
*/
42+
public static boolean hasKey(String localisationKey) {
43+
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
44+
return net.minecraft.util.text.translation.I18n.canTranslate(localisationKey);
45+
} else {
46+
return net.minecraft.client.resources.I18n.hasKey(localisationKey);
47+
}
48+
}
49+
}

src/main/java/gregtech/common/blocks/CompressedItemBlock.java

-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import net.minecraft.block.state.IBlockState;
66
import net.minecraft.item.ItemBlock;
77
import net.minecraft.item.ItemStack;
8-
import net.minecraftforge.fml.relauncher.Side;
9-
import net.minecraftforge.fml.relauncher.SideOnly;
108

119
import javax.annotation.Nonnull;
1210

@@ -25,14 +23,12 @@ public int getMetadata(int damage) {
2523
return damage;
2624
}
2725

28-
@SuppressWarnings("deprecation")
2926
public IBlockState getBlockState(ItemStack stack) {
3027
return compressedBlock.getStateFromMeta(getMetadata(stack.getItemDamage()));
3128
}
3229

3330
@Nonnull
3431
@Override
35-
@SideOnly(Side.CLIENT)
3632
public String getItemStackDisplayName(@Nonnull ItemStack stack) {
3733
Material material = getBlockState(stack).getValue(compressedBlock.variantProperty);
3834
return OrePrefix.block.getLocalNameForItem(material);

src/main/java/gregtech/common/blocks/FrameItemBlock.java

-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import net.minecraft.block.state.IBlockState;
66
import net.minecraft.item.ItemBlock;
77
import net.minecraft.item.ItemStack;
8-
import net.minecraftforge.fml.relauncher.Side;
9-
import net.minecraftforge.fml.relauncher.SideOnly;
108

119
import javax.annotation.Nonnull;
1210

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

3230
@Nonnull
3331
@Override
34-
@SideOnly(Side.CLIENT)
3532
public String getItemStackDisplayName(@Nonnull ItemStack stack) {
3633
Material material = frameBlock.frameMaterial;
3734
return OrePrefix.frameGt.getLocalNameForItem(material);

src/main/java/gregtech/common/blocks/OreItemBlock.java

-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import net.minecraft.creativetab.CreativeTabs;
77
import net.minecraft.item.ItemBlock;
88
import net.minecraft.item.ItemStack;
9-
import net.minecraftforge.fml.relauncher.Side;
10-
import net.minecraftforge.fml.relauncher.SideOnly;
119

1210
import javax.annotation.Nonnull;
1311

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

35-
@SuppressWarnings("deprecation")
3633
protected IBlockState getBlockState(ItemStack stack) {
3734
return oreBlock.getStateFromMeta(getMetadata(stack.getItemDamage()));
3835
}
3936

4037
@Nonnull
4138
@Override
42-
@SideOnly(Side.CLIENT)
4339
public String getItemStackDisplayName(@Nonnull ItemStack stack) {
4440
IBlockState blockState = getBlockState(stack);
4541
StoneType stoneType = blockState.getValue(oreBlock.STONE_TYPE);
4642
return stoneType.processingPrefix.getLocalNameForItem(oreBlock.material);
4743
}
48-
4944
}

src/main/java/gregtech/common/items/behaviors/AbstractMaterialPartBehavior.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
import gregtech.api.unification.material.MaterialRegistry;
99
import gregtech.api.unification.material.Materials;
1010
import gregtech.api.unification.material.properties.PropertyKey;
11+
import gregtech.api.util.LocalizationUtils;
1112
import net.minecraft.client.resources.I18n;
1213
import net.minecraft.item.ItemStack;
1314
import net.minecraft.nbt.NBTTagCompound;
1415
import net.minecraft.util.math.MathHelper;
1516
import net.minecraftforge.common.util.Constants.NBT;
16-
import net.minecraftforge.fml.relauncher.Side;
17-
import net.minecraftforge.fml.relauncher.SideOnly;
1817

1918
import java.util.List;
2019

@@ -65,10 +64,9 @@ public void setPartDamage(ItemStack itemStack, int rotorDamage) {
6564
}
6665

6766
@Override
68-
@SideOnly(Side.CLIENT)
6967
public String getItemStackDisplayName(ItemStack itemStack, String unlocalizedName) {
7068
Material material = getPartMaterial(itemStack);
71-
return I18n.format(unlocalizedName, material.getLocalizedName());
69+
return LocalizationUtils.format(unlocalizedName, material.getLocalizedName());
7270
}
7371

7472
@Override

src/main/java/gregtech/common/items/behaviors/FacadeItem.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import com.google.common.collect.ImmutableList;
44
import gregtech.api.items.metaitem.stats.IItemNameProvider;
55
import gregtech.api.items.metaitem.stats.ISubItemHandler;
6+
import gregtech.api.util.LocalizationUtils;
67
import gregtech.common.ConfigHolder;
78
import gregtech.common.covers.facade.FacadeHelper;
8-
import net.minecraft.client.resources.I18n;
99
import net.minecraft.creativetab.CreativeTabs;
1010
import net.minecraft.init.Blocks;
1111
import net.minecraft.init.Items;
@@ -24,7 +24,7 @@ public class FacadeItem implements IItemNameProvider, ISubItemHandler {
2424
public String getItemStackDisplayName(ItemStack itemStack, String unlocalizedName) {
2525
ItemStack facadeStack = getFacadeStack(itemStack);
2626
String name = facadeStack.getItem().getItemStackDisplayName(facadeStack);
27-
return I18n.format(unlocalizedName, name);
27+
return LocalizationUtils.format(unlocalizedName, name);
2828
}
2929

3030
@Override

0 commit comments

Comments
 (0)