Skip to content

Commit

Permalink
Six Phased Copper Animation Fix (#3320)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Robertz <[email protected]>
  • Loading branch information
CookieBrigade and Dream-Master authored Oct 3, 2024
1 parent 551c690 commit 2f5a788
Showing 1 changed file with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,19 @@ public class GlitchEffectRenderer extends GeneratedMaterialRenderer {
public Random rand = new Random();
int[] red = new int[] { 255, 50, 50, 192 };
int[] cyan = new int[] { 0, 220, 220, 160 };
int counter = 0;

final long frameTimeNanos = 10_000_000L;
final int loopFrameCount = 200;
final int glitchedDurationCount = 40;
final int glitchMoveFrameCount = 5;

double offsetRed = 0;
double offsetCyan = 0;

private void applyGlitchEffect(ItemRenderType type, boolean shouldModulateColor, int[] color, IIcon... icons) {
double offset;
private void applyGlitchEffect(ItemRenderType type, boolean shouldModulateColor, double offset, int[] color,
IIcon... icons) {
for (IIcon icon : icons) {
if (icon == null) continue;
if (counter % 2 == 0) {
offset = offsetRed;
} else {
offset = offsetCyan;
}
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_BLEND);

Tessellator t = Tessellator.instance;

if (type.equals(IItemRenderer.ItemRenderType.INVENTORY)) {
Expand All @@ -50,11 +47,7 @@ private void applyGlitchEffect(ItemRenderType type, boolean shouldModulateColor,
t.addVertexWithUV(16 + offset, 0 + offset, 0, icon.getMaxU(), icon.getMinV());
t.draw();
}

GL11.glDisable(GL11.GL_BLEND);
GL11.glPopMatrix();
}
counter++;
}

@Override
Expand All @@ -63,10 +56,10 @@ protected void renderRegularItem(ItemRenderType type, ItemStack item, IIcon icon
short metaData = (short) item.getItemDamage();
if (!(item.getItem() instanceof IGT_ItemWithMaterialRenderer itemRenderer)) return;

int currentFrame = (int) ((System.nanoTime() % 4_000_000_000L) / 20_000_000L);
boolean timing = currentFrame <= 20;
int currentFrame = (int) ((System.nanoTime() % (frameTimeNanos * loopFrameCount)) / frameTimeNanos);
boolean timing = currentFrame <= glitchedDurationCount;

if (timing && currentFrame % 5 == 0) {
if (timing && currentFrame % glitchMoveFrameCount == 0) {
offsetRed = rand.nextDouble() * 1.7 * Math.signum(rand.nextGaussian());
offsetCyan = rand.nextDouble() * 1.7 * Math.signum(rand.nextGaussian());
}
Expand All @@ -88,8 +81,6 @@ protected void renderRegularItem(ItemRenderType type, ItemStack item, IIcon icon
modulation[3] / 255.0F);
}

GL11.glEnable(GL11.GL_ALPHA_TEST);

if (itemIcon != null) {
markNeedsAnimationUpdate(itemIcon);
renderRegularItem(type, item, itemIcon, aFluid == null);
Expand All @@ -114,10 +105,9 @@ protected void renderRegularItem(ItemRenderType type, ItemStack item, IIcon icon

if (type == ItemRenderType.INVENTORY && timing) {
GL11.glDisable(GL11.GL_DEPTH_TEST);
applyGlitchEffect(type, shouldModulateColor, cyan, itemIcon, overlay);
applyGlitchEffect(type, shouldModulateColor, offsetCyan, cyan, itemIcon, overlay);
GL11.glEnable(GL11.GL_DEPTH_TEST);
applyGlitchEffect(type, shouldModulateColor, red, itemIcon, overlay);

applyGlitchEffect(type, shouldModulateColor, offsetRed, red, itemIcon, overlay);
}
GL11.glDisable(GL11.GL_BLEND);
}
Expand Down

0 comments on commit 2f5a788

Please sign in to comment.