Search in sources :

Example 1 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project MinecraftForge by MinecraftForge.

the class GuiIngameForge method renderHealth.

public void renderHealth(int width, int height) {
    bind(ICONS);
    if (pre(HEALTH))
        return;
    mc.mcProfiler.startSection("health");
    GlStateManager.enableBlend();
    EntityPlayer player = (EntityPlayer) this.mc.getRenderViewEntity();
    int health = MathHelper.ceil(player.getHealth());
    boolean highlight = healthUpdateCounter > (long) updateCounter && (healthUpdateCounter - (long) updateCounter) / 3L % 2L == 1L;
    if (health < this.playerHealth && player.hurtResistantTime > 0) {
        this.lastSystemTime = Minecraft.getSystemTime();
        this.healthUpdateCounter = (long) (this.updateCounter + 20);
    } else if (health > this.playerHealth && player.hurtResistantTime > 0) {
        this.lastSystemTime = Minecraft.getSystemTime();
        this.healthUpdateCounter = (long) (this.updateCounter + 10);
    }
    if (Minecraft.getSystemTime() - this.lastSystemTime > 1000L) {
        this.playerHealth = health;
        this.lastPlayerHealth = health;
        this.lastSystemTime = Minecraft.getSystemTime();
    }
    this.playerHealth = health;
    int healthLast = this.lastPlayerHealth;
    IAttributeInstance attrMaxHealth = player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH);
    float healthMax = (float) attrMaxHealth.getAttributeValue();
    float absorb = MathHelper.ceil(player.getAbsorptionAmount());
    int healthRows = MathHelper.ceil((healthMax + absorb) / 2.0F / 10.0F);
    int rowHeight = Math.max(10 - (healthRows - 2), 3);
    this.rand.setSeed((long) (updateCounter * 312871));
    int left = width / 2 - 91;
    int top = height - left_height;
    left_height += (healthRows * rowHeight);
    if (rowHeight != 10)
        left_height += 10 - rowHeight;
    int regen = -1;
    if (player.isPotionActive(MobEffects.REGENERATION)) {
        regen = updateCounter % 25;
    }
    final int TOP = 9 * (mc.world.getWorldInfo().isHardcoreModeEnabled() ? 5 : 0);
    final int BACKGROUND = (highlight ? 25 : 16);
    int MARGIN = 16;
    if (player.isPotionActive(MobEffects.POISON))
        MARGIN += 36;
    else if (player.isPotionActive(MobEffects.WITHER))
        MARGIN += 72;
    float absorbRemaining = absorb;
    for (int i = MathHelper.ceil((healthMax + absorb) / 2.0F) - 1; i >= 0; --i) {
        //int b0 = (highlight ? 1 : 0);
        int row = MathHelper.ceil((float) (i + 1) / 10.0F) - 1;
        int x = left + i % 10 * 8;
        int y = top - row * rowHeight;
        if (health <= 4)
            y += rand.nextInt(2);
        if (i == regen)
            y -= 2;
        drawTexturedModalRect(x, y, BACKGROUND, TOP, 9, 9);
        if (highlight) {
            if (i * 2 + 1 < healthLast)
                //6
                drawTexturedModalRect(x, y, MARGIN + 54, TOP, 9, 9);
            else if (i * 2 + 1 == healthLast)
                //7
                drawTexturedModalRect(x, y, MARGIN + 63, TOP, 9, 9);
        }
        if (absorbRemaining > 0.0F) {
            if (absorbRemaining == absorb && absorb % 2.0F == 1.0F) {
                //17
                drawTexturedModalRect(x, y, MARGIN + 153, TOP, 9, 9);
                absorbRemaining -= 1.0F;
            } else {
                //16
                drawTexturedModalRect(x, y, MARGIN + 144, TOP, 9, 9);
                absorbRemaining -= 2.0F;
            }
        } else {
            if (i * 2 + 1 < health)
                //4
                drawTexturedModalRect(x, y, MARGIN + 36, TOP, 9, 9);
            else if (i * 2 + 1 == health)
                //5
                drawTexturedModalRect(x, y, MARGIN + 45, TOP, 9, 9);
        }
    }
    GlStateManager.disableBlend();
    mc.mcProfiler.endSection();
    post(HEALTH);
}
Also used : IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 2 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project MinecraftForge by MinecraftForge.

the class GuiIngameForge method renderAir.

protected void renderAir(int width, int height) {
    if (pre(AIR))
        return;
    mc.mcProfiler.startSection("air");
    EntityPlayer player = (EntityPlayer) this.mc.getRenderViewEntity();
    GlStateManager.enableBlend();
    int left = width / 2 + 91;
    int top = height - right_height;
    if (player.isInsideOfMaterial(Material.WATER)) {
        int air = player.getAir();
        int full = MathHelper.ceil((double) (air - 2) * 10.0D / 300.0D);
        int partial = MathHelper.ceil((double) air * 10.0D / 300.0D) - full;
        for (int i = 0; i < full + partial; ++i) {
            drawTexturedModalRect(left - i * 8 - 9, top, (i < full ? 16 : 25), 18, 9, 9);
        }
        right_height += 10;
    }
    GlStateManager.disableBlend();
    mc.mcProfiler.endSection();
    post(AIR);
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 3 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project BluePower by Qmunity.

the class GuiGateWireless method renderGUI.

@Override
protected void renderGUI(int x, int y, float partialTick) {
    super.renderGUI(x, y, partialTick);
    EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    // Enable/disable components depending on our needs
    {
        String txt = frequencyName.getText();
        removeFrequency.enabled = (gate.getFrequency() != null && (gate.getFrequency().getOwner().equals(player.getGameProfile().getId()) || player.capabilities.isCreativeMode)) || (selected != null && (selected.getOwner().equals(player.getGameProfile().getId()) || player.capabilities.isCreativeMode));
        accessLevel.enabled = selected != null || (txt.trim().length() > 0 && checkNoMatches());
        saveFrequency.enabled = selected != null && (acc != selected.getAccessibility() || (txt.trim().length() > 0 && !txt.trim().equals(selected.getFrequencyName())));
        addFrequency.enabled = selected == null && txt.trim().length() > 0 && checkNoMatches();
    }
    // Render title
    drawCenteredString(fontRendererObj, I18n.format("bluepower.gui.wireless"), guiLeft + (xSize / 2), guiTop + 8, 0xEFEFEF);
    // Filter
    {
        drawCenteredString(fontRendererObj, "Filter", guiLeft + 45, guiTop + 22 + 3, 0xEFEFEF);
        String accessLevelLabel = filterAccessLevel.value == 0 ? "bluepower.accessability.public" : (filterAccessLevel.value == 1 ? "bluepower.accessability.shared" : (filterAccessLevel.value == 2 ? "bluepower.accessability.private" : (filterAccessLevel.value == 3 ? "bluepower.gui.admin" : "bluepower.gui.none")));
        drawString(fontRendererObj, I18n.format(accessLevelLabel), guiLeft + 12 + 14 + 3, guiTop + 35 + 3, filterAccessLevel.enabled ? 0xEFEFEF : 0x565656);
    }
    // Label for the access level
    String accessLevelLabel = accessLevel.value == 0 ? "bluepower.accessability.public" : (accessLevel.value == 1 ? "bluepower.accessability.shared" : "bluepower.accessability.private");
    drawString(fontRendererObj, I18n.format(accessLevelLabel), guiLeft + 10 + 14 + 3, guiTop + ySize - 24 + 3, accessLevel.enabled ? 0xEFEFEF : 0x565656);
    // Label for the mode
    String modeLabel = modeSelector.value == 0 ? "bluepower.mode.sendreceive" : (modeSelector.value == 1 ? "bluepower.mode.send" : "bluepower.mode.receive");
    drawString(fontRendererObj, I18n.format(modeLabel), guiLeft + 10 + 14 + 3, guiTop + 57 + 3, 0xEFEFEF);
    // Render the textbox
    frequencyName.drawTextBox();
    // Get all frequencies and sort them
    List<Frequency> frequencies = getFrequencies();
    // Render the list
    for (int i = 0; i < Math.min(frequencies.size(), 12); i++) {
        Frequency f = frequencies.get(i + scrolled);
        int yPos = guiTop + 22 + 10 + 2 + (i * 12);
        int color = f.equals(gate.getFrequency()) ? 0x00CCCC : (f.equals(selected) ? 0x888888 : ((x > guiLeft + 88 && x <= guiLeft + 88 + 133 - (frequencies.size() > 12 ? 11 : 0) && y > yPos && y <= yPos + 11 && f.isBundled() == gate.isBundled()) ? 0xAAAAAA : 0x333333));
        int textColor = f.equals(gate.getFrequency()) ? 0x333333 : (f.isBundled() != gate.isBundled() ? 0x999999 : 0xFFFFFF);
        drawRect(guiLeft + 88, yPos, guiLeft + 88 + 133 - (frequencies.size() > 12 ? 11 : 0), yPos + 11, (0xFF << 24) + color);
        String format = f.isBundled() != gate.isBundled() ? EnumChatFormatting.STRIKETHROUGH.toString() : "";
        String txt = format + f.getFrequencyName() + ((filterAccessLevel.value == 3 || filterAccessLevel.value == 4) ? " [" + StringUtils.capitalize(f.getAccessibility().name().toLowerCase()) + "]" : "");
        fontRendererObj.drawString(txt, guiLeft + 88 + 2 + 12 + 2, yPos + 2, textColor, !f.equals(gate.getFrequency()));
        ItemStack item = PartManager.getPartInfo("wire.bluestone" + (f.isBundled() ? ".bundled" : "")).getStack();
        GL11.glPushMatrix();
        {
            if (f.isBundled() != gate.isBundled())
                GL11.glEnable(GL11.GL_LIGHTING);
            GL11.glTranslated(guiLeft + 88 + 1, yPos - 2, 0);
            GL11.glScaled(0.75, 0.75, 0.75);
            ForgeHooksClient.renderInventoryItem(RenderBlocks.getInstance(), Minecraft.getMinecraft().renderEngine, item, true, 1, 1, 1);
            if (f.isBundled() != gate.isBundled())
                GL11.glDisable(GL11.GL_LIGHTING);
        }
        GL11.glPopMatrix();
    }
    if (frequencies.size() > 12) {
        drawRect(guiLeft + 88 + 133 - 10, guiTop + 22 + 10 + 2, guiLeft + 88 + 133, guiTop + 22 + 10 + 1 + (12 * 12), 0xFF565656);
    }
    for (int i = 0; i < Math.min(frequencies.size(), 12); i++) {
        Frequency f = frequencies.get(i + scrolled);
        int yPos = guiTop + 22 + 10 + 2 + (i * 12);
        if (x > guiLeft + 88 && x <= guiLeft + 88 + 133 - (frequencies.size() > 12 ? 11 : 0) && y > yPos && y <= yPos + 11 && f.isBundled() == gate.isBundled()) {
            func_146283_a(Arrays.asList("Frequency: " + f.getFrequencyName(), EnumChatFormatting.GRAY + "Accessibility: " + StringUtils.capitalize(f.getAccessibility().name().toLowerCase()), EnumChatFormatting.GRAY + "Owner: " + f.getOwnerName(), "Devices: " + f.getDevices()), x, y);
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) Frequency(com.bluepowermod.part.gate.wireless.Frequency) IFrequency(com.bluepowermod.api.wireless.IFrequency) ItemStack(net.minecraft.item.ItemStack)

Example 4 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project BluePower by Qmunity.

the class ItemScrewdriver method damage.

@Override
public boolean damage(ItemStack stack, int damage, EntityPlayer player, boolean simulated) {
    if (player != null && player.capabilities.isCreativeMode)
        return true;
    if ((stack.getItemDamage() % stack.getMaxDamage()) + damage > stack.getMaxDamage())
        return false;
    if (!simulated) {
        if (stack.attemptDamageItem(damage, new Random())) {
            if (player != null)
                player.renderBrokenItemStack(stack);
            --stack.stackSize;
            if (player != null && player instanceof EntityPlayer)
                player.addStat(StatList.objectBreakStats[Item.getIdFromItem(stack.getItem())], 1);
            if (stack.stackSize < 0)
                stack.stackSize = 0;
            stack.setItemDamage(0);
        }
    }
    return true;
}
Also used : Random(java.util.Random) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 5 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project BluePower by Qmunity.

the class PneumaticTube method rayTrace.

@Override
public QMovingObjectPosition rayTrace(Vec3d start, Vec3d end) {
    QMovingObjectPosition mop = super.rayTrace(start, end);
    if (mop == null)
        return null;
    EntityPlayer player = BluePower.proxy.getPlayer();
    if (redwireType != null && player != null && player.isSneaking()) {
        double wireSize = getSize() / 16D;
        double frameSeparation = 4 / 16D - (wireSize - 2 / 16D);
        double frameThickness = 1 / 16D;
        frameThickness /= 1.5;
        frameSeparation -= 1 / 32D;
        QMovingObjectPosition wire = RayTracer.instance().rayTraceCubes(getFrameBoxes(wireSize, frameSeparation, frameThickness, shouldRenderConnection(ForgeDirection.DOWN), shouldRenderConnection(ForgeDirection.UP), shouldRenderConnection(ForgeDirection.WEST), shouldRenderConnection(ForgeDirection.EAST), shouldRenderConnection(ForgeDirection.NORTH), shouldRenderConnection(ForgeDirection.SOUTH), redstoneConnections[ForgeDirection.DOWN.ordinal()], redstoneConnections[ForgeDirection.UP.ordinal()], redstoneConnections[ForgeDirection.WEST.ordinal()], redstoneConnections[ForgeDirection.EAST.ordinal()], redstoneConnections[ForgeDirection.NORTH.ordinal()], redstoneConnections[ForgeDirection.SOUTH.ordinal()], getParent() != null && getWorld() != null), start, end, new Vec3i(this));
        QMovingObjectPosition frame = RayTracer.instance().rayTraceCubes(getFrameBoxes(), start, end, new Vec3i(this));
        if (wire != null) {
            if (frame != null) {
                if (wire.hitVec.distanceTo(start.toVec3()) < frame.hitVec.distanceTo(start.toVec3()))
                    mop.hitInfo = PartManager.getPartInfo("wire." + redwireType.getName()).getStack();
            } else {
                mop.hitInfo = PartManager.getPartInfo("wire." + redwireType.getName()).getStack();
            }
        }
    }
    return mop;
}
Also used : Vec3i(uk.co.qmunity.lib.vec.Vec3i) EntityPlayer(net.minecraft.entity.player.EntityPlayer) QMovingObjectPosition(uk.co.qmunity.lib.raytrace.QMovingObjectPosition)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)1630 ItemStack (net.minecraft.item.ItemStack)468 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)309 Entity (net.minecraft.entity.Entity)249 BlockPos (net.minecraft.util.math.BlockPos)241 EntityLivingBase (net.minecraft.entity.EntityLivingBase)214 World (net.minecraft.world.World)188 IBlockState (net.minecraft.block.state.IBlockState)129 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)127 TileEntity (net.minecraft.tileentity.TileEntity)112 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)104 ArrayList (java.util.ArrayList)99 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)95 EntityItem (net.minecraft.entity.item.EntityItem)85 PotionEffect (net.minecraft.potion.PotionEffect)85 Block (net.minecraft.block.Block)84 TextComponentString (net.minecraft.util.text.TextComponentString)84 Vec3d (net.minecraft.util.math.Vec3d)83 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)80 List (java.util.List)79