mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 11:29:15 +00:00
Revive executable jars for the dedicated server
This has a minor change to development time build scripts. So developers, check the MDK
This commit is contained in:
670 files changed
+3135
-3836
No files matched your search
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.core;
|
||||
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.IModLoadingState;
|
||||
import net.minecraftforge.fml.IModStateProvider;
|
||||
import net.minecraftforge.fml.ModLoadingPhase;
|
||||
import net.minecraftforge.fml.ModLoadingStage;
|
||||
import net.minecraftforge.fml.ModLoadingState;
|
||||
import net.minecraftforge.fml.config.ConfigTracker;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLConstructModEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provider for the core FML mod loading states.
|
||||
*/
|
||||
public class ModStateProvider implements IModStateProvider {
|
||||
/**
|
||||
* The special mod loading state for exceptional situations and error handling.
|
||||
*
|
||||
* @see ModLoadingPhase#ERROR
|
||||
*/
|
||||
final ModLoadingState ERROR = ModLoadingState.empty("ERROR", "",
|
||||
ModLoadingPhase.ERROR);
|
||||
|
||||
/**
|
||||
* First {@linkplain ModLoadingPhase#GATHER gathering state}, for the validation of the mod list.
|
||||
* TODO: figure out where this is used and why this exists instead of CONSTRUCT being the first state
|
||||
*/
|
||||
private final ModLoadingState VALIDATE = ModLoadingState.empty("VALIDATE", "",
|
||||
ModLoadingPhase.GATHER);
|
||||
|
||||
/**
|
||||
* {@linkplain ModLoadingPhase#GATHER Gathering state} after {@linkplain #VALIDATE validation}, for the construction
|
||||
* of mod containers and their backing mod instances.
|
||||
*
|
||||
* @see FMLConstructModEvent
|
||||
* @see ModLoadingStage#CONSTRUCT
|
||||
*/
|
||||
final ModLoadingState CONSTRUCT = ModLoadingState.withTransition("CONSTRUCT", "VALIDATE",
|
||||
ml -> "Constructing %d mods".formatted(ml.size()),
|
||||
ModLoadingPhase.GATHER,
|
||||
new ParallelTransition(ModLoadingStage.CONSTRUCT, FMLConstructModEvent.class));
|
||||
|
||||
/**
|
||||
* First {@linkplain ModLoadingPhase#LOAD loading state}, for loading of the common and (if applicable)
|
||||
* {@linkplain Dist#CLIENT client-side} mod configurations.
|
||||
*/
|
||||
private final ModLoadingState CONFIG_LOAD = ModLoadingState.withInline("CONFIG_LOAD", "",
|
||||
ModLoadingPhase.LOAD,
|
||||
ml -> {
|
||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT,
|
||||
() -> () -> ConfigTracker.INSTANCE.loadConfigs(ModConfig.Type.CLIENT, FMLPaths.CONFIGDIR.get()));
|
||||
ConfigTracker.INSTANCE.loadConfigs(ModConfig.Type.COMMON, FMLPaths.CONFIGDIR.get());
|
||||
});
|
||||
|
||||
/**
|
||||
* {@linkplain ModLoadingPhase#LOAD Loading state} after {@linkplain #CONFIG_LOAD configuration loading}, for
|
||||
* common (non-side-specific) setup and initialization.
|
||||
*
|
||||
* @see FMLCommonSetupEvent
|
||||
* @see ModLoadingStage#COMMON_SETUP
|
||||
*/
|
||||
private final ModLoadingState COMMON_SETUP = ModLoadingState.withTransition("COMMON_SETUP", "CONFIG_LOAD",
|
||||
ModLoadingPhase.LOAD,
|
||||
new ParallelTransition(ModLoadingStage.COMMON_SETUP, FMLCommonSetupEvent.class));
|
||||
|
||||
/**
|
||||
* {@linkplain ModLoadingPhase#LOAD Loading state} after {@linkplain #COMMON_SETUP common setup}, for side-specific
|
||||
* setup and initialization.
|
||||
*
|
||||
* @see FMLClientSetupEvent
|
||||
* @see FMLDedicatedServerSetupEvent
|
||||
* @see ModLoadingStage#SIDED_SETUP
|
||||
*/
|
||||
private final ModLoadingState SIDED_SETUP = ModLoadingState.withTransition("SIDED_SETUP", "COMMON_SETUP",
|
||||
ModLoadingPhase.LOAD,
|
||||
new ParallelTransition(ModLoadingStage.SIDED_SETUP,
|
||||
DistExecutor.unsafeRunForDist(()->()-> FMLClientSetupEvent.class, ()->()-> FMLDedicatedServerSetupEvent.class)));
|
||||
|
||||
/**
|
||||
* First {@linkplain ModLoadingPhase#COMPLETE completion state}, for enqueuing {@link net.minecraftforge.fml.InterModComms}
|
||||
* messages.
|
||||
*
|
||||
* @see InterModEnqueueEvent
|
||||
* @see ModLoadingStage#ENQUEUE_IMC
|
||||
*/
|
||||
private final ModLoadingState ENQUEUE_IMC = ModLoadingState.withTransition("ENQUEUE_IMC", "",
|
||||
ModLoadingPhase.COMPLETE,
|
||||
new ParallelTransition(ModLoadingStage.ENQUEUE_IMC, InterModEnqueueEvent.class));
|
||||
|
||||
/**
|
||||
* {@linkplain ModLoadingPhase#COMPLETE Completion state} after {@linkplain #ENQUEUE_IMC}, for processing of messages
|
||||
* received through {@link net.minecraftforge.fml.InterModComms}.
|
||||
*
|
||||
* @see InterModProcessEvent
|
||||
* @see ModLoadingStage#PROCESS_IMC
|
||||
*/
|
||||
private final ModLoadingState PROCESS_IMC = ModLoadingState.withTransition("PROCESS_IMC", "ENQUEUE_IMC",
|
||||
ModLoadingPhase.COMPLETE,
|
||||
new ParallelTransition(ModLoadingStage.PROCESS_IMC, InterModProcessEvent.class));
|
||||
|
||||
/**
|
||||
* {@linkplain ModLoadingPhase#COMPLETE Completion state} after {@linkplain #PROCESS_IMC}, marking the completion
|
||||
* of the basic mod loading process; however, additional completion states may be present after this.
|
||||
*
|
||||
* @see FMLLoadCompleteEvent
|
||||
* @see ModLoadingStage#COMPLETE
|
||||
*/
|
||||
private final ModLoadingState COMPLETE = ModLoadingState.withTransition("COMPLETE", "PROCESS_IMC",
|
||||
ml -> "completing load of %d mods".formatted(ml.size()),
|
||||
ModLoadingPhase.COMPLETE,
|
||||
new ParallelTransition(ModLoadingStage.COMPLETE, FMLLoadCompleteEvent.class));
|
||||
|
||||
/**
|
||||
* The marker state for the completion of the full mod loading process.
|
||||
*
|
||||
* @see ModLoadingStage#DONE
|
||||
*/
|
||||
private final ModLoadingState DONE = ModLoadingState.empty("DONE", "",
|
||||
ModLoadingPhase.DONE);
|
||||
|
||||
@Override
|
||||
public List<IModLoadingState> getAllStates() {
|
||||
return List.of(ERROR, VALIDATE, CONSTRUCT, CONFIG_LOAD, COMMON_SETUP, SIDED_SETUP, ENQUEUE_IMC, PROCESS_IMC, COMPLETE, DONE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.core;
|
||||
|
||||
import cpw.mods.modlauncher.api.LamdbaExceptionUtils;
|
||||
import net.minecraftforge.fml.IModStateTransition;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModLoadingStage;
|
||||
import net.minecraftforge.fml.ThreadSelector;
|
||||
import net.minecraftforge.fml.event.lifecycle.ParallelDispatchEvent;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
record ParallelTransition(ModLoadingStage stage, Class<? extends ParallelDispatchEvent> event) implements IModStateTransition {
|
||||
@Override
|
||||
public Supplier<Stream<EventGenerator<?>>> eventFunctionStream() {
|
||||
return () -> Stream.of(IModStateTransition.EventGenerator.fromFunction(LamdbaExceptionUtils.rethrowFunction((ModContainer mc) -> event.getConstructor(ModContainer.class, ModLoadingStage.class).newInstance(mc, stage))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThreadSelector threadSelector() {
|
||||
return ThreadSelector.PARALLEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiFunction<Executor, CompletableFuture<Void>, CompletableFuture<Void>> finalActivityGenerator() {
|
||||
return (e, prev) -> prev.thenApplyAsync(t -> {
|
||||
stage.getDeferredWorkQueue().runTasks();
|
||||
return t;
|
||||
}, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiFunction<Executor, ? extends EventGenerator<?>, CompletableFuture<Void>> preDispatchHook() {
|
||||
return (t, f) -> CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiFunction<Executor, ? extends EventGenerator<?>, CompletableFuture<Void>> postDispatchHook() {
|
||||
return (t, f) -> CompletableFuture.completedFuture(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.event.config;
|
||||
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.config.IConfigEvent;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
|
||||
public class ModConfigEvent extends Event implements IModBusEvent, IConfigEvent {
|
||||
private final ModConfig config;
|
||||
|
||||
ModConfigEvent(final ModConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired during mod and server loading, depending on {@link ModConfig.Type} of config file.
|
||||
* Any Config objects associated with this will be valid and can be queried directly.
|
||||
*/
|
||||
public static class Loading extends ModConfigEvent {
|
||||
public Loading(final ModConfig config) {
|
||||
super(config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when the configuration is changed. This can be caused by a change to the config
|
||||
* from a UI or from editing the file itself. IMPORTANT: this can fire at any time
|
||||
* and may not even be on the server or client threads. Ensure you properly synchronize
|
||||
* any resultant changes.
|
||||
*/
|
||||
public static class Reloading extends ModConfigEvent {
|
||||
public Reloading(final ModConfig config) {
|
||||
super(config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a config is unloaded. This only happens when the server closes, which is
|
||||
* probably only really relevant on the client, to reset internal mod state when the
|
||||
* server goes away, though it will fire on the dedicated server as well.
|
||||
* The config file will be saved after this event has fired.
|
||||
*/
|
||||
public static class Unloading extends ModConfigEvent {
|
||||
public Unloading(final ModConfig config) {
|
||||
super(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.event.lifecycle;
|
||||
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModLoadingStage;
|
||||
|
||||
|
||||
/**
|
||||
* This is the second of four commonly called events during mod lifecycle startup.
|
||||
*
|
||||
* Called before {@link InterModEnqueueEvent}
|
||||
* Called after {@link FMLCommonSetupEvent}
|
||||
*
|
||||
* Called on {@link net.minecraftforge.api.distmarker.Dist#CLIENT} - the game client.
|
||||
*
|
||||
* Alternative to {@link FMLDedicatedServerSetupEvent}.
|
||||
*
|
||||
* Do client only setup with this event, such as KeyBindings.
|
||||
*
|
||||
* This is a parallel dispatch event.
|
||||
*/
|
||||
public class FMLClientSetupEvent extends ParallelDispatchEvent
|
||||
{
|
||||
public FMLClientSetupEvent(ModContainer container, ModLoadingStage stage)
|
||||
{
|
||||
super(container, stage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.event.lifecycle;
|
||||
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.DeferredWorkQueue;
|
||||
import net.minecraftforge.fml.ModLoadingStage;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* This is the first of four commonly called events during mod initialization.
|
||||
*
|
||||
* Called after {@link net.minecraftforge.registries.RegisterEvent} events have been fired and before
|
||||
* {@link FMLClientSetupEvent} or {@link FMLDedicatedServerSetupEvent} during mod startup.
|
||||
*
|
||||
* Either register your listener using {@link net.minecraftforge.fml.javafmlmod.AutomaticEventSubscriber} and
|
||||
* {@link net.minecraftforge.eventbus.api.SubscribeEvent} or
|
||||
* {@link net.minecraftforge.eventbus.api.IEventBus#addListener(Consumer)} in your constructor.
|
||||
*
|
||||
* Most non-specific mod setup will be performed here. Note that this is a parallel dispatched event - you cannot
|
||||
* interact with game state in this event.
|
||||
*
|
||||
* @see DeferredWorkQueue to enqueue work to run on the main game thread after this event has
|
||||
* completed dispatch
|
||||
*/
|
||||
public class FMLCommonSetupEvent extends ParallelDispatchEvent
|
||||
{
|
||||
public FMLCommonSetupEvent(final ModContainer container, final ModLoadingStage stage)
|
||||
{
|
||||
super(container, stage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.event.lifecycle;
|
||||
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModLoadingStage;
|
||||
|
||||
public class FMLConstructModEvent extends ParallelDispatchEvent {
|
||||
public FMLConstructModEvent(final ModContainer container, final ModLoadingStage stage) {
|
||||
super(container, stage);
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.event.lifecycle;
|
||||
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModLoadingStage;
|
||||
|
||||
/**
|
||||
* This is the second of four commonly called events during mod core startup.
|
||||
*
|
||||
* Called before {@link InterModEnqueueEvent}
|
||||
* Called after {@link FMLCommonSetupEvent}
|
||||
*
|
||||
* Called on {@link net.minecraftforge.api.distmarker.Dist#DEDICATED_SERVER} - the dedicated game server.
|
||||
*
|
||||
* Alternative to {@link FMLClientSetupEvent}.
|
||||
*
|
||||
* Do dedicated server specific activities with this event.
|
||||
*
|
||||
* <em>This event is fired before construction of the dedicated server. Use {@code FMLServerAboutToStartEvent}
|
||||
* or {@code FMLServerStartingEvent} to do stuff with the server, in both dedicated
|
||||
* and integrated server contexts</em>
|
||||
*
|
||||
* This is a parallel dispatch event.
|
||||
*/
|
||||
public class FMLDedicatedServerSetupEvent extends ParallelDispatchEvent
|
||||
{
|
||||
public FMLDedicatedServerSetupEvent(ModContainer container, ModLoadingStage stage)
|
||||
{
|
||||
super(container, stage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.event.lifecycle;
|
||||
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModLoadingStage;
|
||||
|
||||
/**
|
||||
* This is a mostly internal event fired to mod containers that indicates that loading is complete. Mods should not
|
||||
* in general override or otherwise attempt to implement this event.
|
||||
*
|
||||
* @author cpw
|
||||
*/
|
||||
public class FMLLoadCompleteEvent extends ParallelDispatchEvent
|
||||
{
|
||||
public FMLLoadCompleteEvent(final ModContainer container, final ModLoadingStage stage)
|
||||
{
|
||||
super(container, stage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.event.lifecycle;
|
||||
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModLoadingStage;
|
||||
|
||||
/**
|
||||
* This is the third of four commonly called events during mod core startup.
|
||||
*
|
||||
* Called before {@link InterModProcessEvent}
|
||||
* Called after {@link FMLClientSetupEvent} or {@link FMLDedicatedServerSetupEvent}
|
||||
*
|
||||
*
|
||||
* Enqueue {@link net.minecraftforge.fml.InterModComms} messages to other mods with this event.
|
||||
*
|
||||
* This is a parallel dispatch event.
|
||||
*/
|
||||
public class InterModEnqueueEvent extends ParallelDispatchEvent
|
||||
{
|
||||
|
||||
public InterModEnqueueEvent(final ModContainer container, final ModLoadingStage stage)
|
||||
{
|
||||
super(container, stage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.event.lifecycle;
|
||||
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModLoadingStage;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* This is the fourth of four commonly called events during mod core startup.
|
||||
*
|
||||
* Called after {@link InterModEnqueueEvent}
|
||||
*
|
||||
* Retrieve {@link net.minecraftforge.fml.InterModComms} {@link net.minecraftforge.fml.InterModComms.IMCMessage} suppliers
|
||||
* and process them as you wish with this event.
|
||||
*
|
||||
* This is a parallel dispatch event.
|
||||
*
|
||||
* @see #getIMCStream()
|
||||
* @see #getIMCStream(Predicate)
|
||||
*/
|
||||
public class InterModProcessEvent extends ParallelDispatchEvent
|
||||
{
|
||||
public InterModProcessEvent(final ModContainer container, final ModLoadingStage stage)
|
||||
{
|
||||
super(container, stage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.event.lifecycle;
|
||||
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.InterModComms;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Parent type to all ModLifecycle events. This is based on Forge EventBus. They fire through the
|
||||
* ModContainer's eventbus instance.
|
||||
*/
|
||||
public class ModLifecycleEvent extends Event implements IModBusEvent
|
||||
{
|
||||
private final ModContainer container;
|
||||
|
||||
public ModLifecycleEvent(ModContainer container)
|
||||
{
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
public final String description()
|
||||
{
|
||||
String cn = getClass().getName();
|
||||
return cn.substring(cn.lastIndexOf('.')+1);
|
||||
}
|
||||
|
||||
public Stream<InterModComms.IMCMessage> getIMCStream() {
|
||||
return InterModComms.getMessages(this.container.getModId());
|
||||
}
|
||||
|
||||
public Stream<InterModComms.IMCMessage> getIMCStream(Predicate<String> methodFilter) {
|
||||
return InterModComms.getMessages(this.container.getModId(), methodFilter);
|
||||
}
|
||||
|
||||
ModContainer getContainer() {
|
||||
return this.container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return description();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.event.lifecycle;
|
||||
|
||||
import net.minecraftforge.fml.DeferredWorkQueue;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModLoadingStage;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ParallelDispatchEvent extends ModLifecycleEvent {
|
||||
private final ModLoadingStage modLoadingStage;
|
||||
|
||||
public ParallelDispatchEvent(final ModContainer container, final ModLoadingStage stage) {
|
||||
super(container);
|
||||
this.modLoadingStage = stage;
|
||||
}
|
||||
|
||||
private Optional<DeferredWorkQueue> getQueue() {
|
||||
return DeferredWorkQueue.lookup(Optional.of(modLoadingStage));
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> enqueueWork(Runnable work) {
|
||||
return getQueue().map(q->q.enqueueWork(getContainer(), work)).orElseThrow(()->new RuntimeException("No work queue found!"));
|
||||
}
|
||||
|
||||
public <T> CompletableFuture<T> enqueueWork(Supplier<T> work) {
|
||||
return getQueue().map(q->q.enqueueWork(getContainer(), work)).orElseThrow(()->new RuntimeException("No work queue found!"));
|
||||
}
|
||||
}
|
||||
@@ -8,14 +8,12 @@ package net.minecraftforge.versions.forge;
|
||||
import net.minecraftforge.fml.Logging;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.VersionChecker;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.fml.loading.JarVersionLookupHandler;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ForgeVersion
|
||||
{
|
||||
public class ForgeVersion {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
// This is Forge's Mod Id, used for the ForgeMod and resource locations
|
||||
public static final String MOD_ID = "forge";
|
||||
@@ -26,35 +24,29 @@ public class ForgeVersion
|
||||
|
||||
static {
|
||||
LOGGER.debug(Logging.CORE, "Forge Version package {} from {}", ForgeVersion.class.getPackage(), ForgeVersion.class.getClassLoader());
|
||||
String vers = JarVersionLookupHandler.getImplementationVersion(ForgeVersion.class).orElse(FMLLoader.versionInfo().forgeVersion());
|
||||
if (vers == null) throw new RuntimeException("Missing forge version, cannot continue");
|
||||
String spec = JarVersionLookupHandler.getSpecificationVersion(ForgeVersion.class).orElse(System.getenv("FORGE_SPEC"));
|
||||
if (spec == null) throw new RuntimeException("Missing forge spec, cannot continue");
|
||||
String group = JarVersionLookupHandler.getImplementationTitle(ForgeVersion.class).orElse(FMLLoader.versionInfo().forgeGroup());
|
||||
if (group == null) {
|
||||
group = "net.minecraftforge"; // If all else fails, Our normal group
|
||||
}
|
||||
forgeVersion = vers;
|
||||
forgeSpec = spec;
|
||||
forgeGroup = group;
|
||||
var info = JarVersionLookupHandler.getInfo(ForgeVersion.class);
|
||||
|
||||
if (info.impl().version().isEmpty() || info.spec().version().isEmpty())
|
||||
throw new IllegalStateException("Failed to find version for package " + ForgeVersion.class.getPackageName() + " This is an invalid environment");
|
||||
|
||||
forgeSpec = info.spec().version().get();
|
||||
forgeVersion = info.impl().version().get();
|
||||
forgeGroup = "net.minecraftforge";
|
||||
LOGGER.debug(Logging.CORE, "Found Forge version {}", forgeVersion);
|
||||
LOGGER.debug(Logging.CORE, "Found Forge spec {}", forgeSpec);
|
||||
LOGGER.debug(Logging.CORE, "Found Forge group {}", forgeGroup);
|
||||
}
|
||||
|
||||
public static String getVersion()
|
||||
{
|
||||
public static String getVersion() {
|
||||
return forgeVersion;
|
||||
}
|
||||
|
||||
public static VersionChecker.Status getStatus()
|
||||
{
|
||||
public static VersionChecker.Status getStatus() {
|
||||
return VersionChecker.getResult(ModList.get().getModFileById(MOD_ID).getMods().get(0)).status();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getTarget()
|
||||
{
|
||||
public static String getTarget() {
|
||||
VersionChecker.CheckResult res = VersionChecker.getResult(ModList.get().getModFileById(MOD_ID).getMods().get(0));
|
||||
return res.target() == null ? "" : res.target().toString();
|
||||
}
|
||||
|
||||
@@ -9,24 +9,25 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraftforge.fml.Logging;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.fml.loading.JarVersionLookupHandler;
|
||||
|
||||
public class MCPVersion {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final String mcVersion;
|
||||
private static final String mcpVersion;
|
||||
|
||||
static {
|
||||
LOGGER.debug(Logging.CORE, "MCP Version package {} from {}", MCPVersion.class.getPackage(), MCPVersion.class.getClassLoader());
|
||||
mcVersion = JarVersionLookupHandler.getSpecificationVersion(MCPVersion.class).orElse(FMLLoader.versionInfo().mcVersion());
|
||||
if (mcVersion == null) throw new RuntimeException("Missing MC version, cannot continue");
|
||||
|
||||
mcpVersion = JarVersionLookupHandler.getImplementationVersion(MCPVersion.class).orElse(FMLLoader.versionInfo().mcpVersion());
|
||||
if (mcpVersion == null) throw new RuntimeException("Missing MCP version, cannot continue");
|
||||
var info = JarVersionLookupHandler.getInfo(MCPVersion.class);
|
||||
if (info.spec().version().isEmpty() || info.impl().version().isEmpty())
|
||||
throw new IllegalStateException("Failed to find version for package " + MCPVersion.class.getPackageName() + " This is an invalid environment");
|
||||
|
||||
mcVersion = info.spec().version().get();
|
||||
mcpVersion = info.impl().version().get();
|
||||
LOGGER.debug(Logging.CORE, "Found MC version information {}", mcVersion);
|
||||
LOGGER.debug(Logging.CORE, "Found MCP version information {}", mcpVersion);
|
||||
}
|
||||
|
||||
public static String getMCVersion() {
|
||||
return mcVersion;
|
||||
}
|
||||
@@ -35,8 +36,7 @@ public class MCPVersion {
|
||||
return mcpVersion;
|
||||
}
|
||||
|
||||
public static String getMCPandMCVersion()
|
||||
{
|
||||
return mcVersion+"-"+mcpVersion;
|
||||
public static String getMCPandMCVersion() {
|
||||
return mcVersion + "-" + mcpVersion;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user