1- package dev .compactmods .machines .tests ;
1+ package dev .compactmods .machines .test ;
22
3+ import java .util .Collection ;
4+ import java .util .Optional ;
35import com .google .common .graph .Graph ;
46import com .mojang .serialization .DataResult ;
57import dev .compactmods .machines .data .codec .CodecExtensions ;
810import dev .compactmods .machines .data .graph .CompactMachineRoomNode ;
911import dev .compactmods .machines .data .graph .IMachineGraphNode ;
1012import dev .compactmods .machines .util .MathUtil ;
11- import net .minecraft .nbt .*;
12- import net .minecraft .util .math .ChunkPos ;
13- import net .minecraftforge .common .util .Constants ;
13+ import net .minecraft .nbt .CompoundTag ;
14+ import net .minecraft .nbt .ListTag ;
15+ import net .minecraft .nbt .NbtOps ;
16+ import net .minecraft .nbt .Tag ;
17+ import net .minecraft .world .level .ChunkPos ;
1418import org .junit .jupiter .api .Assertions ;
1519import org .junit .jupiter .api .DisplayName ;
1620import org .junit .jupiter .api .Test ;
1721
18- import java .util .Collection ;
19- import java .util .Optional ;
20-
2122@ DisplayName ("Machine Graph Tests" )
23+ @ org .junit .jupiter .api .Tag ("minecraft" )
2224public class GraphTests {
2325
2426 private CompactMachineConnectionGraph generateGraphWithSingleRoom () {
@@ -135,42 +137,34 @@ void canCreateRoomWithMultipleLinkedMachines() {
135137 void canSerialize () {
136138 CompactMachineConnectionGraph graph = generateGraphWithSingleRoom ();
137139
138- DataResult <INBT > nbtResult = CompactMachineConnectionGraph .CODEC .encodeStart (NBTDynamicOps .INSTANCE , graph );
140+ DataResult <Tag > nbtResult = CompactMachineConnectionGraph .CODEC .encodeStart (NbtOps .INSTANCE , graph );
139141
140142 nbtResult .resultOrPartial (Assertions ::fail )
141143 .ifPresent (nbt -> {
142- Assertions .assertTrue (nbt instanceof CompoundNBT );
143-
144- // try {
145- // File file = FileHelper.RESOURCES_DIR.resolve("graph.dat").toFile();
146- // file.delete();
147- // CompressedStreamTools.writeCompressed((CompoundNBT) nbt, file);
148- // } catch (IOException e) {
149- // e.printStackTrace();
150- // }
144+ Assertions .assertTrue (nbt instanceof CompoundTag );
151145
152- CompoundNBT c = (CompoundNBT ) nbt ;
146+ CompoundTag c = (CompoundTag ) nbt ;
153147 Assertions .assertFalse (c .isEmpty ());
154148
155149 Assertions .assertTrue (c .contains ("connections" ));
156150
157- ListNBT connections = c .getList ("connections" , Constants . NBT .TAG_COMPOUND );
151+ ListTag connections = c .getList ("connections" , Tag .TAG_COMPOUND );
158152 Assertions .assertEquals (1 , connections .size (), "Expected one connection from a machine to a single room." );
159153
160- CompoundNBT conn1 = connections .getCompound (0 );
154+ CompoundTag conn1 = connections .getCompound (0 );
161155 Assertions .assertNotNull (conn1 );
162156
163157 Assertions .assertTrue (conn1 .contains ("machine" ));
164158 Assertions .assertTrue (conn1 .contains ("connections" ));
165159
166- INBT machineChunk = conn1 .get ("machine" );
167- DataResult <ChunkPos > chunkRes = CodecExtensions .CHUNKPOS .parse (NBTDynamicOps .INSTANCE , machineChunk );
160+ Tag machineChunk = conn1 .get ("machine" );
161+ DataResult <ChunkPos > chunkRes = CodecExtensions .CHUNKPOS .parse (NbtOps .INSTANCE , machineChunk );
168162 chunkRes .resultOrPartial (Assertions ::fail )
169163 .ifPresent (chunk -> {
170164 Assertions .assertEquals (new ChunkPos (0 , 0 ), chunk );
171165 });
172166
173- ListNBT connList = conn1 .getList ("connections" , Constants . NBT . TAG_INT );
167+ ListTag connList = conn1 .getList ("connections" , Tag . TAG_COMPOUND );
174168 Assertions .assertNotNull (connList );
175169 Assertions .assertEquals (1 , connList .size ());
176170 Assertions .assertEquals (0 , connList .getInt (0 ));
@@ -199,88 +193,6 @@ void simpleNestedMachines() {
199193 graph .connectMachineToRoom (1 , room1 );
200194
201195 }
202- // private void generateData(MutableGraph<IGraphNode> g, HashMap<String, IGraphNode> lookup) {
203- // Random r = new Random();
204- // MachineExternalLocation[] values = MachineExternalLocation.values();
205- // int numInsides = 0;
206- // int numOutsides = 0;
207- //
208- // Set<IMachineGraphNode> disconnected = new HashSet<>();
209- // List<CompactMachineExternalNode> externals = new ArrayList<>();
210- // List<CompactMachineInsideNode> internals = new ArrayList<>();
211- //
212- // // Seed a couple of machines and insides so they're always there
213- // for(int i = 0; i < 10; i++) {
214- // ChunkPos machineChunk = getMachineChunkPos(numInsides + 1);
215- // CompactMachineExternalNode extern = createMachineExternalNode(g, lookup, i);
216- // CompactMachineInsideNode intern = createMachineInternalNode(g, lookup, machineChunk);
217- //
218- // externals.add(extern);
219- // internals.add(intern);
220- //
221- // extern.connectTo(intern);
222- // numOutsides++;
223- // numInsides++;
224- // }
225- //
226- // for(int i = 0; i < 50; i++) {
227- //
228- // if(r.nextBoolean()) {
229- // // Creating the outside of a machine
230- // MachineExternalLocation loc = values[r.nextInt(values.length)];
231- //
232- // CompactMachineExternalNode machine = createMachineExternalNode(g, lookup, numOutsides + 1);
233- // externals.add(machine);
234- //
235- // switch (loc) {
236- // case EXTERNAL_DIMENSION:
237- // int randomMachineInsideE = r.nextInt(internals.size());
238- // CompactMachineInsideNode miE = internals.get(randomMachineInsideE);
239- // machine.connectTo(miE);
240- //
241- // // try to remove from disconnected if it exists there
242- // disconnected.remove(miE);
243- // break;
244- //
245- // case INSIDE_MACHINE:
246- // int randomMachineInsideI = r.nextInt(internals.size());
247- // CompactMachineInsideNode miI = internals.get(randomMachineInsideI);
248- //
249- // // Put the machine inside a randomly chosen existing machine
250- // g.putEdge(miI, machine);
251- //
252- // boolean connectToAnother = r.nextBoolean();
253- // if(connectToAnother) {
254- // System.out.println("connect");
255- // int randomMachine = r.nextInt(internals.size());
256- // CompactMachineInsideNode in = internals.get(randomMachine);
257- // machine.connectTo(in);
258- //
259- // g.successors(machine); // All the connections internally
260- // }
261- // break;
262- // }
263- //
264- // numOutsides++;
265- // } else {
266- // // Creating the inside of a machine
267- // ChunkPos machineChunk= getMachineChunkPos(numInsides + 1);
268- // CompactMachineInsideNode mi = createMachineInternalNode(g, lookup, machineChunk);
269- // disconnected.add(mi);
270- // numInsides++;
271- // }
272- // }
273- //
274- // if(!disconnected.isEmpty()) {
275- // for (IMachineGraphNode di : disconnected) {
276- // CompactMachineExternalNode machine = createMachineExternalNode(g, lookup, numOutsides + 1);
277- // machine.connectTo(di);
278- // numOutsides++;
279- // }
280- // }
281- //
282- // disconnected.clear();
283- // }
284196
285197 public static String write (final CompactMachineConnectionGraph graph ) {
286198 StringBuilder sb = new StringBuilder ();
@@ -290,20 +202,6 @@ public static String write(final CompactMachineConnectionGraph graph) {
290202 .append ("\t layout = fdp;" ).append (System .lineSeparator ())
291203 .append ("\t node [shape=square,style=filled,color=lightgray];" ).append (System .lineSeparator ());
292204
293- // Set<CompactMachineNode> topLevelMachines = graph.getMachines()
294- // .filter(n -> graph.getConnectedRoom(n.getMachineId()).isPresent())
295- // .collect(Collectors.toSet());
296- //
297- // for (CompactMachineNode n : topLevelMachines)
298- // outputExternalNode(sb, n);
299- //
300- // graph.nodes().stream()
301- // .filter(n -> n instanceof CompactMachineRoomNode)
302- // .map(n -> (CompactMachineRoomNode) n)
303- // .forEach(n -> {
304- // outputMachineInside(graph, sb, n);
305- // });
306-
307205 sb .append ("}" );
308206 return sb .toString ();
309207 }
0 commit comments