Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #967 Fix graphical issues with recipe animations
- Loading branch information
Showing
7 changed files
with
120 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,38 @@ | ||
package mezz.jei.gui; | ||
|
||
import mezz.jei.api.gui.ITickTimer; | ||
import net.minecraft.client.Minecraft; | ||
|
||
public class TickTimer implements ITickTimer { | ||
private final int ticksPerCycle; | ||
private final int msPerCycle; | ||
private final int maxValue; | ||
private final boolean countDown; | ||
|
||
private long lastUpdateWorldTime = 0; | ||
private int tickCount = 0; | ||
private final long startTime; | ||
|
||
public TickTimer(int ticksPerCycle, int maxValue, boolean countDown) { | ||
this.ticksPerCycle = ticksPerCycle; | ||
this.msPerCycle = ticksPerCycle * 50; | ||
this.maxValue = maxValue; | ||
this.countDown = countDown; | ||
this.startTime = System.currentTimeMillis(); | ||
} | ||
|
||
@Override | ||
public int getValue() { | ||
long worldTime = Minecraft.getMinecraft().world.getTotalWorldTime(); | ||
long ticksPassed = worldTime - lastUpdateWorldTime; | ||
lastUpdateWorldTime = worldTime; | ||
tickCount += ticksPassed; | ||
if (tickCount >= ticksPerCycle) { | ||
tickCount = 0; | ||
} | ||
long currentTime = System.currentTimeMillis(); | ||
return getValue(startTime, currentTime, maxValue, msPerCycle, countDown); | ||
} | ||
|
||
int value = Math.round(tickCount * maxValue / (float) ticksPerCycle); | ||
@Override | ||
public int getMaxValue() { | ||
return maxValue; | ||
} | ||
|
||
public static int getValue(long startTime, long currentTime, int maxValue, int msPerCycle, boolean countDown) { | ||
long msPassed = (currentTime - startTime) % msPerCycle; | ||
int value = (int) Math.floorDiv(msPassed * (maxValue + 1), msPerCycle); | ||
if (countDown) { | ||
return maxValue - value; | ||
} else { | ||
return value; | ||
} | ||
} | ||
|
||
@Override | ||
public int getMaxValue() { | ||
return maxValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package mezz.jei.test; | ||
|
||
import mezz.jei.gui.TickTimer; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class TickTimerTest { | ||
@Test | ||
public void testBasicTickTimerMath() { | ||
int maxValue = 1000; | ||
int msPerCycle = 20; | ||
for (int i = 0; i < 1000; i++) { | ||
int expectedValue = (i % msPerCycle) * 50; | ||
int value = TickTimer.getValue(0, i, maxValue, msPerCycle, false); | ||
Assert.assertEquals(expectedValue, value); | ||
|
||
int expectedDownValue = maxValue - expectedValue; | ||
int downValue = TickTimer.getValue(0, i, maxValue, msPerCycle, true); | ||
Assert.assertEquals(expectedDownValue, downValue); | ||
} | ||
} | ||
|
||
@Test | ||
public void testMoreTicksThanValuesMath() { | ||
int maxValue = 4; | ||
int msPerCycle = 20; | ||
int[] expectedValues = new int[] {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4}; | ||
for (int i = 0; i < 1000; i++) { | ||
int expectedValue = expectedValues[i % msPerCycle]; | ||
int value = TickTimer.getValue(0, i, maxValue, msPerCycle, false); | ||
Assert.assertEquals(expectedValue, value); | ||
|
||
int expectedDownValue = maxValue - expectedValue; | ||
int downValue = TickTimer.getValue(0, i, maxValue, msPerCycle, true); | ||
Assert.assertEquals(expectedDownValue, downValue); | ||
} | ||
} | ||
|
||
@Test | ||
public void testIndivisibleTicking() { | ||
int maxValue = 3; | ||
int msPerCycle = 10; | ||
int[] expectedValues = new int[] {0, 0, 0, 1, 1, 2, 2, 2, 3, 3}; | ||
for (int i = 0; i < 1000; i++) { | ||
int expectedValue = expectedValues[i % msPerCycle]; | ||
int value = TickTimer.getValue(0, i, maxValue, msPerCycle, false); | ||
Assert.assertEquals(expectedValue, value); | ||
|
||
int expectedDownValue = maxValue - expectedValue; | ||
int downValue = TickTimer.getValue(0, i, maxValue, msPerCycle, true); | ||
Assert.assertEquals(expectedDownValue, downValue); | ||
} | ||
} | ||
} |