mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 11:05:40 +00:00
Update to 0.10 modlauncher API with performance improvements..
Signed-off-by: cpw <[email protected]>
This commit is contained in:
9 files changed
+103
-52
No files matched your search
@@ -28,6 +28,7 @@ import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraftforge.fml.config.ConfigTracker;
|
||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||
import net.minecraftforge.fml.util.ThreeConsumer;
|
||||
import net.minecraftforge.registries.ForgeRegistry;
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -35,10 +36,14 @@ import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static net.minecraftforge.registries.ForgeRegistry.REGISTRIES;
|
||||
|
||||
/**
|
||||
* Instance responsible for handling the overall FML network handshake.
|
||||
*
|
||||
@@ -176,6 +181,9 @@ public class FMLHandshakeHandler {
|
||||
private final NetworkDirection direction;
|
||||
private final NetworkManager manager;
|
||||
private int packetPosition;
|
||||
private ForgeRegistry.Snapshot registrySnapshot;
|
||||
private Set<String> registriesToReceive;
|
||||
|
||||
private FMLHandshakeHandler(NetworkManager networkManager, NetworkDirection side)
|
||||
{
|
||||
this.direction = side;
|
||||
@@ -199,6 +207,8 @@ public class FMLHandshakeHandler {
|
||||
LOGGER.debug(FMLHSMARKER, "Accepted server connection");
|
||||
// Set the modded marker on the channel so we know we got packets
|
||||
c.get().getNetworkManager().channel().attr(FMLNetworking.FML_MARKER).set(NetworkHooks.NETVERSION);
|
||||
this.registriesToReceive = new HashSet<>(serverModList.getRegistries());
|
||||
LOGGER.debug(REGISTRIES, "Expecting {} registries: {}", ()->this.registriesToReceive.size(), ()->this.registriesToReceive);
|
||||
}
|
||||
|
||||
private <MSG extends FMLHandshakeMessages.LoginIndexedMessage> void handleIndexedMessage(MSG message, Supplier<NetworkEvent.Context> c)
|
||||
@@ -223,10 +233,12 @@ public class FMLHandshakeHandler {
|
||||
LOGGER.debug(FMLHSMARKER, "Accepted client connection mod list");
|
||||
}
|
||||
private void handleRegistryMessage(final FMLHandshakeMessages.S2CRegistry registryPacket, final Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
this.registriesToReceive.remove(registryPacket.getRegistryName());
|
||||
RegistryManager.acceptRegistry(registryPacket, contextSupplier);
|
||||
contextSupplier.get().setPacketHandled(true);
|
||||
final FMLHandshakeMessages.C2SAcknowledge reply = new FMLHandshakeMessages.C2SAcknowledge();
|
||||
channel.reply(reply, contextSupplier.get());
|
||||
if (this.registriesToReceive.isEmpty()) {}//injectSnapshot
|
||||
}
|
||||
|
||||
private void handleClientAck(final FMLHandshakeMessages.C2SAcknowledge msg, final Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
|
||||
@@ -29,6 +29,7 @@ import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
|
||||
import net.minecraftforge.registries.ForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -51,6 +52,7 @@ public class FMLHandshakeMessages
|
||||
*/
|
||||
public static class S2CModList extends LoginIndexedMessage
|
||||
{
|
||||
private List<String> registries;
|
||||
private NBTTagList channels;
|
||||
private List<String> modList;
|
||||
|
||||
@@ -62,6 +64,7 @@ public class FMLHandshakeMessages
|
||||
{
|
||||
this.modList = nbtTagCompound.getList("modlist", 8).stream().map(INBTBase::getString).collect(Collectors.toList());
|
||||
this.channels = nbtTagCompound.getList("channels", 10);
|
||||
this.registries = nbtTagCompound.getList("registries", 8).stream().map(INBTBase::getString).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static S2CModList decode(PacketBuffer packetBuffer)
|
||||
@@ -75,6 +78,7 @@ public class FMLHandshakeMessages
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setTag("modlist",modList.stream().map(NBTTagString::new).collect(Collectors.toCollection(NBTTagList::new)));
|
||||
tag.setTag("channels", NetworkRegistry.buildChannelVersions());
|
||||
tag.setTag("registries", RegistryManager.registryNames().stream().map(NBTTagString::new).collect(Collectors.toCollection(NBTTagList::new)));
|
||||
packetBuffer.writeCompoundTag(tag);
|
||||
}
|
||||
|
||||
@@ -82,6 +86,9 @@ public class FMLHandshakeMessages
|
||||
return String.join(",", modList);
|
||||
}
|
||||
|
||||
List<String> getRegistries() {
|
||||
return this.registries;
|
||||
}
|
||||
NBTTagList getChannels() {
|
||||
return this.channels;
|
||||
}
|
||||
@@ -119,17 +126,26 @@ public class FMLHandshakeMessages
|
||||
}
|
||||
|
||||
public static class S2CRegistry extends LoginIndexedMessage {
|
||||
private String registryName;
|
||||
|
||||
public S2CRegistry(final ResourceLocation key, final ForgeRegistry<? extends IForgeRegistryEntry<?>> registry) {
|
||||
registryName = key.toString();
|
||||
}
|
||||
|
||||
S2CRegistry() {
|
||||
private S2CRegistry(final String registryName) {
|
||||
this.registryName = registryName;
|
||||
}
|
||||
|
||||
void encode(final PacketBuffer buffer) {
|
||||
buffer.writeString(registryName, 128);
|
||||
}
|
||||
|
||||
public static S2CRegistry decode(final PacketBuffer buffer) {
|
||||
return new S2CRegistry();
|
||||
return new S2CRegistry(buffer.readString(128));
|
||||
}
|
||||
|
||||
public String getRegistryName() {
|
||||
return registryName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import static net.minecraftforge.registries.ForgeRegistry.REGISTRIES;
|
||||
|
||||
public class RegistryManager
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
@@ -154,7 +156,11 @@ public class RegistryManager
|
||||
collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<String> registryNames() {
|
||||
return ACTIVE.registries.entrySet().stream().map(Map.Entry::getKey).map(Object::toString).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static void acceptRegistry(final FMLHandshakeMessages.S2CRegistry registryUpdate, final Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
LOGGER.debug("Received registry packet");
|
||||
LOGGER.debug(REGISTRIES,"Received registry packet for {}", registryUpdate.getRegistryName());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user