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