Refactored and reformatted code to use less static variables

This commit is contained in:
CrushedPixel
2015-04-23 14:09:54 +02:00
parent f22416be2c
commit 0003f040ed
109 changed files with 9037 additions and 10229 deletions

View File

@@ -2,19 +2,13 @@ package eu.crushedpixel.replaymod.holders;
public class Keyframe {
private int realTimestamp;
public Keyframe(int realTimestamp) {
this.realTimestamp = realTimestamp;
}
private final int realTimestamp;
public int getRealTimestamp() {
return realTimestamp;
}
public Keyframe(int realTimestamp) {
this.realTimestamp = realTimestamp;
}
public void setRealTimestamp(int realTimestamp) {
this.realTimestamp = realTimestamp;
}
public int getRealTimestamp() {
return realTimestamp;
}
}

View File

@@ -1,16 +1,16 @@
package eu.crushedpixel.replaymod.holders;
import java.util.Comparator;
import eu.crushedpixel.replaymod.replay.ReplayHandler;
import java.util.Comparator;
public class KeyframeComparator implements Comparator<Keyframe> {
@Override
public int compare(Keyframe o1, Keyframe o2) {
if(ReplayHandler.isSelected(o1)) return 1;
if(ReplayHandler.isSelected(o2)) return -1;
return ((Integer)o1.getRealTimestamp()).compareTo(o2.getRealTimestamp());
}
@Override
public int compare(Keyframe o1, Keyframe o2) {
if(ReplayHandler.isSelected(o1)) return 1;
if(ReplayHandler.isSelected(o2)) return -1;
return ((Integer) o1.getRealTimestamp()).compareTo(o2.getRealTimestamp());
}
}

View File

@@ -1,30 +1,30 @@
package eu.crushedpixel.replaymod.holders;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.Packet;
public class PacketData {
private byte[] array;
private int timestamp;
public PacketData(byte[] array, int timestamp) {
this.array = array;
this.timestamp = timestamp;
}
public byte[] getByteArray() {
return array;
}
public void setByteArray(byte[] array) {
this.array = array;
}
public int getTimestamp() {
return timestamp;
}
public void setTimestamp(int timestamp) {
this.timestamp = timestamp;
}
private byte[] array;
private int timestamp;
public PacketData(byte[] array, int timestamp) {
this.array = array;
this.timestamp = timestamp;
}
public byte[] getByteArray() {
return array;
}
public void setByteArray(byte[] array) {
this.array = array;
}
public int getTimestamp() {
return timestamp;
}
public void setTimestamp(int timestamp) {
this.timestamp = timestamp;
}
}

View File

@@ -4,67 +4,67 @@ import net.minecraft.entity.Entity;
public class Position {
private double x, y, z;
private float pitch, yaw;
public Position(Entity e) {
this.x = e.posX;
this.y = e.posY;
this.z = e.posZ;
this.pitch = e.rotationPitch;
this.yaw = e.rotationYaw;
}
public Position(double x, double y, double z, float pitch, float yaw) {
this.x = x;
this.y = y;
this.z = z;
this.pitch = pitch;
this.yaw = yaw;
}
private double x, y, z;
private float pitch, yaw;
public double getX() {
return x;
}
public Position(Entity e) {
this.x = e.posX;
this.y = e.posY;
this.z = e.posZ;
this.pitch = e.rotationPitch;
this.yaw = e.rotationYaw;
}
public void setX(double x) {
this.x = x;
}
public Position(double x, double y, double z, float pitch, float yaw) {
this.x = x;
this.y = y;
this.z = z;
this.pitch = pitch;
this.yaw = yaw;
}
public double getY() {
return y;
}
public double getX() {
return x;
}
public void setY(double y) {
this.y = y;
}
public void setX(double x) {
this.x = x;
}
public double getZ() {
return z;
}
public double getY() {
return y;
}
public void setZ(double z) {
this.z = z;
}
public void setY(double y) {
this.y = y;
}
public float getPitch() {
return pitch;
}
public double getZ() {
return z;
}
public void setPitch(float pitch) {
this.pitch = pitch;
}
public void setZ(double z) {
this.z = z;
}
public float getYaw() {
return yaw;
}
public float getPitch() {
return pitch;
}
public void setYaw(float yaw) {
this.yaw = yaw;
}
@Override
public String toString() {
return "X="+x+", Y="+y+", Z="+z+", Yaw="+yaw+", Pitch="+pitch;
}
public void setPitch(float pitch) {
this.pitch = pitch;
}
public float getYaw() {
return yaw;
}
public void setYaw(float yaw) {
this.yaw = yaw;
}
@Override
public String toString() {
return "X=" + x + ", Y=" + y + ", Z=" + z + ", Yaw=" + yaw + ", Pitch=" + pitch;
}
}

View File

@@ -2,19 +2,14 @@ package eu.crushedpixel.replaymod.holders;
public class PositionKeyframe extends Keyframe {
private Position position;
public PositionKeyframe(int realTime, Position position) {
super(realTime);
this.position = position;
}
private final Position position;
public Position getPosition() {
return position;
}
public PositionKeyframe(int realTime, Position position) {
super(realTime);
this.position = position;
}
public void setPosition(Position position) {
this.position = position;
}
public Position getPosition() {
return position;
}
}

View File

@@ -1,100 +0,0 @@
package eu.crushedpixel.replaymod.holders;
/**
* Copyright (c) 2014 Johni0702
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
**/
public final class TimeInfo {
@Override
public String toString() {
return start+" | "+speedSince+" | "+speed+" | "+jumpTo;
}
public static TimeInfo create() {
long now = System.currentTimeMillis();
return new TimeInfo(now, now, 1, -1);
}
public TimeInfo(long start, long speedSince, double speed, long jumpTo) {
this.start = start;
this.speedSince = speedSince;
this.speed = speed;
this.jumpTo = jumpTo;
}
private final long start;
private final long speedSince;
private final double speed;
private final long jumpTo;
public long getActualStartTime(long now) {
long realTimePassed = now - speedSince;
long ingameTimePassed = (long) (realTimePassed * this.speed);
return start + realTimePassed - ingameTimePassed;
}
public long getInGameTimePassed(long now) {
long realTimePassed = now - speedSince;
long ingameTimePassed = (long) (realTimePassed * this.speed);
return speedSince - start + ingameTimePassed;
}
public TimeInfo updateSpeed(long now, double speed) {
if (isJumping()) {
return new TimeInfo(now-jumpTo, now, speed, -1);
} else {
if (this.speed == speed) {
return this;
}
long start;
if (this.speed == 1) {
start = this.start;
} else {
start = getActualStartTime(now);
}
return new TimeInfo(start, now, speed, -1);
}
}
public boolean isJumping() {
return jumpTo != -1;
}
public TimeInfo jumpTo(long jumpTo) {
return new TimeInfo(start, speedSince, speed, jumpTo);
}
public long getStart() {
return start;
}
public long getSpeedSince() {
return speedSince;
}
public double getSpeed() {
return speed;
}
public long getJumpTo() {
return jumpTo;
}
}

View File

@@ -2,18 +2,14 @@ package eu.crushedpixel.replaymod.holders;
public class TimeKeyframe extends Keyframe {
private int timestamp;
public TimeKeyframe(int realTime, int timestamp) {
super(realTime);
this.timestamp = timestamp;
}
private final int timestamp;
public int getTimestamp() {
return timestamp;
}
public void setTimestamp(int timestamp) {
this.timestamp = timestamp;
}
public TimeKeyframe(int realTime, int timestamp) {
super(realTime);
this.timestamp = timestamp;
}
public int getTimestamp() {
return timestamp;
}
}