The camera entity is now thePlayer
This commit is contained in:
@@ -3,21 +3,20 @@ package eu.crushedpixel.replaymod.entities;
|
||||
import eu.crushedpixel.replaymod.holders.AdvancedPosition;
|
||||
import eu.crushedpixel.replaymod.replay.LesserDataWatcher;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import net.minecraft.block.material.Material;
|
||||
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.item.ItemStack;
|
||||
import net.minecraft.stats.StatFileWriter;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import org.lwjgl.Sys;
|
||||
|
||||
public class CameraEntity extends EntityPlayer {
|
||||
public class CameraEntity extends EntityPlayerSP {
|
||||
|
||||
public static final double SPEED_CHANGE = 0.5;
|
||||
public static final double LOWER_SPEED = 2;
|
||||
@@ -46,35 +45,12 @@ public class CameraEntity extends EntityPlayer {
|
||||
private Vec3 dirBefore;
|
||||
private double motion;
|
||||
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private long lastCall = 0;
|
||||
|
||||
private boolean speedup = false;
|
||||
|
||||
public CameraEntity(World worldIn) {
|
||||
super(worldIn, Minecraft.getMinecraft().getSession().getProfile());
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void tick(TickEvent.ClientTickEvent event) {
|
||||
if (event.phase == TickEvent.Phase.END) {
|
||||
if(!ReplayHandler.isInReplay()) return;
|
||||
Entity view = Minecraft.getMinecraft().getRenderViewEntity();
|
||||
if (view != this && view != null) {
|
||||
prevPosX = view.prevPosX;
|
||||
prevPosY = view.prevPosY;
|
||||
prevPosZ = view.prevPosZ;
|
||||
prevRotationYaw = view.prevRotationYaw;
|
||||
prevRotationPitch = view.prevRotationPitch;
|
||||
posX = view.posX;
|
||||
posY = view.posY;
|
||||
posZ = view.posZ;
|
||||
rotationYaw = view.rotationYaw;
|
||||
rotationPitch = view.rotationPitch;
|
||||
}
|
||||
}
|
||||
public CameraEntity(Minecraft mcIn, World worldIn, NetHandlerPlayClient netHandlerPlayClient, StatFileWriter statFileWriter) {
|
||||
super(mcIn, worldIn, netHandlerPlayClient, statFileWriter);
|
||||
}
|
||||
|
||||
//frac = time since last tick
|
||||
@@ -95,13 +71,6 @@ public class CameraEntity extends EntityPlayer {
|
||||
|
||||
motion = Math.min(motion, MAX_SPEED);
|
||||
|
||||
if(ReplayHandler.getCameraEntity() != null && mc.thePlayer != null
|
||||
&& mc.getRenderViewEntity() != null) {
|
||||
//Aligns the particle rotation
|
||||
mc.thePlayer.rotationPitch = mc.thePlayer.prevRotationPitch = mc.getRenderViewEntity().rotationPitch;
|
||||
mc.thePlayer.rotationYaw = mc.thePlayer.prevRotationYaw = mc.getRenderViewEntity().rotationYaw;
|
||||
}
|
||||
|
||||
lastCall = Sys.getTime();
|
||||
|
||||
if(direction == null || motion < THRESHOLD) {
|
||||
@@ -192,6 +161,19 @@ public class CameraEntity extends EntityPlayer {
|
||||
posX + width / 2, posY + height, posZ + width / 2));
|
||||
}
|
||||
|
||||
private void updatePos(Entity to) {
|
||||
prevPosX = to.prevPosX;
|
||||
prevPosY = to.prevPosY;
|
||||
prevPosZ = to.prevPosZ;
|
||||
prevRotationYaw = to.prevRotationYaw;
|
||||
prevRotationPitch = to.prevRotationPitch;
|
||||
posX = to.posX;
|
||||
posY = to.posY;
|
||||
posZ = to.posZ;
|
||||
rotationYaw = to.rotationYaw;
|
||||
rotationPitch = to.rotationPitch;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit() {
|
||||
this.dataWatcher = new LesserDataWatcher(this);
|
||||
@@ -208,9 +190,37 @@ public class CameraEntity extends EntityPlayer {
|
||||
this.prevRotationYawHead = this.rotationYawHead = this.prevRotationYaw = this.rotationYaw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
Entity view = mc.getRenderViewEntity();
|
||||
if (view != null && view != this) {
|
||||
updatePos(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEntityInsideOpaqueBlock() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInsideOfMaterial(Material materialIn) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInLava() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInWater() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBePushed() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -218,22 +228,9 @@ public class CameraEntity extends EntityPlayer {
|
||||
|
||||
@Override
|
||||
public boolean canBeCollidedWith() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRenderOnFire() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentItemOrArmor(int slotIn, ItemStack stack) {}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getInventory() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpectator() {
|
||||
return true;
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.mixin;
|
||||
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(EntityPlayerSP.class)
|
||||
public abstract class MixinEntityPlayerSP {
|
||||
@Inject(method = "onLivingUpdate", at = @At("HEAD"), cancellable = true)
|
||||
public void isInReplay(CallbackInfo ci) {
|
||||
if (ReplayHandler.isInReplay()) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,13 +108,13 @@ public abstract class MixinEntityRenderer implements EntityRendererHandler.IEnti
|
||||
ci.cancel();
|
||||
return; // No spectator hands during 360° view, we wouldn't even know where to put it
|
||||
}
|
||||
Entity currentEntity = ReplayHandler.getCurrentEntity();
|
||||
Entity currentEntity = Minecraft.getMinecraft().getRenderViewEntity();
|
||||
if (!ReplayHandler.isCamera() && currentEntity instanceof EntityPlayer) {
|
||||
renderPass = handler.data == StereoscopicOpenGlFrameCapturer.Data.LEFT_EYE ? 1 : 0;
|
||||
spectatorRenderer.renderSpectatorHand((EntityPlayer) currentEntity, partialTicks, renderPass);
|
||||
}
|
||||
} else if (ReplayHandler.isInReplay() && !ReplayHandler.isCamera()) {
|
||||
Entity currentEntity = ReplayHandler.getCurrentEntity();
|
||||
Entity currentEntity = Minecraft.getMinecraft().getRenderViewEntity();
|
||||
if (!ReplayHandler.isCamera() && currentEntity instanceof EntityPlayer) {
|
||||
spectatorRenderer.renderSpectatorHand((EntityPlayer) currentEntity, partialTicks, renderPass);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package eu.crushedpixel.replaymod.mixin;
|
||||
|
||||
import eu.crushedpixel.replaymod.entities.CameraEntity;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||
import net.minecraft.stats.StatFileWriter;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(PlayerControllerMP.class)
|
||||
public abstract class MixinPlayerControllerMP {
|
||||
|
||||
@Shadow
|
||||
private Minecraft mc;
|
||||
|
||||
@Shadow
|
||||
private NetHandlerPlayClient netClientHandler;
|
||||
|
||||
@Inject(method = "func_178892_a", at=@At("HEAD"), cancellable = true)
|
||||
public void createReplayCamera(World worldIn, StatFileWriter statFileWriter, CallbackInfoReturnable<EntityPlayerSP> ci) {
|
||||
if (ReplayHandler.isInReplay()) {
|
||||
ci.setReturnValue(new CameraEntity(mc, worldIn, netClientHandler, statFileWriter));
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package eu.crushedpixel.replaymod.renderer;
|
||||
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import eu.crushedpixel.replaymod.utils.SkinProvider;
|
||||
import eu.crushedpixel.replaymod.video.EntityRendererHandler;
|
||||
import net.minecraft.block.material.Material;
|
||||
@@ -35,7 +34,7 @@ public class SpectatorRenderer {
|
||||
}
|
||||
|
||||
private EntityPlayer getSpectatedPlayer() {
|
||||
Entity current = ReplayHandler.getCurrentEntity();
|
||||
Entity current = mc.getRenderViewEntity();
|
||||
if(!(current instanceof EntityPlayer)) return null;
|
||||
return (EntityPlayer)current;
|
||||
}
|
||||
@@ -211,7 +210,7 @@ public class SpectatorRenderer {
|
||||
|
||||
public void renderMapArms(EntityPlayer entityPlayer) {
|
||||
bindPlayerTexture(entityPlayer);
|
||||
Render render = mc.entityRenderer.itemRenderer.renderManager.getEntityRenderObject(ReplayHandler.getCurrentEntity());
|
||||
Render render = mc.entityRenderer.itemRenderer.renderManager.getEntityRenderObject(entityPlayer);
|
||||
RenderPlayer renderplayer = (RenderPlayer)render;
|
||||
|
||||
if(!entityPlayer.isInvisible()) {
|
||||
@@ -397,7 +396,7 @@ public class SpectatorRenderer {
|
||||
public void tickEvent(TickEvent event) {
|
||||
if(event.type != TickEvent.Type.CLIENT) return;
|
||||
if(event.phase != TickEvent.Phase.START) return;
|
||||
Entity current = ReplayHandler.getCurrentEntity();
|
||||
Entity current = mc.getRenderViewEntity();
|
||||
if(!(current instanceof EntityPlayer)) return;
|
||||
EntityPlayer entityPlayer = (EntityPlayer)current;
|
||||
updateEquippedItem(entityPlayer);
|
||||
|
||||
@@ -31,7 +31,6 @@ import net.minecraft.network.EnumPacketDirection;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.INetHandlerPlayClient;
|
||||
import net.minecraft.util.ReportedException;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher;
|
||||
|
||||
@@ -51,13 +50,11 @@ public class ReplayHandler {
|
||||
private static Keyframe selectedKeyframe;
|
||||
|
||||
private static boolean inPath = false;
|
||||
private static CameraEntity cameraEntity;
|
||||
|
||||
private static KeyframeList<AdvancedPosition> positionKeyframes = new KeyframeList<AdvancedPosition>();
|
||||
private static KeyframeList<TimestampValue> timeKeyframes = new KeyframeList<TimestampValue>();
|
||||
|
||||
private static boolean inReplay = false;
|
||||
private static Entity currentEntity = null;
|
||||
private static AdvancedPosition lastPosition = null;
|
||||
|
||||
private static KeyframeList<Marker> initialMarkers = new KeyframeList<Marker>();
|
||||
@@ -142,31 +139,18 @@ public class ReplayHandler {
|
||||
spectateCamera();
|
||||
}
|
||||
else {
|
||||
currentEntity = e;
|
||||
if (mc.getRenderViewEntity() != currentEntity) {
|
||||
mc.setRenderViewEntity(currentEntity);
|
||||
if (mc.getRenderViewEntity() != e) {
|
||||
mc.setRenderViewEntity(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void spectateCamera() {
|
||||
if(currentEntity != null) {
|
||||
AdvancedPosition prev = new AdvancedPosition(currentEntity, false);
|
||||
cameraEntity.movePath(prev);
|
||||
}
|
||||
currentEntity = cameraEntity;
|
||||
if(cameraEntity == null) {
|
||||
cameraEntity = new CameraEntity(mc.theWorld);
|
||||
}
|
||||
mc.setRenderViewEntity(cameraEntity);
|
||||
mc.setRenderViewEntity(getCameraEntity());
|
||||
}
|
||||
|
||||
public static boolean isCamera() {
|
||||
return currentEntity == cameraEntity;
|
||||
}
|
||||
|
||||
public static Entity getCurrentEntity() {
|
||||
return currentEntity;
|
||||
return mc.thePlayer instanceof CameraEntity && mc.thePlayer == mc.getRenderViewEntity();
|
||||
}
|
||||
|
||||
public static void startPath(RenderOptions renderOptions, boolean fromStart) {
|
||||
@@ -210,21 +194,7 @@ public class ReplayHandler {
|
||||
}
|
||||
|
||||
public static CameraEntity getCameraEntity() {
|
||||
if(cameraEntity == null && mc.theWorld != null) {
|
||||
synchronized (ReplayHandler.class) {
|
||||
World world = mc.theWorld;
|
||||
if (cameraEntity == null && world != null) {
|
||||
cameraEntity = new CameraEntity(world);
|
||||
}
|
||||
}
|
||||
}
|
||||
return cameraEntity;
|
||||
}
|
||||
|
||||
public static void setCameraEntity(CameraEntity entity) {
|
||||
if(entity == null) return;
|
||||
cameraEntity = entity;
|
||||
spectateCamera();
|
||||
return mc.thePlayer instanceof CameraEntity ? (CameraEntity) mc.thePlayer : null;
|
||||
}
|
||||
|
||||
public static float getCameraTilt() {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package eu.crushedpixel.replaymod.video;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.entities.CameraEntity;
|
||||
import eu.crushedpixel.replaymod.gui.GuiVideoRenderer;
|
||||
import eu.crushedpixel.replaymod.holders.AdvancedPosition;
|
||||
import eu.crushedpixel.replaymod.holders.Keyframe;
|
||||
@@ -206,11 +205,8 @@ public class VideoRenderer implements RenderInfo {
|
||||
private void updateCam() {
|
||||
KeyframeList<AdvancedPosition> positionKeyframes = ReplayHandler.getPositionKeyframes();
|
||||
|
||||
if (ReplayHandler.getCameraEntity() == null) {
|
||||
if (mc.theWorld == null) {
|
||||
return; // World hasn't been sent yet
|
||||
}
|
||||
ReplayHandler.setCameraEntity(new CameraEntity(mc.theWorld));
|
||||
if (mc.thePlayer == null) {
|
||||
return; // Not ready yet
|
||||
}
|
||||
int videoTime = framesDone * 1000 / fps;
|
||||
int posCount = ReplayHandler.getPositionKeyframes().size();
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
"required": true,
|
||||
"package": "eu.crushedpixel.replaymod.mixin",
|
||||
"mixins": [
|
||||
"MixinEntityPlayerSP",
|
||||
"MixinEffectRenderer",
|
||||
"MixinEntityRenderer",
|
||||
"MixinMinecraft",
|
||||
"MixinPlayerControllerMP",
|
||||
"MixinRender",
|
||||
"MixinRenderArrow",
|
||||
"MixinRendererLivingEntity",
|
||||
|
||||
Reference in New Issue
Block a user