Search in sources :

Example 1 with IScubaGear

use of net.tropicraft.core.common.item.scuba.api.IScubaGear in project Tropicraft by Tropicraft.

the class ScubaOverlayHandler method onRenderOverlay.

@SubscribeEvent
public void onRenderOverlay(RenderGameOverlayEvent.Text event) {
    // Check to see if player inventory contains dive computer
    float airRemaining = -1, airTemp, timeRemaining = 0, yaw;
    int blocksAbove, blocksBelow, currentDepth, maxDepth;
    EntityPlayer player = Minecraft.getMinecraft().player;
    FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
    ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
    ItemStack helmet = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
    if (helmet == null || !(helmet.getItem() instanceof ItemScubaHelmet)) {
        return;
    }
    ItemStack chestplate = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
    IScubaGear gear = chestplate != null ? chestplate.getCapability(ScubaCapabilities.getGearCapability(), null) : null;
    maxDepth = getTagCompound(helmet).getInteger("MaxDepth");
    blocksAbove = getTagCompound(helmet).getInteger("WaterBlocksAbove");
    blocksBelow = getTagCompound(helmet).getInteger("WaterBlocksBelow");
    if (gear != null) {
        airRemaining = gear.getTotalPressure();
        timeRemaining += getTimeRemaining(gear.getTanks().getLeft());
        timeRemaining += getTimeRemaining(gear.getTanks().getRight());
    }
    airTemp = player.world.getBiomeForCoordsBody(new BlockPos(MathHelper.floor(player.posX), 0, MathHelper.floor(player.posZ))).getTemperature(player.getPosition());
    yaw = player.rotationYaw;
    int size = 100;
    int offset = -size / 2;
    GlStateManager.pushMatrix();
    GlStateManager.translate(sr.getScaledWidth() + offset - 20, 120, 0);
    GlStateManager.rotate(yaw + 180, 0.0F, 0.0F, -1.0F);
    Minecraft.getMinecraft().getTextureManager().bindTexture(TropicraftRenderUtils.getTextureGui("compass_background"));
    drawModalRectWithCustomSizedTexture(offset, offset, 0, 0, size, size, size, size);
    GlStateManager.popMatrix();
    // TODO make locations of text configurable
    GlStateManager.pushMatrix();
    if (gear != null) {
        drawString(fr, "psi", sr.getScaledWidth() - 50, 48, 0xffffff);
        // TODO display warning if air is running low / out
        drawString(fr, "Air", sr.getScaledWidth() - 75, 34, 0xffffff);
    }
    GlStateManager.scale(1.5F, 1.5F, 1.0F);
    if (gear != null) {
        String psi = String.format("%.0f", airRemaining);
        drawString(fr, psi, (int) ((sr.getScaledWidth() - 50) / 1.5f) - fr.getStringWidth(psi) - 1, 30, 0x00ccde);
    }
    // Current depth
    drawString(fr, TropicraftRenderUtils.translateGUI("currentDepth") + ": " + blocksAbove, 4, 70, 0xbbbbff);
    GlStateManager.popMatrix();
    drawString(fr, TropicraftRenderUtils.translateGUI("maxDepth") + ": " + maxDepth, 6, 130, 0xffffffff);
    drawString(fr, (airTemp * 50) + " F", 6, 150, 0xffffffff);
    if (gear != null) {
        // TODO localize
        String timeUnits = timeRemaining <= 60 ? "secs" : "mins";
        timeRemaining = timeRemaining <= 60 ? timeRemaining : timeRemaining / 60;
        drawString(fr, TropicraftRenderUtils.translateGUI("timeRemaining"), 30, 34, 0xffffff);
        drawString(fr, String.format("%.0f %s", timeRemaining, timeUnits), 33, 45, 0xF6EB12);
    }
    GlStateManager.depthMask(true);
    GlStateManager.enableAlpha();
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
}
Also used : ScaledResolution(net.minecraft.client.gui.ScaledResolution) IScubaGear(net.tropicraft.core.common.item.scuba.api.IScubaGear) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemScubaHelmet(net.tropicraft.core.common.item.scuba.ItemScubaHelmet) BlockPos(net.minecraft.util.math.BlockPos) FontRenderer(net.minecraft.client.gui.FontRenderer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IScubaGear

use of net.tropicraft.core.common.item.scuba.api.IScubaGear in project Tropicraft by Tropicraft.

the class ItemScubaChestplateGear method addInformation.

/**
 * allows items to add custom lines of information to the mouseover description
 */
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack itemstack, @Nullable World world, List<String> tooltip, @Nonnull ITooltipFlag flagIn) {
    IScubaGear cap = itemstack.getCapability(ScubaCapabilities.getGearCapability(), null);
    ItemStack leftTank = cap.getStackInSlot(0);
    ItemStack rightTank = cap.getStackInSlot(1);
    String suitType = scubaMaterial.getDisplayName();
    tooltip.add(TextFormatting.BLUE + I18n.format("tropicraft.gui.suit.type", TextFormatting.GRAY + suitType));
    tooltip.add("");
    if (leftTank.isEmpty()) {
        tooltip.add(I18n.format("tropicraft.gui.gear.tank.left.none"));
    } else {
        tooltip.add(I18n.format("tropicraft.gui.gear.tank.left.info"));
        // IScubaTank tank = leftTank.getCapability(ScubaCapabilities.getTankCapability(), null);
        // IAirType airType = tank.getAirType();
        // String airRemaining = tank.getPressure() + " psi";
        leftTank.getItem().addInformation(leftTank, world, tooltip, flagIn);
        // list.add(TextFormatting.BLUE + I18n.format("gui.tropicraft:airType", TextFormatting.GRAY + airType.getDisplayName()));
        // list.add(TextFormatting.BLUE + I18n.format("gui.tropicraft:maxAirCapacity", TextFormatting.GRAY.toString() + airType.getMaxCapacity() + " psi"));
        // list.add(TextFormatting.BLUE + I18n.format("gui.tropicraft:airRemaining", TextFormatting.GRAY + airRemaining));
        // list.add(TextFormatting.BLUE + I18n.format("gui.tropicraft:useEfficiency", TextFormatting.GRAY, (airType.getUsageRate() * 20)));
        tooltip.add("");
    }
    if (rightTank.isEmpty()) {
        tooltip.add(I18n.format("tropicraft.gui.gear.tank.right.none"));
    } else {
        tooltip.add(I18n.format("tropicraft.gui.gear.tank.right.info"));
        // IScubaTank tank = rightTank.getCapability(ScubaCapabilities.getTankCapability(), null);
        // IAirType airType = tank.getAirType();
        // String airRemaining = tank.getPressure() + " psi";
        rightTank.getItem().addInformation(rightTank, world, tooltip, flagIn);
    // list.add(TextFormatting.BLUE + I18n.format("gui.tropicraft:airType", TextFormatting.GRAY + airType.getDisplayName()));
    // list.add(TextFormatting.BLUE + I18n.format("gui.tropicraft:maxAirCapacity", TextFormatting.GRAY.toString() + airType.getMaxCapacity() + " psi"));
    // list.add(TextFormatting.BLUE + I18n.format("gui.tropicraft:airRemaining", TextFormatting.GRAY + airRemaining));
    // list.add(TextFormatting.BLUE + I18n.format("gui.tropicraft:useEfficiency", TextFormatting.GRAY, (airType.getUsageRate() * 20)));
    }
    tooltip.add(I18n.format("tropicraft.gui.gear.tank.click"));
// list.add(TextFormatting.BLUE + I18n.format("gui.tropicraft:numTanks", TextFormatting.GRAY + numTanks));
}
Also used : IScubaGear(net.tropicraft.core.common.item.scuba.api.IScubaGear) ItemStack(net.minecraft.item.ItemStack) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with IScubaGear

use of net.tropicraft.core.common.item.scuba.api.IScubaGear in project Tropicraft by Tropicraft.

the class ModelScubaGear method renderTank.

private void renderTank(EntityLivingBase entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
    ItemStack gearStack = entityIn.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
    IScubaGear gear = gearStack.getCapability(ScubaCapabilities.getGearCapability(), null);
    TextureManager tm = Minecraft.getMinecraft().getTextureManager();
    if (gear.getTanks().getRight() != null) {
        ScubaMaterial material = gear.getStackInSlot(1).getItem() == ItemRegistry.pinkScubaTank ? ScubaMaterial.PINK : ScubaMaterial.YELLOW;
        tm.bindTexture(ItemScubaGear.getArmorTexture(material));
        Tank2.rotateAngleX = 0F;
        Tank2.rotateAngleY = 0F;
        Tank2.rotateAngleZ = 0F;
        Tank2.renderWithRotation(scale);
        Tank2m1.rotateAngleX = 0F;
        Tank2m1.rotateAngleY = 0F;
        Tank2m1.rotateAngleZ = 0F;
        Tank2m1.renderWithRotation(scale);
        Tank2m2.rotateAngleX = 0F;
        Tank2m2.rotateAngleY = -1.570796F;
        Tank2m2.rotateAngleZ = 0F;
        Tank2m2.renderWithRotation(scale);
        Tank2m3.rotateAngleX = 0F;
        Tank2m3.rotateAngleY = -1.570796F;
        Tank2m3.rotateAngleZ = 0F;
        Tank2m3.renderWithRotation(scale);
        Tank2m4.rotateAngleX = 0F;
        Tank2m4.rotateAngleY = 0F;
        Tank2m4.rotateAngleZ = 0F;
        Tank2m4.renderWithRotation(scale);
        Tank2m5.rotateAngleX = 0F;
        Tank2m5.rotateAngleY = 0F;
        Tank2m5.rotateAngleZ = 0F;
        Tank2m5.renderWithRotation(scale);
        Tank2m6.rotateAngleX = 0F;
        Tank2m6.rotateAngleY = 0F;
        Tank2m6.rotateAngleZ = 0F;
        Tank2m6.renderWithRotation(scale);
        Tank2m7.rotateAngleX = 0F;
        Tank2m7.rotateAngleY = 0F;
        Tank2m7.rotateAngleZ = 0F;
        Tank2m7.renderWithRotation(scale);
    }
    if (gear.getTanks().getLeft() != null) {
        ScubaMaterial material = gear.getStackInSlot(0).getItem() == ItemRegistry.pinkScubaTank ? ScubaMaterial.PINK : ScubaMaterial.YELLOW;
        tm.bindTexture(ItemScubaGear.getArmorTexture(material));
        Tank1.rotateAngleX = 0F;
        Tank1.rotateAngleY = 0F;
        Tank1.rotateAngleZ = 0F;
        Tank1.renderWithRotation(scale);
        Tank1m1.rotateAngleX = 0F;
        Tank1m1.rotateAngleY = 0F;
        Tank1m1.rotateAngleZ = 0F;
        Tank1m1.renderWithRotation(scale);
        Tank1m2.rotateAngleX = 0F;
        Tank1m2.rotateAngleY = -1.570796F;
        Tank1m2.rotateAngleZ = 0F;
        Tank1m2.renderWithRotation(scale);
        Tank1m3.rotateAngleX = 0F;
        Tank1m3.rotateAngleY = -1.570796F;
        Tank1m3.rotateAngleZ = 0F;
        Tank1m3.renderWithRotation(scale);
        Tank1m4.rotateAngleX = 0F;
        Tank1m4.rotateAngleY = 0F;
        Tank1m4.rotateAngleZ = 0F;
        Tank1m4.renderWithRotation(scale);
        Tank1m5.rotateAngleX = 0F;
        Tank1m5.rotateAngleY = 0F;
        Tank1m5.rotateAngleZ = 0F;
        Tank1m5.renderWithRotation(scale);
        Tank1m6.rotateAngleX = 0F;
        Tank1m6.rotateAngleY = 0F;
        Tank1m6.rotateAngleZ = 0F;
        Tank1m6.renderWithRotation(scale);
        Tank1m7.rotateAngleX = 0F;
        Tank1m7.rotateAngleY = 0F;
        Tank1m7.rotateAngleZ = 0F;
        Tank1m7.renderWithRotation(scale);
    }
    Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(((ItemArmor) gearStack.getItem()).getArmorTexture(gearStack, entityIn, EntityEquipmentSlot.CHEST, null)));
}
Also used : TextureManager(net.minecraft.client.renderer.texture.TextureManager) ScubaMaterial(net.tropicraft.core.common.item.scuba.api.ScubaMaterial) ResourceLocation(net.minecraft.util.ResourceLocation) ItemArmor(net.minecraft.item.ItemArmor) IScubaGear(net.tropicraft.core.common.item.scuba.api.IScubaGear) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IScubaGear

use of net.tropicraft.core.common.item.scuba.api.IScubaGear in project Tropicraft by Tropicraft.

the class ItemScubaChestplateGear method onScubaTick.

@Override
public void onScubaTick(World world, EntityPlayer player, ItemStack itemstack) {
    if (player.capabilities.isCreativeMode)
        return;
    if (!world.isRemote && world.getTotalWorldTime() % UPDATE_RATE == 0) {
        ItemStack helmetStack = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
        // Ensure the player doesn't drown if they have the proper tanks / air in tanks
        if (!itemstack.isEmpty() && !helmetStack.isEmpty() && helmetStack.getItem() instanceof ItemScubaHelmet) {
            IScubaGear gear = itemstack.getCapability(ScubaCapabilities.getGearCapability(), null);
            IScubaTank tankToEmpty = gear.getFirstNonEmptyTank();
            if (tankToEmpty != null) {
                float air = tankToEmpty.getPressure();
                if (air > 0) {
                    IAirType airType = tankToEmpty.getAirType();
                    tankToEmpty.setPressure(Math.max(0, air - airType.getUsageRate()));
                    gear.markDirty();
                    player.setAir(300);
                }
            }
        }
    }
}
Also used : IScubaGear(net.tropicraft.core.common.item.scuba.api.IScubaGear) ItemStack(net.minecraft.item.ItemStack) IScubaTank(net.tropicraft.core.common.item.scuba.api.IScubaTank) IAirType(net.tropicraft.core.common.item.scuba.api.IAirType)

Aggregations

ItemStack (net.minecraft.item.ItemStack)4 IScubaGear (net.tropicraft.core.common.item.scuba.api.IScubaGear)4 FontRenderer (net.minecraft.client.gui.FontRenderer)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 TextureManager (net.minecraft.client.renderer.texture.TextureManager)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemArmor (net.minecraft.item.ItemArmor)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 BlockPos (net.minecraft.util.math.BlockPos)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1 ItemScubaHelmet (net.tropicraft.core.common.item.scuba.ItemScubaHelmet)1 IAirType (net.tropicraft.core.common.item.scuba.api.IAirType)1 IScubaTank (net.tropicraft.core.common.item.scuba.api.IScubaTank)1 ScubaMaterial (net.tropicraft.core.common.item.scuba.api.ScubaMaterial)1