Guest User

Untitled

a guest
Dec 22nd, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.82 KB | None | 0 0
  1. package Com.gun.main;
  2.  
  3.  
  4.  
  5.  
  6.  
  7. import Com.gun.gun.EnumGunType;
  8. import Com.gun.gun.ItemGun;
  9. import Com.gun.gun.ItemMagazine;
  10. import cpw.mods.fml.common.eventhandler.SubscribeEvent;
  11. import cpw.mods.fml.relauncher.Side;
  12. import cpw.mods.fml.relauncher.SideOnly;
  13. import net.minecraft.client.Minecraft;
  14. import net.minecraft.client.entity.EntityClientPlayerMP;
  15. import net.minecraft.client.entity.EntityPlayerSP;
  16. import net.minecraft.client.gui.FontRenderer;
  17. import net.minecraft.client.gui.Gui;
  18. import net.minecraft.client.gui.ScaledResolution;
  19. import net.minecraft.client.renderer.Tessellator;
  20. import net.minecraft.client.renderer.texture.TextureManager;
  21. import net.minecraft.client.resources.I18n;
  22. import net.minecraft.client.settings.GameSettings;
  23. import net.minecraft.client.settings.KeyBinding;
  24. import net.minecraft.entity.player.PlayerCapabilities;
  25. import net.minecraft.item.Item;
  26. import net.minecraft.item.ItemStack;
  27. import net.minecraft.nbt.NBTTagCompound;
  28. import net.minecraft.util.ResourceLocation;
  29. import net.minecraftforge.client.event.FOVUpdateEvent;
  30. import net.minecraftforge.client.event.RenderGameOverlayEvent;
  31.  
  32. import org.lwjgl.opengl.GL11;
  33.  
  34.  
  35.  
  36. public class ClientTickHandler
  37. {
  38. public boolean isZoomed = false;
  39. private ResourceLocation m22Crosshair;
  40. private ResourceLocation ironCrosshair;
  41. private ResourceLocation ammo;
  42. private int lastPerspective = -1;
  43. public int flashTimeout = 0;
  44. public int scopeTime = -1;
  45.  
  46. public ClientTickHandler()
  47. {
  48. this.m22Crosshair = new ResourceLocation("battlefield:textures/gui/crosshair_m22.png");
  49. this.ironCrosshair = new ResourceLocation("battlefield:textures/gui/crosshair_iron.png");
  50. this.ammo = new ResourceLocation("battlefield:textures/gui/ammo.png");
  51. }
  52.  
  53. @SideOnly(Side.CLIENT)
  54. @SubscribeEvent
  55. public void renderOverlay(RenderGameOverlayEvent event)
  56. {
  57. GL11.glPushMatrix();
  58.  
  59. ScaledResolution res = event.resolution;
  60. EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
  61. ItemStack stack = player.getHeldItem();
  62. ItemGun item = (stack != null) && ((stack.getItem() instanceof ItemGun)) ? (ItemGun)stack.getItem() : null;
  63. FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
  64. if (item != null)
  65. {
  66. if (this.isZoomed)
  67. {
  68. boolean isIronsight = item.hasAttachment(stack, MainRegistry.content().ironSights.getName());
  69. ResourceLocation texture = isIronsight ? this.ironCrosshair : this.m22Crosshair;
  70.  
  71. GL11.glDisable(2929);
  72. GL11.glDepthMask(false);
  73. GL11.glEnable(3042);
  74. GL11.glBlendFunc(770, 771);
  75. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  76. Minecraft.getMinecraft().renderEngine.bindTexture(texture);
  77. Tessellator tessellator = Tessellator.instance;
  78. tessellator.startDrawingQuads();
  79. tessellator.addVertexWithUV(0.0D, res.getScaledHeight(), -90.0D, 0.0D, 1.0D);
  80. tessellator.addVertexWithUV(res.getScaledWidth(), res.getScaledHeight(), -90.0D, 1.0D, 1.0D);
  81. tessellator.addVertexWithUV(res.getScaledWidth(), 0.0D, -90.0D, 1.0D, 0.0D);
  82. tessellator.addVertexWithUV(0.0D, 0.0D, -90.0D, 0.0D, 0.0D);
  83. tessellator.draw();
  84. GL11.glDepthMask(true);
  85. GL11.glDisable(3042);
  86. GL11.glEnable(2929);
  87. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  88. }
  89. NBTTagCompound nbt = stack.stackTagCompound;
  90. ItemMagazine mag = (ItemMagazine)item.getMagazineItem();
  91. String text = (nbt != null ? nbt.getInteger("remainingAmmo") : 0) + "/" + String.valueOf(mag != null ? mag.getMaxDamage() : 0);
  92. fr.drawStringWithShadow(text, res.getScaledWidth() - fr.getStringWidth(text) - 10, res.getScaledHeight() - 20, 16777215);
  93. String reloadText = null;
  94. if (item.hasAmmo(stack))
  95. {
  96. if (nbt.getInteger("remainingAmmo") < (item.getGunType() == EnumGunType.PISTOL ? 3 : 10)) {
  97. if (nbt.getInteger("remainingAmmo") > 0) {
  98. if (item.getGunType() != EnumGunType.MISC) {
  99. reloadText = I18n.format("gui.overlay.low", new Object[0]);
  100. }
  101. }
  102. }
  103. }
  104. else {
  105. reloadText = I18n.format("gui.overlay.reload", new Object[] { GameSettings.getKeyDisplayString(KeyHandler.reload.getKeyCode()) });
  106. }
  107. if ((reloadText != null) && (!player.capabilities.isCreativeMode)) {
  108. drawCenteredString(fr, reloadText, res.getScaledWidth() / 2, res.getScaledHeight() / 2 + fr.FONT_HEIGHT, 16777215);
  109. }
  110. }
  111. GL11.glPopMatrix();
  112.  
  113. GL11.glColor3f(1.0F, 1.0F, 1.0F);
  114. Minecraft.getMinecraft().renderEngine.bindTexture(Gui.icons);
  115. }
  116.  
  117. @SideOnly(Side.CLIENT)
  118. @SubscribeEvent
  119. public void fovUpdate(FOVUpdateEvent event)
  120. {
  121. float fov = event.fov;
  122. ItemStack stack = event.entity.getHeldItem();
  123. if ((stack != null) && ((stack.getItem() instanceof ItemGun)) && (((ItemGun)stack.getItem()).canUseScope(stack)) && (this.isZoomed))
  124. {
  125. this.scopeTime += 1;
  126. if (this.lastPerspective == -1) {
  127. this.lastPerspective = Minecraft.getMinecraft().gameSettings.thirdPersonView;
  128. }
  129. if (Minecraft.getMinecraft().gameSettings.thirdPersonView != 0) {
  130. Minecraft.getMinecraft().gameSettings.thirdPersonView = 0;
  131. }
  132. float multiplier = 4.0F;
  133. boolean isIronsight = ((ItemGun)stack.getItem()).hasAttachment(stack, MainRegistry.content().ironSights.getName());
  134.  
  135. multiplier *= multiplier;
  136. if (isIronsight) {
  137. multiplier *= 0.05F;
  138. }
  139. fov *= (1.0F - multiplier * 0.8F);
  140. }
  141. else
  142. {
  143. this.isZoomed = false;
  144. this.scopeTime = -1;
  145. if (this.lastPerspective != -1)
  146. {
  147. Minecraft.getMinecraft().gameSettings.thirdPersonView = this.lastPerspective;
  148. this.lastPerspective = -1;
  149. }
  150. }
  151. event.newfov = fov;
  152. }
  153.  
  154. @Deprecated
  155. public float tickScope(EntityPlayerSP player, ItemStack stack, ItemGun item, float fov)
  156. {
  157. if (this.isZoomed)
  158. {
  159. this.scopeTime += 1;
  160. if (this.lastPerspective == -1) {
  161. this.lastPerspective = Minecraft.getMinecraft().gameSettings.thirdPersonView;
  162. }
  163. if (Minecraft.getMinecraft().gameSettings.thirdPersonView != 0) {
  164. Minecraft.getMinecraft().gameSettings.thirdPersonView = 0;
  165. }
  166. if ((stack == null) || (item == null) || (!item.canUseScope(stack)))
  167. {
  168. this.isZoomed = false;
  169. return fov;
  170. }
  171. float f = fov;
  172. boolean isAcog = item.hasAttachment(stack, MainRegistry.content().ironSights.getName());
  173. if (player.capabilities.isFlying) {
  174. f *= 1.1F;
  175. }
  176. f *= (player.moveForward * player.moveForward + 1.0F) / 2.0F;
  177. if ((player.isUsingItem()) && (player.getItemInUse().isItemEqual(stack)))
  178. {
  179. int i = stack.getItem().getMaxItemUseDuration(stack);
  180. float f1 = i / 20.0F;
  181. if (f1 > 1.0F) {
  182. f1 = 1.0F;
  183. } else {
  184. f1 *= f1;
  185. }
  186. f *= (1.0F - f1 * 0.15F);
  187. }
  188. float fovModifierHand = fov;
  189. fovModifierHand += (f - fovModifierHand) * 0.5F;
  190. if (fovModifierHand > 1.5F) {
  191. fovModifierHand = 1.5F;
  192. }
  193. if (fovModifierHand < 0.1F) {
  194. fovModifierHand = 0.1F;
  195. }
  196. if (isAcog) {
  197. fovModifierHand *= 4.0F;
  198. }
  199. return fovModifierHand;
  200. }
  201. if (this.lastPerspective != -1)
  202. {
  203. Minecraft.getMinecraft().gameSettings.thirdPersonView = this.lastPerspective;
  204. this.lastPerspective = -1;
  205. }
  206. if (this.scopeTime > 0) {
  207. this.scopeTime = -1;
  208. }
  209. return fov;
  210. }
  211.  
  212. public void drawCenteredString(FontRenderer par1FontRenderer, String par2Str, int par3, int par4, int par5)
  213. {
  214. par1FontRenderer.drawStringWithShadow(par2Str, par3 - par1FontRenderer.getStringWidth(par2Str) / 2, par4, par5);
  215. }
  216. }
Add Comment
Please, Sign In to add comment