Networking V1: Fool me once shame on me. Fool me twice shame on me. (#1207)

This commit is contained in:
i509VCB 2020-12-08 12:55:54 -06:00 committed by GitHub
parent 33708c72c9
commit b08303c750
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 0 deletions

View file

@ -62,6 +62,8 @@ public abstract class AbstractChanneledNetworkAddon<H> extends AbstractNetworkAd
this.sendableChannelsView = Collections.unmodifiableSet(sendableChannels);
}
public abstract void lateInit();
protected void registerPendingChannels(ChannelInfoHolder holder) {
final Collection<Identifier> pending = holder.getPendingChannelsNames();

View file

@ -52,7 +52,10 @@ public final class ClientPlayNetworkAddon extends AbstractChanneledNetworkAddon<
// Register global receivers and attach to session
this.receiver.startSession(this);
}
@Override
public void lateInit() {
for (Map.Entry<Identifier, ClientPlayNetworking.PlayChannelHandler> entry : this.receiver.getHandlers().entrySet()) {
this.registerChannel(entry.getKey(), entry.getValue());
}

View file

@ -50,7 +50,10 @@ public final class ServerPlayNetworkAddon extends AbstractChanneledNetworkAddon<
// Register global receivers and attach to session
this.receiver.startSession(this);
}
@Override
public void lateInit() {
for (Map.Entry<Identifier, ServerPlayNetworking.PlayChannelHandler> entry : this.receiver.getHandlers().entrySet()) {
this.registerChannel(entry.getKey(), entry.getValue());
}

View file

@ -52,6 +52,8 @@ abstract class ServerPlayNetworkHandlerMixin implements ServerPlayNetworkHandler
@Inject(method = "<init>", at = @At("RETURN"))
private void initAddon(CallbackInfo ci) {
this.addon = new ServerPlayNetworkAddon((ServerPlayNetworkHandler) (Object) this, this.server);
// A bit of a hack but it allows the field above to be set in case someone registers handlers during INIT event which refers to said field
this.addon.lateInit();
}
@Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true)

View file

@ -47,6 +47,8 @@ abstract class ClientPlayNetworkHandlerMixin implements ClientPlayNetworkHandler
@Inject(method = "<init>", at = @At("RETURN"))
private void initAddon(CallbackInfo ci) {
this.addon = new ClientPlayNetworkAddon((ClientPlayNetworkHandler) (Object) this, this.client);
// A bit of a hack but it allows the field above to be set in case someone registers handlers during INIT event which refers to said field
this.addon.lateInit();
}
@Inject(method = "onGameJoin", at = @At("RETURN"))