From 2eaccba3e33f2e752a34b8259f066381b09238e5 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 3 Aug 2016 17:17:52 +0200 Subject: [PATCH] Added a character limit to the NBT display of the advanced info so that it doesn't crash on really long NBT tags --- .../mod/config/values/ConfigIntValues.java | 3 ++- .../actuallyadditions/mod/event/ClientEvents.java | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigIntValues.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigIntValues.java index 41eb4f576..e561e36c6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigIntValues.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigIntValues.java @@ -23,7 +23,8 @@ public enum ConfigIntValues{ BLACK_LOTUS_AMOUNT("Black Lotus: Amount", ConfigCategories.WORLD_GEN, 14, 1, 50, "The Amount of Black Lotus generating"), LUSH_CAVE_CHANCE("Lush Caves: Chance", ConfigCategories.WORLD_GEN, 20, 1, 100, "The chance for lush caves to generate. The lower the number, the likelier."), - TILE_ENTITY_UPDATE_INTERVAL("Tile Entities: Update Interval", ConfigCategories.OTHER, 5, 1, 100, "The amount of ticks waited before a TileEntity sends an additional Update to the Client"); + TILE_ENTITY_UPDATE_INTERVAL("Tile Entities: Update Interval", ConfigCategories.OTHER, 5, 1, 100, "The amount of ticks waited before a TileEntity sends an additional Update to the Client"), + CTRL_INFO_NBT_CHAR_LIMIT("Advanced Info NBT Character Limit", ConfigCategories.OTHER, 1000, 0, 100000000, "The maximum amount of characters that is displayed by the NBT view of the CTRL Advanced Info. Set to a zero to have no limit"); public final String name; public final String category; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/event/ClientEvents.java b/src/main/java/de/ellpeck/actuallyadditions/mod/event/ClientEvents.java index 54e1f4328..5e7657e44 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/event/ClientEvents.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/event/ClientEvents.java @@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.event; import de.ellpeck.actuallyadditions.mod.blocks.IHudDisplay; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; +import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues; import de.ellpeck.actuallyadditions.mod.inventory.gui.EnergyDisplay; import de.ellpeck.actuallyadditions.mod.tile.IEnergyDisplay; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; @@ -99,7 +100,18 @@ public class ClientEvents{ if(compound != null && !compound.hasNoTags()){ event.getToolTip().add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".nbt.desc")+":"); if(GuiScreen.isShiftKeyDown()){ - event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+compound.toString()); + int limit = ConfigIntValues.CTRL_INFO_NBT_CHAR_LIMIT.getValue(); + String compoundStrg = compound.toString(); + int compoundStrgLength = compoundStrg.length(); + + String compoundDisplay; + if(limit > 0 && compoundStrgLength > limit){ + compoundDisplay = compoundStrg.substring(0, limit)+TextFormatting.GRAY+" ("+(compoundStrgLength-limit)+" more characters...)"; + } + else{ + compoundDisplay = compoundStrg; + } + event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+compoundDisplay); } else{ event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+TextFormatting.ITALIC+"["+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".pressShift.desc")+"]");