Added Core Mod to redirect the Enchantment Rendering getSystemTime() calls to a the EnchantmentTimer (glow now slows down)

This commit is contained in:
Marius Metzger
2015-03-16 01:45:36 +01:00
parent 403d896862
commit 14f53f7429
31 changed files with 549 additions and 184 deletions

View File

@@ -0,0 +1,35 @@
package eu.crushedpixel.replaymod.timer;
import eu.crushedpixel.replaymod.replay.ReplayHandler;
import eu.crushedpixel.replaymod.replay.ReplayProcess;
public class EnchantmentTimer {
private static long lastRealTime = System.currentTimeMillis();
private static long lastFakeTime = System.currentTimeMillis();
private static long recordingTime = 0;
public static void resetRecordingTime() {
recordingTime = 0;
}
public static void increaseRecordingTime(long amount) {
recordingTime += amount;
}
public static long getEnchantmentTime() {
if(!(ReplayHandler.isInPath() && ReplayProcess.isVideoRecording())) {
if(ReplayHandler.isInReplay()) {
long timeDiff = System.currentTimeMillis() - lastRealTime;
double toAdd = timeDiff*ReplayHandler.getSpeed();
lastFakeTime = Math.round(lastFakeTime+toAdd);
lastRealTime = System.currentTimeMillis();
return lastFakeTime;
}
lastFakeTime = lastRealTime = System.currentTimeMillis();
return lastRealTime;
}
return recordingTime;
}
}

View File

@@ -0,0 +1,174 @@
package eu.crushedpixel.replaymod.timer;
import java.lang.reflect.Field;
import net.minecraft.client.Minecraft;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Timer;
import eu.crushedpixel.replaymod.reflection.MCPNames;
import eu.crushedpixel.replaymod.video.ReplayTimer;
public class MCTimerHandler {
private static Field mcTimer;
private static Minecraft mc = Minecraft.getMinecraft();
private static ReplayTimer rpt = new ReplayTimer(20);
private static Timer timerBefore;
static {
try {
mcTimer = Minecraft.class.getDeclaredField(MCPNames.field("field_71428_T"));
mcTimer.setAccessible(true);
} catch(Exception e) {
e.printStackTrace();
}
}
public static void setActiveTimer() {
try {
if(timerBefore != null) {
mcTimer.set(mc, timerBefore);
}
} catch(Exception e) {
e.printStackTrace();
}
}
public static void setPassiveTimer() {
try {
if(!(getTimer() instanceof ReplayTimer)) {
timerBefore = getTimer();
mcTimer.set(mc, rpt);
}
} catch(Exception e) {
e.printStackTrace();
}
}
public static int getTicks() {
try {
Timer t = getTimer();
return t.elapsedTicks;
} catch(Exception e) {
e.printStackTrace();
}
return 0;
}
public static float getPartialTicks() {
try {
Timer t = getTimer();
return t.elapsedPartialTicks;
} catch(Exception e) {
e.printStackTrace();
}
return 0;
}
public static float getRenderTicks() {
try {
Timer t = getTimer();
return t.renderPartialTicks;
} catch(Exception e) {
e.printStackTrace();
}
return 0;
}
private static Timer getTimer() throws IllegalArgumentException, IllegalAccessException {
return (Timer)mcTimer.get(mc);
}
public static void advanceTicks(int ticks) {
try {
Timer t = getTimer();
t.elapsedTicks += ticks;
} catch(Exception e) {
e.printStackTrace();
}
}
public static void advancePartialTicks(float ticks) {
try {
Timer t = getTimer();
t.elapsedPartialTicks += ticks;
} catch(Exception e) {
e.printStackTrace();
}
}
public static void advanceRenderPartialTicks(float ticks) {
try {
Timer t = getTimer();
t.renderPartialTicks += ticks;
} catch(Exception e) {
e.printStackTrace();
}
}
public static void setTimerSpeed(float speed) {
try {
Timer t = getTimer();
t.timerSpeed = speed;
if(timerBefore != null) {
timerBefore.timerSpeed = speed;
}
} catch(Exception e) {
e.printStackTrace();
}
}
public static void setRenderPartialTicks(float ticks) {
try {
getTimer().renderPartialTicks = ticks;
} catch(Exception e) {
e.printStackTrace();
}
}
public static void setPartialTicks(float ticks) {
try {
getTimer().elapsedPartialTicks = ticks;
} catch(Exception e) {
e.printStackTrace();
}
}
public static void setTicks(int ticks) {
try {
getTimer().elapsedTicks = ticks;
} catch(Exception e) {
e.printStackTrace();
}
}
public static float getTimerSpeed() {
try {
return getTimer().timerSpeed;
} catch(Exception e) {
e.printStackTrace();
}
return 1;
}
public static void updateTimer(double d) {
try {
Timer t = getTimer();
double d2 = d;
//d2 = MathHelper.clamp_double(d2, 0.0D, 1.0D);
t.elapsedPartialTicks = (float)((double)t.elapsedPartialTicks + d2 * (double)t.timerSpeed * 20);
t.elapsedTicks = (int)t.elapsedPartialTicks;
t.elapsedPartialTicks -= (float)t.elapsedTicks;
if (t.elapsedTicks > 10)
{
t.elapsedTicks = 10;
}
t.renderPartialTicks = t.elapsedPartialTicks;
} catch(Exception e) {
e.printStackTrace();
}
}
}