From 6e99f84e91289ae08aa7241c84fdde4aa492cbdf Mon Sep 17 00:00:00 2001 From: cpw Date: Sun, 1 Jul 2018 16:10:13 -0400 Subject: [PATCH] Moving some stuff around, network and server events. --- .../net/minecraftforge/fml/InterModComms.java | 125 ++++++ .../fml/ServerLifecycleHooks.java | 10 +- .../fml/common/LoadController.java | 2 - .../net/minecraftforge/fml/common/Loader.java | 2 - .../net/minecraftforge/fml/common/Mod.java | 2 - .../fml/common/event/FMLInterModComms.java | 414 ------------------ .../event/FMLServerAboutToStartEvent.java | 11 +- .../common/event/FMLServerStartedEvent.java | 8 +- .../common/event/FMLServerStartingEvent.java | 13 +- .../common/event/FMLServerStoppedEvent.java | 9 +- .../common/event/FMLServerStoppingEvent.java | 9 +- ...teEvent.java => ServerLifecycleEvent.java} | 24 +- .../fml/loading/DefaultModInfos.java | 10 +- ...ider.java => FMLClientLaunchProvider.java} | 4 +- .../loading/FMLDevClientLaunchProvider.java | 2 +- .../loading/FMLDevServerLaunchProvider.java | 2 +- .../loading/moddiscovery/ModFileParser.java | 10 +- .../fml/network/NetworkDirection.java | 8 +- .../fml/network/NetworkHooks.java | 8 +- .../fml/network/simple/SimpleChannel.java | 6 +- ...mods.modlauncher.api.ILaunchHandlerService | 2 +- 21 files changed, 190 insertions(+), 491 deletions(-) create mode 100644 src/main/java/net/minecraftforge/fml/InterModComms.java delete mode 100644 src/main/java/net/minecraftforge/fml/common/event/FMLInterModComms.java rename src/main/java/net/minecraftforge/fml/common/event/{FMLStateEvent.java => ServerLifecycleEvent.java} (59%) rename src/main/java/net/minecraftforge/fml/loading/{FMLLaunchProvider.java => FMLClientLaunchProvider.java} (91%) diff --git a/src/main/java/net/minecraftforge/fml/InterModComms.java b/src/main/java/net/minecraftforge/fml/InterModComms.java new file mode 100644 index 000000000..8c296ab99 --- /dev/null +++ b/src/main/java/net/minecraftforge/fml/InterModComms.java @@ -0,0 +1,125 @@ +/* + * Minecraft Forge + * Copyright (c) 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; + + +import java.util.Iterator; +import java.util.Spliterator; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ConcurrentMap; +import java.util.function.Consumer; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; + +public class InterModComms +{ + public static final class IMCMessage { + private final String modId; + private final String method; + private final Supplier thing; + + IMCMessage(String modId, String method, Supplier thing) + { + this.modId = modId; + this.method = method; + this.thing = thing; + } + + public final String getModId() { + return this.modId; + } + + public final String getMethod() { + return this.method; + } + + @SuppressWarnings("unchecked") + public final Supplier getMessageSupplier() { + return (Supplier)this.thing; + } + } + private static ConcurrentMap> containerQueues = new ConcurrentHashMap<>(); + + public static boolean sendTo(final String modId, final String method, final Supplier thing) { + if (!ModList.get().isLoaded(modId)) return false; + containerQueues.computeIfAbsent(modId, k->new ConcurrentLinkedQueue<>()).add(new IMCMessage(modId, method, thing)); + return true; + } + + public static Stream getMessages(final String modId, final Predicate methodMatcher) { + ConcurrentLinkedQueue queue = containerQueues.get(modId); + if (queue == null) return Stream.empty(); + return StreamSupport.stream(new QueueFilteringSpliterator(queue, methodMatcher), false); + } + + public static Stream getMessages(final String modId) { + return getMessages(modId, s->Boolean.TRUE); + } + + private static class QueueFilteringSpliterator implements Spliterator + { + private final ConcurrentLinkedQueue queue; + private final Predicate methodFilter; + private final Iterator iterator; + + public QueueFilteringSpliterator(final ConcurrentLinkedQueue queue, final Predicate methodFilter) { + this.queue = queue; + this.iterator = queue.iterator(); + this.methodFilter = methodFilter; + } + + @Override + public int characteristics() { + return Spliterator.CONCURRENT | Spliterator.NONNULL | Spliterator.ORDERED; + } + + @Override + public long estimateSize() { + return queue.size(); + } + + @Override + public boolean tryAdvance(final Consumer action) + { + IMCMessage next; + do + { + if (!iterator.hasNext()) + { + return false; + } + next = this.iterator.next(); + } + while (!methodFilter.test(next.method)); + action.accept(next); + this.iterator.remove(); + return true; + } + + @Override + public Spliterator trySplit() { + return null; + } + + } +} diff --git a/src/main/java/net/minecraftforge/fml/ServerLifecycleHooks.java b/src/main/java/net/minecraftforge/fml/ServerLifecycleHooks.java index 7930cfbd7..e137ed701 100644 --- a/src/main/java/net/minecraftforge/fml/ServerLifecycleHooks.java +++ b/src/main/java/net/minecraftforge/fml/ServerLifecycleHooks.java @@ -60,16 +60,16 @@ public class ServerLifecycleHooks return !MinecraftForge.EVENT_BUS.post(new FMLServerStartingEvent(server)); } - public static void handleServerStarted() + public static void handleServerStarted(final MinecraftServer server) { - MinecraftForge.EVENT_BUS.post(new FMLServerStartedEvent()); + MinecraftForge.EVENT_BUS.post(new FMLServerStartedEvent(server)); allowLogins.set(true); } - public static void handleServerStopping() + public static void handleServerStopping(final MinecraftServer server) { allowLogins.set(false); - MinecraftForge.EVENT_BUS.post(new FMLServerStoppingEvent()); + MinecraftForge.EVENT_BUS.post(new FMLServerStoppingEvent(server)); } public static void expectServerStopped() @@ -79,7 +79,7 @@ public class ServerLifecycleHooks public static void handleServerStopped(final MinecraftServer server) { - MinecraftForge.EVENT_BUS.post(new FMLServerStoppedEvent()); + MinecraftForge.EVENT_BUS.post(new FMLServerStoppedEvent(server)); currentServer = null; LogicalSidedProvider.setServer(null); CountDownLatch latch = exitLatch; diff --git a/src/main/java/net/minecraftforge/fml/common/LoadController.java b/src/main/java/net/minecraftforge/fml/common/LoadController.java index d5e1c0bcf..d7c060bd1 100644 --- a/src/main/java/net/minecraftforge/fml/common/LoadController.java +++ b/src/main/java/net/minecraftforge/fml/common/LoadController.java @@ -34,8 +34,6 @@ import net.minecraftforge.fml.common.event.ModLifecycleEvent; import net.minecraftforge.fml.common.event.FMLLoadEvent; import net.minecraftforge.fml.common.event.FMLModDisabledEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.fml.common.event.FMLStateEvent; -import net.minecraftforge.fml.common.eventhandler.FMLThrowingEventBus; import net.minecraftforge.fml.common.versioning.ArtifactVersion; import net.minecraftforge.fml.ModContainer; diff --git a/src/main/java/net/minecraftforge/fml/common/Loader.java b/src/main/java/net/minecraftforge/fml/common/Loader.java index 9e781c496..079f865e8 100644 --- a/src/main/java/net/minecraftforge/fml/common/Loader.java +++ b/src/main/java/net/minecraftforge/fml/common/Loader.java @@ -44,7 +44,6 @@ import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.fml.ModContainer; import net.minecraftforge.fml.ModContainer.Disableable; import net.minecraftforge.fml.common.ProgressManager.ProgressBar; -import net.minecraftforge.fml.common.event.FMLInterModComms; import net.minecraftforge.fml.common.event.FMLLoadEvent; import net.minecraftforge.fml.common.event.FMLModIdMappingEvent; import net.minecraftforge.fml.common.registry.*; @@ -56,7 +55,6 @@ import net.minecraftforge.fml.common.versioning.ArtifactVersion; import net.minecraftforge.fml.common.versioning.DependencyParser; import net.minecraftforge.fml.common.versioning.VersionParser; import net.minecraftforge.fml.relauncher.ModListHelper; -import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.registries.GameData; import net.minecraftforge.registries.ObjectHolderRegistry; diff --git a/src/main/java/net/minecraftforge/fml/common/Mod.java b/src/main/java/net/minecraftforge/fml/common/Mod.java index 9e44e89a8..be2c903bd 100644 --- a/src/main/java/net/minecraftforge/fml/common/Mod.java +++ b/src/main/java/net/minecraftforge/fml/common/Mod.java @@ -28,7 +28,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.common.event.ModLifecycleEvent; import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLInterModComms; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLServerAboutToStartEvent; @@ -36,7 +35,6 @@ import net.minecraftforge.fml.common.event.FMLServerStartedEvent; import net.minecraftforge.fml.common.event.FMLServerStartingEvent; import net.minecraftforge.fml.common.event.FMLServerStoppedEvent; import net.minecraftforge.fml.common.event.FMLServerStoppingEvent; -import net.minecraftforge.fml.common.event.FMLInterModComms.IMCEvent; import net.minecraftforge.fml.common.registry.GameRegistry; /** diff --git a/src/main/java/net/minecraftforge/fml/common/event/FMLInterModComms.java b/src/main/java/net/minecraftforge/fml/common/event/FMLInterModComms.java deleted file mode 100644 index 47878efdb..000000000 --- a/src/main/java/net/minecraftforge/fml/common/event/FMLInterModComms.java +++ /dev/null @@ -1,414 +0,0 @@ -/* - * 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.common.event; - -import java.util.function.Function; -import java.util.Optional; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.ModList; -import net.minecraftforge.fml.ModThreadContext; -import net.minecraftforge.fml.common.FMLCommonHandler; -import net.minecraftforge.fml.common.FMLLog; -import net.minecraftforge.fml.ModContainer; -import net.minecraftforge.fml.common.Mod.Instance; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ImmutableList; - -import javax.annotation.Nonnull; - -/** - * Simple intermod communications to receive simple messages directed at you - * from other mods - * - * @author cpw - * - */ -public class FMLInterModComms { - private static final ImmutableList emptyIMCList = ImmutableList.of(); - private static ArrayListMultimap modMessages = ArrayListMultimap.create(); - - /** - * Subscribe to this event to receive your messages (they are sent between - * {@link FMLInitializationEvent} and {@link FMLPostInitializationEvent}) - * - * @see net.minecraftforge.fml.common.Mod.EventHandler for how to subscribe to this event - * @author cpw - */ - public static class IMCEvent extends ModLifecycleEvent - { - private ModContainer activeContainer; - - public IMCEvent() - { - super(activeContainer); - } - - @Override - public void applyModContainer(ModContainer activeContainer) - { - this.activeContainer = activeContainer; - this.currentList = null; - FMLLog.log.trace("Attempting to deliver {} IMC messages to mod {}", modMessages.get(activeContainer.getModId()).size(), activeContainer.getModId()); - } - - private ImmutableList currentList; - - public ImmutableList getMessages() - { - if (currentList == null) - { - currentList = ImmutableList.copyOf(modMessages.removeAll(activeContainer.getModId())); - } - return currentList; - } - } - - /** - * You will receive an instance of this for each message sent - * - * @author cpw - * - */ - public static final class IMCMessage { - private final boolean isFunction; - /** - * This is the modid of the mod that sent you the message - */ - private String sender; - /** - * This field, and {@link #value} are both at the mod's discretion - */ - @Nonnull - public final String key; - /** - * This field, and {@link #key} are both at the mod's discretion - */ - @Nonnull - private final Object value; - - private IMCMessage(@Nonnull String key, @Nonnull Object value) - { - this.key = key; - this.value = value; - this.isFunction = false; - } - - private IMCMessage(@Nonnull String key, @Nonnull String value, boolean isFunction) { - this.key = key; - this.value = value; - this.isFunction = isFunction; - } - - @Override - public String toString() - { - return sender; - } - - /** - * Get the sending modId of this message. - * @return The modId of the mod that originated the message - */ - public String getSender() - { - return this.sender; - } - - void setSender(ModContainer activeModContainer) - { - this.sender = activeModContainer.getModId(); - } - - /** - * Get the string value from this message. - * @throws ClassCastException if this message doesn't contain a String value - * @return The string value - */ - public String getStringValue() - { - return (String) value; - } - /** - * Get the ResourceLocation value from this message. - * @throws ClassCastException if this message doesn't contain a ResourceLocation value - * @return The string value - */ - public ResourceLocation getResourceLocationValue() - { - return (ResourceLocation) value; - } - - /** - * Get the {@link NBTTagCompound} value from this message - * @throws ClassCastException if this message doesn't contain an NBT value - * @return The NBT value - */ - public NBTTagCompound getNBTValue() - { - return (NBTTagCompound) value; - } - - /** - * Get the {@link ItemStack} value from this message - * @throws ClassCastException if this message doesn't contain an Itemstack value - * @return The Itemstack value - */ - @Nonnull - public ItemStack getItemStackValue() - { - return (ItemStack) value; - } - - /** - * Get the {@link Function} value from this message. This will attempt to classload the function - * supplied by the caller. The parameter classes are strictly to give a concrete generic function return value. - * @param functionFrom The type of the argument to the function - * @param functionTo The type of the result of the function - * @param The argument type - * @param The result type - * @return The function value or Optional.absent if it wasn't readable or isn't a function call - */ - @SuppressWarnings("unchecked") - public Optional> getFunctionValue(Class functionFrom, Class functionTo) { - if (!isFunction) { - return Optional.empty(); - } - try { - Function f = Class.forName((String) value).asSubclass(Function.class).newInstance(); - return Optional.of(f); - } catch (Exception e) { - FMLLog.log.info("An error occurred instantiating the IMC function. key: {} value: {}, caller: {}", key,value,sender); - return Optional.empty(); - } - } - - /** - * Get the actual message class type - * @return The type of the message - */ - public Class getMessageType() - { - return value.getClass(); - } - - /** - * Is this a string type message - * @return if this is a string type message - */ - public boolean isStringMessage() - { - return String.class.isAssignableFrom(getMessageType()); - } - - /** - * Is this an {@link ItemStack} type message - * @return if this is an itemstack type message - */ - public boolean isItemStackMessage() - { - return ItemStack.class.isAssignableFrom(getMessageType()); - } - - /** - * Is this an {@link NBTTagCompound} type message - * @return if this is an NBT type message - */ - public boolean isNBTMessage() - { - return NBTTagCompound.class.isAssignableFrom(getMessageType()); - } - - /** - * Is this an {@link ResourceLocation} type message - * @return if this is an NBT type message - */ - public boolean isResourceLocationMessage() - { - return ResourceLocation.class.isAssignableFrom(getMessageType()); - } - - /** - * Is this a {@link Function} type message - * @return if this is a function type message - */ - public boolean isFunctionMessage() { return Function.class.isAssignableFrom(getMessageType()); } - } - - /** - * Send a startup time message - * @param modId The modid to send it to - * @param key The mod specific key - * @param value An NBT type value - * @return if the message was enqueued successfully and will be processed during startup - */ - public static boolean sendMessage(String modId, String key, NBTTagCompound value) - { - return enqueueStartupMessage(modId, new IMCMessage(key, value)); - } - - /** - * Send a startup time message - * @param modId The modid to send it to - * @param key The mod specific key - * @param value An Itemstack value - * @return if the message was enqueued successfully and will be processed during startup - */ - public static boolean sendMessage(String modId, String key, ItemStack value) - { - return enqueueStartupMessage(modId, new IMCMessage(key, value)); - } - - /** - * Send a startup time message - * @param modId The modid to send it to - * @param key The mod specific key - * @param value A ResourceLocation value - * @return if the message was enqueued successfully and will be processed during startup - */ - public static boolean sendMessage(String modId, String key, ResourceLocation value) - { - return enqueueStartupMessage(modId, new IMCMessage(key, value)); - } - - /** - * Send a startup time message - * @param modId The modid to send it to - * @param key The mod specific key - * @param value A String value - * @return if the message was enqueued successfully and will be processed during startup - */ - public static boolean sendMessage(String modId, String key, String value) - { - return enqueueStartupMessage(modId, new IMCMessage(key, value)); - } - /** - * Send a startup time function message - * @param modId The modid to send it to - * @param key The mod specific key - * @param functionClassName The class name of a function that will be instantiated when the - * message is read. It must implement {@link Function} - * @return if the message was enqueued successfully and will be processed during startup - */ - public static boolean sendFunctionMessage(String modId, String key, String functionClassName) - { - return enqueueStartupMessage(modId, new IMCMessage(key, functionClassName, true)); - } - - /** - * Send a post-startup message - * @param sourceMod The mod sending the message - * @param modId The modid to send it to - * @param key The mod specific key - * @param value An NBT type value - */ - public static void sendRuntimeMessage(Object sourceMod, String modId, String key, NBTTagCompound value) - { - enqueueMessage(sourceMod, modId, new IMCMessage(key, value)); - } - - /** - * Send a post-startup message - * @param sourceMod The mod sending the message - * @param modId The modid to send it to - * @param key The mod specific key - * @param value An Itemstack value - */ - public static void sendRuntimeMessage(Object sourceMod, String modId, String key, ItemStack value) - { - enqueueMessage(sourceMod, modId, new IMCMessage(key, value)); - } - - /** - * Send a post-startup message - * @param sourceMod The mod sending the message - * @param modId The modid to send it to - * @param key The mod specific key - * @param value A string value - */ - public static void sendRuntimeMessage(Object sourceMod, String modId, String key, String value) - { - enqueueMessage(sourceMod, modId, new IMCMessage(key, value)); - } - - /** - * Send a post-startup message - * @param sourceMod The mod sending the message - * @param modId The modid to send it to - * @param key The mod specific key - * @param value A string value - */ - public static void sendRuntimeMessage(Object sourceMod, String modId, String key, ResourceLocation value) - { - enqueueMessage(sourceMod, modId, new IMCMessage(key, value)); - } - /** - * Send a post-startup function message. - * - * @param sourceMod The mod originating this message - * @param modId The modid to send it to - * @param key The mod specific key - * @param functionClassName The name of a class to be loaded when the caller processes this message. - * The named class must extend {@link Function} - */ - public static void sendRuntimeFunctionMessage(Object sourceMod, String modId, String key, String functionClassName) - { - enqueueMessage(sourceMod, modId, new IMCMessage(key, functionClassName, true)); - } - - private static boolean enqueueStartupMessage(String modTarget, IMCMessage message) - { - if (ModThreadContext.get().getActiveContainer() == null) - { - return false; - } - enqueueMessage(ModThreadContext.get().getActiveContainer(), modTarget, message); - return ModList.get().isLoaded(modTarget); - - } - private static void enqueueMessage(ModContainer sourceMod, String modTarget, IMCMessage message) - { - if (ModList.get().isLoaded(modTarget)) - { - message.setSender(sourceMod); - modMessages.put(modTarget, message); - } - } - - /** - * Retrieve any pending runtime messages for the mod - * @param forMod The {@link Instance} of the Mod to fetch messages for - * @return any messages - the collection will never be null - */ - public static ImmutableList fetchRuntimeMessages(Object forMod) - { - ModContainer mc = FMLCommonHandler.instance().findContainerFor(forMod); - if (mc != null) - { - return ImmutableList.copyOf(modMessages.removeAll(mc.getModId())); - } - else - { - return emptyIMCList; - } - } -} diff --git a/src/main/java/net/minecraftforge/fml/common/event/FMLServerAboutToStartEvent.java b/src/main/java/net/minecraftforge/fml/common/event/FMLServerAboutToStartEvent.java index 5769bca15..b4e9786b4 100644 --- a/src/main/java/net/minecraftforge/fml/common/event/FMLServerAboutToStartEvent.java +++ b/src/main/java/net/minecraftforge/fml/common/event/FMLServerAboutToStartEvent.java @@ -26,20 +26,13 @@ import net.minecraft.server.MinecraftServer; * 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. - * @see net.minecraftforge.fml.common.Mod.EventHandler for how to subscribe to this event * @author cpw */ -public class FMLServerAboutToStartEvent extends FMLStateEvent { - - private final MinecraftServer server; +public class FMLServerAboutToStartEvent extends ServerLifecycleEvent { public FMLServerAboutToStartEvent(MinecraftServer server) { - this.server = (MinecraftServer) server; + super(server); } - public MinecraftServer getServer() - { - return server; - } } diff --git a/src/main/java/net/minecraftforge/fml/common/event/FMLServerStartedEvent.java b/src/main/java/net/minecraftforge/fml/common/event/FMLServerStartedEvent.java index ce1a9cbcf..b408fa9e4 100644 --- a/src/main/java/net/minecraftforge/fml/common/event/FMLServerStartedEvent.java +++ b/src/main/java/net/minecraftforge/fml/common/event/FMLServerStartedEvent.java @@ -19,16 +19,18 @@ package net.minecraftforge.fml.common.event; +import net.minecraft.server.MinecraftServer; + /** * Called after {@link FMLServerStartingEvent} when the server is available and ready to play. * - * @see net.minecraftforge.fml.common.Mod.EventHandler for how to subscribe to this event * @author cpw */ -public class FMLServerStartedEvent extends FMLStateEvent +public class FMLServerStartedEvent extends ServerLifecycleEvent { - public FMLServerStartedEvent() + public FMLServerStartedEvent(final MinecraftServer server) { + super(server); } } diff --git a/src/main/java/net/minecraftforge/fml/common/event/FMLServerStartingEvent.java b/src/main/java/net/minecraftforge/fml/common/event/FMLServerStartingEvent.java index f6c101d98..d94f1c3a1 100644 --- a/src/main/java/net/minecraftforge/fml/common/event/FMLServerStartingEvent.java +++ b/src/main/java/net/minecraftforge/fml/common/event/FMLServerStartingEvent.java @@ -28,22 +28,13 @@ import net.minecraft.server.MinecraftServer; * This event allows for customizations of the server, such as loading custom commands, perhaps customizing recipes or * other activities. * - * @see net.minecraftforge.fml.common.Mod.EventHandler for how to subscribe to this event * @author cpw */ -public class FMLServerStartingEvent extends FMLStateEvent +public class FMLServerStartingEvent extends ServerLifecycleEvent { - - private final MinecraftServer server; - public FMLServerStartingEvent(final MinecraftServer server) { - this.server = (MinecraftServer) server; - } - - public MinecraftServer getServer() - { - return server; + super(server); } public void registerServerCommand(ICommand command) diff --git a/src/main/java/net/minecraftforge/fml/common/event/FMLServerStoppedEvent.java b/src/main/java/net/minecraftforge/fml/common/event/FMLServerStoppedEvent.java index 365435ae0..a93ce08f9 100644 --- a/src/main/java/net/minecraftforge/fml/common/event/FMLServerStoppedEvent.java +++ b/src/main/java/net/minecraftforge/fml/common/event/FMLServerStoppedEvent.java @@ -19,13 +19,18 @@ package net.minecraftforge.fml.common.event; +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. * - * @see net.minecraftforge.fml.common.Mod.EventHandler for how to subscribe to this event * @author cpw */ -public class FMLServerStoppedEvent extends FMLStateEvent { +public class FMLServerStoppedEvent extends ServerLifecycleEvent { + public FMLServerStoppedEvent(MinecraftServer server) + { + super(server); + } } diff --git a/src/main/java/net/minecraftforge/fml/common/event/FMLServerStoppingEvent.java b/src/main/java/net/minecraftforge/fml/common/event/FMLServerStoppingEvent.java index 874e874b4..41ba24561 100644 --- a/src/main/java/net/minecraftforge/fml/common/event/FMLServerStoppingEvent.java +++ b/src/main/java/net/minecraftforge/fml/common/event/FMLServerStoppingEvent.java @@ -19,12 +19,17 @@ package net.minecraftforge.fml.common.event; +import net.minecraft.server.MinecraftServer; + /** * Called when the server begins an orderly shutdown, before {@link FMLServerStoppedEvent}. * - * @see net.minecraftforge.fml.common.Mod.EventHandler for how to subscribe to this event * @author cpw */ -public class FMLServerStoppingEvent extends FMLStateEvent +public class FMLServerStoppingEvent extends ServerLifecycleEvent { + public FMLServerStoppingEvent(MinecraftServer server) + { + super(server); + } } diff --git a/src/main/java/net/minecraftforge/fml/common/event/FMLStateEvent.java b/src/main/java/net/minecraftforge/fml/common/event/ServerLifecycleEvent.java similarity index 59% rename from src/main/java/net/minecraftforge/fml/common/event/FMLStateEvent.java rename to src/main/java/net/minecraftforge/fml/common/event/ServerLifecycleEvent.java index 42dae9bef..b83d5ca3a 100644 --- a/src/main/java/net/minecraftforge/fml/common/event/FMLStateEvent.java +++ b/src/main/java/net/minecraftforge/fml/common/event/ServerLifecycleEvent.java @@ -19,27 +19,21 @@ package net.minecraftforge.fml.common.event; -import net.minecraftforge.fml.common.FMLCommonHandler; -import net.minecraftforge.api.distmarker.Dist; +import net.minecraft.server.MinecraftServer; +import net.minecraftforge.eventbus.api.Event; -/** - * The parent of all mod-state changing events - */ -public abstract class FMLStateEvent extends ModLifecycleEvent +public class ServerLifecycleEvent extends Event { - public FMLStateEvent() + protected final MinecraftServer server; + + public ServerLifecycleEvent(MinecraftServer server) { - super(null); + this.server = server; } - /** - * The side we're loading on. {@link Side#CLIENT} means we're loading in the client, {@link Side#SERVER} means - * we're loading in the dedicated server. - * @return Return which side we're loading on. - */ - public Side getSide() + public MinecraftServer getServer() { - return FMLCommonHandler.instance().getSide(); + return server; } } diff --git a/src/main/java/net/minecraftforge/fml/loading/DefaultModInfos.java b/src/main/java/net/minecraftforge/fml/loading/DefaultModInfos.java index 87c8e0bf6..749c566cd 100644 --- a/src/main/java/net/minecraftforge/fml/loading/DefaultModInfos.java +++ b/src/main/java/net/minecraftforge/fml/loading/DefaultModInfos.java @@ -19,7 +19,7 @@ package net.minecraftforge.fml.loading; -import com.electronwill.nightconfig.core.path.PathConfig; +import com.electronwill.nightconfig.core.file.FileConfig; import net.minecraftforge.fml.language.IModInfo; import net.minecraftforge.fml.loading.moddiscovery.ModInfo; @@ -31,12 +31,12 @@ import java.util.List; public class DefaultModInfos { static { - PathConfig minecraftmod; - PathConfig forgemod; + FileConfig minecraftmod; + FileConfig forgemod; try { - minecraftmod = PathConfig.of(Paths.get(DefaultModInfos.class.getClassLoader().getResource("minecraftmod.toml").toURI())); - forgemod = PathConfig.of(Paths.get(DefaultModInfos.class.getClassLoader().getResource("forgemod.toml").toURI())); + minecraftmod = FileConfig.of(Paths.get(DefaultModInfos.class.getClassLoader().getResource("minecraftmod.toml").toURI())); + forgemod = FileConfig.of(Paths.get(DefaultModInfos.class.getClassLoader().getResource("forgemod.toml").toURI())); minecraftmod.load(); forgemod.load(); } diff --git a/src/main/java/net/minecraftforge/fml/loading/FMLLaunchProvider.java b/src/main/java/net/minecraftforge/fml/loading/FMLClientLaunchProvider.java similarity index 91% rename from src/main/java/net/minecraftforge/fml/loading/FMLLaunchProvider.java rename to src/main/java/net/minecraftforge/fml/loading/FMLClientLaunchProvider.java index 0b6ebfb47..5b21c6458 100644 --- a/src/main/java/net/minecraftforge/fml/loading/FMLLaunchProvider.java +++ b/src/main/java/net/minecraftforge/fml/loading/FMLClientLaunchProvider.java @@ -26,12 +26,12 @@ import net.minecraftforge.api.distmarker.Dist; import java.nio.file.Path; import java.util.concurrent.Callable; -public class FMLLaunchProvider extends FMLCommonLaunchHandler implements ILaunchHandlerService +public class FMLClientLaunchProvider extends FMLCommonLaunchHandler implements ILaunchHandlerService { @Override public String name() { - return "fml"; + return "fmlclient"; } @Override diff --git a/src/main/java/net/minecraftforge/fml/loading/FMLDevClientLaunchProvider.java b/src/main/java/net/minecraftforge/fml/loading/FMLDevClientLaunchProvider.java index 503d400a6..6234ce373 100644 --- a/src/main/java/net/minecraftforge/fml/loading/FMLDevClientLaunchProvider.java +++ b/src/main/java/net/minecraftforge/fml/loading/FMLDevClientLaunchProvider.java @@ -40,7 +40,7 @@ public class FMLDevClientLaunchProvider extends FMLCommonLaunchHandler implement @Override public String name() { - return "devfmlclient"; + return "fmldevclient"; } private static final List SKIPPACKAGES = Arrays.asList( diff --git a/src/main/java/net/minecraftforge/fml/loading/FMLDevServerLaunchProvider.java b/src/main/java/net/minecraftforge/fml/loading/FMLDevServerLaunchProvider.java index 86eb28e6c..ae30b3058 100644 --- a/src/main/java/net/minecraftforge/fml/loading/FMLDevServerLaunchProvider.java +++ b/src/main/java/net/minecraftforge/fml/loading/FMLDevServerLaunchProvider.java @@ -40,7 +40,7 @@ public class FMLDevServerLaunchProvider extends FMLCommonLaunchHandler implement @Override public String name() { - return "devfmlserver"; + return "fmldevserver"; } private static final List SKIPPACKAGES = Arrays.asList( diff --git a/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFileParser.java b/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFileParser.java index ff7296722..c894a490d 100644 --- a/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFileParser.java +++ b/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFileParser.java @@ -19,7 +19,7 @@ package net.minecraftforge.fml.loading.moddiscovery; -import com.electronwill.nightconfig.core.path.PathConfig; +import com.electronwill.nightconfig.core.file.FileConfig; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import net.minecraftforge.fml.language.IModFileInfo; @@ -49,10 +49,10 @@ public class ModFileParser { public static IModFileInfo loadModFile(final ModFile file, final Path modsjson) { - final PathConfig pathConfig = PathConfig.builder(modsjson).build(); - pathConfig.load(); - pathConfig.close(); - return new ModFileInfo(file, pathConfig); + final FileConfig fileConfig = FileConfig.builder(modsjson).build(); + fileConfig.load(); + fileConfig.close(); + return new ModFileInfo(file, fileConfig); } protected static List getCoreMods(final ModFile modFile) { diff --git a/src/main/java/net/minecraftforge/fml/network/NetworkDirection.java b/src/main/java/net/minecraftforge/fml/network/NetworkDirection.java index cc65356ae..972837163 100644 --- a/src/main/java/net/minecraftforge/fml/network/NetworkDirection.java +++ b/src/main/java/net/minecraftforge/fml/network/NetworkDirection.java @@ -27,10 +27,10 @@ import java.util.function.Supplier; public enum NetworkDirection { - PLAYSERVER(NetworkEvent.ClientCustomPayloadEvent::new, LogicalSide.CLIENT), - PLAYCLIENT(NetworkEvent.ServerCustomPayloadEvent::new, LogicalSide.SERVER), - LOGINSERVER(NetworkEvent.ClientCustomPayloadEvent::new, LogicalSide.CLIENT), - LOGINCLIENT(NetworkEvent.ServerCustomPayloadEvent::new, LogicalSide.SERVER); + PLAY_TO_SERVER(NetworkEvent.ClientCustomPayloadEvent::new, LogicalSide.CLIENT), + PLAY_TO_CLIENT(NetworkEvent.ServerCustomPayloadEvent::new, LogicalSide.SERVER), + LOGIN_TO_SERVER(NetworkEvent.ClientCustomPayloadEvent::new, LogicalSide.CLIENT), + LOGIN_TO_CLIENT(NetworkEvent.ServerCustomPayloadEvent::new, LogicalSide.SERVER); private final BiFunction, NetworkEvent> eventSupplier; private final LogicalSide logicalSide; diff --git a/src/main/java/net/minecraftforge/fml/network/NetworkHooks.java b/src/main/java/net/minecraftforge/fml/network/NetworkHooks.java index 6ba5dd01a..70fa3e688 100644 --- a/src/main/java/net/minecraftforge/fml/network/NetworkHooks.java +++ b/src/main/java/net/minecraftforge/fml/network/NetworkHooks.java @@ -62,22 +62,22 @@ public class NetworkHooks public static void onServerCustomPayload(final SPacketCustomPayload packet, final NetworkManager manager) { NetworkRegistry.findTarget(new ResourceLocation(packet.getChannelName())). - ifPresent(ni->ni.dispatch(NetworkDirection.PLAYSERVER, packet.getBufferData(), manager)); + ifPresent(ni->ni.dispatch(NetworkDirection.PLAY_TO_SERVER, packet.getBufferData(), manager)); } public static void onClientCustomPayload(final CPacketCustomPayload packet, final NetworkManager manager) { NetworkRegistry.findTarget(new ResourceLocation(packet.getChannelName())). - ifPresent(ni->ni.dispatch(NetworkDirection.PLAYCLIENT, packet.getBufferData(), manager)); + ifPresent(ni->ni.dispatch(NetworkDirection.PLAY_TO_CLIENT, packet.getBufferData(), manager)); } public static void onServerLoginCustomPayload(final SPacketCustomPayload packet, final NetworkManager manager) { NetworkRegistry.findTarget(new ResourceLocation(packet.getChannelName())). - ifPresent(ni->ni.dispatch(NetworkDirection.LOGINSERVER, packet.getBufferData(), manager)); + ifPresent(ni->ni.dispatch(NetworkDirection.LOGIN_TO_SERVER, packet.getBufferData(), manager)); } public static void onClientLoginCustomPayload(final CPacketCustomPayload packet, final NetworkManager manager) { NetworkRegistry.findTarget(new ResourceLocation(packet.getChannelName())). - ifPresent(ni->ni.dispatch(NetworkDirection.LOGINCLIENT, packet.getBufferData(), manager)); + ifPresent(ni->ni.dispatch(NetworkDirection.LOGIN_TO_CLIENT, packet.getBufferData(), manager)); } public static void registerServerChannel(NetworkManager manager, C00Handshake packet) diff --git a/src/main/java/net/minecraftforge/fml/network/simple/SimpleChannel.java b/src/main/java/net/minecraftforge/fml/network/simple/SimpleChannel.java index a7547a030..373d1408b 100644 --- a/src/main/java/net/minecraftforge/fml/network/simple/SimpleChannel.java +++ b/src/main/java/net/minecraftforge/fml/network/simple/SimpleChannel.java @@ -62,6 +62,10 @@ public class SimpleChannel Minecraft.getMinecraft().getConnection().sendPacket(payload); } + public MessageBuilder messageBuilder(final Class type, int id) { + return MessageBuilder.forType(this, type, id); + } + public static class MessageBuilder { private SimpleChannel channel; private Class type; @@ -70,7 +74,7 @@ public class SimpleChannel private Function decoder; private BiConsumer> consumer; - public static MessageBuilder forType(final SimpleChannel channel, final Class type, int id) { + private static MessageBuilder forType(final SimpleChannel channel, final Class type, int id) { MessageBuilder builder = new MessageBuilder<>(); builder.channel = channel; builder.id = id; diff --git a/src/main/resources/META-INF/services/cpw.mods.modlauncher.api.ILaunchHandlerService b/src/main/resources/META-INF/services/cpw.mods.modlauncher.api.ILaunchHandlerService index eb484bf44..d0168ed78 100644 --- a/src/main/resources/META-INF/services/cpw.mods.modlauncher.api.ILaunchHandlerService +++ b/src/main/resources/META-INF/services/cpw.mods.modlauncher.api.ILaunchHandlerService @@ -1,3 +1,3 @@ -net.minecraftforge.fml.loading.FMLLaunchProvider +net.minecraftforge.fml.loading.FMLClientLaunchProvider net.minecraftforge.fml.loading.FMLDevClientLaunchProvider net.minecraftforge.fml.loading.FMLDevServerLaunchProvider \ No newline at end of file