Skip to content

Commit aad2a43

Browse files
committed
Implement data-driven splicing table iota rendering
1 parent e91f50d commit aad2a43

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+765
-233
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package gay.object.hexdebug.api.client.splicing;
2+
3+
public enum SplicingTableIotaBackgroundType {
4+
GOLD,
5+
SLATE,
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package gay.object.hexdebug.api.client.splicing;
2+
3+
import net.minecraft.client.gui.GuiGraphics;
4+
import org.jetbrains.annotations.NotNull;
5+
6+
@FunctionalInterface
7+
public interface SplicingTableIotaRenderer {
8+
void render(@NotNull GuiGraphics guiGraphics, int x, int y);
9+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package gay.object.hexdebug.api.client.splicing;
2+
3+
import com.google.gson.Gson;
4+
import com.google.gson.JsonObject;
5+
import org.jetbrains.annotations.NotNull;
6+
import org.jetbrains.annotations.Nullable;
7+
8+
@FunctionalInterface
9+
public interface SplicingTableIotaRendererParser<T extends SplicingTableIotaRendererProvider> {
10+
/**
11+
* Attempts to parse the JSON data and return a provider for an iota renderer.
12+
* Throws {@link IllegalArgumentException} or {@link com.google.gson.JsonParseException} if
13+
* the input is invalid.
14+
*/
15+
@NotNull
16+
T parse(@NotNull Gson gson, @NotNull JsonObject jsonObject, @Nullable T parent);
17+
18+
/**
19+
* Creates a parser that always returns the given instance.
20+
*/
21+
@NotNull
22+
static <T extends SplicingTableIotaRendererProvider> SplicingTableIotaRendererParser<T> of(T instance) {
23+
return (gson, jsonObject, parent) -> instance;
24+
}
25+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package gay.object.hexdebug.api.client.splicing;
2+
3+
import at.petrak.hexcasting.api.casting.iota.IotaType;
4+
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes;
5+
import gay.object.hexdebug.api.splicing.SplicingTableIotaClientView;
6+
import gay.object.hexdebug.gui.splicing.SplicingTableScreen;
7+
import net.minecraft.network.chat.Component;
8+
import org.jetbrains.annotations.NotNull;
9+
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
13+
public interface SplicingTableIotaRendererProvider {
14+
/**
15+
* Creates and returns a new renderer for the provided iota.
16+
* <br>
17+
* This is called every time the splicing table changes which iotas are currently visible, so
18+
* don't do anything too laggy in here.
19+
*/
20+
@NotNull
21+
SplicingTableIotaRenderer createRenderer(
22+
@NotNull IotaType<?> type,
23+
@NotNull SplicingTableIotaClientView iota
24+
);
25+
26+
/**
27+
* Creates and returns a new tooltip for the provided iota.
28+
* <br>
29+
* This is called every time the splicing table changes which iotas are currently visible, so
30+
* don't do anything too laggy in here.
31+
*/
32+
@NotNull
33+
default SplicingTableIotaTooltip createTooltip(
34+
@NotNull IotaType<?> type,
35+
@NotNull SplicingTableIotaClientView iota,
36+
int index
37+
) {
38+
ArrayList<Component> advanced = new ArrayList<>();
39+
var typeKey = HexIotaTypes.REGISTRY.getKey(type);
40+
if (typeKey != null) {
41+
advanced.add(Component.literal(typeKey.toString()));
42+
}
43+
return new SplicingTableIotaTooltip(
44+
iota.name(),
45+
new ArrayList<>(),
46+
new ArrayList<>(List.of(SplicingTableScreen.tooltipText("index", index))),
47+
advanced,
48+
null
49+
);
50+
}
51+
52+
/**
53+
* Returns the background type for this renderer.
54+
*/
55+
@NotNull
56+
default SplicingTableIotaBackgroundType getBackgroundType(
57+
@NotNull IotaType<?> type,
58+
@NotNull SplicingTableIotaClientView iota
59+
) {
60+
return SplicingTableIotaBackgroundType.GOLD;
61+
}
62+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package gay.object.hexdebug.api.client.splicing;
2+
3+
import com.google.common.collect.Maps;
4+
import gay.object.hexdebug.HexDebug;
5+
import net.minecraft.resources.ResourceLocation;
6+
import org.jetbrains.annotations.ApiStatus;
7+
import org.jetbrains.annotations.NotNull;
8+
import org.jetbrains.annotations.Nullable;
9+
10+
import java.util.Map;
11+
12+
public final class SplicingTableIotaRenderers {
13+
private static final Map<ResourceLocation, SplicingTableIotaRendererParser<?>> PARSERS = Maps.newHashMap();
14+
15+
/**
16+
* Register a splicing table iota renderer.
17+
* <br>
18+
* This is used to parse resource files and create providers for iota renderers.
19+
*/
20+
public static void register(
21+
@NotNull ResourceLocation id,
22+
@NotNull SplicingTableIotaRendererParser<?> parser
23+
) {
24+
if (PARSERS.containsKey(id)) {
25+
HexDebug.LOGGER.warn("Overriding existing splicing table iota renderer parser: {}", id);
26+
}
27+
PARSERS.put(id, parser);
28+
}
29+
30+
@ApiStatus.Internal
31+
@Nullable
32+
public static SplicingTableIotaRendererParser<?> getParser(@NotNull ResourceLocation id) {
33+
return PARSERS.get(id);
34+
}
35+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package gay.object.hexdebug.api.client.splicing;
2+
3+
import net.minecraft.ChatFormatting;
4+
import net.minecraft.client.Minecraft;
5+
import net.minecraft.client.gui.components.Tooltip;
6+
import net.minecraft.network.chat.Component;
7+
import net.minecraft.network.chat.ComponentUtils;
8+
import org.jetbrains.annotations.NotNull;
9+
import org.jetbrains.annotations.Nullable;
10+
11+
import java.util.ArrayList;
12+
13+
public record SplicingTableIotaTooltip(
14+
@NotNull Component name,
15+
@NotNull ArrayList<Component> body,
16+
@NotNull ArrayList<Component> details,
17+
@NotNull ArrayList<Component> advanced,
18+
@Nullable Component narration
19+
) {
20+
public Tooltip build() {
21+
var lines = new ArrayList<Component>();
22+
lines.add(name);
23+
lines.addAll(body);
24+
for (var line : details) {
25+
lines.add(line.copy().withStyle(ChatFormatting.GRAY));
26+
}
27+
if (Minecraft.getInstance().options.advancedItemTooltips) {
28+
for (var line : advanced) {
29+
lines.add(line.copy().withStyle(ChatFormatting.DARK_GRAY));
30+
}
31+
}
32+
33+
var tooltipText = ComponentUtils.formatList(lines, Component.literal("\n"));
34+
if (narration != null) {
35+
return Tooltip.create(tooltipText, narration);
36+
}
37+
return Tooltip.create(tooltipText);
38+
}
39+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package gay.object.hexdebug.api.splicing;
2+
3+
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment;
4+
import at.petrak.hexcasting.api.casting.iota.Iota;
5+
import at.petrak.hexcasting.api.casting.iota.IotaType;
6+
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes;
7+
import gay.object.hexdebug.utils.ExtensionsKt;
8+
import net.minecraft.nbt.CompoundTag;
9+
import net.minecraft.nbt.Tag;
10+
import net.minecraft.network.chat.Component;
11+
import org.jetbrains.annotations.NotNull;
12+
import org.jetbrains.annotations.Nullable;
13+
14+
public record SplicingTableIotaClientView(
15+
@NotNull CompoundTag tag,
16+
@NotNull Component name,
17+
@NotNull String hexpatternSource
18+
) {
19+
public SplicingTableIotaClientView(@NotNull Iota iota, @NotNull CastingEnvironment env) {
20+
this(
21+
IotaType.serialize(iota),
22+
ExtensionsKt.displayWithPatternName(iota, env),
23+
ExtensionsKt.toHexpatternSource(iota, env)
24+
);
25+
}
26+
27+
@Nullable
28+
public Tag getData() {
29+
return tag.get(HexIotaTypes.KEY_DATA);
30+
}
31+
}

Common/src/main/kotlin/gay/object/hexdebug/HexDebugAbstractions.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package gay.`object`.hexdebug
55

66
import dev.architectury.injectables.annotations.ExpectPlatform
77
import gay.`object`.hexdebug.registry.HexDebugRegistrar
8+
import net.minecraft.resources.ResourceLocation
9+
import net.minecraft.server.packs.resources.PreparableReloadListener
810

911
fun initRegistries(vararg registries: HexDebugRegistrar<*>) {
1012
for (registry in registries) {
@@ -16,3 +18,8 @@ fun initRegistries(vararg registries: HexDebugRegistrar<*>) {
1618
fun <T : Any> initRegistry(registrar: HexDebugRegistrar<T>) {
1719
throw AssertionError()
1820
}
21+
22+
@ExpectPlatform
23+
fun registerClientResourceReloadListener(id: ResourceLocation, listener: PreparableReloadListener) {
24+
throw AssertionError()
25+
}

Common/src/main/kotlin/gay/object/hexdebug/HexDebugClient.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ import at.petrak.hexcasting.api.utils.gray
77
import at.petrak.hexcasting.api.utils.plusAssign
88
import gay.`object`.hexdebug.HexDebug.LOGGER
99
import gay.`object`.hexdebug.adapter.proxy.DebugProxyClient
10+
import gay.`object`.hexdebug.api.client.splicing.SplicingTableIotaRenderers
1011
import gay.`object`.hexdebug.blocks.focusholder.FocusHolderBlock
1112
import gay.`object`.hexdebug.config.HexDebugClientConfig
1213
import gay.`object`.hexdebug.config.HexDebugServerConfig
14+
import gay.`object`.hexdebug.gui.splicing.renderers.ListRendererProvider
15+
import gay.`object`.hexdebug.gui.splicing.renderers.PatternRendererProvider
16+
import gay.`object`.hexdebug.gui.splicing.renderers.TextureRendererProvider
1317
import gay.`object`.hexdebug.registry.HexDebugBlocks
18+
import gay.`object`.hexdebug.resources.splicing.SplicingTableIotasResourceReloadListener
1419
import gay.`object`.hexdebug.utils.styledHoverName
1520
import gay.`object`.hexdebug.utils.toComponent
1621
import me.shedaniel.autoconfig.AutoConfig
@@ -35,6 +40,8 @@ object HexDebugClient {
3540
HexDebugClientConfig.init()
3641
DebugProxyClient.init()
3742
addScryingLensOverlays()
43+
registerSplicingTableIotaRenderers()
44+
registerClientResourceReloadListener(HexDebug.id("splicing_iotas"), SplicingTableIotasResourceReloadListener)
3845
}
3946

4047
fun getConfigScreen(parent: Screen): Screen {
@@ -86,4 +93,10 @@ object HexDebugClient {
8693

8794
return MojangPair(stack, truncatedDisplay)
8895
}
96+
97+
private fun registerSplicingTableIotaRenderers() {
98+
SplicingTableIotaRenderers.register(HexDebug.id("list"), ListRendererProvider.PARSER)
99+
SplicingTableIotaRenderers.register(HexDebug.id("pattern"), PatternRendererProvider.PARSER)
100+
SplicingTableIotaRenderers.register(HexDebug.id("texture"), TextureRendererProvider.PARSER)
101+
}
89102
}

Common/src/main/kotlin/gay/object/hexdebug/blocks/splicing/SplicingTableBlockEntity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import at.petrak.hexcasting.api.pigment.FrozenPigment
1616
import at.petrak.hexcasting.api.utils.*
1717
import at.petrak.hexcasting.xplat.IXplatAbstractions
1818
import gay.`object`.hexdebug.api.HexDebugTags
19+
import gay.`object`.hexdebug.api.splicing.SplicingTableIotaClientView
1920
import gay.`object`.hexdebug.blocks.base.BaseContainer
2021
import gay.`object`.hexdebug.blocks.base.ContainerDataDelegate
2122
import gay.`object`.hexdebug.blocks.base.ContainerDataLongDelegate
@@ -201,7 +202,7 @@ class SplicingTableBlockEntity(pos: BlockPos, state: BlockState) :
201202
override fun getClientView() = getData(null)?.run {
202203
val env = FakeCastEnv(level)
203204
SplicingTableClientView(
204-
list = list?.map { IotaClientView(it, env) },
205+
list = list?.map { SplicingTableIotaClientView(it, env) },
205206
clipboard = clipboard?.let { IotaType.serialize(it) },
206207
isListWritable = listWriter != null,
207208
isClipboardWritable = clipboardWriter != null,

0 commit comments

Comments
 (0)