aboutsummaryrefslogtreecommitdiff
path: root/src/gametest/java/de/hysky/skyblocker/SkyblockerGameTest.java
blob: c410352b8dc606183750c13867ebff53d57b301c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package de.hysky.skyblocker;

import de.hysky.skyblocker.debug.SnapshotDebug;
import de.hysky.skyblocker.skyblock.fancybars.FancyStatusBars;
import it.unimi.dsi.fastutil.Pair;
import net.fabricmc.fabric.api.client.gametest.v1.context.ClientGameTestContext;
import net.fabricmc.fabric.api.client.gametest.v1.FabricClientGameTest;
//import net.fabricmc.fabric.api.client.gametest.v1.screenshot.TestScreenshotComparisonOptions;
import net.fabricmc.fabric.api.client.gametest.v1.context.TestSingleplayerContext;
import net.minecraft.client.gui.screen.world.WorldCreator;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.world.gen.WorldPresets;

@SuppressWarnings("UnstableApiUsage")
public class SkyblockerGameTest implements FabricClientGameTest {
	@Override
	public void runTest(ClientGameTestContext context) {
		try (TestSingleplayerContext singleplayer = context.worldBuilder().adjustSettings(worldCreator -> {
			worldCreator.setWorldType(new WorldCreator.WorldType(worldCreator.getGeneratorOptionsHolder().getCombinedRegistryManager().getOrThrow(RegistryKeys.WORLD_PRESET).getOrThrow(WorldPresets.DEFAULT)));
			worldCreator.setSeed(String.valueOf(SnapshotDebug.AARON_WORLD_SEED));
		}).create()) {
			// Set up the world
			singleplayer.getServer().runCommand("/fill 180 63 -13 184 67 -17 air");
			singleplayer.getServer().runCommand("/setblock 175 66 -4 minecraft:barrier");
			singleplayer.getServer().runCommand("/tp @a 175 67 -4");

			context.runOnClient(client -> {
				assert client.player != null;
				client.player.setYaw(180);
				client.player.setPitch(20);
			});

			// Save the current fancy status bars config and reset it to default
			var config = context.computeOnClient(client -> {
				var curConfig = FancyStatusBars.statusBars.entrySet().stream().map(e -> Pair.of(e.getKey(), e.getValue().toJson())).toList();

				int[] counts = new int[7];
				FancyStatusBars.statusBars.forEach((type, bar) -> {
					bar.anchor = type.getDefaultAnchor();
					bar.gridY = type.getDefaultGridY();
					bar.gridX = counts[type.getDefaultAnchor().ordinal()]++;
				});
				FancyStatusBars.placeBarsInPositioner();
				FancyStatusBars.updatePositions(false);
				return curConfig;
			});

			// Take a screenshot and compare it
			//singleplayer.getClientWorld().waitForChunksRender();
			//context.assertScreenshotEquals(TestScreenshotComparisonOptions.of("skyblocker_render").saveWithFileName("skyblocker_render"));

			// Restore the fancy status bars config
			context.runOnClient(client -> {
				config.forEach(pair -> FancyStatusBars.statusBars.get(pair.key()).loadFromJson(pair.value()));
				FancyStatusBars.placeBarsInPositioner();
				FancyStatusBars.updatePositions(false);
			});
		}
	}
}