mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-21 12:42:26 +00:00
Update to 1.17
Update to Official classnames Patchwork Make the game compile and run Merge in the new HUD overlay API Merge in the new render properties API PEEL Use Gradle 7.2 snapshot to fix eclipse integration bug in 7.1, Would use 7.0 but FG needs 7.1 for some reason. New FML installer Update to 1.17.1 Co-authored-by: LexManos <[email protected]> Co-authored-by: SizableShrimp <[email protected]> Co-authored-by: cpw <[email protected]> Co-authored-by: Curle <[email protected]> Co-authored-by: Unnoen <[email protected]> Co-authored-by: covers1624 <[email protected]> Co-authored-by: DaemonUmbra <[email protected]> Co-authored-by: gigaherz <[email protected]> Signed-off-by: SizableShrimp <[email protected]>
This commit is contained in:
1 parent
064ae6961b
commit
be5446b91c
1990 files changed
+35661
-37544
No files matched your search
@@ -26,13 +26,13 @@ import java.util.function.BiConsumer;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import net.minecraft.network.IPacket;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.PacketDirection;
|
||||
import net.minecraft.network.ProtocolType;
|
||||
import net.minecraft.network.play.server.SAdvancementInfoPacket;
|
||||
import net.minecraft.network.play.server.STagsListPacket;
|
||||
import net.minecraft.network.play.server.SUpdateRecipesPacket;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
import net.minecraft.network.ConnectionProtocol;
|
||||
import net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundUpdateTagsPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
@@ -49,12 +49,12 @@ public class ForgeConnectionNetworkFilter extends VanillaPacketFilter
|
||||
this(null);
|
||||
}
|
||||
|
||||
public ForgeConnectionNetworkFilter(@Nullable NetworkManager manager)
|
||||
public ForgeConnectionNetworkFilter(@Nullable Connection manager)
|
||||
{
|
||||
super(buildHandlers(manager));
|
||||
}
|
||||
|
||||
private static Map<Class<? extends IPacket<?>>, BiConsumer<IPacket<?>, List<? super IPacket<?>>>> buildHandlers(@Nullable NetworkManager manager)
|
||||
private static Map<Class<? extends Packet<?>>, BiConsumer<Packet<?>, List<? super Packet<?>>>> buildHandlers(@Nullable Connection manager)
|
||||
{
|
||||
|
||||
VanillaPacketSplitter.RemoteCompatibility compatibility = manager == null ? VanillaPacketSplitter.RemoteCompatibility.ABSENT : VanillaPacketSplitter.getRemoteCompatibility(manager);
|
||||
@@ -62,28 +62,25 @@ public class ForgeConnectionNetworkFilter extends VanillaPacketFilter
|
||||
{
|
||||
return ImmutableMap.of();
|
||||
}
|
||||
ImmutableMap.Builder<Class<? extends IPacket<?>>, BiConsumer<IPacket<?>, List<? super IPacket<?>>>> builder = ImmutableMap.<Class<? extends IPacket<?>>, BiConsumer<IPacket<?>, List<? super IPacket<?>>>>builder()
|
||||
.put(SUpdateRecipesPacket.class, ForgeConnectionNetworkFilter::splitPacket)
|
||||
.put(STagsListPacket.class, ForgeConnectionNetworkFilter::splitPacket);
|
||||
ImmutableMap.Builder<Class<? extends Packet<?>>, BiConsumer<Packet<?>, List<? super Packet<?>>>> builder = ImmutableMap.<Class<? extends Packet<?>>, BiConsumer<Packet<?>, List<? super Packet<?>>>>builder()
|
||||
.put(ClientboundUpdateRecipesPacket.class, ForgeConnectionNetworkFilter::splitPacket)
|
||||
.put(ClientboundUpdateTagsPacket.class, ForgeConnectionNetworkFilter::splitPacket)
|
||||
.put(ClientboundUpdateAdvancementsPacket.class, ForgeConnectionNetworkFilter::splitPacket);
|
||||
|
||||
if (compatibility == VanillaPacketSplitter.RemoteCompatibility.V11)
|
||||
{
|
||||
builder.put(SAdvancementInfoPacket.class, ForgeConnectionNetworkFilter::splitPacket);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isNecessary(NetworkManager manager)
|
||||
protected boolean isNecessary(Connection manager)
|
||||
{
|
||||
// not needed on local connections, because packets are not encoded to bytes there
|
||||
return !manager.isMemoryConnection() && VanillaPacketSplitter.isRemoteCompatible(manager);
|
||||
}
|
||||
|
||||
private static void splitPacket(IPacket<?> packet, List<? super IPacket<?>> out)
|
||||
private static void splitPacket(Packet<?> packet, List<? super Packet<?>> out)
|
||||
{
|
||||
VanillaPacketSplitter.appendPackets(
|
||||
ProtocolType.PLAY, PacketDirection.CLIENTBOUND, packet, out
|
||||
ConnectionProtocol.PLAY, PacketFlow.CLIENTBOUND, packet, out
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ package net.minecraftforge.network;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Connection;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -34,12 +34,12 @@ public class NetworkFilters
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
private static final Map<String, Function<NetworkManager, VanillaPacketFilter>> instances = ImmutableMap.of(
|
||||
private static final Map<String, Function<Connection, VanillaPacketFilter>> instances = ImmutableMap.of(
|
||||
"forge:vanilla_filter", manager -> new VanillaConnectionNetworkFilter(),
|
||||
"forge:forge_fixes", ForgeConnectionNetworkFilter::new
|
||||
);
|
||||
|
||||
public static void injectIfNecessary(NetworkManager manager)
|
||||
public static void injectIfNecessary(Connection manager)
|
||||
{
|
||||
instances.forEach((key, filterFactory) -> {
|
||||
VanillaPacketFilter filter = filterFactory.apply(manager);
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
package net.minecraftforge.network;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
@@ -27,14 +26,14 @@ import java.util.function.BiConsumer;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import net.minecraft.command.ISuggestionProvider;
|
||||
import net.minecraft.command.arguments.ArgumentTypes;
|
||||
import net.minecraft.network.IPacket;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.server.SCommandListPacket;
|
||||
import net.minecraft.network.play.server.SEntityPropertiesPacket;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypes;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.game.ClientboundCommandsPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.fmllegacy.network.NetworkHooks;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -56,15 +55,15 @@ public class VanillaConnectionNetworkFilter extends VanillaPacketFilter
|
||||
public VanillaConnectionNetworkFilter()
|
||||
{
|
||||
super(
|
||||
ImmutableMap.<Class<? extends IPacket<?>>, BiConsumer<IPacket<?>, List<? super IPacket<?>>>>builder()
|
||||
.put(handler(SEntityPropertiesPacket.class, VanillaConnectionNetworkFilter::filterEntityProperties))
|
||||
.put(handler(SCommandListPacket.class, VanillaConnectionNetworkFilter::filterCommandList))
|
||||
ImmutableMap.<Class<? extends Packet<?>>, BiConsumer<Packet<?>, List<? super Packet<?>>>>builder()
|
||||
.put(handler(ClientboundUpdateAttributesPacket.class, VanillaConnectionNetworkFilter::filterEntityProperties))
|
||||
.put(handler(ClientboundCommandsPacket.class, VanillaConnectionNetworkFilter::filterCommandList))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isNecessary(NetworkManager manager)
|
||||
protected boolean isNecessary(Connection manager)
|
||||
{
|
||||
return NetworkHooks.isVanillaConnection(manager);
|
||||
}
|
||||
@@ -74,9 +73,9 @@ public class VanillaConnectionNetworkFilter extends VanillaPacketFilter
|
||||
* A vanilla client would ignore these with an error log.
|
||||
*/
|
||||
@Nonnull
|
||||
private static SEntityPropertiesPacket filterEntityProperties(SEntityPropertiesPacket msg)
|
||||
private static ClientboundUpdateAttributesPacket filterEntityProperties(ClientboundUpdateAttributesPacket msg)
|
||||
{
|
||||
SEntityPropertiesPacket newPacket = new SEntityPropertiesPacket(msg.getEntityId(), Collections.emptyList());
|
||||
ClientboundUpdateAttributesPacket newPacket = new ClientboundUpdateAttributesPacket(msg.getEntityId(), Collections.emptyList());
|
||||
msg.getValues().stream()
|
||||
.filter(snapshot -> {
|
||||
ResourceLocation key = ForgeRegistries.ATTRIBUTES.getKey(snapshot.getAttribute());
|
||||
@@ -91,13 +90,13 @@ public class VanillaConnectionNetworkFilter extends VanillaPacketFilter
|
||||
* A vanilla client would fail to deserialize the packet and disconnect with an error message if these were sent.
|
||||
*/
|
||||
@Nonnull
|
||||
private static SCommandListPacket filterCommandList(SCommandListPacket packet)
|
||||
private static ClientboundCommandsPacket filterCommandList(ClientboundCommandsPacket packet)
|
||||
{
|
||||
RootCommandNode<ISuggestionProvider> root = packet.getRoot();
|
||||
RootCommandNode<ISuggestionProvider> newRoot = CommandTreeCleaner.cleanArgumentTypes(root, argType -> {
|
||||
RootCommandNode<SharedSuggestionProvider> root = packet.getRoot();
|
||||
RootCommandNode<SharedSuggestionProvider> newRoot = CommandTreeCleaner.cleanArgumentTypes(root, argType -> {
|
||||
ResourceLocation id = ArgumentTypes.getId(argType);
|
||||
return id != null && (id.getNamespace().equals("minecraft") || id.getNamespace().equals("brigadier"));
|
||||
});
|
||||
return new SCommandListPacket(newRoot);
|
||||
return new ClientboundCommandsPacket(newRoot);
|
||||
}
|
||||
}
|
||||
@@ -29,18 +29,18 @@ import javax.annotation.Nonnull;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageEncoder;
|
||||
import net.minecraft.network.IPacket;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.Connection;
|
||||
|
||||
/**
|
||||
* A filter for vanilla network packets.
|
||||
*/
|
||||
public abstract class VanillaPacketFilter extends MessageToMessageEncoder<IPacket<?>>
|
||||
public abstract class VanillaPacketFilter extends MessageToMessageEncoder<Packet<?>>
|
||||
{
|
||||
|
||||
protected final Map<Class<? extends IPacket<?>>, BiConsumer<IPacket<?>, List<? super IPacket<?>>>> handlers;
|
||||
protected final Map<Class<? extends Packet<?>>, BiConsumer<Packet<?>, List<? super Packet<?>>>> handlers;
|
||||
|
||||
protected VanillaPacketFilter(Map<Class<? extends IPacket<?>>, BiConsumer<IPacket<?>, List<? super IPacket<?>>>> handlers)
|
||||
protected VanillaPacketFilter(Map<Class<? extends Packet<?>>, BiConsumer<Packet<?>, List<? super Packet<?>>>> handlers)
|
||||
{
|
||||
this.handlers = handlers;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public abstract class VanillaPacketFilter extends MessageToMessageEncoder<IPacke
|
||||
* Helper function for building the handler map.
|
||||
*/
|
||||
@Nonnull
|
||||
protected static <T extends IPacket<?>> Map.Entry<Class<? extends IPacket<?>>, BiConsumer<IPacket<?>, List<? super IPacket<?>>>> handler(Class<T> cls, Function<T, ? extends IPacket<?>> function)
|
||||
protected static <T extends Packet<?>> Map.Entry<Class<? extends Packet<?>>, BiConsumer<Packet<?>, List<? super Packet<?>>>> handler(Class<T> cls, Function<T, ? extends Packet<?>> function)
|
||||
{
|
||||
return handler(cls, (pkt, list) -> list.add(function.apply(cls.cast(pkt))));
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public abstract class VanillaPacketFilter extends MessageToMessageEncoder<IPacke
|
||||
* Helper function for building the handler map.
|
||||
*/
|
||||
@Nonnull
|
||||
protected static <T extends IPacket<?>> Map.Entry<Class<? extends IPacket<?>>, BiConsumer<IPacket<?>, List<? super IPacket<?>>>> handler(Class<T> cls, BiConsumer<IPacket<?>, List<? super IPacket<?>>> consumer)
|
||||
protected static <T extends Packet<?>> Map.Entry<Class<? extends Packet<?>>, BiConsumer<Packet<?>, List<? super Packet<?>>>> handler(Class<T> cls, BiConsumer<Packet<?>, List<? super Packet<?>>> consumer)
|
||||
{
|
||||
return new AbstractMap.SimpleEntry<>(cls, consumer);
|
||||
}
|
||||
@@ -66,12 +66,12 @@ public abstract class VanillaPacketFilter extends MessageToMessageEncoder<IPacke
|
||||
/**
|
||||
* Whether this filter is necessary on the given connection.
|
||||
*/
|
||||
protected abstract boolean isNecessary(NetworkManager manager);
|
||||
protected abstract boolean isNecessary(Connection manager);
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, IPacket<?> msg, List<Object> out)
|
||||
protected void encode(ChannelHandlerContext ctx, Packet<?> msg, List<Object> out)
|
||||
{
|
||||
BiConsumer<IPacket<?>, List<? super IPacket<?>>> consumer = handlers.getOrDefault(msg.getClass(), (pkt, list) -> list.add(pkt));
|
||||
BiConsumer<Packet<?>, List<? super Packet<?>>> consumer = handlers.getOrDefault(msg.getClass(), (pkt, list) -> list.add(pkt));
|
||||
consumer.accept(msg, out);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,32 +19,29 @@
|
||||
|
||||
package net.minecraftforge.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.network.play.ClientPlayNetHandler;
|
||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
import net.minecraft.network.*;
|
||||
import net.minecraft.network.play.server.SCustomPayloadPlayPacket;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.network.FMLConnectionData;
|
||||
import net.minecraftforge.fml.network.NetworkDirection;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
import net.minecraftforge.fml.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.network.event.EventNetworkChannel;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.fmllegacy.network.FMLConnectionData;
|
||||
import net.minecraftforge.fmllegacy.network.NetworkDirection;
|
||||
import net.minecraftforge.fmllegacy.network.NetworkEvent;
|
||||
import net.minecraftforge.fmllegacy.network.NetworkHooks;
|
||||
import net.minecraftforge.fmllegacy.network.NetworkRegistry;
|
||||
import net.minecraftforge.fmllegacy.network.event.EventNetworkChannel;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* A custom payload channel that allows sending vanilla server-to-client packets, even if they would normally
|
||||
* be too large for the vanilla protocol. This is achieved by splitting them into multiple custom payload packets.
|
||||
@@ -55,13 +52,7 @@ public class VanillaPacketSplitter
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
private static final ResourceLocation CHANNEL = new ResourceLocation("forge", "split");
|
||||
// TODO 1.17: bump this to version 1.1 and remove dummy channel
|
||||
// Version 1.1 removed client-side whitelist
|
||||
// we don't bump actual channel version because that would prevent old clients from connecting
|
||||
// but we still need to detect new clients, so we add a dummy channel just for that.
|
||||
private static final ResourceLocation V11_DUMMY_CHANNEL = new ResourceLocation("forge", "split_11");
|
||||
private static final String VERSION = "1.0";
|
||||
private static final String VERSION_11 = "1.1";
|
||||
private static final String VERSION = "1.1";
|
||||
|
||||
private static final int PROTOCOL_MAX = 2097152;
|
||||
|
||||
@@ -77,16 +68,13 @@ public class VanillaPacketSplitter
|
||||
Predicate<String> versionCheck = NetworkRegistry.acceptMissingOr(VERSION);
|
||||
EventNetworkChannel channel = NetworkRegistry.newEventChannel(CHANNEL, () -> VERSION, versionCheck, versionCheck);
|
||||
channel.addListener(VanillaPacketSplitter::onClientPacket);
|
||||
|
||||
Predicate<String> version11Check = NetworkRegistry.acceptMissingOr(VERSION_11);
|
||||
NetworkRegistry.newEventChannel(V11_DUMMY_CHANNEL, () -> VERSION_11, version11Check, version11Check);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the given packet to the given list. If the packet needs to be split, multiple packets will be appened.
|
||||
* Otherwise only the packet itself.
|
||||
*/
|
||||
public static void appendPackets(ProtocolType protocol, PacketDirection direction, IPacket<?> packet, List<? super IPacket<?>> out)
|
||||
public static void appendPackets(ConnectionProtocol protocol, PacketFlow direction, Packet<?> packet, List<? super Packet<?>> out)
|
||||
{
|
||||
if (heuristicIsDefinitelySmallEnough(packet))
|
||||
{
|
||||
@@ -94,15 +82,8 @@ public class VanillaPacketSplitter
|
||||
}
|
||||
else
|
||||
{
|
||||
PacketBuffer buf = new PacketBuffer(Unpooled.buffer());
|
||||
try
|
||||
{
|
||||
packet.write(buf);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
|
||||
packet.write(buf);
|
||||
if (buf.readableBytes() <= PROTOCOL_MAX)
|
||||
{
|
||||
buf.release();
|
||||
@@ -125,7 +106,7 @@ public class VanillaPacketSplitter
|
||||
{
|
||||
partPrefix = Unpooled.buffer(5);
|
||||
partPrefix.writeByte(STATE_FIRST);
|
||||
new PacketBuffer(partPrefix).writeVarInt(protocol.getPacketId(direction, packet));
|
||||
new FriendlyByteBuf(partPrefix).writeVarInt(protocol.getPacketId(direction, packet));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -138,7 +119,7 @@ public class VanillaPacketSplitter
|
||||
buf.retainedSlice(buf.readerIndex(), partSize)
|
||||
);
|
||||
buf.skipBytes(partSize);
|
||||
out.add(new SCustomPayloadPlayPacket(CHANNEL, new PacketBuffer(partBuf)));
|
||||
out.add(new ClientboundCustomPayloadPacket(CHANNEL, new FriendlyByteBuf(partBuf)));
|
||||
}
|
||||
// we retained all the slices, so we do not need this one anymore
|
||||
buf.release();
|
||||
@@ -147,23 +128,23 @@ public class VanillaPacketSplitter
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean heuristicIsDefinitelySmallEnough(IPacket<?> packet)
|
||||
private static boolean heuristicIsDefinitelySmallEnough(Packet<?> packet)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final List<PacketBuffer> receivedBuffers = new ArrayList<>();
|
||||
private static final List<FriendlyByteBuf> receivedBuffers = new ArrayList<>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void onClientPacket(NetworkEvent.ServerCustomPayloadEvent event)
|
||||
{
|
||||
NetworkEvent.Context ctx = event.getSource().get();
|
||||
PacketDirection direction = ctx.getDirection() == NetworkDirection.PLAY_TO_CLIENT ? PacketDirection.CLIENTBOUND : PacketDirection.SERVERBOUND;
|
||||
ProtocolType protocol = ProtocolType.PLAY;
|
||||
PacketFlow direction = ctx.getDirection() == NetworkDirection.PLAY_TO_CLIENT ? PacketFlow.CLIENTBOUND : PacketFlow.SERVERBOUND;
|
||||
ConnectionProtocol protocol = ConnectionProtocol.PLAY;
|
||||
|
||||
ctx.setPacketHandled(true);
|
||||
|
||||
PacketBuffer buf = event.getPayload();
|
||||
FriendlyByteBuf buf = event.getPayload();
|
||||
|
||||
byte state = buf.readByte();
|
||||
if (state == STATE_FIRST)
|
||||
@@ -178,27 +159,18 @@ public class VanillaPacketSplitter
|
||||
receivedBuffers.add(buf);
|
||||
if (state == STATE_LAST)
|
||||
{
|
||||
PacketBuffer full = new PacketBuffer(Unpooled.wrappedBuffer(receivedBuffers.toArray(new PacketBuffer[0])));
|
||||
FriendlyByteBuf full = new FriendlyByteBuf(Unpooled.wrappedBuffer(receivedBuffers.toArray(new FriendlyByteBuf[0])));
|
||||
int packetId = full.readVarInt();
|
||||
IPacket<?> packet = protocol.createPacket(direction, packetId);
|
||||
Packet<?> packet = protocol.createPacket(direction, packetId, full);
|
||||
if (packet == null)
|
||||
{
|
||||
LOGGER.error("Received invalid packet ID {} in forge:split", packetId);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
packet.read(full);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new UncheckedIOException(e);
|
||||
} finally {
|
||||
receivedBuffers.clear();
|
||||
full.release();
|
||||
}
|
||||
ctx.enqueueWork(() -> ((IPacket<ClientPlayNetHandler>)packet).handle(Minecraft.getInstance().getConnection()));
|
||||
receivedBuffers.clear();
|
||||
full.release();
|
||||
ctx.enqueueWork(() -> ((Packet<ClientPacketListener>)packet).handle(Minecraft.getInstance().getConnection()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -206,24 +178,15 @@ public class VanillaPacketSplitter
|
||||
public enum RemoteCompatibility
|
||||
{
|
||||
ABSENT,
|
||||
V10_LEGACY,
|
||||
V11
|
||||
PRESENT
|
||||
}
|
||||
|
||||
public static RemoteCompatibility getRemoteCompatibility(NetworkManager manager)
|
||||
public static RemoteCompatibility getRemoteCompatibility(Connection manager)
|
||||
{
|
||||
FMLConnectionData connectionData = NetworkHooks.getConnectionData(manager);
|
||||
if (connectionData == null)
|
||||
if (connectionData != null && connectionData.getChannels().containsKey(CHANNEL))
|
||||
{
|
||||
return RemoteCompatibility.ABSENT;
|
||||
}
|
||||
else if (connectionData.getChannels().containsKey(V11_DUMMY_CHANNEL))
|
||||
{
|
||||
return RemoteCompatibility.V11;
|
||||
}
|
||||
else if (connectionData.getChannels().containsKey(CHANNEL))
|
||||
{
|
||||
return RemoteCompatibility.V10_LEGACY;
|
||||
return RemoteCompatibility.PRESENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -231,7 +194,7 @@ public class VanillaPacketSplitter
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isRemoteCompatible(NetworkManager manager)
|
||||
public static boolean isRemoteCompatible(Connection manager)
|
||||
{
|
||||
return getRemoteCompatibility(manager) != RemoteCompatibility.ABSENT;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user