Fix storage search chat names localization (#1073)

This commit is contained in:
Eldrinn-Elantey authored and GitHub committed 2026-02-17 10:39:44 +01:00
1 parent 97b80f7092
commit c301a8c711
4 files changed
+118 -17

No files matched your search

@@ -3,9 +3,12 @@ package appeng.api.util;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
public class ItemSearchDTO {
@@ -17,21 +20,31 @@ public class ItemSearchDTO {
public ForgeDirection up;
public String blockName;
public String itemName;
public boolean blockNameNeedsTranslation;
private ItemStack itemStack;
public ItemSearchDTO(DimensionalCoord coord, IAEStack items, String blockName, int cellSlot, ForgeDirection forward,
ForgeDirection up) {
public ItemSearchDTO(DimensionalCoord coord, IAEStack items, String blockName, boolean blockNameNeedsTranslation,
int cellSlot, ForgeDirection forward, ForgeDirection up) {
this.coord = coord;
this.cellSlot = cellSlot;
this.itemCount = items.getStackSize();
if (items instanceof final IAEItemStack itemStack) {
this.itemStack = itemStack.getItemStack();
}
this.itemName = items.getLocalizedName();
if (this.itemName == null) this.itemName = " ";
this.blockName = blockName;
this.blockNameNeedsTranslation = blockNameNeedsTranslation;
this.forward = forward;
this.up = up;
}
public ItemSearchDTO(DimensionalCoord coord, IAEStack items, String blockName, boolean blockNameNeedsTranslation) {
this(coord, items, blockName, blockNameNeedsTranslation, -1, ForgeDirection.UNKNOWN, ForgeDirection.UNKNOWN);
}
public ItemSearchDTO(DimensionalCoord coord, IAEStack items, String blockName) {
this(coord, items, blockName, -1, ForgeDirection.UNKNOWN, ForgeDirection.UNKNOWN);
this(coord, items, blockName, false);
}
public ItemSearchDTO(final NBTTagCompound data) {
@@ -47,8 +60,14 @@ public class ItemSearchDTO {
data.setLong("itemCount", itemCount);
data.setString("blockName", blockName);
data.setString("itemName", itemName);
data.setBoolean("blockNameNeedsTranslation", blockNameNeedsTranslation);
data.setString("forward", this.forward.name());
data.setString("up", this.up.name());
if (this.itemStack != null) {
final NBTTagCompound itemStackData = new NBTTagCompound();
this.itemStack.writeToNBT(itemStackData);
data.setTag("itemStack", itemStackData);
}
}
public static void writeListToNBT(final NBTTagCompound tag, List<ItemSearchDTO> list) {
@@ -79,11 +98,45 @@ public class ItemSearchDTO {
int z = data.getInteger("z");
this.blockName = data.getString("blockName");
this.itemName = data.getString("itemName");
this.blockNameNeedsTranslation = data.getBoolean("blockNameNeedsTranslation");
this.itemCount = data.getLong("itemCount");
this.cellSlot = data.getInteger("cellSlot");
this.coord = new DimensionalCoord(x, y, z, dim);
this.forward = ForgeDirection.valueOf(data.getString("forward"));
this.up = ForgeDirection.valueOf(data.getString("up"));
if (data.hasKey("itemStack")) {
this.itemStack = ItemStack.loadItemStackFromNBT(data.getCompoundTag("itemStack"));
}
}
public String getDisplayItemName() {
if (this.itemStack != null) {
return this.itemStack.getDisplayName();
}
return this.itemName;
}
public String getDisplayBlockName() {
if (!this.blockNameNeedsTranslation) {
return this.blockName;
}
return translateBlockName(this.blockName);
}
private static String translateBlockName(final String unlocalizedName) {
if (unlocalizedName == null || unlocalizedName.isEmpty()) {
return " ";
}
final String nameKey = unlocalizedName.endsWith(".name") ? unlocalizedName : unlocalizedName + ".name";
if (StatCollector.canTranslate(nameKey)) {
return StatCollector.translateToLocal(nameKey);
}
if (StatCollector.canTranslate(unlocalizedName)) {
return StatCollector.translateToLocal(unlocalizedName);
}
return unlocalizedName;
}
}
@@ -48,22 +48,26 @@ public class StoragePosHighlighter extends BlockPosHighlighter {
if (foundMsg == null) {
continue;
}
final String blockName = storage.getDisplayBlockName();
final String itemName = storage.getDisplayItemName();
player.addChatMessage(
new ChatComponentTranslation(
foundMsg,
storage.blockName,
blockName,
storage.itemCount,
storage.itemName,
itemName,
storage.coord.x,
storage.coord.y,
storage.coord.z));
} else if (wrongDimMsg != null) {
final String blockName = storage.getDisplayBlockName();
final String itemName = storage.getDisplayItemName();
player.addChatMessage(
new ChatComponentTranslation(
wrongDimMsg,
storage.blockName,
blockName,
storage.itemCount,
storage.itemName,
itemName,
storage.coord.getDimension()));
}
}
@@ -46,6 +46,7 @@ import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.implementations.guiobjects.INetworkTool;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridBlock;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
@@ -796,6 +797,7 @@ public abstract class AEBaseContainer extends Container {
}
machineCount++;
IGridHost machine = gridNode.getMachine();
final HighlightNameData machineNameData = this.getHighlightNameData(gridNode, machine);
if (machine instanceof TileDrive innerMachine) {
for (int i = 0; i < innerMachine.getSizeInventory(); i++) {
@@ -806,13 +808,12 @@ public abstract class AEBaseContainer extends Container {
.getAvailableItem(slotItem, IterationCounter.fetchNewId());
if (result == null) continue;
String blockName = innerMachine.getCustomName();
coords.add(
new ItemSearchDTO(
innerMachine.getLocation(),
result,
blockName,
machineNameData.name,
machineNameData.translate,
i,
innerMachine.getForward(),
innerMachine.getUp()));
@@ -829,7 +830,12 @@ public abstract class AEBaseContainer extends Container {
IAEStack<IAEItemStack> result = handler
.getAvailableItem(slotItem, IterationCounter.fetchNewId());
if (result == null) continue;
coords.add(new ItemSearchDTO(innerMachine.getLocation(), result, innerMachine.getCustomName()));
coords.add(
new ItemSearchDTO(
innerMachine.getLocation(),
result,
machineNameData.name,
machineNameData.translate));
}
if (machine instanceof TileChest innerMachine) {
try {
@@ -840,7 +846,8 @@ public abstract class AEBaseContainer extends Container {
new ItemSearchDTO(
innerMachine.getLocation(),
result,
innerMachine.getCustomName()));
machineNameData.name,
machineNameData.translate));
} catch (Exception e) {
// :/
}
@@ -868,6 +875,33 @@ public abstract class AEBaseContainer extends Container {
}
}
private HighlightNameData getHighlightNameData(final IGridNode gridNode, final IGridHost machine) {
if (machine instanceof final ICustomNameObject customNameObject && customNameObject.hasCustomName()) {
return new HighlightNameData(customNameObject.getCustomName(), false);
}
final IGridBlock gridBlock = gridNode.getGridBlock();
if (gridBlock != null) {
final ItemStack machineRepresentation = gridBlock.getMachineRepresentation();
if (machineRepresentation != null && machineRepresentation.getItem() != null) {
return new HighlightNameData(machineRepresentation.getUnlocalizedName(), true);
}
}
return new HighlightNameData(machine.getClass().getSimpleName(), false);
}
private static final class HighlightNameData {
private final String name;
private final boolean translate;
private HighlightNameData(final String name, final boolean translate) {
this.name = name;
this.translate = translate;
}
}
protected void highlightBlocks(final EntityPlayerMP p, List<ItemSearchDTO> coords) {
if (Platform.isServer()) {
try {
@@ -32,6 +32,7 @@ tile.appliedenergistics2.BlockSpatialPylon.name=Пространственный
tile.appliedenergistics2.BlockTinyTNT.name=Маленький динамит
tile.appliedenergistics2.BlockVibrationChamber.name=Вибрационная камера
tile.appliedenergistics2.BlockWireless.name=МЭ беспроводная точка доступа
tile.appliedenergistics2.BlockWireless.desc=Right click with terminal in hand to bind it
tile.appliedenergistics2.OreQuartz.name=Руда истинного кварца
tile.appliedenergistics2.OreQuartzCharged.name=Заряженная руда истинного кварца
tile.appliedenergistics2.BlockSecurity.name=МЭ терминал безопасности
@@ -104,6 +105,7 @@ chat.appliedenergistics2.InvalidMachine=Неподходящий механиз
chat.appliedenergistics2.LoadedSettings=Настройки успешно загружены.
chat.appliedenergistics2.DeviceNotPowered=Устройству недостаточно энергии.
chat.appliedenergistics2.DeviceNotWirelessTerminal=Устройство не беспроводной терминал.
chat.appliedenergistics2.DeviceSuccessLinked=§aDevice successfully linked.
chat.appliedenergistics2.DeviceNotLinked=Устройство не соединено.
chat.appliedenergistics2.StationCanNotBeLocated=Станция не может быть найдена.
chat.appliedenergistics2.MachineNotPowered=Устройство без питания.
@@ -130,13 +132,15 @@ chat.appliedenergistics2.PriorityConfigured=Приоритет обновлен
chat.appliedenergistics2.DriveLockingToggled=Ячейки в накопителе были размечены/не размечены
chat.appliedenergistics2.ChestLockingToggled=Ячейка в сундуке была размечена/не размечена
chat.appliedenergistics2.FinishCraftingRemind=Создание %s * %s завершено за %s.
chat.appliedenergistics2.CraftComplete=§5Auto-Crafting Complete
chat.appliedenergistics2.CraftComplete.tip=%s %s, took %s
chat.appliedenergistics2.CraftingCantExtract=Невозможно извлечь необходимое количество ингредиента из хранилища: %d / %d | %s
chat.appliedenergistics2.MachineInOtherDim=%d расположен в измерении: %d и не может быть подсвечен
chat.appliedenergistics2.MachineInOtherDimNamed=%d "%s" located in dimension: %d and can't be highlighted
chat.appliedenergistics2.MachineInOtherDimNamed=%d "%s" расположен в измерении: %d и не может быть подсвечен
chat.appliedenergistics2.MachineHighlighted=%d сейчас подсвечен и находится: %d, %d, %d
chat.appliedenergistics2.MachineHighlightedNamed=The %d "%d" is now highlighted at %d, %d, %d
chat.appliedenergistics2.StorageHighlighted=The %d containing %d %d is now highlighted at %d, %d, %d
chat.appliedenergistics2.StorageInOtherDim=%d containing %d %d is located in dimension: %d and can't be highlighted
chat.appliedenergistics2.MachineHighlightedNamed=%d "%s" сейчас подсвечен и находится: %d, %d, %d
chat.appliedenergistics2.StorageHighlighted=%d содержащий %d %s сейчас подсвечен и находится: %d, %d, %d
chat.appliedenergistics2.StorageInOtherDim=%d содержащий %d %s расположен в измерении: %d и не может быть подсвечен
chat.appliedenergistics2.PickBlockTerminalNotFound=AE2 wireless terminal not found.
chat.appliedenergistics2.PatternRepeaterProvider=§5Provider§r - will provide pattern to current system from in front §5Accessor§r.
chat.appliedenergistics2.PatternRepeaterAccessor=§5Accessor§r - will provide pattern to in front §5Provider§r.
@@ -520,6 +524,10 @@ gui.tooltips.appliedenergistics2.ItemsStored=Хранящиеся предмет
gui.tooltips.appliedenergistics2.ItemCount=Количество предметов: %s
gui.tooltips.appliedenergistics2.ItemsRequestable=Запрашиваемые предметы: %s
gui.tooltips.appliedenergistics2.P2PFrequency=Частота: %s
gui.tooltips.appliedenergistics2.ExtractFromNetworkToContainer=§e%s + Left-click§f to extract §b%s§f from network
gui.tooltips.appliedenergistics2.InsertFromContainerToNetwork=§e%s + Right-click§f to insert §b%s§f into network
gui.tooltips.appliedenergistics2.HoldShiftProcessStack=Hold Shift to process the entire stack
gui.tooltips.appliedenergistics2.RegisterContainerContent=Hold §e%s§f to register as §b%s§f
gui.tooltips.appliedenergistics2.OreFilterHint=Фильтрует предметы с помощью имен Ore Dictionary
gui.tooltips.appliedenergistics2.OreFilter=Фильтр Ore Dictionary
gui.tooltips.appliedenergistics2.SearchStringTooltip=Щелкните ПКМ, чтобы очистить строку поиска
@@ -624,6 +632,7 @@ gui.tooltips.appliedenergistics2.scheduledreason.LOCK_MODE=Режим запир
gui.tooltips.appliedenergistics2.scheduledreason.NO_TARGET=Не могу найти цель для вставки
gui.tooltips.appliedenergistics2.scheduledreason.NOT_ENOUGH_INGREDIENTS=Недостаточно ингредиентов
gui.tooltips.appliedenergistics2.scheduledreason.SAME_NETWORK=Целевой интерфейс в той же сети
gui.tooltips.appliedenergistics2.scheduledreason.UNSUPPORTED_STACK=Contains a stack not supported by this interface
gui.tooltips.appliedenergistics2.ToggleShowOnlySubstitute=Переключает отображение интерфейсов с шаблонами с включённой заменой
gui.tooltips.appliedenergistics2.ToggleShowOnlySubstituteOnDesc=Отображение всех интерфейсов
@@ -692,6 +701,7 @@ waila.appliedenergistics2.Singularity=Singularity
waila.appliedenergistics2.Provider=§5Provider§r
waila.appliedenergistics2.Accessor=§5Accessor§r
waila.appliedenergistics2.Waiting=Waiting:
waila.appliedenergistics2.IOBusSpeed=Speed: %s %s/t
# Baubles Extended
slot.Terminal=§aTerminal§7
@@ -961,7 +971,7 @@ key.appliedenergistics2.category=Applied Energistics 2
key.pick_block.desc=AE2 Pick Block
key.toggle_focus.desc=Переключить фокус на окно поиска
key.search_connected_inventories.desc=Search network inventories for item
key.control_operation.desc=Control operation
key.container_interaction.desc=Container Item Interaction
# NEI
nei.options.keys.gui.pattern_view=View Pattern