Translations! and formatters
This commit is contained in:
parent
dac3a1cabd
commit
cc05975c2f
@ -23,8 +23,10 @@ import ru.dbotthepony.mc.otm.capability.AndroidCapability;
|
||||
import ru.dbotthepony.mc.otm.capability.AndroidCapabilityPlayer;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
import ru.dbotthepony.mc.otm.client.AndroidGui;
|
||||
import ru.dbotthepony.mc.otm.menu.FormattingHelper;
|
||||
import ru.dbotthepony.mc.otm.network.MatteryNetwork;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
// The value here should match an entry in the META-INF/mods.toml file
|
||||
|
@ -21,7 +21,7 @@ public class MatteryCapability {
|
||||
CapabilityManager.INSTANCE.register(IMatteryEnergyStorage.class);
|
||||
}
|
||||
|
||||
public static final MathContext ROUND_RULES = new MathContext(16, RoundingMode.HALF_UP);
|
||||
public static final MathContext ROUND_RULES = new MathContext(24, RoundingMode.HALF_UP);
|
||||
|
||||
public static final BigDecimal INT_MAX_VALUE = new BigDecimal(Integer.MAX_VALUE);
|
||||
public static final BigDecimal INT_MIN_VALUE = new BigDecimal(Integer.MIN_VALUE);
|
||||
|
@ -1,5 +1,9 @@
|
||||
package ru.dbotthepony.mc.otm.item;
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
@ -13,6 +17,8 @@ import ru.dbotthepony.mc.otm.capability.AndroidCapabilityPlayer;
|
||||
import ru.dbotthepony.mc.otm.capability.IAndroidCapability;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ItemPill extends Item {
|
||||
@ -33,6 +39,18 @@ public class ItemPill extends Item {
|
||||
return 32;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack p_41421_, @Nullable Level p_41422_, List<Component> p_41423_, TooltipFlag p_41424_) {
|
||||
super.appendHoverText(p_41421_, p_41422_, p_41423_, p_41424_);
|
||||
|
||||
if (this.pill_type == PillType.BECOME_ANDROID)
|
||||
p_41423_.add(new TranslatableComponent("otm.pill.android").withStyle(ChatFormatting.GRAY));
|
||||
else
|
||||
p_41423_.add(new TranslatableComponent("otm.pill.humane").withStyle(ChatFormatting.GRAY));
|
||||
|
||||
p_41423_.add(new TranslatableComponent("otm.pill.warning").withStyle(ChatFormatting.RED));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level level, Player ply, InteractionHand hand) {
|
||||
if (ply instanceof FakePlayer)
|
||||
|
115
src/main/java/ru/dbotthepony/mc/otm/menu/FormattingHelper.java
Normal file
115
src/main/java/ru/dbotthepony/mc/otm/menu/FormattingHelper.java
Normal file
@ -0,0 +1,115 @@
|
||||
package ru.dbotthepony.mc.otm.menu;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
public class FormattingHelper {
|
||||
public static final String[] SUFFIX_COMPONENTS_ABOVE_ONE = new String[] {
|
||||
"otm.suffix.kilo",
|
||||
"otm.suffix.mega",
|
||||
"otm.suffix.giga",
|
||||
"otm.suffix.tera",
|
||||
"otm.suffix.peta",
|
||||
"otm.suffix.exa",
|
||||
"otm.suffix.zetta",
|
||||
"otm.suffix.yotta",
|
||||
};
|
||||
|
||||
public static final BigDecimal[] SUFFIX_ABOVE_ONE = new BigDecimal[] {
|
||||
new BigDecimal("1000"), // "otm.suffix.kilo": "k%s",
|
||||
new BigDecimal("1000000"), // "otm.suffix.mega": "M%s",
|
||||
new BigDecimal("1000000000"), // "otm.suffix.giga": "G%s",
|
||||
new BigDecimal("1000000000000"), // "otm.suffix.tera": "T%s",
|
||||
new BigDecimal("1000000000000000"), // "otm.suffix.peta": "P%s",
|
||||
new BigDecimal("1000000000000000000"), // "otm.suffix.exa": "E%s",
|
||||
new BigDecimal("1000000000000000000000"), // "otm.suffix.zetta": "Z%s",
|
||||
new BigDecimal("1000000000000000000000000"), // "otm.suffix.yotta": "Y%s",
|
||||
};
|
||||
|
||||
public static final String[] SUFFIX_COMPONENTS_BELOW_ONE = new String[] {
|
||||
"otm.suffix.milli",
|
||||
"otm.suffix.micro",
|
||||
"otm.suffix.nano",
|
||||
"otm.suffix.pico",
|
||||
"otm.suffix.femto",
|
||||
"otm.suffix.atto",
|
||||
"otm.suffix.zepto",
|
||||
"otm.suffix.yocto",
|
||||
};
|
||||
|
||||
public static final BigDecimal[] SUFFIX_BELOW_ONE = new BigDecimal[] {
|
||||
BigDecimal.ONE.divide(new BigDecimal("1000")), // "otm.suffix.milli": "m%s",
|
||||
BigDecimal.ONE.divide(new BigDecimal("1000000")), // "otm.suffix.micro": "μ%s",
|
||||
BigDecimal.ONE.divide(new BigDecimal("1000000000")), // "otm.suffix.nano": "n%s",
|
||||
BigDecimal.ONE.divide(new BigDecimal("1000000000000")), // "otm.suffix.pico": "p%s",
|
||||
BigDecimal.ONE.divide(new BigDecimal("1000000000000000")), // "otm.suffix.femto": "f%s",
|
||||
BigDecimal.ONE.divide(new BigDecimal("1000000000000000000")), // "otm.suffix.atto": "a%s",
|
||||
BigDecimal.ONE.divide(new BigDecimal("1000000000000000000000")), // "otm.suffix.zepto": "z%s",
|
||||
BigDecimal.ONE.divide(new BigDecimal("1000000000000000000000000")), // "otm.suffix.yocto": "y%s",
|
||||
};
|
||||
|
||||
public static String formatDecimal(BigDecimal value, int decimals) {
|
||||
return value.setScale(decimals, RoundingMode.HALF_UP).toString();
|
||||
}
|
||||
|
||||
public static final TranslatableComponent POWER_NAME = new TranslatableComponent("otm.gui.power.name");
|
||||
|
||||
public static Component formatPowerLevel(BigDecimal power, BigDecimal max_power) {
|
||||
return new TranslatableComponent("otm.gui.level", formatSI(power, POWER_NAME), formatSI(max_power, POWER_NAME));
|
||||
}
|
||||
|
||||
public static FormattedText formatSI(BigDecimal value) {
|
||||
return formatSI(value, "");
|
||||
}
|
||||
|
||||
public static FormattedText formatSI(BigDecimal value, Object end_suffix) {
|
||||
if (value.compareTo(BigDecimal.ZERO) == 0) {
|
||||
if ("".equals(end_suffix)) {
|
||||
return new TextComponent("0.00");
|
||||
} else {
|
||||
return new TranslatableComponent("otm.suffix.merge", "0.00", end_suffix);
|
||||
}
|
||||
}
|
||||
|
||||
int compare = value.compareTo(BigDecimal.ONE);
|
||||
|
||||
if (compare == 0) {
|
||||
if ("".equals(end_suffix)) {
|
||||
return new TextComponent("1.00");
|
||||
} else {
|
||||
return new TranslatableComponent("otm.suffix.merge", "1.00", end_suffix);
|
||||
}
|
||||
} else if (compare > 0) {
|
||||
for (int i = SUFFIX_ABOVE_ONE.length - 1; i >= 0; i--) {
|
||||
if (value.compareTo(SUFFIX_ABOVE_ONE[i]) >= 0) {
|
||||
return new TranslatableComponent(SUFFIX_COMPONENTS_ABOVE_ONE[i], formatDecimal(value.divide(SUFFIX_ABOVE_ONE[i]), 2), end_suffix);
|
||||
}
|
||||
}
|
||||
|
||||
if ("".equals(end_suffix)) {
|
||||
return new TextComponent(formatDecimal(value, 2));
|
||||
} else {
|
||||
return new TranslatableComponent("otm.suffix.merge", formatDecimal(value, 2), end_suffix);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = SUFFIX_BELOW_ONE.length - 1; i >= 0; i--) {
|
||||
if (value.compareTo(SUFFIX_BELOW_ONE[i]) < 0) {
|
||||
return new TranslatableComponent(SUFFIX_COMPONENTS_BELOW_ONE[i], formatDecimal(value.divide(SUFFIX_BELOW_ONE[i]), 2), end_suffix);
|
||||
}
|
||||
}
|
||||
|
||||
if ("".equals(end_suffix)) {
|
||||
return new TextComponent(formatDecimal(value, 2));
|
||||
} else {
|
||||
return new TranslatableComponent("otm.suffix.merge", formatDecimal(value, 2), end_suffix);
|
||||
}
|
||||
}
|
||||
}
|
@ -87,7 +87,7 @@ public class AndroidCapabilityChangePacket {
|
||||
context.get().setPacketHandled(true);
|
||||
|
||||
context.get().enqueueWork(() -> {
|
||||
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> ClientAndroidCapabilityChangePacketHandler.handlePacket(this, context));
|
||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> ClientAndroidCapabilityChangePacketHandler.handlePacket(this, context));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -7,17 +7,19 @@ import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
import ru.dbotthepony.mc.otm.menu.FormattingHelper;
|
||||
import ru.dbotthepony.mc.otm.menu.PoweredMachineMenu;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
public class PoweredMachineScreen<T extends PoweredMachineMenu> extends AbstractContainerScreen<T> {
|
||||
private static ResourceLocation CONTAINER_BACKGROUND = new ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/mattery_machine_base.png");
|
||||
private static final ResourceLocation CONTAINER_BACKGROUND = new ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/mattery_machine_base.png");
|
||||
|
||||
protected boolean auto_draw_gauge = true;
|
||||
protected int power_gauge_x = 13;
|
||||
@ -49,9 +51,9 @@ public class PoweredMachineScreen<T extends PoweredMachineMenu> extends Abstract
|
||||
level = energy.divide(max_energy, MatteryCapability.ROUND_RULES).floatValue();
|
||||
}
|
||||
|
||||
return List.of( // TODO: translation
|
||||
new TextComponent(String.format("Energy level: %.2f%%", level * 100d)),
|
||||
new TextComponent(String.format("%s / %s Mattery Energy", energy.toString(), max_energy.toString()))
|
||||
return List.of(
|
||||
new TranslatableComponent("otm.gui.power.percentage_level", String.format("%.2f", level * 100d)),
|
||||
FormattingHelper.formatPowerLevel(energy, max_energy)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,33 @@
|
||||
{
|
||||
"otm.pill.warning": "WARNING: This will INSTANTLY kill you upon ingestion!",
|
||||
"otm.pill.android": "Take this pill and lose what is holding your back.",
|
||||
"otm.pill.humane": "Take this pill and wake up in bed none the wiser.",
|
||||
"otm.gui.power.percentage_level": "Energy level: %s%%",
|
||||
"otm.gui.level": "%s / %s",
|
||||
"otm.gui.power.name": "MtE",
|
||||
|
||||
"otm.suffix.merge": "%s %s",
|
||||
|
||||
"otm.suffix.kilo": "%s k%s",
|
||||
"otm.suffix.mega": "%s M%s",
|
||||
"otm.suffix.giga": "%s G%s",
|
||||
"otm.suffix.tera": "%s T%s",
|
||||
"otm.suffix.peta": "%s P%s",
|
||||
"otm.suffix.exa": "%s E%s",
|
||||
"otm.suffix.zetta": "%s Z%s",
|
||||
"otm.suffix.yotta": "%s Y%s",
|
||||
|
||||
"otm.suffix.milli": "%s m%s",
|
||||
"otm.suffix.micro": "%s μ%s",
|
||||
"otm.suffix.nano": "%s n%s",
|
||||
"otm.suffix.pico": "%s p%s",
|
||||
"otm.suffix.femto": "%s f%s",
|
||||
"otm.suffix.atto": "%s a%s",
|
||||
"otm.suffix.zepto": "%s z%s",
|
||||
"otm.suffix.yocto": "%s y%s",
|
||||
|
||||
"container.otm.android_station": "Android station",
|
||||
"block.overdrive_that_matters.android_station": "Android station",
|
||||
"item.overdrive_that_matters.pill_android": "Android pill",
|
||||
"item.overdrive_that_matters.pill_humane": "Humane pill"
|
||||
}
|
Loading…
Reference in New Issue
Block a user