Warning, GIGANTIC COMMIT!
Replaced Keyframe subclasses with Generic Types of Keyframe and replaced all instanceof calls Replaced implementations of Linear and Spline interpolation to interpolate any Object that extends KeyframeValue and contains at least one public double Field. I'll need this for Keyframe interpolation in CustomImageObject Transformations Made MarkerKeyframe *no* subclass of Keyframe to avoid conflicts with PositionKeyframe in instanceof checks for Keyframe#getValue Created KeyframeList which extends ArrayList to provide some helping functions which DRY up the ReplayHandler Split up ReplayHandler's keyframeList into timeKeyframeList and positionKeyframeList
This commit is contained in:
@@ -1,81 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.holders;
|
||||
|
||||
import eu.crushedpixel.replaymod.registry.ResourceHelper;
|
||||
import eu.crushedpixel.replaymod.utils.RoundUtils;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class CustomImageObject implements GuiEntryListEntry {
|
||||
|
||||
public CustomImageObject(Position position, String name, final File imageSource) throws IOException {
|
||||
|
||||
this.position = new ExtendedPosition(RoundUtils.round(position.getX()), RoundUtils.round(position.getY()), RoundUtils.round(position.getZ()), 0, 0);
|
||||
|
||||
this.name = name;
|
||||
|
||||
setImageFile(imageSource);
|
||||
}
|
||||
|
||||
@Getter @Setter private ExtendedPosition position;
|
||||
@Getter @Setter private String name;
|
||||
@Getter private File imageFile;
|
||||
|
||||
public void setImageFile(final File imageSource) throws IOException {
|
||||
this.imageFile = imageSource;
|
||||
|
||||
final BufferedImage bufferedImage = ImageIO.read(imageSource);
|
||||
|
||||
this.textureWidth = bufferedImage.getWidth();
|
||||
this.textureHeight = bufferedImage.getHeight();
|
||||
|
||||
float w;
|
||||
float h;
|
||||
|
||||
if(bufferedImage.getWidth() > bufferedImage.getHeight()) {
|
||||
w = 1;
|
||||
h = (bufferedImage.getHeight()/(float)bufferedImage.getWidth());
|
||||
} else {
|
||||
w = (bufferedImage.getWidth()/(float)bufferedImage.getHeight());
|
||||
h = 1;
|
||||
}
|
||||
|
||||
this.position.setWidth(w);
|
||||
this.position.setHeight(h);
|
||||
|
||||
Minecraft.getMinecraft().addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
resourceLocation = new ResourceLocation("customImages/"+imageSource.getAbsolutePath());
|
||||
dynamicTexture = new DynamicTexture(bufferedImage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private ResourceLocation resourceLocation;
|
||||
private DynamicTexture dynamicTexture;
|
||||
|
||||
@Getter private float textureWidth, textureHeight;
|
||||
|
||||
public ResourceLocation getResourceLocation() {
|
||||
if(!ResourceHelper.isRegistered(resourceLocation)) {
|
||||
ResourceHelper.registerResource(resourceLocation);
|
||||
Minecraft.getMinecraft().getTextureManager().loadTexture(resourceLocation, dynamicTexture);
|
||||
dynamicTexture.updateDynamicTexture();
|
||||
}
|
||||
|
||||
return resourceLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.holders;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ExtendedPosition extends Position {
|
||||
|
||||
public ExtendedPosition(double x, double y, double z, float width, float height) {
|
||||
super(x, y, z, 0, 0);
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
private float anchorX, anchorY;
|
||||
private float width, height;
|
||||
private float scale = 1f;
|
||||
private float opacity = 1f;
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package eu.crushedpixel.replaymod.holders;
|
||||
|
||||
import eu.crushedpixel.replaymod.interpolation.KeyframeValue;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -7,9 +8,12 @@ import lombok.EqualsAndHashCode;
|
||||
@Data
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor
|
||||
public abstract class Keyframe {
|
||||
public class Keyframe<T extends KeyframeValue> {
|
||||
|
||||
private int realTimestamp;
|
||||
private T value;
|
||||
|
||||
public abstract Keyframe copy();
|
||||
public Keyframe copy() {
|
||||
return new Keyframe<T>(realTimestamp, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import java.util.List;
|
||||
|
||||
public class KeyframeSet implements GuiEntryListEntry {
|
||||
private String name;
|
||||
private PositionKeyframe[] positionKeyframes;
|
||||
private TimeKeyframe[] timeKeyframes;
|
||||
private Keyframe<Position>[] positionKeyframes;
|
||||
private Keyframe<TimestampValue>[] timeKeyframes;
|
||||
|
||||
public KeyframeSet(String name, Keyframe[] keyframes) {
|
||||
this.name = name;
|
||||
@@ -21,18 +21,18 @@ public class KeyframeSet implements GuiEntryListEntry {
|
||||
}
|
||||
|
||||
public void setKeyframes(Keyframe[] keyframes) {
|
||||
List<PositionKeyframe> posKFList = new ArrayList<PositionKeyframe>();
|
||||
List<TimeKeyframe> timeKFList = new ArrayList<TimeKeyframe>();
|
||||
List<Keyframe<Position>> posKFList = new ArrayList<Keyframe<Position>>();
|
||||
List<Keyframe<TimestampValue>> timeKFList = new ArrayList<Keyframe<TimestampValue>>();
|
||||
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(kf instanceof PositionKeyframe)
|
||||
posKFList.add((PositionKeyframe)kf);
|
||||
else if(kf instanceof TimeKeyframe)
|
||||
timeKFList.add((TimeKeyframe) kf);
|
||||
if(kf.getValue() instanceof Position)
|
||||
posKFList.add((Keyframe<Position>)kf);
|
||||
else if(kf.getValue() instanceof TimestampValue)
|
||||
timeKFList.add((Keyframe<TimestampValue>) kf);
|
||||
}
|
||||
|
||||
positionKeyframes = posKFList.toArray(new PositionKeyframe[posKFList.size()]);
|
||||
timeKeyframes = timeKFList.toArray(new TimeKeyframe[timeKFList.size()]);
|
||||
positionKeyframes = posKFList.toArray(new Keyframe[posKFList.size()]);
|
||||
timeKeyframes = timeKFList.toArray(new Keyframe[timeKFList.size()]);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
@@ -1,23 +1,14 @@
|
||||
package eu.crushedpixel.replaymod.holders;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public final class MarkerKeyframe extends Keyframe {
|
||||
@AllArgsConstructor
|
||||
public final class MarkerKeyframe {
|
||||
|
||||
private int realTimestamp;
|
||||
private Position position;
|
||||
private String name;
|
||||
|
||||
public MarkerKeyframe(Position position, int timestamp, String name) {
|
||||
super(timestamp);
|
||||
this.position = position;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Keyframe copy() {
|
||||
return new MarkerKeyframe(position, getRealTimestamp(), name);
|
||||
}
|
||||
}
|
||||
|
||||
13
src/main/java/eu/crushedpixel/replaymod/holders/Point.java
Normal file
13
src/main/java/eu/crushedpixel/replaymod/holders/Point.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package eu.crushedpixel.replaymod.holders;
|
||||
|
||||
import eu.crushedpixel.replaymod.interpolation.KeyframeValue;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Point extends KeyframeValue {
|
||||
|
||||
public double x, y;
|
||||
|
||||
}
|
||||
@@ -1,27 +1,38 @@
|
||||
package eu.crushedpixel.replaymod.holders;
|
||||
|
||||
import eu.crushedpixel.replaymod.interpolation.KeyframeValue;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Position {
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper=true)
|
||||
public class Position extends KeyframeValue {
|
||||
|
||||
private double x, y, z;
|
||||
private float pitch, yaw, roll;
|
||||
public double x, y, z;
|
||||
public double pitch, yaw, roll;
|
||||
|
||||
public Position(int entityID) {
|
||||
this(Minecraft.getMinecraft().theWorld.getEntityByID(entityID));
|
||||
private Integer spectatedEntityID;
|
||||
|
||||
public Position(int entityID, boolean spectate) {
|
||||
this(Minecraft.getMinecraft().theWorld.getEntityByID(entityID), spectate);
|
||||
}
|
||||
|
||||
public Position(Entity e) {
|
||||
this(e.posX, e.posY, e.posZ, e.rotationPitch, e.rotationYaw);
|
||||
public Position(Entity e, boolean spectate) {
|
||||
this(e.posX, e.posY, e.posZ, e.rotationPitch, e.rotationYaw, spectate ? e.getEntityId() : null);
|
||||
}
|
||||
|
||||
public Position(double x, double y, double z, float pitch, float yaw, Integer spectatedEntityID) {
|
||||
this(x, y, z, pitch, yaw, 0, spectatedEntityID);
|
||||
}
|
||||
|
||||
public Position(double x, double y, double z, float pitch, float yaw) {
|
||||
this(x, y, z, pitch, yaw, 0);
|
||||
this(x, y, z, pitch, yaw, 0, null);
|
||||
}
|
||||
|
||||
public double distanceSquared(double x, double y, double z) {
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.holders;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public final class PositionKeyframe extends Keyframe {
|
||||
|
||||
private Position position;
|
||||
private Integer spectatedEntityID;
|
||||
|
||||
public PositionKeyframe(int realTime, Position position) {
|
||||
this(realTime, position, null);
|
||||
}
|
||||
|
||||
public PositionKeyframe(int realTime, Position position, Integer spectatedEntityID) {
|
||||
super(realTime);
|
||||
this.position = position;
|
||||
this.spectatedEntityID = spectatedEntityID;
|
||||
}
|
||||
|
||||
public PositionKeyframe(int realTime, int spectatedEntityID) {
|
||||
this(realTime, new Position(spectatedEntityID), spectatedEntityID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Keyframe copy() {
|
||||
return new PositionKeyframe(getRealTimestamp(), position, spectatedEntityID);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.holders;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public final class TimeKeyframe extends Keyframe {
|
||||
|
||||
private final int timestamp;
|
||||
|
||||
public TimeKeyframe(int realTime, int timestamp) {
|
||||
super(realTime);
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Keyframe copy() {
|
||||
return new TimeKeyframe(getRealTimestamp(), getTimestamp());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package eu.crushedpixel.replaymod.holders;
|
||||
|
||||
import eu.crushedpixel.replaymod.interpolation.KeyframeValue;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TimestampValue extends KeyframeValue {
|
||||
|
||||
public double value;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package eu.crushedpixel.replaymod.holders;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Transformations {
|
||||
|
||||
private Position anchor;
|
||||
private Position position;
|
||||
private Position orientation;
|
||||
private Point scale;
|
||||
private float opacity;
|
||||
|
||||
private float width, height;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user