diff --git a/run/ModularWarfare/prototype/assets/modularwarfare/lang/en_US.lang b/run/ModularWarfare/prototype/assets/modularwarfare/lang/en_US.lang index 6ed30241..c12bd383 100644 --- a/run/ModularWarfare/prototype/assets/modularwarfare/lang/en_US.lang +++ b/run/ModularWarfare/prototype/assets/modularwarfare/lang/en_US.lang @@ -58,9 +58,9 @@ item.prototype.tactical_vest_lv1_tan.name=Tactical Vest Lv.1 item.prototype.tactical_vest_lv2_black.name=Tactical Vest Lv.2 item.prototype.tactical_vest_lv2_green.name=Tactical Vest Lv.2 item.prototype.tactical_vest_lv2_tan.name=Tactical Vest Lv.2 -item.prototype.uniform_chest.name=Uniform Chest -item.prototype.uniform_feet.name=Uniform Boots item.prototype.uniform_legs.name=Uniform Pants +item.prototype.uniform_feet.name=Uniform Boots +item.prototype.uniform_chest.name=Uniform Chest item.prototype.vest.name=Vest item.prototype.12gauge.name=12 Gauge Shell item.prototype.12sluggauge.name=12 Slug Gauge Shot diff --git a/src/main/java/com/modularwarfare/client/ClientEventHandler.java b/src/main/java/com/modularwarfare/client/ClientEventHandler.java index c9061688..33de9c80 100644 --- a/src/main/java/com/modularwarfare/client/ClientEventHandler.java +++ b/src/main/java/com/modularwarfare/client/ClientEventHandler.java @@ -2,6 +2,7 @@ import com.modularwarfare.ModConfig; import com.modularwarfare.ModularWarfare; +import com.modularwarfare.client.hud.FlashSystem; import com.modularwarfare.client.model.InstantBulletRenderer; import com.modularwarfare.common.init.ModSounds; import com.modularwarfare.common.network.PacketOpenGui; @@ -48,8 +49,8 @@ public void onPlaySound(PlaySoundEvent event) { Minecraft mc = Minecraft.getMinecraft(); final ResourceLocation currentSound = event.getSound().getSoundLocation(); - if (ClientRenderHooks.flashValue > 0 && !event.getSound().getSoundLocation().toString().contains("stun") && !event.getSound().getSoundLocation().toString().contains("flashed")) { - event.setResultSound(new PositionedSoundRecord(currentSound, event.getSound().getCategory(), 0.05f, 1.0f - ((float) ClientRenderHooks.flashValue / 50), false, 0, ISound.AttenuationType.LINEAR, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF()) {{ + if (FlashSystem.flashValue > 0 && !event.getSound().getSoundLocation().toString().contains("stun") && !event.getSound().getSoundLocation().toString().contains("flashed")) { + event.setResultSound(new PositionedSoundRecord(currentSound, event.getSound().getCategory(), 0.05f, 1.0f - ((float) FlashSystem.flashValue / 50), false, 0, ISound.AttenuationType.LINEAR, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF()) {{ }}); } @@ -58,45 +59,45 @@ public void onPlaySound(PlaySoundEvent event) { } if (currentSound.toString().equals("minecraft:block.grass.step")) { if (mc.player.isSprinting()) { - event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_GRASS_SPRINT, SoundCategory.BLOCKS, (ClientRenderHooks.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (ClientRenderHooks.flashValue > 0) ? 1.0f - ((float) ClientRenderHooks.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); + event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_GRASS_SPRINT, SoundCategory.BLOCKS, (FlashSystem.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (FlashSystem.flashValue > 0) ? 1.0f - ((float) FlashSystem.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); } else { - event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_GRASS_WALK, SoundCategory.BLOCKS, (ClientRenderHooks.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (ClientRenderHooks.flashValue > 0) ? 1.0f - ((float) ClientRenderHooks.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); + event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_GRASS_WALK, SoundCategory.BLOCKS, (FlashSystem.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (FlashSystem.flashValue > 0) ? 1.0f - ((float) FlashSystem.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); } } else if (currentSound.toString().equals("minecraft:block.stone.step")) { if (mc.player.isSprinting()) { - event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_STONE_SPRINT, SoundCategory.BLOCKS, (ClientRenderHooks.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (ClientRenderHooks.flashValue > 0) ? 1.0f - ((float) ClientRenderHooks.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); + event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_STONE_SPRINT, SoundCategory.BLOCKS, (FlashSystem.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (FlashSystem.flashValue > 0) ? 1.0f - ((float) FlashSystem.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); } else { - event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_STONE_WALK, SoundCategory.BLOCKS, (ClientRenderHooks.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (ClientRenderHooks.flashValue > 0) ? 1.0f - ((float) ClientRenderHooks.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); + event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_STONE_WALK, SoundCategory.BLOCKS, (FlashSystem.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (FlashSystem.flashValue > 0) ? 1.0f - ((float) FlashSystem.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); } } else if (currentSound.toString().equals("minecraft:block.gravel.step")) { if (mc.player.isSprinting()) { - event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_GRAVEL_SPRINT, SoundCategory.BLOCKS, (ClientRenderHooks.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (ClientRenderHooks.flashValue > 0) ? 1.0f - ((float) ClientRenderHooks.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); + event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_GRAVEL_SPRINT, SoundCategory.BLOCKS, (FlashSystem.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (FlashSystem.flashValue > 0) ? 1.0f - ((float) FlashSystem.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); } else { - event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_GRAVEL_WALK, SoundCategory.BLOCKS, (ClientRenderHooks.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (ClientRenderHooks.flashValue > 0) ? 1.0f - ((float) ClientRenderHooks.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); + event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_GRAVEL_WALK, SoundCategory.BLOCKS, (FlashSystem.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (FlashSystem.flashValue > 0) ? 1.0f - ((float) FlashSystem.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); } } else if (currentSound.toString().equals("minecraft:block.metal.step")) { if (mc.player.isSprinting()) { - event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_METAL_SPRINT, SoundCategory.BLOCKS, (ClientRenderHooks.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (ClientRenderHooks.flashValue > 0) ? 1.0f - ((float) ClientRenderHooks.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); + event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_METAL_SPRINT, SoundCategory.BLOCKS, (FlashSystem.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (FlashSystem.flashValue > 0) ? 1.0f - ((float) FlashSystem.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); } else { - event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_METAL_WALK, SoundCategory.BLOCKS, (ClientRenderHooks.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (ClientRenderHooks.flashValue > 0) ? 1.0f - ((float) ClientRenderHooks.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); + event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_METAL_WALK, SoundCategory.BLOCKS, (FlashSystem.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (FlashSystem.flashValue > 0) ? 1.0f - ((float) FlashSystem.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); } } else if (currentSound.toString().equals("minecraft:block.wood.step")) { if (mc.player.isSprinting()) { - event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_WOOD_SPRINT, SoundCategory.BLOCKS, (ClientRenderHooks.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (ClientRenderHooks.flashValue > 0) ? 1.0f - ((float) ClientRenderHooks.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); + event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_WOOD_SPRINT, SoundCategory.BLOCKS, (FlashSystem.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (FlashSystem.flashValue > 0) ? 1.0f - ((float) FlashSystem.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); } else { - event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_WOOD_WALK, SoundCategory.BLOCKS, (ClientRenderHooks.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (ClientRenderHooks.flashValue > 0) ? 1.0f - ((float) ClientRenderHooks.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); + event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_WOOD_WALK, SoundCategory.BLOCKS, (FlashSystem.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (FlashSystem.flashValue > 0) ? 1.0f - ((float) FlashSystem.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); } } else if (currentSound.toString().equals("minecraft:block.sand.step")) { if (mc.player.isSprinting()) { - event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_SAND_SPRINT, SoundCategory.BLOCKS, (ClientRenderHooks.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (ClientRenderHooks.flashValue > 0) ? 1.0f - ((float) ClientRenderHooks.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); + event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_SAND_SPRINT, SoundCategory.BLOCKS, (FlashSystem.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (FlashSystem.flashValue > 0) ? 1.0f - ((float) FlashSystem.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); } else { - event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_SAND_WALK, SoundCategory.BLOCKS, (ClientRenderHooks.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (ClientRenderHooks.flashValue > 0) ? 1.0f - ((float) ClientRenderHooks.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); + event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_SAND_WALK, SoundCategory.BLOCKS, (FlashSystem.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (FlashSystem.flashValue > 0) ? 1.0f - ((float) FlashSystem.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); } } else if (currentSound.toString().equals("minecraft:block.snow.step")) { if (mc.player.isSprinting()) { - event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_SNOW_SPRINT, SoundCategory.BLOCKS, (ClientRenderHooks.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (ClientRenderHooks.flashValue > 0) ? 1.0f - ((float) ClientRenderHooks.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); + event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_SNOW_SPRINT, SoundCategory.BLOCKS, (FlashSystem.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (FlashSystem.flashValue > 0) ? 1.0f - ((float) FlashSystem.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); } else { - event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_SNOW_WALK, SoundCategory.BLOCKS, (ClientRenderHooks.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (ClientRenderHooks.flashValue > 0) ? 1.0f - ((float) ClientRenderHooks.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); + event.setResultSound(new PositionedSoundRecord(ModSounds.STEP_SNOW_WALK, SoundCategory.BLOCKS, (FlashSystem.flashValue > 0) ? soundVolume * 0.05f : soundVolume, (FlashSystem.flashValue > 0) ? 1.0f - ((float) FlashSystem.flashValue / 50) : 1.0f, event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF())); } } } diff --git a/src/main/java/com/modularwarfare/client/ClientProxy.java b/src/main/java/com/modularwarfare/client/ClientProxy.java index 6a4af983..dab3c1f8 100644 --- a/src/main/java/com/modularwarfare/client/ClientProxy.java +++ b/src/main/java/com/modularwarfare/client/ClientProxy.java @@ -11,6 +11,7 @@ import com.modularwarfare.client.export.ItemModelExport; import com.modularwarfare.client.handler.*; import com.modularwarfare.client.hud.AttachmentUI; +import com.modularwarfare.client.hud.FlashSystem; import com.modularwarfare.client.hud.GunUI; import com.modularwarfare.client.killchat.KillFeedManager; import com.modularwarfare.client.killchat.KillFeedRender; @@ -108,6 +109,8 @@ public class ClientProxy extends CommonProxy { public static HashMap modSounds = new HashMap(); public static ScopeUtils scopeUtils; + public static FlashSystem flashImage; + public static ItemLight itemLight = new ItemLight("light"); public static ClientRenderHooks renderHooks; @@ -309,6 +312,9 @@ public void load() { this.scopeUtils = new ScopeUtils(); MinecraftForge.EVENT_BUS.register(this.scopeUtils); + this.flashImage = new FlashSystem(); + MinecraftForge.EVENT_BUS.register(this.flashImage); + this.attachmentUI = new AttachmentUI(); MinecraftForge.EVENT_BUS.register(this.attachmentUI); diff --git a/src/main/java/com/modularwarfare/client/ClientRenderHooks.java b/src/main/java/com/modularwarfare/client/ClientRenderHooks.java index 8d91fb01..b63e4716 100644 --- a/src/main/java/com/modularwarfare/client/ClientRenderHooks.java +++ b/src/main/java/com/modularwarfare/client/ClientRenderHooks.java @@ -55,8 +55,6 @@ public class ClientRenderHooks extends ForgeEvent { private Minecraft mc; private float equippedProgress = 1f, prevEquippedProgress = 1f; - public static int flashValue; - public static final ResourceLocation grenade_smoke = new ResourceLocation("modularwarfare", "textures/particles/smoke.png"); public ClientRenderHooks() { @@ -135,15 +133,6 @@ public void onWorldRenderLast(RenderWorldLastEvent event) { } } - @SubscribeEvent - public void onRenderPost(RenderGameOverlayEvent.Post event) { - Minecraft mc = Minecraft.getMinecraft(); - if(event.getType() == RenderGameOverlayEvent.ElementType.ALL) { - if (flashValue != 0) { - RenderHelperMW.renderRectAlphaComp(0, 0, mc.displayWidth, mc.displayHeight, 0xFFFFFF, ClientRenderHooks.flashValue); - } - } - } @SubscribeEvent public void renderHeldItem(RenderSpecificHandEvent event) { diff --git a/src/main/java/com/modularwarfare/client/handler/ClientTickHandler.java b/src/main/java/com/modularwarfare/client/handler/ClientTickHandler.java index 3bc49d05..2405e640 100644 --- a/src/main/java/com/modularwarfare/client/handler/ClientTickHandler.java +++ b/src/main/java/com/modularwarfare/client/handler/ClientTickHandler.java @@ -5,6 +5,7 @@ import com.modularwarfare.client.ClientRenderHooks; import com.modularwarfare.client.anim.AnimStateMachine; import com.modularwarfare.client.anim.StateEntry; +import com.modularwarfare.client.hud.FlashSystem; import com.modularwarfare.client.model.InstantBulletRenderer; import com.modularwarfare.client.model.ModelGun; import com.modularwarfare.client.model.renders.RenderParameters; @@ -211,10 +212,10 @@ public void onClientTickStart(Minecraft minecraft) { ClientProxy.gunUI.bulletSnapFade -= 0.01F; } //Client Flash Grenade - if (ClientRenderHooks.flashValue > 0) { - ClientRenderHooks.flashValue -= 2; - } else if (ClientRenderHooks.flashValue < 0) { - ClientRenderHooks.flashValue = 0; + if (FlashSystem.flashValue > 0) { + FlashSystem.flashValue -= 2; + } else if (FlashSystem.flashValue < 0) { + FlashSystem.flashValue = 0; } } diff --git a/src/main/java/com/modularwarfare/client/hud/FlashSystem.java b/src/main/java/com/modularwarfare/client/hud/FlashSystem.java new file mode 100644 index 00000000..5b159a8d --- /dev/null +++ b/src/main/java/com/modularwarfare/client/hud/FlashSystem.java @@ -0,0 +1,186 @@ +package com.modularwarfare.client.hud; + +import com.modularwarfare.ModularWarfare; +import com.modularwarfare.client.model.ModelAttachment; +import com.modularwarfare.client.scope.ScopeUtils; +import com.modularwarfare.utility.OptifineHelper; +import com.modularwarfare.utility.RenderHelperMW; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.util.math.RayTraceResult; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.GL11; + +import java.lang.reflect.Field; +import java.nio.ByteBuffer; + +public class FlashSystem { + + private static Minecraft mc = Minecraft.getMinecraft(); + + public static final int quality = 1024; + public static int FLASHED_TEX; + public static boolean hasTookScreenshot = false; + public static int flashValue; + private Field renderEndNanoTime; + + public FlashSystem() { + GL11.glPushMatrix(); + + FLASHED_TEX = GL11.glGenTextures(); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, FLASHED_TEX); + GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, quality, quality, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); + + GL11.glPopMatrix(); + try { + this.renderEndNanoTime = EntityRenderer.class.getDeclaredField("renderEndNanoTime"); + } catch (Exception ignored) { + } + if (this.renderEndNanoTime == null) try { + this.renderEndNanoTime = EntityRenderer.class.getDeclaredField("field_78534_ac"); + } catch (Exception ignored) { + } + if (this.renderEndNanoTime != null) { + this.renderEndNanoTime.setAccessible(true); + } + } + + @SubscribeEvent + public void onRenderPost(RenderGameOverlayEvent.Post event) { + Minecraft mc = Minecraft.getMinecraft(); + if(event.getType() == RenderGameOverlayEvent.ElementType.ALL) { + if (flashValue != 0) { + int width = Display.getWidth(); + int height = Display.getHeight(); + int x = 0; + int y = 0; + GL11.glPushMatrix(); + GL11.glScalef(0.5f, 0.5f,0); + + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferbuilder = tessellator.getBuffer(); + + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); + GlStateManager.color(1.0f, 1.0f, 1.0f, (FlashSystem.flashValue / 255.0F)); + GlStateManager.bindTexture(FLASHED_TEX); + bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX); + bufferbuilder.pos(x, y + height, 0.0D).tex(0.0D, 0.0D).endVertex(); + bufferbuilder.pos(x + width, y + height, 0.0D).tex(1.0D, 0.0D).endVertex(); + bufferbuilder.pos(x + width, y, 0.0D).tex(1.0D, 1.0D).endVertex(); + bufferbuilder.pos(x, y, 0.0D).tex(0.0D, 1.0D).endVertex(); + tessellator.draw(); + GlStateManager.disableBlend(); + GL11.glPopMatrix(); + RenderHelperMW.renderRectAlphaComp(0, 0, mc.displayWidth, mc.displayHeight, 0xFFFFFF, FlashSystem.flashValue); + } + } + } + + @SubscribeEvent + public void renderTick(TickEvent.RenderTickEvent event) { + if (event.phase == TickEvent.Phase.START) { + if(!hasTookScreenshot && flashValue > 0) { + GL11.glPushMatrix(); + if (mc.player != null && mc.currentScreen == null) { + if (!OptifineHelper.isShadersEnabled()) { + takeScreenShot(mc, event.renderTickTime); + } + } + GL11.glPopMatrix(); + hasTookScreenshot = true; + } + } + } + + public void takeScreenShot(Minecraft mc, float partialTick) { + float zoom = mc.gameSettings.fovSetting; + + GL11.glPushMatrix(); + + //Get the current Display and Height/Width + int width = Display.getWidth(); + int height = Display.getHeight(); + + RenderGlobal renderBackup = mc.renderGlobal; + //Save the current settings to be reset later + long endTime = 0; + int w = mc.displayWidth; + int h = mc.displayHeight; + boolean hide = mc.gameSettings.hideGUI; + int mipmapBackup = mc.gameSettings.mipmapLevels; + int view = mc.gameSettings.thirdPersonView; + int limit = mc.gameSettings.limitFramerate; + RayTraceResult mouseOver = mc.objectMouseOver; + float fov = mc.gameSettings.fovSetting; + boolean fboBackup = mc.gameSettings.fboEnable; + boolean bobbingBackup = mc.gameSettings.viewBobbing; + float mouseSensitivityBackup = mc.gameSettings.mouseSensitivity; + + //Change game settings for the Scope + mc.gameSettings.hideGUI = true; + mc.gameSettings.thirdPersonView = 0; + mc.gameSettings.mipmapLevels = 3; + mc.gameSettings.fovSetting = zoom; + mc.gameSettings.fboEnable = false; + mc.gameSettings.viewBobbing = false; + + mc.displayHeight = height; + mc.displayWidth = width; + //Make sure the FOV isn't less than 1 + if (mc.gameSettings.fovSetting < 0) { + mc.gameSettings.fovSetting = 1; + } + + if (limit != 0 && renderEndNanoTime != null) { + try { + endTime = renderEndNanoTime.getLong(mc.entityRenderer); + } catch (Exception ignored) { + } + } + + + int fps = Math.max(30, mc.gameSettings.limitFramerate); + mc.entityRenderer.renderWorld(partialTick, endTime + (1000000000 / fps)); + + GlStateManager.disableDepth(); + + //Bind mirror texture and apply the screen to it as a texture + GL11.glBindTexture(GL11.GL_TEXTURE_2D, FLASHED_TEX); + GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, 0, 0, width, height, 0); + + + if (limit != 0 && renderEndNanoTime != null) { + try { + renderEndNanoTime.setLong(mc.entityRenderer, endTime); + } catch (Exception ignored) { + } + } + + + //Go back to the original Settings + mc.objectMouseOver = mouseOver; + mc.gameSettings.limitFramerate = limit; + mc.gameSettings.thirdPersonView = view; + mc.gameSettings.hideGUI = hide; + mc.gameSettings.mipmapLevels = mipmapBackup; + mc.displayWidth = w; + mc.displayHeight = h; + mc.gameSettings.fboEnable = fboBackup; + mc.gameSettings.viewBobbing = bobbingBackup; + mc.gameSettings.mouseSensitivity = mouseSensitivityBackup; + + mc.gameSettings.fovSetting = fov; + mc.renderGlobal = renderBackup; + + + GL11.glPopMatrix(); + } + +} diff --git a/src/main/java/com/modularwarfare/client/model/renders/RenderItemLoot.java b/src/main/java/com/modularwarfare/client/model/renders/RenderItemLoot.java index 50fa076a..603fcd1f 100644 --- a/src/main/java/com/modularwarfare/client/model/renders/RenderItemLoot.java +++ b/src/main/java/com/modularwarfare/client/model/renders/RenderItemLoot.java @@ -104,7 +104,6 @@ public void doRender(final EntityItemLoot entity, final double x, final double y GlStateManager.rotate(entity.rotationPitch, 1, 0, 0.0F); GlStateManager.translate(0, -height, 0); - ItemGun gun = (ItemGun) itemstack.getItem(); GunType gunType = gun.type; ModelGun model = (ModelGun) gunType.model; @@ -183,12 +182,12 @@ public void doRender(final EntityItemLoot entity, final double x, final double y GlStateManager.popMatrix(); } + GlStateManager.popMatrix(); GlStateManager.popMatrix(); GlStateManager.disableRescaleNormal(); GlStateManager.disableBlend(); } else { - int i; if (itemstack != null && itemstack.getItem() != null) { i = Item.getIdFromItem(itemstack.getItem()) + itemstack.getMetadata(); diff --git a/src/main/java/com/modularwarfare/common/guns/ItemGun.java b/src/main/java/com/modularwarfare/common/guns/ItemGun.java index d47aeeda..5d1f8ede 100644 --- a/src/main/java/com/modularwarfare/common/guns/ItemGun.java +++ b/src/main/java/com/modularwarfare/common/guns/ItemGun.java @@ -383,6 +383,9 @@ public void fireServer(EntityPlayer entityPlayer, float rotationPitch, float rot } else { if (!world.isRemote) { if (rayTrace.rayTraceResult != null) { + if (rayTrace.rayTraceResult.entityHit instanceof EntityGrenade) { + ((EntityGrenade)rayTrace.rayTraceResult.entityHit).explode(); + } if (rayTrace.rayTraceResult.entityHit instanceof EntityLivingBase) { final EntityLivingBase victim = (EntityLivingBase) ((BulletHit) rayTrace).rayTraceResult.entityHit; if (victim != null) { @@ -399,10 +402,6 @@ public void fireServer(EntityPlayer entityPlayer, float rotationPitch, float rot gunType.playSoundPos(blockPos, world, WeaponSoundType.Crack, entityPlayer, 1.0f); doHit(rayTrace.rayTraceResult, entityPlayer); } - if (rayTrace.rayTraceResult.entityHit instanceof EntityGrenade) { - ((EntityGrenade)rayTrace.rayTraceResult.entityHit).explode(); - } - } } } @@ -771,7 +770,7 @@ public int getMaxItemUseDuration(ItemStack p_77626_1_) { @Override public EnumAction getItemUseAction(ItemStack p_77661_1_) { - return EnumAction.BLOCK; + return EnumAction.NONE; } @Override diff --git a/src/main/java/com/modularwarfare/common/network/PacketFlashClient.java b/src/main/java/com/modularwarfare/common/network/PacketFlashClient.java index 8e29a697..33777426 100644 --- a/src/main/java/com/modularwarfare/common/network/PacketFlashClient.java +++ b/src/main/java/com/modularwarfare/common/network/PacketFlashClient.java @@ -1,6 +1,6 @@ package com.modularwarfare.common.network; -import com.modularwarfare.client.ClientRenderHooks; +import com.modularwarfare.client.hud.FlashSystem; import com.modularwarfare.common.init.ModSounds; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; @@ -41,13 +41,14 @@ public void handleClientSide(EntityPlayer entityPlayer) { //Minecraft.getMinecraft().getSoundHandler().stopSounds(); - ClientRenderHooks.flashValue += this.flashAmount; - Minecraft.getMinecraft().getSoundHandler().playSound(new PositionedSoundRecord(ModSounds.FLASHED, SoundCategory.PLAYERS, (float) ClientRenderHooks.flashValue / 1000, 1, (float) entityPlayer.posX, (float) entityPlayer.posY, (float) entityPlayer.posZ)); + FlashSystem.hasTookScreenshot = false; + FlashSystem.flashValue += this.flashAmount; + Minecraft.getMinecraft().getSoundHandler().playSound(new PositionedSoundRecord(ModSounds.FLASHED, SoundCategory.PLAYERS, (float) FlashSystem.flashValue / 1000, 1, (float) entityPlayer.posX, (float) entityPlayer.posY, (float) entityPlayer.posZ)); Minecraft.getMinecraft().getSoundHandler().playSound(new PositionedSoundRecord(ModSounds.FLASHED, SoundCategory.PLAYERS, 5.0f, 0.2f, (float) entityPlayer.posX, (float) entityPlayer.posY, (float) entityPlayer.posZ)); Minecraft.getMinecraft().getSoundHandler().playSound(new PositionedSoundRecord(ModSounds.FLASHED, SoundCategory.PLAYERS, 5.0f, 0.1f, (float) entityPlayer.posX, (float) entityPlayer.posY, (float) entityPlayer.posZ)); - if (ClientRenderHooks.flashValue > 255) { - ClientRenderHooks.flashValue = 255; + if (FlashSystem.flashValue > 255) { + FlashSystem.flashValue = 255; } } } diff --git a/src/main/java/com/modularwarfare/utility/RenderHelperMW.java b/src/main/java/com/modularwarfare/utility/RenderHelperMW.java index e9f1b52b..73c1535e 100644 --- a/src/main/java/com/modularwarfare/utility/RenderHelperMW.java +++ b/src/main/java/com/modularwarfare/utility/RenderHelperMW.java @@ -840,4 +840,26 @@ public static void renderSmoke(ResourceLocation par1, double par2, double par3, GL11.glPopMatrix(); } + + public static void renderRectFlash(double x, double y, double width, double height) { + + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferbuilder = tessellator.getBuffer(); + + GL11.glEnable(3042); + GL11.glEnable(2832); + GL11.glHint(3153, 4353); + + bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX); + + bufferbuilder.pos(x, y + height, 0.0D).tex(0.0D, 1.0D).endVertex(); + bufferbuilder.pos(x + width, y + height, 0.0D).tex(1.0D, 1.0D).endVertex(); + bufferbuilder.pos(x + width, y, 0.0D).tex(1.0D, 0.0D).endVertex(); + bufferbuilder.pos(x, y, 0.0D).tex(0.0D, 0.0D).endVertex(); + + tessellator.draw(); + + GL11.glDisable(3042); + GL11.glDisable(2832); + } }