Java Code Examples for net.minecraft.util.DamageSource#getEntity()

The following examples show how to use net.minecraft.util.DamageSource#getEntity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MoCEntityHorse.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{

    Entity entity = damagesource.getEntity();
    if ((riddenByEntity != null) && (entity == riddenByEntity)) { return false; }
    if (entity instanceof EntityWolf)
    {
        EntityCreature entitycreature = (EntityCreature) entity;
        entitycreature.setAttackTarget(null);
        return false;
    }
    else
    {
        i = i - (getArmorType() + 2);
        if (i < 0)
        {
            i = 0;
        }
        return super.attackEntityFrom(damagesource, i);
    }
}
 
Example 2
Source File: MoCEntityAmbient.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
	Entity entity = damagesource.getEntity();
	//this avoids damage done by Players to a tamed creature that is not theirs
	if (MoCreatures.proxy.enableOwnership && getOwnerName() != null && !getOwnerName().equals("") && entity != null && entity instanceof EntityPlayer && !((EntityPlayer) entity).username.equals(getOwnerName())) { return false; }

	if (MoCreatures.isServer() && getIsTamed())
	{
		MoCServerPacketHandler.sendHealth(this.entityId, this.worldObj.provider.dimensionId, this.getHealth());
	}
	/*if (isNotScared())
	{
		Entity tempEntity = entityToAttack;
		boolean flag = super.attackEntityFrom(damagesource, i);
		fleeingTick = 0;
		entityToAttack = tempEntity;
		return flag;
	}
	else*/
	{
		return super.attackEntityFrom(damagesource, i);
	}
}
 
Example 3
Source File: MoCEntityScorpion.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i))
    {
        Entity entity = damagesource.getEntity();
        //if ((entity != null) && (entity instanceof EntityPlayer) && getIsTamed()) { return false; }

        if ((entity != null) && (entity != this) && (worldObj.difficultySetting > 0) && getIsAdult())
        {
            entityToAttack = entity;
        }
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 4
Source File: MoCEntityKomodo.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i))
    {
        Entity entity = damagesource.getEntity();
     
        
        if (entity != null && getIsTamed() && entity instanceof EntityPlayer) { return false; }
        

        if ((riddenByEntity != null) && (entity == riddenByEntity)) { return false; }
        
        if ((entity != this) && (worldObj.difficultySetting > 0))
        {
            entityToAttack = entity;
        }
        return true;
    }
    return false;
}
 
Example 5
Source File: MoCEntityBee.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i))
    {
        Entity entity = damagesource.getEntity();
        if ((entity != this) && (worldObj.difficultySetting > 0))
        {
            entityToAttack = entity;
        }
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 6
Source File: MoCEntityRay.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i))
    {
        if (getType() == 1 || (worldObj.difficultySetting == 0)) { return true; }
        Entity entity = damagesource.getEntity();

        if (entity != this)
        {
            entityToAttack = entity;
        }
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 7
Source File: MoCEntityGoat.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i))
    {
        Entity entity = damagesource.getEntity();

        if ((entity != this) && (worldObj.difficultySetting > 0) && getType() > 4)
        {
            entityToAttack = entity;
            setUpset(true);
        }
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 8
Source File: MoCEntityFishy.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i))
    {
        Entity entity = damagesource.getEntity();
        if ((riddenByEntity == entity) || (ridingEntity == entity)) { return true; }
        if (entity != this && getType() == 10 && worldObj.difficultySetting > 0)
        {
            entityToAttack = entity;
        }
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 9
Source File: MoCEntityBear.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i))
    {
        Entity entity = damagesource.getEntity();
        if ((riddenByEntity == entity) || (ridingEntity == entity)) { return true; }
        if ((entity != this) && (worldObj.difficultySetting > 0) && this.getType() != 3)
        {
            entityToAttack = entity;
        }
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 10
Source File: MoCEntityFox.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i))
    {
        Entity entity = damagesource.getEntity();
        if ((riddenByEntity == entity) || (ridingEntity == entity)) { return true; }
        if ((entity != this) && (worldObj.difficultySetting > 0))
        {
            entityToAttack = entity;
        }
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 11
Source File: MoCEntityElephant.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i))
    {
        Entity entity = damagesource.getEntity();
        if (entity != null && getIsTamed() && entity instanceof EntityPlayer) { return false; }
        if ((riddenByEntity == entity) || (ridingEntity == entity)) { return true; }
        if ((entity != this) && (worldObj.difficultySetting > 0))
        {
            entityToAttack = entity;
        }
        return true;
    }
    return false;
}
 
Example 12
Source File: MoCEntityShark.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i) && (worldObj.difficultySetting > 0))
    {
        Entity entity = damagesource.getEntity();
        if ((riddenByEntity == entity) || (ridingEntity == entity)) { return true; }
        if (entity != this)
        {
            entityToAttack = entity;
        }
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 13
Source File: MoCEntityPetScorpion.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i))
    {
        Entity entity = damagesource.getEntity();
        if ((entity != null) && (entity instanceof EntityPlayer) && getIsTamed()) { return false; }

        if ((entity != null) && (entity != this) && (worldObj.difficultySetting > 0) && getIsAdult())
        {
            entityToAttack = entity;
        }
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 14
Source File: MoCEntityWerewolf.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDeath(DamageSource damagesource)
{
    Entity entity = damagesource.getEntity();
    if ((scoreValue > 0) && (entity != null))
    {
        entity.addToPlayerScore(this, scoreValue);
    }
    if (entity != null)
    {
        entity.onKillEntity(this);
    }
    //unused_flag = true;
    if (!worldObj.isRemote)
    {
        for (int i = 0; i < 2; i++)
        {
            int j = getDropItemId();
            if (j > 0)
            {
                dropItem(j, 1);
            }
        }

    }
}
 
Example 15
Source File: MoCEntityBigCat.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i))
    {
        Entity entity = damagesource.getEntity();
        if (entity != null && getIsTamed() && entity instanceof EntityPlayer) { return false; }
        if ((riddenByEntity == entity) || (ridingEntity == entity)) { return true; }
        if ((entity != this) && (worldObj.difficultySetting > 0))
        {
            entityToAttack = entity;
        }
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 16
Source File: MoCEntityAquatic.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    Entity entity = damagesource.getEntity();
    //this avoids damage done by Players to a tamed creature that is not theirs
    if (MoCreatures.proxy.enableOwnership && getOwnerName() != null && !getOwnerName().equals("") && entity != null && entity instanceof EntityPlayer && !((EntityPlayer) entity).username.equals(getOwnerName())) { return false; }

    if (MoCreatures.isServer() && getIsTamed())
    {
        MoCServerPacketHandler.sendHealth(this.entityId, this.worldObj.provider.dimensionId, this.getHealth());
    }

    return super.attackEntityFrom(damagesource, i);

}
 
Example 17
Source File: MoCEntityWerewolf.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    Entity entity = damagesource.getEntity();
    if (!getIsHumanForm() && (entity != null) && (entity instanceof EntityPlayer))
    {
        EntityPlayer entityplayer = (EntityPlayer) entity;
        ItemStack itemstack = entityplayer.getCurrentEquippedItem();
        if (itemstack != null)
        {
            i = 1;
            if (itemstack.itemID == Item.hoeGold.itemID)
            {
                i = 6;
            }
            if (itemstack.itemID == Item.shovelGold.itemID)
            {
                i = 7;
            }
            if (itemstack.itemID == Item.pickaxeGold.itemID)
            {
                i = 8;
            }
            if (itemstack.itemID == Item.axeGold.itemID)
            {
                i = 9;
            }
            if (itemstack.itemID == Item.swordGold.itemID)
            {
                i = 10;
            }
        }
    }
    return super.attackEntityFrom(damagesource, i);
}
 
Example 18
Source File: MoCEntityRat.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i))
    {
        Entity entity = damagesource.getEntity();
        if (entity instanceof EntityPlayer)
        {
            entityToAttack = entity;
        }
        if ((entity instanceof EntityArrow) && (((EntityArrow) entity).shootingEntity != null))
        {
            entity = ((EntityArrow) entity).shootingEntity;
        }
        if (entity instanceof EntityLiving)
        {
            //TODO 4FIX TEST
            List list = worldObj.getEntitiesWithinAABB(MoCEntityRat.class, AxisAlignedBB.getBoundingBox(posX, posY, posZ, posX + 1.0D, posY + 1.0D, posZ + 1.0D).expand(16D, 4D, 16D));
            Iterator iterator = list.iterator();
            do
            {
                if (!iterator.hasNext())
                {
                    break;
                }
                Entity entity1 = (Entity) iterator.next();
                MoCEntityRat entityrat = (MoCEntityRat) entity1;
                if ((entityrat != null) && (entityrat.entityToAttack == null))
                {
                    entityrat.entityToAttack = entity;
                }
            } while (true);
        }
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 19
Source File: GolemUpgradeRunicShield.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void sendShieldEffect(EntityGolemBase golem, DamageSource source) {
    int target = -1;
    if (source.getEntity() != null) {
        target = source.getEntity().getEntityId();
    } else if (source == DamageSource.fall) {
        target = -2;
    } else if (source == DamageSource.fallingBlock) {
        target = -3;
    }

    PacketHandler.INSTANCE.sendToAllAround(new PacketFXShield(golem.getEntityId(), target),
            new NetworkRegistry.TargetPoint(golem.worldObj.provider.dimensionId, golem.posX, golem.posY, golem.posZ, 64.0D));
}
 
Example 20
Source File: MoCEntityKitty.java    From mocreaturesdev with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i))
    {
        Entity entity = damagesource.getEntity();
        if (entity != this)
        {
            if (getKittyState() == 10)
            {
                List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(16D, 6D, 16D));
                for (int j = 0; j < list.size(); j++)
                {
                    Entity entity1 = (Entity) list.get(j);
                    if ((entity1 instanceof MoCEntityKitty) && (((MoCEntityKitty) entity1).getKittyState() == 21))
                    {
                        ((MoCEntityKitty) entity1).entityToAttack = entity;
                        return true;
                    }
                }

                return true;
            }
            if (entity instanceof EntityPlayer)
            {
                if (getKittyState() < 2)
                {
                    entityToAttack = entity;
                    setKittyState(-1);
                }
                if ((getKittyState() == 19) || (getKittyState() == 20) || (getKittyState() == 21))
                {
                    entityToAttack = entity;
                    setSitting(false);
                    return true;
                }
                if ((getKittyState() > 1) && (getKittyState() != 10) && (getKittyState() != 19) && (getKittyState() != 20) && (getKittyState() != 21))
                {
                    setKittyState(13);
                    setSitting(false);
                }
                return true;
            }
            entityToAttack = entity;
        }
        return true;
    }
    else
    {
        return false;
    }
}