Fix spectating player entities past death and respawn (fixes #36)

While spectating, a special camera controller should be active. However after
a world change (which happens when the player dies), the camera is recreated
with the default controller, same when the controller setting is changed.

Also fixes the spectated entity if the player respawns in the same dimension
This commit is contained in:
johni0702
2016-11-13 17:09:37 +01:00
parent ad2893bf4e
commit 1f2c05e696

View File

@@ -69,7 +69,11 @@ public class CameraEntity extends EntityPlayerSP {
super(mcIn, worldIn, netHandlerPlayClient, statFileWriter); super(mcIn, worldIn, netHandlerPlayClient, statFileWriter);
FMLCommonHandler.instance().bus().register(eventHandler); FMLCommonHandler.instance().bus().register(eventHandler);
MinecraftForge.EVENT_BUS.register(eventHandler); MinecraftForge.EVENT_BUS.register(eventHandler);
if (ReplayModReplay.instance.getReplayHandler().getSpectatedUUID() == null) {
cameraController = ReplayModReplay.instance.createCameraController(this); cameraController = ReplayModReplay.instance.createCameraController(this);
} else {
cameraController = new SpectatorCameraController(this);
}
} }
/** /**
@@ -151,7 +155,9 @@ public class CameraEntity extends EntityPlayerSP {
// This is important if the spectated player respawns as their // This is important if the spectated player respawns as their
// entity is recreated and we have to spectate a new entity // entity is recreated and we have to spectate a new entity
UUID spectating = ReplayModReplay.instance.getReplayHandler().getSpectatedUUID(); UUID spectating = ReplayModReplay.instance.getReplayHandler().getSpectatedUUID();
if (spectating != null && (view.getUniqueID() != spectating || view.worldObj != worldObj)) { if (spectating != null && (view.getUniqueID() != spectating
|| view.worldObj != worldObj)
|| worldObj.getEntityByID(view.getEntityId()) != view) {
view = worldObj.getPlayerEntityByUUID(spectating); view = worldObj.getPlayerEntityByUUID(spectating);
if (view != null) { if (view != null) {
mc.setRenderViewEntity(view); mc.setRenderViewEntity(view);
@@ -354,7 +360,11 @@ public class CameraEntity extends EntityPlayerSP {
@SubscribeEvent @SubscribeEvent
public void onSettingsChanged(SettingsChangedEvent event) { public void onSettingsChanged(SettingsChangedEvent event) {
if (event.getKey() == Setting.CAMERA) { if (event.getKey() == Setting.CAMERA) {
if (ReplayModReplay.instance.getReplayHandler().getSpectatedUUID() == null) {
cameraController = ReplayModReplay.instance.createCameraController(CameraEntity.this); cameraController = ReplayModReplay.instance.createCameraController(CameraEntity.this);
} else {
cameraController = new SpectatorCameraController(CameraEntity.this);
}
} }
} }