From c58981df168ac4d40aec2fa10157b37b6fb3b9cd Mon Sep 17 00:00:00 2001 From: LemADEC Date: Sun, 23 Apr 2017 13:10:23 +0200 Subject: [PATCH] Added breathing alarms and air level to HUD Fixed empty air canister returning no storage capacity Fixed minor inconsistency in breathing API --- .../java/cr0s/warpdrive/BreathingManager.java | 165 +++++++++++++----- src/main/java/cr0s/warpdrive/WarpDrive.java | 5 +- .../cr0s/warpdrive/api/IAirContainerItem.java | 2 +- .../warpdrive/item/ItemAirCanisterFull.java | 13 +- .../cr0s/warpdrive/item/ItemComponent.java | 14 +- .../cr0s/warpdrive/render/RenderCommons.java | 81 +++++++++ .../warpdrive/render/RenderOverlayAir.java | 105 +++++++++++ .../warpdrive/render/RenderOverlayCamera.java | 59 +++---- .../assets/warpdrive/lang/de_DE.lang | 5 + .../assets/warpdrive/lang/en_US.lang | 5 + .../assets/warpdrive/lang/fr_FR.lang | 5 + .../assets/warpdrive/lang/ru_RU.lang | 5 + 12 files changed, 379 insertions(+), 85 deletions(-) create mode 100644 src/main/java/cr0s/warpdrive/render/RenderCommons.java create mode 100644 src/main/java/cr0s/warpdrive/render/RenderOverlayAir.java diff --git a/src/main/java/cr0s/warpdrive/BreathingManager.java b/src/main/java/cr0s/warpdrive/BreathingManager.java index 7f8ad31e..34b9f1c3 100644 --- a/src/main/java/cr0s/warpdrive/BreathingManager.java +++ b/src/main/java/cr0s/warpdrive/BreathingManager.java @@ -110,37 +110,24 @@ public class BreathingManager { } // damage entity if in vacuum without protection - final ItemStack itemStackHelmet = entityLivingBase.getEquipmentInSlot(4); - final ItemStack itemStackChestplate = entityLivingBase.getEquipmentInSlot(3); - final ItemStack itemStackLeggings = entityLivingBase.getEquipmentInSlot(2); - final ItemStack itemStackBoots = entityLivingBase.getEquipmentInSlot(1); + final boolean hasValidSetup = hasValidSetup(entityLivingBase); if (entityLivingBase instanceof EntityPlayerMP) { EntityPlayerMP player = (EntityPlayerMP) entityLivingBase; air = player_airTank.get(uuidEntity); - boolean hasHelmet = false; - // need full armor set to breath - if ( itemStackHelmet != null - && itemStackChestplate != null - && itemStackLeggings != null - && itemStackBoots != null ) { - // need a working breathing helmet to breath - Item itemHelmet = itemStackHelmet.getItem(); - if ( (itemHelmet instanceof IBreathingHelmet && ((IBreathingHelmet) itemHelmet).canBreath(entityLivingBase)) - || Dictionary.ITEMS_BREATHING_HELMET.contains(itemHelmet) ) { - hasHelmet = true; - if (air == null) {// new player in space => grace period - player_airTank.put(uuidEntity, AIR_FIRST_BREATH_TICKS); - } else if (air <= 1) { - int ticksAir = consumeAir(player); - if (ticksAir > 0) { - player_airTank.put(uuidEntity, ticksAir); - } else { - hasHelmet = false; - } + boolean hasHelmet = hasValidSetup; + if (hasValidSetup) { + if (air == null) {// new player in space => grace period + player_airTank.put(uuidEntity, AIR_FIRST_BREATH_TICKS); + } else if (air <= 1) { + int ticksAir = consumeAir(player); + if (ticksAir > 0) { + player_airTank.put(uuidEntity, ticksAir); } else { - player_airTank.put(uuidEntity, air - 1); + hasHelmet = false; } + } else { + player_airTank.put(uuidEntity, air - 1); } } @@ -156,18 +143,9 @@ public class BreathingManager { } } else {// (in space, no air block and not a player) - // need just a working breathing helmet to breath - if (itemStackHelmet != null) { - final Item itemHelmet = itemStackHelmet.getItem(); - if ( (itemHelmet instanceof IBreathingHelmet && ((IBreathingHelmet) itemHelmet).canBreath(entityLivingBase)) - || Dictionary.ITEMS_BREATHING_HELMET.contains(itemHelmet) ) { - // let it live for now, checking periodically if helmet gets broken in combat - entity_airBlock.put(uuidEntity, AIR_FIRST_BREATH_TICKS); - } else { - entity_airBlock.put(uuidEntity, 0); - entityLivingBase.attackEntityFrom(WarpDrive.damageAsphyxia, 2.0F); - } - + if (hasValidSetup) { + // let it live for now, checking periodically if helmet gets broken in combat + entity_airBlock.put(uuidEntity, AIR_FIRST_BREATH_TICKS); } else { entity_airBlock.put(uuidEntity, 0); entityLivingBase.attackEntityFrom(WarpDrive.damageAsphyxia, 2.0F); @@ -176,15 +154,15 @@ public class BreathingManager { } } - static private int consumeAir(Entity entity) { + private static int consumeAir(EntityLivingBase entityLivingBase) { if (WarpDriveConfig.LOGGING_BREATHING) { WarpDrive.logger.info("Checking inventory for air reserves..."); } - if (!(entity instanceof EntityPlayerMP)) { + if (!(entityLivingBase instanceof EntityPlayerMP)) { return 0; } - EntityPlayerMP entityPlayer = (EntityPlayerMP) entity; + EntityPlayerMP entityPlayer = (EntityPlayerMP) entityLivingBase; ItemStack[] playerInventory = entityPlayer.inventory.mainInventory; int slotAirCanisterFound = -1; float fillingRatioAirCanisterFound = 0.0F; @@ -225,10 +203,10 @@ public class BreathingManager { } else { ItemStack itemStackNew = airContainerItem.consumeAir(itemStack); if (itemStack != itemStackNew) { - playerInventory[slotAirCanisterFound] = itemStack; + playerInventory[slotAirCanisterFound] = itemStackNew; } } - return airContainerItem.airTicksPerConsumption(itemStack); + return airContainerItem.getAirTicksPerConsumption(itemStack); } } } @@ -262,13 +240,110 @@ public class BreathingManager { if (itemStackChestplate != null) { final Item itemChestplate = itemStackChestplate.getItem(); if (itemChestplate == WarpDrive.itemWarpArmor[1]) { - return electrolyseIceToAir(entity); + return electrolyseIceToAir(entityLivingBase); } } return 0; } - static private int electrolyseIceToAir(Entity entity) { + public static boolean hasValidSetup(EntityLivingBase entityLivingBase) { + final ItemStack itemStackHelmet = entityLivingBase.getEquipmentInSlot(4); + if (entityLivingBase instanceof EntityPlayer) { + final ItemStack itemStackChestplate = entityLivingBase.getEquipmentInSlot(3); + final ItemStack itemStackLeggings = entityLivingBase.getEquipmentInSlot(2); + final ItemStack itemStackBoots = entityLivingBase.getEquipmentInSlot(1); + // need full armor set to breath + if ( itemStackHelmet != null + && itemStackChestplate != null + && itemStackLeggings != null + && itemStackBoots != null) { + // need a working breathing helmet to breath + final Item itemHelmet = itemStackHelmet.getItem(); + return (itemHelmet instanceof IBreathingHelmet && ((IBreathingHelmet) itemHelmet).canBreath(entityLivingBase)) + || Dictionary.ITEMS_BREATHING_HELMET.contains(itemHelmet); + } + + } else { + // need just a working breathing helmet to breath + if (itemStackHelmet != null) { + final Item itemHelmet = itemStackHelmet.getItem(); + return (itemHelmet instanceof IBreathingHelmet && ((IBreathingHelmet) itemHelmet).canBreath(entityLivingBase)) + || Dictionary.ITEMS_BREATHING_HELMET.contains(itemHelmet); + } + } + return false; + } + + public static float getAirReserveRatio(EntityPlayer entityPlayer) { + ItemStack[] playerInventory = entityPlayer.inventory.mainInventory; + + // check electrolysing + boolean canElectrolyse = false; + final ItemStack itemStackChestplate = entityPlayer.getCurrentArmor(2); + if (itemStackChestplate != null) { + final Item itemChestplate = itemStackChestplate.getItem(); + if (itemChestplate == WarpDrive.itemWarpArmor[1]) { + canElectrolyse = true; + } + } + + // check all inventory slots for air containers, etc. + final Item itemIce = Item.getItemFromBlock(Blocks.ice); + int sumAirCapacityTicks = 0; + int sumAirStoredTicks = 0; + int countAirContainer = 0; + int countIce = 0; + int countEnergy = 0; + ItemStack itemStackAirContainer = null; + for (int slotIndex = 0; slotIndex < playerInventory.length; slotIndex++) { + final ItemStack itemStack = playerInventory[slotIndex]; + if (itemStack != null) { + if (itemStack.getItem() instanceof IAirContainerItem) { + countAirContainer++; + itemStackAirContainer = itemStack; + final IAirContainerItem airContainerItem = (IAirContainerItem) itemStack.getItem(); + final int airAvailable = airContainerItem.getCurrentAirStorage(itemStack); + if (airAvailable > 0) { + sumAirStoredTicks += airAvailable * airContainerItem.getAirTicksPerConsumption(itemStack); + } + final int airCapacity = airContainerItem.getMaxAirStorage(itemStack); + sumAirCapacityTicks += airCapacity * airContainerItem.getAirTicksPerConsumption(itemStack); + + } else if (WarpDriveConfig.IC2_compressedAir != null && itemStack.isItemEqual(WarpDriveConfig.IC2_compressedAir)) { + sumAirStoredTicks += AIR_IC2_COMPRESSED_AIR_TICKS; + sumAirCapacityTicks += AIR_IC2_COMPRESSED_AIR_TICKS; + + } else if (WarpDriveConfig.IC2_emptyCell != null && itemStack.isItemEqual(WarpDriveConfig.IC2_emptyCell)) { + sumAirCapacityTicks += AIR_IC2_COMPRESSED_AIR_TICKS; + + } else if (canElectrolyse) { + if (itemStack.getItem() == itemIce) { + countIce += itemStack.stackSize; + } else if ( ItemEnergyWrapper.isEnergyContainer(itemStack) + && ItemEnergyWrapper.canOutput(itemStack) + && ItemEnergyWrapper.getEnergyStored(itemStack) >= AIR_ENERGY_FOR_ELECTROLYSE ) { + countEnergy += Math.floor(ItemEnergyWrapper.getEnergyStored(itemStack) / AIR_ENERGY_FOR_ELECTROLYSE); + } + } + } + } + + // add electrolyse bonus + if (countAirContainer >= 1 && countIce > 0 && countEnergy > 0 && itemStackAirContainer.getItem() instanceof IAirContainerItem) { + IAirContainerItem airContainerItem = (IAirContainerItem) itemStackAirContainer.getItem(); + final int sumElectrolyseTicks = + Math.min(2, countAirContainer) // up to 2 containers refilled + * Math.min(countIce, countEnergy) // requiring both ice and energy + * airContainerItem.getMaxAirStorage(itemStackAirContainer) + * airContainerItem.getAirTicksPerConsumption(itemStackAirContainer); + sumAirStoredTicks += sumElectrolyseTicks; + sumAirCapacityTicks += sumElectrolyseTicks; + } + + return sumAirCapacityTicks > 0 ? sumAirStoredTicks / (float) sumAirCapacityTicks : 0.0F; + } + + private static int electrolyseIceToAir(Entity entity) { if (WarpDriveConfig.LOGGING_BREATHING) { WarpDrive.logger.info("Checking inventory for ice electrolysing..."); } @@ -348,7 +423,7 @@ public class BreathingManager { entityPlayer.sendContainerToPlayer(entityPlayer.inventoryContainer); // first air breath is free - return airCanister.airTicksPerConsumption(itemStackAirCanister); + return airCanister.getAirTicksPerConsumption(itemStackAirCanister); } } diff --git a/src/main/java/cr0s/warpdrive/WarpDrive.java b/src/main/java/cr0s/warpdrive/WarpDrive.java index d514cb26..f40630f3 100644 --- a/src/main/java/cr0s/warpdrive/WarpDrive.java +++ b/src/main/java/cr0s/warpdrive/WarpDrive.java @@ -127,6 +127,7 @@ import cr0s.warpdrive.network.PacketHandler; import cr0s.warpdrive.render.ClientCameraHandler; import cr0s.warpdrive.render.RenderBlockForceField; import cr0s.warpdrive.render.RenderBlockStandard; +import cr0s.warpdrive.render.RenderOverlayAir; import cr0s.warpdrive.render.RenderOverlayCamera; import cr0s.warpdrive.world.BiomeSpace; import cr0s.warpdrive.world.HyperSpaceWorldGenerator; @@ -143,7 +144,6 @@ import com.mojang.authlib.GameProfile; import net.minecraft.block.Block; import net.minecraft.block.BlockColored; -import net.minecraft.client.Minecraft; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemArmor; @@ -294,7 +294,8 @@ public class WarpDrive implements LoadingCallback { RecipeSorter.register("warpdrive:tuningDriver", RecipeTuningDriver.class, RecipeSorter.Category.SHAPELESS, "before:minecraft:shapeless"); if (FMLCommonHandler.instance().getSide().isClient()) { - MinecraftForge.EVENT_BUS.register(new RenderOverlayCamera(Minecraft.getMinecraft())); + MinecraftForge.EVENT_BUS.register(new RenderOverlayAir()); + MinecraftForge.EVENT_BUS.register(new RenderOverlayCamera()); FMLCommonHandler.instance().bus().register(new ClientCameraHandler()); diff --git a/src/main/java/cr0s/warpdrive/api/IAirContainerItem.java b/src/main/java/cr0s/warpdrive/api/IAirContainerItem.java index 88fcc37e..cd484c4b 100644 --- a/src/main/java/cr0s/warpdrive/api/IAirContainerItem.java +++ b/src/main/java/cr0s/warpdrive/api/IAirContainerItem.java @@ -17,7 +17,7 @@ public interface IAirContainerItem { ItemStack consumeAir(ItemStack itemStack); // Return duration of air for a single call to consumeAir(). Defaults to 300 ticks. - int airTicksPerConsumption(ItemStack itemStack); + int getAirTicksPerConsumption(ItemStack itemStack); // Return an empty air container ItemStack getEmptyAirContainer(ItemStack itemStack); diff --git a/src/main/java/cr0s/warpdrive/item/ItemAirCanisterFull.java b/src/main/java/cr0s/warpdrive/item/ItemAirCanisterFull.java index 67f0083a..f12858dc 100644 --- a/src/main/java/cr0s/warpdrive/item/ItemAirCanisterFull.java +++ b/src/main/java/cr0s/warpdrive/item/ItemAirCanisterFull.java @@ -42,11 +42,16 @@ public class ItemAirCanisterFull extends Item implements IAirContainerItem { @Override public int getMaxAirStorage(ItemStack itemStack) { - if ( itemStack == null - || itemStack.getItem() != this ) { + if (itemStack == null) { return 0; } - return itemStack.getMaxDamage(); + if (itemStack.getItem() == this) { + return itemStack.getMaxDamage(); + } + if (itemStack.getItem() == WarpDrive.itemComponent) { + return 20; // @TODO add proper empty air canister item + } + return 0; } @Override @@ -72,7 +77,7 @@ public class ItemAirCanisterFull extends Item implements IAirContainerItem { } @Override - public int airTicksPerConsumption(ItemStack itemStack) { + public int getAirTicksPerConsumption(ItemStack itemStack) { return 300; } diff --git a/src/main/java/cr0s/warpdrive/item/ItemComponent.java b/src/main/java/cr0s/warpdrive/item/ItemComponent.java index ba9ac806..c21c1992 100644 --- a/src/main/java/cr0s/warpdrive/item/ItemComponent.java +++ b/src/main/java/cr0s/warpdrive/item/ItemComponent.java @@ -86,7 +86,11 @@ public class ItemComponent extends Item implements IAirContainerItem { @Override public int getMaxAirStorage(ItemStack itemStack) { - return 0; + if (canContainAir(itemStack)) { + return WarpDrive.itemAirCanisterFull.getMaxAirStorage(itemStack); + } else { + return 0; + } } @Override @@ -101,8 +105,12 @@ public class ItemComponent extends Item implements IAirContainerItem { } @Override - public int airTicksPerConsumption(ItemStack itemStack) { - return 0; + public int getAirTicksPerConsumption(ItemStack itemStack) { + if (canContainAir(itemStack)) { + return WarpDrive.itemAirCanisterFull.getAirTicksPerConsumption(itemStack); + } else { + return 0; + } } @Override diff --git a/src/main/java/cr0s/warpdrive/render/RenderCommons.java b/src/main/java/cr0s/warpdrive/render/RenderCommons.java new file mode 100644 index 00000000..f8879421 --- /dev/null +++ b/src/main/java/cr0s/warpdrive/render/RenderCommons.java @@ -0,0 +1,81 @@ +package cr0s.warpdrive.render; + +import cr0s.warpdrive.Commons; + +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.util.StatCollector; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class RenderCommons { + + private static final Minecraft minecraft = Minecraft.getMinecraft(); + + protected static int colorGradient(final float gradient, final int start, final int end) { + return Math.max(0, Math.min(255, start + Math.round(gradient * (end - start)))); + } + + protected static int colorARGBtoInt(final int alpha, final int red, final int green, final int blue) { + return (Commons.clamp(0, 255, alpha) << 24) + + (Commons.clamp(0, 255, red ) << 16) + + (Commons.clamp(0, 255, green) << 8) + + Commons.clamp(0, 255, blue ); + } + + // from net.minecraft.client.gui.Gui + private static final float scaleUV = 0.00390625F; // 1/256 + protected static void drawTexturedModalRect(final int x, final int y, final int u, final int v, final int sizeX, final int sizeY, final int zLevel) { + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV( x , (y + sizeY), zLevel, scaleUV * u , scaleUV * (v + sizeY)); + tessellator.addVertexWithUV((x + sizeX), (y + sizeY), zLevel, scaleUV * (u + sizeX), scaleUV * (v + sizeY)); + tessellator.addVertexWithUV((x + sizeX), y , zLevel, scaleUV * (u + sizeX), scaleUV * v ); + tessellator.addVertexWithUV( x , y , zLevel, scaleUV * u , scaleUV * v ); + tessellator.draw(); + } + + public static int drawSplashAlarm(final int scaledWidth, final int scaledHeight, final String title, final String message) { + // compute animation clock + final double cycle = ((System.nanoTime() / 1000) % 0x200000) / (double) 0x200000; + + // start rendering + GL11.glPushMatrix(); + GL11.glScalef(2.0F, 2.0F, 0.0F); + + int y = scaledHeight / 10; + + // bold title, single line, centered, with shadows + final String textTitle = "§l" + StatCollector.translateToLocal(title); + minecraft.fontRenderer.drawString(textTitle, + scaledWidth / 4 - minecraft.fontRenderer.getStringWidth(textTitle) / 2, + y - minecraft.fontRenderer.FONT_HEIGHT, + colorARGBtoInt(230, 255, 32, 24), + true); + + // normal message, multi-lines, centered, without shadows + final String textMessage = StatCollector.translateToLocal(message).replace("\\n", "\n"); + final int alpha = 160 + (int) (85.0D * Math.sin(cycle * 2 * Math.PI)); + + @SuppressWarnings("unchecked") + final List listMessages = minecraft.fontRenderer.listFormattedStringToWidth(textMessage, scaledWidth / 2); + for (final String textLine : listMessages) { + minecraft.fontRenderer.drawString(textLine, + scaledWidth / 4 - minecraft.fontRenderer.getStringWidth(textLine) / 2, + y, + colorARGBtoInt(alpha, 192, 64, 48), + false); + y += minecraft.fontRenderer.FONT_HEIGHT; + } + + // close rendering + GL11.glPopMatrix(); + return alpha; + } +} \ No newline at end of file diff --git a/src/main/java/cr0s/warpdrive/render/RenderOverlayAir.java b/src/main/java/cr0s/warpdrive/render/RenderOverlayAir.java new file mode 100644 index 00000000..4b3836c1 --- /dev/null +++ b/src/main/java/cr0s/warpdrive/render/RenderOverlayAir.java @@ -0,0 +1,105 @@ +package cr0s.warpdrive.render; + +import cr0s.warpdrive.BreathingManager; +import cr0s.warpdrive.data.CelestialObject; +import cr0s.warpdrive.data.StarMapRegistry; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.MathHelper; +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraftforge.client.GuiIngameForge; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; + +@SideOnly(Side.CLIENT) +public class RenderOverlayAir { + + private static Minecraft minecraft = Minecraft.getMinecraft(); + + private static float ratioPreviousAir = 1.0F; + private static long timePreviousAir = 0; + + private void renderAir(final int width, final int height) { + // get player + EntityPlayer entityPlayer = minecraft.thePlayer; + if (entityPlayer == null) { + return; + } + final int x = MathHelper.floor_double(entityPlayer.posX); + final int z = MathHelper.floor_double(entityPlayer.posZ); + + // get celestial object + final CelestialObject celestialObject = StarMapRegistry.getCelestialObject(entityPlayer.dimension, x, z); + if (celestialObject.hasAtmosphere()) {// skip (no display) if environment is breathable + return; + } + + // get air stats + // final boolean hasAirBlock = BreathingManager.hasAirBlock(entityPlayer, x, y, z); + final boolean hasValidSetup = BreathingManager.hasValidSetup(entityPlayer); + final float ratioAirReserve = BreathingManager.getAirReserveRatio(entityPlayer); + + // start rendering + GL11.glEnable(GL11.GL_BLEND); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + + // show splash message + int alpha = 255; + if (!hasValidSetup) { + alpha = RenderCommons.drawSplashAlarm(width, height, "warpdrive.breathing.alarm", "warpdrive.breathing.invalid_setup"); + } else if (ratioAirReserve <= 0.0F) { + alpha = RenderCommons.drawSplashAlarm(width, height, "warpdrive.breathing.alarm", "warpdrive.breathing.no_air"); + } else if (ratioAirReserve < 0.15F) { + alpha = RenderCommons.drawSplashAlarm(width, height, "warpdrive.breathing.alarm", "warpdrive.breathing.low_reserve"); + } + + // restore texture + minecraft.getTextureManager().bindTexture(Gui.icons); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + + // position right above food bar + final int left = width / 2 + 91; + final int top = height - GuiIngameForge.right_height; + + // draw animated air bubble + final long timeWorld = entityPlayer.worldObj.getTotalWorldTime(); + if (ratioAirReserve != ratioPreviousAir) { + timePreviousAir = timeWorld; + ratioPreviousAir = ratioAirReserve; + } + final long timeDelta = timeWorld - timePreviousAir; + if (timeDelta >= 0 && timeDelta <= 8) { + RenderCommons.drawTexturedModalRect(left - 9, top, 25, 18, 9, 9, 100); + } else if (timeDelta < 0 || timeDelta > 16) { + RenderCommons.drawTexturedModalRect(left - 9, top, 16, 18, 9, 9, 100); + } + + // draw air level bar + final int full = MathHelper.ceiling_double_int(ratioAirReserve * 71.0D); + RenderCommons.drawTexturedModalRect(left - 81, top + 2, 20, 84, 71, 5, 100); + if (alpha != 255) { + final float factor = 1.0F - alpha / 255.0F; + GL11.glColor4f(1.0F, 0.2F + 0.8F * factor, 0.2F + 0.8F * factor, 1.0F); + } + RenderCommons.drawTexturedModalRect(left - 10 - full, top + 2, 91 - full, 89, full, 5, 100); + + // close rendering + GuiIngameForge.right_height += 10; + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glDisable(GL11.GL_BLEND); + } + + @SubscribeEvent + public void onRender(RenderGameOverlayEvent.Pre event) { + if (event.type == ElementType.AIR) { + renderAir(event.resolution.getScaledWidth(), event.resolution.getScaledHeight()); + } + } +} \ No newline at end of file diff --git a/src/main/java/cr0s/warpdrive/render/RenderOverlayCamera.java b/src/main/java/cr0s/warpdrive/render/RenderOverlayCamera.java index 95734fa0..b8c43c01 100644 --- a/src/main/java/cr0s/warpdrive/render/RenderOverlayCamera.java +++ b/src/main/java/cr0s/warpdrive/render/RenderOverlayCamera.java @@ -9,23 +9,20 @@ import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.ResourceLocation; import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; +@SideOnly(Side.CLIENT) public class RenderOverlayCamera { - private Minecraft mc; + + private static final int ANIMATION_FRAMES = 200; + + private Minecraft minecraft = Minecraft.getMinecraft(); private int frameCount = 0; - private static int ANIMATION_FRAMES = 200; - public RenderOverlayCamera(Minecraft parMinecraft) { - mc = parMinecraft; - } - - private static int colorGradient(float gradient, int start, int end) { - return Math.max(0, Math.min(255, start + Math.round(gradient * (end - start)))); - } - - protected void renderOverlay(int scaledWidth, int scaledHeight) { + private void renderOverlay(final int scaledWidth, final int scaledHeight) { GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDepthMask(false); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); @@ -33,15 +30,15 @@ public class RenderOverlayCamera { GL11.glDisable(GL11.GL_ALPHA_TEST); try { - String strHelp; + final String strHelp; if (ClientCameraHandler.overlayType == EnumCameraType.SIMPLE_CAMERA) { - mc.getTextureManager().bindTexture(new ResourceLocation("warpdrive", "textures/blocks/detection/cameraOverlay.png")); + minecraft.getTextureManager().bindTexture(new ResourceLocation("warpdrive", "textures/blocks/detection/cameraOverlay.png")); strHelp = "Left click to zoom / Right click to exit"; } else { - mc.getTextureManager().bindTexture(new ResourceLocation("warpdrive", "textures/blocks/weapon/laserCameraOverlay.png")); + minecraft.getTextureManager().bindTexture(new ResourceLocation("warpdrive", "textures/blocks/weapon/laserCameraOverlay.png")); strHelp = "Left click to zoom / Right click to exit / Space to fire"; } - + Tessellator tessellator = Tessellator.instance; tessellator.startDrawingQuads(); tessellator.addVertexWithUV( 0.0D, scaledHeight, -90.0D, 0.0D, 1.0D); @@ -54,24 +51,26 @@ public class RenderOverlayCamera { if (frameCount >= ANIMATION_FRAMES) { frameCount = 0; } - float time = Math.abs(frameCount * 2.0F / ANIMATION_FRAMES - 1.0F); - int color = (colorGradient(time, 0x40, 0xA0) << 16) + (colorGradient(time, 0x80, 0x00) << 8) + colorGradient(time, 0x80, 0xFF); - mc.fontRenderer.drawString(strHelp, - (scaledWidth - mc.fontRenderer.getStringWidth(strHelp)) / 2, - (int)(scaledHeight * 0.19) - mc.fontRenderer.FONT_HEIGHT, - color, true); + final float time = Math.abs(frameCount * 2.0F / ANIMATION_FRAMES - 1.0F); + final int color = (RenderCommons.colorGradient(time, 0x40, 0xA0) << 16) + + (RenderCommons.colorGradient(time, 0x80, 0x00) << 8) + + RenderCommons.colorGradient(time, 0x80, 0xFF); + minecraft.fontRenderer.drawString(strHelp, + (scaledWidth - minecraft.fontRenderer.getStringWidth(strHelp)) / 2, + (int)(scaledHeight * 0.19) - minecraft.fontRenderer.FONT_HEIGHT, + color, true); - String strZoom = "Zoom " + (ClientCameraHandler.originalFOV / mc.gameSettings.fovSetting) + "x"; - mc.fontRenderer.drawString(strZoom, - (int) (scaledWidth * 0.91) - mc.fontRenderer.getStringWidth(strZoom), - (int) (scaledHeight * 0.81), - 0x40A080, true); + String strZoom = "Zoom " + (ClientCameraHandler.originalFOV / minecraft.gameSettings.fovSetting) + "x"; + minecraft.fontRenderer.drawString(strZoom, + (int) (scaledWidth * 0.91) - minecraft.fontRenderer.getStringWidth(strZoom), + (int) (scaledHeight * 0.81), + 0x40A080, true); if (WarpDriveConfig.LOGGING_CAMERA) { - mc.fontRenderer.drawString(ClientCameraHandler.overlayLoggingMessage, - (scaledWidth - mc.fontRenderer.getStringWidth(ClientCameraHandler.overlayLoggingMessage)) / 2, - (int)(scaledHeight * 0.19), - 0xFF008F, true); + minecraft.fontRenderer.drawString(ClientCameraHandler.overlayLoggingMessage, + (scaledWidth - minecraft.fontRenderer.getStringWidth(ClientCameraHandler.overlayLoggingMessage)) / 2, + (int)(scaledHeight * 0.19), + 0xFF008F, true); } } catch (Exception exception) { exception.printStackTrace(); diff --git a/src/main/resources/assets/warpdrive/lang/de_DE.lang b/src/main/resources/assets/warpdrive/lang/de_DE.lang index dbc86f78..b64f77f0 100644 --- a/src/main/resources/assets/warpdrive/lang/de_DE.lang +++ b/src/main/resources/assets/warpdrive/lang/de_DE.lang @@ -498,6 +498,11 @@ warpdrive.beam_frequency.statusLine.valid=Strahlfrequenz %1$d ist gültig. warpdrive.beam_frequency.statusLine.invalid=§cStrahlfrequenz %1$d ist ungültig. warpdrive.beam_frequency.statusLine.undefined=§7Undefinierte Strahlfrequenz.\n§bNutze eine Stimmgabel§f um die Strahlfrequenz festzulegen. +warpdrive.breathing.alarm=Breathing alarm !!! +warpdrive.breathing.invalid_setup=No breathing helmet\nor incomplete armor !!! +warpdrive.breathing.low_reserve=Low air reserve! !!! +warpdrive.breathing.no_air=No more air! !!! + warpdrive.control_channel.tooltip=Control channel is set to %1$d !!! warpdrive.control_channel.get=Control channel %2$d has been retrieved from %1$s !!! warpdrive.control_channel.set=%1$s is now tuned with Control channel %2$d !!! diff --git a/src/main/resources/assets/warpdrive/lang/en_US.lang b/src/main/resources/assets/warpdrive/lang/en_US.lang index b16b64b3..75fd9edf 100644 --- a/src/main/resources/assets/warpdrive/lang/en_US.lang +++ b/src/main/resources/assets/warpdrive/lang/en_US.lang @@ -498,6 +498,11 @@ warpdrive.beam_frequency.statusLine.valid=Beam frequency %1$d is valid. warpdrive.beam_frequency.statusLine.invalid=§cBeam frequency %1$d is invalid. warpdrive.beam_frequency.statusLine.undefined=§7Undefined beam frequency.\n§bUse a Tuning fork§r to set it. +warpdrive.breathing.alarm=Breathing alarm +warpdrive.breathing.invalid_setup=No breathing helmet\nor incomplete armor +warpdrive.breathing.low_reserve=Low air reserve! +warpdrive.breathing.no_air=No more air! + warpdrive.control_channel.tooltip=Control channel is set to %1$d warpdrive.control_channel.get=Control channel %2$d has been retrieved from %1$s warpdrive.control_channel.set=%1$s is now tuned with Control channel %2$d diff --git a/src/main/resources/assets/warpdrive/lang/fr_FR.lang b/src/main/resources/assets/warpdrive/lang/fr_FR.lang index eecf62fa..5f409707 100644 --- a/src/main/resources/assets/warpdrive/lang/fr_FR.lang +++ b/src/main/resources/assets/warpdrive/lang/fr_FR.lang @@ -498,6 +498,11 @@ warpdrive.beam_frequency.statusLine.valid=La fréquence de faisceau %1$d est val warpdrive.beam_frequency.statusLine.invalid=§cLa fréquence de faisceau %1$d est invalide. warpdrive.beam_frequency.statusLine.undefined=§7La fréquence de faisceau est non définie.\n§bUtilises un Diapason§f pour l'ajuster. +warpdrive.breathing.alarm=Alarme de respiration +warpdrive.breathing.invalid_setup=Pas de casque respiratoire\nou armure incomplète +warpdrive.breathing.low_reserve=Réserve d'air faible! +warpdrive.breathing.no_air=Réserve d'air épuisée! + warpdrive.control_channel.tooltip=Canal de contrôle ajusté à %1$d warpdrive.control_channel.get=Le canal de contrôle %2$d a été récupéré de %1$s warpdrive.control_channel.set=%1$s est désormais accordé au Canal de contrôle %2$d diff --git a/src/main/resources/assets/warpdrive/lang/ru_RU.lang b/src/main/resources/assets/warpdrive/lang/ru_RU.lang index 91d655aa..480957fb 100644 --- a/src/main/resources/assets/warpdrive/lang/ru_RU.lang +++ b/src/main/resources/assets/warpdrive/lang/ru_RU.lang @@ -499,6 +499,11 @@ warpdrive.beam_frequency.statusLine.valid=Частота луча %1$d дейс warpdrive.beam_frequency.statusLine.invalid=§cЧастота луча %1$d недействительна. warpdrive.beam_frequency.statusLine.undefined=§7Undefined beam frequency.\n§bUse a Tuning fork§r to set Beam frequency. +warpdrive.breathing.alarm=Breathing alarm +warpdrive.breathing.invalid_setup=No breathing helmet\nor incomplete armor +warpdrive.breathing.low_reserve=Low air reserve! +warpdrive.breathing.no_air=No more air! + warpdrive.control_channel.tooltip=Control channel is set to %1$d warpdrive.control_channel.get=Control channel %2$d has been retrieved from %1$s warpdrive.control_channel.set=%1$s is now tuned with Control channel %2$d