From 31eed1cb487eb86c69763b502e8cdb7fc5cd6eb6 Mon Sep 17 00:00:00 2001 From: Electroblob77 <35599699+Electroblob77@users.noreply.github.com> Date: Sun, 31 May 2020 21:15:21 +0100 Subject: [PATCH] Add 'glitch' effect to spell HUD when arcane jammed --- .../wizardry/client/DrawingUtils.java | 25 ++++++++++++++++ .../wizardry/client/gui/GuiSpellDisplay.java | 29 ++++++++++++++----- .../client/gui/config/GuiSelectHUDSkin.java | 6 ++-- 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/main/java/electroblob/wizardry/client/DrawingUtils.java b/src/main/java/electroblob/wizardry/client/DrawingUtils.java index ff591a5c..9a63c4da 100644 --- a/src/main/java/electroblob/wizardry/client/DrawingUtils.java +++ b/src/main/java/electroblob/wizardry/client/DrawingUtils.java @@ -9,6 +9,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.math.MathHelper; import org.lwjgl.opengl.GL11; +import java.util.Random; + /** * Utility class containing some useful static methods for drawing GUIs. Previously these were spread across the main * {@code WizardryUtilities} class and various individual GUI classes. @@ -124,6 +126,29 @@ public final class DrawingUtils { tessellator.draw(); } + /** + * Draws a 'glitch' rectangle, with some rows of pixels shifted randomly to give a broken effect. + * + * @param random A random number generator to use + * @param x The x position of the rectangle + * @param y The y position of the rectangle + * @param u The x position of the top left corner of the section of the image wanted + * @param v The y position of the top left corner of the section of the image wanted + * @param width The width of the section + * @param height The height of the section + * @param textureWidth The width of the actual image. + * @param textureHeight The height of the actual image. + * @param flipX Whether to flip the texture in the x direction. + * @param flipY Whether to flip the texture in the y direction. + */ + public static void drawGlitchRect(Random random, int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight, boolean flipX, boolean flipY){ + for(int i=0; i skins = new LinkedHashMap<>(14); // 14 is the number of skins packaged with the mod private static final Gson gson = new Gson(); + private static final Random random = new Random(); /** Width and height of the spell icon (very unlikely to change!) */ private static final int SPELL_ICON_SIZE = 32; @@ -200,7 +201,7 @@ public class GuiSpellDisplay { progress = maxCooldown == 0 ? 1 : (maxCooldown - (float)cooldown + event.getPartialTicks()) / maxCooldown; } - skin.drawBackground(x, y, flipX, flipY, icon, progress, player.isCreative()); + skin.drawBackground(x, y, flipX, flipY, icon, progress, player.isCreative(), player.isPotionActive(WizardryPotions.arcane_jammer)); } @@ -457,8 +458,9 @@ public class GuiSpellDisplay { * @param icon A {@code ResourceLocation} corresponding to the icon of the selected spell. * @param cooldownBarProgress The fraction of the cooldown bar to draw; must be between 0 and 1 (inclusive). * @param creativeMode True to draw the creative mode HUD, false for the survival mode version. + * @param jammed True to show the 'glitch' effect (user for arcane jammer), false to draw normally. */ - public void drawBackground(int x, int y, boolean flipX, boolean flipY, ResourceLocation icon, float cooldownBarProgress, boolean creativeMode){ + public void drawBackground(int x, int y, boolean flipX, boolean flipY, ResourceLocation icon, float cooldownBarProgress, boolean creativeMode, boolean jammed){ // Moves the origin if the HUD does not mirror; neatens the rest of the code. if(flipX && !mirrorX) x -= width; @@ -475,8 +477,13 @@ public class GuiSpellDisplay { int x1 = flipX && mirrorX ? x - spellIconInsetX - SPELL_ICON_SIZE : x + spellIconInsetX; // y is upside-down so this is the other way round int y1 = flipY && mirrorY ? y + spellIconInsetY : y - spellIconInsetY - SPELL_ICON_SIZE; - - DrawingUtils.drawTexturedRect(x1, y1, 0, 0, SPELL_ICON_SIZE, SPELL_ICON_SIZE, SPELL_ICON_SIZE, SPELL_ICON_SIZE); + + if(jammed){ + random.setSeed(Minecraft.getMinecraft().world.getTotalWorldTime() * 3); + DrawingUtils.drawGlitchRect(random, x1, y1, 0, 0, SPELL_ICON_SIZE, SPELL_ICON_SIZE, SPELL_ICON_SIZE, SPELL_ICON_SIZE, false, false); + }else{ + DrawingUtils.drawTexturedRect(x1, y1, 0, 0, SPELL_ICON_SIZE, SPELL_ICON_SIZE, SPELL_ICON_SIZE, SPELL_ICON_SIZE); + } // Background of spell hud mc.renderEngine.bindTexture(texture); @@ -485,7 +492,11 @@ public class GuiSpellDisplay { y1 = flipY && mirrorY ? y : y - height; // The 128 here is a uv value, not a dimension, and hence is left as a hardcoded number. // TODO: Since the HUD is wider than it is tall, perhaps the creative mode texture should be in the bottom half instead of the right half? - DrawingUtils.drawTexturedFlippedRect(x1, y1, creativeMode ? 128 : 0, 0, width, height, 256, 256, flipX && mirrorX, flipY && mirrorY); + if(jammed){ + DrawingUtils.drawGlitchRect(random, x1, y1, creativeMode ? 128 : 0, 0, width, height, 256, 256, flipX && mirrorX, flipY && mirrorY); + }else{ + DrawingUtils.drawTexturedFlippedRect(x1, y1, creativeMode ? 128 : 0, 0, width, height, 256, 256, flipX && mirrorX, flipY && mirrorY); + } // Cooldown bar if(!creativeMode && cooldownBarProgress > 0 && (showCooldownWhenFull || cooldownBarProgress < 1)){ @@ -497,8 +508,12 @@ public class GuiSpellDisplay { int u = cooldownBarX; // This doesn't change, even when cooldownBarMirrorX is true, because it should int v = height; // always start with the left-hand in the actual texture file - - DrawingUtils.drawTexturedFlippedRect(x1, y1, u, v, l, cooldownBarHeight, 256, 256, flipX && cooldownBarMirrorX, flipY && cooldownBarMirrorY); + + if(jammed){ + DrawingUtils.drawGlitchRect(random, x1, y1, u, v, l, cooldownBarHeight, 256, 256, flipX && cooldownBarMirrorX, flipY && cooldownBarMirrorY); + }else{ + DrawingUtils.drawTexturedFlippedRect(x1, y1, u, v, l, cooldownBarHeight, 256, 256, flipX && cooldownBarMirrorX, flipY && cooldownBarMirrorY); + } } GlStateManager.popMatrix(); diff --git a/src/main/java/electroblob/wizardry/client/gui/config/GuiSelectHUDSkin.java b/src/main/java/electroblob/wizardry/client/gui/config/GuiSelectHUDSkin.java index 985d1594..f992f85e 100644 --- a/src/main/java/electroblob/wizardry/client/gui/config/GuiSelectHUDSkin.java +++ b/src/main/java/electroblob/wizardry/client/gui/config/GuiSelectHUDSkin.java @@ -65,15 +65,15 @@ public class GuiSelectHUDSkin extends GuiSelectString { float scale = Math.min((previewRight - previewLeft - 2*previewBorder)/(float)skin.getWidth(), (previewBottom - previewTop - 2*previewBorder)/(float)skin.getHeight()); - float x = (previewLeft + previewRight)/2 - (skin.getWidth()*scale)/2; - float y = (previewBottom + previewTop)/2 + (skin.getHeight()*scale)/2; + float x = (previewLeft + previewRight)/2f - (skin.getWidth()*scale)/2; + float y = (previewBottom + previewTop)/2f + (skin.getHeight()*scale)/2; GlStateManager.pushMatrix(); GlStateManager.scale(scale, scale, scale); skin.drawBackground((int)(x/scale), (int)(y/scale), false, false, - Spells.magic_missile.getIcon(), 0.6f, false); + Spells.magic_missile.getIcon(), 0.6f, false, false); skin.drawText((int)(x/scale), (int)(y/scale), false, false, Spells.none.getDisplayNameWithFormatting(),