net.minecraft.entity.IEntityLivingData Java Examples

The following examples show how to use net.minecraft.entity.IEntityLivingData. 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: EntityZombieVillager.java    From Et-Futurum with The Unlicense 6 votes vote down vote up
@Override
protected void convertToVillager() {
	EntityVillager villager = new EntityVillager(worldObj);
	villager.copyLocationAndAnglesFrom(this);
	villager.onSpawnWithEgg((IEntityLivingData) null);
	villager.setLookingForHome();
	villager.setProfession(getType());

	if (isChild())
		villager.setGrowingAge(-24000);

	worldObj.removeEntity(this);
	worldObj.spawnEntityInWorld(villager);
	villager.addPotionEffect(new PotionEffect(Potion.confusion.id, 200, 0));
	worldObj.playAuxSFXAtEntity(null, 1017, (int) posX, (int) posY, (int) posZ, 0);
}
 
Example #2
Source File: EntityGuard.java    From ToroQuest with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Called only once on an entity when first time spawned, via egg, mob
 * spawner, natural spawning etc, but not called when entity is reloaded
 * from nbt. Mainly used for initializing attributes and inventory
 */
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
	livingdata = super.onInitialSpawn(difficulty, livingdata);

	setCanPickUpLoot(true);
	setEquipmentBasedOnDifficulty(difficulty);
	setEnchantmentBasedOnDifficulty(difficulty);

	setHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.DIAMOND_SWORD, 1));
	setHeldItem(EnumHand.OFF_HAND, new ItemStack(Items.SHIELD, 1));

	// addArmor();

	return livingdata;
}
 
Example #3
Source File: IVariantTypes.java    From CommunityMod with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Nullable
default IEntityLivingData initData(IEntityLivingData livingdata) {

    if (!this.isChildI()) {
        int i = this.getRandomType();

        if (livingdata instanceof TypeData) {
            i = ((TypeData) livingdata).typeData;
        } else {
            livingdata = new TypeData(i);
        }

        this.setType(i);

    }

    return livingdata;
}
 
Example #4
Source File: EntityDabSquirrel.java    From CommunityMod with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
	if (!this.isChild()) {
		int i = this.rand.nextInt(this.getVariantMax()) + 1; // Values 1 to 3
		if (i == 3 && this.rand.nextInt(4) != 0) { // 1/4 chance it remains white (overall 1/12 chance of white)
			i = this.rand.nextInt(2) + 1; // 1 - 2
		}
		if (livingdata instanceof TypeData) {
			i = ((TypeData) livingdata).typeData;
		} else {
			livingdata = new TypeData(i);
		}

		this.setType(i);
	}
	return livingdata;
}
 
Example #5
Source File: EntitySpawning.java    From ToroQuest with GNU General Public License v3.0 6 votes vote down vote up
private void replaceEntityWithVillageLord(PossibleConversionData data, EntityLiving toEntity) {
	World world = data.from.world;
	BlockPos pos = data.from.getPosition();

	if (toEntity == null) {
		toEntity = data.to;
	}

	if (toEntity == null) {
		return;
	}

	if (!data.from.isDead) {
		data.from.setDead();
	}

	toEntity.onInitialSpawn(world.getDifficultyForLocation(pos), (IEntityLivingData) null);
	toEntity.setPosition(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
	world.spawnEntity(toEntity);
	toEntity.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 200, 0));
}
 
Example #6
Source File: EntityFallenKnight.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
@Override
  public IEntityLivingData onInitialSpawn(DifficultyInstance di, IEntityLivingData livingData) {
    spawned = true;

    //From base entity living class
    getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).applyModifier(new AttributeModifier("Random spawn bonus", rand.nextGaussian() * 0.05D, 1));
//    func_189768_a(SkeletonType.NORMAL);//skeleton types do not exist anymore in 1.11.2. so its always normal.
    addRandomArmor();
    setEnchantmentBasedOnDifficulty(di); //enchantEquipment();

    float f = di.getClampedAdditionalDifficulty();
    this.setCanPickUpLoot(this.rand.nextFloat() < 0.55F * f);
    setCanPickUpLoot(rand.nextFloat() < 0.55F * f);
    setCanBreakDoors(rand.nextFloat() < f * 0.1F);

    return livingData;
  }
 
Example #7
Source File: TileEntityToroSpawner.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
private void spawnCreature() {
	EntityGuard entity = new EntityGuard(world);
	EntityLiving entityliving = (EntityLiving) entity;
	entity.setLocationAndAngles((double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, MathHelper.wrapDegrees(world.rand.nextFloat() * 360.0F), 0.0F);
	entityliving.rotationYawHead = entityliving.rotationYaw;
	entityliving.renderYawOffset = entityliving.rotationYaw;
	entityliving.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(entityliving)), (IEntityLivingData) null);
	world.spawnEntity(entity);
}
 
Example #8
Source File: CivilizationHandlers.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
private void spawnFugitive(BlockPos position, World world) {
	BlockPos randomNearbySpot = position.add(randomSpawnDistance(world.rand), 0, randomSpawnDistance(world.rand));

	if (world.rand.nextInt(200) != 0) {
		return;
	}

	Province province = CivilizationUtil.getProvinceAt(world, randomNearbySpot.getX() / 16, randomNearbySpot.getZ() / 16);

	if (province == null) {
		return;
	}

	BlockPos spawnPos = findSpawnLocationFrom(world, randomNearbySpot);

	if (spawnPos == null) {
		return;
	}

	int localFugitiveCount = world.getEntitiesWithinAABB(EntityFugitive.class, new AxisAlignedBB(spawnPos).expand(50, 40, 50)).size();

	if (localFugitiveCount > 1) {
		return;
	}

	EntityFugitive e = new EntityFugitive(world);
	e.setPosition(spawnPos.getX() + 0.5, spawnPos.getY(), spawnPos.getZ() + 0.5);
	e.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(e)), (IEntityLivingData) null);
	world.spawnEntity(e);
}
 
Example #9
Source File: EntityRainbowGuard.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
	livingdata = super.onInitialSpawn(difficulty, livingdata);
	setLeftHanded(false);
	setHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.GOLDEN_SWORD, 1));
	setCanPickUpLoot(false);
	addArmor();
	return livingdata;
}
 
Example #10
Source File: EntitySentry.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
	livingdata = super.onInitialSpawn(difficulty, livingdata);

	setCanPickUpLoot(true);
	setEquipmentBasedOnDifficulty(difficulty);
	setEnchantmentBasedOnDifficulty(difficulty);

	setHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.IRON_SWORD, 1));

	addArmor();

	return livingdata;
}
 
Example #11
Source File: ItemEntityEgg.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
public static Entity spawnEntity(World world, int id, double x, double y, double z) {
	Entity entity = ModEntityList.createEntityByID(id, world);

	if (entity != null && entity instanceof EntityLivingBase) {
		EntityLiving entityliving = (EntityLiving) entity;
		entity.setLocationAndAngles(x, y, z, MathHelper.wrapAngleTo180_float(world.rand.nextFloat() * 360.0F), 0.0F);
		entityliving.rotationYawHead = entityliving.rotationYaw;
		entityliving.renderYawOffset = entityliving.rotationYaw;
		entityliving.onSpawnWithEgg((IEntityLivingData) null);
		world.spawnEntityInWorld(entity);
		entityliving.playLivingSound();
	}

	return entity;
}
 
Example #12
Source File: EntityVillageLord.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
	livingdata = super.onInitialSpawn(difficulty, livingdata);
	setCanPickUpLoot(false);
	addArmor();
	if (isEntityAlive()) {
		setHasLord(true);
	}
	return livingdata;
}
 
Example #13
Source File: WrathSpawnerLogic.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 5 votes vote down vote up
public Entity spawnMob(Entity par1Entity) {
    if (par1Entity instanceof EntityLivingBase && par1Entity.worldObj != null) {
        ((EntityLiving) par1Entity).onSpawnWithEgg((IEntityLivingData) null);
        this.getSpawnerWorld().spawnEntityInWorld(par1Entity);
    }

    return par1Entity;
}
 
Example #14
Source File: ThroneRoomGenerator.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
private void spawnRainbowGuard(int x, int z, Color color) {
	EntityRainbowGuard entity = new EntityRainbowGuard(world);
	entity.setColor(color);
	entity.setPosition(origin.getX() + x + 0.5d, origin.getY() + 2, origin.getZ() + z + 0.5d);
	if (x < 15) {
		entity.setLookAt(origin.add(x + 100, 4, z));
	} else {
		entity.setLookAt(origin.add(x - 100, 4, z));
	}
	entity.onInitialSpawn(world.getDifficultyForLocation(origin), (IEntityLivingData) null);
	world.spawnEntity(entity);
}
 
Example #15
Source File: ThroneRoomGenerator.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
private void spawnKing() {
	EntityRainbowKing king = new EntityRainbowKing(world);
	king.setPosition(origin.getX() + 15 + 0.5D, origin.getY() + 7, origin.getZ() + (length - 3) + 0.5D);
	king.onInitialSpawn(world.getDifficultyForLocation(origin), (IEntityLivingData) null);
	king.setLookAt(origin.add(15, king.getEyeHeight(), 0));
	world.spawnEntity(king);
}
 
Example #16
Source File: StructureTofuVillagePieces.java    From TofuCraftReload with MIT License 5 votes vote down vote up
/**
 * Spawns a number of villagers in this component. Parameters: world, component bounding box, x offset, y
 * offset, z offset, number of villagers
 */
protected void spawnVillagers(World worldIn, StructureBoundingBox structurebb, int x, int y, int z, int count) {
    if (this.villagersSpawned < count) {
        for (int i = this.villagersSpawned; i < count; ++i) {
            int j = this.getXWithOffset(x + i, z);
            int k = this.getYWithOffset(y);
            int l = this.getZWithOffset(x + i, z);

            if (!structurebb.isVecInside(new BlockPos(j, k, l))) {
                break;
            }

            ++this.villagersSpawned;

            if (this.field_189929_i) {
                EntityZombieVillager entityzombie = new EntityZombieVillager(worldIn);
                entityzombie.setLocationAndAngles((double) j + 0.5D, (double) k, (double) l + 0.5D, 0.0F, 0.0F);
                entityzombie.onInitialSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityzombie)), (IEntityLivingData) null);
                entityzombie.enablePersistence();
                worldIn.spawnEntity(entityzombie);
            } else {
                EntityTofunian entityvillager = new EntityTofunian(worldIn);
                entityvillager.setLocationAndAngles((double) j + 0.5D, (double) k, (double) l + 0.5D, 0.0F, 0.0F);
                entityvillager.onInitialSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityvillager)), (IEntityLivingData) null);
                worldIn.spawnEntity(entityvillager);
            }
        }
    }
}
 
Example #17
Source File: EntityHelper.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 
 * @param world The world object
 * @param pos The BlockPos to spawn the entity at
 * @param newEnt A new EntityLiving, e.g. pass (new EntityPig(world)) into function
 * @return Returns result of spawnEntityInWorld (true if spawn was successful?)
 */
public static boolean spawnEntityAtBlockPos(World world, BlockPos pos, EntityLiving newEnt)
{
	// mostly copied from spawner eggs
	newEnt.setLocationAndAngles(pos.getX()+0.5D, pos.getY(), pos.getZ()+0.5D, world.rand.nextFloat()*360F, 0F);
	newEnt.rotationYawHead = newEnt.rotationYaw;
	newEnt.renderYawOffset = newEnt.rotationYaw;
	newEnt.onInitialSpawn(world.getDifficultyForLocation(pos), (IEntityLivingData)null);
	boolean flag = world.spawnEntity(newEnt);
	newEnt.playLivingSound();
	
       return flag;
}
 
Example #18
Source File: EntityGnome.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public IEntityLivingData onInitialSpawn(DifficultyInstance diff, IEntityLivingData data)
{
	data = super.onInitialSpawn(diff, data);
	
	this.setCarriedToAir();
	
	return data;
}
 
Example #19
Source File: EntityGnomeWood.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public IEntityLivingData onInitialSpawn(DifficultyInstance diff, IEntityLivingData data)
{
	data = super.onInitialSpawn(diff, data);
	//this.setCarried(Blocks.CHEST);
	//this.assignedGnode = new TileEntityGnomeCache();
	
	return data;
}
 
Example #20
Source File: EntityTofuCow.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
    Biome biome = this.world.getBiome(new BlockPos(this));

    if (biome instanceof BiomeZundaTofuPlains) {
        this.setVariant(1);
    } else {
        this.setVariant(0);
    }
    return super.onInitialSpawn(difficulty, livingdata);
}
 
Example #21
Source File: StructureTofuVillagePieces.java    From TofuCraftReload with MIT License 5 votes vote down vote up
protected void spawnVillagers(World worldIn, StructureBoundingBox structurebb, int x, int y, int z, int count,int profession) {
    if (this.villagersSpawned < count) {
        for (int i = this.villagersSpawned; i < count; ++i) {
            int j = this.getXWithOffset(x + i, z);
            int k = this.getYWithOffset(y);
            int l = this.getZWithOffset(x + i, z);

            if (!structurebb.isVecInside(new BlockPos(j, k, l))) {
                break;
            }

            ++this.villagersSpawned;

            if (this.field_189929_i) {
                EntityZombieVillager entityzombie = new EntityZombieVillager(worldIn);
                entityzombie.setLocationAndAngles((double) j + 0.5D, (double) k, (double) l + 0.5D, 0.0F, 0.0F);
                entityzombie.onInitialSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityzombie)), (IEntityLivingData) null);
                entityzombie.enablePersistence();
                worldIn.spawnEntity(entityzombie);
            } else {
                EntityTofunian entityvillager = new EntityTofunian(worldIn);
                entityvillager.setLocationAndAngles((double) j + 0.5D, (double) k, (double) l + 0.5D, 0.0F, 0.0F);
                entityvillager.onInitialSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityvillager)), (IEntityLivingData) null);
                entityvillager.setTofuProfession(profession);
                worldIn.spawnEntity(entityvillager);
            }
        }
    }
}
 
Example #22
Source File: EntityFallenMount.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@Override
public IEntityLivingData onInitialSpawn(DifficultyInstance di, IEntityLivingData data) {  

  setHorseArmorStack(ItemStack.EMPTY);        
  setHorseSaddled(true);    
  setGrowingAge(0);
  getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(Config.fallenMountHealth);
  getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.2);
  getAttributeMap().getAttributeInstanceByName("horse.jumpStrength").setBaseValue(0.5);
  setHealth(getMaxHealth());
  
  float chanceOfArmor = world.getDifficulty() == EnumDifficulty.HARD ? Config.fallenMountChanceArmoredHard
      : Config.fallenMountChanceArmored;
  if(rand.nextFloat() <= chanceOfArmor) {

    //Value between 0 and 1 (normal) - 1.5 based on how long a chunk has been occupied and the moon phase
    
    //float occupiedDiffcultyMultiplier = worldObj.func_147462_b(posX, posY, posZ);
    
    float occupiedDiffcultyMultiplier = di.getClampedAdditionalDifficulty();
    //TODO: Do I need this normalised still?
    occupiedDiffcultyMultiplier /= 1.5f; // normalize
    float chanceImprovedArmor = world.getDifficulty() == EnumDifficulty.HARD ? Config.fallenMountChanceArmorUpgradeHard
        : Config.fallenMountChanceArmorUpgrade;
    chanceImprovedArmor *= (1 + occupiedDiffcultyMultiplier); //If we have the max occupied factor, double the chance of improved armor

    int armorLevel = 0;
    for (int i = 0; i < 2; i++) {
      if(rand.nextFloat() <= chanceImprovedArmor) {
        armorLevel++;
      }
    }
    Item armorItem = Items.IRON_HORSE_ARMOR;
    switch (armorLevel) {
    case 1:
      armorItem = Items.GOLDEN_HORSE_ARMOR;
      break;
    case 2:
      armorItem = Items.DIAMOND_HORSE_ARMOR;
      break;
    }
    armor = new ItemStack(armorItem);
    setHorseArmorStack(armor);
  } else {
    armor = ItemStack.EMPTY;
    setHorseArmorStack(armor);
  }
  return data;
}
 
Example #23
Source File: EntityWitherWitch.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@Override
public IEntityLivingData onInitialSpawn(DifficultyInstance di, IEntityLivingData livingData) {
  spawned = true;
  return super.onInitialSpawn(di, livingData);
}
 
Example #24
Source File: EntityZombieVillager.java    From Et-Futurum with The Unlicense 4 votes vote down vote up
@Override
public IEntityLivingData onSpawnWithEgg(IEntityLivingData data) {
	setType(worldObj.rand.nextInt(6));
	return super.onSpawnWithEgg(data);
}
 
Example #25
Source File: EntityRabbit.java    From Et-Futurum with The Unlicense 4 votes vote down vote up
@Override
public IEntityLivingData onSpawnWithEgg(IEntityLivingData livingdata) {
	setRabbitType(rand.nextInt(6));
	return super.onSpawnWithEgg(livingdata);
}
 
Example #26
Source File: CivilizationHandlers.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
protected void spawnSentry(EntityPlayer player, BlockPos position, World world) {
	if (world == null || world.provider == null) {
		return;
	}

	if (world.provider.getDimension() != 0) {
		return;
	}
	BlockPos randomNearbySpot = position.add(randomSpawnDistance(world.rand), 0, randomSpawnDistance(world.rand));

	Province province = CivilizationUtil.getProvinceAt(world, randomNearbySpot.getX() / 16, randomNearbySpot.getZ() / 16);

	if (province == null) {
		return;
	}

	if (!province.hasLord) {
		return;
	}

	BlockPos spawnPos = findSpawnLocationFrom(world, randomNearbySpot);

	if (spawnPos == null) {
		return;
	}

	int localSentryCount = world.getEntitiesWithinAABB(EntitySentry.class, new AxisAlignedBB(spawnPos).expand(50, 40, 50)).size();

	int rep = PlayerCivilizationCapabilityImpl.get(player).getReputation(province.civilization);

	int extraSpawns = 0;

	if (rep < -10) {
		extraSpawns = Math.round(-rep / 50f);
	}

	if (localSentryCount > (5 + extraSpawns)) {
		return;
	}

	if(ConfigurationHandler.sentrySpawnRate == 0) {
		return;
	}

	//TODO: Look into max spawn for sentrys
	int count = world.rand.nextInt(ConfigurationHandler.sentrySpawnRate) + 1;

	for (int i = 0; i < count; i++) {
		EntitySentry e = new EntitySentry(world);
		e.setCivilization(province.civilization);
		e.setPosition(spawnPos.getX() + 0.5, spawnPos.getY(), spawnPos.getZ() + 0.5);
		e.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(e)), (IEntityLivingData) null);
		world.spawnEntity(e);
	}
}
 
Example #27
Source File: EntityBas.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Called only once on an entity when first time spawned, via egg, mob
 * spawner, natural spawning etc, but not called when entity is reloaded
 * from nbt. Mainly used for initializing attributes and inventory
 */
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
	livingdata = super.onInitialSpawn(difficulty, livingdata);
	return livingdata;
}
 
Example #28
Source File: EntityFugitive.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
@Override
public IEntityLivingData finalizeMobSpawn(DifficultyInstance p_190672_1_, @Nullable IEntityLivingData p_190672_2_, boolean p_190672_3_) {
	return p_190672_2_;
}
 
Example #29
Source File: EntityShopkeeper.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
@Override
public IEntityLivingData finalizeMobSpawn(DifficultyInstance p_190672_1_, @Nullable IEntityLivingData p_190672_2_, boolean p_190672_3_) {
	return p_190672_2_;
}
 
Example #30
Source File: EntityRainbowKing.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
	livingdata = super.onInitialSpawn(difficulty, livingdata);
	setEquipmentBasedOnDifficulty(difficulty);
	return livingdata;
}