diff --git a/build.gradle b/build.gradle index d84a46148..5bf0a5a46 100644 --- a/build.gradle +++ b/build.gradle @@ -412,7 +412,7 @@ project(':forge') { installer 'org.ow2.asm:asm:6.2' installer 'org.ow2.asm:asm-commons:6.2' installer 'org.ow2.asm:asm-tree:6.2' - installer 'cpw.mods:modlauncher:3.1.+' + installer 'cpw.mods:modlauncher:3.2.+' installer 'cpw.mods:grossjava9hacks:1.1.+' installer 'net.minecraftforge:accesstransformers:0.16.+:shadowed' installer 'net.minecraftforge:eventbus:0.10.+:service' diff --git a/src/main/java/net/minecraftforge/fml/InterModComms.java b/src/main/java/net/minecraftforge/fml/InterModComms.java index 81c1af1fe..3c9b98a38 100644 --- a/src/main/java/net/minecraftforge/fml/InterModComms.java +++ b/src/main/java/net/minecraftforge/fml/InterModComms.java @@ -36,42 +36,99 @@ public class InterModComms public static final class IMCMessage { private final String modId; private final String method; + private final String senderModId; private final Supplier thing; - IMCMessage(String modId, String method, Supplier thing) + IMCMessage(String senderModId, String modId, String method, Supplier thing) { + this.senderModId = senderModId; this.modId = modId; this.method = method; this.thing = thing; } + /** + * @return The modid of the sender. This is supplied by the caller, or by the active mod container context. + * Consider it unreliable. + */ + public final String getSenderModId() { + return this.senderModId; + } + + /** + * @return The modid being sent to. + */ public final String getModId() { return this.modId; } + /** + * @return The method being sent to. + */ public final String getMethod() { return this.method; } + /** + * @param The type of the message. + * @return A {@link Supplier} of the message. + */ @SuppressWarnings("unchecked") public final Supplier getMessageSupplier() { return (Supplier)this.thing; } } + private static ConcurrentMap> containerQueues = new ConcurrentHashMap<>(); + /** + * Send IMC to remote. Sender will default to the active modcontainer, or minecraft if not. + * + * @param modId the mod id to send to + * @param method the method name to send + * @param thing the thing associated with the method name + * @return true if the message was enqueued for sending (the target modid is loaded) + */ 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)); + containerQueues.computeIfAbsent(modId, k->new ConcurrentLinkedQueue<>()).add(new IMCMessage(ModLoadingContext.get().getActiveContainer().getModId(), modId, method, thing)); return true; } + /** + * Send IMC to remote. + * + * @param senderModId the mod id you are sending from + * @param modId the mod id to send to + * @param method the method name to send + * @param thing the thing associated with the method name + * @return true if the message was enqueued for sending (the target modid is loaded) + */ + public static boolean sendTo(final String senderModId, 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(senderModId, modId, method, thing)); + return true; + } + + /** + * Retrieve pending messages for your modid. Use the predicate to filter the method name. + * + * @param modId the modid you are querying for + * @param methodMatcher a predicate for the method you are interested in + * @return All messages passing the supplied method predicate + */ 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); } + /** + * Retrieve all message for your modid. + * + * @param modId the modid you are querying for + * @return All messages + */ public static Stream getMessages(final String modId) { return getMessages(modId, s->Boolean.TRUE); }