Skip to content

Commit d64f44f

Browse files
committed
Fix static initializers
1 parent ec211d6 commit d64f44f

11 files changed

Lines changed: 152 additions & 33 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Changes:
22

33
* Fixed missing explicit dependencies on fabric.
4+
* Fixed some class initializer orders that would cause GraphLib-Syncing-KNet to have null fields.

modules/syncing-knet-xplat/src/main/java/com/kneelawk/graphlib/syncing/knet/api/SyncingKNet.java

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import com.kneelawk.graphlib.syncing.knet.api.graph.user.LinkEntitySyncing;
5454
import com.kneelawk.graphlib.syncing.knet.api.graph.user.LinkKeySyncing;
5555
import com.kneelawk.graphlib.syncing.knet.api.graph.user.NodeEntitySyncing;
56+
import com.kneelawk.graphlib.syncing.knet.api.util.IdPaletteUtils;
5657
import com.kneelawk.graphlib.syncing.knet.api.util.InSyncedUniverse;
5758
import com.kneelawk.graphlib.syncing.knet.impl.StreamCodecHelper;
5859
import com.kneelawk.knet.api.channel.context.PlayChannelContext;
@@ -74,69 +75,79 @@ private SyncingKNet() {}
7475

7576
/**
7677
* Attachment key for a palette of {@link ResourceLocation}s.
78+
*
79+
* @deprecated use {@link IdPaletteUtils#ID_PALETTE} instead.
7780
*/
78-
public static final AttachmentKey<Palette<ResourceLocation>> ID_PALETTE = AttachmentKey.ofStaticFieldName();
81+
@Deprecated
82+
public static final AttachmentKey<Palette<ResourceLocation>> ID_PALETTE = IdPaletteUtils.ID_PALETTE;
7983

8084
/**
81-
* {@link ResourceLocation} codec that can use an {@link #ID_PALETTE} attachment if present.
85+
* {@link ResourceLocation} codec that can use an {@link IdPaletteUtils#ID_PALETTE} attachment if present.
86+
*
87+
* @deprecated use {@link IdPaletteUtils#PALETTED_ID_CODEC} instead.
8288
*/
89+
@Deprecated
8390
public static final StreamCodec<FriendlyByteBuf, ResourceLocation> PALETTED_ID_CODEC =
84-
ID_PALETTE.dispatchIfPresentStreamCodec(palette -> palette.asCodec("id palette"),
85-
ResourceLocation.STREAM_CODEC);
91+
IdPaletteUtils.PALETTED_ID_CODEC;
8692

8793
/**
8894
* Wraps the given {@link StreamCodec} codec in a palette that will be used in both encoding and decoding.
8995
* <p>
90-
* This provides the {@link #ID_PALETTE} attachment.
96+
* This provides the {@link IdPaletteUtils#ID_PALETTE} attachment.
9197
*
9298
* @param wrappedCodec the codec to wrap.
9399
* @param childBufferCtor the constructor for the buffer type the wrapped codec uses.
94100
* @param <B1> the type of the parent buffer.
95101
* @param <B2> the type of the child buffer.
96102
* @param <V> the result type.
97103
* @return the wrapper stream codec.
104+
* @deprecated use {@link IdPaletteUtils#attachPalette(StreamCodec, ChildBufferFactory)} instead.
98105
*/
106+
@Deprecated
99107
public static <B1 extends FriendlyByteBuf & NetBuf<B1>, B2 extends FriendlyByteBuf, V> StreamCodec<B1, V> attachPalette(
100108
StreamCodec<? super B2, V> wrappedCodec, ChildBufferFactory<? super B1, B2> childBufferCtor) {
101-
return ID_PALETTE.mutReadAttachingStreamCodec(Palette.codec(ResourceLocation.STREAM_CODEC), childBufferCtor,
102-
wrappedCodec, obj -> new Palette<>());
109+
return IdPaletteUtils.<B1, B2, V>attachPalette(wrappedCodec, childBufferCtor);
103110
}
104111

105112
/**
106113
* Wraps the given {@link StreamCodec} codec in a palette that will be used in both encoding and decoding, using a
107114
* buffer capable of being used as a {@link net.minecraft.network.RegistryFriendlyByteBuf}.
108115
* <p>
109-
* This provides the {@link #ID_PALETTE} attachment.
116+
* This provides the {@link IdPaletteUtils#ID_PALETTE} attachment.
110117
*
111118
* @param wrappedCodec the codec to wrap.
112119
* @param <V> the result type.
113120
* @return the wrapper stream codec.
121+
* @deprecated use {@link IdPaletteUtils#registryAttachPalette(StreamCodec)} instead.
114122
*/
123+
@Deprecated
115124
public static <V> StreamCodec<NetRegistryByteBuf, V> registryAttachPalette(
116125
StreamCodec<? super NetRegistryByteBuf, V> wrappedCodec) {
117-
return attachPalette(wrappedCodec, (cap, old) -> NetBufs.netRegistryBuf(cap, old.registryAccess()));
126+
return IdPaletteUtils.registryAttachPalette(wrappedCodec);
118127
}
119128

120129
/**
121130
* Wraps the given {@link StreamCodec} codec in a palette that will be used in both encoding and decoding, using a
122131
* buffer capable of being used as a {@link NetByteBuf}.
123132
* <p>
124-
* This provides the {@link #ID_PALETTE} attachment.
133+
* This provides the {@link IdPaletteUtils#ID_PALETTE} attachment.
125134
*
126135
* @param wrappedCodec the codec to wrap.
127136
* @param <V> the result type.
128137
* @return the wrapper stream codec.
138+
* @deprecated use {@link IdPaletteUtils#netAttachPalette(StreamCodec)} instead.
129139
*/
140+
@Deprecated
130141
public static <V> StreamCodec<NetRegistryByteBuf, V> netAttachPalette(
131142
StreamCodec<? super RegistryNetByteBuf, V> wrappedCodec) {
132-
return attachPalette(wrappedCodec, (cap, old) -> NetBufs.registryNetBuf(cap, old.registryAccess()));
143+
return IdPaletteUtils.netAttachPalette(wrappedCodec);
133144
}
134145

135146
/**
136147
* Stream codec that encodes/decodes an entire {@link BlockNode}.
137148
* <p>
138149
* <b>This requires the {@link KNetSyncedUniverse#ATTACHMENT_KEY} attachment.</b>
139-
* This can optionally make use of the {@link SyncingKNet#ID_PALETTE} attachment.
150+
* This can optionally make use of the {@link IdPaletteUtils#ID_PALETTE} attachment.
140151
*/
141152
public static final StreamCodec<NetRegistryByteBuf, BlockNode> BLOCK_NODE_CODEC =
142153
StreamCodecHelper.createObjStreamCodec(BlockNodeSyncing.REF_CODEC, BlockNode::getType,
@@ -146,7 +157,7 @@ public static <V> StreamCodec<NetRegistryByteBuf, V> netAttachPalette(
146157
* Stream codec that encodes/decodes an entire {@link LinkKey}.
147158
* <p>
148159
* <b>This requires the {@link KNetSyncedUniverse#ATTACHMENT_KEY} attachment.</b>
149-
* This can optionally make use of the {@link SyncingKNet#ID_PALETTE} attachment.
160+
* This can optionally make use of the {@link IdPaletteUtils#ID_PALETTE} attachment.
150161
*/
151162
public static final StreamCodec<NetRegistryByteBuf, LinkKey> LINK_KEY_CODEC =
152163
StreamCodecHelper.createObjStreamCodec(LinkKeySyncing.REF_CODEC, LinkKey::getType,
@@ -156,7 +167,7 @@ public static <V> StreamCodec<NetRegistryByteBuf, V> netAttachPalette(
156167
* Stream codec that encodes/decodes an entire {@link NodeEntity}.
157168
* <p>
158169
* <b>This requires the {@link KNetSyncedUniverse#ATTACHMENT_KEY} attachment.</b>
159-
* This can optionally make use of the {@link SyncingKNet#ID_PALETTE} attachment.
170+
* This can optionally make use of the {@link IdPaletteUtils#ID_PALETTE} attachment.
160171
*/
161172
public static final StreamCodec<NetRegistryByteBuf, NodeEntity> NODE_ENTITY_CODEC =
162173
StreamCodecHelper.createObjStreamCodec(NodeEntitySyncing.REF_CODEC, NodeEntity::getType,
@@ -166,7 +177,7 @@ public static <V> StreamCodec<NetRegistryByteBuf, V> netAttachPalette(
166177
* Stream codec that encodes/decodes an entire {@link LinkEntity}.
167178
* <p>
168179
* <b>This requires the {@link KNetSyncedUniverse#ATTACHMENT_KEY} attachment.</b>
169-
* This can optionally make use of the {@link SyncingKNet#ID_PALETTE} attachment.
180+
* This can optionally make use of the {@link IdPaletteUtils#ID_PALETTE} attachment.
170181
*/
171182
public static final StreamCodec<NetRegistryByteBuf, LinkEntity> LINK_ENTITY_CODEC =
172183
StreamCodecHelper.createObjStreamCodec(LinkEntitySyncing.REF_CODEC, LinkEntity::getType,
@@ -176,7 +187,7 @@ public static <V> StreamCodec<NetRegistryByteBuf, V> netAttachPalette(
176187
* Stream codec that encodes/decodes an entire {@link GraphEntity}.
177188
* <p>
178189
* <b>This requires the {@link KNetSyncedUniverse#ATTACHMENT_KEY} attachment.</b>
179-
* This can optionally make use of the {@link SyncingKNet#ID_PALETTE} attachment.
190+
* This can optionally make use of the {@link IdPaletteUtils#ID_PALETTE} attachment.
180191
*/
181192
public static final StreamCodec<NetRegistryByteBuf, GraphEntity<?>> GRAPH_ENTITY_CODEC =
182193
StreamCodecHelper.createObjStreamCodec(GraphEntitySyncing.REF_CODEC, GraphEntity::getType,
@@ -186,7 +197,7 @@ public static <V> StreamCodec<NetRegistryByteBuf, V> netAttachPalette(
186197
* Stream codec for a {@link NodePos}.
187198
* <p>
188199
* <b>This requires the {@link KNetSyncedUniverse#ATTACHMENT_KEY} attachment.</b>
189-
* This can optionally make use of the {@link SyncingKNet#ID_PALETTE} attachment.
200+
* This can optionally make use of the {@link IdPaletteUtils#ID_PALETTE} attachment.
190201
*/
191202
public static final StreamCodec<NetRegistryByteBuf, NodePos> NODE_POS_CODEC =
192203
StreamCodec.composite(NetCodecs.BLOCK_POS.mapStream(NetBufs::netOf), NodePos::pos, BLOCK_NODE_CODEC,
@@ -196,7 +207,7 @@ public static <V> StreamCodec<NetRegistryByteBuf, V> netAttachPalette(
196207
* Stream codec for a {@link LinkPos}.
197208
* <p>
198209
* <b>This requires the {@link KNetSyncedUniverse#ATTACHMENT_KEY} attachment.</b>
199-
* This can optionally make use of the {@link SyncingKNet#ID_PALETTE} attachment.
210+
* This can optionally make use of the {@link IdPaletteUtils#ID_PALETTE} attachment.
200211
*/
201212
public static final StreamCodec<NetRegistryByteBuf, LinkPos> LINK_POS_CODEC =
202213
StreamCodec.composite(NODE_POS_CODEC, LinkPos::first, NODE_POS_CODEC, LinkPos::second, LINK_KEY_CODEC,

modules/syncing-knet-xplat/src/main/java/com/kneelawk/graphlib/syncing/knet/api/graph/KNetSyncedUniverse.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import com.kneelawk.graphlib.syncing.knet.api.graph.user.LinkEntitySyncing;
5656
import com.kneelawk.graphlib.syncing.knet.api.graph.user.LinkKeySyncing;
5757
import com.kneelawk.graphlib.syncing.knet.api.graph.user.NodeEntitySyncing;
58+
import com.kneelawk.graphlib.syncing.knet.api.util.IdPaletteUtils;
5859
import com.kneelawk.graphlib.syncing.knet.impl.graph.simple.SimpleKNetSyncedUniverseBuilder;
5960

6061
/**
@@ -69,7 +70,7 @@ public interface KNetSyncedUniverse extends SyncedUniverse {
6970
/**
7071
* Codec for referencing a specific {@link KNetSyncedUniverse}.
7172
*/
72-
StreamCodec<FriendlyByteBuf, KNetSyncedUniverse> REF_CODEC = SyncingKNet.PALETTED_ID_CODEC.map(id -> {
73+
StreamCodec<FriendlyByteBuf, KNetSyncedUniverse> REF_CODEC = IdPaletteUtils.PALETTED_ID_CODEC.map(id -> {
7374
if (!GraphLibSyncing.syncingEnabled(id))
7475
throw new DecoderException("There is no synced universe called '" + id + "'");
7576
return SyncingKNet.getUniverse(id);

modules/syncing-knet-xplat/src/main/java/com/kneelawk/graphlib/syncing/knet/api/graph/user/BlockNodeSyncing.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
import com.kneelawk.graphlib.api.graph.user.BlockNode;
3939
import com.kneelawk.graphlib.api.graph.user.BlockNodeType;
4040
import com.kneelawk.graphlib.syncing.api.util.ObjectSyncing;
41-
import com.kneelawk.graphlib.syncing.knet.api.SyncingKNet;
4241
import com.kneelawk.graphlib.syncing.knet.api.graph.KNetSyncedUniverse;
42+
import com.kneelawk.graphlib.syncing.knet.api.util.IdPaletteUtils;
4343
import com.kneelawk.graphlib.syncing.knet.impl.StreamCodecHelper;
4444
import com.kneelawk.knet.api.util.NetBufs;
4545
import com.kneelawk.knet.api.util.NetRegistryByteBuf;
@@ -53,7 +53,7 @@ public final class BlockNodeSyncing implements ObjectSyncing<BlockNodeType> {
5353
* {@link BlockNodeSyncing} static stream codec.
5454
* <p>
5555
* <b>This requires the {@link KNetSyncedUniverse#ATTACHMENT_KEY} attachment.</b>
56-
* This can optionally make use of the {@link SyncingKNet#ID_PALETTE} attachment.
56+
* This can optionally make use of the {@link IdPaletteUtils#ID_PALETTE} attachment.
5757
*/
5858
public static final StreamCodec<FriendlyByteBuf, BlockNodeSyncing> REF_CODEC =
5959
StreamCodecHelper.createRefStreamCodec(GraphUniverse::getNodeType, KNetSyncedUniverse::getNodeSyncing,

modules/syncing-knet-xplat/src/main/java/com/kneelawk/graphlib/syncing/knet/api/graph/user/GraphEntitySyncing.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
import com.kneelawk.graphlib.api.graph.user.GraphEntity;
3939
import com.kneelawk.graphlib.api.graph.user.GraphEntityType;
4040
import com.kneelawk.graphlib.syncing.api.util.ObjectSyncing;
41-
import com.kneelawk.graphlib.syncing.knet.api.SyncingKNet;
4241
import com.kneelawk.graphlib.syncing.knet.api.graph.KNetSyncedUniverse;
42+
import com.kneelawk.graphlib.syncing.knet.api.util.IdPaletteUtils;
4343
import com.kneelawk.graphlib.syncing.knet.impl.StreamCodecHelper;
4444
import com.kneelawk.knet.api.util.NetBufs;
4545
import com.kneelawk.knet.api.util.NetRegistryByteBuf;
@@ -55,7 +55,7 @@ public final class GraphEntitySyncing<G extends GraphEntity<G>> implements Objec
5555
* {@link GraphEntitySyncing} static codec.
5656
* <p>
5757
* <b>This requires the {@link KNetSyncedUniverse#ATTACHMENT_KEY} attachment.</b>
58-
* This can optionally make use of the {@link SyncingKNet#ID_PALETTE} attachment.
58+
* This can optionally make use of the {@link IdPaletteUtils#ID_PALETTE} attachment.
5959
*/
6060
public static final StreamCodec<FriendlyByteBuf, GraphEntitySyncing<?>> REF_CODEC =
6161
StreamCodecHelper.createRefStreamCodec(GraphUniverse::getGraphEntityType,

modules/syncing-knet-xplat/src/main/java/com/kneelawk/graphlib/syncing/knet/api/graph/user/LinkEntitySyncing.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
import com.kneelawk.graphlib.api.graph.user.LinkEntity;
3838
import com.kneelawk.graphlib.api.graph.user.LinkEntityType;
3939
import com.kneelawk.graphlib.syncing.api.util.ObjectSyncing;
40-
import com.kneelawk.graphlib.syncing.knet.api.SyncingKNet;
4140
import com.kneelawk.graphlib.syncing.knet.api.graph.KNetSyncedUniverse;
41+
import com.kneelawk.graphlib.syncing.knet.api.util.IdPaletteUtils;
4242
import com.kneelawk.graphlib.syncing.knet.impl.StreamCodecHelper;
4343
import com.kneelawk.knet.api.util.NetBufs;
4444
import com.kneelawk.knet.api.util.NetRegistryByteBuf;
@@ -52,7 +52,7 @@ public final class LinkEntitySyncing implements ObjectSyncing<LinkEntityType> {
5252
* {@link LinkEntitySyncing} static codec.
5353
* <p>
5454
* <b>This requires the {@link KNetSyncedUniverse#ATTACHMENT_KEY} attachment.</b>
55-
* This can optionally make use of the {@link SyncingKNet#ID_PALETTE} attachment.
55+
* This can optionally make use of the {@link IdPaletteUtils#ID_PALETTE} attachment.
5656
*/
5757
public static final StreamCodec<FriendlyByteBuf, LinkEntitySyncing> REF_CODEC =
5858
StreamCodecHelper.createRefStreamCodec(GraphUniverse::getLinkEntityType,

modules/syncing-knet-xplat/src/main/java/com/kneelawk/graphlib/syncing/knet/api/graph/user/LinkKeySyncing.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
import com.kneelawk.graphlib.api.graph.user.LinkKey;
3838
import com.kneelawk.graphlib.api.graph.user.LinkKeyType;
3939
import com.kneelawk.graphlib.syncing.api.util.ObjectSyncing;
40-
import com.kneelawk.graphlib.syncing.knet.api.SyncingKNet;
4140
import com.kneelawk.graphlib.syncing.knet.api.graph.KNetSyncedUniverse;
41+
import com.kneelawk.graphlib.syncing.knet.api.util.IdPaletteUtils;
4242
import com.kneelawk.graphlib.syncing.knet.impl.StreamCodecHelper;
4343
import com.kneelawk.knet.api.util.NetBufs;
4444
import com.kneelawk.knet.api.util.NetRegistryByteBuf;
@@ -52,7 +52,7 @@ public final class LinkKeySyncing implements ObjectSyncing<LinkKeyType> {
5252
* {@link LinkKeySyncing} static codec.
5353
* <p>
5454
* <b>This requires the {@link KNetSyncedUniverse#ATTACHMENT_KEY} attachment.</b>
55-
* This can optionally make use of the {@link SyncingKNet#ID_PALETTE} attachment.
55+
* This can optionally make use of the {@link IdPaletteUtils#ID_PALETTE} attachment.
5656
*/
5757
public static final StreamCodec<FriendlyByteBuf, LinkKeySyncing> REF_CODEC =
5858
StreamCodecHelper.createRefStreamCodec(GraphUniverse::getLinkKeyType, KNetSyncedUniverse::getLinkKeySyncing,

modules/syncing-knet-xplat/src/main/java/com/kneelawk/graphlib/syncing/knet/api/graph/user/NodeEntitySyncing.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
import com.kneelawk.graphlib.api.graph.user.NodeEntity;
3838
import com.kneelawk.graphlib.api.graph.user.NodeEntityType;
3939
import com.kneelawk.graphlib.syncing.api.util.ObjectSyncing;
40-
import com.kneelawk.graphlib.syncing.knet.api.SyncingKNet;
4140
import com.kneelawk.graphlib.syncing.knet.api.graph.KNetSyncedUniverse;
41+
import com.kneelawk.graphlib.syncing.knet.api.util.IdPaletteUtils;
4242
import com.kneelawk.graphlib.syncing.knet.impl.StreamCodecHelper;
4343
import com.kneelawk.knet.api.util.NetBufs;
4444
import com.kneelawk.knet.api.util.NetRegistryByteBuf;
@@ -52,7 +52,7 @@ public final class NodeEntitySyncing implements ObjectSyncing<NodeEntityType> {
5252
* {@link NodeEntitySyncing} static codec.
5353
* <p>
5454
* <b>This requires the {@link KNetSyncedUniverse#ATTACHMENT_KEY} attachment.</b>
55-
* This can optionally make use of the {@link SyncingKNet#ID_PALETTE} attachment.
55+
* This can optionally make use of the {@link IdPaletteUtils#ID_PALETTE} attachment.
5656
*/
5757
public static final StreamCodec<FriendlyByteBuf, NodeEntitySyncing> REF_CODEC =
5858
StreamCodecHelper.createRefStreamCodec(GraphUniverse::getNodeEntityType,

0 commit comments

Comments
 (0)