Fix replay not being closed properly
This commit is contained in:
@@ -111,6 +111,10 @@ public class ReplayHandler {
|
|||||||
|
|
||||||
channel.close().awaitUninterruptibly();
|
channel.close().awaitUninterruptibly();
|
||||||
|
|
||||||
|
if (mc.thePlayer instanceof CameraEntity) {
|
||||||
|
mc.thePlayer.setDead();
|
||||||
|
}
|
||||||
|
|
||||||
if (mc.theWorld != null) {
|
if (mc.theWorld != null) {
|
||||||
mc.theWorld.sendQuittingDisconnectingPacket();
|
mc.theWorld.sendQuittingDisconnectingPacket();
|
||||||
mc.loadWorld(null);
|
mc.loadWorld(null);
|
||||||
@@ -122,6 +126,8 @@ public class ReplayHandler {
|
|||||||
// These might have been hidden by the overlay, so we have to make sure they're visible again
|
// These might have been hidden by the overlay, so we have to make sure they're visible again
|
||||||
ReplayGuiRegistry.show();
|
ReplayGuiRegistry.show();
|
||||||
|
|
||||||
|
ReplayModReplay.instance.replayHandler = null;
|
||||||
|
|
||||||
FMLCommonHandler.instance().bus().post(new ReplayCloseEvent.Post(this));
|
FMLCommonHandler.instance().bus().post(new ReplayCloseEvent.Post(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class ReplayModReplay {
|
|||||||
|
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
|
|
||||||
private ReplayHandler replayHandler;
|
protected ReplayHandler replayHandler;
|
||||||
|
|
||||||
public ReplayHandler getReplayHandler() {
|
public ReplayHandler getReplayHandler() {
|
||||||
return replayHandler;
|
return replayHandler;
|
||||||
|
|||||||
@@ -54,10 +54,17 @@ public class CameraEntity extends EntityPlayerSP {
|
|||||||
*/
|
*/
|
||||||
private Entity lastHandRendered = null;
|
private Entity lastHandRendered = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The hashCode and equals methods of Entity are not stable.
|
||||||
|
* Therefore we cannot register any event handlers directly in the CameraEntity class and
|
||||||
|
* instead have this inner class.
|
||||||
|
*/
|
||||||
|
private final EventHandler eventHandler = new EventHandler();
|
||||||
|
|
||||||
public CameraEntity(Minecraft mcIn, World worldIn, NetHandlerPlayClient netHandlerPlayClient, StatFileWriter statFileWriter) {
|
public CameraEntity(Minecraft mcIn, World worldIn, NetHandlerPlayClient netHandlerPlayClient, StatFileWriter statFileWriter) {
|
||||||
super(mcIn, worldIn, netHandlerPlayClient, statFileWriter);
|
super(mcIn, worldIn, netHandlerPlayClient, statFileWriter);
|
||||||
FMLCommonHandler.instance().bus().register(this);
|
FMLCommonHandler.instance().bus().register(eventHandler);
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(eventHandler);
|
||||||
cameraController = ReplayModReplay.instance.createCameraController(this);
|
cameraController = ReplayModReplay.instance.createCameraController(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,23 +267,8 @@ public class CameraEntity extends EntityPlayerSP {
|
|||||||
@Override
|
@Override
|
||||||
public void setDead() {
|
public void setDead() {
|
||||||
super.setDead();
|
super.setDead();
|
||||||
FMLCommonHandler.instance().bus().unregister(this);
|
FMLCommonHandler.instance().bus().unregister(eventHandler);
|
||||||
MinecraftForge.EVENT_BUS.unregister(this);
|
MinecraftForge.EVENT_BUS.unregister(eventHandler);
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onPreClientTick(TickEvent.ClientTickEvent event) {
|
|
||||||
if (event.phase == TickEvent.Phase.START) {
|
|
||||||
update();
|
|
||||||
updateArmYawAndPitch();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onRenderUpdate(TickEvent.RenderTickEvent event) {
|
|
||||||
if (event.phase == TickEvent.Phase.START) {
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update() {
|
private void update() {
|
||||||
@@ -301,6 +293,27 @@ public class CameraEntity extends EntityPlayerSP {
|
|||||||
renderArmYaw = renderArmYaw + (rotationYaw - renderArmYaw) * 0.5f;
|
renderArmYaw = renderArmYaw + (rotationYaw - renderArmYaw) * 0.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean canSpectate(Entity e) {
|
||||||
|
return e != null && !e.isInvisible()
|
||||||
|
&& (e instanceof EntityPlayer || e instanceof EntityLiving || e instanceof EntityItemFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class EventHandler {
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onPreClientTick(TickEvent.ClientTickEvent event) {
|
||||||
|
if (event.phase == TickEvent.Phase.START) {
|
||||||
|
update();
|
||||||
|
updateArmYawAndPitch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onRenderUpdate(TickEvent.RenderTickEvent event) {
|
||||||
|
if (event.phase == TickEvent.Phase.START) {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void preCrosshairRender(RenderGameOverlayEvent.Pre event) {
|
public void preCrosshairRender(RenderGameOverlayEvent.Pre event) {
|
||||||
// The crosshair should only render if targeted entity can actually be spectated
|
// The crosshair should only render if targeted entity can actually be spectated
|
||||||
@@ -309,22 +322,17 @@ public class CameraEntity extends EntityPlayerSP {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canSpectate(Entity e) {
|
|
||||||
return e != null && !e.isInvisible()
|
|
||||||
&& (e instanceof EntityPlayer || e instanceof EntityLiving || e instanceof EntityItemFrame);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onSettingsChanged(SettingsChangedEvent event) {
|
public void onSettingsChanged(SettingsChangedEvent event) {
|
||||||
if (event.getKey() == Setting.CAMERA) {
|
if (event.getKey() == Setting.CAMERA) {
|
||||||
cameraController = ReplayModReplay.instance.createCameraController(this);
|
cameraController = ReplayModReplay.instance.createCameraController(CameraEntity.this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onRenderHand(RenderHandEvent event) {
|
public void onRenderHand(RenderHandEvent event) {
|
||||||
// Unless we are spectating another player, don't render our hand
|
// Unless we are spectating another player, don't render our hand
|
||||||
if (mc.getRenderViewEntity() == this || !(mc.getRenderViewEntity() instanceof EntityPlayer)) {
|
if (mc.getRenderViewEntity() == CameraEntity.this || !(mc.getRenderViewEntity() instanceof EntityPlayer)) {
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -351,8 +359,9 @@ public class CameraEntity extends EntityPlayerSP {
|
|||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onEntityViewRenderEvent(EntityViewRenderEvent.CameraSetup event) {
|
public void onEntityViewRenderEvent(EntityViewRenderEvent.CameraSetup event) {
|
||||||
if (mc.getRenderViewEntity() == this) {
|
if (mc.getRenderViewEntity() == CameraEntity.this) {
|
||||||
event.roll = roll;
|
event.roll = roll;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user