diff options
author | Draknyte1 <Draknyte1@hotmail.com> | 2016-08-29 18:33:37 +1000 |
---|---|---|
committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-08-29 18:33:37 +1000 |
commit | b0ae00d54790023197a7df31199cdbfd3e54ec10 (patch) | |
tree | e3e4bf0363c10c94dec3f5446f0ef4f5d8b9d9e2 /src/Java/miscutil/core/gui/item | |
parent | 059d00c29b765fd6b5937e9686dda3cd03af08e4 (diff) | |
download | GT5-Unofficial-b0ae00d54790023197a7df31199cdbfd3e54ec10.tar.gz GT5-Unofficial-b0ae00d54790023197a7df31199cdbfd3e54ec10.tar.bz2 GT5-Unofficial-b0ae00d54790023197a7df31199cdbfd3e54ec10.zip |
+ Added Custom Backpacks.
- Removed some old blocks which were statically generated. They still exist, now just are created using the dynamic block creation system.
Diffstat (limited to 'src/Java/miscutil/core/gui/item')
-rw-r--r-- | src/Java/miscutil/core/gui/item/GuiBaseBackpack.java | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/src/Java/miscutil/core/gui/item/GuiBaseBackpack.java b/src/Java/miscutil/core/gui/item/GuiBaseBackpack.java new file mode 100644 index 0000000000..180f0c50eb --- /dev/null +++ b/src/Java/miscutil/core/gui/item/GuiBaseBackpack.java @@ -0,0 +1,122 @@ +package miscutil.core.gui.item; + +import miscutil.core.container.Container_BackpackBase; +import miscutil.core.inventories.BaseInventoryBackpack; +import miscutil.core.lib.CORE; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import com.sun.org.apache.xml.internal.security.utils.I18n; + +public class GuiBaseBackpack extends GuiContainer +{ + /** x and y size of the inventory window in pixels. Defined as float, passed as int + * These are used for drawing the player model. */ + private float xSize_lo; + private float ySize_lo; + + /** The FontRenderer used by GuiScreen */ + protected FontRenderer fontRenderer; + + /** ResourceLocation takes 2 parameters: ModId, path to texture at the location: + * "src/minecraft/assets/modid/" + * + * I have provided a sample texture file that works with this tutorial. Download it + * from Forge_Tutorials/textures/gui/ + */ + private static final ResourceLocation iconLocation = new ResourceLocation(CORE.MODID, "textures/gui/itemBackpack.png"); + + /** The inventory to render on screen */ + private final BaseInventoryBackpack inventory; + + public GuiBaseBackpack(Container_BackpackBase containerItem) + { + super(containerItem); + this.inventory = containerItem.inventory; + } + + /** + * Draws the screen and all the components in it. + */ + @Override + public void drawScreen(int par1, int par2, float par3) + { + super.drawScreen(par1, par2, par3); + this.xSize_lo = (float)par1; + this.ySize_lo = (float)par2; + } + + /** + * Draw the foreground layer for the GuiContainer (everything in front of the items) + */ + @Override + protected void drawGuiContainerForegroundLayer(int par1, int par2) + { + String s = this.inventory.hasCustomInventoryName() ? this.inventory.getInventoryName() : I18n.translate(this.inventory.getInventoryName()); + //this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 0, 4210752); + //this.fontRenderer.drawString(I18n.translate("container.inventory"), 26, this.ySize - 96 + 4, 4210752); + } + + /** + * Draw the background layer for the GuiContainer (everything behind the items) + */ + @Override + protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) + { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.getTextureManager().bindTexture(iconLocation); + int k = (this.width - this.xSize) / 2; + int l = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); + int i1; + drawPlayerModel(k + 51, l + 75, 30, (float)(k + 51) - this.xSize_lo, (float)(l + 75 - 50) - this.ySize_lo, this.mc.thePlayer); + } + + /** + * This renders the player model in standard inventory position (in later versions of Minecraft / Forge, you can + * simply call GuiInventory.drawEntityOnScreen directly instead of copying this code) + */ + public static void drawPlayerModel(int x, int y, int scale, float yaw, float pitch, EntityLivingBase entity) { + GL11.glEnable(GL11.GL_COLOR_MATERIAL); + GL11.glPushMatrix(); + GL11.glTranslatef(x, y, 50.0F); + GL11.glScalef(-scale, scale, scale); + GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F); + float f2 = entity.renderYawOffset; + float f3 = entity.rotationYaw; + float f4 = entity.rotationPitch; + float f5 = entity.prevRotationYawHead; + float f6 = entity.rotationYawHead; + GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F); + RenderHelper.enableStandardItemLighting(); + GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(-((float) Math.atan(pitch / 40.0F)) * 20.0F, 1.0F, 0.0F, 0.0F); + entity.renderYawOffset = (float) Math.atan(yaw / 40.0F) * 20.0F; + entity.rotationYaw = (float) Math.atan(yaw / 40.0F) * 40.0F; + entity.rotationPitch = -((float) Math.atan(pitch / 40.0F)) * 20.0F; + entity.rotationYawHead = entity.rotationYaw; + entity.prevRotationYawHead = entity.rotationYaw; + GL11.glTranslatef(0.0F, entity.yOffset, 0.0F); + RenderManager.instance.playerViewY = 180.0F; + RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F); + entity.renderYawOffset = f2; + entity.rotationYaw = f3; + entity.rotationPitch = f4; + entity.prevRotationYawHead = f5; + entity.rotationYawHead = f6; + GL11.glPopMatrix(); + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit); + GL11.glDisable(GL11.GL_TEXTURE_2D); + OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); + } +} |