The original hotfix is no longer necessary, as all remaning calls to getFullName are fully client-side
This commit is contained in:
abel1502 2025-05-26 11:58:28 +03:00
parent 38c6b4691d
commit 00c73d63c0
No known key found for this signature in database
GPG Key ID: 076926596A536338
2 changed files with 25 additions and 19 deletions

View File

@ -1,6 +1,6 @@
package com.hbm.handler.ability; package com.hbm.handler.ability;
import com.hbm.util.i18n.I18nUtil; import net.minecraft.client.resources.I18n;
public interface IBaseAbility extends Comparable<IBaseAbility> { public interface IBaseAbility extends Comparable<IBaseAbility> {
public String getName(); public String getName();
@ -9,9 +9,9 @@ public interface IBaseAbility extends Comparable<IBaseAbility> {
return ""; return "";
} }
// Note: only usable client-side. Server-side, use ChatComponentTranslation manually instead
public default String getFullName(int level) { public default String getFullName(int level) {
//bandaid fix so it doesn't crash servers instantly, TODO: use ChatComponentTranslation return I18n.format(getName()) + getExtension(level);
return I18nUtil.format(getName()) + getExtension(level);
} }
public default boolean isAllowed() { public default boolean isAllowed() {

View File

@ -27,26 +27,32 @@ public class ToolPreset {
this.harvestAbilityLevel = harvestAbilityLevel; this.harvestAbilityLevel = harvestAbilityLevel;
} }
public ChatComponentText getMessage() { public ChatComponentText getMessage() {
if(isNone()) if (isNone()) {
return ChatBuilder.start("[Tool ability deactivated]").color(EnumChatFormatting.GOLD).flush(); return ChatBuilder.start("[Tool ability deactivated]").color(EnumChatFormatting.GOLD).flush();
}
String areaPart = areaAbility.getFullName(areaAbilityLevel); boolean hasArea = areaAbility != IToolAreaAbility.NONE;
String harvestPart = harvestAbility.getFullName(harvestAbilityLevel); boolean hasHarvest = harvestAbility != IToolHarvestAbility.NONE;
ChatBuilder builder = ChatBuilder.start("[Enabled ");
ChatBuilder builder = ChatBuilder.start("[Enabled "); if (hasArea) {
builder.nextTranslation(areaAbility.getName());
builder.next(areaAbility.getExtension(areaAbilityLevel));
}
if(!areaPart.isEmpty()) if (hasArea && hasHarvest) {
builder.next(areaPart); builder.next(" + ");
}
if(!areaPart.isEmpty() && !harvestPart.isEmpty()) if (hasHarvest) {
builder.next(" + "); builder.nextTranslation(harvestAbility.getName());
builder.next(harvestAbility.getExtension(harvestAbilityLevel));
if(!harvestPart.isEmpty()) }
builder.next(harvestPart);
return builder.colorAll(EnumChatFormatting.YELLOW).flush();
return builder.colorAll(EnumChatFormatting.YELLOW).flush(); }
}
public boolean isNone() { public boolean isNone() {
return areaAbility == IToolAreaAbility.NONE && harvestAbility == IToolHarvestAbility.NONE; return areaAbility == IToolAreaAbility.NONE && harvestAbility == IToolHarvestAbility.NONE;