From bb4785eb887ec2f2de0d1d88c70d0436f1005024 Mon Sep 17 00:00:00 2001 From: Lizbeth Rika Date: Thu, 9 Apr 2015 18:22:43 +0100 Subject: [PATCH] Fancy flowers for contributors. --- .../core/handler/BaubleRenderHandler.java | 49 +----- .../handler/ContributorFancinessHandler.java | 153 ++++++++++++++++++ .../client/core/helper/ShaderHelper.java | 4 +- .../botania/client/lib/LibResources.java | 3 +- .../resources/assets/botania/shader/gold.frag | 16 ++ 5 files changed, 176 insertions(+), 49 deletions(-) create mode 100644 src/main/java/vazkii/botania/client/core/handler/ContributorFancinessHandler.java create mode 100644 src/main/resources/assets/botania/shader/gold.frag diff --git a/src/main/java/vazkii/botania/client/core/handler/BaubleRenderHandler.java b/src/main/java/vazkii/botania/client/core/handler/BaubleRenderHandler.java index dfa2a9262..a76cd0220 100644 --- a/src/main/java/vazkii/botania/client/core/handler/BaubleRenderHandler.java +++ b/src/main/java/vazkii/botania/client/core/handler/BaubleRenderHandler.java @@ -65,8 +65,8 @@ public final class BaubleRenderHandler { ItemStack helm = player.inventory.armorItemInSlot(3); if(helm != null && helm.getItem() instanceof ItemTerrasteelHelm) ItemTerrasteelHelm.renderOnPlayer(helm, event); - if(event.entityPlayer.getCommandSenderName().equals("Vazkii")) - renderFancyExclusiveDevStuffBecauseImAnEvilDevWhoDoesntCareAboutTheCommunityBooo(event); + + ContributorFancinessHandler.render(event); GL11.glPopMatrix(); } @@ -139,50 +139,5 @@ public final class BaubleRenderHandler { } } - private void renderFancyExclusiveDevStuffBecauseImAnEvilDevWhoDoesntCareAboutTheCommunityBooo(RenderPlayerEvent event) { - GL11.glPushMatrix(); - IIcon icon = ((ItemManaResource) ModItems.manaResource).tailIcon; - float f = icon.getMinU(); - float f1 = icon.getMaxU(); - float f2 = icon.getMinV(); - float f3 = icon.getMaxV(); - Helper.translateToHeadLevel(event.entityPlayer); - Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationItemsTexture); - GL11.glPushMatrix(); - GL11.glColor4f(1F, 1F, 1F, 1F); - GL11.glRotatef(90F, 0F, 1F, 0F); - float t = 0.13F; - GL11.glTranslatef(t, -0.5F, -0.1F); - if(event.entityPlayer.motionY < 0) - GL11.glRotatef((float) event.entityPlayer.motionY * 20F, 1F, 0F, 0F); - - float r = -18F + (float) Math.sin((ClientTickHandler.ticksInGame + event.partialRenderTick) * 0.05F) * 2F; - GL11.glRotatef(r, 0F, 0F, 1F); - float s = 0.9F; - GL11.glScalef(s, s, s); - ItemRenderer.renderItemIn2D(Tessellator.instance, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 1F / 16F); - GL11.glRotatef(-r, 0F, 0F, 1F); - GL11.glTranslatef(-t, -0F, 0F); - GL11.glScalef(-1F, 1F, 1F); - GL11.glTranslatef(t, -0F, 0F); - GL11.glRotatef(r, 0F, 0F, 1F); - ItemRenderer.renderItemIn2D(Tessellator.instance, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 1F / 16F); - GL11.glPopMatrix(); - - Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture); - icon = BlockModFlower.icons[6]; - f = icon.getMinU(); - f1 = icon.getMaxU(); - f2 = icon.getMinV(); - f3 = icon.getMaxV(); - GL11.glRotatef(180F, 0F, 0F, 1F); - GL11.glRotatef(90F, 0F, 1F, 0F); - GL11.glScalef(0.5F, 0.5F, 0.5F); - GL11.glTranslatef(-0.5F, 0.7F, 0F); - - ItemRenderer.renderItemIn2D(Tessellator.instance, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 1F / 16F); - - GL11.glPopMatrix(); - } } diff --git a/src/main/java/vazkii/botania/client/core/handler/ContributorFancinessHandler.java b/src/main/java/vazkii/botania/client/core/handler/ContributorFancinessHandler.java new file mode 100644 index 000000000..c88ed6cf0 --- /dev/null +++ b/src/main/java/vazkii/botania/client/core/handler/ContributorFancinessHandler.java @@ -0,0 +1,153 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Apr 9, 2015, 5:35:26 PM (GMT)] + */ +package vazkii.botania.client.core.handler; + +import java.io.InputStreamReader; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import org.lwjgl.opengl.GL11; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraftforge.client.event.RenderPlayerEvent; +import vazkii.botania.api.BotaniaAPI; +import vazkii.botania.api.item.IBaubleRender.Helper; +import vazkii.botania.api.subtile.signature.SubTileSignature; +import vazkii.botania.client.core.helper.ShaderHelper; +import vazkii.botania.common.block.BlockModFlower; +import vazkii.botania.common.block.ModBlocks; +import vazkii.botania.common.core.version.VersionChecker; +import vazkii.botania.common.item.ModItems; +import vazkii.botania.common.item.block.ItemBlockSpecialFlower; +import vazkii.botania.common.item.material.ItemManaResource; +import cpw.mods.fml.common.FMLLog; + +public final class ContributorFancinessHandler { + + private volatile static Map flowerMap = null; + private static boolean startedLoading = false; + + public static void render(RenderPlayerEvent.Specials event) { + if(!startedLoading) { + new ThreadContributorListLoader(); + startedLoading = true; + } + + String name = event.entityPlayer.getDisplayName(); + + if(name.equals("Vazkii")) + renderFancyExclusiveDevStuffBecauseImAnEvilDevWhoDoesntCareAboutTheCommunityBooo(event); + + name = name.toLowerCase(); + if(flowerMap != null && flowerMap.containsKey(name)) + renderFlower(event, flowerMap.get(name)); + } + + public static void load(Properties props) { + flowerMap = new HashMap(); + for(String key : props.stringPropertyNames()) { + String value = props.getProperty(key); + + try { + int i = Integer.parseInt(value); + if(i < 0 || i >= 16) + throw new NumberFormatException(); + flowerMap.put(key, ModBlocks.flower.func_149735_b(0, i)); + } catch(NumberFormatException e) { + SubTileSignature sig = BotaniaAPI.getSignatureForName(value); + if(sig != null) + flowerMap.put(key, ItemBlockSpecialFlower.ofType(value).getIconIndex()); + } + } + } + + + private static void renderFancyExclusiveDevStuffBecauseImAnEvilDevWhoDoesntCareAboutTheCommunityBooo(RenderPlayerEvent event) { + GL11.glPushMatrix(); + IIcon icon = ((ItemManaResource) ModItems.manaResource).tailIcon; + float f = icon.getMinU(); + float f1 = icon.getMaxU(); + float f2 = icon.getMinV(); + float f3 = icon.getMaxV(); + Helper.translateToHeadLevel(event.entityPlayer); + Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationItemsTexture); + GL11.glColor4f(1F, 1F, 1F, 1F); + GL11.glRotatef(90F, 0F, 1F, 0F); + float t = 0.13F; + GL11.glTranslatef(t, -0.5F, -0.1F); + if(event.entityPlayer.motionY < 0) + GL11.glRotatef((float) event.entityPlayer.motionY * 20F, 1F, 0F, 0F); + + float r = -18F + (float) Math.sin((ClientTickHandler.ticksInGame + event.partialRenderTick) * 0.05F) * 2F; + GL11.glRotatef(r, 0F, 0F, 1F); + float s = 0.9F; + GL11.glScalef(s, s, s); + ItemRenderer.renderItemIn2D(Tessellator.instance, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 1F / 16F); + GL11.glRotatef(-r, 0F, 0F, 1F); + GL11.glTranslatef(-t, -0F, 0F); + GL11.glScalef(-1F, 1F, 1F); + GL11.glTranslatef(t, -0F, 0F); + GL11.glRotatef(r, 0F, 0F, 1F); + ItemRenderer.renderItemIn2D(Tessellator.instance, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 1F / 16F); + GL11.glPopMatrix(); + } + + private static void renderFlower(RenderPlayerEvent event, IIcon icon) { + GL11.glPushMatrix(); + Helper.translateToHeadLevel(event.entityPlayer); + Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture); + float f = icon.getMinU(); + float f1 = icon.getMaxU(); + float f2 = icon.getMinV(); + float f3 = icon.getMaxV(); + GL11.glRotatef(180F, 0F, 0F, 1F); + GL11.glRotatef(90F, 0F, 1F, 0F); + GL11.glScalef(0.5F, 0.5F, 0.5F); + GL11.glTranslatef(-0.5F, 0.7F, 0F); + + ShaderHelper.useShader(ShaderHelper.gold); + ItemRenderer.renderItemIn2D(Tessellator.instance, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 1F / 16F); + ShaderHelper.releaseShader(); + GL11.glPopMatrix(); + } + + public static class ThreadContributorListLoader extends Thread { + + public ThreadContributorListLoader() { + setName("Botania Contributor Fanciness Thread"); + setDaemon(true); + start(); + } + + @Override + public void run() { + try { + URL url = new URL("https://raw.githubusercontent.com/Vazkii/Botania/master/contributors.properties"); + Properties props = new Properties(); + props.load(new InputStreamReader(url.openStream())); + load(props); + } catch(Exception e) { + FMLLog.info("[Botania] Could not load contributors list. Either you're offline or github is down. Nothing to worry about, carry on~"); + e.printStackTrace(); + } + VersionChecker.doneChecking = true; + } + + } + +} diff --git a/src/main/java/vazkii/botania/client/core/helper/ShaderHelper.java b/src/main/java/vazkii/botania/client/core/helper/ShaderHelper.java index 73d461a52..8287c044c 100644 --- a/src/main/java/vazkii/botania/client/core/helper/ShaderHelper.java +++ b/src/main/java/vazkii/botania/client/core/helper/ShaderHelper.java @@ -41,6 +41,7 @@ public final class ShaderHelper { public static int dopplegangerBar = 0; public static int terraPlateRune = 0; public static int filmGrain = 0; + public static int gold = 0; public static void initShaders() { if(!useShaders()) @@ -53,7 +54,8 @@ public final class ShaderHelper { halo = createProgram(null, LibResources.SHADER_HALO_FRAG); dopplegangerBar = createProgram(null, LibResources.SHADER_DOPLLEGANGER_BAR_FRAG); terraPlateRune = createProgram(null, LibResources.SHADER_TERRA_PLATE_RUNE_FRAG); - filmGrain = createProgram(null, LibResources.SHADER_FILM_GRAIN); + filmGrain = createProgram(null, LibResources.SHADER_FILM_GRAIN_FRAG); + gold = createProgram(null, LibResources.SHADER_GOLD_FRAG); } public static void useShader(int shader, ShaderCallback callback) { diff --git a/src/main/java/vazkii/botania/client/lib/LibResources.java b/src/main/java/vazkii/botania/client/lib/LibResources.java index c5268e688..e347f8067 100644 --- a/src/main/java/vazkii/botania/client/lib/LibResources.java +++ b/src/main/java/vazkii/botania/client/lib/LibResources.java @@ -128,6 +128,7 @@ public final class LibResources { public static final String SHADER_HALO_FRAG = PREFIX_SHADER + "halo.frag"; public static final String SHADER_DOPLLEGANGER_BAR_FRAG = PREFIX_SHADER + "doppleganger_bar.frag"; public static final String SHADER_TERRA_PLATE_RUNE_FRAG = PREFIX_SHADER + "terra_plate_rune.frag"; - public static final String SHADER_FILM_GRAIN = PREFIX_SHADER + "film_grain.frag"; + public static final String SHADER_FILM_GRAIN_FRAG = PREFIX_SHADER + "film_grain.frag"; + public static final String SHADER_GOLD_FRAG = PREFIX_SHADER + "gold.frag"; } diff --git a/src/main/resources/assets/botania/shader/gold.frag b/src/main/resources/assets/botania/shader/gold.frag new file mode 100644 index 000000000..9d22b154f --- /dev/null +++ b/src/main/resources/assets/botania/shader/gold.frag @@ -0,0 +1,16 @@ +#version 120 + +uniform sampler2D bgl_RenderedTexture; +uniform int time; // Passed in, see ShaderHelper.java + +void main() { + vec2 texcoord = vec2(gl_TexCoord[0]); + vec4 color = texture2D(bgl_RenderedTexture, texcoord); + float gs = (color.r + color.g + color.g) / 3.0; + + float rm = 1.0; + float gm = 0.85; + float bm = 0.07; + + gl_FragColor = vec4(gs * rm, gs * gm, gs * bm, color.a); +} \ No newline at end of file