Correctly parse Keyframe Presets with the new Spectator Keyframes from JSON
This commit is contained in:
@@ -14,7 +14,7 @@ import net.minecraft.entity.Entity;
|
|||||||
@EqualsAndHashCode(callSuper=true)
|
@EqualsAndHashCode(callSuper=true)
|
||||||
public class SpectatorData extends AdvancedPosition {
|
public class SpectatorData extends AdvancedPosition {
|
||||||
|
|
||||||
private int spectatedEntityID;
|
private Integer spectatedEntityID;
|
||||||
|
|
||||||
public SpectatorData(double x, double y, double z, double pitch, double yaw, double roll, int entityID) {
|
public SpectatorData(double x, double y, double z, double pitch, double yaw, double roll, int entityID) {
|
||||||
super(x, y, z, pitch, yaw, roll);
|
super(x, y, z, pitch, yaw, roll);
|
||||||
@@ -30,6 +30,15 @@ public class SpectatorData extends AdvancedPosition {
|
|||||||
this.spectatedEntityID = e.getEntityId();
|
this.spectatedEntityID = e.getEntityId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return itself if it's a valid SpectatorData object,
|
||||||
|
* otherwise a new AdvancedPosition object containing the same position data
|
||||||
|
*/
|
||||||
|
public AdvancedPosition normalize() {
|
||||||
|
if(spectatedEntityID != null) return this;
|
||||||
|
return new AdvancedPosition(x, y, z, pitch, yaw, roll);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SpectatorData newInstance() {
|
public SpectatorData newInstance() {
|
||||||
return new SpectatorData();
|
return new SpectatorData();
|
||||||
|
|||||||
@@ -5,10 +5,7 @@ import com.google.gson.TypeAdapter;
|
|||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
import eu.crushedpixel.replaymod.assets.CustomImageObject;
|
import eu.crushedpixel.replaymod.assets.CustomImageObject;
|
||||||
import eu.crushedpixel.replaymod.holders.AdvancedPosition;
|
import eu.crushedpixel.replaymod.holders.*;
|
||||||
import eu.crushedpixel.replaymod.holders.Keyframe;
|
|
||||||
import eu.crushedpixel.replaymod.holders.KeyframeSet;
|
|
||||||
import eu.crushedpixel.replaymod.holders.TimestampValue;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -47,8 +44,8 @@ public class LegacyKeyframeSetAdapter extends TypeAdapter<KeyframeSet[]> {
|
|||||||
while(in.hasNext()) {
|
while(in.hasNext()) {
|
||||||
String jsonKeyframeTag = in.nextName();
|
String jsonKeyframeTag = in.nextName();
|
||||||
if("value".equals(jsonKeyframeTag) || "position".equals(jsonKeyframeTag)) {
|
if("value".equals(jsonKeyframeTag) || "position".equals(jsonKeyframeTag)) {
|
||||||
AdvancedPosition position = new Gson().fromJson(in, AdvancedPosition.class);
|
SpectatorData spectatorData = new Gson().fromJson(in, SpectatorData.class);
|
||||||
newKeyframe.setValue(position);
|
newKeyframe.setValue(spectatorData.normalize());
|
||||||
} else if("realTimestamp".equals(jsonKeyframeTag)) {
|
} else if("realTimestamp".equals(jsonKeyframeTag)) {
|
||||||
newKeyframe.setRealTimestamp(in.nextInt());
|
newKeyframe.setRealTimestamp(in.nextInt());
|
||||||
} else if("spectatedEntityID".equals(jsonKeyframeTag)) {
|
} else if("spectatedEntityID".equals(jsonKeyframeTag)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user