aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java')
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java b/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java
index 8218f71..8e3c31b 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java
@@ -1,12 +1,26 @@
package com.anthonyhilyard.iceberg;
+import java.util.List;
+
+import com.anthonyhilyard.iceberg.events.RenderTooltipEvents;
+import com.anthonyhilyard.iceberg.events.RenderTooltipEvents.GatherResult;
+import com.anthonyhilyard.iceberg.util.Tooltips.TitleBreakComponent;
+import com.mojang.datafixers.util.Either;
+
import net.fabricmc.api.ClientModInitializer;
+import net.minecraft.network.chat.FormattedText;
+import net.minecraft.world.InteractionResult;
+import net.minecraft.world.inventory.tooltip.TooltipComponent;
+import net.minecraft.world.item.ItemStack;
public class IcebergClient implements ClientModInitializer
{
@Override
public void onInitializeClient()
{
+ TitleBreakComponent.registerFactory();
+ RenderTooltipEvents.GATHER.register(IcebergClient::onGatherComponentsEventEnd);
+
// Event testing.
// CriterionCallback.EVENT.register((player, advancement, criterion) -> { Loader.LOGGER.info("CriterionCallback: {}, {}, {}", player.getName().getString(), advancement.getId().toString(), criterion); });
// NewItemPickupCallback.EVENT.register((uuid, itemStack) -> { Loader.LOGGER.info("NewItemPickupCallback: {}, {}", uuid.toString(), itemStack.getDisplayName().getString()); });
@@ -23,4 +37,22 @@ public class IcebergClient implements ClientModInitializer
// Loader.LOGGER.info("RenderTooltipEvents.POST: {}, {}, {}, {}, {}, {}, {}, {}, {}", stack.getDisplayName().getString(), components.stream().map(Object::toString).collect(Collectors.joining()), poseStack, x, y, font, width, height, comparison);
// });
}
+
+ public static GatherResult onGatherComponentsEventEnd(ItemStack itemStack, int screenWidth, int screenHeight, List<Either<FormattedText, TooltipComponent>> tooltipElements, int maxWidth, int index)
+ {
+ if (tooltipElements.size() > 1)
+ {
+ // Insert a title break component after the first formattedText component.
+ for (int i = 0; i < tooltipElements.size(); i++)
+ {
+ if (tooltipElements.get(i).left().isPresent())
+ {
+ tooltipElements.add(i + 1, Either.<FormattedText, TooltipComponent>right(new TitleBreakComponent()));
+ break;
+ }
+ }
+ }
+
+ return new GatherResult(InteractionResult.PASS, maxWidth, tooltipElements);
+ }
}