From 383a24e3ffb83f9012904facd9aa13a1791ae888 Mon Sep 17 00:00:00 2001 From: LatvianModder Date: Wed, 24 Jul 2024 12:35:50 +0300 Subject: [PATCH] Moved some tooltip classes around, added clear action --- .../mods/kubejs/client/KubeJSClient.java | 2 +- .../client/KubeJSClientEventHandler.java | 8 ++-- .../mods/kubejs/client/KubeSessionData.java | 2 +- .../item/ModifyItemTooltipsKubeEvent.java | 22 ++++++---- .../kubejs/neoforge/KubeJSNeoForgeClient.java | 2 +- .../mods/kubejs/net/KubeServerData.java | 2 +- .../kubejs/text/action/AddTextAction.java | 21 +++++++++ .../kubejs/text/action/ClearTextAction.java | 21 +++++++++ .../kubejs/text/action/DynamicTextAction.java | 20 +++++++++ .../kubejs/text/action/InsertTextAction.java | 26 +++++++++++ .../action/RemoveExactTextTextAction.java | 20 +++++++++ .../text/action/RemoveLineTextAction.java | 22 ++++++++++ .../action/RemoveTextTextAction.java} | 10 ++--- .../action/TextAction.java} | 25 +++++------ .../kubejs/text/action/TextActionBuilder.java | 40 +++++++++++++++++ .../kubejs/text/action/TooltipActionType.java | 7 +++ .../{ => text}/tooltip/ItemTooltipData.java | 8 ++-- .../tooltip/TooltipRequirements.java | 2 +- .../tooltip/ItemStartupTooltipsKubeEvent.java | 9 ---- .../kubejs/tooltip/TooltipActionBuilder.java | 43 ------------------- .../tooltip/action/AddTooltipAction.java | 21 --------- .../tooltip/action/DynamicTooltipAction.java | 20 --------- .../tooltip/action/InsertTooltipAction.java | 26 ----------- .../action/RemoveExactTextTooltipAction.java | 20 --------- .../action/RemoveLineTooltipAction.java | 20 --------- .../tooltip/action/TooltipActionType.java | 7 --- 26 files changed, 221 insertions(+), 205 deletions(-) create mode 100644 src/main/java/dev/latvian/mods/kubejs/text/action/AddTextAction.java create mode 100644 src/main/java/dev/latvian/mods/kubejs/text/action/ClearTextAction.java create mode 100644 src/main/java/dev/latvian/mods/kubejs/text/action/DynamicTextAction.java create mode 100644 src/main/java/dev/latvian/mods/kubejs/text/action/InsertTextAction.java create mode 100644 src/main/java/dev/latvian/mods/kubejs/text/action/RemoveExactTextTextAction.java create mode 100644 src/main/java/dev/latvian/mods/kubejs/text/action/RemoveLineTextAction.java rename src/main/java/dev/latvian/mods/kubejs/{tooltip/action/RemoveTextTooltipAction.java => text/action/RemoveTextTextAction.java} (52%) rename src/main/java/dev/latvian/mods/kubejs/{tooltip/action/TooltipAction.java => text/action/TextAction.java} (57%) create mode 100644 src/main/java/dev/latvian/mods/kubejs/text/action/TextActionBuilder.java create mode 100644 src/main/java/dev/latvian/mods/kubejs/text/action/TooltipActionType.java rename src/main/java/dev/latvian/mods/kubejs/{ => text}/tooltip/ItemTooltipData.java (76%) rename src/main/java/dev/latvian/mods/kubejs/{ => text}/tooltip/TooltipRequirements.java (96%) delete mode 100644 src/main/java/dev/latvian/mods/kubejs/tooltip/ItemStartupTooltipsKubeEvent.java delete mode 100644 src/main/java/dev/latvian/mods/kubejs/tooltip/TooltipActionBuilder.java delete mode 100644 src/main/java/dev/latvian/mods/kubejs/tooltip/action/AddTooltipAction.java delete mode 100644 src/main/java/dev/latvian/mods/kubejs/tooltip/action/DynamicTooltipAction.java delete mode 100644 src/main/java/dev/latvian/mods/kubejs/tooltip/action/InsertTooltipAction.java delete mode 100644 src/main/java/dev/latvian/mods/kubejs/tooltip/action/RemoveExactTextTooltipAction.java delete mode 100644 src/main/java/dev/latvian/mods/kubejs/tooltip/action/RemoveLineTooltipAction.java delete mode 100644 src/main/java/dev/latvian/mods/kubejs/tooltip/action/TooltipActionType.java diff --git a/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClient.java b/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClient.java index fb8606a47..45d3981ba 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClient.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClient.java @@ -15,7 +15,7 @@ import dev.latvian.mods.kubejs.script.data.GeneratedData; import dev.latvian.mods.kubejs.script.data.GeneratedDataStage; import dev.latvian.mods.kubejs.script.data.VirtualAssetPack; -import dev.latvian.mods.kubejs.tooltip.ItemTooltipData; +import dev.latvian.mods.kubejs.text.tooltip.ItemTooltipData; import net.minecraft.SharedConstants; import net.minecraft.Util; import net.minecraft.client.Minecraft; diff --git a/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClientEventHandler.java b/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClientEventHandler.java index 6f3fc0c94..e2abc96e9 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClientEventHandler.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClientEventHandler.java @@ -10,9 +10,9 @@ import dev.latvian.mods.kubejs.kubedex.KubedexHighlight; import dev.latvian.mods.kubejs.script.ConsoleJS; import dev.latvian.mods.kubejs.script.ScriptType; -import dev.latvian.mods.kubejs.tooltip.ItemTooltipData; -import dev.latvian.mods.kubejs.tooltip.TooltipRequirements; -import dev.latvian.mods.kubejs.tooltip.action.DynamicTooltipAction; +import dev.latvian.mods.kubejs.text.action.DynamicTextAction; +import dev.latvian.mods.kubejs.text.tooltip.ItemTooltipData; +import dev.latvian.mods.kubejs.text.tooltip.TooltipRequirements; import dev.latvian.mods.kubejs.util.Tristate; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.ImageButton; @@ -118,7 +118,7 @@ public static boolean testRequirements(Minecraft mc, DynamicItemTooltipsKubeEven private static void handleItemTooltips(Minecraft mc, ItemTooltipData tooltip, DynamicItemTooltipsKubeEvent event) { if ((tooltip.filter().isEmpty() || tooltip.filter().get().test(event.item)) && (tooltip.requirements().isEmpty() || testRequirements(mc, event, tooltip.requirements().get()))) { for (var action : tooltip.actions()) { - if (action instanceof DynamicTooltipAction dynamic) { + if (action instanceof DynamicTextAction dynamic) { try { ItemEvents.DYNAMIC_TOOLTIPS.post(ScriptType.CLIENT, dynamic.id(), event); } catch (Exception ex) { diff --git a/src/main/java/dev/latvian/mods/kubejs/client/KubeSessionData.java b/src/main/java/dev/latvian/mods/kubejs/client/KubeSessionData.java index e0bba5846..00194de89 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/KubeSessionData.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/KubeSessionData.java @@ -4,7 +4,7 @@ import dev.latvian.mods.kubejs.net.KubeServerData; import dev.latvian.mods.kubejs.recipe.viewer.server.RecipeViewerData; import dev.latvian.mods.kubejs.recipe.viewer.server.RemoteRecipeViewerDataUpdatedEvent; -import dev.latvian.mods.kubejs.tooltip.ItemTooltipData; +import dev.latvian.mods.kubejs.text.tooltip.ItemTooltipData; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.resources.ResourceLocation; diff --git a/src/main/java/dev/latvian/mods/kubejs/item/ModifyItemTooltipsKubeEvent.java b/src/main/java/dev/latvian/mods/kubejs/item/ModifyItemTooltipsKubeEvent.java index 8b8ac2977..ed06539e4 100644 --- a/src/main/java/dev/latvian/mods/kubejs/item/ModifyItemTooltipsKubeEvent.java +++ b/src/main/java/dev/latvian/mods/kubejs/item/ModifyItemTooltipsKubeEvent.java @@ -1,9 +1,9 @@ package dev.latvian.mods.kubejs.item; import dev.latvian.mods.kubejs.event.KubeEvent; -import dev.latvian.mods.kubejs.tooltip.ItemTooltipData; -import dev.latvian.mods.kubejs.tooltip.TooltipActionBuilder; -import dev.latvian.mods.kubejs.tooltip.TooltipRequirements; +import dev.latvian.mods.kubejs.text.action.TextActionBuilder; +import dev.latvian.mods.kubejs.text.tooltip.ItemTooltipData; +import dev.latvian.mods.kubejs.text.tooltip.TooltipRequirements; import net.minecraft.network.chat.Component; import net.minecraft.world.item.crafting.Ingredient; import org.jetbrains.annotations.Nullable; @@ -19,29 +19,33 @@ public ModifyItemTooltipsKubeEvent(Consumer callback) { this.callback = callback; } - private void modify(@Nullable Ingredient filter, Optional requirements, Consumer consumer) { - var builder = new TooltipActionBuilder(); + private void modify(@Nullable Ingredient filter, Optional requirements, Consumer consumer) { + var builder = new TextActionBuilder(); consumer.accept(builder); callback.accept(new ItemTooltipData(filter == null || filter.isEmpty() || filter.kjs$isWildcard() ? Optional.empty() : Optional.of(filter), requirements, List.copyOf(builder.actions))); } - public void modify(Ingredient filter, TooltipRequirements requirements, Consumer consumer) { + public void modify(Ingredient filter, TooltipRequirements requirements, Consumer consumer) { modify(filter, Optional.ofNullable(requirements), consumer); } - public void modify(Ingredient filter, Consumer consumer) { + public void modify(Ingredient filter, Consumer consumer) { modify(filter, Optional.empty(), consumer); } - public void modifyAll(TooltipRequirements requirements, Consumer consumer) { + public void modifyAll(TooltipRequirements requirements, Consumer consumer) { modify(null, Optional.ofNullable(requirements), consumer); } - public void modifyAll(Consumer consumer) { + public void modifyAll(Consumer consumer) { modify(null, Optional.empty(), consumer); } public void add(Ingredient filter, List text) { modify(filter, builder -> builder.add(text)); } + + public void add(Ingredient filter, TooltipRequirements requirements, List text) { + modify(filter, requirements, builder -> builder.add(text)); + } } \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/neoforge/KubeJSNeoForgeClient.java b/src/main/java/dev/latvian/mods/kubejs/neoforge/KubeJSNeoForgeClient.java index 43454e4b6..1495e0c8e 100644 --- a/src/main/java/dev/latvian/mods/kubejs/neoforge/KubeJSNeoForgeClient.java +++ b/src/main/java/dev/latvian/mods/kubejs/neoforge/KubeJSNeoForgeClient.java @@ -24,7 +24,7 @@ import dev.latvian.mods.kubejs.kubedex.KubedexHighlight; import dev.latvian.mods.kubejs.registry.RegistryObjectStorage; import dev.latvian.mods.kubejs.script.ScriptType; -import dev.latvian.mods.kubejs.tooltip.ItemTooltipData; +import dev.latvian.mods.kubejs.text.tooltip.ItemTooltipData; import dev.latvian.mods.kubejs.util.ID; import net.minecraft.client.KeyMapping; import net.minecraft.client.renderer.ItemBlockRenderTypes; diff --git a/src/main/java/dev/latvian/mods/kubejs/net/KubeServerData.java b/src/main/java/dev/latvian/mods/kubejs/net/KubeServerData.java index 97a2359e5..aed94b67f 100644 --- a/src/main/java/dev/latvian/mods/kubejs/net/KubeServerData.java +++ b/src/main/java/dev/latvian/mods/kubejs/net/KubeServerData.java @@ -4,7 +4,7 @@ import dev.latvian.mods.kubejs.item.ModifyItemTooltipsKubeEvent; import dev.latvian.mods.kubejs.recipe.viewer.server.RecipeViewerData; import dev.latvian.mods.kubejs.script.ScriptType; -import dev.latvian.mods.kubejs.tooltip.ItemTooltipData; +import dev.latvian.mods.kubejs.text.tooltip.ItemTooltipData; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; diff --git a/src/main/java/dev/latvian/mods/kubejs/text/action/AddTextAction.java b/src/main/java/dev/latvian/mods/kubejs/text/action/AddTextAction.java new file mode 100644 index 000000000..942da3c16 --- /dev/null +++ b/src/main/java/dev/latvian/mods/kubejs/text/action/AddTextAction.java @@ -0,0 +1,21 @@ +package dev.latvian.mods.kubejs.text.action; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentSerialization; +import net.minecraft.network.codec.ByteBufCodecs; + +import java.util.List; + +public record AddTextAction(List lines) implements TextAction { + public static final TooltipActionType TYPE = new TooltipActionType<>(1, ComponentSerialization.STREAM_CODEC.apply(ByteBufCodecs.list()).map(AddTextAction::new, AddTextAction::lines)); + + @Override + public TooltipActionType type() { + return TYPE; + } + + @Override + public void apply(List lines) { + lines.addAll(this.lines); + } +} diff --git a/src/main/java/dev/latvian/mods/kubejs/text/action/ClearTextAction.java b/src/main/java/dev/latvian/mods/kubejs/text/action/ClearTextAction.java new file mode 100644 index 000000000..bf185c138 --- /dev/null +++ b/src/main/java/dev/latvian/mods/kubejs/text/action/ClearTextAction.java @@ -0,0 +1,21 @@ +package dev.latvian.mods.kubejs.text.action; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.codec.StreamCodec; + +import java.util.List; + +public record ClearTextAction() implements TextAction { + public static final ClearTextAction INSTANCE = new ClearTextAction(); + public static final TooltipActionType TYPE = new TooltipActionType<>(6, StreamCodec.unit(INSTANCE)); + + @Override + public TooltipActionType type() { + return TYPE; + } + + @Override + public void apply(List lines) { + lines.clear(); + } +} diff --git a/src/main/java/dev/latvian/mods/kubejs/text/action/DynamicTextAction.java b/src/main/java/dev/latvian/mods/kubejs/text/action/DynamicTextAction.java new file mode 100644 index 000000000..33d8acdc3 --- /dev/null +++ b/src/main/java/dev/latvian/mods/kubejs/text/action/DynamicTextAction.java @@ -0,0 +1,20 @@ +package dev.latvian.mods.kubejs.text.action; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.codec.ByteBufCodecs; + +import java.util.List; + +public record DynamicTextAction(String id) implements TextAction { + public static final TooltipActionType TYPE = new TooltipActionType<>(0, ByteBufCodecs.STRING_UTF8.map(DynamicTextAction::new, DynamicTextAction::id)); + + @Override + public TooltipActionType type() { + return TYPE; + } + + @Override + public void apply(List lines) { + lines.add(Component.literal("Not supported!").kjs$red()); + } +} diff --git a/src/main/java/dev/latvian/mods/kubejs/text/action/InsertTextAction.java b/src/main/java/dev/latvian/mods/kubejs/text/action/InsertTextAction.java new file mode 100644 index 000000000..64260daf1 --- /dev/null +++ b/src/main/java/dev/latvian/mods/kubejs/text/action/InsertTextAction.java @@ -0,0 +1,26 @@ +package dev.latvian.mods.kubejs.text.action; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentSerialization; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; + +import java.util.List; + +public record InsertTextAction(int line, List lines) implements TextAction { + public static final TooltipActionType TYPE = new TooltipActionType<>(2, StreamCodec.composite( + ByteBufCodecs.VAR_INT, InsertTextAction::line, + ComponentSerialization.STREAM_CODEC.apply(ByteBufCodecs.list()), InsertTextAction::lines, + InsertTextAction::new + )); + + @Override + public TooltipActionType type() { + return TYPE; + } + + @Override + public void apply(List lines) { + lines.addAll(line, this.lines); + } +} diff --git a/src/main/java/dev/latvian/mods/kubejs/text/action/RemoveExactTextTextAction.java b/src/main/java/dev/latvian/mods/kubejs/text/action/RemoveExactTextTextAction.java new file mode 100644 index 000000000..80e751476 --- /dev/null +++ b/src/main/java/dev/latvian/mods/kubejs/text/action/RemoveExactTextTextAction.java @@ -0,0 +1,20 @@ +package dev.latvian.mods.kubejs.text.action; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentSerialization; + +import java.util.List; + +public record RemoveExactTextTextAction(Component match) implements TextAction { + public static final TooltipActionType TYPE = new TooltipActionType<>(5, ComponentSerialization.STREAM_CODEC.map(RemoveExactTextTextAction::new, RemoveExactTextTextAction::match)); + + @Override + public TooltipActionType type() { + return TYPE; + } + + @Override + public void apply(List lines) { + lines.removeIf(match::equals); + } +} diff --git a/src/main/java/dev/latvian/mods/kubejs/text/action/RemoveLineTextAction.java b/src/main/java/dev/latvian/mods/kubejs/text/action/RemoveLineTextAction.java new file mode 100644 index 000000000..66fec8b5c --- /dev/null +++ b/src/main/java/dev/latvian/mods/kubejs/text/action/RemoveLineTextAction.java @@ -0,0 +1,22 @@ +package dev.latvian.mods.kubejs.text.action; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.codec.ByteBufCodecs; + +import java.util.List; + +public record RemoveLineTextAction(int line) implements TextAction { + public static final TooltipActionType TYPE = new TooltipActionType<>(3, ByteBufCodecs.VAR_INT.map(RemoveLineTextAction::new, RemoveLineTextAction::line)); + + @Override + public TooltipActionType type() { + return TYPE; + } + + @Override + public void apply(List lines) { + if (line >= 0 && line < lines.size()) { + lines.remove(line); + } + } +} diff --git a/src/main/java/dev/latvian/mods/kubejs/tooltip/action/RemoveTextTooltipAction.java b/src/main/java/dev/latvian/mods/kubejs/text/action/RemoveTextTextAction.java similarity index 52% rename from src/main/java/dev/latvian/mods/kubejs/tooltip/action/RemoveTextTooltipAction.java rename to src/main/java/dev/latvian/mods/kubejs/text/action/RemoveTextTextAction.java index c0c049a81..62c956b25 100644 --- a/src/main/java/dev/latvian/mods/kubejs/tooltip/action/RemoveTextTooltipAction.java +++ b/src/main/java/dev/latvian/mods/kubejs/text/action/RemoveTextTextAction.java @@ -1,4 +1,4 @@ -package dev.latvian.mods.kubejs.tooltip.action; +package dev.latvian.mods.kubejs.text.action; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.ComponentContents; @@ -6,8 +6,8 @@ import java.util.List; -public record RemoveTextTooltipAction(Component match) implements TooltipAction { - public static final TooltipActionType TYPE = new TooltipActionType<>(4, ComponentSerialization.STREAM_CODEC.map(RemoveTextTooltipAction::new, RemoveTextTooltipAction::match)); +public record RemoveTextTextAction(Component match) implements TextAction { + public static final TooltipActionType TYPE = new TooltipActionType<>(4, ComponentSerialization.STREAM_CODEC.map(RemoveTextTextAction::new, RemoveTextTextAction::match)); @Override public TooltipActionType type() { @@ -15,8 +15,8 @@ public TooltipActionType type() { } @Override - public void apply(List tooltip) { - tooltip.removeIf(component -> RemoveTextTooltipAction.equals(component, match.getContents())); + public void apply(List lines) { + lines.removeIf(component -> RemoveTextTextAction.equals(component, match.getContents())); } private static boolean equals(Component c, ComponentContents contents) { diff --git a/src/main/java/dev/latvian/mods/kubejs/tooltip/action/TooltipAction.java b/src/main/java/dev/latvian/mods/kubejs/text/action/TextAction.java similarity index 57% rename from src/main/java/dev/latvian/mods/kubejs/tooltip/action/TooltipAction.java rename to src/main/java/dev/latvian/mods/kubejs/text/action/TextAction.java index fac791b49..7e0fd94e7 100644 --- a/src/main/java/dev/latvian/mods/kubejs/tooltip/action/TooltipAction.java +++ b/src/main/java/dev/latvian/mods/kubejs/text/action/TextAction.java @@ -1,4 +1,4 @@ -package dev.latvian.mods.kubejs.tooltip.action; +package dev.latvian.mods.kubejs.text.action; import dev.latvian.mods.kubejs.util.Cast; import net.minecraft.network.RegistryFriendlyByteBuf; @@ -11,25 +11,26 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -public interface TooltipAction { +public interface TextAction { Map> MAP = Stream.of( - DynamicTooltipAction.TYPE, - AddTooltipAction.TYPE, - InsertTooltipAction.TYPE, - RemoveLineTooltipAction.TYPE, - RemoveTextTooltipAction.TYPE, - RemoveExactTextTooltipAction.TYPE + DynamicTextAction.TYPE, + AddTextAction.TYPE, + InsertTextAction.TYPE, + RemoveLineTextAction.TYPE, + RemoveTextTextAction.TYPE, + RemoveExactTextTextAction.TYPE, + ClearTextAction.TYPE ).collect(Collectors.toMap(TooltipActionType::type, Function.identity())); - StreamCodec STREAM_CODEC = new StreamCodec<>() { + StreamCodec STREAM_CODEC = new StreamCodec<>() { @Override - public TooltipAction decode(RegistryFriendlyByteBuf buf) { + public TextAction decode(RegistryFriendlyByteBuf buf) { int id = buf.readByte(); return MAP.get(id).streamCodec().decode(buf); } @Override - public void encode(RegistryFriendlyByteBuf buf, TooltipAction value) { + public void encode(RegistryFriendlyByteBuf buf, TextAction value) { buf.writeByte(value.type().type()); value.type().streamCodec().encode(buf, Cast.to(value)); } @@ -37,5 +38,5 @@ public void encode(RegistryFriendlyByteBuf buf, TooltipAction value) { TooltipActionType type(); - void apply(List tooltip); + void apply(List lines); } diff --git a/src/main/java/dev/latvian/mods/kubejs/text/action/TextActionBuilder.java b/src/main/java/dev/latvian/mods/kubejs/text/action/TextActionBuilder.java new file mode 100644 index 000000000..7cc13b67e --- /dev/null +++ b/src/main/java/dev/latvian/mods/kubejs/text/action/TextActionBuilder.java @@ -0,0 +1,40 @@ +package dev.latvian.mods.kubejs.text.action; + +import dev.latvian.mods.rhino.util.HideFromJS; +import net.minecraft.network.chat.Component; + +import java.util.ArrayList; +import java.util.List; + +public class TextActionBuilder { + @HideFromJS + public List actions = new ArrayList<>(1); + + public void dynamic(String id) { + actions.add(new DynamicTextAction(id)); + } + + public void add(List text) { + actions.add(new AddTextAction(text)); + } + + public void insert(int line, List text) { + actions.add(new InsertTextAction(line, text)); + } + + public void removeLine(int line) { + actions.add(new RemoveLineTextAction(line)); + } + + public void removeText(Component match) { + actions.add(new RemoveTextTextAction(match)); + } + + public void removeExactText(Component match) { + actions.add(new RemoveExactTextTextAction(match)); + } + + public void clear() { + actions.add(ClearTextAction.INSTANCE); + } +} diff --git a/src/main/java/dev/latvian/mods/kubejs/text/action/TooltipActionType.java b/src/main/java/dev/latvian/mods/kubejs/text/action/TooltipActionType.java new file mode 100644 index 000000000..ee5f907e8 --- /dev/null +++ b/src/main/java/dev/latvian/mods/kubejs/text/action/TooltipActionType.java @@ -0,0 +1,7 @@ +package dev.latvian.mods.kubejs.text.action; + +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; + +public record TooltipActionType(int type, StreamCodec streamCodec) { +} diff --git a/src/main/java/dev/latvian/mods/kubejs/tooltip/ItemTooltipData.java b/src/main/java/dev/latvian/mods/kubejs/text/tooltip/ItemTooltipData.java similarity index 76% rename from src/main/java/dev/latvian/mods/kubejs/tooltip/ItemTooltipData.java rename to src/main/java/dev/latvian/mods/kubejs/text/tooltip/ItemTooltipData.java index 812b3ac06..8d32a1203 100644 --- a/src/main/java/dev/latvian/mods/kubejs/tooltip/ItemTooltipData.java +++ b/src/main/java/dev/latvian/mods/kubejs/text/tooltip/ItemTooltipData.java @@ -1,6 +1,6 @@ -package dev.latvian.mods.kubejs.tooltip; +package dev.latvian.mods.kubejs.text.tooltip; -import dev.latvian.mods.kubejs.tooltip.action.TooltipAction; +import dev.latvian.mods.kubejs.text.action.TextAction; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; @@ -12,12 +12,12 @@ public record ItemTooltipData( Optional filter, Optional requirements, - List actions + List actions ) { public static final StreamCodec STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.optional(Ingredient.CONTENTS_STREAM_CODEC), ItemTooltipData::filter, ByteBufCodecs.optional(TooltipRequirements.STREAM_CODEC), ItemTooltipData::requirements, - TooltipAction.STREAM_CODEC.apply(ByteBufCodecs.list()), ItemTooltipData::actions, + TextAction.STREAM_CODEC.apply(ByteBufCodecs.list()), ItemTooltipData::actions, ItemTooltipData::new ); } diff --git a/src/main/java/dev/latvian/mods/kubejs/tooltip/TooltipRequirements.java b/src/main/java/dev/latvian/mods/kubejs/text/tooltip/TooltipRequirements.java similarity index 96% rename from src/main/java/dev/latvian/mods/kubejs/tooltip/TooltipRequirements.java rename to src/main/java/dev/latvian/mods/kubejs/text/tooltip/TooltipRequirements.java index cee2e4f6c..07685af99 100644 --- a/src/main/java/dev/latvian/mods/kubejs/tooltip/TooltipRequirements.java +++ b/src/main/java/dev/latvian/mods/kubejs/text/tooltip/TooltipRequirements.java @@ -1,4 +1,4 @@ -package dev.latvian.mods.kubejs.tooltip; +package dev.latvian.mods.kubejs.text.tooltip; import dev.latvian.mods.kubejs.util.Tristate; import net.minecraft.network.RegistryFriendlyByteBuf; diff --git a/src/main/java/dev/latvian/mods/kubejs/tooltip/ItemStartupTooltipsKubeEvent.java b/src/main/java/dev/latvian/mods/kubejs/tooltip/ItemStartupTooltipsKubeEvent.java deleted file mode 100644 index ae7201f23..000000000 --- a/src/main/java/dev/latvian/mods/kubejs/tooltip/ItemStartupTooltipsKubeEvent.java +++ /dev/null @@ -1,9 +0,0 @@ -package dev.latvian.mods.kubejs.tooltip; - -import dev.latvian.mods.kubejs.event.KubeStartupEvent; -import dev.latvian.mods.kubejs.item.ItemPredicate; - -public class ItemStartupTooltipsKubeEvent implements KubeStartupEvent { - public void modify(ItemPredicate filter) { - } -} diff --git a/src/main/java/dev/latvian/mods/kubejs/tooltip/TooltipActionBuilder.java b/src/main/java/dev/latvian/mods/kubejs/tooltip/TooltipActionBuilder.java deleted file mode 100644 index 5a17abecd..000000000 --- a/src/main/java/dev/latvian/mods/kubejs/tooltip/TooltipActionBuilder.java +++ /dev/null @@ -1,43 +0,0 @@ -package dev.latvian.mods.kubejs.tooltip; - -import dev.latvian.mods.kubejs.tooltip.action.AddTooltipAction; -import dev.latvian.mods.kubejs.tooltip.action.DynamicTooltipAction; -import dev.latvian.mods.kubejs.tooltip.action.InsertTooltipAction; -import dev.latvian.mods.kubejs.tooltip.action.RemoveExactTextTooltipAction; -import dev.latvian.mods.kubejs.tooltip.action.RemoveLineTooltipAction; -import dev.latvian.mods.kubejs.tooltip.action.RemoveTextTooltipAction; -import dev.latvian.mods.kubejs.tooltip.action.TooltipAction; -import dev.latvian.mods.rhino.util.HideFromJS; -import net.minecraft.network.chat.Component; - -import java.util.ArrayList; -import java.util.List; - -public class TooltipActionBuilder { - @HideFromJS - public List actions = new ArrayList<>(1); - - public void dynamic(String id) { - actions.add(new DynamicTooltipAction(id)); - } - - public void add(List text) { - actions.add(new AddTooltipAction(text)); - } - - public void insert(int line, List text) { - actions.add(new InsertTooltipAction(line, text)); - } - - public void removeLine(int line) { - actions.add(new RemoveLineTooltipAction(line)); - } - - public void removeText(Component match) { - actions.add(new RemoveTextTooltipAction(match)); - } - - public void removeExactText(Component match) { - actions.add(new RemoveExactTextTooltipAction(match)); - } -} diff --git a/src/main/java/dev/latvian/mods/kubejs/tooltip/action/AddTooltipAction.java b/src/main/java/dev/latvian/mods/kubejs/tooltip/action/AddTooltipAction.java deleted file mode 100644 index d331ae306..000000000 --- a/src/main/java/dev/latvian/mods/kubejs/tooltip/action/AddTooltipAction.java +++ /dev/null @@ -1,21 +0,0 @@ -package dev.latvian.mods.kubejs.tooltip.action; - -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.ComponentSerialization; -import net.minecraft.network.codec.ByteBufCodecs; - -import java.util.List; - -public record AddTooltipAction(List lines) implements TooltipAction { - public static final TooltipActionType TYPE = new TooltipActionType<>(1, ComponentSerialization.STREAM_CODEC.apply(ByteBufCodecs.list()).map(AddTooltipAction::new, AddTooltipAction::lines)); - - @Override - public TooltipActionType type() { - return TYPE; - } - - @Override - public void apply(List tooltip) { - tooltip.addAll(lines); - } -} diff --git a/src/main/java/dev/latvian/mods/kubejs/tooltip/action/DynamicTooltipAction.java b/src/main/java/dev/latvian/mods/kubejs/tooltip/action/DynamicTooltipAction.java deleted file mode 100644 index 5cdc5b56a..000000000 --- a/src/main/java/dev/latvian/mods/kubejs/tooltip/action/DynamicTooltipAction.java +++ /dev/null @@ -1,20 +0,0 @@ -package dev.latvian.mods.kubejs.tooltip.action; - -import net.minecraft.network.chat.Component; -import net.minecraft.network.codec.ByteBufCodecs; - -import java.util.List; - -public record DynamicTooltipAction(String id) implements TooltipAction { - public static final TooltipActionType TYPE = new TooltipActionType<>(0, ByteBufCodecs.STRING_UTF8.map(DynamicTooltipAction::new, DynamicTooltipAction::id)); - - @Override - public TooltipActionType type() { - return TYPE; - } - - @Override - public void apply(List tooltip) { - tooltip.add(Component.literal("Dynamic tooltip is not supported!").kjs$red()); - } -} diff --git a/src/main/java/dev/latvian/mods/kubejs/tooltip/action/InsertTooltipAction.java b/src/main/java/dev/latvian/mods/kubejs/tooltip/action/InsertTooltipAction.java deleted file mode 100644 index 358536fcf..000000000 --- a/src/main/java/dev/latvian/mods/kubejs/tooltip/action/InsertTooltipAction.java +++ /dev/null @@ -1,26 +0,0 @@ -package dev.latvian.mods.kubejs.tooltip.action; - -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.ComponentSerialization; -import net.minecraft.network.codec.ByteBufCodecs; -import net.minecraft.network.codec.StreamCodec; - -import java.util.List; - -public record InsertTooltipAction(int line, List lines) implements TooltipAction { - public static final TooltipActionType TYPE = new TooltipActionType<>(2, StreamCodec.composite( - ByteBufCodecs.VAR_INT, InsertTooltipAction::line, - ComponentSerialization.STREAM_CODEC.apply(ByteBufCodecs.list()), InsertTooltipAction::lines, - InsertTooltipAction::new - )); - - @Override - public TooltipActionType type() { - return TYPE; - } - - @Override - public void apply(List tooltip) { - tooltip.addAll(line, lines); - } -} diff --git a/src/main/java/dev/latvian/mods/kubejs/tooltip/action/RemoveExactTextTooltipAction.java b/src/main/java/dev/latvian/mods/kubejs/tooltip/action/RemoveExactTextTooltipAction.java deleted file mode 100644 index 8750564d3..000000000 --- a/src/main/java/dev/latvian/mods/kubejs/tooltip/action/RemoveExactTextTooltipAction.java +++ /dev/null @@ -1,20 +0,0 @@ -package dev.latvian.mods.kubejs.tooltip.action; - -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.ComponentSerialization; - -import java.util.List; - -public record RemoveExactTextTooltipAction(Component match) implements TooltipAction { - public static final TooltipActionType TYPE = new TooltipActionType<>(5, ComponentSerialization.STREAM_CODEC.map(RemoveExactTextTooltipAction::new, RemoveExactTextTooltipAction::match)); - - @Override - public TooltipActionType type() { - return TYPE; - } - - @Override - public void apply(List tooltip) { - tooltip.removeIf(match::equals); - } -} diff --git a/src/main/java/dev/latvian/mods/kubejs/tooltip/action/RemoveLineTooltipAction.java b/src/main/java/dev/latvian/mods/kubejs/tooltip/action/RemoveLineTooltipAction.java deleted file mode 100644 index 3849ead90..000000000 --- a/src/main/java/dev/latvian/mods/kubejs/tooltip/action/RemoveLineTooltipAction.java +++ /dev/null @@ -1,20 +0,0 @@ -package dev.latvian.mods.kubejs.tooltip.action; - -import net.minecraft.network.chat.Component; -import net.minecraft.network.codec.ByteBufCodecs; - -import java.util.List; - -public record RemoveLineTooltipAction(int line) implements TooltipAction { - public static final TooltipActionType TYPE = new TooltipActionType<>(3, ByteBufCodecs.VAR_INT.map(RemoveLineTooltipAction::new, RemoveLineTooltipAction::line)); - - @Override - public TooltipActionType type() { - return TYPE; - } - - @Override - public void apply(List tooltip) { - tooltip.remove(line); - } -} diff --git a/src/main/java/dev/latvian/mods/kubejs/tooltip/action/TooltipActionType.java b/src/main/java/dev/latvian/mods/kubejs/tooltip/action/TooltipActionType.java deleted file mode 100644 index 00dbcb510..000000000 --- a/src/main/java/dev/latvian/mods/kubejs/tooltip/action/TooltipActionType.java +++ /dev/null @@ -1,7 +0,0 @@ -package dev.latvian.mods.kubejs.tooltip.action; - -import net.minecraft.network.RegistryFriendlyByteBuf; -import net.minecraft.network.codec.StreamCodec; - -public record TooltipActionType(int type, StreamCodec streamCodec) { -}