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

The following are Jave code examples for showing how to use attackEntityFrom() 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: harshencastle   File: HarshenDimensionalDoor.java   View Source Code Vote up 6 votes
@Override
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) 
{
	if(player.capabilities.isCreativeMode)
	{
		super.onBlockHarvested(worldIn, pos, state, player);
		return;
	}
	player.attackEntityFrom(DamageSource.MAGIC, 21);
	if(!worldIn.isRemote)
	{
		player.sendMessage((ITextComponent) new TextComponentTranslation("message.broken"));
	}


}
 
Example 2
Project: harshencastle   File: HarshenDimensionalStairs.java   View Source Code Vote up 6 votes
@Override
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) 
{
	if(player.capabilities.isCreativeMode)
	{
		super.onBlockHarvested(worldIn, pos, state, player);
		return;
	}
	player.attackEntityFrom(DamageSource.MAGIC, 21);
	if(!worldIn.isRemote)
	{
		player.sendMessage((ITextComponent) new TextComponentTranslation("message.broken"));
	}


}
 
Example 3
Project: ExPetrum   File: PlayerManager.java   View Source Code Vote up 6 votes
public static void tick(EntityPlayer player, IExPPlayer data, int skippedTicks)
{
	if (!player.world.isRemote)
	{
		if (data.getCurrentHealth() <= 0)
		{
			data.resetData();
			while (player.isEntityAlive())
			{
				player.attackEntityFrom(expDeathCause, Float.MAX_VALUE);
			}
		}
		
		handleHunger(player, data, skippedTicks);
		handleThirst(player, data, skippedTicks);
	}
}
 
Example 4
Project: pnc-repressurized   File: PacketSecurityStationFailedHack.java   View Source Code Vote up 5 votes
@Override
public void handleServerSide(PacketSecurityStationFailedHack message, EntityPlayer player) {
    TileEntity te = message.getTileEntity(player.world);
    if (te instanceof TileEntitySecurityStation) {
        TileEntitySecurityStation station = (TileEntitySecurityStation) te;
        if (!station.isPlayerOnWhiteList(player)) {
            player.attackEntityFrom(DamageSourcePneumaticCraft.SECURITY_STATION, 19);
        }
    }
}
 
Example 5
Project: Industrial-Foregoing   File: LavaStrawHandler.java   View Source Code Vote up 5 votes
@Override
public void onDrink(World world, BlockPos pos, FluidStack stack, EntityPlayer player, boolean fromFluidContainer) {
    player.attackEntityFrom(DamageSource.LAVA, 7);
    player.setFire(30);
    NBTTagCompound tag = player.getEntityData();
    tag.setLong("lavaDrink", world.getTotalWorldTime());
}
 
Example 6
Project: harshencastle   File: BaseHarshenBlockCastle.java   View Source Code Vote up 5 votes
@Override
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) 
{
	if(player.capabilities.isCreativeMode)
	{
		super.onBlockHarvested(worldIn, pos, state, player);
		return;
	}
	player.attackEntityFrom(DamageSource.MAGIC, 21);
	if(!worldIn.isRemote)
	{
		player.sendMessage((ITextComponent) new TextComponentTranslation("message.broken"));
	}
}
 
Example 7
Project: harshencastle   File: HarshenDimensionalGlass.java   View Source Code Vote up 5 votes
@Override
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) 
{
	if(player.capabilities.isCreativeMode)
	{
		super.onBlockHarvested(worldIn, pos, state, player);
		return;
	}
	player.attackEntityFrom(DamageSource.MAGIC, 21);
	if(!worldIn.isRemote)
	{
		player.sendMessage((ITextComponent) new TextComponentTranslation("message.broken"));
	}
}
 
Example 8
Project: harshencastle   File: HarshenSoulOre.java   View Source Code Vote up 5 votes
@Override
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) 
{
	if(player.capabilities.isCreativeMode)
	{
		super.onBlockHarvested(worldIn, pos, state, player);
		return;
	}
	ItemStack item = player.inventory.getCurrentItem();
	if(item.getItem() instanceof SoulHarsherPickaxe)
	{
		if(!worldIn.isRemote)
		{
			InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(HarshenItems.HARSHEN_SOUL_FRAGMENT));
			super.onBlockHarvested(worldIn, pos, state, player);
			player.sendMessage((ITextComponent) new TextComponentTranslation("message.success"));
		}	
	}
	else
	{
		player.attackEntityFrom(DamageSource.MAGIC, 21);
		if(!worldIn.isRemote)
		{
			player.sendMessage((ITextComponent) new TextComponentTranslation("message.failed"));
		}
	}

}
 
Example 9
Project: uniquecrops   File: TileShyPlant.java   View Source Code Vote up 5 votes
@Override
public void update() {

	if (worldObj.isRemote)
		return;
	
	if (this.worldObj.getTotalWorldTime() % 10L != 0)
		return;
	
	boolean wasLooking = this.isLooking();
	int range = 10;
	List<EntityPlayer> players = worldObj.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(pos.add(-range, -range, -range), pos.add(range, range, range)));
	
	boolean looker = false;
	for (EntityPlayer player : players) {
		ItemStack helm = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
		if (helm != null && helm.getItem() == Item.getItemFromBlock(Blocks.PUMPKIN))
			continue;
		
		RayTraceResult rtr = this.rayTraceFromEntity(worldObj, player, true, range);
		if (rtr != null && rtr.getBlockPos() != null && rtr.getBlockPos().equals(getPos())) {
			looker = true;
			break;
		}
		if (!wasLooking && ((WeepingBells)worldObj.getBlockState(getPos()).getBlock()).isWeepingCropGrown(worldObj.getBlockState(getPos())) && !player.capabilities.isCreativeMode) {
			if (getTarget(worldObj, getPos()).canEntityBeSeen(player)) {
				player.attackEntityFrom(DamageSource.outOfWorld, 1.0F);
			}
		}
	}
	if (looker != wasLooking && !worldObj.isRemote)
		setLooking(looker);
}
 
Example 10
Project: ExPetrum   File: PlayerManager.java   View Source Code Vote up 5 votes
public static void handleHunger(EntityPlayer player, IExPPlayer data, int skippedTicks)
{
	player.getFoodStats().setFoodLevel(data.getCalories() < 2000 ? 19 : 20);
	if ((data.getCalories() <= 0 || data.getThirst() <= 0) && player.ticksExisted % 40 == 0)
	{
		player.attackEntityFrom(DamageSource.STARVE, 1);
	}
	
	if (skippedTicks == 0)
	{
		if (data.getCurrentHealth() < data.getMaxHealth(true) && player.ticksExisted % 100 == 0)
		{
			handleHealthRegen(data, 1);
		}
		
		handleHungerChange(player, data, 1);
	}
	else
	{
		for (int i = 0; i < skippedTicks; ++i)
		{
			if (data.getCurrentHealth() < data.getMaxHealth(true) && i % 100 == 0)
			{
				handleHealthRegen(data, 0.5F);
			}
			
			handleHungerChange(player, data, 0.5f);
		}
	}
}
 
Example 11
Project: Bewitchment   File: FortuneDeath.java   View Source Code Vote up 4 votes
@Override
public boolean apply(@Nonnull EntityPlayer player) {
	player.getCapability(CapabilityDivination.CAPABILITY, null).setActive();
	player.attackEntityFrom(DamageSource.MAGIC, 50000000);
	return true;
}
 
Example 12
Project: DecompiledMinecraft   File: FoodStats.java   View Source Code Vote up 4 votes
/**
 * Handles the food game logic.
 */
public void onUpdate(EntityPlayer player)
{
    EnumDifficulty enumdifficulty = player.worldObj.getDifficulty();
    this.prevFoodLevel = this.foodLevel;

    if (this.foodExhaustionLevel > 4.0F)
    {
        this.foodExhaustionLevel -= 4.0F;

        if (this.foodSaturationLevel > 0.0F)
        {
            this.foodSaturationLevel = Math.max(this.foodSaturationLevel - 1.0F, 0.0F);
        }
        else if (enumdifficulty != EnumDifficulty.PEACEFUL)
        {
            this.foodLevel = Math.max(this.foodLevel - 1, 0);
        }
    }

    if (player.worldObj.getGameRules().getBoolean("naturalRegeneration") && this.foodLevel >= 18 && player.shouldHeal())
    {
        ++this.foodTimer;

        if (this.foodTimer >= 80)
        {
            player.heal(1.0F);
            this.addExhaustion(3.0F);
            this.foodTimer = 0;
        }
    }
    else if (this.foodLevel <= 0)
    {
        ++this.foodTimer;

        if (this.foodTimer >= 80)
        {
            if (player.getHealth() > 10.0F || enumdifficulty == EnumDifficulty.HARD || player.getHealth() > 1.0F && enumdifficulty == EnumDifficulty.NORMAL)
            {
                player.attackEntityFrom(DamageSource.starve, 1.0F);
            }

            this.foodTimer = 0;
        }
    }
    else
    {
        this.foodTimer = 0;
    }
}
 
Example 13
Project: DecompiledMinecraft   File: FoodStats.java   View Source Code Vote up 4 votes
/**
 * Handles the food game logic.
 */
public void onUpdate(EntityPlayer player)
{
    EnumDifficulty enumdifficulty = player.worldObj.getDifficulty();
    this.prevFoodLevel = this.foodLevel;

    if (this.foodExhaustionLevel > 4.0F)
    {
        this.foodExhaustionLevel -= 4.0F;

        if (this.foodSaturationLevel > 0.0F)
        {
            this.foodSaturationLevel = Math.max(this.foodSaturationLevel - 1.0F, 0.0F);
        }
        else if (enumdifficulty != EnumDifficulty.PEACEFUL)
        {
            this.foodLevel = Math.max(this.foodLevel - 1, 0);
        }
    }

    if (player.worldObj.getGameRules().getBoolean("naturalRegeneration") && this.foodLevel >= 18 && player.shouldHeal())
    {
        ++this.foodTimer;

        if (this.foodTimer >= 80)
        {
            player.heal(1.0F);
            this.addExhaustion(3.0F);
            this.foodTimer = 0;
        }
    }
    else if (this.foodLevel <= 0)
    {
        ++this.foodTimer;

        if (this.foodTimer >= 80)
        {
            if (player.getHealth() > 10.0F || enumdifficulty == EnumDifficulty.HARD || player.getHealth() > 1.0F && enumdifficulty == EnumDifficulty.NORMAL)
            {
                player.attackEntityFrom(DamageSource.starve, 1.0F);
            }

            this.foodTimer = 0;
        }
    }
    else
    {
        this.foodTimer = 0;
    }
}
 
Example 14
Project: BaseClient   File: FoodStats.java   View Source Code Vote up 4 votes
/**
 * Handles the food game logic.
 */
public void onUpdate(EntityPlayer player)
{
    EnumDifficulty enumdifficulty = player.worldObj.getDifficulty();
    this.prevFoodLevel = this.foodLevel;

    if (this.foodExhaustionLevel > 4.0F)
    {
        this.foodExhaustionLevel -= 4.0F;

        if (this.foodSaturationLevel > 0.0F)
        {
            this.foodSaturationLevel = Math.max(this.foodSaturationLevel - 1.0F, 0.0F);
        }
        else if (enumdifficulty != EnumDifficulty.PEACEFUL)
        {
            this.foodLevel = Math.max(this.foodLevel - 1, 0);
        }
    }

    if (player.worldObj.getGameRules().getBoolean("naturalRegeneration") && this.foodLevel >= 18 && player.shouldHeal())
    {
        ++this.foodTimer;

        if (this.foodTimer >= 80)
        {
            player.heal(1.0F);
            this.addExhaustion(3.0F);
            this.foodTimer = 0;
        }
    }
    else if (this.foodLevel <= 0)
    {
        ++this.foodTimer;

        if (this.foodTimer >= 80)
        {
            if (player.getHealth() > 10.0F || enumdifficulty == EnumDifficulty.HARD || player.getHealth() > 1.0F && enumdifficulty == EnumDifficulty.NORMAL)
            {
                player.attackEntityFrom(DamageSource.starve, 1.0F);
            }

            this.foodTimer = 0;
        }
    }
    else
    {
        this.foodTimer = 0;
    }
}
 
Example 15
Project: BaseClient   File: FoodStats.java   View Source Code Vote up 4 votes
/**
 * Handles the food game logic.
 */
public void onUpdate(EntityPlayer player)
{
    EnumDifficulty enumdifficulty = player.worldObj.getDifficulty();
    this.prevFoodLevel = this.foodLevel;

    if (this.foodExhaustionLevel > 4.0F)
    {
        this.foodExhaustionLevel -= 4.0F;

        if (this.foodSaturationLevel > 0.0F)
        {
            this.foodSaturationLevel = Math.max(this.foodSaturationLevel - 1.0F, 0.0F);
        }
        else if (enumdifficulty != EnumDifficulty.PEACEFUL)
        {
            this.foodLevel = Math.max(this.foodLevel - 1, 0);
        }
    }

    if (player.worldObj.getGameRules().getBoolean("naturalRegeneration") && this.foodLevel >= 18 && player.shouldHeal())
    {
        ++this.foodTimer;

        if (this.foodTimer >= 80)
        {
            player.heal(1.0F);
            this.addExhaustion(3.0F);
            this.foodTimer = 0;
        }
    }
    else if (this.foodLevel <= 0)
    {
        ++this.foodTimer;

        if (this.foodTimer >= 80)
        {
            if (player.getHealth() > 10.0F || enumdifficulty == EnumDifficulty.HARD || player.getHealth() > 1.0F && enumdifficulty == EnumDifficulty.NORMAL)
            {
                player.attackEntityFrom(DamageSource.starve, 1.0F);
            }

            this.foodTimer = 0;
        }
    }
    else
    {
        this.foodTimer = 0;
    }
}
 
Example 16
Project: Backmemed   File: FoodStats.java   View Source Code Vote up 4 votes
/**
 * Handles the food game logic.
 */
public void onUpdate(EntityPlayer player)
{
    EnumDifficulty enumdifficulty = player.world.getDifficulty();
    this.prevFoodLevel = this.foodLevel;

    if (this.foodExhaustionLevel > 4.0F)
    {
        this.foodExhaustionLevel -= 4.0F;

        if (this.foodSaturationLevel > 0.0F)
        {
            this.foodSaturationLevel = Math.max(this.foodSaturationLevel - 1.0F, 0.0F);
        }
        else if (enumdifficulty != EnumDifficulty.PEACEFUL)
        {
            this.foodLevel = Math.max(this.foodLevel - 1, 0);
        }
    }

    boolean flag = player.world.getGameRules().getBoolean("naturalRegeneration");

    if (flag && this.foodSaturationLevel > 0.0F && player.shouldHeal() && this.foodLevel >= 20)
    {
        ++this.foodTimer;

        if (this.foodTimer >= 10)
        {
            float f = Math.min(this.foodSaturationLevel, 6.0F);
            player.heal(f / 6.0F);
            this.addExhaustion(f);
            this.foodTimer = 0;
        }
    }
    else if (flag && this.foodLevel >= 18 && player.shouldHeal())
    {
        ++this.foodTimer;

        if (this.foodTimer >= 80)
        {
            player.heal(1.0F);
            this.addExhaustion(6.0F);
            this.foodTimer = 0;
        }
    }
    else if (this.foodLevel <= 0)
    {
        ++this.foodTimer;

        if (this.foodTimer >= 80)
        {
            if (player.getHealth() > 10.0F || enumdifficulty == EnumDifficulty.HARD || player.getHealth() > 1.0F && enumdifficulty == EnumDifficulty.NORMAL)
            {
                player.attackEntityFrom(DamageSource.starve, 1.0F);
            }

            this.foodTimer = 0;
        }
    }
    else
    {
        this.foodTimer = 0;
    }
}
 
Example 17
Project: CustomWorldGen   File: FoodStats.java   View Source Code Vote up 4 votes
/**
 * Handles the food game logic.
 */
public void onUpdate(EntityPlayer player)
{
    EnumDifficulty enumdifficulty = player.worldObj.getDifficulty();
    this.prevFoodLevel = this.foodLevel;

    if (this.foodExhaustionLevel > 4.0F)
    {
        this.foodExhaustionLevel -= 4.0F;

        if (this.foodSaturationLevel > 0.0F)
        {
            this.foodSaturationLevel = Math.max(this.foodSaturationLevel - 1.0F, 0.0F);
        }
        else if (enumdifficulty != EnumDifficulty.PEACEFUL)
        {
            this.foodLevel = Math.max(this.foodLevel - 1, 0);
        }
    }

    boolean flag = player.worldObj.getGameRules().getBoolean("naturalRegeneration");

    if (flag && this.foodSaturationLevel > 0.0F && player.shouldHeal() && this.foodLevel >= 20)
    {
        ++this.foodTimer;

        if (this.foodTimer >= 10)
        {
            float f = Math.min(this.foodSaturationLevel, 4.0F);
            player.heal(f / 4.0F);
            this.addExhaustion(f);
            this.foodTimer = 0;
        }
    }
    else if (flag && this.foodLevel >= 18 && player.shouldHeal())
    {
        ++this.foodTimer;

        if (this.foodTimer >= 80)
        {
            player.heal(1.0F);
            this.addExhaustion(4.0F);
            this.foodTimer = 0;
        }
    }
    else if (this.foodLevel <= 0)
    {
        ++this.foodTimer;

        if (this.foodTimer >= 80)
        {
            if (player.getHealth() > 10.0F || enumdifficulty == EnumDifficulty.HARD || player.getHealth() > 1.0F && enumdifficulty == EnumDifficulty.NORMAL)
            {
                player.attackEntityFrom(DamageSource.starve, 1.0F);
            }

            this.foodTimer = 0;
        }
    }
    else
    {
        this.foodTimer = 0;
    }
}