Fix up event naming, move them to sensible packages and document everything a bit.

This commit is contained in:
cpw committed 2019-01-14 22:43:17 -05:00
1 parent 220bf8730a
commit 56a3926b86
95 files changed
+333 -251

No files matched your search

@@ -0,0 +1,55 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.event.lifecycle;
import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.ModContainer;
import java.util.function.Supplier;
/**
* 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 ModLifecycleEvent
{
private final Supplier<Minecraft> minecraftSupplier;
public FMLClientSetupEvent(Supplier<Minecraft> mc, ModContainer container)
{
super(container);
this.minecraftSupplier = mc;
}
public Supplier<Minecraft> getMinecraftSupplier()
{
return minecraftSupplier;
}
}
@@ -0,0 +1,49 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.event.lifecycle;
import net.minecraftforge.fml.ModContainer;
import java.util.function.Consumer;
/**
* This is the first of four commonly called events during mod initialization.
*
* Called before {@link FMLClientSetupEvent} or {@link FMLDedicatedServerSetupEvent} during mod startup.
*
* Called after {@link net.minecraftforge.event.RegistryEvent.Register} events have been fired.
*
* Either register your listener using {@link net.minecraftforge.fml.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 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 FMLCommonSetupEvent(final ModContainer container)
{
super(container);
}
}
@@ -0,0 +1,55 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.event.lifecycle;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraftforge.fml.ModContainer;
import java.util.function.Supplier;
/**
* 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#DEDICATED_SERVER} - the dedicated game server.
*
* Alternative to {@link FMLClientSetupEvent}.
*
* Do dedicated server specific activities with this event.
*
* This is a parallel dispatch event.
*/
public class FMLDedicatedServerSetupEvent extends ModLifecycleEvent
{
private final Supplier<DedicatedServer> serverSupplier;
public FMLDedicatedServerSetupEvent(Supplier<DedicatedServer> server, ModContainer container)
{
super(container);
this.serverSupplier = server;
}
public Supplier<DedicatedServer> getServerSupplier()
{
return serverSupplier;
}
}
@@ -0,0 +1,54 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.event.lifecycle;
import java.io.File;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
import net.minecraftforge.fml.common.Mod;
/**
* A special event used when the {@link Mod#certificateFingerprint()} doesn't match the certificate loaded from the JAR
* file. You could use this to log a warning that the code that is running might not be yours, for example.
*/
public class FMLFingerprintViolationEvent extends ModLifecycleEvent
{
private final boolean isDirectory;
private final Set<String> fingerprints;
private final File source;
private final String expectedFingerprint;
public FMLFingerprintViolationEvent(boolean isDirectory, File source, ImmutableSet<String> fingerprints, String expectedFingerprint)
{
super(null);
this.isDirectory = isDirectory;
this.source = source;
this.fingerprints = fingerprints;
this.expectedFingerprint = expectedFingerprint;
}
public boolean isDirectory() { return isDirectory; }
public Set<String> getFingerprints() { return fingerprints; }
public File getSource() { return source; }
public String getExpectedFingerprint() { return expectedFingerprint; }
}
@@ -0,0 +1,36 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.event.lifecycle;
import net.minecraftforge.fml.ModContainer;
/**
* 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 ModLifecycleEvent
{
public FMLLoadCompleteEvent(final ModContainer container)
{
super(container);
}
}
@@ -0,0 +1,91 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.event.lifecycle;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.minecraft.util.ResourceLocation;
/**
* Called whenever the ID mapping might have changed. If you register for this event, you
* will be called back whenever the client or server loads an ID set. This includes both
* when the ID maps are loaded from disk, as well as when the ID maps revert to the initial
* state.
*
* Note: you cannot change the IDs that have been allocated, but you might want to use
* this event to update caches or other in-mod artifacts that might be impacted by an ID
* change.
*
* @see net.minecraftforge.fml.common.Mod.EventHandler for how to subscribe to this event
* @author cpw
*/
public class FMLModIdMappingEvent extends ModLifecycleEvent
{
public class ModRemapping
{
public final ResourceLocation registry;
public final ResourceLocation key;
public final int oldId;
public final int newId;
private ModRemapping(ResourceLocation registry, ResourceLocation key, int oldId, int newId)
{
this.registry = registry;
this.key = key;
this.oldId = oldId;
this.newId = newId;
}
}
private final Map<ResourceLocation, ImmutableList<ModRemapping>> remaps;
private final ImmutableSet<ResourceLocation> keys;
public final boolean isFrozen;
public FMLModIdMappingEvent(Map<ResourceLocation, Map<ResourceLocation, Integer[]>> remaps, boolean isFrozen)
{
super(null);
this.isFrozen = isFrozen;
this.remaps = Maps.newHashMap();
remaps.forEach((name, rm) ->
{
List<ModRemapping> tmp = Lists.newArrayList();
rm.forEach((key, value) -> tmp.add(new ModRemapping(name, key, value[0], value[1])));
tmp.sort(Comparator.comparingInt(o -> o.newId));
this.remaps.put(name, ImmutableList.copyOf(tmp));
});
this.keys = ImmutableSet.copyOf(this.remaps.keySet());
}
public ImmutableSet<ResourceLocation> getRegistries()
{
return this.keys;
}
public ImmutableList<ModRemapping> getRemaps(ResourceLocation registry)
{
return this.remaps.get(registry);
}
}
@@ -0,0 +1,42 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.event.lifecycle;
import net.minecraftforge.fml.ModContainer;
/**
* This is the third of four commonly called events during mod lifecycle 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 ModLifecycleEvent
{
public InterModEnqueueEvent(final ModContainer container)
{
super(container);
}
}
@@ -0,0 +1,45 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.event.lifecycle;
import net.minecraftforge.fml.ModContainer;
import java.util.function.Predicate;
/**
* This is the fourth of four commonly called events during mod lifecycle 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 ModLifecycleEvent
{
public InterModProcessEvent(final ModContainer container)
{
super(container);
}
}
@@ -0,0 +1,55 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.event.lifecycle;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.ModContainer;
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
{
private final ModContainer container;
public ModLifecycleEvent(ModContainer container)
{
this.container = container;
}
public final String description()
{
String cn = getClass().getName();
return cn.substring(cn.lastIndexOf('.')+4,cn.length()-5);
}
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);
}
}
@@ -0,0 +1,38 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.event.server;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
/**
* Called before the server begins loading anything. Called after {@link InterModProcessEvent} on the dedicated
* server, and after the player has hit "Play Selected World" in the client. Called before {@link FMLServerStartingEvent}.
*
* You can obtain a reference to the server with this event.
* @author cpw
*/
public class FMLServerAboutToStartEvent extends ServerLifecycleEvent {
public FMLServerAboutToStartEvent(MinecraftServer server)
{
super(server);
}
}
@@ -0,0 +1,36 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.event.server;
import net.minecraft.server.MinecraftServer;
/**
* Called after {@link FMLServerStartingEvent} when the server is available and ready to play.
*
* @author cpw
*/
public class FMLServerStartedEvent extends ServerLifecycleEvent
{
public FMLServerStartedEvent(final MinecraftServer server)
{
super(server);
}
}
@@ -0,0 +1,43 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.event.server;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.command.CommandSource;
import net.minecraft.server.MinecraftServer;
/**
* Called after {@link FMLServerAboutToStartEvent} and before {@link FMLServerStartedEvent}.
* This event allows for customizations of the server, such as loading custom commands, perhaps customizing recipes or
* other activities.
*
* @author cpw
*/
public class FMLServerStartingEvent extends ServerLifecycleEvent
{
public FMLServerStartingEvent(final MinecraftServer server)
{
super(server);
}
public CommandDispatcher<CommandSource> getCommandDispatcher() {
return server.getCommandManager().getDispatcher();
}
}
@@ -0,0 +1,36 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.event.server;
import net.minecraft.server.MinecraftServer;
/**
* Called after {@link FMLServerStoppingEvent} when the server has completely shut down.
* Called immediately before shutting down, on the dedicated server, and before returning
* to the main menu on the client.
*
* @author cpw
*/
public class FMLServerStoppedEvent extends ServerLifecycleEvent {
public FMLServerStoppedEvent(MinecraftServer server)
{
super(server);
}
}
@@ -0,0 +1,35 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.event.server;
import net.minecraft.server.MinecraftServer;
/**
* Called when the server begins an orderly shutdown, before {@link FMLServerStoppedEvent}.
*
* @author cpw
*/
public class FMLServerStoppingEvent extends ServerLifecycleEvent
{
public FMLServerStoppingEvent(MinecraftServer server)
{
super(server);
}
}
@@ -0,0 +1,39 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.event.server;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.eventbus.api.Event;
public class ServerLifecycleEvent extends Event
{
protected final MinecraftServer server;
public ServerLifecycleEvent(MinecraftServer server)
{
this.server = server;
}
public MinecraftServer getServer()
{
return server;
}
}