mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 19:15:32 +00:00
Add in MC REGISTER nonsense. Shut up #5730
Tweak network a bit to fix initialization order stupidity. (Constants don't load classes!) Signed-off-by: cpw <[email protected]>
This commit is contained in:
8 files changed
+177
-31
No files matched your search
+17
-8
@@ -1,6 +1,14 @@
|
||||
--- a/net/minecraft/client/network/play/ClientPlayNetHandler.java
|
||||
+++ b/net/minecraft/client/network/play/ClientPlayNetHandler.java
|
||||
@@ -714,7 +714,7 @@
|
||||
@@ -366,6 +366,7 @@
|
||||
this.field_147299_f.field_71439_g.func_145769_d(i);
|
||||
this.field_147299_f.field_71439_g.func_175150_k(p_147282_1_.func_179744_h());
|
||||
this.field_147299_f.field_71442_b.func_78746_a(p_147282_1_.func_149198_e());
|
||||
+ net.minecraftforge.fml.network.NetworkHooks.sendMCRegistryPackets(field_147302_e, "PLAY_TO_SERVER");
|
||||
this.field_147299_f.field_71474_y.func_82879_c();
|
||||
this.field_147302_e.func_179290_a(new CCustomPayloadPacket(CCustomPayloadPacket.field_210344_a, (new PacketBuffer(Unpooled.buffer())).func_180714_a(ClientBrandRetriever.getClientModName())));
|
||||
this.field_147299_f.func_213229_ar().func_216814_a();
|
||||
@@ -714,7 +715,7 @@
|
||||
BlockPos blockpos = new BlockPos(compoundnbt.func_74762_e("x"), compoundnbt.func_74762_e("y"), compoundnbt.func_74762_e("z"));
|
||||
TileEntity tileentity = this.field_147300_g.func_175625_s(blockpos);
|
||||
if (tileentity != null) {
|
||||
@@ -9,7 +17,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -790,7 +790,9 @@
|
||||
@@ -790,7 +791,9 @@
|
||||
|
||||
public void func_147251_a(SChatPacket p_147251_1_) {
|
||||
PacketThreadUtil.func_218797_a(p_147251_1_, this, this.field_147299_f);
|
||||
@@ -20,7 +28,7 @@
|
||||
}
|
||||
|
||||
public void func_147279_a(SAnimateHandPacket p_147279_1_) {
|
||||
@@ -962,6 +964,7 @@
|
||||
@@ -962,6 +965,7 @@
|
||||
this.field_147299_f.field_71439_g = clientplayerentity1;
|
||||
this.field_147299_f.field_175622_Z = clientplayerentity1;
|
||||
clientplayerentity1.func_184212_Q().func_187218_a(clientplayerentity.func_184212_Q().func_187231_c());
|
||||
@@ -28,7 +36,7 @@
|
||||
clientplayerentity1.func_70065_x();
|
||||
clientplayerentity1.func_175158_f(s);
|
||||
this.field_147300_g.func_217408_a(i, clientplayerentity1);
|
||||
@@ -1084,6 +1087,12 @@
|
||||
@@ -1084,6 +1088,12 @@
|
||||
boolean flag = i == 2 && tileentity instanceof CommandBlockTileEntity;
|
||||
if (i == 1 && tileentity instanceof MobSpawnerTileEntity || flag || i == 3 && tileentity instanceof BeaconTileEntity || i == 4 && tileentity instanceof SkullTileEntity || i == 6 && tileentity instanceof BannerTileEntity || i == 7 && tileentity instanceof StructureBlockTileEntity || i == 8 && tileentity instanceof EndGatewayTileEntity || i == 9 && tileentity instanceof SignTileEntity || i == 11 && tileentity instanceof BedTileEntity || i == 5 && tileentity instanceof ConduitTileEntity || i == 12 && tileentity instanceof JigsawTileEntity || i == 13 && tileentity instanceof CampfireTileEntity) {
|
||||
tileentity.func_145839_a(p_147273_1_.func_148857_g());
|
||||
@@ -41,7 +49,7 @@
|
||||
}
|
||||
|
||||
if (flag && this.field_147299_f.field_71462_r instanceof CommandBlockScreen) {
|
||||
@@ -1253,6 +1262,7 @@
|
||||
@@ -1253,6 +1263,7 @@
|
||||
clientrecipebook.func_199644_c();
|
||||
clientrecipebook.func_199642_d().forEach(imutablesearchtree::func_217872_a);
|
||||
imutablesearchtree.func_194040_a();
|
||||
@@ -49,7 +57,7 @@
|
||||
}
|
||||
|
||||
public void func_200232_a(SPlayerLookPacket p_200232_1_) {
|
||||
@@ -1333,7 +1343,7 @@
|
||||
@@ -1333,7 +1344,7 @@
|
||||
PacketThreadUtil.func_218797_a(p_147260_1_, this, this.field_147299_f);
|
||||
Entity entity = this.field_147300_g.func_73045_a(p_147260_1_.func_149426_d());
|
||||
if (entity instanceof LivingEntity) {
|
||||
@@ -58,12 +66,13 @@
|
||||
if (effect != null) {
|
||||
EffectInstance effectinstance = new EffectInstance(effect, p_147260_1_.func_180755_e(), p_147260_1_.func_149428_f(), p_147260_1_.func_186984_g(), p_147260_1_.func_179707_f(), p_147260_1_.func_205527_h());
|
||||
effectinstance.func_100012_b(p_147260_1_.func_149429_c());
|
||||
@@ -1766,10 +1776,12 @@
|
||||
@@ -1766,10 +1777,12 @@
|
||||
|
||||
this.field_147299_f.field_184132_p.field_217741_m.func_217692_a(pointofinterestdebugrenderer$braininfo);
|
||||
} else {
|
||||
- field_147301_d.warn("Unknown custom packed identifier: {}", (Object)resourcelocation);
|
||||
+ if (!net.minecraftforge.fml.network.NetworkHooks.onCustomPayload(p_147240_1_, this.field_147302_e))
|
||||
field_147301_d.warn("Unknown custom packed identifier: {}", (Object)resourcelocation);
|
||||
+ field_147301_d.warn("Unknown custom packet identifier: {}", (Object)resourcelocation);
|
||||
}
|
||||
} finally {
|
||||
if (packetbuffer != null) {
|
||||
|
||||
@@ -23,7 +23,15 @@
|
||||
p_72355_2_.func_70029_a(serverworld);
|
||||
p_72355_2_.field_71134_c.func_73080_a((ServerWorld)p_72355_2_.field_70170_p);
|
||||
String s1 = "local";
|
||||
@@ -142,7 +151,7 @@
|
||||
@@ -121,6 +130,7 @@
|
||||
WorldInfo worldinfo = serverworld.func_72912_H();
|
||||
this.func_72381_a(p_72355_2_, (ServerPlayerEntity)null, serverworld);
|
||||
ServerPlayNetHandler serverplaynethandler = new ServerPlayNetHandler(this.field_72400_f, p_72355_1_, p_72355_2_);
|
||||
+ net.minecraftforge.fml.network.NetworkHooks.sendMCRegistryPackets(p_72355_1_, "PLAY_TO_CLIENT");
|
||||
serverplaynethandler.func_147359_a(new SJoinGamePacket(p_72355_2_.func_145782_y(), p_72355_2_.field_71134_c.func_73081_b(), worldinfo.func_76093_s(), serverworld.field_73011_w.func_186058_p(), this.func_72352_l(), worldinfo.func_76067_t(), this.field_72402_d, serverworld.func_82736_K().func_223586_b(GameRules.field_223612_o)));
|
||||
serverplaynethandler.func_147359_a(new SCustomPayloadPlayPacket(SCustomPayloadPlayPacket.field_209911_b, (new PacketBuffer(Unpooled.buffer())).func_180714_a(this.func_72365_p().getServerModName())));
|
||||
serverplaynethandler.func_147359_a(new SServerDifficultyPacket(worldinfo.func_176130_y(), worldinfo.func_176123_z()));
|
||||
@@ -142,7 +152,7 @@
|
||||
|
||||
this.func_148539_a(itextcomponent.func_211708_a(TextFormatting.YELLOW));
|
||||
serverplaynethandler.func_147364_a(p_72355_2_.field_70165_t, p_72355_2_.field_70163_u, p_72355_2_.field_70161_v, p_72355_2_.field_70177_z, p_72355_2_.field_70125_A);
|
||||
@@ -32,7 +40,7 @@
|
||||
this.field_177454_f.put(p_72355_2_.func_110124_au(), p_72355_2_);
|
||||
this.func_148540_a(new SPlayerListItemPacket(SPlayerListItemPacket.Action.ADD_PLAYER, p_72355_2_));
|
||||
|
||||
@@ -163,8 +172,9 @@
|
||||
@@ -163,8 +173,9 @@
|
||||
|
||||
if (compoundnbt != null && compoundnbt.func_150297_b("RootVehicle", 10)) {
|
||||
CompoundNBT compoundnbt1 = compoundnbt.func_74775_l("RootVehicle");
|
||||
@@ -43,7 +51,7 @@
|
||||
});
|
||||
if (entity1 != null) {
|
||||
UUID uuid = compoundnbt1.func_186857_a("Attach");
|
||||
@@ -191,6 +201,7 @@
|
||||
@@ -191,6 +202,7 @@
|
||||
}
|
||||
|
||||
p_72355_2_.func_71116_b();
|
||||
@@ -51,7 +59,7 @@
|
||||
}
|
||||
|
||||
protected void func_96456_a(ServerScoreboard p_96456_1_, ServerPlayerEntity p_96456_2_) {
|
||||
@@ -252,6 +263,7 @@
|
||||
@@ -252,6 +264,7 @@
|
||||
compoundnbt1 = compoundnbt;
|
||||
p_72380_1_.func_70020_e(compoundnbt);
|
||||
field_148546_d.debug("loading single player");
|
||||
@@ -59,7 +67,7 @@
|
||||
} else {
|
||||
compoundnbt1 = this.field_72412_k.func_75752_b(p_72380_1_);
|
||||
}
|
||||
@@ -260,6 +272,7 @@
|
||||
@@ -260,6 +273,7 @@
|
||||
}
|
||||
|
||||
protected void func_72391_b(ServerPlayerEntity p_72391_1_) {
|
||||
@@ -67,7 +75,7 @@
|
||||
this.field_72412_k.func_75753_a(p_72391_1_);
|
||||
ServerStatisticsManager serverstatisticsmanager = this.field_148547_k.get(p_72391_1_.func_110124_au());
|
||||
if (serverstatisticsmanager != null) {
|
||||
@@ -274,6 +287,7 @@
|
||||
@@ -274,6 +288,7 @@
|
||||
}
|
||||
|
||||
public void func_72367_e(ServerPlayerEntity p_72367_1_) {
|
||||
@@ -75,7 +83,7 @@
|
||||
ServerWorld serverworld = p_72367_1_.func_71121_q();
|
||||
p_72367_1_.func_195066_a(Stats.field_75947_j);
|
||||
this.func_72391_b(p_72367_1_);
|
||||
@@ -295,7 +309,7 @@
|
||||
@@ -295,7 +310,7 @@
|
||||
p_72367_1_.func_213319_R();
|
||||
serverworld.func_217434_e(p_72367_1_);
|
||||
p_72367_1_.func_192039_O().func_192745_a();
|
||||
@@ -84,7 +92,7 @@
|
||||
this.field_72400_f.func_201300_aS().func_201382_b(p_72367_1_);
|
||||
UUID uuid = p_72367_1_.func_110124_au();
|
||||
ServerPlayerEntity serverplayerentity = this.field_177454_f.get(uuid);
|
||||
@@ -364,10 +378,18 @@
|
||||
@@ -364,10 +379,18 @@
|
||||
}
|
||||
|
||||
public ServerPlayerEntity func_72368_a(ServerPlayerEntity p_72368_1_, DimensionType p_72368_2_, boolean p_72368_3_) {
|
||||
@@ -107,7 +115,7 @@
|
||||
p_72368_1_.field_71093_bK = p_72368_2_;
|
||||
PlayerInteractionManager playerinteractionmanager;
|
||||
if (this.field_72400_f.func_71242_L()) {
|
||||
@@ -379,6 +401,8 @@
|
||||
@@ -379,6 +402,8 @@
|
||||
ServerPlayerEntity serverplayerentity = new ServerPlayerEntity(this.field_72400_f, this.field_72400_f.func_71218_a(p_72368_1_.field_71093_bK), p_72368_1_.func_146103_bH(), playerinteractionmanager);
|
||||
serverplayerentity.field_71135_a = p_72368_1_.field_71135_a;
|
||||
serverplayerentity.func_193104_a(p_72368_1_, p_72368_3_);
|
||||
@@ -116,7 +124,7 @@
|
||||
serverplayerentity.func_145769_d(p_72368_1_.func_145782_y());
|
||||
serverplayerentity.func_184819_a(p_72368_1_.func_184591_cq());
|
||||
|
||||
@@ -393,7 +417,7 @@
|
||||
@@ -393,7 +418,7 @@
|
||||
if (optional.isPresent()) {
|
||||
Vec3d vec3d = optional.get();
|
||||
serverplayerentity.func_70012_b(vec3d.field_72450_a, vec3d.field_72448_b, vec3d.field_72449_c, 0.0F, 0.0F);
|
||||
@@ -125,7 +133,7 @@
|
||||
} else {
|
||||
serverplayerentity.field_71135_a.func_147359_a(new SChangeGameStatePacket(0, 0.0F));
|
||||
}
|
||||
@@ -413,10 +437,11 @@
|
||||
@@ -413,10 +438,11 @@
|
||||
this.func_72354_b(serverplayerentity, serverworld);
|
||||
this.func_187243_f(serverplayerentity);
|
||||
serverworld.func_217433_d(serverplayerentity);
|
||||
@@ -138,7 +146,7 @@
|
||||
return serverplayerentity;
|
||||
}
|
||||
|
||||
@@ -736,7 +761,7 @@
|
||||
@@ -736,7 +762,7 @@
|
||||
}
|
||||
|
||||
public List<ServerPlayerEntity> func_181057_v() {
|
||||
@@ -147,7 +155,7 @@
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -766,4 +791,12 @@
|
||||
@@ -766,4 +792,12 @@
|
||||
public boolean func_206257_x() {
|
||||
return this.field_72407_n;
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class ModLoader
|
||||
this.loadingWarnings = FMLLoader.getLoadingModList().
|
||||
getBrokenFiles().stream().map(file -> new ModLoadingWarning(null, ModLoadingStage.VALIDATE,
|
||||
InvalidModIdentifier.identifyJarProblem(file.getFilePath()).orElse("fml.modloading.brokenfile"), file.getFileName())).collect(Collectors.toList());
|
||||
LOGGER.debug(CORE, "Loading Network data for FML net version: {}", FMLNetworkConstants.NETVERSION);
|
||||
LOGGER.debug(CORE, "Loading Network data for FML net version: {}", FMLNetworkConstants.init());
|
||||
CrashReportExtender.registerCrashCallable("ModLauncher", FMLLoader::getLauncherInfo);
|
||||
CrashReportExtender.registerCrashCallable("ModLauncher launch target", FMLLoader::launcherHandlerName);
|
||||
CrashReportExtender.registerCrashCallable("ModLauncher naming", FMLLoader::getNaming);
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package net.minecraftforge.fml.network;
|
||||
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.util.Attribute;
|
||||
import net.minecraft.network.IPacket;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class FMLMCRegisterPacketHandler {
|
||||
public static final FMLMCRegisterPacketHandler INSTANCE = new FMLMCRegisterPacketHandler();
|
||||
|
||||
public static class ChannelList {
|
||||
private Set<ResourceLocation> locations = new HashSet<>();
|
||||
|
||||
public void updateFrom(PacketBuffer buffer) {
|
||||
locations = bytesToResLocation(buffer.readByteArray());
|
||||
}
|
||||
|
||||
byte[] toByteArray() {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
for (ResourceLocation rl : locations) {
|
||||
try {
|
||||
bos.write(rl.toString().getBytes(StandardCharsets.UTF_8));
|
||||
bos.write(0);
|
||||
} catch (IOException e) {
|
||||
// fake IOE
|
||||
}
|
||||
}
|
||||
return bos.toByteArray();
|
||||
}
|
||||
|
||||
private Set<ResourceLocation> bytesToResLocation(byte[] all) {
|
||||
HashSet<ResourceLocation> rl = new HashSet<>();
|
||||
int last = 0;
|
||||
for (int cur = 0; cur < all.length; cur++) {
|
||||
if (all[cur] == '\0') {
|
||||
String s = new String(all, last, cur - last, StandardCharsets.UTF_8);
|
||||
rl.add(new ResourceLocation(s));
|
||||
last = cur + 1;
|
||||
}
|
||||
}
|
||||
return rl;
|
||||
}
|
||||
}
|
||||
|
||||
public void addChannels(Set<ResourceLocation> locations, NetworkManager manager) {
|
||||
getFrom(manager).locations.addAll(locations);
|
||||
}
|
||||
|
||||
void registerListener(NetworkEvent evt) {
|
||||
final ChannelList channelList = getFrom(evt);
|
||||
channelList.updateFrom(evt.getPayload());
|
||||
evt.getSource().get().setPacketHandled(true);
|
||||
}
|
||||
|
||||
void unregisterListener(NetworkEvent evt) {
|
||||
final ChannelList channelList = getFrom(evt);
|
||||
channelList.updateFrom(evt.getPayload());
|
||||
evt.getSource().get().setPacketHandled(true);
|
||||
}
|
||||
|
||||
private static ChannelList getFrom(NetworkManager manager) {
|
||||
return fromAttr(manager.channel().attr(FMLNetworkConstants.FML_MC_REGISTRY));
|
||||
}
|
||||
|
||||
private static ChannelList getFrom(NetworkEvent event) {
|
||||
return fromAttr(event.getSource().get().attr(FMLNetworkConstants.FML_MC_REGISTRY));
|
||||
}
|
||||
|
||||
private static ChannelList fromAttr(Attribute<ChannelList> attr) {
|
||||
attr.setIfAbsent(new ChannelList());
|
||||
return attr.get();
|
||||
}
|
||||
|
||||
public void sendRegistry(NetworkManager manager, final NetworkDirection dir) {
|
||||
PacketBuffer pb = new PacketBuffer(Unpooled.buffer());
|
||||
pb.writeByteArray(getFrom(manager).toByteArray());
|
||||
final ICustomPacket<IPacket<?>> iPacketICustomPacket = dir.buildPacket(Pair.of(pb, 0), FMLNetworkConstants.MC_REGISTER_RESOURCE);
|
||||
manager.sendPacket(iPacketICustomPacket.getThis());
|
||||
}
|
||||
}
|
||||
@@ -21,10 +21,12 @@ package net.minecraftforge.fml.network;
|
||||
|
||||
import io.netty.util.AttributeKey;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.network.event.EventNetworkChannel;
|
||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
|
||||
import java.util.List;
|
||||
/**
|
||||
* Constants related to networking
|
||||
*/
|
||||
@@ -38,12 +40,20 @@ public class FMLNetworkConstants
|
||||
static final Marker NETWORK = MarkerManager.getMarker("FMLNETWORK");
|
||||
static final AttributeKey<String> FML_NETVERSION = AttributeKey.valueOf("fml:netversion");
|
||||
static final AttributeKey<FMLHandshakeHandler> FML_HANDSHAKE_HANDLER = AttributeKey.valueOf("fml:handshake");
|
||||
static final AttributeKey<FMLMCRegisterPacketHandler.ChannelList> FML_MC_REGISTRY = AttributeKey.valueOf("minecraft:netregistry");
|
||||
static final ResourceLocation FML_HANDSHAKE_RESOURCE = new ResourceLocation("fml:handshake");
|
||||
static final ResourceLocation FML_PLAY_RESOURCE = new ResourceLocation("fml:play");
|
||||
static final ResourceLocation MC_REGISTER_RESOURCE = new ResourceLocation("minecraft:register");
|
||||
static final ResourceLocation MC_UNREGISTER_RESOURCE = new ResourceLocation("minecraft:unregister");
|
||||
static final SimpleChannel handshakeChannel = NetworkInitialization.getHandshakeChannel();
|
||||
static final SimpleChannel playChannel = NetworkInitialization.getPlayChannel();
|
||||
static final List<EventNetworkChannel> mcRegChannels = NetworkInitialization.buildMCRegistrationChannels();
|
||||
/**
|
||||
* Return this value in your {@link net.minecraftforge.fml.ExtensionPoint#DISPLAYTEST} function to be ignored.
|
||||
*/
|
||||
public static final String IGNORESERVERONLY = "OHNOES\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31";
|
||||
|
||||
public static String init() {
|
||||
return FMLNetworkConstants.NETVERSION;
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,10 @@
|
||||
package net.minecraftforge.fml.network;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -79,6 +81,14 @@ public class NetworkHooks
|
||||
FMLHandshakeHandler.registerHandshake(manager, NetworkDirection.LOGIN_TO_SERVER);
|
||||
}
|
||||
|
||||
public synchronized static void sendMCRegistryPackets(NetworkManager manager, String direction) {
|
||||
final Set<ResourceLocation> resourceLocations = NetworkRegistry.buildChannelVersions().keySet().stream().
|
||||
filter(rl -> !Objects.equals(rl.getNamespace(), "minecraft")).
|
||||
collect(Collectors.toSet());
|
||||
FMLMCRegisterPacketHandler.INSTANCE.addChannels(resourceLocations, manager);
|
||||
FMLMCRegisterPacketHandler.INSTANCE.sendRegistry(manager, NetworkDirection.valueOf(direction));
|
||||
}
|
||||
|
||||
public static void handleClientLoginSuccess(NetworkManager manager) {
|
||||
if (manager == null || manager.channel() == null) throw new NullPointerException("ARGH! Network Manager is null (" + manager != null ? "CHANNEL" : "MANAGER"+")" );
|
||||
if (getConnectionType(()->manager) == ConnectionType.VANILLA) {
|
||||
|
||||
@@ -20,9 +20,13 @@
|
||||
package net.minecraftforge.fml.network;
|
||||
|
||||
import net.minecraftforge.fml.config.ConfigTracker;
|
||||
import net.minecraftforge.fml.network.event.EventNetworkChannel;
|
||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
class NetworkInitialization {
|
||||
|
||||
public static SimpleChannel getHandshakeChannel() {
|
||||
@@ -75,12 +79,12 @@ class NetworkInitialization {
|
||||
}
|
||||
|
||||
public static SimpleChannel getPlayChannel() {
|
||||
SimpleChannel playChannel = NetworkRegistry.ChannelBuilder
|
||||
.named(FMLNetworkConstants.FML_PLAY_RESOURCE)
|
||||
.clientAcceptedVersions(a -> true)
|
||||
.serverAcceptedVersions(a -> true)
|
||||
.networkProtocolVersion(() -> FMLNetworkConstants.NETVERSION)
|
||||
.simpleChannel();
|
||||
SimpleChannel playChannel = NetworkRegistry.ChannelBuilder.
|
||||
named(FMLNetworkConstants.FML_PLAY_RESOURCE).
|
||||
clientAcceptedVersions(a -> true).
|
||||
serverAcceptedVersions(a -> true).
|
||||
networkProtocolVersion(() -> FMLNetworkConstants.NETVERSION).
|
||||
simpleChannel();
|
||||
|
||||
playChannel.messageBuilder(FMLPlayMessages.SpawnEntity.class, 0).
|
||||
decoder(FMLPlayMessages.SpawnEntity::decode).
|
||||
@@ -97,5 +101,21 @@ class NetworkInitialization {
|
||||
return playChannel;
|
||||
}
|
||||
|
||||
|
||||
public static List<EventNetworkChannel> buildMCRegistrationChannels() {
|
||||
final EventNetworkChannel mcRegChannel = NetworkRegistry.ChannelBuilder.
|
||||
named(FMLNetworkConstants.MC_REGISTER_RESOURCE).
|
||||
clientAcceptedVersions(a -> true).
|
||||
serverAcceptedVersions(a -> true).
|
||||
networkProtocolVersion(() -> FMLNetworkConstants.NETVERSION).
|
||||
eventNetworkChannel();
|
||||
mcRegChannel.addListener(FMLMCRegisterPacketHandler.INSTANCE::registerListener);
|
||||
final EventNetworkChannel mcUnregChannel = NetworkRegistry.ChannelBuilder.
|
||||
named(FMLNetworkConstants.MC_UNREGISTER_RESOURCE).
|
||||
clientAcceptedVersions(a -> true).
|
||||
serverAcceptedVersions(a -> true).
|
||||
networkProtocolVersion(() -> FMLNetworkConstants.NETVERSION).
|
||||
eventNetworkChannel();
|
||||
mcUnregChannel.addListener(FMLMCRegisterPacketHandler.INSTANCE::unregisterListener);
|
||||
return Arrays.asList(mcRegChannel, mcUnregChannel);
|
||||
}
|
||||
}
|
||||
@@ -125,15 +125,15 @@ public class NetworkRegistry
|
||||
*/
|
||||
private static NetworkInstance createInstance(ResourceLocation name, Supplier<String> networkProtocolVersion, Predicate<String> clientAcceptedVersions, Predicate<String> serverAcceptedVersions)
|
||||
{
|
||||
if(lock && !name.getNamespace().equals("fml")){
|
||||
if(lock) {
|
||||
LOGGER.error(NETREGISTRY, "Attempted to register channel {} even though registry phase is over", name);
|
||||
throw new IllegalArgumentException("Registration of network channels is locked");
|
||||
}
|
||||
final NetworkInstance networkInstance = new NetworkInstance(name, networkProtocolVersion, clientAcceptedVersions, serverAcceptedVersions);
|
||||
if (instances.containsKey(name)) {
|
||||
LOGGER.error(NETREGISTRY, "NetworkDirection channel {} already registered.", name);
|
||||
throw new IllegalArgumentException("NetworkDirection Channel {"+ name +"} already registered");
|
||||
}
|
||||
final NetworkInstance networkInstance = new NetworkInstance(name, networkProtocolVersion, clientAcceptedVersions, serverAcceptedVersions);
|
||||
instances.put(name, networkInstance);
|
||||
return networkInstance;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user