Add a modfolderfactory. Fix up login payload exposure.
Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
parent
734a3d76aa
commit
bdce8d0494
5 changed files with 33 additions and 14 deletions
|
@ -408,7 +408,7 @@ project(':forge') {
|
|||
installer 'cpw.mods:grossjava9hacks:1.1.+'
|
||||
installer 'net.minecraftforge:accesstransformers:1.0.+:shadowed'
|
||||
installer 'net.minecraftforge:eventbus:1.0.+:service'
|
||||
installer 'net.minecraftforge:forgespi:1.2.+'
|
||||
installer 'net.minecraftforge:forgespi:1.3.+'
|
||||
installer 'net.minecraftforge:coremods:1.0.+'
|
||||
installer 'net.minecraftforge:unsafe:0.2.+'
|
||||
installer 'com.electronwill.night-config:core:3.6.0'
|
||||
|
|
|
@ -19,10 +19,12 @@
|
|||
|
||||
package net.minecraftforge.fml.loading.moddiscovery;
|
||||
|
||||
import cpw.mods.modlauncher.Launcher;
|
||||
import cpw.mods.modlauncher.ServiceLoaderStreamUtils;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.fml.loading.LoadingModList;
|
||||
import net.minecraftforge.fml.loading.ModSorter;
|
||||
import net.minecraftforge.forgespi.Environment;
|
||||
import net.minecraftforge.forgespi.locating.IModFile;
|
||||
import net.minecraftforge.forgespi.locating.IModLocator;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
@ -63,6 +65,7 @@ public class ModDiscoverer {
|
|||
private final List<IModLocator> locatorList;
|
||||
|
||||
public ModDiscoverer(Map<String, ?> arguments) {
|
||||
Launcher.INSTANCE.environment().computePropertyIfAbsent(Environment.Keys.MODFOLDERFACTORY.get(), v->ModsFolderLocator::new);
|
||||
locators = ServiceLoader.load(IModLocator.class);
|
||||
locatorList = ServiceLoaderStreamUtils.toList(this.locators);
|
||||
locatorList.forEach(l->l.initArguments(arguments));
|
||||
|
|
|
@ -38,15 +38,11 @@ import org.apache.logging.log4j.MarkerManager;
|
|||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static net.minecraftforge.registries.ForgeRegistry.REGISTRIES;
|
||||
|
@ -142,7 +138,7 @@ public class FMLHandshakeHandler {
|
|||
* @param <MSG> message type
|
||||
* @return A {@link BiConsumer} for use in message handling
|
||||
*/
|
||||
public static <MSG extends FMLHandshakeMessages.LoginIndexedMessage> BiConsumer<MSG, Supplier<NetworkEvent.Context>> biConsumerFor(ThreeConsumer<FMLHandshakeHandler, ? super MSG, ? super Supplier<NetworkEvent.Context>> consumer)
|
||||
public static <MSG extends IntSupplier> BiConsumer<MSG, Supplier<NetworkEvent.Context>> biConsumerFor(ThreeConsumer<FMLHandshakeHandler, ? super MSG, ? super Supplier<NetworkEvent.Context>> consumer)
|
||||
{
|
||||
return (m, c) -> ThreeConsumer.bindArgs(consumer, m, c).accept(getHandshake(c));
|
||||
}
|
||||
|
@ -157,7 +153,7 @@ public class FMLHandshakeHandler {
|
|||
* @param <MSG> message type
|
||||
* @return A {@link BiConsumer} for use in message handling
|
||||
*/
|
||||
public static <MSG extends FMLHandshakeMessages.LoginIndexedMessage> BiConsumer<MSG, Supplier<NetworkEvent.Context>> indexFirst(ThreeConsumer<FMLHandshakeHandler, MSG, Supplier<NetworkEvent.Context>> next)
|
||||
public static <MSG extends IntSupplier> BiConsumer<MSG, Supplier<NetworkEvent.Context>> indexFirst(ThreeConsumer<FMLHandshakeHandler, MSG, Supplier<NetworkEvent.Context>> next)
|
||||
{
|
||||
final BiConsumer<MSG, Supplier<NetworkEvent.Context>> loginIndexedMessageSupplierBiConsumer = biConsumerFor(FMLHandshakeHandler::handleIndexedMessage);
|
||||
return loginIndexedMessageSupplierBiConsumer.andThen(biConsumerFor(next));
|
||||
|
@ -194,12 +190,12 @@ public class FMLHandshakeHandler {
|
|||
LOGGER.debug(REGISTRIES, "Expecting {} registries: {}", ()->this.registriesToReceive.size(), ()->this.registriesToReceive);
|
||||
}
|
||||
|
||||
<MSG extends FMLHandshakeMessages.LoginIndexedMessage> void handleIndexedMessage(MSG message, Supplier<NetworkEvent.Context> c)
|
||||
<MSG extends IntSupplier> void handleIndexedMessage(MSG message, Supplier<NetworkEvent.Context> c)
|
||||
{
|
||||
LOGGER.debug(FMLHSMARKER, "Received client indexed reply {} of type {}", message.getLoginIndex(), message.getClass().getName());
|
||||
boolean removed = this.sentMessages.removeIf(i->i==message.getLoginIndex());
|
||||
LOGGER.debug(FMLHSMARKER, "Received client indexed reply {} of type {}", message.getAsInt(), message.getClass().getName());
|
||||
boolean removed = this.sentMessages.removeIf(i-> i == message.getAsInt());
|
||||
if (!removed) {
|
||||
LOGGER.error(FMLHSMARKER, "Recieved unexpected index {} in client reply", message.getLoginIndex());
|
||||
LOGGER.error(FMLHSMARKER, "Recieved unexpected index {} in client reply", message.getAsInt());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,8 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -38,7 +40,8 @@ import com.google.common.collect.Maps;
|
|||
|
||||
public class FMLHandshakeMessages
|
||||
{
|
||||
static class LoginIndexedMessage {
|
||||
static class LoginIndexedMessage implements IntSupplier
|
||||
{
|
||||
private int loginIndex;
|
||||
|
||||
void setLoginIndex(final int loginIndex) {
|
||||
|
@ -48,6 +51,11 @@ public class FMLHandshakeMessages
|
|||
int getLoginIndex() {
|
||||
return loginIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
return getLoginIndex();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Server to client "list of mods". Always first handshake message.
|
||||
|
|
|
@ -33,6 +33,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class SimpleChannel
|
||||
|
@ -112,6 +113,14 @@ public class SimpleChannel
|
|||
context.getPacketDispatcher().sendPacket(instance.getChannelName(), toBuffer(msgToReply).getLeft());
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new MessageBuilder. The type should implement {@link java.util.function.IntSupplier} if it is a login
|
||||
* packet.
|
||||
* @param type Type of message
|
||||
* @param id id in the indexed codec
|
||||
* @param <M> Type of type
|
||||
* @return a MessageBuilder
|
||||
*/
|
||||
public <M> MessageBuilder<M> messageBuilder(final Class<M> type, int id) {
|
||||
return MessageBuilder.forType(this, type, id);
|
||||
}
|
||||
|
@ -179,6 +188,9 @@ public class SimpleChannel
|
|||
message.setLoginIndexSetter(this.loginIndexSetter);
|
||||
}
|
||||
if (this.loginIndexGetter != null) {
|
||||
if (!IntSupplier.class.isAssignableFrom(this.type)) {
|
||||
throw new IllegalArgumentException("Login packet type that does not supply an index as an IntSupplier");
|
||||
}
|
||||
message.setLoginIndexGetter(this.loginIndexGetter);
|
||||
}
|
||||
if (this.loginPacketGenerators != null) {
|
||||
|
|
Loading…
Reference in a new issue