Skip to content

Commit

Permalink
Remove caching from localization keys. Fixes #48
Browse files Browse the repository at this point in the history
  • Loading branch information
falkreon committed Aug 11, 2023
1 parent 176792d commit 00cecfb
Showing 1 changed file with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ public class TypedGroupedBlockItem extends BlockItem implements TypedGrouped {

protected final TypedGroupedBlock typedGroupedBlock;

@ClientOnly
protected Text cachedLocalization = null;

public <T extends Block & TypedGrouped> TypedGroupedBlockItem(T block, Settings settings) {
super(block, settings);
typedGroupedBlock = block.getTypedGroupedBlock();
Expand Down Expand Up @@ -57,21 +54,16 @@ private Text getBaseTranslationKey() {
@Override
@ClientOnly
public Text getName() {
if (cachedLocalization == null) {
String translationKey = Util.createTranslationKey("block", Registries.ITEM.getId(this));
if (I18n.hasTranslation(translationKey)) {
return Text.translatable(translationKey);
} else {
Text baseBlock = getBaseTranslationKey();
String typedGroupedKey = BLOCK_TYPE_PREFIX + "." + typedGroupedBlock.type().toString();
Text blockType = Text.translatable(typedGroupedKey);

String translationKey = Util.createTranslationKey("block", Registries.ITEM.getId(this));
if (I18n.hasTranslation(translationKey)) {
cachedLocalization = Text.translatable(translationKey);
} else {
Text baseBlock = getBaseTranslationKey();
String typedGroupedKey = BLOCK_TYPE_PREFIX + "." + typedGroupedBlock.type().toString();
Text blockType = Text.translatable(typedGroupedKey);

cachedLocalization = Text.translatable(BLOCKTYPE_BLOCK_KEY, baseBlock, blockType);
}
return Text.translatable(BLOCKTYPE_BLOCK_KEY, baseBlock, blockType);
}

return cachedLocalization;
}

@Override
Expand Down

0 comments on commit 00cecfb

Please sign in to comment.