Skip to content

Commit

Permalink
Try fixing target based fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
mchorse committed Oct 30, 2016
1 parent c208a27 commit e10a795
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ private void calculateRelativePosition()
@Override
public void applyFixture(float progress, float partialTicks, Position pos)
{
if (this.entity == null)
{
this.tryFindingEntity();

return;
}

float x = (float) (this.entity.lastTickPosX + (this.entity.posX - this.entity.lastTickPosX) * partialTicks);
float y = (float) (this.entity.lastTickPosY + (this.entity.posY - this.entity.lastTickPosY) * partialTicks);
float z = (float) (this.entity.lastTickPosZ + (this.entity.posZ - this.entity.lastTickPosZ) * partialTicks);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/mchorse/blockbuster/camera/fixtures/LookFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public class LookFixture extends IdleFixture
{
protected Entity entity;
protected String target;

private float oldYaw = 0;
private float oldPitch = 0;
Expand All @@ -35,6 +36,7 @@ public Entity getTarget()
public void setTarget(String target)
{
this.entity = EntityUtils.entityByUUID(Minecraft.getMinecraft().theWorld, target);
this.target = target;
}

@Override
Expand All @@ -52,6 +54,7 @@ public void edit(String[] args, EntityPlayer player) throws CommandException
if ((this.entity == null || this.entity.isDead) && target != null)
{
this.entity = target;
this.target = target.getUniqueID().toString();
}
}

Expand All @@ -61,6 +64,13 @@ public void edit(String[] args, EntityPlayer player) throws CommandException
@Override
public void applyFixture(float progress, float partialTicks, Position pos)
{
if (this.entity == null)
{
this.tryFindingEntity();

return;
}

double x = (this.entity.lastTickPosX + (this.entity.posX - this.entity.lastTickPosX) * partialTicks);
double y = (this.entity.lastTickPosY + (this.entity.posY - this.entity.lastTickPosY) * partialTicks);
double z = (this.entity.lastTickPosZ + (this.entity.posZ - this.entity.lastTickPosZ) * partialTicks);
Expand Down Expand Up @@ -94,6 +104,11 @@ public void applyFixture(float progress, float partialTicks, Position pos)
this.oldProgress = progress;
}

protected void tryFindingEntity()
{
this.entity = EntityUtils.entityByUUID(Minecraft.getMinecraft().theWorld, this.target);
}

/**
* Special interpolation method for interpolating yaw. The problem with yaw,
* is that it may go in the "wrong" direction when having, for example,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void applyOnActor(EntityActor actor, boolean force)
actor.prevRotationPitch = actor.rotationPitch;

/* Inject frame's values into actor */
if (!isRemote)
if (!isRemote || force)
{
actor.posX = this.x;
actor.posY = this.y;
Expand Down

0 comments on commit e10a795

Please sign in to comment.