Skip to content

Commit

Permalink
Merge branch '1.21.4' into hud-render-events
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinthegreat1 committed Jan 29, 2025
2 parents f2bf391 + 1bdf666 commit b4f8aab
Show file tree
Hide file tree
Showing 74 changed files with 506 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package net.fabricmc.fabric.api.client.gametest.v1;

import net.fabricmc.fabric.api.client.gametest.v1.context.ClientGameTestContext;

/**
* The {@code fabric-client-gametest} entrypoint interface. See the package documentation.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package net.fabricmc.fabric.api.client.gametest.v1;
package net.fabricmc.fabric.api.client.gametest.v1.context;

import java.nio.file.Path;
import java.util.function.Predicate;
Expand All @@ -30,6 +30,11 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;

import net.fabricmc.fabric.api.client.gametest.v1.TestInput;
import net.fabricmc.fabric.api.client.gametest.v1.screenshot.TestScreenshotComparisonOptions;
import net.fabricmc.fabric.api.client.gametest.v1.screenshot.TestScreenshotOptions;
import net.fabricmc.fabric.api.client.gametest.v1.world.TestWorldBuilder;

/**
* Context for a client gametest containing various helpful functions and functions to access the game.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package net.fabricmc.fabric.api.client.gametest.v1;
package net.fabricmc.fabric.api.client.gametest.v1.context;

import org.jetbrains.annotations.ApiStatus;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package net.fabricmc.fabric.api.client.gametest.v1;
package net.fabricmc.fabric.api.client.gametest.v1.context;

import org.jetbrains.annotations.ApiStatus;

Expand All @@ -23,6 +23,10 @@
* This class implements {@link AutoCloseable} and is intended to be used in a try-with-resources statement. When
* closed, the dedicated server will be stopped.
*
* <p>Dedicated servers will only run if the EULA has been accepted in {@code eula.txt}. If you have read and accepted
* the <a href="https://aka.ms/MinecraftEULA">Minecraft EULA</a>, you can write the file at build-time by setting
* {@code fabricApi.configureTests { eula = true }} in your {@code build.gradle}.
*
* <p>Functions in this class can only be called on the client gametest thread.
*/
@ApiStatus.NonExtendable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package net.fabricmc.fabric.api.client.gametest.v1;
package net.fabricmc.fabric.api.client.gametest.v1.context;

import org.jetbrains.annotations.ApiStatus;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package net.fabricmc.fabric.api.client.gametest.v1;
package net.fabricmc.fabric.api.client.gametest.v1.context;

import org.apache.commons.lang3.function.FailableConsumer;
import org.apache.commons.lang3.function.FailableFunction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
* limitations under the License.
*/

package net.fabricmc.fabric.api.client.gametest.v1;
package net.fabricmc.fabric.api.client.gametest.v1.context;

import org.jetbrains.annotations.ApiStatus;

import net.fabricmc.fabric.api.client.gametest.v1.world.TestWorldSave;

/**
* Context for a client gametest containing various helpful functions while a singleplayer game is open.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ApiStatus.Experimental
package net.fabricmc.fabric.api.client.gametest.v1.context;

import org.jetbrains.annotations.ApiStatus;
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,38 @@
* {@code fabric-client-gametest} entrypoint in your {@code fabric.mod.json}. Your gametest class should implement
* {@link net.fabricmc.fabric.api.client.gametest.v1.FabricClientGameTest FabricClientGameTest}.
*
* <p>Loom provides an API to configure client gametests in your {@code build.gradle}. It is recommended to run
* gametests from a separate source set and test mod:
* <pre>
* {@code
* fabricApi.configureTests {
* createSourceSet = true
* modId = 'your-gametest-mod-id'
* }
* }
* </pre>
*
* <h1>Lifecycle</h1>
* Client gametests are run sequentially. When a gametest ends, the game will be
* returned to the title screen. When all gametests have been run, the game will be closed.
*
* <h1>Threading</h1>
*
* <p>Client gametests run on the client gametest thread. Use the functions inside
* {@link net.fabricmc.fabric.api.client.gametest.v1.ClientGameTestContext ClientGameTestContext} and other test helper
* classes to run code on the correct thread. Exceptions are transparently rethrown on the test thread, and their stack
* traces are mutated to include the async stack trace, to make them easy to track. You can disable this behavior by
* setting the {@code fabric.client.gametest.disableJoinAsyncStackTraces} system property.
* {@link net.fabricmc.fabric.api.client.gametest.v1.context.ClientGameTestContext ClientGameTestContext} and other test
* helper classes to run code on the correct thread. Exceptions are transparently rethrown on the test thread, and their
* stack traces are mutated to include the async stack trace, to make them easy to track. You can disable this behavior
* by setting the {@code fabric.client.gametest.disableJoinAsyncStackTraces} system property.
*
* <p>The game remains paused unless you explicitly unpause it using various waiting functions such as
* {@link net.fabricmc.fabric.api.client.gametest.v1.ClientGameTestContext#waitTick() ClientGameTestContext.waitTick()}.
* {@link net.fabricmc.fabric.api.client.gametest.v1.context.ClientGameTestContext#waitTick() ClientGameTestContext.waitTick()}.
* A side effect of this is that <strong>the results of your code may not be immediate if the game needs a tick to
* process them</strong>. A big example of this is key bindings, although some key binding methods have built-in tick
* waits to mitigate the issue. See the {@link net.fabricmc.fabric.api.client.gametest.v1.TestInput TestInput}
* documentation for details. Another pseudo-example is effects on the server need a tick to propagate to the client and
* vice versa, although this is related to packets more than the fact the game is suspended (see the network
* synchronization section below). A good strategy for debugging these issues is by
* {@linkplain net.fabricmc.fabric.api.client.gametest.v1.ClientGameTestContext#takeScreenshot(String) taking screenshots},
* {@linkplain net.fabricmc.fabric.api.client.gametest.v1.context.ClientGameTestContext#takeScreenshot(String) taking screenshots},
* which capture the immediate state of the game.
*
* <p>A few changes have been made to how the vanilla game threads run, to make tests more reproducible. Notably, there
Expand Down Expand Up @@ -75,7 +86,7 @@
* <td>{@code 5}</td>
* <td>{@code 10}</td>
* <td>Speeds up loading of chunks, especially for functions such as
* {@link net.fabricmc.fabric.api.client.gametest.v1.TestClientWorldContext#waitForChunksRender() TestClientWorldContext.waitForChunksRender()}</td>
* {@link net.fabricmc.fabric.api.client.gametest.v1.context.TestClientWorldContext#waitForChunksRender() TestClientWorldContext.waitForChunksRender()}</td>
* </tr>
* <tr>
* <td>{@linkplain net.minecraft.client.option.GameOptions#getSoundVolumeOption(net.minecraft.sound.SoundCategory) Music volume}</td>
Expand All @@ -87,7 +98,7 @@
*
* <h2>World creation options</h2>
* These adjusted defaults only apply if the world builder's
* {@linkplain net.fabricmc.fabric.api.client.gametest.v1.TestWorldBuilder#setUseConsistentSettings(boolean) consistent settings}
* {@linkplain net.fabricmc.fabric.api.client.gametest.v1.world.TestWorldBuilder#setUseConsistentSettings(boolean) consistent settings}
* have not been set to {@code false}.
*
* <table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package net.fabricmc.fabric.api.client.gametest.v1;
package net.fabricmc.fabric.api.client.gametest.v1.screenshot;

import java.nio.file.Path;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package net.fabricmc.fabric.api.client.gametest.v1;
package net.fabricmc.fabric.api.client.gametest.v1.screenshot;

import com.google.common.base.Preconditions;
import org.jetbrains.annotations.ApiStatus;
Expand All @@ -23,7 +23,7 @@

import net.minecraft.client.texture.NativeImage;

import net.fabricmc.fabric.impl.client.gametest.TestScreenshotComparisonAlgorithms;
import net.fabricmc.fabric.impl.client.gametest.screenshot.TestScreenshotComparisonAlgorithms;

/**
* An algorithm for finding a template subimage (the "needle") in a screenshot (the "haystack"). Comparison algorithms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
* limitations under the License.
*/

package net.fabricmc.fabric.api.client.gametest.v1;
package net.fabricmc.fabric.api.client.gametest.v1.screenshot;

import com.google.common.base.Preconditions;
import org.jetbrains.annotations.ApiStatus;

import net.minecraft.client.texture.NativeImage;

import net.fabricmc.fabric.impl.client.gametest.TestScreenshotComparisonOptionsImpl;
import net.fabricmc.fabric.api.client.gametest.v1.context.ClientGameTestContext;
import net.fabricmc.fabric.impl.client.gametest.screenshot.TestScreenshotComparisonOptionsImpl;

/**
* Options for comparing screenshots.
Expand All @@ -37,10 +38,11 @@
* <p>Template images must be fully opaque, this API will throw if the template image has any transparent pixels.
*
* <p>Template images loaded from a path are expected to be in the {@code templates} directory inside the resources
* directory of the mod which registered the gametest. If the template image is not found, and the
* {@code fabric.client.gametest.testModResourcesPath} system property is set to the resources folder of the mod which
* registered the gametest, then the screenshot will be saved to the {@code templates} folder so that it can be used
* next time the gametest is run.
* directory of the mod which registered the gametest. If the template image is not found then the screenshot will be
* saved to the {@code templates} directory so that it can be used next time the gametest is run. Your test mod's
* resources directory is in the {@code fabric.client.gametest.testModResourcesPath} system property which is set by
* Loom by default. You may set this system property to override the location of the test mod resources directory. If
* this system property is unset and the template image is not found, then the test will fail.
*/
@ApiStatus.NonExtendable
public interface TestScreenshotComparisonOptions extends TestScreenshotCommonOptions<TestScreenshotComparisonOptions> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* limitations under the License.
*/

package net.fabricmc.fabric.api.client.gametest.v1;
package net.fabricmc.fabric.api.client.gametest.v1.screenshot;

import com.google.common.base.Preconditions;
import org.jetbrains.annotations.ApiStatus;

import net.fabricmc.fabric.impl.client.gametest.TestScreenshotOptionsImpl;
import net.fabricmc.fabric.impl.client.gametest.screenshot.TestScreenshotOptionsImpl;

/**
* Options to customize a screenshot.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ApiStatus.Experimental
package net.fabricmc.fabric.api.client.gametest.v1.screenshot;

import org.jetbrains.annotations.ApiStatus;
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package net.fabricmc.fabric.api.client.gametest.v1;
package net.fabricmc.fabric.api.client.gametest.v1.world;

import java.util.Properties;
import java.util.function.Consumer;
Expand All @@ -23,6 +23,9 @@

import net.minecraft.client.gui.screen.world.WorldCreator;

import net.fabricmc.fabric.api.client.gametest.v1.context.TestDedicatedServerContext;
import net.fabricmc.fabric.api.client.gametest.v1.context.TestSingleplayerContext;

/**
* A builder used for creating singleplayer worlds and dedicated servers.
*
Expand Down Expand Up @@ -63,6 +66,9 @@ public interface TestWorldBuilder {
/**
* Creates and starts a dedicated server with the configured world settings.
*
* <p>The dedicated server will only run if the EULA has been accepted in {@code eula.txt}. See
* {@link TestDedicatedServerContext} for details.
*
* @return The dedicated server context of the server that was created
*/
default TestDedicatedServerContext createServer() {
Expand All @@ -72,6 +78,9 @@ default TestDedicatedServerContext createServer() {
/**
* Creates and starts a dedicated server with the configured world settings and some custom server properties.
*
* <p>The dedicated server will only run if the EULA has been accepted in {@code eula.txt}. See
* {@link TestDedicatedServerContext} for details.
*
* @param serverProperties The custom server properties to be written to the {@code server.properties} file.
* @return The dedicated server context of the server that was created.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
* limitations under the License.
*/

package net.fabricmc.fabric.api.client.gametest.v1;
package net.fabricmc.fabric.api.client.gametest.v1.world;

import java.nio.file.Path;

import org.jetbrains.annotations.ApiStatus;

import net.fabricmc.fabric.api.client.gametest.v1.context.TestSingleplayerContext;

/**
* A handle for a singleplayer world save. Can be used to reopen a singleplayer world that was created earlier in the
* same gametest.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ApiStatus.Experimental
package net.fabricmc.fabric.api.client.gametest.v1.world;

import org.jetbrains.annotations.ApiStatus;
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

public class ClientGameTestMixinConfigPlugin implements IMixinConfigPlugin {
private static final boolean ENABLED = System.getProperty("fabric.client.gametest") != null;
static final boolean ENABLED = System.getProperty("fabric.client.gametest") != null;

@Override
public void onLoad(String mixinPackage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.TitleScreen;

import net.fabricmc.fabric.api.client.gametest.v1.ClientGameTestContext;
import net.fabricmc.fabric.api.client.gametest.v1.FabricClientGameTest;
import net.fabricmc.fabric.api.client.gametest.v1.context.ClientGameTestContext;
import net.fabricmc.fabric.impl.client.gametest.context.ClientGameTestContextImpl;
import net.fabricmc.fabric.impl.client.gametest.threading.ThreadingImpl;
import net.fabricmc.fabric.impl.client.gametest.util.WindowHooks;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.entrypoint.EntrypointContainer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;

import net.fabricmc.fabric.api.client.gametest.v1.ClientGameTestContext;
import net.fabricmc.fabric.api.client.gametest.v1.TestInput;
import net.fabricmc.fabric.mixin.client.gametest.KeyBindingAccessor;
import net.fabricmc.fabric.mixin.client.gametest.KeyboardAccessor;
import net.fabricmc.fabric.mixin.client.gametest.MouseAccessor;
import net.fabricmc.fabric.api.client.gametest.v1.context.ClientGameTestContext;
import net.fabricmc.fabric.impl.client.gametest.threading.ThreadingImpl;
import net.fabricmc.fabric.impl.client.gametest.util.WindowHooks;
import net.fabricmc.fabric.mixin.client.gametest.input.KeyBindingAccessor;
import net.fabricmc.fabric.mixin.client.gametest.input.KeyboardAccessor;
import net.fabricmc.fabric.mixin.client.gametest.input.MouseAccessor;

public final class TestInputImpl implements TestInput {
private static final Set<InputUtil.Key> KEYS_DOWN = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.impl.client.gametest;

import org.jetbrains.annotations.Nullable;

public final class TestSystemProperties {
private TestSystemProperties() {
}

// Whether client gametests are to be run. Reference the field in the mixin config plugin rather than the other way
// round so that this class isn't loaded before mixins are bootstrapped.
public static final boolean ENABLED = ClientGameTestMixinConfigPlugin.ENABLED;

// The resources path of the test mod to be written to by (e.g. screenshot) regression tests.
@Nullable
public static final String TEST_MOD_RESOURCES_PATH = System.getProperty("fabric.client.gametest.testModResourcesPath");

// Disable the network (packet) synchronizer.
public static final boolean DISABLE_NETWORK_SYNCHRONIZER = System.getProperty("fabric.client.gametest.disableNetworkSynchronizer") != null;

// Disable the joining of async stack traces in ThreadingImpl.
public static final boolean DISABLE_JOIN_ASYNC_STACK_TRACES = System.getProperty("fabric.client.gametest.disableJoinAsyncStackTraces") != null;
}
Loading

0 comments on commit b4f8aab

Please sign in to comment.