-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f30241b
commit b1fdc4c
Showing
5 changed files
with
85 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/com/mitchej123/hodgepodge/util/ChatComponentItemTranslation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.mitchej123.hodgepodge.util; | ||
|
||
import java.util.Locale; | ||
import java.util.regex.Pattern; | ||
|
||
import net.minecraft.item.Item; | ||
import net.minecraft.util.ChatComponentStyle; | ||
import net.minecraft.util.IChatComponent; | ||
import net.minecraft.util.StatCollector; | ||
|
||
public class ChatComponentItemTranslation extends ChatComponentStyle { | ||
|
||
private static final Pattern FORMATTING_CODE_PATTERN = Pattern.compile("(?i)\u00a7[0-9A-FK-OR]"); | ||
|
||
private final Item item; | ||
|
||
public ChatComponentItemTranslation(Item item) { | ||
this.item = item; | ||
} | ||
|
||
@Override | ||
public String getUnformattedTextForChat() { | ||
String unlocalizedName = this.item.getUnlocalizedName() + ".name"; | ||
String localizedName = StatCollector.translateToLocal(unlocalizedName); | ||
StringBuilder sb = new StringBuilder(getTextWithoutFormattingCodes(localizedName)); | ||
for (IChatComponent sibling : this.getSiblings()) { | ||
sb.append(sibling.getUnformattedTextForChat()); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
@Override | ||
public IChatComponent createCopy() { | ||
ChatComponentItemTranslation component = new ChatComponentItemTranslation(this.item); | ||
for (IChatComponent sibling : this.getSiblings()) { | ||
component.appendSibling(sibling.createCopy()); | ||
} | ||
return component; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return 31 * super.hashCode() + this.item.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format( | ||
Locale.ROOT, | ||
"TranslatableItemComponent{item=%s, siblings=%s, style=%s}", | ||
this.item.delegate.name(), | ||
this.getSiblings(), | ||
this.getChatStyle()); | ||
} | ||
|
||
private static String getTextWithoutFormattingCodes(String text) { | ||
return text == null ? null : FORMATTING_CODE_PATTERN.matcher(text).replaceAll(""); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,22 @@ | ||
key.hodgepodge.category=Hodgepodge | ||
key.fastBlockPlacing.desc=Fast Block Placing | ||
key.fastBlockPlacing.enabled=§fFast Block Placing §aEnabled | ||
key.fastBlockPlacing.disabled=§fFast Block Placing §cDisabled | ||
key.fastBlockPlacing.disabled=§fFast Block Placing §cDisabled | ||
|
||
tile.dirt.name=Dirt | ||
tile.sapling.name=Sapling | ||
tile.sand.name=Sand | ||
tile.flower1.name=Flower | ||
tile.flower2.name=Flower | ||
tile.stoneSlab.name=Slab | ||
tile.monsterStoneEgg.name=Stone Monster Egg | ||
tile.woodSlab.name=Slab | ||
tile.cobbleWall.name=Wall | ||
tile.quartzBlock.name=Quartz Block | ||
tile.clayHardenedStained.name=Stained Clay | ||
tile.woolCarpet.name=Carpet | ||
tile.doublePlant.name=Large Plant | ||
|
||
item.dyePowder.name=Dye | ||
item.skull.name=Skull | ||
item.fish.name=Fish |