Skip to content

Commit 392b30a

Browse files
committed
Unify syncing objects under interface
1 parent 4fbec2a commit 392b30a

11 files changed

Lines changed: 82 additions & 12 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2024 Cyan Kneelawk.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
*/
25+
26+
package com.kneelawk.graphlib.syncing.api.util;
27+
28+
import org.jetbrains.annotations.NotNull;
29+
30+
import net.minecraft.resources.ResourceLocation;
31+
32+
import com.kneelawk.graphlib.api.util.ObjectType;
33+
34+
/**
35+
* Simple super type for all syncing types.
36+
*
37+
* @param <T> the object type this syncing type is associated with.
38+
*/
39+
public interface ObjectSyncing<T extends ObjectType> {
40+
/**
41+
* {@return the object type associated with this syncing type}
42+
*/
43+
@NotNull
44+
T getType();
45+
46+
/**
47+
* {@return the id associated with this syncing type}
48+
*/
49+
default ResourceLocation getId() {
50+
return getType().getId();
51+
}
52+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.kneelawk.graphlib.api.graph.GraphUniverse;
3838
import com.kneelawk.graphlib.api.graph.user.BlockNode;
3939
import com.kneelawk.graphlib.api.graph.user.BlockNodeType;
40+
import com.kneelawk.graphlib.syncing.api.util.ObjectSyncing;
4041
import com.kneelawk.graphlib.syncing.knet.api.SyncingKNet;
4142
import com.kneelawk.graphlib.syncing.knet.api.graph.KNetSyncedUniverse;
4243
import com.kneelawk.graphlib.syncing.knet.impl.StreamCodecHelper;
@@ -47,7 +48,7 @@
4748
/**
4849
* Holds a block node encoder and decoder.
4950
*/
50-
public final class BlockNodeSyncing {
51+
public final class BlockNodeSyncing implements ObjectSyncing<BlockNodeType> {
5152
/**
5253
* {@link BlockNodeSyncing} static stream codec.
5354
* <p>
@@ -80,6 +81,7 @@ private BlockNodeSyncing(@NotNull BlockNodeType type,
8081
/**
8182
* {@return this syncing descriptor's type}
8283
*/
84+
@Override
8385
public @NotNull BlockNodeType getType() {
8486
return type;
8587
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.kneelawk.graphlib.api.graph.GraphUniverse;
3838
import com.kneelawk.graphlib.api.graph.user.GraphEntity;
3939
import com.kneelawk.graphlib.api.graph.user.GraphEntityType;
40+
import com.kneelawk.graphlib.syncing.api.util.ObjectSyncing;
4041
import com.kneelawk.graphlib.syncing.knet.api.SyncingKNet;
4142
import com.kneelawk.graphlib.syncing.knet.api.graph.KNetSyncedUniverse;
4243
import com.kneelawk.graphlib.syncing.knet.impl.StreamCodecHelper;
@@ -49,7 +50,7 @@
4950
*
5051
* @param <G> the type of graph entity this syncs.
5152
*/
52-
public final class GraphEntitySyncing<G extends GraphEntity<G>> {
53+
public final class GraphEntitySyncing<G extends GraphEntity<G>> implements ObjectSyncing<GraphEntityType<G>> {
5354
/**
5455
* {@link GraphEntitySyncing} static codec.
5556
* <p>
@@ -95,6 +96,7 @@ private GraphEntitySyncing(@NotNull GraphEntityType<G> type,
9596
/**
9697
* {@return this syncing descriptor's type}
9798
*/
99+
@Override
98100
public @NotNull GraphEntityType<G> getType() {
99101
return type;
100102
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.kneelawk.graphlib.api.graph.GraphUniverse;
3737
import com.kneelawk.graphlib.api.graph.user.LinkEntity;
3838
import com.kneelawk.graphlib.api.graph.user.LinkEntityType;
39+
import com.kneelawk.graphlib.syncing.api.util.ObjectSyncing;
3940
import com.kneelawk.graphlib.syncing.knet.api.SyncingKNet;
4041
import com.kneelawk.graphlib.syncing.knet.api.graph.KNetSyncedUniverse;
4142
import com.kneelawk.graphlib.syncing.knet.impl.StreamCodecHelper;
@@ -46,7 +47,7 @@
4647
/**
4748
* Holds a link entity encoder and decoder.
4849
*/
49-
public final class LinkEntitySyncing {
50+
public final class LinkEntitySyncing implements ObjectSyncing<LinkEntityType> {
5051
/**
5152
* {@link LinkEntitySyncing} static codec.
5253
* <p>
@@ -79,6 +80,7 @@ private LinkEntitySyncing(@NotNull LinkEntityType type,
7980
/**
8081
* {@return this syncing descriptor's type}
8182
*/
83+
@Override
8284
public @NotNull LinkEntityType getType() {
8385
return type;
8486
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.kneelawk.graphlib.api.graph.GraphUniverse;
3737
import com.kneelawk.graphlib.api.graph.user.LinkKey;
3838
import com.kneelawk.graphlib.api.graph.user.LinkKeyType;
39+
import com.kneelawk.graphlib.syncing.api.util.ObjectSyncing;
3940
import com.kneelawk.graphlib.syncing.knet.api.SyncingKNet;
4041
import com.kneelawk.graphlib.syncing.knet.api.graph.KNetSyncedUniverse;
4142
import com.kneelawk.graphlib.syncing.knet.impl.StreamCodecHelper;
@@ -46,7 +47,7 @@
4647
/**
4748
* Holds a link key encoder and decoder.
4849
*/
49-
public final class LinkKeySyncing {
50+
public final class LinkKeySyncing implements ObjectSyncing<LinkKeyType> {
5051
/**
5152
* {@link LinkKeySyncing} static codec.
5253
* <p>
@@ -79,6 +80,7 @@ private LinkKeySyncing(@NotNull LinkKeyType type,
7980
/**
8081
* {@return this syncing descriptor's type}
8182
*/
83+
@Override
8284
public @NotNull LinkKeyType getType() {
8385
return type;
8486
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.kneelawk.graphlib.api.graph.GraphUniverse;
3737
import com.kneelawk.graphlib.api.graph.user.NodeEntity;
3838
import com.kneelawk.graphlib.api.graph.user.NodeEntityType;
39+
import com.kneelawk.graphlib.syncing.api.util.ObjectSyncing;
3940
import com.kneelawk.graphlib.syncing.knet.api.SyncingKNet;
4041
import com.kneelawk.graphlib.syncing.knet.api.graph.KNetSyncedUniverse;
4142
import com.kneelawk.graphlib.syncing.knet.impl.StreamCodecHelper;
@@ -46,7 +47,7 @@
4647
/**
4748
* Holds a node entity encoder and decoder.
4849
*/
49-
public final class NodeEntitySyncing {
50+
public final class NodeEntitySyncing implements ObjectSyncing<NodeEntityType> {
5051
/**
5152
* {@link NodeEntitySyncing} static codec.
5253
* <p>
@@ -79,6 +80,7 @@ private NodeEntitySyncing(@NotNull NodeEntityType type,
7980
/**
8081
* {@return this syncing descriptor's type}
8182
*/
83+
@Override
8284
public @NotNull NodeEntityType getType() {
8385
return type;
8486
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@
3737

3838
import com.kneelawk.graphlib.api.graph.user.BlockNode;
3939
import com.kneelawk.graphlib.api.graph.user.BlockNodeType;
40+
import com.kneelawk.graphlib.syncing.api.util.ObjectSyncing;
4041

4142
/**
4243
* Holds a block node encoder and decoder.
4344
*/
44-
public final class BlockNodeSyncing {
45+
public final class BlockNodeSyncing implements ObjectSyncing<BlockNodeType> {
4546
private final @NotNull BlockNodeType type;
4647
private final @NotNull BlockNodePacketEncoder<?> encoder;
4748
private final @NotNull BlockNodePacketDecoder decoder;
@@ -56,6 +57,7 @@ private BlockNodeSyncing(@NotNull BlockNodeType type, @NotNull BlockNodePacketEn
5657
/**
5758
* {@return the type associated with this syncing}
5859
*/
60+
@Override
5961
public @NotNull BlockNodeType getType() {
6062
return type;
6163
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@
3737

3838
import com.kneelawk.graphlib.api.graph.user.GraphEntity;
3939
import com.kneelawk.graphlib.api.graph.user.GraphEntityType;
40+
import com.kneelawk.graphlib.syncing.api.util.ObjectSyncing;
4041

4142
/**
4243
* Holds a graph entity encoder and decoder.
4344
*
4445
* @param <G> the type of graph entity this syncs.
4546
*/
46-
public final class GraphEntitySyncing<G extends GraphEntity<G>> {
47+
public final class GraphEntitySyncing<G extends GraphEntity<G>> implements ObjectSyncing<GraphEntityType<G>> {
4748
private final @NotNull GraphEntityType<G> type;
4849
private final @NotNull GraphEntityPacketEncoder<G> encoder;
4950
private final @NotNull GraphEntityPacketDecoder decoder;
@@ -58,6 +59,7 @@ private GraphEntitySyncing(@NotNull GraphEntityType<G> type, @NotNull GraphEntit
5859
/**
5960
* {@return the type associated with this syncing}
6061
*/
62+
@Override
6163
public @NotNull GraphEntityType<G> getType() {
6264
return type;
6365
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434
import alexiil.mc.lib.net.InvalidInputDataException;
3535
import alexiil.mc.lib.net.NetByteBuf;
3636

37-
import com.kneelawk.graphlib.api.graph.user.BlockNodeType;
3837
import com.kneelawk.graphlib.api.graph.user.LinkEntity;
3938
import com.kneelawk.graphlib.api.graph.user.LinkEntityType;
39+
import com.kneelawk.graphlib.syncing.api.util.ObjectSyncing;
4040

4141
/**
4242
* Holds a link entity encoder and decoder.
4343
*/
44-
public final class LinkEntitySyncing {
44+
public final class LinkEntitySyncing implements ObjectSyncing<LinkEntityType> {
4545
private final @NotNull LinkEntityType type;
4646
private final @NotNull LinkEntityPacketEncoder<?> encoder;
4747
private final @NotNull LinkEntityPacketDecoder decoder;
@@ -56,6 +56,7 @@ private LinkEntitySyncing(@NotNull LinkEntityType type, @NotNull LinkEntityPacke
5656
/**
5757
* {@return the type associated with this syncing}
5858
*/
59+
@Override
5960
public @NotNull LinkEntityType getType() {
6061
return type;
6162
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434
import alexiil.mc.lib.net.InvalidInputDataException;
3535
import alexiil.mc.lib.net.NetByteBuf;
3636

37-
import com.kneelawk.graphlib.api.graph.user.BlockNodeType;
3837
import com.kneelawk.graphlib.api.graph.user.LinkKey;
3938
import com.kneelawk.graphlib.api.graph.user.LinkKeyType;
39+
import com.kneelawk.graphlib.syncing.api.util.ObjectSyncing;
4040

4141
/**
4242
* Holds a link key encoder and decoder.
4343
*/
44-
public final class LinkKeySyncing {
44+
public final class LinkKeySyncing implements ObjectSyncing<LinkKeyType> {
4545
private final @NotNull LinkKeyType type;
4646
private final @NotNull LinkKeyPacketEncoder<?> encoder;
4747
private final @NotNull LinkKeyPacketDecoder decoder;
@@ -56,6 +56,7 @@ private LinkKeySyncing(@NotNull LinkKeyType type, @NotNull LinkKeyPacketEncoder<
5656
/**
5757
* {@return the type associated with this syncing}
5858
*/
59+
@Override
5960
public @NotNull LinkKeyType getType() {
6061
return type;
6162
}

0 commit comments

Comments
 (0)