Add in some client only player connectivity events. Closes #5536

Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
cpw 2019-08-31 13:53:43 -04:00
parent ea1c7a7339
commit a4aa85259e
No known key found for this signature in database
GPG key ID: 8EB3DF749553B1B7
4 changed files with 134 additions and 14 deletions

View file

@ -215,7 +215,12 @@
WorkingScreen workingscreen = new WorkingScreen();
workingscreen.func_200210_a(new TranslationTextComponent("connect.joining"));
this.func_213241_c(workingscreen);
@@ -1587,6 +1615,7 @@
@@ -1583,10 +1611,12 @@
IntegratedServer integratedserver = this.field_71437_Z;
this.field_71437_Z = null;
this.field_71460_t.func_190564_k();
+ net.minecraftforge.fml.client.ClientHooks.firePlayerLogout(this.field_71442_b, this.field_71439_g);
this.field_71442_b = null;
NarratorChatListener.field_193643_a.func_193642_b();
this.func_213241_c(p_213231_1_);
if (this.field_71441_e != null) {
@ -223,7 +228,7 @@
if (integratedserver != null) {
while(!integratedserver.func_213201_w()) {
this.func_195542_b(false);
@@ -1624,6 +1653,7 @@
@@ -1624,6 +1654,7 @@
}
TileEntityRendererDispatcher.field_147556_a.func_147543_a(p_213257_1_);
@ -231,7 +236,7 @@
}
public final boolean func_71355_q() {
@@ -1649,112 +1679,8 @@
@@ -1649,112 +1680,8 @@
private void func_147112_ai() {
if (this.field_71476_x != null && this.field_71476_x.func_216346_c() != RayTraceResult.Type.MISS) {
@ -346,7 +351,7 @@
}
}
@@ -1826,6 +1752,7 @@
@@ -1826,6 +1753,7 @@
return field_71432_P;
}
@ -354,7 +359,7 @@
public CompletableFuture<Void> func_213245_w() {
return this.func_213169_a(this::func_213237_g).thenCompose((p_213240_0_) -> {
return p_213240_0_;
@@ -1972,6 +1899,8 @@
@@ -1972,6 +1900,8 @@
}
public MusicTicker.MusicType func_147109_W() {
@ -363,7 +368,7 @@
if (this.field_71462_r instanceof WinGameScreen) {
return MusicTicker.MusicType.CREDITS;
} else if (this.field_71439_g == null) {
@@ -2128,4 +2057,12 @@
@@ -2128,4 +2058,12 @@
public LoadingGui func_213250_au() {
return this.field_213279_p;
}

View file

@ -1,6 +1,14 @@
--- a/net/minecraft/client/network/play/ClientPlayNetHandler.java
+++ b/net/minecraft/client/network/play/ClientPlayNetHandler.java
@@ -366,6 +366,7 @@
@@ -356,6 +356,7 @@
this.field_147299_f.field_184132_p.func_217737_a();
this.field_147299_f.field_71439_g.func_70065_x();
+ net.minecraftforge.fml.client.ClientHooks.firePlayerLogin(this.field_147299_f.field_71442_b, this.field_147299_f.field_71439_g, this.field_147299_f.func_147114_u().func_147298_b());
int i = p_147282_1_.func_149197_c();
this.field_147300_g.func_217408_a(i, this.field_147299_f.field_71439_g);
this.field_147299_f.field_71439_g.field_71158_b = new MovementInputFromOptions(this.field_147299_f.field_71474_y);
@@ -366,6 +367,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());
@ -8,7 +16,7 @@
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 @@
@@ -714,7 +716,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) {
@ -17,7 +25,7 @@
}
}
@@ -790,7 +791,9 @@
@@ -790,7 +792,9 @@
public void func_147251_a(SChatPacket p_147251_1_) {
PacketThreadUtil.func_218797_a(p_147251_1_, this, this.field_147299_f);
@ -28,15 +36,18 @@
}
public void func_147279_a(SAnimateHandPacket p_147279_1_) {
@@ -962,6 +965,7 @@
@@ -962,8 +966,10 @@
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());
+ clientplayerentity1.updateSyncFields(clientplayerentity); // Forge: fix MC-10657
clientplayerentity1.func_70065_x();
clientplayerentity1.func_175158_f(s);
+ net.minecraftforge.fml.client.ClientHooks.firePlayerRespawn(this.field_147299_f.field_71442_b, clientplayerentity, clientplayerentity1, clientplayerentity1.field_71174_a.func_147298_b());
this.field_147300_g.func_217408_a(i, clientplayerentity1);
@@ -1084,6 +1088,12 @@
clientplayerentity1.field_70177_z = -180.0F;
clientplayerentity1.field_71158_b = new MovementInputFromOptions(this.field_147299_f.field_71474_y);
@@ -1084,6 +1090,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());
@ -49,7 +60,7 @@
}
if (flag && this.field_147299_f.field_71462_r instanceof CommandBlockScreen) {
@@ -1253,6 +1263,7 @@
@@ -1253,6 +1265,7 @@
clientrecipebook.func_199644_c();
clientrecipebook.func_199642_d().forEach(imutablesearchtree::func_217872_a);
imutablesearchtree.func_194040_a();
@ -57,7 +68,7 @@
}
public void func_200232_a(SPlayerLookPacket p_200232_1_) {
@@ -1333,7 +1344,7 @@
@@ -1333,7 +1346,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) {
@ -66,7 +77,7 @@
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 +1777,12 @@
@@ -1766,10 +1779,12 @@
this.field_147299_f.field_184132_p.field_217741_m.func_217692_a(pointofinterestdebugrenderer$braininfo);
} else {

View file

@ -0,0 +1,87 @@
package net.minecraftforge.client.event;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.multiplayer.PlayerController;
import net.minecraft.network.NetworkManager;
import net.minecraftforge.eventbus.api.Event;
import javax.annotation.Nullable;
/**
* Client side player connectivity events.
*/
public class ClientPlayerNetworkEvent extends Event {
private final PlayerController controller;
private final ClientPlayerEntity player;
private final NetworkManager networkManager;
/**
* @return the player controller for the client side
*/
@Nullable
public PlayerController getController() {
return controller;
}
/**
* @return the player instance (if present - may be null)
*/
@Nullable
public ClientPlayerEntity getPlayer() {
return player;
}
/**
* @return the network connection (if present - may be null)
*/
@Nullable
public NetworkManager getNetworkManager() {
return networkManager;
}
ClientPlayerNetworkEvent(final PlayerController controller, final ClientPlayerEntity player, final NetworkManager networkManager) {
this.controller = controller;
this.player = player;
this.networkManager = networkManager;
}
/**
* Fired when the client player logs in to the server. The player should be initialized.
*/
public static class LoggedInEvent extends ClientPlayerNetworkEvent {
public LoggedInEvent(final PlayerController controller, final ClientPlayerEntity player, final NetworkManager networkManager) {
super(controller, player, networkManager);
}
}
/**
* Fired when the player logs out. Note this might also fire when a new integrated server is being created.
*/
public static class LoggedOutEvent extends ClientPlayerNetworkEvent {
public LoggedOutEvent(final PlayerController controller, final ClientPlayerEntity player, final NetworkManager networkManager) {
super(controller, player, networkManager);
}
}
/**
* Fired when the player object respawns, such as dimension changes.
*/
public static class RespawnEvent extends ClientPlayerNetworkEvent {
private final ClientPlayerEntity oldPlayer;
public RespawnEvent(final PlayerController pc, final ClientPlayerEntity oldPlayer, final ClientPlayerEntity newPlayer, final NetworkManager networkManager) {
super(pc, newPlayer, networkManager);
this.oldPlayer = oldPlayer;
}
public ClientPlayerEntity getOldPlayer() {
return oldPlayer;
}
public ClientPlayerEntity getNewPlayer() {
return super.getPlayer();
}
}
}

View file

@ -34,9 +34,13 @@ import com.google.common.collect.HashMultimap;
import com.google.common.collect.SetMultimap;
import com.google.common.collect.Sets;
import com.google.common.collect.Table;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.screen.MultiplayerScreen;
import net.minecraft.client.gui.screen.WorldSelectionScreen;
import net.minecraft.client.multiplayer.PlayerController;
import net.minecraftforge.client.event.ClientPlayerNetworkEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.ExtensionPoint;
import net.minecraftforge.fml.ForgeI18n;
import net.minecraftforge.fml.ModList;
@ -309,4 +313,17 @@ public class ClientHooks
logger.error(Strings.repeat("+=", 25));
}
public static void firePlayerLogin(PlayerController pc, ClientPlayerEntity player, NetworkManager networkManager) {
MinecraftForge.EVENT_BUS.post(new ClientPlayerNetworkEvent.LoggedInEvent(pc, player, networkManager));
}
public static void firePlayerLogout(PlayerController pc, ClientPlayerEntity player) {
MinecraftForge.EVENT_BUS.post(new ClientPlayerNetworkEvent.LoggedOutEvent(pc, player, player != null ? player.connection != null ? player.connection.getNetworkManager() : null : null));
}
public static void firePlayerRespawn(PlayerController pc, ClientPlayerEntity oldPlayer, ClientPlayerEntity newPlayer, NetworkManager networkManager) {
MinecraftForge.EVENT_BUS.post(new ClientPlayerNetworkEvent.RespawnEvent(pc, oldPlayer, newPlayer, networkManager));
}
}