mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-26 15:03:04 +00:00
Forge 1.19
* Bump pack.mcmeta formats * 1.19 biome modifiers * Mark ClientPlayerNetworkEvent.LoggedOutEvent's getters as nullable * Add docs and package-info to client extension interfaces package * Move RenderBlockOverlayEvent hooks to ForgeHooksClient * Add package-infos to client events package * Rename SoundLoadEvent to SoundEngineLoadEvent This reduces confusion from consumers which may think the name SoundLoadEvent refers to an individual sound being loaded rather than the sound engine. * Document and change SoundLoadEvent to fire on mod bus Previously, it fired on both the mod bus and the Forge bus, which is confusing for consumers. * Delete SoundSetupEvent Looking at its original implementation shows that there isn't an appropriate place in the new sound code to reinsert the event, and the place of 'sound engine/manager initialization event' is taken already by SoundLoadEvent. * Perform some cleanup on client events - Removed nullable annotations from ClientPlayerNetworkEvent - Renamed #getPartialTicks methods to #getPartialTick, to be consistent with vanilla's naming of the partial tick - Cleanup documentation to remove line breaks, use the spelling 'cancelled' over 'canceled', and improve docs on existing and new methods. * Remove EntityEvent.CanUpdate Closes MinecraftForge/MinecraftForge#6394 * Switch to Jetbrains nullability annotations * New PlayLevelSoundEvent; replaces old PlaySoundAtEntityEvent * Remove ForgeWorldPresetScreens * Remove IForgeRegistryEntry * Remove use of List<Throwable> in FML's CompletableFutures * Add docs to mod loading stages, stages, and phases * Gradle 7.4.2 * Use SLF4J in FMLLoader and other subprojects * Switch dynamic versions in subprojects to pinned ones * Switch ForgeRoot and MDK to FG plugin markers * Configure Forge javadoc task The task now uses a custom stylesheet with MCForge elements, and configured to combine the generation from the four FML subprojects (fmlloader, fmlcore, javafmllanguage, mclanguage) and the Forge project into the javadoc output. * Update docs/md files, for 1.19 update and the move away from IRC to Discord. * Make "Potentially dangerous alternative prefix" a debug warning, not info. Co-authored-by: Curle <[email protected]> Co-authored-by: sciwhiz12 <[email protected]> Signed-off-by: SizableShrimp <[email protected]>
This commit is contained in:
1 parent
270e778ac5
commit
4ed9117799
1485 files changed
+14960
-15446
No files matched your search
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.eventtest.internal;
|
||||
|
||||
/**
|
||||
* The basis of the Event regression testing framework.
|
||||
* Allows each bootstrap event to be queried in turn to see whether the event passed.
|
||||
* For gameplay events, a callback is set for when the respective event is fired.
|
||||
*
|
||||
* Test cases should be in a subclass of this, annotated with TestHolder.
|
||||
* If the test is for an event that fires in Bootstrap, set the field in constructor.
|
||||
* Register the event handler in the registerEvents method, which will be fired automatically.
|
||||
*
|
||||
* Use the pass / fail / error methods in this class to tell the Framework what the result of the test is.
|
||||
*
|
||||
* @author Curle
|
||||
*/
|
||||
public abstract class EventTest {
|
||||
protected Result testResult = Result.NOT_PROCESSED;
|
||||
protected String errorDetail = "Event not processed";
|
||||
protected boolean bootstrap; // true for events that fire when the game is loading to the main menu. false for events that fire after the game has loaded.
|
||||
|
||||
/**
|
||||
* A summarised view of the test result.
|
||||
* For passes: "PASS"
|
||||
* For failures: "FAIL - ($errorDetail)"
|
||||
* @return test result
|
||||
*/
|
||||
public String getTestResult() {
|
||||
return (testResult.passed() ? "PASS" : "FAIL; ") + (testResult.failed() ? getEnhancedDetail() : "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide extra detail about the error.
|
||||
* Pass-through of errorDetail is default, but some events require something more robust.
|
||||
* @return information to be shown in case of a test failure
|
||||
*/
|
||||
protected String getEnhancedDetail() { return errorDetail; }
|
||||
|
||||
/**
|
||||
* @return whether or not this event should be monitored while the game is loading to the main menu.
|
||||
*/
|
||||
public boolean isBootstrap() { return bootstrap; }
|
||||
|
||||
/**
|
||||
* Register event handlers for this event.
|
||||
* Trade-off between "magic annotations" and verbosity should be evaluated.
|
||||
*/
|
||||
public abstract void registerEvents();
|
||||
|
||||
/**
|
||||
* Helper method - combines setting failure state with detail message.
|
||||
* @param reason extra detail about why the failure occurred
|
||||
*/
|
||||
protected void fail(String reason) {
|
||||
testResult = Result.FAIL;
|
||||
errorDetail = reason;
|
||||
|
||||
TestFramework.testChangedState(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method - sets the test pass flag.
|
||||
*/
|
||||
protected void pass() {
|
||||
testResult = Result.PASS;
|
||||
|
||||
TestFramework.testChangedState(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method - combines setting error state with detail message.
|
||||
* @param reason extra detail about why the error occured.
|
||||
*/
|
||||
protected void error(String reason) {
|
||||
testResult = Result.TESTFAIL;
|
||||
errorDetail = reason;
|
||||
|
||||
TestFramework.testChangedState(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes information about how the test progressed.
|
||||
*/
|
||||
public enum Result {
|
||||
PASS, // The test passed with no errors
|
||||
FAIL, // The code being tested failed to meet the requirements
|
||||
TESTFAIL, // The test threw an error when trying to evaluate the requirements
|
||||
NOT_PROCESSED; // The test was not fired, or did not return a result.
|
||||
|
||||
/**
|
||||
* @return whether the test passed.
|
||||
*/
|
||||
public boolean passed() {
|
||||
return this == PASS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether the test or the code being tested failed.
|
||||
*/
|
||||
public boolean failed() {
|
||||
return this != PASS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether the test encountered an error
|
||||
*/
|
||||
public boolean errored() {
|
||||
return this == TESTFAIL;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.eventtest.internal;
|
||||
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import net.minecraftforge.client.event.ScreenOpenEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.GameShuttingDownEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.loading.LoadingModList;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.core.LoggerContext;
|
||||
import org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender;
|
||||
import org.apache.logging.log4j.core.appender.rolling.OnStartupTriggeringPolicy;
|
||||
import org.apache.logging.log4j.core.config.Configuration;
|
||||
import org.apache.logging.log4j.core.config.LoggerConfig;
|
||||
import org.apache.logging.log4j.core.layout.PatternLayout;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The backend of the "curletest" event testing framework.
|
||||
* All tests are registered to this class, and are set up according to the needs they declare.
|
||||
*
|
||||
* All bootstrap tests will be summed up into a log file when the main menu loads.
|
||||
* All gameplay events will be printed to the console when they fire, and written to the above log.
|
||||
*
|
||||
* To register a new event test, simply create the class in the events package and add it to the list here.
|
||||
*/
|
||||
@Mod(TestFramework.MODID)
|
||||
public class TestFramework {
|
||||
public static final String MODID = "eventtests";
|
||||
|
||||
final List<EventTest> tests;
|
||||
final static Map<EventTest, String> testNames = new HashMap<>();
|
||||
final static Logger LOGGER = LogManager.getLogger();
|
||||
final static Type CURLETEST_ANNOTATION = Type.getType(TestHolder.class);
|
||||
|
||||
boolean bootstrapHandled = false;
|
||||
|
||||
/**
|
||||
* Pre-initialize the framework and all events.
|
||||
*/
|
||||
public TestFramework() {
|
||||
prepareLogger();
|
||||
|
||||
LOGGER.info("Preparing all event tests.");
|
||||
|
||||
tests = gatherEvents();
|
||||
// Let each event set up
|
||||
tests.forEach(EventTest::registerEvents);
|
||||
|
||||
// Register the screen opened listener.
|
||||
// The main menu signals the end of the bootstrap tests.
|
||||
MinecraftForge.EVENT_BUS.addListener(this::collectBootstrapTests);
|
||||
|
||||
// Register the game shutting down listener.
|
||||
// If there are any unhandled tests after shutdown, notify of an event not fired.
|
||||
MinecraftForge.EVENT_BUS.addListener(this::collectMissedTests);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gameplay events require to be able to notify the framework when their task is completed.
|
||||
* Bootstrap events are ignored when updates occur.
|
||||
*/
|
||||
public static void testChangedState(EventTest test) {
|
||||
if(test.isBootstrap()) return;
|
||||
|
||||
LOGGER.info("Test " + testNames.get(test) + ": " + test.getTestResult());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enumerate all tests that should be ran with the framework.
|
||||
* All classes with the @TestHolder annotation are resolved and instantiated as tests.
|
||||
*
|
||||
* @return all tests to run
|
||||
*/
|
||||
private List<EventTest> gatherEvents() {
|
||||
var tests = new ArrayList<EventTest>();
|
||||
|
||||
// Search all annotations in the current mod, filter for @CurleTest, and condense to a list.
|
||||
var anns = LoadingModList.get().getModFileById(MODID).getFile().getScanResult().getAnnotations()
|
||||
.stream()
|
||||
.filter(ann -> CURLETEST_ANNOTATION.equals(ann.annotationType()))
|
||||
.toList();
|
||||
|
||||
// For each instance of the annotation, resolve the class it's attached to, create a new instance, and add it to the list.
|
||||
anns.forEach(annotationData -> {
|
||||
Class<?> clazz;
|
||||
try {
|
||||
clazz = Class.forName(annotationData.clazz().getClassName());
|
||||
EventTest instance = (EventTest) clazz.getDeclaredConstructor().newInstance();
|
||||
tests.add(instance);
|
||||
testNames.put(instance, (String) annotationData.annotationData().get("value"));
|
||||
} catch (ClassNotFoundException | InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
return tests;
|
||||
}
|
||||
|
||||
/**
|
||||
* At the mark of the end of the bootstrap period, collect and log all test results.
|
||||
* the ScreenOpenEvent fired by TitleScreen is the last event fired without user interaction, so it is the
|
||||
* end of the "automatic" bootstrap time.
|
||||
*/
|
||||
private void collectBootstrapTests(ScreenOpenEvent event) {
|
||||
if(!(event.getScreen() instanceof TitleScreen) || bootstrapHandled)
|
||||
return;
|
||||
|
||||
LOGGER.info("Preparing to run bootstrap tests:");
|
||||
tests.forEach(test -> {
|
||||
if(test.isBootstrap()) {
|
||||
LOGGER.info(" - " + testNames.get(test) + ": " + test.getTestResult());
|
||||
}
|
||||
});
|
||||
LOGGER.info("All bootstrap tests evaluated.");
|
||||
|
||||
bootstrapHandled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for unfired events when the game is shutting down.
|
||||
* Summarise all test results.
|
||||
*/
|
||||
private void collectMissedTests(GameShuttingDownEvent event) {
|
||||
LOGGER.info("Test summary processing..");
|
||||
tests.forEach(test -> {
|
||||
LOGGER.info("\tTest " + testNames.get(test) + ": ");
|
||||
LOGGER.info(test.testResult == EventTest.Result.NOT_PROCESSED ?
|
||||
"\t\tMISSED - Not fired." :
|
||||
"\t\t" + test.getTestResult()
|
||||
);
|
||||
});
|
||||
LOGGER.info("Event Test Framework finished.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the LOGGER instance in this class to only write to logs/curletest.log.
|
||||
* Log4J is annoying and requires manual initialization and preparation.
|
||||
*/
|
||||
private void prepareLogger() {
|
||||
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
|
||||
final Configuration config = ctx.getConfiguration();
|
||||
final LoggerConfig loggerConfig = getLoggerConfiguration(config, LOGGER.getName());
|
||||
|
||||
final RollingRandomAccessFileAppender appender = RollingRandomAccessFileAppender.newBuilder()
|
||||
.setName("EventTestLog")
|
||||
.withFileName("logs/curletest.log")
|
||||
.withFilePattern("logs/%d{yyyy-MM-dd}-%i.log.gz")
|
||||
.setLayout(PatternLayout.newBuilder()
|
||||
.withPattern("[%d{ddMMMyyyy HH:mm:ss}] [%logger]: %minecraftFormatting{%msg}{strip}%n%xEx")
|
||||
.build()
|
||||
)
|
||||
.withPolicy(
|
||||
OnStartupTriggeringPolicy.createPolicy(1)
|
||||
)
|
||||
.build();
|
||||
|
||||
appender.start();
|
||||
|
||||
loggerConfig.setParent(null);
|
||||
loggerConfig.getAppenders().keySet().forEach(loggerConfig::removeAppender);
|
||||
loggerConfig.addAppender(
|
||||
appender,
|
||||
Level.INFO,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
private static LoggerConfig getLoggerConfiguration(@NotNull final Configuration configuration, @NotNull final String loggerName)
|
||||
{
|
||||
final LoggerConfig lc = configuration.getLoggerConfig(loggerName);
|
||||
if (lc.getName().equals(loggerName))
|
||||
{
|
||||
return lc;
|
||||
}
|
||||
else
|
||||
{
|
||||
final LoggerConfig nlc = new LoggerConfig(loggerName, lc.getLevel(), lc.isAdditive());
|
||||
nlc.setParent(lc);
|
||||
configuration.addLogger(loggerName, nlc);
|
||||
configuration.getLoggerContext().updateLoggers();
|
||||
|
||||
return nlc;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.eventtest.internal;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* A marker annotation used with the Event Testing Framework.
|
||||
* Can only be placed on a class, enum or record.
|
||||
*
|
||||
* This annotation is used with FML Scan Data to construct and register the test automatically.
|
||||
* The testName field is used in the output of the test.
|
||||
*
|
||||
* @author Curle
|
||||
*/
|
||||
@Target({ElementType.TYPE})
|
||||
public @interface TestHolder {
|
||||
String value();
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.eventtest.tests.forge.client;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||
import net.minecraftforge.eventtest.internal.EventTest;
|
||||
import net.minecraftforge.eventtest.internal.TestHolder;
|
||||
|
||||
/**
|
||||
* Test case for the EntityJoinWorldEvent.
|
||||
*
|
||||
* Event fires during gameplay.
|
||||
* Success condition:
|
||||
* EntityJoinWorldEvent fired for Minecraft.getInstance().player
|
||||
* Failure info:
|
||||
* "EntityJoinWorldEvent was not fired"
|
||||
*
|
||||
*/
|
||||
|
||||
@TestHolder("EntityJoinWorld")
|
||||
public class EntityJoinedWorldTest extends EventTest {
|
||||
|
||||
@Override
|
||||
public void registerEvents() {
|
||||
MinecraftForge.EVENT_BUS.addListener(this::eventListener);
|
||||
}
|
||||
|
||||
private void eventListener(EntityJoinWorldEvent event) {
|
||||
final Entity eventEntity = event.getEntity();
|
||||
final Player gamePlayer = Minecraft.getInstance().player;
|
||||
|
||||
final boolean eventFiredForPlayer = eventEntity == gamePlayer;
|
||||
|
||||
if(eventFiredForPlayer)
|
||||
pass();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user