-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved some tooltip classes around, added clear action
- Loading branch information
1 parent
6375e00
commit 383a24e
Showing
26 changed files
with
221 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/dev/latvian/mods/kubejs/text/action/AddTextAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Component> lines) implements TextAction { | ||
public static final TooltipActionType<AddTextAction> 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<Component> lines) { | ||
lines.addAll(this.lines); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/dev/latvian/mods/kubejs/text/action/ClearTextAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ClearTextAction> TYPE = new TooltipActionType<>(6, StreamCodec.unit(INSTANCE)); | ||
|
||
@Override | ||
public TooltipActionType<?> type() { | ||
return TYPE; | ||
} | ||
|
||
@Override | ||
public void apply(List<Component> lines) { | ||
lines.clear(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/dev/latvian/mods/kubejs/text/action/DynamicTextAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<DynamicTextAction> TYPE = new TooltipActionType<>(0, ByteBufCodecs.STRING_UTF8.map(DynamicTextAction::new, DynamicTextAction::id)); | ||
|
||
@Override | ||
public TooltipActionType<?> type() { | ||
return TYPE; | ||
} | ||
|
||
@Override | ||
public void apply(List<Component> lines) { | ||
lines.add(Component.literal("Not supported!").kjs$red()); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/dev/latvian/mods/kubejs/text/action/InsertTextAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Component> lines) implements TextAction { | ||
public static final TooltipActionType<InsertTextAction> 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<Component> lines) { | ||
lines.addAll(line, this.lines); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/dev/latvian/mods/kubejs/text/action/RemoveExactTextTextAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<RemoveExactTextTextAction> TYPE = new TooltipActionType<>(5, ComponentSerialization.STREAM_CODEC.map(RemoveExactTextTextAction::new, RemoveExactTextTextAction::match)); | ||
|
||
@Override | ||
public TooltipActionType<?> type() { | ||
return TYPE; | ||
} | ||
|
||
@Override | ||
public void apply(List<Component> lines) { | ||
lines.removeIf(match::equals); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/dev/latvian/mods/kubejs/text/action/RemoveLineTextAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<RemoveLineTextAction> TYPE = new TooltipActionType<>(3, ByteBufCodecs.VAR_INT.map(RemoveLineTextAction::new, RemoveLineTextAction::line)); | ||
|
||
@Override | ||
public TooltipActionType<?> type() { | ||
return TYPE; | ||
} | ||
|
||
@Override | ||
public void apply(List<Component> lines) { | ||
if (line >= 0 && line < lines.size()) { | ||
lines.remove(line); | ||
} | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
...oltip/action/RemoveTextTooltipAction.java → ...ejs/text/action/RemoveTextTextAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/dev/latvian/mods/kubejs/text/action/TextActionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TextAction> actions = new ArrayList<>(1); | ||
|
||
public void dynamic(String id) { | ||
actions.add(new DynamicTextAction(id)); | ||
} | ||
|
||
public void add(List<Component> text) { | ||
actions.add(new AddTextAction(text)); | ||
} | ||
|
||
public void insert(int line, List<Component> 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); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/dev/latvian/mods/kubejs/text/action/TooltipActionType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T extends TextAction>(int type, StreamCodec<? super RegistryFriendlyByteBuf, ? extends T> streamCodec) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.