Skip to content

Commit fa1b388

Browse files
committed
pull changes from upstream #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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 5 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 2 additions & 9 deletions
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

Lines changed: 2 additions & 5 deletions
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

Lines changed: 2 additions & 5 deletions
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

Lines changed: 4 additions & 5 deletions
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

Lines changed: 49 additions & 0 deletions
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

Lines changed: 0 additions & 4 deletions
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);

0 commit comments

Comments
 (0)