Java tutorial
/** * AbyssalCraft * Copyright 2012-2015 Shinoow * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.shinoow.abyssalcraft.client.gui.necronomicon.buttons; import org.lwjgl.opengl.GL11; import com.shinoow.abyssalcraft.AbyssalCraft; import com.shinoow.abyssalcraft.client.gui.necronomicon.GuiNecronomicon; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.Tessellator; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; public class ButtonCategory extends GuiButton { GuiNecronomicon gui; Item icon; float ticksHovered = 0F; public ButtonCategory(int par1, int par2, int par3, GuiNecronomicon gui, String label, Item icon) { super(par1, par2, par3, 120, 24, label); this.gui = gui; this.icon = icon; } @Override public void drawButton(Minecraft mc, int mx, int my) { FontRenderer fr = mc.fontRenderer; boolean inside = mx >= xPosition && my >= yPosition && mx < xPosition + width && my < yPosition + height; float time = 5F; if (inside) ticksHovered = Math.min(time, ticksHovered); else ticksHovered = Math.max(0F, ticksHovered); ResourceLocation res = getTexture(icon); if (res == null) res = getTexture(AbyssalCraft.necronomicon); mc.renderEngine.bindTexture(res); float s = 1F / 48F; GL11.glPushMatrix(); GL11.glColor4f(1F, 1F, 1F, 1); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glScalef(0.5F, 0.5F, 0.5F); drawTexturedModalRect(xPosition * 2, yPosition * 2, zLevel * 2, 0, 0, 48, 48, s, s); // drawTexturedModalRect(xPosition, yPosition, 0, 16, 48, 48); GL11.glPopMatrix(); fr.drawString(displayString, xPosition + 20, yPosition + 10, 0); } ResourceLocation getTexture(Item par1) { if (par1 == AbyssalCraft.abyssalnomicon) return new ResourceLocation("abyssalcraft:textures/items/abyssalnomicon.png"); else if (par1 == AbyssalCraft.necronomicon_cor) return new ResourceLocation("abyssalcraft:textures/items/necronomicon_cor.png"); else if (par1 == AbyssalCraft.necronomicon_dre) return new ResourceLocation("abyssalcraft:textures/items/necronomicon_dre.png"); else if (par1 == AbyssalCraft.necronomicon_omt) return new ResourceLocation("abyssalcraft:textures/items/necronomicon_omt.png"); else return new ResourceLocation("abyssalcraft:textures/items/necronomicon.png"); } public static void drawTexturedModalRect(int par1, int par2, float z, int par3, int par4, int par5, int par6, float f, float f1) { Tessellator tessellator = Tessellator.instance; tessellator.startDrawingQuads(); tessellator.addVertexWithUV(par1 + 0, par2 + par6, z, (par3 + 0) * f, (par4 + par6) * f1); tessellator.addVertexWithUV(par1 + par5, par2 + par6, z, (par3 + par5) * f, (par4 + par6) * f1); tessellator.addVertexWithUV(par1 + par5, par2 + 0, z, (par3 + par5) * f, (par4 + 0) * f1); tessellator.addVertexWithUV(par1 + 0, par2 + 0, z, (par3 + 0) * f, (par4 + 0) * f1); tessellator.draw(); } }