Fix spectating being quit on world change / respawn
This commit is contained in:
@@ -8,6 +8,7 @@ import net.minecraft.client.Minecraft;
|
|||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.stats.StatFileWriter;
|
import net.minecraft.stats.StatFileWriter;
|
||||||
import net.minecraft.util.AxisAlignedBB;
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
import net.minecraft.util.MathHelper;
|
import net.minecraft.util.MathHelper;
|
||||||
@@ -16,6 +17,8 @@ import net.minecraft.util.Vec3;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import org.lwjgl.Sys;
|
import org.lwjgl.Sys;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class CameraEntity extends EntityPlayerSP {
|
public class CameraEntity extends EntityPlayerSP {
|
||||||
|
|
||||||
public static final double SPEED_CHANGE = 0.5;
|
public static final double SPEED_CHANGE = 0.5;
|
||||||
@@ -49,8 +52,13 @@ public class CameraEntity extends EntityPlayerSP {
|
|||||||
|
|
||||||
private boolean speedup = false;
|
private boolean speedup = false;
|
||||||
|
|
||||||
|
private UUID spectating;
|
||||||
|
|
||||||
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);
|
||||||
|
if (mc.thePlayer instanceof CameraEntity) {
|
||||||
|
spectating = ((CameraEntity) mc.thePlayer).spectating;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//frac = time since last tick
|
//frac = time since last tick
|
||||||
@@ -193,8 +201,19 @@ public class CameraEntity extends EntityPlayerSP {
|
|||||||
@Override
|
@Override
|
||||||
public void onUpdate() {
|
public void onUpdate() {
|
||||||
Entity view = mc.getRenderViewEntity();
|
Entity view = mc.getRenderViewEntity();
|
||||||
if (view != null && view != this) {
|
if (view != null) {
|
||||||
updatePos(view);
|
if (spectating != null && (view.getUniqueID() != spectating || view.worldObj != worldObj)) {
|
||||||
|
view = worldObj.getPlayerEntityByUUID(spectating);
|
||||||
|
if (view != null) {
|
||||||
|
mc.setRenderViewEntity(view);
|
||||||
|
} else {
|
||||||
|
mc.setRenderViewEntity(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (view != this) {
|
||||||
|
updatePos(view);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,6 +255,20 @@ public class CameraEntity extends EntityPlayerSP {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void spectate(Entity e) {
|
||||||
|
if (e == null || e == this) {
|
||||||
|
spectating = null;
|
||||||
|
e = this;
|
||||||
|
} else if (e instanceof EntityPlayer) {
|
||||||
|
spectating = e.getUniqueID();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mc.getRenderViewEntity() != e) {
|
||||||
|
mc.setRenderViewEntity(e);
|
||||||
|
updatePos(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public enum MoveDirection {
|
public enum MoveDirection {
|
||||||
UP, DOWN, LEFT, RIGHT, FORWARD, BACKWARD
|
UP, DOWN, LEFT, RIGHT, FORWARD, BACKWARD
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,10 +54,6 @@ public class TickAndRenderListener {
|
|||||||
|
|
||||||
if(ReplayHandler.isInPath()) ReplayProcess.tickReplay(false);
|
if(ReplayHandler.isInPath()) ReplayProcess.tickReplay(false);
|
||||||
if(ReplayHandler.isCamera()) mc.setRenderViewEntity(ReplayHandler.getCameraEntity());
|
if(ReplayHandler.isCamera()) mc.setRenderViewEntity(ReplayHandler.getCameraEntity());
|
||||||
if(mc.getRenderViewEntity() != null && (mc.getRenderViewEntity() == mc.thePlayer || !mc.getRenderViewEntity().isEntityAlive())
|
|
||||||
&& ReplayHandler.getCameraEntity() != null && !ReplayHandler.isInPath()) {
|
|
||||||
ReplayHandler.spectateCamera();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mc.isGamePaused() && ReplayHandler.isInPath()) {
|
if(mc.isGamePaused() && ReplayHandler.isInPath()) {
|
||||||
mc.isGamePaused = false;
|
mc.isGamePaused = false;
|
||||||
|
|||||||
@@ -71,9 +71,8 @@ public class KeyInputHandler {
|
|||||||
if(ReplayHandler.isCamera()) {
|
if(ReplayHandler.isCamera()) {
|
||||||
down = true;
|
down = true;
|
||||||
speedup = true;
|
speedup = true;
|
||||||
} else {
|
|
||||||
ReplayHandler.spectateCamera();
|
|
||||||
}
|
}
|
||||||
|
ReplayHandler.spectateCamera();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -135,18 +135,11 @@ public class ReplayHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void spectateEntity(Entity e) {
|
public static void spectateEntity(Entity e) {
|
||||||
if(e == null) {
|
getCameraEntity().spectate(e);
|
||||||
spectateCamera();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (mc.getRenderViewEntity() != e) {
|
|
||||||
mc.setRenderViewEntity(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void spectateCamera() {
|
public static void spectateCamera() {
|
||||||
mc.setRenderViewEntity(getCameraEntity());
|
spectateEntity(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isCamera() {
|
public static boolean isCamera() {
|
||||||
|
|||||||
@@ -386,8 +386,6 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
|
|||||||
|
|
||||||
CameraEntity cent = ReplayHandler.getCameraEntity();
|
CameraEntity cent = ReplayHandler.getCameraEntity();
|
||||||
cent.moveAbsolute(ppl.func_148932_c(), ppl.func_148928_d(), ppl.func_148933_e());
|
cent.moveAbsolute(ppl.func_148932_c(), ppl.func_148928_d(), ppl.func_148933_e());
|
||||||
|
|
||||||
ReplayHandler.spectateCamera();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}.call();
|
}.call();
|
||||||
|
|||||||
Reference in New Issue
Block a user