diff --git a/src/main/java/com/hbm/handler/GunConfiguration.java b/src/main/java/com/hbm/handler/GunConfiguration.java index ab7fe8cca..f771e56da 100644 --- a/src/main/java/com/hbm/handler/GunConfiguration.java +++ b/src/main/java/com/hbm/handler/GunConfiguration.java @@ -9,6 +9,8 @@ import com.hbm.render.anim.BusAnimation; import com.hbm.render.anim.HbmAnimations.AnimType; import com.hbm.render.util.RenderScreenOverlay.Crosshair; +import net.minecraft.util.ResourceLocation; + public class GunConfiguration implements Cloneable { /** @@ -32,8 +34,14 @@ public class GunConfiguration implements Cloneable { //animations! public HashMap animations = new HashMap(); - //whether ot not to disable crosshais when sneaking + //whether or not to disable crosshair when sneaking public boolean hasSights; + //texture overlay when sneaking + public ResourceLocation scopeTexture; + //whether the FOV multiplier should be absolute or additive to other modifiers, additive mode is experimental! + public boolean absoluteFOV = true; + //the target FOV/added FOV modifier when sneaking + public float zoomFOV = 0.0F; //how long the reload animation will play //MUST BE GREATER THAN ZERO ! ! ! diff --git a/src/main/java/com/hbm/handler/guncfg/Gun44MagnumFactory.java b/src/main/java/com/hbm/handler/guncfg/Gun44MagnumFactory.java index c7b3707ec..a51751b3a 100644 --- a/src/main/java/com/hbm/handler/guncfg/Gun44MagnumFactory.java +++ b/src/main/java/com/hbm/handler/guncfg/Gun44MagnumFactory.java @@ -17,6 +17,7 @@ import com.hbm.inventory.RecipesCommon.ComparableStack; import com.hbm.items.ModItems; import com.hbm.items.ItemAmmoEnums.Ammo44Magnum; import com.hbm.lib.HbmCollection; +import com.hbm.lib.RefStrings; import com.hbm.lib.HbmCollection.EnumGunManufacturer; import com.hbm.packet.AuxParticlePacketNT; import com.hbm.packet.PacketDispatcher; @@ -29,6 +30,7 @@ import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.PotionEffect; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.Vec3; public class Gun44MagnumFactory { @@ -79,6 +81,8 @@ public class Gun44MagnumFactory { return config; } + public static final ResourceLocation pips_amazing_scope_wow = new ResourceLocation(RefStrings.MODID, "textures/misc/scope_basic.png"); + public static GunConfiguration getMacintoshConfig() { GunConfiguration config = getBaseConfig(); @@ -89,6 +93,11 @@ public class Gun44MagnumFactory { config.manufacturer = EnumGunManufacturer.IF; config.comment.add("Poppin' mentats like tic tacs"); + config.hasSights = true; + config.absoluteFOV = true; + config.zoomFOV = 3F; + config.scopeTexture = pips_amazing_scope_wow; + config.config = new ArrayList(); config.config.add(BulletConfigSyncingUtil.M44_PIP); config.config.addAll(HbmCollection.fourtyFourMagBasic); diff --git a/src/main/java/com/hbm/handler/guncfg/Gun50AEFactory.java b/src/main/java/com/hbm/handler/guncfg/Gun50AEFactory.java index 7fa8c658f..fb28d5a4a 100644 --- a/src/main/java/com/hbm/handler/guncfg/Gun50AEFactory.java +++ b/src/main/java/com/hbm/handler/guncfg/Gun50AEFactory.java @@ -52,6 +52,9 @@ public class Gun50AEFactory { config.name = "deagle"; config.manufacturer = EnumGunManufacturer.MAGNUM_R_IMI; + config.absoluteFOV = true; + config.zoomFOV = 1.5F; + config.hasSights = true; config.config = HbmCollection.fiftyAE; diff --git a/src/main/java/com/hbm/main/ModEventHandlerClient.java b/src/main/java/com/hbm/main/ModEventHandlerClient.java index f375b7a72..a21dd1293 100644 --- a/src/main/java/com/hbm/main/ModEventHandlerClient.java +++ b/src/main/java/com/hbm/main/ModEventHandlerClient.java @@ -19,6 +19,7 @@ import com.hbm.entity.projectile.EntityChopperMine; import com.hbm.extprop.HbmLivingProps; import com.hbm.extprop.HbmPlayerProps; import com.hbm.handler.ArmorModHandler; +import com.hbm.handler.GunConfiguration; import com.hbm.handler.HTTPHandler; import com.hbm.handler.HazmatRegistry; import com.hbm.handler.ImpactWorldHandler; @@ -113,6 +114,7 @@ import net.minecraft.world.World; import net.minecraft.world.WorldProviderSurface; import net.minecraftforge.client.GuiIngameForge; import net.minecraftforge.client.IRenderHandler; +import net.minecraftforge.client.event.FOVUpdateEvent; import net.minecraftforge.client.event.MouseEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; @@ -219,6 +221,18 @@ public class ModEventHandlerClient { PacketDispatcher.wrapper.sendToServer(new AuxButtonPacket(0, 0, 0, 999, 0)); } + /// HANDLE SCOPE OVERLAY /// + ItemStack held = player.getHeldItem(); + + if(player.isSneaking() && held != null && held.getItem() instanceof ItemGunBase) { + GunConfiguration config = ((ItemGunBase) held.getItem()).mainConfig; + + if(config.scopeTexture != null) { + ScaledResolution resolution = event.resolution; + RenderScreenOverlay.renderScope(resolution, config.scopeTexture); + } + } + /// HANDLE FSB HUD /// ItemStack helmet = player.inventory.armorInventory[3]; @@ -327,6 +341,27 @@ public class ModEventHandlerClient { } } + @SubscribeEvent + public void setupFOV(FOVUpdateEvent event) { + + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + ItemStack held = player.getHeldItem(); + + if(held == null) return; + if(!(held.getItem() instanceof ItemGunBase)) return; + + GunConfiguration config = ((ItemGunBase) held.getItem()).mainConfig; + + if(config == null) return; + if(config.zoomFOV == 0F || !player.isSneaking()) return; + + if(config.absoluteFOV) { + event.newfov = config.zoomFOV; + } else { + event.newfov += config.zoomFOV; + } + } + public static boolean ducked = false; @SubscribeEvent diff --git a/src/main/java/com/hbm/render/item/weapon/ItemRenderOverkill.java b/src/main/java/com/hbm/render/item/weapon/ItemRenderOverkill.java index 35f7b5782..3f39188fb 100644 --- a/src/main/java/com/hbm/render/item/weapon/ItemRenderOverkill.java +++ b/src/main/java/com/hbm/render/item/weapon/ItemRenderOverkill.java @@ -6,6 +6,7 @@ import com.hbm.items.ModItems; import com.hbm.items.weapon.GunFolly; import com.hbm.items.weapon.ItemGunBase; import com.hbm.lib.RefStrings; +import com.hbm.main.MainRegistry; import com.hbm.render.model.ModelCalBarrel; import com.hbm.render.model.ModelCalDualStock; import com.hbm.render.model.ModelCalStock; @@ -83,6 +84,9 @@ public class ItemRenderOverkill implements IItemRenderer { if((Entity)data[1] instanceof EntityPlayer) f = ((EntityPlayer)data[1]).getItemInUseDuration(); + //prevent rendering when using scope + if(item.getItem() == ModItems.gun_revolver_pip && type == ItemRenderType.EQUIPPED_FIRST_PERSON && MainRegistry.proxy.me().isSneaking()) return; + switch(type) { case EQUIPPED_FIRST_PERSON: GL11.glPushMatrix(); diff --git a/src/main/java/com/hbm/render/util/RenderScreenOverlay.java b/src/main/java/com/hbm/render/util/RenderScreenOverlay.java index d4283cc03..7753457aa 100644 --- a/src/main/java/com/hbm/render/util/RenderScreenOverlay.java +++ b/src/main/java/com/hbm/render/util/RenderScreenOverlay.java @@ -5,6 +5,7 @@ import org.lwjgl.opengl.GL12; import com.hbm.extprop.HbmPlayerProps; import com.hbm.interfaces.Spaghetti; +import com.hbm.interfaces.Untested; import com.hbm.lib.RefStrings; import net.minecraft.client.Minecraft; @@ -13,6 +14,7 @@ import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -313,6 +315,46 @@ public class RenderScreenOverlay { Minecraft.getMinecraft().renderEngine.bindTexture(Gui.icons); } + @Untested + public static void renderScope(ScaledResolution res, ResourceLocation tex) { + + GL11.glEnable(GL11.GL_BLEND); + GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glDepthMask(false); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glDisable(GL11.GL_ALPHA_TEST); + + Minecraft.getMinecraft().renderEngine.bindTexture(tex); + Tessellator tess = Tessellator.instance; + + double w = res.getScaledWidth_double(); + double h = res.getScaledHeight_double(); + + double wToH = w / h; + double hToW = h / w; + + double lower = 4.5D / 16D; + double upper = 11.5D / 16D; + + double hMin = h < w ? lower : 0.5D - (9D / 32D) * hToW; + double hMax = h < w ? upper : 0.5D + (9D / 32D) * hToW; + double wMin = w < h ? lower : 0.5D - (9D / 32D) * wToH; + double wMax = w < h ? upper : 0.5D + (9D / 32D) * wToH; + + tess.startDrawingQuads(); + tess.addVertexWithUV(0, 0, 0, wMin, 1D - hMin); + tess.addVertexWithUV(w, 0, 0, wMax, 1D - hMin); + tess.addVertexWithUV(w, 0, h, wMax, 1D - hMax); + tess.addVertexWithUV(0, 0, h, wMin, 1D - hMax); + tess.draw(); + + GL11.glDepthMask(true); + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glEnable(GL11.GL_ALPHA_TEST); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + } + public enum Crosshair { NONE(0, 0, 0), diff --git a/src/main/resources/assets/hbm/textures/misc/scope_basic.png b/src/main/resources/assets/hbm/textures/misc/scope_basic.png new file mode 100644 index 000000000..4a9fa9eef Binary files /dev/null and b/src/main/resources/assets/hbm/textures/misc/scope_basic.png differ