diff --git a/src/main/java/eu/crushedpixel/replaymod/interpolation/GenericLinearInterpolation.java b/src/main/java/eu/crushedpixel/replaymod/interpolation/GenericLinearInterpolation.java index af3e9cbf..8f6fc077 100755 --- a/src/main/java/eu/crushedpixel/replaymod/interpolation/GenericLinearInterpolation.java +++ b/src/main/java/eu/crushedpixel/replaymod/interpolation/GenericLinearInterpolation.java @@ -30,8 +30,13 @@ public class GenericLinearInterpolation implements Inte @Override public void applyPoint(float position, T toEdit) { - if(points.isEmpty()) { - throw new IllegalStateException("At least one Value needs to be added for this operation"); + if(fields == null) { + throw new IllegalStateException("At least one Keyframe has to be added before preparing"); + } + + if(fields.length <= 0) { + throw new IllegalStateException("The passed KeyframeValue class" + + " has to contain at least one Field"); } //first, get previous and next T for given position diff --git a/src/main/java/eu/crushedpixel/replaymod/interpolation/GenericSplineInterpolation.java b/src/main/java/eu/crushedpixel/replaymod/interpolation/GenericSplineInterpolation.java index e222dc24..0b62976e 100755 --- a/src/main/java/eu/crushedpixel/replaymod/interpolation/GenericSplineInterpolation.java +++ b/src/main/java/eu/crushedpixel/replaymod/interpolation/GenericSplineInterpolation.java @@ -30,10 +30,15 @@ public class GenericSplineInterpolation extends BasicSp @Override public void prepare() { + if(fields == null) { + throw new IllegalStateException("At least one Keyframe has to be added before preparing"); + } + if(fields.length <= 0) { throw new IllegalStateException("The passed KeyframeValue class" + " has to contain at least one Field"); } + if(!points.isEmpty()) { cubics = new ArrayList>(fields.length); for (Field field : fields) { diff --git a/src/main/java/eu/crushedpixel/replaymod/interpolation/KeyframeList.java b/src/main/java/eu/crushedpixel/replaymod/interpolation/KeyframeList.java index c7077431..96420ddc 100644 --- a/src/main/java/eu/crushedpixel/replaymod/interpolation/KeyframeList.java +++ b/src/main/java/eu/crushedpixel/replaymod/interpolation/KeyframeList.java @@ -153,15 +153,7 @@ public class KeyframeList extends ArrayList K toApply = (K) first().getValue().newInstance(); if(previousCallLinear != (Boolean)linear) { - previousCallLinear = linear; - - interpolation = linear ? new GenericLinearInterpolation() : new GenericSplineInterpolation(); - - for(Keyframe keyframe : this) { - interpolation.addPoint(keyframe.getValue()); - } - - interpolation.prepare(); + recalculate(linear); } interpolation.applyPoint(pathPosition, toApply); @@ -169,6 +161,24 @@ public class KeyframeList extends ArrayList return toApply; } + /** + * Recalculates the underlying Interpolation instances. + * @param linear Whether to prepare linear or cubic interpolation + */ + public void recalculate(boolean linear) { + previousCallLinear = linear; + + if(isEmpty()) return; + + interpolation = linear ? new GenericLinearInterpolation() : new GenericSplineInterpolation(); + + for(Keyframe keyframe : this) { + interpolation.addPoint(keyframe.getValue()); + } + + interpolation.prepare(); + } + /** * Returns a value between 0 and 1, representing the number that should be passed * to Interpolation#getValue() calls on this list of Keyframes. diff --git a/src/main/java/eu/crushedpixel/replaymod/replay/ReplayHandler.java b/src/main/java/eu/crushedpixel/replaymod/replay/ReplayHandler.java index 92afff76..762cad71 100755 --- a/src/main/java/eu/crushedpixel/replaymod/replay/ReplayHandler.java +++ b/src/main/java/eu/crushedpixel/replaymod/replay/ReplayHandler.java @@ -579,6 +579,7 @@ public class ReplayHandler { public static void fireKeyframesModifyEvent() { FMLCommonHandler.instance().bus().post(new KeyframesModifyEvent(positionKeyframes, timeKeyframes)); - + positionKeyframes.recalculate(ReplayMod.replaySettings.isLinearMovement()); + timeKeyframes.recalculate(ReplayMod.replaySettings.isLinearMovement()); } }