|
25 | 25 | import net.minecraft.component.DataComponentTypes; |
26 | 26 | import net.minecraft.component.type.*; |
27 | 27 | import net.minecraft.component.type.SuspiciousStewEffectsComponent.StewEffect; |
28 | | -import net.minecraft.entity.*; |
| 28 | +import net.minecraft.entity.Bucketable; |
| 29 | +import net.minecraft.entity.EntityType; |
| 30 | +import net.minecraft.entity.LivingEntity; |
| 31 | +import net.minecraft.entity.SpawnReason; |
29 | 32 | import net.minecraft.entity.effect.StatusEffectInstance; |
30 | 33 | import net.minecraft.entity.effect.StatusEffectUtil; |
31 | 34 | import net.minecraft.item.*; |
@@ -163,6 +166,14 @@ public class BetterTooltips extends Module { |
163 | 166 | .build() |
164 | 167 | ); |
165 | 168 |
|
| 169 | + private final Setting<SortSize> sizeType = sgOther.add(new EnumSetting.Builder<SortSize>() |
| 170 | + .name("byte-size-format") |
| 171 | + .description("The format by which to display the item's byte size.") |
| 172 | + .defaultValue(SortSize.Dynamic) |
| 173 | + .visible(byteSize::get) |
| 174 | + .build() |
| 175 | + ); |
| 176 | + |
166 | 177 | private final Setting<Boolean> statusEffects = sgOther.add(new BoolSetting.Builder() |
167 | 178 | .name("status-effects") |
168 | 179 | .description("Adds list of status effects to tooltips of food items.") |
@@ -233,19 +244,25 @@ private void appendTooltip(ItemStackTooltipEvent event) { |
233 | 244 | success.value().write(ByteCountDataOutput.INSTANCE); |
234 | 245 |
|
235 | 246 | int byteCount = ByteCountDataOutput.INSTANCE.getCount(); |
236 | | - String count; |
| 247 | + String count = switch (sizeType.get()) { |
| 248 | + case Bytes -> String.format("%d bytes", byteCount); |
| 249 | + case Kilobytes -> String.format("%.2f kB", byteCount / 1024f); |
| 250 | + case Megabytes -> String.format("%.4f MB", byteCount / 1048576f); |
| 251 | + case Dynamic -> { |
| 252 | + if (byteCount >= 1048576) yield String.format("%.2f MB", byteCount / 1048576f); |
| 253 | + else if (byteCount >= 1024) yield String.format("%.2f kB", byteCount / 1024f); |
| 254 | + else yield String.format("%d bytes", byteCount); |
| 255 | + } |
| 256 | + }; |
237 | 257 |
|
238 | 258 | ByteCountDataOutput.INSTANCE.reset(); |
239 | 259 |
|
240 | | - if (byteCount >= 1024) count = String.format("%.2f kb", byteCount / (float) 1024); |
241 | | - else count = String.format("%d bytes", byteCount); |
242 | | - |
243 | | - event.appendEnd(Text.literal(count).formatted(Formatting.GRAY)); |
| 260 | + event.appendEnd(Text.literal(count).formatted(Formatting.DARK_GRAY)); |
244 | 261 | } catch (Exception e) { |
245 | 262 | event.appendEnd(Text.literal("Error getting bytes.").formatted(Formatting.RED)); |
246 | 263 | } |
247 | 264 | } |
248 | | - case DataResult.Error<NbtElement> error -> |
| 265 | + case DataResult.Error<NbtElement> ignored -> |
249 | 266 | event.appendEnd(Text.literal("Error getting bytes.").formatted(Formatting.RED)); |
250 | 267 | default -> |
251 | 268 | throw new MatchException(null, null); |
@@ -441,4 +458,11 @@ public enum DisplayWhen { |
441 | 458 | Keybind, |
442 | 459 | Always |
443 | 460 | } |
| 461 | + |
| 462 | + public enum SortSize { |
| 463 | + Bytes, |
| 464 | + Kilobytes, |
| 465 | + Megabytes, |
| 466 | + Dynamic, |
| 467 | + } |
444 | 468 | } |
0 commit comments