mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-23 21:49:46 +00:00
Redo event dispatch, removes a bunch of nonsense, and tries to integrate with the vanilla CF system where possible
Signed-off-by: cpw <[email protected]>
This commit is contained in:
24 files changed
+570
-617
No files matched your search
@@ -38,14 +38,14 @@ import java.util.function.Supplier;
|
||||
*
|
||||
* This is a parallel dispatch event.
|
||||
*/
|
||||
public class FMLClientSetupEvent extends ModLifecycleEvent
|
||||
public class FMLClientSetupEvent extends ParallelDispatchEvent
|
||||
{
|
||||
private final Supplier<Minecraft> minecraftSupplier;
|
||||
|
||||
public FMLClientSetupEvent(Supplier<Minecraft> mc, ModContainer container)
|
||||
public FMLClientSetupEvent(ModContainer container)
|
||||
{
|
||||
super(container);
|
||||
this.minecraftSupplier = mc;
|
||||
minecraftSupplier = Minecraft::getInstance;
|
||||
}
|
||||
|
||||
public Supplier<Minecraft> getMinecraftSupplier()
|
||||
|
||||
@@ -40,7 +40,7 @@ import java.util.function.Consumer;
|
||||
* @see net.minecraftforge.fml.DeferredWorkQueue to enqueue work to run on the main game thread after this event has
|
||||
* completed dispatch
|
||||
*/
|
||||
public class FMLCommonSetupEvent extends ModLifecycleEvent
|
||||
public class FMLCommonSetupEvent extends ParallelDispatchEvent
|
||||
{
|
||||
public FMLCommonSetupEvent(final ModContainer container)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package net.minecraftforge.fml.event.lifecycle;
|
||||
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
|
||||
public class FMLConstructModEvent extends ParallelDispatchEvent {
|
||||
public FMLConstructModEvent(final ModContainer container) {
|
||||
super(container);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -42,7 +42,7 @@ import java.util.function.Supplier;
|
||||
*
|
||||
* This is a parallel dispatch event.
|
||||
*/
|
||||
public class FMLDedicatedServerSetupEvent extends ModLifecycleEvent
|
||||
public class FMLDedicatedServerSetupEvent extends ParallelDispatchEvent
|
||||
{
|
||||
public FMLDedicatedServerSetupEvent(ModContainer container)
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ import net.minecraftforge.fml.ModContainer;
|
||||
*
|
||||
* @author cpw
|
||||
*/
|
||||
public class FMLLoadCompleteEvent extends ModLifecycleEvent
|
||||
public class FMLLoadCompleteEvent extends ParallelDispatchEvent
|
||||
{
|
||||
public FMLLoadCompleteEvent(final ModContainer container)
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ import net.minecraftforge.fml.ModContainer;
|
||||
*
|
||||
* This is a parallel dispatch event.
|
||||
*/
|
||||
public class InterModEnqueueEvent extends ModLifecycleEvent
|
||||
public class InterModEnqueueEvent extends ParallelDispatchEvent
|
||||
{
|
||||
|
||||
public InterModEnqueueEvent(final ModContainer container)
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.util.function.Predicate;
|
||||
* @see #getIMCStream()
|
||||
* @see #getIMCStream(Predicate)
|
||||
*/
|
||||
public class InterModProcessEvent extends ModLifecycleEvent
|
||||
public class InterModProcessEvent extends ParallelDispatchEvent
|
||||
{
|
||||
public InterModProcessEvent(final ModContainer container)
|
||||
{
|
||||
|
||||
@@ -54,6 +54,10 @@ public class ModLifecycleEvent extends Event implements IModBusEvent
|
||||
return InterModComms.getMessages(this.container.getModId(), methodFilter);
|
||||
}
|
||||
|
||||
ModContainer getContainer() {
|
||||
return this.container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return description();
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package net.minecraftforge.fml.event.lifecycle;
|
||||
|
||||
import net.minecraftforge.fml.DeferredWorkQueue;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ParallelDispatchEvent extends ModLifecycleEvent {
|
||||
public ParallelDispatchEvent(final ModContainer container) {
|
||||
super(container);
|
||||
}
|
||||
|
||||
private Optional<DeferredWorkQueue> getQueue() {
|
||||
return DeferredWorkQueue.lookup(Optional.of(getClass()));
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> enqueueWork(Runnable work) {
|
||||
return getQueue().map(q->q.enqueueWork(getContainer().getModInfo(), work)).orElseThrow(()->new RuntimeException("No work queue found!"));
|
||||
}
|
||||
|
||||
public <T> CompletableFuture<T> enqueueWork(Supplier<T> work) {
|
||||
return getQueue().map(q->q.enqueueWork(getContainer().getModInfo(), work)).orElseThrow(()->new RuntimeException("No work queue found!"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user