Java Code Examples for net.minecraft.entity.player.EntityPlayer.getMaxHealth()

The following are Jave code examples for showing how to use getMaxHealth() of the net.minecraft.entity.player.EntityPlayer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Loot-Slash-Conquer   File: GuiHealth.java   View Source Code Vote up 6 votes
@SubscribeEvent
public void onRenderOverlay(RenderGameOverlayEvent.Post event)
{	
	if (event.getType() != ElementType.EXPERIENCE) return;
	else
	{	
		ScaledResolution sr = event.getResolution();
		EntityPlayer player = Minecraft.getMinecraft().player;
		
		if (!player.capabilities.isCreativeMode)
		{
			double healthBarWidth = (double) player.getHealth() / player.getMaxHealth() * 81.0;
			int xPos = sr.getScaledWidth() / 2 - 91;
			int yPos = sr.getScaledHeight() - 39;
			
			mc.renderEngine.bindTexture(location);
			
			this.drawTexturedModalRect(xPos, yPos, 0, 0, 81, 9);
			this.drawTexturedModalRect(xPos, yPos, 0, 9, (int) healthBarWidth, 8);	
		}
	}
}
 
Example 2
Project: Loot-Slash-Conquer   File: GuiHealth.java   View Source Code Vote up 6 votes
@SubscribeEvent
public void onRenderOverlayText(RenderGameOverlayEvent.Text event)
{
	ScaledResolution sr = event.getResolution();
	EntityPlayer player = Minecraft.getMinecraft().player;
	
	if (!player.capabilities.isCreativeMode)
	{
		String health = (int) player.getHealth() + " / " + (int) player.getMaxHealth();
		
		GL11.glPushMatrix();
		GL11.glScalef(0.5F, 0.5F, 0.5F);
		Minecraft.getMinecraft().fontRenderer.drawStringWithShadow(health, (sr.getScaledWidth() / 2 - 60) * 2, (sr.getScaledHeight() - 36) * 2, 0xFFFFFF);
		GL11.glPopMatrix();
	}
}
 
Example 3
Project: pnc-repressurized   File: PlayerHealthSensor.java   View Source Code Vote up 5 votes
@Override
public int getRedstoneValue(World world, BlockPos pos, int sensorRange, String textBoxText) {
    EntityPlayer player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUsername(textBoxText);
    if (player != null) {
        return (int) (15 * player.getHealth() / player.getMaxHealth());
    } else {
        return 0;
    }
}
 
Example 4
Project: pnc-repressurized   File: TileEntityAerialInterface.java   View Source Code Vote up 5 votes
private boolean okToFeed(@Nonnull ItemStack stack, EntityPlayer player) {
    int foodValue = getFoodValue(stack);
    int curFoodLevel = player.getFoodStats().getFoodLevel();
    int tmpFeedMode = feedMode;
    if (tmpFeedMode == 2) {
        tmpFeedMode = player.getMaxHealth() - player.getHealth() > 0 ? 1 : 0;
    }
    switch (tmpFeedMode) {
        case 0:
            return 20 - curFoodLevel >= foodValue * stack.getCount();
        case 1:
            return 20 - curFoodLevel >= foodValue * (stack.getCount() - 1) + 1;
    }
    return false;
}
 
Example 5
Project: FirstAid   File: PlayerDamageModel.java   View Source Code Vote up 4 votes
@Override
public void tick(World world, EntityPlayer player) {
    if (isDead(player))
        return;

    float currentHealth = getCurrentHealth();
    if (currentHealth <= 0F) {
        FirstAid.logger.error("Got {} health left, but isn't marked as dead!", currentHealth);
        return;
    }

    if (FirstAid.playerMaxHealth != -1) {
        float newCurrentHealth = (player.getMaxHealth() * currentHealth) / FirstAid.playerMaxHealth;

        if (Float.isInfinite(newCurrentHealth)) {
            FirstAid.logger.error("Error calculating current health: Value was infinite"); //Shouldn't happen anymore, but let's be safe
        } else {
            if (newCurrentHealth != prevHealthCurrent)
                ((DataManagerWrapper) player.dataManager).set_impl(EntityPlayer.HEALTH, newCurrentHealth);
            prevHealthCurrent = newCurrentHealth;
        }
    }

    if (!this.hasTutorial)
        this.hasTutorial = PlayerDataManager.tutorialDone.contains(player.getName());

    if (FirstAid.scaleMaxHealth) { //Attempt to calculate the max health of the body parts based on the maxHealth attribute
        float globalFactor = player.getMaxHealth() / 20F;
        if (prevScaleFactor != globalFactor) {
            int reduced = 0;
            int added = 0;
            for (AbstractDamageablePart part : this) {
                int result = Math.round(part.initialMaxHealth * globalFactor);
                if (result % 2 == 1) {
                    int partMaxHealth = part.getMaxHealth();
                    if (part.currentHealth < partMaxHealth && reduced < 4) {
                        result--;
                        reduced++;
                    } else if (part.currentHealth > partMaxHealth && added < 4) {
                        result++;
                        added++;
                    } else if (reduced > added) {
                        result++;
                        added++;
                    } else {
                        result--;
                        reduced++;
                    }
                }
                part.setMaxHealth(result);
            }
        }
        prevScaleFactor = globalFactor;
    }

    if (!world.isRemote && world instanceof WorldServer && FirstAid.activeHealingConfig.sleepHealing != 0) {
        WorldServer worldServer = (WorldServer) player.world;
        if (worldServer.areAllPlayersAsleep()) { // We are going to wake up on the next tick, add health
            HealthDistribution.distributeHealth(FirstAid.activeHealingConfig.sleepHealing, player, true);
        }
    }

    forEach(part -> part.tick(world, player, morphineTicksLeft == 0));
    if (morphineTicksLeft <= 0)
        sharedDebuffs.forEach(sharedDebuff -> sharedDebuff.tick(player));
    else
        morphineTicksLeft--;
}