Moving some stuff around, network and server events.
This commit is contained in:
parent
689ebd8036
commit
6e99f84e91
|
@ -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 <T> Supplier<T> getMessageSupplier() {
|
||||||
|
return (Supplier<T>)this.thing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static ConcurrentMap<String, ConcurrentLinkedQueue<IMCMessage>> 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<IMCMessage> getMessages(final String modId, final Predicate<String> methodMatcher) {
|
||||||
|
ConcurrentLinkedQueue<IMCMessage> queue = containerQueues.get(modId);
|
||||||
|
if (queue == null) return Stream.empty();
|
||||||
|
return StreamSupport.stream(new QueueFilteringSpliterator(queue, methodMatcher), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Stream<IMCMessage> getMessages(final String modId) {
|
||||||
|
return getMessages(modId, s->Boolean.TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class QueueFilteringSpliterator implements Spliterator<IMCMessage>
|
||||||
|
{
|
||||||
|
private final ConcurrentLinkedQueue<IMCMessage> queue;
|
||||||
|
private final Predicate<String> methodFilter;
|
||||||
|
private final Iterator<IMCMessage> iterator;
|
||||||
|
|
||||||
|
public QueueFilteringSpliterator(final ConcurrentLinkedQueue<IMCMessage> queue, final Predicate<String> 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<? super IMCMessage> 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<IMCMessage> trySplit() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -60,16 +60,16 @@ public class ServerLifecycleHooks
|
||||||
return !MinecraftForge.EVENT_BUS.post(new FMLServerStartingEvent(server));
|
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);
|
allowLogins.set(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleServerStopping()
|
public static void handleServerStopping(final MinecraftServer server)
|
||||||
{
|
{
|
||||||
allowLogins.set(false);
|
allowLogins.set(false);
|
||||||
MinecraftForge.EVENT_BUS.post(new FMLServerStoppingEvent());
|
MinecraftForge.EVENT_BUS.post(new FMLServerStoppingEvent(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void expectServerStopped()
|
public static void expectServerStopped()
|
||||||
|
@ -79,7 +79,7 @@ public class ServerLifecycleHooks
|
||||||
|
|
||||||
public static void handleServerStopped(final MinecraftServer server)
|
public static void handleServerStopped(final MinecraftServer server)
|
||||||
{
|
{
|
||||||
MinecraftForge.EVENT_BUS.post(new FMLServerStoppedEvent());
|
MinecraftForge.EVENT_BUS.post(new FMLServerStoppedEvent(server));
|
||||||
currentServer = null;
|
currentServer = null;
|
||||||
LogicalSidedProvider.setServer(null);
|
LogicalSidedProvider.setServer(null);
|
||||||
CountDownLatch latch = exitLatch;
|
CountDownLatch latch = exitLatch;
|
||||||
|
|
|
@ -34,8 +34,6 @@ import net.minecraftforge.fml.common.event.ModLifecycleEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLLoadEvent;
|
import net.minecraftforge.fml.common.event.FMLLoadEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLModDisabledEvent;
|
import net.minecraftforge.fml.common.event.FMLModDisabledEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
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.common.versioning.ArtifactVersion;
|
||||||
|
|
||||||
import net.minecraftforge.fml.ModContainer;
|
import net.minecraftforge.fml.ModContainer;
|
||||||
|
|
|
@ -44,7 +44,6 @@ import net.minecraftforge.common.crafting.CraftingHelper;
|
||||||
import net.minecraftforge.fml.ModContainer;
|
import net.minecraftforge.fml.ModContainer;
|
||||||
import net.minecraftforge.fml.ModContainer.Disableable;
|
import net.minecraftforge.fml.ModContainer.Disableable;
|
||||||
import net.minecraftforge.fml.common.ProgressManager.ProgressBar;
|
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.FMLLoadEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLModIdMappingEvent;
|
import net.minecraftforge.fml.common.event.FMLModIdMappingEvent;
|
||||||
import net.minecraftforge.fml.common.registry.*;
|
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.DependencyParser;
|
||||||
import net.minecraftforge.fml.common.versioning.VersionParser;
|
import net.minecraftforge.fml.common.versioning.VersionParser;
|
||||||
import net.minecraftforge.fml.relauncher.ModListHelper;
|
import net.minecraftforge.fml.relauncher.ModListHelper;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.registries.GameData;
|
import net.minecraftforge.registries.GameData;
|
||||||
import net.minecraftforge.registries.ObjectHolderRegistry;
|
import net.minecraftforge.registries.ObjectHolderRegistry;
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.fml.common.event.ModLifecycleEvent;
|
import net.minecraftforge.fml.common.event.ModLifecycleEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent;
|
import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
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.FMLPostInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLServerAboutToStartEvent;
|
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.FMLServerStartingEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLServerStoppedEvent;
|
import net.minecraftforge.fml.common.event.FMLServerStoppedEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent;
|
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCEvent;
|
|
||||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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<IMCMessage> emptyIMCList = ImmutableList.of();
|
|
||||||
private static ArrayListMultimap<String, IMCMessage> 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<IMCMessage> currentList;
|
|
||||||
|
|
||||||
public ImmutableList<IMCMessage> 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 <T> The argument type
|
|
||||||
* @param <V> The result type
|
|
||||||
* @return The function value or Optional.absent if it wasn't readable or isn't a function call
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <T,V> Optional<Function<T,V>> getFunctionValue(Class<T> functionFrom, Class<V> functionTo) {
|
|
||||||
if (!isFunction) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Function<T,V> 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<IMCMessage> fetchRuntimeMessages(Object forMod)
|
|
||||||
{
|
|
||||||
ModContainer mc = FMLCommonHandler.instance().findContainerFor(forMod);
|
|
||||||
if (mc != null)
|
|
||||||
{
|
|
||||||
return ImmutableList.copyOf(modMessages.removeAll(mc.getModId()));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return emptyIMCList;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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}.
|
* 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.
|
* 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
|
* @author cpw
|
||||||
*/
|
*/
|
||||||
public class FMLServerAboutToStartEvent extends FMLStateEvent {
|
public class FMLServerAboutToStartEvent extends ServerLifecycleEvent {
|
||||||
|
|
||||||
private final MinecraftServer server;
|
|
||||||
|
|
||||||
public FMLServerAboutToStartEvent(MinecraftServer server)
|
public FMLServerAboutToStartEvent(MinecraftServer server)
|
||||||
{
|
{
|
||||||
this.server = (MinecraftServer) server;
|
super(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MinecraftServer getServer()
|
|
||||||
{
|
|
||||||
return server;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,16 +19,18 @@
|
||||||
|
|
||||||
package net.minecraftforge.fml.common.event;
|
package net.minecraftforge.fml.common.event;
|
||||||
|
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called after {@link FMLServerStartingEvent} when the server is available and ready to play.
|
* 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
|
* @author cpw
|
||||||
*/
|
*/
|
||||||
public class FMLServerStartedEvent extends FMLStateEvent
|
public class FMLServerStartedEvent extends ServerLifecycleEvent
|
||||||
{
|
{
|
||||||
|
|
||||||
public FMLServerStartedEvent()
|
public FMLServerStartedEvent(final MinecraftServer server)
|
||||||
{
|
{
|
||||||
|
super(server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* This event allows for customizations of the server, such as loading custom commands, perhaps customizing recipes or
|
||||||
* other activities.
|
* other activities.
|
||||||
*
|
*
|
||||||
* @see net.minecraftforge.fml.common.Mod.EventHandler for how to subscribe to this event
|
|
||||||
* @author cpw
|
* @author cpw
|
||||||
*/
|
*/
|
||||||
public class FMLServerStartingEvent extends FMLStateEvent
|
public class FMLServerStartingEvent extends ServerLifecycleEvent
|
||||||
{
|
{
|
||||||
|
|
||||||
private final MinecraftServer server;
|
|
||||||
|
|
||||||
public FMLServerStartingEvent(final MinecraftServer server)
|
public FMLServerStartingEvent(final MinecraftServer server)
|
||||||
{
|
{
|
||||||
this.server = (MinecraftServer) server;
|
super(server);
|
||||||
}
|
|
||||||
|
|
||||||
public MinecraftServer getServer()
|
|
||||||
{
|
|
||||||
return server;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerServerCommand(ICommand command)
|
public void registerServerCommand(ICommand command)
|
||||||
|
|
|
@ -19,13 +19,18 @@
|
||||||
|
|
||||||
package net.minecraftforge.fml.common.event;
|
package net.minecraftforge.fml.common.event;
|
||||||
|
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called after {@link FMLServerStoppingEvent} when the server has completely shut down.
|
* Called after {@link FMLServerStoppingEvent} when the server has completely shut down.
|
||||||
* Called immediately before shutting down, on the dedicated server, and before returning
|
* Called immediately before shutting down, on the dedicated server, and before returning
|
||||||
* to the main menu on the client.
|
* to the main menu on the client.
|
||||||
*
|
*
|
||||||
* @see net.minecraftforge.fml.common.Mod.EventHandler for how to subscribe to this event
|
|
||||||
* @author cpw
|
* @author cpw
|
||||||
*/
|
*/
|
||||||
public class FMLServerStoppedEvent extends FMLStateEvent {
|
public class FMLServerStoppedEvent extends ServerLifecycleEvent {
|
||||||
|
public FMLServerStoppedEvent(MinecraftServer server)
|
||||||
|
{
|
||||||
|
super(server);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,17 @@
|
||||||
|
|
||||||
package net.minecraftforge.fml.common.event;
|
package net.minecraftforge.fml.common.event;
|
||||||
|
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the server begins an orderly shutdown, before {@link FMLServerStoppedEvent}.
|
* 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
|
* @author cpw
|
||||||
*/
|
*/
|
||||||
public class FMLServerStoppingEvent extends FMLStateEvent
|
public class FMLServerStoppingEvent extends ServerLifecycleEvent
|
||||||
{
|
{
|
||||||
|
public FMLServerStoppingEvent(MinecraftServer server)
|
||||||
|
{
|
||||||
|
super(server);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,27 +19,21 @@
|
||||||
|
|
||||||
package net.minecraftforge.fml.common.event;
|
package net.minecraftforge.fml.common.event;
|
||||||
|
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.eventbus.api.Event;
|
||||||
|
|
||||||
/**
|
public class ServerLifecycleEvent extends Event
|
||||||
* The parent of all mod-state changing events
|
|
||||||
*/
|
|
||||||
public abstract class FMLStateEvent extends ModLifecycleEvent
|
|
||||||
{
|
{
|
||||||
|
|
||||||
public FMLStateEvent()
|
protected final MinecraftServer server;
|
||||||
|
|
||||||
|
public ServerLifecycleEvent(MinecraftServer server)
|
||||||
{
|
{
|
||||||
super(null);
|
this.server = server;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public MinecraftServer getServer()
|
||||||
* 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()
|
|
||||||
{
|
{
|
||||||
return FMLCommonHandler.instance().getSide();
|
return server;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
package net.minecraftforge.fml.loading;
|
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.language.IModInfo;
|
||||||
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
|
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
|
||||||
|
|
||||||
|
@ -31,12 +31,12 @@ import java.util.List;
|
||||||
public class DefaultModInfos
|
public class DefaultModInfos
|
||||||
{
|
{
|
||||||
static {
|
static {
|
||||||
PathConfig minecraftmod;
|
FileConfig minecraftmod;
|
||||||
PathConfig forgemod;
|
FileConfig forgemod;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
minecraftmod = PathConfig.of(Paths.get(DefaultModInfos.class.getClassLoader().getResource("minecraftmod.toml").toURI()));
|
minecraftmod = FileConfig.of(Paths.get(DefaultModInfos.class.getClassLoader().getResource("minecraftmod.toml").toURI()));
|
||||||
forgemod = PathConfig.of(Paths.get(DefaultModInfos.class.getClassLoader().getResource("forgemod.toml").toURI()));
|
forgemod = FileConfig.of(Paths.get(DefaultModInfos.class.getClassLoader().getResource("forgemod.toml").toURI()));
|
||||||
minecraftmod.load();
|
minecraftmod.load();
|
||||||
forgemod.load();
|
forgemod.load();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,12 @@ import net.minecraftforge.api.distmarker.Dist;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
public class FMLLaunchProvider extends FMLCommonLaunchHandler implements ILaunchHandlerService
|
public class FMLClientLaunchProvider extends FMLCommonLaunchHandler implements ILaunchHandlerService
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public String name()
|
public String name()
|
||||||
{
|
{
|
||||||
return "fml";
|
return "fmlclient";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -40,7 +40,7 @@ public class FMLDevClientLaunchProvider extends FMLCommonLaunchHandler implement
|
||||||
@Override
|
@Override
|
||||||
public String name()
|
public String name()
|
||||||
{
|
{
|
||||||
return "devfmlclient";
|
return "fmldevclient";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final List<String> SKIPPACKAGES = Arrays.asList(
|
private static final List<String> SKIPPACKAGES = Arrays.asList(
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class FMLDevServerLaunchProvider extends FMLCommonLaunchHandler implement
|
||||||
@Override
|
@Override
|
||||||
public String name()
|
public String name()
|
||||||
{
|
{
|
||||||
return "devfmlserver";
|
return "fmldevserver";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final List<String> SKIPPACKAGES = Arrays.asList(
|
private static final List<String> SKIPPACKAGES = Arrays.asList(
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
package net.minecraftforge.fml.loading.moddiscovery;
|
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.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import net.minecraftforge.fml.language.IModFileInfo;
|
import net.minecraftforge.fml.language.IModFileInfo;
|
||||||
|
@ -49,10 +49,10 @@ public class ModFileParser {
|
||||||
|
|
||||||
public static IModFileInfo loadModFile(final ModFile file, final Path modsjson)
|
public static IModFileInfo loadModFile(final ModFile file, final Path modsjson)
|
||||||
{
|
{
|
||||||
final PathConfig pathConfig = PathConfig.builder(modsjson).build();
|
final FileConfig fileConfig = FileConfig.builder(modsjson).build();
|
||||||
pathConfig.load();
|
fileConfig.load();
|
||||||
pathConfig.close();
|
fileConfig.close();
|
||||||
return new ModFileInfo(file, pathConfig);
|
return new ModFileInfo(file, fileConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static List<CoreModFile> getCoreMods(final ModFile modFile) {
|
protected static List<CoreModFile> getCoreMods(final ModFile modFile) {
|
||||||
|
|
|
@ -27,10 +27,10 @@ import java.util.function.Supplier;
|
||||||
|
|
||||||
public enum NetworkDirection
|
public enum NetworkDirection
|
||||||
{
|
{
|
||||||
PLAYSERVER(NetworkEvent.ClientCustomPayloadEvent::new, LogicalSide.CLIENT),
|
PLAY_TO_SERVER(NetworkEvent.ClientCustomPayloadEvent::new, LogicalSide.CLIENT),
|
||||||
PLAYCLIENT(NetworkEvent.ServerCustomPayloadEvent::new, LogicalSide.SERVER),
|
PLAY_TO_CLIENT(NetworkEvent.ServerCustomPayloadEvent::new, LogicalSide.SERVER),
|
||||||
LOGINSERVER(NetworkEvent.ClientCustomPayloadEvent::new, LogicalSide.CLIENT),
|
LOGIN_TO_SERVER(NetworkEvent.ClientCustomPayloadEvent::new, LogicalSide.CLIENT),
|
||||||
LOGINCLIENT(NetworkEvent.ServerCustomPayloadEvent::new, LogicalSide.SERVER);
|
LOGIN_TO_CLIENT(NetworkEvent.ServerCustomPayloadEvent::new, LogicalSide.SERVER);
|
||||||
|
|
||||||
private final BiFunction<PacketBuffer, Supplier<NetworkEvent.Context>, NetworkEvent> eventSupplier;
|
private final BiFunction<PacketBuffer, Supplier<NetworkEvent.Context>, NetworkEvent> eventSupplier;
|
||||||
private final LogicalSide logicalSide;
|
private final LogicalSide logicalSide;
|
||||||
|
|
|
@ -62,22 +62,22 @@ public class NetworkHooks
|
||||||
|
|
||||||
public static void onServerCustomPayload(final SPacketCustomPayload packet, final NetworkManager manager) {
|
public static void onServerCustomPayload(final SPacketCustomPayload packet, final NetworkManager manager) {
|
||||||
NetworkRegistry.findTarget(new ResourceLocation(packet.getChannelName())).
|
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) {
|
public static void onClientCustomPayload(final CPacketCustomPayload packet, final NetworkManager manager) {
|
||||||
NetworkRegistry.findTarget(new ResourceLocation(packet.getChannelName())).
|
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) {
|
public static void onServerLoginCustomPayload(final SPacketCustomPayload packet, final NetworkManager manager) {
|
||||||
NetworkRegistry.findTarget(new ResourceLocation(packet.getChannelName())).
|
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) {
|
public static void onClientLoginCustomPayload(final CPacketCustomPayload packet, final NetworkManager manager) {
|
||||||
NetworkRegistry.findTarget(new ResourceLocation(packet.getChannelName())).
|
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)
|
public static void registerServerChannel(NetworkManager manager, C00Handshake packet)
|
||||||
|
|
|
@ -62,6 +62,10 @@ public class SimpleChannel
|
||||||
Minecraft.getMinecraft().getConnection().sendPacket(payload);
|
Minecraft.getMinecraft().getConnection().sendPacket(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <M> MessageBuilder<M> messageBuilder(final Class<M> type, int id) {
|
||||||
|
return MessageBuilder.forType(this, type, id);
|
||||||
|
}
|
||||||
|
|
||||||
public static class MessageBuilder<MSG> {
|
public static class MessageBuilder<MSG> {
|
||||||
private SimpleChannel channel;
|
private SimpleChannel channel;
|
||||||
private Class<MSG> type;
|
private Class<MSG> type;
|
||||||
|
@ -70,7 +74,7 @@ public class SimpleChannel
|
||||||
private Function<PacketBuffer, MSG> decoder;
|
private Function<PacketBuffer, MSG> decoder;
|
||||||
private BiConsumer<MSG, Supplier<NetworkEvent.Context>> consumer;
|
private BiConsumer<MSG, Supplier<NetworkEvent.Context>> consumer;
|
||||||
|
|
||||||
public static <MSG> MessageBuilder<MSG> forType(final SimpleChannel channel, final Class<MSG> type, int id) {
|
private static <MSG> MessageBuilder<MSG> forType(final SimpleChannel channel, final Class<MSG> type, int id) {
|
||||||
MessageBuilder<MSG> builder = new MessageBuilder<>();
|
MessageBuilder<MSG> builder = new MessageBuilder<>();
|
||||||
builder.channel = channel;
|
builder.channel = channel;
|
||||||
builder.id = id;
|
builder.id = id;
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
net.minecraftforge.fml.loading.FMLLaunchProvider
|
net.minecraftforge.fml.loading.FMLClientLaunchProvider
|
||||||
net.minecraftforge.fml.loading.FMLDevClientLaunchProvider
|
net.minecraftforge.fml.loading.FMLDevClientLaunchProvider
|
||||||
net.minecraftforge.fml.loading.FMLDevServerLaunchProvider
|
net.minecraftforge.fml.loading.FMLDevServerLaunchProvider
|
Loading…
Reference in New Issue