Skip to content

Commit 4e76786

Browse files
committed
It begins
1 parent bf095f4 commit 4e76786

File tree

11 files changed

+216
-0
lines changed

11 files changed

+216
-0
lines changed

javadoc-options.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.kneelawk.graphlib.v3.api;
2+
3+
/**
4+
* GraphLib Public API.
5+
*/
6+
public final class GraphLib {
7+
private GraphLib() {}
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.kneelawk.graphlib.v3.api.graph.user;
2+
3+
import com.mojang.serialization.MapCodec;
4+
5+
/**
6+
* Interface that all graph nodes should implement.
7+
* <p>
8+
* A graph node is a piece of immutable data that sits in a graph and can be used to allow utilities to determine which
9+
* things are connected to which and how.
10+
*/
11+
public interface GraphNode {
12+
// TODO: universe lookups
13+
/**
14+
* {@link GraphNode} map codec.
15+
*/
16+
MapCodec<GraphNode> MAP_CODEC = MapCodec.unit(() -> {throw new AssertionError("Stub");});
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* User-implemented GraphLib interfaces.
3+
*/
4+
@ParametersAreNonnullByDefault
5+
@MethodsReturnNonnullByDefault
6+
@FieldsAreNonnullByDefault
7+
package com.kneelawk.graphlib.v3.api.graph.user;
8+
9+
import javax.annotation.ParametersAreNonnullByDefault;
10+
11+
import net.minecraft.FieldsAreNonnullByDefault;
12+
import net.minecraft.MethodsReturnNonnullByDefault;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Root GraphLib API package.
3+
*/
4+
@ParametersAreNonnullByDefault
5+
@MethodsReturnNonnullByDefault
6+
@FieldsAreNonnullByDefault
7+
package com.kneelawk.graphlib.v3.api;
8+
9+
import javax.annotation.ParametersAreNonnullByDefault;
10+
11+
import net.minecraft.FieldsAreNonnullByDefault;
12+
import net.minecraft.MethodsReturnNonnullByDefault;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.kneelawk.graphlib.v3.api.pos;
2+
3+
import com.mojang.serialization.MapCodec;
4+
import com.mojang.serialization.codecs.RecordCodecBuilder;
5+
6+
import net.minecraft.core.BlockPos;
7+
8+
import com.kneelawk.graphlib.v3.api.graph.user.GraphNode;
9+
10+
import static com.kneelawk.graphlib.v3.impl.GLConstants.rl;
11+
12+
/**
13+
* Represents a node positioned in a specific block.
14+
*
15+
* @param pos the block the node is in.
16+
* @param dimension the dimension the node is in.
17+
* @param node the node itself.
18+
*/
19+
public record BlockNodePos(BlockPos pos, DimensionRef dimension, GraphNode node) implements NodePos {
20+
/**
21+
* {@link BlockNodePos} codec.
22+
*/
23+
public static final MapCodec<BlockNodePos> MAP_CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
24+
BlockPos.CODEC.fieldOf("pos").forGetter(BlockNodePos::pos),
25+
DimensionRef.MAP_CODEC.codec().fieldOf("dim").forGetter(BlockNodePos::dimension),
26+
GraphNode.MAP_CODEC.codec().fieldOf("node").forGetter(BlockNodePos::node)
27+
).apply(instance, BlockNodePos::new));
28+
/**
29+
* {@link BlockNodePos} codec.
30+
*/
31+
public static final Type<BlockNodePos> TYPE = new Type<>(rl("block"), MAP_CODEC);
32+
33+
@Override
34+
public Type<? extends NodePos> getType() {
35+
return TYPE;
36+
}
37+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.kneelawk.graphlib.v3.api.pos;
2+
3+
import com.mojang.serialization.MapCodec;
4+
5+
import net.minecraft.resources.ResourceLocation;
6+
7+
/**
8+
* A reference to a level or dimension type object. This can be a {@link net.minecraft.world.level.Level} or something
9+
* with a custom implementation like a Create Contraption.
10+
*/
11+
public interface DimensionRef {
12+
// TODO: Universe lookups
13+
/**
14+
* DimensionRef codec.
15+
*/
16+
MapCodec<DimensionRef> MAP_CODEC = MapCodec.unit(() -> {throw new AssertionError("Stub");});
17+
18+
/**
19+
* {@return this dimension ref's type}
20+
*/
21+
Type<? extends DimensionRef> getType();
22+
23+
/**
24+
* The type of a dimension reference.
25+
*
26+
* @param id the id of this type of dimension reference within a given universe.
27+
* @param codec the codec for encoding and decoding this dimension reference type.
28+
* @param <T> the type of dimension reference this type describes.
29+
*/
30+
record Type<T extends DimensionRef>(ResourceLocation id, MapCodec<T> codec) {}
31+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.kneelawk.graphlib.v3.api.pos;
2+
3+
import com.mojang.serialization.MapCodec;
4+
5+
import net.minecraft.resources.ResourceLocation;
6+
7+
import static com.kneelawk.graphlib.v3.impl.GLConstants.rl;
8+
9+
/**
10+
* A reference to a specific {@link net.minecraft.world.level.Level}.
11+
*
12+
* @param level the name of the level, stored in the server.
13+
*/
14+
public record LevelRef(ResourceLocation level) implements DimensionRef {
15+
/**
16+
* LevelRef codec.
17+
*/
18+
public static final MapCodec<LevelRef> MAP_CODEC =
19+
ResourceLocation.CODEC.fieldOf("level").xmap(LevelRef::new, LevelRef::level);
20+
/**
21+
* LevelRef type.
22+
*/
23+
public static final Type<LevelRef> TYPE = new Type<>(rl("level"), MAP_CODEC);
24+
25+
@Override
26+
public Type<? extends DimensionRef> getType() {
27+
return TYPE;
28+
}
29+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.kneelawk.graphlib.v3.api.pos;
2+
3+
import com.mojang.serialization.MapCodec;
4+
5+
import net.minecraft.core.BlockPos;
6+
import net.minecraft.resources.ResourceLocation;
7+
8+
import com.kneelawk.graphlib.v3.api.graph.user.GraphNode;
9+
10+
/**
11+
* Generic Node position. This can have different implementations, depending on what the node is actually attached to.
12+
*/
13+
public interface NodePos {
14+
/**
15+
* Utility method for creating a block node position.
16+
*
17+
* @param pos the block position of the node.
18+
* @param dimension the dimension the node is in.
19+
* @param node the node itself.
20+
* @return the node pos for uniquely describing that node.
21+
*/
22+
static NodePos block(BlockPos pos, ResourceLocation dimension, GraphNode node) {
23+
return new BlockNodePos(pos, new LevelRef(dimension), node);
24+
}
25+
26+
/**
27+
* {@return the graph node of this node pos}
28+
*/
29+
GraphNode node();
30+
31+
/**
32+
* {@return this dimension ref's type}
33+
*/
34+
Type<? extends NodePos> getType();
35+
36+
/**
37+
* The type of a dimension reference.
38+
*
39+
* @param id the id of this type of dimension reference within a given universe.
40+
* @param codec the codec for encoding and decoding this dimension reference type.
41+
* @param <T> the type of node pos this type describes.
42+
*/
43+
record Type<T extends NodePos>(ResourceLocation id, MapCodec<T> codec) {}
44+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* GraphLib positioning.
3+
* <p>
4+
* This the constructs for referencing a specific node in a graph.
5+
*/
6+
@ParametersAreNonnullByDefault
7+
@MethodsReturnNonnullByDefault
8+
@FieldsAreNonnullByDefault
9+
package com.kneelawk.graphlib.v3.api.pos;
10+
11+
import javax.annotation.ParametersAreNonnullByDefault;
12+
13+
import net.minecraft.FieldsAreNonnullByDefault;
14+
import net.minecraft.MethodsReturnNonnullByDefault;

0 commit comments

Comments
 (0)