net.minecraft.entity.EntityCreature Java Examples

The following examples show how to use net.minecraft.entity.EntityCreature. 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: EntityUtil.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
public static BlockPos findRandomClearArea(EntityCreature entity, int searchRange, int minY, int maxY, int searchAttempts) {
  BlockPos ep = entity.getPosition();
  Vec3d pos = entity.getPositionVector();
  World worldObj = entity.getEntityWorld();
  for (int i = 0; i < searchAttempts; i++) {
    int x = ep.getX() + -searchRange + (worldObj.rand.nextInt(searchRange + 1) * 2);
    int y = minY + worldObj.rand.nextInt(maxY - minY + 1);
    int z = ep.getZ() + -searchRange + (worldObj.rand.nextInt(searchRange + 1) * 2);      
    entity.setPosition(x + 0.5, y, z + 0.5);
    boolean isSpace = SpawnUtil.isSpaceAvailableForSpawn(worldObj, entity, false);
    entity.setPosition(pos.x, pos.y, pos.z);
    if(isSpace) {
      return new BlockPos(x,y,z);
    } 
  }
  return null;
}
 
Example #2
Source File: EntityAIWanderHex.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
private static BlockPos moveAboveSolid(BlockPos pos, EntityCreature entity)
{
	if (!entity.world.getBlockState(pos).getMaterial().isSolid())
	{
		return pos;
	}
	else
	{
		BlockPos blockpos;

		for (blockpos = pos.up(); blockpos.getY() < entity.world.getHeight() && entity.world.getBlockState(blockpos).getMaterial().isSolid(); blockpos = blockpos.up())
		{
			;
		}

		return blockpos;
	}
}
 
Example #3
Source File: EntityAIHerdMove.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
private static BlockPos moveAboveSolid(BlockPos p_191378_0_, EntityCreature p_191378_1_)
{
	if (!p_191378_1_.world.getBlockState(p_191378_0_).getMaterial().isSolid())
	{
		return p_191378_0_;
	}
	else
	{
		BlockPos blockpos;

		for (blockpos = p_191378_0_.up(); blockpos.getY() < p_191378_1_.world.getHeight() && p_191378_1_.world.getBlockState(blockpos).getMaterial().isSolid(); blockpos = blockpos.up())
		{
			;
		}

		return blockpos;
	}
}
 
Example #4
Source File: MoCEntityBigCat.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
public EntityCreature getMastersEnemy(EntityPlayer entityplayer, double d)
{
    double d1 = -1D;
    EntityCreature entitycreature = null;
    List list = worldObj.getEntitiesWithinAABBExcludingEntity(entityplayer, boundingBox.expand(d, 4D, d));
    for (int i = 0; i < list.size(); i++)
    {
        Entity entity = (Entity) list.get(i);
        if (!(entity instanceof EntityCreature) || (entity == this))
        {
            continue;
        }
        EntityCreature entitycreature1 = (EntityCreature) entity;
        if ((entitycreature1 != null) && (entitycreature1.getAttackTarget() == entityplayer)) { return entitycreature1; }
    }

    return entitycreature;
}
 
Example #5
Source File: EntityAIFlyingFindPerch.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
@Override
  public boolean shouldExecute() {
    int chance = executionChance;
    if (isOnLeaves()) { // if we are already on leaves, don't look for a new perch so often
      chance *= 10;
    } 
//    chance = 5;
    if (entity.getRNG().nextInt(chance) != 0) {
      return false;
    }

    BlockPos targetPos = EntityUtil.findRandomLandingSurface(entity, searchRange, entity.getPosition().getY() + 1, 250, searchAttempts);
    if (targetPos != null) {
      List<EntityCreature> others = entity.getEntityWorld().getEntitiesWithinAABB(entity.getClass(), EntityUtil.getBoundsAround(targetPos, 4));
      if (others != null && others.size() > 1) {
        return false;
      }
      xPosition = targetPos.getX() + 0.5;
      yPosition = targetPos.getY();
      zPosition = targetPos.getZ() + 0.5;
      return true;
    }
    return false;

  }
 
Example #6
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 #7
Source File: ActivationRange.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Initializes an entities type on construction to specify what group this
 * entity is in for activation ranges.
 *
 * @param entity
 * @return group id
 */
public static byte initializeEntityActivationType(Entity entity)
{
    Chunk chunk = null;
    // Cauldron start - account for entities that dont extend EntityMob, EntityAmbientCreature, EntityCreature
    if ( entity instanceof EntityMob || entity instanceof EntitySlime || entity.isCreatureType(EnumCreatureType.monster, false)) // Cauldron - account for entities that dont extend EntityMob
    {
        return 1; // Monster
    } else if ( entity instanceof EntityCreature || entity instanceof EntityAmbientCreature || entity.isCreatureType(EnumCreatureType.creature, false) 
             || entity.isCreatureType(EnumCreatureType.waterCreature, false) || entity.isCreatureType(EnumCreatureType.ambient, false))
    {
        return 2; // Animal
    // Cauldron end
    } else
    {
        return 3; // Misc
    }
}
 
Example #8
Source File: PotionTimeSlow.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void applyAttributesModifiersToEntity(EntityLivingBase entityLivingBaseIn, @Nonnull AbstractAttributeMap attributeMapIn, int amplifier) {
	super.applyAttributesModifiersToEntity(entityLivingBaseIn, attributeMapIn, amplifier);

	if (timeScale(entityLivingBaseIn) == 0 && entityLivingBaseIn instanceof EntityCreature) {
		((EntityLiving) entityLivingBaseIn).setNoAI(true);

		if(entityLivingBaseIn instanceof EntityCreeper) {
			((EntityCreeper)entityLivingBaseIn).setCreeperState(-1);
		}
	}

	entityLivingBaseIn.world.playSound(null, entityLivingBaseIn.getPosition(), ModSounds.SLOW_MOTION_IN, SoundCategory.NEUTRAL, 1f, 1);
}
 
Example #9
Source File: SpawnUtil.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
public static boolean isSpaceAvailableForSpawn(World worldObj, EntityLiving entity, EntityCreature asCreature, boolean checkEntityCollisions, boolean canSpawnInLiquid) {
  if(asCreature != null && asCreature.getBlockPathWeight(entity.getPosition()) < 0) {
    return false;
  }
  if(checkEntityCollisions && !worldObj.checkNoEntityCollision(entity.getEntityBoundingBox())) {
    return false;
  }
  if(!worldObj.getCollisionBoxes(entity, entity.getEntityBoundingBox()).isEmpty()) {
    return false;
  }    
  if(!canSpawnInLiquid && worldObj.containsAnyLiquid(entity.getEntityBoundingBox())) {
    return false;
  }    
  return true;
}
 
Example #10
Source File: EntityAIMoveToBlock.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
public EntityAIMoveToBlock(EntityCreature creature, double speedIn, int length) {
	destinationBlock = BlockPos.ORIGIN;
	theEntity = creature;
	movementSpeed = speedIn;
	searchLength = length;
	setMutexBits(5);
}
 
Example #11
Source File: MoCTools.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
public static void MoveCreatureToXYZ(EntityCreature movingEntity, int x, int y, int z, float f)
{
    //PathEntity pathentity = MoCreatures.mc.theWorld.getEntityPathToXYZ(movingEntity, x, y, z, f);
    //pathToEntity = worldObj.getEntityPathToXYZ(this, i, j, k, 10F, true, false, false, true);
    //TODO works?
    PathEntity pathentity = movingEntity.worldObj.getEntityPathToXYZ(movingEntity, x, y, z, f, true, false, false, true);

    if (pathentity != null)
    {
        movingEntity.setPathToEntity(pathentity);

    }

}
 
Example #12
Source File: CraftCreature.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public void setTarget(LivingEntity target) {
    EntityCreature entity = getHandle();
    if (target == null) {
        entity.entityToAttack = null;
    } else if (target instanceof CraftLivingEntity) {
        entity.entityToAttack = ((CraftLivingEntity) target).getHandle();
        entity.pathToEntity = entity.worldObj.getPathEntityToEntity(entity, entity.entityToAttack, 16.0F, true, false, false, true);
    }
}
 
Example #13
Source File: MoCTools.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
public static void MoveToWater(EntityCreature entity)
{

    int ai[] = MoCTools.ReturnNearestMaterialCoord(entity, Material.water, Double.valueOf(20D), 2D);
    if (ai[0] > -1000)
    {
        MoCTools.MoveCreatureToXYZ(entity, ai[0], ai[1], ai[2], 24F);

    }
}
 
Example #14
Source File: EntityAIMoveIntoArea.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
public EntityAIMoveIntoArea(EntityCreature entity, double speedIn, int radius) {
	this.entity = entity;
	this.movementSpeed = speedIn;
	this.radiusSq = radius * radius;

	this.setMutexBits(1);
}
 
Example #15
Source File: PotionTimeSlow.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void removeAttributesModifiersFromEntity(EntityLivingBase entityLivingBaseIn, @Nonnull AbstractAttributeMap attributeMapIn, int amplifier) {
	super.removeAttributesModifiersFromEntity(entityLivingBaseIn, attributeMapIn, amplifier);
	if (timeScale(entityLivingBaseIn) == 0 && entityLivingBaseIn instanceof EntityCreature) {
		((EntityLiving) entityLivingBaseIn).setNoAI(false);
	}

	entityLivingBaseIn.world.playSound(null, entityLivingBaseIn.getPosition(), ModSounds.SLOW_MOTION_OUT, SoundCategory.NEUTRAL, 1f, 1);
}
 
Example #16
Source File: EntityAIMountedAttackOnCollide.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
public EntityAIMountedAttackOnCollide(EntityCreature attacker, double speedTowardsTarget, double speedTowardsTargetMounted, boolean longMemory) {
  this.attacker = attacker;
  this.worldObj = attacker.world;
  this.speedTowardsTarget = speedTowardsTarget;
  this.speedTowardsTargetMounted = speedTowardsTargetMounted;
  this.longMemory = longMemory;
  this.setMutexBits(3);
}
 
Example #17
Source File: PacketSetMobTarget.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handleClientSide(PacketSetMobTarget message, EntityPlayer player){
    Entity mob = player.worldObj.getEntityByID(message.mobId);
    Entity target = player.worldObj.getEntityByID(message.targetId);
    if(mob instanceof EntityCreature) {
        ((EntityCreature)mob).setAttackTarget(target instanceof EntityLivingBase ? (EntityLivingBase)target : null);
    }
}
 
Example #18
Source File: EventHandlerPneumaticCraft.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Used by PneumaticHelmet
 * @param event
 */
@SubscribeEvent
public void onMobTargetSet(LivingSetAttackTargetEvent event){
    if(event.entity instanceof EntityCreature) {
        if(!event.entity.worldObj.isRemote) {
            NetworkHandler.sendToAllAround(new PacketSetMobTarget((EntityCreature)event.entity, event.target), new NetworkRegistry.TargetPoint(event.entity.worldObj.provider.dimensionId, event.entity.posX, event.entity.posY, event.entity.posZ, TileEntityConstants.PACKET_UPDATE_DISTANCE));
        } else {
            warnPlayerIfNecessary(event);
        }
    }
}
 
Example #19
Source File: EntityUtil.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
public static BlockPos findRandomLandingSurface(EntityCreature entity, int searchRange, int minY, int maxY, int searchAttempts) {
  for (int i = 0; i < searchAttempts; i++) {
    BlockPos res = findRandomLandingSurface(entity, searchRange, minY, maxY);
    if (res != null) {
      return res;
    }
  }
  return null;
}
 
Example #20
Source File: EntityAINearestAttackableTargetFiltered.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
public EntityAINearestAttackableTargetFiltered(EntityCreature creature, Class<T> classTarget, int chance, boolean checkSight, boolean onlyNearby, @Nullable final Predicate<? super T> targetSelector) {
	super(creature, checkSight, onlyNearby);
	this.targetClass = classTarget;
	this.targetChance = chance;
	this.sorter = new EntityAINearestAttackableTarget.Sorter(creature);
	this.setMutexBits(1);

	UUID exclude = creature.getEntityData().getUniqueId("owner");

	this.targetEntitySelector = (Predicate<T>) entity -> (entity != null && !entity.getUniqueID().equals(exclude)) && (targetSelector == null || targetSelector.apply(entity) && (EntitySelectors.NOT_SPECTATING.apply(entity) && EntityAINearestAttackableTargetFiltered.this.isSuitableTarget(entity, false)));
}
 
Example #21
Source File: EntityAIAttackOnCollideAggressive.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
public EntityAIAttackOnCollideAggressive(EntityCreature attacker, double attackSpeed, boolean longMemory) {
  this.attacker = attacker;
  worldObj = attacker.world;
  speedTowardsTarget = attackSpeed;
  this.longMemory = longMemory;
  setMutexBits(3);
}
 
Example #22
Source File: EntityAIWanderHex.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public EntityAIWanderHex(EntityCreature creatureIn, double speedIn, int chance)
{
	this.entity = creatureIn;
	this.speed = speedIn;
	this.executionChance = chance;
	this.setMutexBits(1);
}
 
Example #23
Source File: CraftCreature.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public void setTarget(LivingEntity target) {
    EntityCreature entity = getHandle();
    if (target == null) {
        entity.setAttackTarget(null, null, false);
    } else if (target instanceof CraftLivingEntity) {
        entity.setAttackTarget(((CraftLivingEntity) target).getHandle(), null, false);
    }
}
 
Example #24
Source File: EntityUtil.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
public static boolean isOnGround(EntityCreature entity) {
  List<AxisAlignedBB> collides = entity.getEntityWorld().getCollisionBoxes(entity, entity.getEntityBoundingBox().offset(0, -0.1, 0));
  if (collides == null || collides.isEmpty()) {
    return false;
  }
  BlockPos groundPos = entity.getPosition().down();
  IBlockState bs = entity.getEntityWorld().getBlockState(groundPos);
  if (bs.getMaterial().isLiquid()) {
    return false;
  }
  return true;
}
 
Example #25
Source File: EntityAIAttackOnCollideOwned.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public EntityAIAttackOnCollideOwned(IOwnable<? extends EntityCreature, ? extends EntityLivingBase> ownable, Class<? extends Entity> p_i1635_2_, double p_i1635_3_,
    boolean p_i1635_5_, EntityAIFollowOwner followTask) {
  super(ownable.asEntity(), p_i1635_3_, p_i1635_5_);
  this.ownable = ownable;
  this.followTask = followTask;
}
 
Example #26
Source File: EntityAIFollowOwner.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public EntityAIFollowOwner(IOwnable<? extends EntityCreature, ? extends EntityLivingBase> owned, double minDist, double maxDist, double followSpeed) {
  this.owned = owned;
  minDistanceSq = minDist * minDist;
  maxDistanceSq = maxDist * maxDist;
  this.followSpeed = followSpeed;
}
 
Example #27
Source File: SpawnUtil.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public static boolean isSpaceAvailableForSpawn(World worldObj, EntityCreature entityCreature, boolean checkEntityCollisions, boolean canSpawnInLiquid) {
  return isSpaceAvailableForSpawn(worldObj, entityCreature, entityCreature, checkEntityCollisions, false);
}
 
Example #28
Source File: EntityAIFlyingPanic.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public EntityAIFlyingPanic(EntityCreature creature, double speedIn) {
  theEntityCreature = creature;
  speed = speedIn;
  setMutexBits(1);
}
 
Example #29
Source File: EntityAIAttackOnCollideOwned.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public EntityAIAttackOnCollideOwned(IOwnable<? extends EntityCreature, ? extends EntityLivingBase> ownable, double p_i1636_2_, boolean p_i1636_4_,
    EntityAIFollowOwner followTask) {
  super(ownable.asEntity(), p_i1636_2_, p_i1636_4_);
  this.ownable = ownable;
  this.followTask = followTask;
}
 
Example #30
Source File: EntityAINearestAttackableTargetBounded.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public EntityAINearestAttackableTargetBounded(EntityCreature creature, Class<T> classTarget, int chance, boolean checkSight, boolean onlyNearby,
    final Predicate<? super T> targetSelector) {
  super(creature, classTarget, chance, checkSight, onlyNearby, targetSelector);
  targetChance = chance;
}