本文整理汇总了Java中net.minecraft.world.DifficultyInstance类的典型用法代码示例。如果您正苦于以下问题:Java DifficultyInstance类的具体用法?Java DifficultyInstance怎么用?Java DifficultyInstance使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DifficultyInstance类属于net.minecraft.world包,在下文中一共展示了DifficultyInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onInitialSpawn
import net.minecraft.world.DifficultyInstance; //导入依赖的package包/类
/**
* 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)
{
this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).applyModifier(new AttributeModifier("Random spawn bonus", this.rand.nextGaussian() * 0.05D, 1));
if (this.rand.nextFloat() < 0.05F)
{
this.setLeftHanded(true);
}
else
{
this.setLeftHanded(false);
}
return livingdata;
}
示例2: onInitialSpawn
import net.minecraft.world.DifficultyInstance; //导入依赖的package包/类
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
livingdata = super.onInitialSpawn(difficulty, livingdata);
float f = difficulty.getClampedAdditionalDifficulty();
this.setCanPickUpLoot(false);
this.setEquipmentBasedOnDifficulty(difficulty);
this.setEnchantmentBasedOnDifficulty(difficulty);
this.setCombatTask();
this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).applyModifier(
new AttributeModifier("Random spawn bonus", this.rand.nextDouble() * 0.05000000074505806D, 0));
double d0 = this.rand.nextDouble() * 1.5D * (double) f;
if (d0 > 1.0D) {
this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE)
.applyModifier(new AttributeModifier("Random zombie-spawn bonus", d0, 2));
}
return livingdata;
}
示例3: setEnchantmentBasedOnDifficulty
import net.minecraft.world.DifficultyInstance; //导入依赖的package包/类
/**
* Enchants Entity's current equipments based on given DifficultyInstance
*/
protected void setEnchantmentBasedOnDifficulty(DifficultyInstance difficulty)
{
float f = difficulty.getClampedAdditionalDifficulty();
if (this.getHeldItem() != null && this.rand.nextFloat() < 0.25F * f)
{
EnchantmentHelper.addRandomEnchantment(this.rand, this.getHeldItem(), (int)(5.0F + f * (float)this.rand.nextInt(18)));
}
for (int i = 0; i < 4; ++i)
{
ItemStack itemstack = this.getCurrentArmor(i);
if (itemstack != null && this.rand.nextFloat() < 0.5F * f)
{
EnchantmentHelper.addRandomEnchantment(this.rand, itemstack, (int)(5.0F + f * (float)this.rand.nextInt(18)));
}
}
}
示例4: onInitialSpawn
import net.minecraft.world.DifficultyInstance; //导入依赖的package包/类
/**
* 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
*/
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata)
{
livingdata = super.onInitialSpawn(difficulty, livingdata);
int i = this.rand.nextInt(6);
boolean flag = false;
if (livingdata instanceof EntityRabbit.RabbitTypeData)
{
i = ((EntityRabbit.RabbitTypeData)livingdata).typeData;
flag = true;
}
else
{
livingdata = new EntityRabbit.RabbitTypeData(i);
}
this.setRabbitType(i);
if (flag)
{
this.setGrowingAge(-24000);
}
return livingdata;
}
示例5: onInitialSpawn
import net.minecraft.world.DifficultyInstance; //导入依赖的package包/类
/**
* 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
*/
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata)
{
if (livingdata instanceof EntityPolarBear.GroupData)
{
if (((EntityPolarBear.GroupData)livingdata).madeParent)
{
this.setGrowingAge(-24000);
}
}
else
{
EntityPolarBear.GroupData entitypolarbear$groupdata = new EntityPolarBear.GroupData();
entitypolarbear$groupdata.madeParent = true;
livingdata = entitypolarbear$groupdata;
}
return (IEntityLivingData)livingdata;
}
示例6: setEquipmentBasedOnDifficulty
import net.minecraft.world.DifficultyInstance; //导入依赖的package包/类
/**
* Gives armor or weapon for entity based on given DifficultyInstance
*/
protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty)
{
super.setEquipmentBasedOnDifficulty(difficulty);
if (this.rand.nextFloat() < (this.worldObj.getDifficulty() == EnumDifficulty.HARD ? 0.05F : 0.01F))
{
int i = this.rand.nextInt(3);
if (i == 0)
{
this.setCurrentItemOrArmor(0, new ItemStack(Items.iron_sword));
}
else
{
this.setCurrentItemOrArmor(0, new ItemStack(Items.iron_shovel));
}
}
}
示例7: onInitialSpawn
import net.minecraft.world.DifficultyInstance; //导入依赖的package包/类
/**
* 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
*/
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata)
{
livingdata = super.onInitialSpawn(difficulty, livingdata);
if (this.worldObj.rand.nextInt(7) == 0)
{
for (int i = 0; i < 2; ++i)
{
EntityOcelot entityocelot = new EntityOcelot(this.worldObj);
entityocelot.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F);
entityocelot.setGrowingAge(-24000);
this.worldObj.spawnEntityInWorld(entityocelot);
}
}
return livingdata;
}
示例8: createSkeleton
import net.minecraft.world.DifficultyInstance; //导入依赖的package包/类
private EntitySkeleton createSkeleton(DifficultyInstance p_188514_1_, EntityHorse p_188514_2_)
{
EntitySkeleton entityskeleton = new EntitySkeleton(p_188514_2_.worldObj);
entityskeleton.onInitialSpawn(p_188514_1_, (IEntityLivingData)null);
entityskeleton.setPosition(p_188514_2_.posX, p_188514_2_.posY, p_188514_2_.posZ);
entityskeleton.hurtResistantTime = 60;
entityskeleton.enablePersistence();
if (entityskeleton.getItemStackFromSlot(EntityEquipmentSlot.HEAD) == null)
{
entityskeleton.setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(Items.IRON_HELMET));
}
EnchantmentHelper.addRandomEnchantment(entityskeleton.getRNG(), entityskeleton.getHeldItemMainhand(), (int)(5.0F + p_188514_1_.getClampedAdditionalDifficulty() * (float)entityskeleton.getRNG().nextInt(18)), false);
EnchantmentHelper.addRandomEnchantment(entityskeleton.getRNG(), entityskeleton.getItemStackFromSlot(EntityEquipmentSlot.HEAD), (int)(5.0F + p_188514_1_.getClampedAdditionalDifficulty() * (float)entityskeleton.getRNG().nextInt(18)), false);
entityskeleton.worldObj.spawnEntityInWorld(entityskeleton);
return entityskeleton;
}
示例9: updateTask
import net.minecraft.world.DifficultyInstance; //导入依赖的package包/类
/**
* Updates the task
*/
public void updateTask()
{
DifficultyInstance difficultyinstance = this.horse.worldObj.getDifficultyForLocation(new BlockPos(this.horse));
this.horse.setSkeletonTrap(false);
this.horse.setType(HorseType.SKELETON);
this.horse.setHorseTamed(true);
this.horse.setGrowingAge(0);
this.horse.worldObj.addWeatherEffect(new EntityLightningBolt(this.horse.worldObj, this.horse.posX, this.horse.posY, this.horse.posZ, true));
EntitySkeleton entityskeleton = this.createSkeleton(difficultyinstance, this.horse);
entityskeleton.startRiding(this.horse);
for (int i = 0; i < 3; ++i)
{
EntityHorse entityhorse = this.createHorse(difficultyinstance);
EntitySkeleton entityskeleton1 = this.createSkeleton(difficultyinstance, entityhorse);
entityskeleton1.startRiding(entityhorse);
entityhorse.addVelocity(this.horse.getRNG().nextGaussian() * 0.5D, 0.0D, this.horse.getRNG().nextGaussian() * 0.5D);
}
}
示例10: onInitialSpawn
import net.minecraft.world.DifficultyInstance; //导入依赖的package包/类
/**
* 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);
if (this.getTameSkin() == 0 && this.worldObj.rand.nextInt(7) == 0)
{
for (int i = 0; i < 2; ++i)
{
EntityOcelot entityocelot = new EntityOcelot(this.worldObj);
entityocelot.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F);
entityocelot.setGrowingAge(-24000);
this.worldObj.spawnEntityInWorld(entityocelot);
}
}
return livingdata;
}
示例11: attackEntityWithRangedAttack
import net.minecraft.world.DifficultyInstance; //导入依赖的package包/类
/**
* Overridden to fire "fake" arrows instead of real ones.
* see {@link net.minecraft.entity.monster.EntitySkeleton#attackEntityWithRangedAttack(net.minecraft.entity.EntityLivingBase, float)}.
*/
@Override
public void attackEntityWithRangedAttack(EntityLivingBase target, float distanceFactor)
{
EntityFakeArrow entityarrow = new EntityFakeArrow(this.world, this);
double x = target.posX - this.posX;
double y = target.getEntityBoundingBox().minY + (double)(target.height / 3.0F) - entityarrow.posY;
double z = target.posZ - this.posZ;
double d3 = (double)MathHelper.sqrt(x * x + z * z);
entityarrow.setThrowableHeading(x, y + d3 * 0.2D, z, 1.6F, (float)(14 - this.world.getDifficulty().getDifficultyId() * 4));
DifficultyInstance difficultyinstance = this.world.getDifficultyForLocation(new BlockPos(this));
entityarrow.setDamage((double)(distanceFactor * 2.0F) + this.rand.nextGaussian() * 0.25D + (double)((float)this.world.getDifficulty().getDifficultyId() * 0.11F));
this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
this.world.spawnEntity(entityarrow);
}
示例12: onInitialSpawn
import net.minecraft.world.DifficultyInstance; //导入依赖的package包/类
/**
* Overridden to call {@link EntityZombie#setChild(boolean)} to force all ZombieHands to be adults, and to create HuskHands in desert biomes
*/
@Override
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata)
{
super.onInitialSpawn(difficulty, livingdata);
this.setChild(false);
// *** logic copied from 1.10 implementation of EntityZombie
Biome biome = this.world.getBiome(new BlockPos(this));
if (biome instanceof BiomeDesert && this.world.canSeeSky(new BlockPos(this)) && this.rand.nextInt(5) != 0)
{
this.setZombieType(ZombieType.HUSK);
}
// *** logic copied from 1.10 implementation of EntityZombie
return livingdata;
}
示例13: updateTask
import net.minecraft.world.DifficultyInstance; //导入依赖的package包/类
/**
* Updates the task
*/
public void updateTask()
{
DifficultyInstance difficultyinstance = this.horse.world.getDifficultyForLocation(new BlockPos(this.horse));
this.horse.func_190691_p(false);
this.horse.setHorseTamed(true);
this.horse.setGrowingAge(0);
this.horse.world.addWeatherEffect(new EntityLightningBolt(this.horse.world, this.horse.posX, this.horse.posY, this.horse.posZ, true));
EntitySkeleton entityskeleton = this.createSkeleton(difficultyinstance, this.horse);
entityskeleton.startRiding(this.horse);
for (int i = 0; i < 3; ++i)
{
AbstractHorse abstracthorse = this.createHorse(difficultyinstance);
EntitySkeleton entityskeleton1 = this.createSkeleton(difficultyinstance, abstracthorse);
entityskeleton1.startRiding(abstracthorse);
abstracthorse.addVelocity(this.horse.getRNG().nextGaussian() * 0.5D, 0.0D, this.horse.getRNG().nextGaussian() * 0.5D);
}
}
示例14: createSkeleton
import net.minecraft.world.DifficultyInstance; //导入依赖的package包/类
private EntitySkeleton createSkeleton(DifficultyInstance p_188514_1_, AbstractHorse p_188514_2_)
{
EntitySkeleton entityskeleton = new EntitySkeleton(p_188514_2_.world);
entityskeleton.onInitialSpawn(p_188514_1_, (IEntityLivingData)null);
entityskeleton.setPosition(p_188514_2_.posX, p_188514_2_.posY, p_188514_2_.posZ);
entityskeleton.hurtResistantTime = 60;
entityskeleton.enablePersistence();
if (entityskeleton.getItemStackFromSlot(EntityEquipmentSlot.HEAD).func_190926_b())
{
entityskeleton.setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(Items.IRON_HELMET));
}
entityskeleton.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, EnchantmentHelper.addRandomEnchantment(entityskeleton.getRNG(), entityskeleton.getHeldItemMainhand(), (int)(5.0F + p_188514_1_.getClampedAdditionalDifficulty() * (float)entityskeleton.getRNG().nextInt(18)), false));
entityskeleton.setItemStackToSlot(EntityEquipmentSlot.HEAD, EnchantmentHelper.addRandomEnchantment(entityskeleton.getRNG(), entityskeleton.getItemStackFromSlot(EntityEquipmentSlot.HEAD), (int)(5.0F + p_188514_1_.getClampedAdditionalDifficulty() * (float)entityskeleton.getRNG().nextInt(18)), false));
entityskeleton.world.spawnEntityInWorld(entityskeleton);
return entityskeleton;
}
示例15: setEnchantmentBasedOnDifficulty
import net.minecraft.world.DifficultyInstance; //导入依赖的package包/类
/**
* Enchants Entity's current equipments based on given DifficultyInstance
*/
protected void setEnchantmentBasedOnDifficulty(DifficultyInstance difficulty)
{
float f = difficulty.getClampedAdditionalDifficulty();
if (!this.getHeldItemMainhand().func_190926_b() && this.rand.nextFloat() < 0.25F * f)
{
this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, EnchantmentHelper.addRandomEnchantment(this.rand, this.getHeldItemMainhand(), (int)(5.0F + f * (float)this.rand.nextInt(18)), false));
}
for (EntityEquipmentSlot entityequipmentslot : EntityEquipmentSlot.values())
{
if (entityequipmentslot.getSlotType() == EntityEquipmentSlot.Type.ARMOR)
{
ItemStack itemstack = this.getItemStackFromSlot(entityequipmentslot);
if (!itemstack.func_190926_b() && this.rand.nextFloat() < 0.5F * f)
{
this.setItemStackToSlot(entityequipmentslot, EnchantmentHelper.addRandomEnchantment(this.rand, itemstack, (int)(5.0F + f * (float)this.rand.nextInt(18)), false));
}
}
}
}