Advertisement
Guest User

Extended_Jamiga

a guest
Apr 12th, 2014
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. package aJamigaPack1;
  2.  
  3. import org.lwjgl.opengl.GL11;
  4. import org.lwjgl.opengl.GL12;
  5.  
  6. import net.minecraft.client.gui.inventory.GuiContainer;
  7. import net.minecraft.client.renderer.OpenGlHelper;
  8. import net.minecraft.client.renderer.RenderHelper;
  9. import net.minecraft.client.renderer.entity.RenderManager;
  10. import net.minecraft.client.resources.I18n;
  11. import net.minecraft.entity.EntityLivingBase;
  12. import net.minecraft.entity.player.EntityPlayer;
  13. import net.minecraft.entity.player.InventoryPlayer;
  14. import net.minecraft.util.ResourceLocation;
  15.  
  16. public class GuiCustomPlayerInventory extends GuiContainer
  17. {
  18. /** x size of the inventory window in pixels. Defined as float, passed as int */
  19. private float xSize_lo;
  20.  
  21. /** y size of the inventory window in pixels. Defined as float, passed as int. */
  22. private float ySize_lo;
  23.  
  24. /** Normally I use '(ModInfo.MOD_ID, "textures/...")', but it can be done this way as well */
  25. private static final ResourceLocation iconLocation = new ResourceLocation("tutorial:textures/gui/custom_inventory.png");
  26.  
  27. /** Could use IInventory type to be more generic, but this way will save an import... */
  28. private final InventoryCustomPlayer inventory;
  29.  
  30. public GuiCustomPlayerInventory(EntityPlayer player, InventoryPlayer inventoryPlayer, InventoryCustomPlayer inventoryCustom)
  31. {
  32. super(new ContainerCustomPlayer(player, inventoryPlayer, inventoryCustom));
  33. this.inventory = inventoryCustom;
  34. // if you need the player for something later on, store it in a local variable here as well
  35. }
  36.  
  37. /**
  38. * Draws the screen and all the components in it.
  39. */
  40. public void drawScreen(int par1, int par2, float par3)
  41. {
  42. super.drawScreen(par1, par2, par3);
  43. this.xSize_lo = (float)par1;
  44. this.ySize_lo = (float)par2;
  45. }
  46.  
  47. /**
  48. * Draw the foreground layer for the GuiContainer (everything in front of the items)
  49. */
  50. protected void drawGuiContainerForegroundLayer(int par1, int par2)
  51. {
  52. // This method will simply draw inventory names on the screen - you could do without it entirely
  53. // if that's not important to you, since we are overriding the default inventory rather than
  54. // creating a specific type of inventory
  55.  
  56. String s = this.inventory.isInvNameLocalized() ? this.inventory.getInvName() : I18n.getString(this.inventory.getInvName());
  57. // with the name "Custom Inventory", the 'Cu' will be drawn in the first slot
  58. this.fontRenderer.drawString(s, this.xSize - this.fontRenderer.getStringWidth(s), 12, 4210752);
  59. // this just adds "Inventory" above the player's inventory below
  60. this.fontRenderer.drawString(I18n.getString("container.inventory"), 80, this.ySize - 96, 4210752);
  61. }
  62.  
  63. /**
  64. * Draw the background layer for the GuiContainer (everything behind the items)
  65. */
  66. protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
  67. {
  68. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  69. this.mc.getTextureManager().bindTexture(iconLocation);
  70. int k = (this.width - this.xSize) / 2;
  71. int l = (this.height - this.ySize) / 2;
  72. this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
  73. int i1;
  74. drawPlayerModel(k + 51, l + 75, 30, (float)(k + 51) - this.xSize_lo, (float)(l + 75 - 50) - this.ySize_lo, this.mc.thePlayer);
  75. }
  76.  
  77. /**
  78. * This renders the player model in standard inventory position;
  79. * copied straight from vanilla code but with renamed method parameters
  80. */
  81. public static void drawPlayerModel(int x, int y, int scale, float yaw, float pitch, EntityLivingBase entity) {
  82. GL11.glEnable(GL11.GL_COLOR_MATERIAL);
  83. GL11.glPushMatrix();
  84. GL11.glTranslatef(x, y, 50.0F);
  85. GL11.glScalef(-scale, scale, scale);
  86. GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
  87. float f2 = entity.renderYawOffset;
  88. float f3 = entity.rotationYaw;
  89. float f4 = entity.rotationPitch;
  90. float f5 = entity.prevRotationYawHead;
  91. float f6 = entity.rotationYawHead;
  92. GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F);
  93. RenderHelper.enableStandardItemLighting();
  94. GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
  95. GL11.glRotatef(-((float) Math.atan(pitch / 40.0F)) * 20.0F, 1.0F, 0.0F, 0.0F);
  96. entity.renderYawOffset = (float) Math.atan(yaw / 40.0F) * 20.0F;
  97. entity.rotationYaw = (float) Math.atan(yaw / 40.0F) * 40.0F;
  98. entity.rotationPitch = -((float) Math.atan(pitch / 40.0F)) * 20.0F;
  99. entity.rotationYawHead = entity.rotationYaw;
  100. entity.prevRotationYawHead = entity.rotationYaw;
  101. GL11.glTranslatef(0.0F, entity.yOffset, 0.0F);
  102. RenderManager.instance.playerViewY = 180.0F;
  103. RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
  104. entity.renderYawOffset = f2;
  105. entity.rotationYaw = f3;
  106. entity.rotationPitch = f4;
  107. entity.prevRotationYawHead = f5;
  108. entity.rotationYawHead = f6;
  109. GL11.glPopMatrix();
  110. RenderHelper.disableStandardItemLighting();
  111. GL11.glDisable(GL12.GL_RESCALE_NORMAL);
  112. OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
  113. GL11.glDisable(GL11.GL_TEXTURE_2D);
  114. OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement