Merge pull request #2178 from abel1502/abel-fix-2177

Fix #2177
This commit is contained in:
HbmMods 2025-05-26 11:30:36 +02:00 committed by GitHub
commit b00e3b9efb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 19 deletions

View File

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

View File

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