本文整理了Java中net.minecraft.entity.Entity.addVelocity()
方法的一些代码示例,展示了Entity.addVelocity()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entity.addVelocity()
方法的具体详情如下:
包路径:net.minecraft.entity.Entity
类名称:Entity
方法名:addVelocity
暂无
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
@Override
public void addVelocity(double par1, double par3, double par5) {
super.addVelocity(par1, par3, par5);
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
@Override
public void applyEntityCollision(Entity entity) {
super.applyEntityCollision(entity);
if (isInside(entity))
entity.addVelocity(0, -gateStatus * 0.5, 0);
}
代码示例来源:origin: PrinceOfAmber/Cyclic
public static void setVelocity(Entity entity, float rotationPitch, float rotationYaw, float power) {
entity.motionX = 0;
entity.motionY = 0;
entity.motionZ = 0;
double velX = -MathHelper.sin(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI) * power;
double velZ = MathHelper.cos(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI) * power;
double velY = MathHelper.sin((rotationPitch) / 180.0F * (float) Math.PI) * power;
// if (velY < 0) {
// velY *= -1;// make it always up never down
// }
if (Math.abs(velX) < lowEnough) velX = 0;
if (Math.abs(velY) < lowEnough) velY = 0;
if (Math.abs(velZ) < lowEnough) velZ = 0;
// if(entity.getEntityWorld().isRemote){
// ModCyclic.logger.info("(angle,yaw,power) = " + rotationPitch + "," + rotationYaw + "," + power);
// ModCyclic.logger.info("!setvelocity " + velX + "," + velY + "," + velZ);
//// ModCyclic.logger.info("!onground " + entity.onGround);
// ModCyclic.logger.info("!posY " + entity.posY);
// }
//setting to zero first then using add, pretty much the same as set
entity.addVelocity(velX, velY, velZ);
}
代码示例来源:origin: PrinceOfAmber/Cyclic
public static void launch(Entity entity, float rotationPitch, float rotationYaw, float power) {
float mountPower = (float) (power + 0.5);
double velX = -MathHelper.sin(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI) * power;
double velZ = MathHelper.cos(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI) * power;
double velY = -MathHelper.sin((rotationPitch) / 180.0F * (float) Math.PI) * power;
// launch the player up and forward at minimum angle
// regardless of look vector
if (velY < 0) {
velY *= -1;// make it always up never down
}
Entity ridingEntity = entity.getRidingEntity();
if (ridingEntity != null) {
// boost power a bit, horses are heavy as F
ridingEntity.motionY = 0;
ridingEntity.fallDistance = 0;
ridingEntity.addVelocity(velX * mountPower, velY * mountPower, velZ * mountPower);
}
else {
entity.motionY = 0;
entity.fallDistance = 0;
entity.addVelocity(velX, velY, velZ);
}
}
代码示例来源:origin: vadis365/TheErebus
@Override
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
if (entity instanceof EntityLivingBase) {
int Knockback = 1;
entity.attackEntityFrom(DamageSource.CACTUS, 1);
entity.addVelocity(MathHelper.sin(entity.rotationYaw * 3.141593F / 180.0F) * Knockback * 0.1F, 0.08D, -MathHelper.cos(entity.rotationYaw * 3.141593F / 180.0F) * Knockback * 0.1F);
entity.getEntityWorld().playSound(null, pos, ModSounds.GLOW_WORM_HURT, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
}
}
代码示例来源:origin: vadis365/TheErebus
@Override
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
if (entity instanceof EntityLivingBase) {
int Knockback = 1;
entity.attackEntityFrom(DamageSource.CACTUS, 1);
entity.addVelocity(MathHelper.sin(entity.rotationYaw * 3.141593F / 180.0F) * Knockback * 0.1F, 0.08D, -MathHelper.cos(entity.rotationYaw * 3.141593F / 180.0F) * Knockback * 0.1F);
entity.getEntityWorld().playSound(null, pos, ModSounds.GLOW_WORM_HURT, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
}
代码示例来源:origin: vadis365/TheErebus
protected Entity areaOfEffect2() {
List<?> list = getEntityWorld().getEntitiesWithinAABB(EntityLivingBase.class, getEntityBoundingBox().grow(16D, 1D, 16D));
for (int i = 0; i < list.size(); i++) {
Entity entity = (Entity) list.get(i);
if (entity != null)
if (entity instanceof EntityLivingBase && !(entity instanceof EntityAntlionBoss)) {
float Knockback = (-3.0F + getEntityWorld().rand.nextInt(4)) * 0.1F;
entity.attackEntityFrom(DamageSource.causeMobDamage(this), (float) (ConfigHandler.INSTANCE.mobAttackDamageMultiplier < 2 ? 2D : 2D * ConfigHandler.INSTANCE.mobAttackDamageMultiplier));
entity.addVelocity(-MathHelper.sin(rotationYaw * -3.141593F + getEntityWorld().rand.nextInt(3) + 0.141593F / 180.0F) * Knockback, 0.01D, MathHelper.cos(rotationYaw * -3.141593F + getEntityWorld().rand.nextInt(3) + 0.141593F / 180.0F) * Knockback);
getEntityWorld().playSound(null, getPosition(), ModSounds.ANTLION_SLAM, SoundCategory.HOSTILE, 1.0F, 1.0F);
}
}
return null;
}
代码示例来源:origin: ForestryMC/Binnie
@Override
protected IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing, World world, BlockPos position) {
final List<Entity> entities = this.getEntities(Entity.class, genome, housing);
for (final Entity entity : entities) {
float entityStrength = 1.0f;
if (entity instanceof EntityPlayer) {
entityStrength *= 100.0f;
}
double posX = position.getX() - entity.posX;
double posY = position.getY() - entity.posY;
double posZ = position.getZ() - entity.posZ;
if (posX * posX + posY * posY + posZ * posZ < 2.0) {
return storedData;
}
final double strength = 0.5 / (posX * posX + posY * posY + posZ * posZ) * entityStrength;
entity.addVelocity(posX * strength, posY * strength, posZ * strength);
}
return storedData;
}
},
代码示例来源:origin: vadis365/TheErebus
protected Entity areaOfEffect(World world, ItemStack stack, EntityPlayer player) {
List<?> list = world.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(player.getEntityBoundingBox().minX, player.getEntityBoundingBox().minY, player.getEntityBoundingBox().minZ, player.getEntityBoundingBox().maxX, player.getEntityBoundingBox().maxY, player.getEntityBoundingBox().maxZ).grow(stack.getTagCompound().getInteger("charge") * 0.25D, 1D, stack.getTagCompound().getInteger("charge") * 0.25D));
for (int i = 0; i < list.size(); i++) {
Entity entity = (Entity) list.get(i);
if (entity != null)
if (entity instanceof EntityLivingBase && entity != player) {
float Knockback = (float) (stack.getTagCompound().getInteger("charge") * 0.025D);
entity.attackEntityFrom(DamageSource.causeMobDamage(player), stack.getTagCompound().getInteger("charge") * 0.25F);
entity.addVelocity(-MathHelper.sin(player.rotationYaw * -3.141593F + world.rand.nextInt(3) + 0.141593F / 180.0F) * Knockback, 0.01D, MathHelper.cos(player.rotationYaw * -3.141593F + world.rand.nextInt(3) + 0.141593F / 180.0F) * Knockback);
}
}
return null;
}
代码示例来源:origin: vadis365/TheErebus
@Override
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
if (!world.isRemote && entity instanceof EntityLiving)
if (entity.getEntityWorld().getBlockState(pos).getBlock() == ModBlocks.INSECT_REPELLENT && ((EntityLiving) entity).getCreatureAttribute().equals(EnumCreatureAttribute.ARTHROPOD)) {
int Knockback = 1;
entity.addVelocity(MathHelper.sin(entity.rotationYaw * 3.141593F / 180.0F) * Knockback * 0.1F, 0.1D, MathHelper.cos(entity.rotationYaw * 3.141593F / 180.0F) * Knockback * 0.1F);
entity.getEntityWorld().playSound(null, pos, SoundEvents.ENTITY_PLAYER_SMALL_FALL, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
}
}
代码示例来源:origin: MrCrayfish/MrCrayfishFurnitureMod
@Override
public void onFallenUpon(World worldIn, BlockPos pos, Entity entityIn, float fallDistance)
{
if(entityIn instanceof EntityLivingBase)
{
float height = entityIn.fallDistance;
if(height > 0 && !entityIn.isSneaking())
{
if(height > 9) height = 9;
entityIn.motionY = 0;
entityIn.addVelocity(0, getRequiredVelocity(height + 1), 0);
worldIn.playSound(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, FurnitureSounds.boing, SoundCategory.BLOCKS, 0.75F, 1.0F, false);
if(worldIn.isRemote)
{
for(int i = 0; i < 5; i++)
{
worldIn.spawnParticle(EnumParticleTypes.SPELL_MOB, entityIn.posX, entityIn.posY, entityIn.posZ, 1, 1, 1, 0);
}
}
}
entityIn.fallDistance = 0;
}
}
代码示例来源:origin: vadis365/TheErebus
protected Entity areaOfEffect() {
List<?> list = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, attacker.getEntityBoundingBox().grow(8D, 1D, 8D));
for (int i = 0; i < list.size(); i++) {
Entity entity = (Entity) list.get(i);
if (entity != null)
if (entity instanceof EntityLivingBase && !(entity instanceof EntityAntlionBoss)) {
entity.attackEntityFrom(DamageSource.causeMobDamage(attacker), (float) (ConfigHandler.INSTANCE.mobAttackDamageMultiplier < 2 ? 8D : 8D * ConfigHandler.INSTANCE.mobAttackDamageMultiplier));
entity.addVelocity(-MathHelper.sin(attacker.rotationYaw * 3.141593F / 180.0F) * 1D, 0.4D, MathHelper.cos(attacker.rotationYaw * 3.141593F / 180.0F) * 1D);
worldObj.playSound(null, entity.getPosition(), ModSounds.ANTLION_SLAM, SoundCategory.HOSTILE, 1.0F, 1.0F);
worldObj.playSound(null, entity.getPosition(), ModSounds.ANTLION_EXPLODE, SoundCategory.HOSTILE, 1.0F, 1.0F);;
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 8 * 20, 0));
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 8 * 20, 0));
}
}
return null;
}
}
代码示例来源:origin: vadis365/TheErebus
@SuppressWarnings("unchecked")
private void explode() {
List<Entity> list = getEntityWorld().getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(posX - 0.5D, posY - 0.5D, posZ - 0.5D, posX + 0.5D, posY + 0.5D, posZ + 0.5D).grow(4D, 4D, 4D));
for (int i = 0; i < list.size(); i++) {
Entity entity = list.get(i);
if (entity != null)
if (entity instanceof EntityLivingBase) {
entity.addVelocity(-MathHelper.sin(entity.rotationYaw * 3.141593F / 180.0F) * 2.0D, 1D, MathHelper.cos(entity.rotationYaw * 3.141593F / 180.0F) * 2.0D);
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 10 * 20, 3));
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, 10 * 20, 0));
getEntityWorld().playSound(null, getPosition(), ModSounds.BEETLE_LARVA_SPLAT, SoundCategory.BLOCKS, 1.0F, 0.5F);
getEntityWorld().playSound(null, getPosition(), ModSounds.SQUISH, SoundCategory.BLOCKS, 1.0F, 0.7F);
}
}
}
代码示例来源:origin: vadis365/TheErebus
protected Entity findEnemyToAttack() {
List<?> list = getEntityWorld().getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(posX + 0.5D, posY + 0.5D, posZ + 0.5D, posX + 0.5D, posY + 0.5D, posZ + 0.5D).grow(sonics * 0.2D, 0.5D, sonics * 0.2D));
for (int i = 0; i < list.size(); i++) {
Entity entity = (Entity) list.get(i);
if (entity instanceof EntityPlayer && !((EntityPlayer) entity).capabilities.isCreativeMode) {
if (sonics == 20) {
if (getEntityWorld().isRemote)
spawnSonicParticles();
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.BLINDNESS, 8 * 20, 0));
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 8 * 20, 0));
entity.addVelocity(-MathHelper.sin(rotationYaw * 3.141593F / 180.0F) * 2.0D, 0D, MathHelper.cos(rotationYaw * 3.141593F / 180.0F) * 2.0D);
getEntityWorld().playSound((EntityPlayer)null, getPosition(), ModSounds.LOCUST_SPAWN, SoundCategory.NEUTRAL, 1.0F, 6.0F);
setCicadaFlying(true);
}
return canEntityBeSeen(entity) ? entity : null;
}
}
return null;
}
代码示例来源:origin: vadis365/TheErebus
@SuppressWarnings("unchecked")
protected Entity areaOfEffect() {
List<EntityLivingBase> list = attacker.getEntityWorld().getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(attacker.getEntityBoundingBox().minX, attacker.getEntityBoundingBox().minY, attacker.getEntityBoundingBox().minZ, attacker.getEntityBoundingBox().maxX, attacker.getEntityBoundingBox().maxY, attacker.getEntityBoundingBox().maxZ).grow(8D, 1D, 8D));
for (int i = 0; i < list.size(); i++) {
Entity entity = list.get(i);
if (entity != null)
if (entity instanceof EntityLivingBase && !(entity instanceof EntityTarantulaMiniboss) && !(entity instanceof EntityTarantula) && !(entity instanceof EntityTarantulaBaby)) {
float Knockback = 2;
entity.attackEntityFrom(DamageSource.causeMobDamage(attacker), (float) (ConfigHandler.INSTANCE.mobAttackDamageMultiplier < 2 ? 8D : 8D * ConfigHandler.INSTANCE.mobAttackDamageMultiplier));
entity.addVelocity(-MathHelper.sin(attacker.rotationYaw * 3.141593F / 180.0F) * Knockback * 0.5F, 0.4D, MathHelper.cos(attacker.rotationYaw * 3.141593F / 180.0F) * Knockback * 0.5F);
attacker.getEntityWorld().playSound(null, attacker.getPosition(), ModSounds.BLAM_SOUND, SoundCategory.HOSTILE, 1.5F, 1.0F);
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 8 * 20, 0));
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.BLINDNESS, 5 * 20, 0));
}
}
return null;
}
}
代码示例来源:origin: vadis365/TheErebus
@Override
protected void onImpact(RayTraceResult target) {
if (target.entityHit != null) {
byte damage = 4;
if (!target.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, getThrower()), damage))
;
if (isBurning() && !(target.entityHit instanceof EntityEnderman))
target.entityHit.setFire(5);
if (!getEntityWorld().isRemote) {
target.entityHit.addVelocity(-MathHelper.sin(getThrower().rotationYaw * 3.141593F / 180.0F) * 0.5F, 0.1D, MathHelper.cos(getThrower().rotationYaw * 3.141593F / 180.0F) * 0.5F);
spawnWoodlouse();
}
} else if (!getEntityWorld().isRemote)
spawnWoodlouse();
}
代码示例来源:origin: vadis365/TheErebus
protected boolean Attack(Entity entity) {
if (!getEntityWorld().isRemote) {
if (onGround) {
double d0 = entity.posX - posX;
double d1 = entity.posZ - posZ;
float f2 = MathHelper.sqrt(d0 * d0 + d1 * d1);
motionX = d0 / f2 * 0.5D * 0.800000011920929D + motionX * 0.20000000298023224D;
motionZ = d1 / f2 * 0.5D * 0.800000011920929D + motionZ * 0.20000000298023224D;
motionY = 0.4000000059604645D;
}
int Knockback = 1;
entity.attackEntityFrom(DamageSource.causeMobDamage(this), (float) (ConfigHandler.INSTANCE.mobAttackDamageMultiplier < 2 ? 5D : 5D * ConfigHandler.INSTANCE.mobAttackDamageMultiplier));
entity.addVelocity(-MathHelper.sin(rotationYaw * 3.141593F / 180.0F) * Knockback * 0.5F, 0.4D, MathHelper.cos(rotationYaw * 3.141593F / 180.0F) * Knockback * 0.5F);
getEntityWorld().playSound(null, getPosition(), SoundEvents.ENTITY_PLAYER_BIG_FALL, SoundCategory.NEUTRAL, 1.0F, 1.0F);
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, getEntityWorld().getDifficulty().ordinal() * 50, 0));
return true;
}
return true;
}
代码示例来源:origin: MatterOverdrive/MatterOverdrive-Legacy-Edition
@Override
public void onAndroidUpdate(AndroidPlayer android, int level) {
if (isActive(android, level)) {
if (!android.getPlayer().world.isRemote && !android.getPlayer().isDead) {
for (Entity entityitem : android.getPlayer().world.getEntitiesWithinAABBExcludingEntity(android.getPlayer(), android.getPlayer().getEntityBoundingBox().grow(10.0D, 5.0D, 10.0D))) {
if (entityitem instanceof EntityItem) {
if (!((EntityItem) entityitem).cannotPickup()) {
Vec3d dir = android.getPlayer().getPositionVector().addVector(0, android.getPlayer().getEyeHeight(), 0).subtract(entityitem.getPositionVector()).normalize();
entityitem.addVelocity(dir.x * ITEM_SPEED, dir.y * ITEM_SPEED, dir.z * ITEM_SPEED);
android.extractEnergyScaled(ENERGY_PULL_PER_ITEM);
}
} else if (entityitem instanceof EntityXPOrb && ((EntityXPOrb) entityitem).delayBeforeCanPickup <= 0 && android.getPlayer().xpCooldown == 0) {
Vec3d dir = android.getPlayer().getPositionVector().addVector(0, android.getPlayer().getEyeHeight(), 0).subtract(entityitem.getPositionVector()).normalize();
entityitem.addVelocity(dir.x * ITEM_SPEED, dir.y * ITEM_SPEED, dir.z * ITEM_SPEED);
android.extractEnergyScaled(ENERGY_PULL_PER_ITEM);
}
}
}
}
}
代码示例来源:origin: vadis365/TheErebus
protected boolean attack(Entity entity) {
if (!getEntityWorld().isRemote && canEntityBeSeen(entity)) {
if (onGround) {
double d0 = entity.posX - posX;
double d1 = entity.posZ - posZ;
float f2 = MathHelper.sqrt(d0 * d0 + d1 * d1);
motionX = d0 / f2 * 0.5D * 0.800000011920929D + motionX * 0.20000000298023224D;
motionZ = d1 / f2 * 0.5D * 0.800000011920929D + motionZ * 0.20000000298023224D;
motionY = 0.4000000059604645D;
}
int knockback = 1;
entity.attackEntityFrom(DamageSource.causeMobDamage(this), (float) (ConfigHandler.INSTANCE.mobAttackDamageMultiplier < 2 ? getAttackStrength() : getAttackStrength() * ConfigHandler.INSTANCE.mobAttackDamageMultiplier));
entity.addVelocity(-MathHelper.sin(rotationYaw * 3.141593F / 180.0F) * knockback * 0.5F, 0.4D, MathHelper.cos(rotationYaw * 3.141593F / 180.0F) * knockback * 0.5F);
getEntityWorld().playSound(null, getPosition(), SoundEvents.ENTITY_PLAYER_BIG_FALL, SoundCategory.HOSTILE, 1.0F, 1.0F);
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, getEntityWorld().getDifficulty().ordinal() * 50, 0));
return true;
}
return true;
}
代码示例来源:origin: vadis365/TheErebus
private boolean ram(Entity entity, float knockback, float damage) {
if (getTameState() == 0 || !isBeingRidden())
setRammingCharge((byte) 32);
if (!getEntityWorld().isRemote && entity.getEntityBoundingBox().maxY >= getEntityBoundingBox().minY && entity.getEntityBoundingBox().minY <= getEntityBoundingBox().maxY && entity.getEntityBoundingBox().maxX >= getEntityBoundingBox().minX - 0.25D && entity.getEntityBoundingBox().minX <= getEntityBoundingBox().maxX + 0.25D && entity.getEntityBoundingBox().maxZ >= getEntityBoundingBox().minZ - 0.25D && entity.getEntityBoundingBox().minZ <= getEntityBoundingBox().maxZ + 0.25D) {
entity.attackEntityFrom(DamageSource.causeMobDamage(this), (int) damage);
entity.addVelocity(-MathHelper.sin(rotationYaw * 3.141593F / 180.0F) * knockback, 0.4D, MathHelper.cos(rotationYaw * 3.141593F / 180.0F) * knockback);
getEntityWorld().playSound((EntityPlayer)null, getPosition(), SoundEvents.ENTITY_PLAYER_BIG_FALL, SoundCategory.HOSTILE, 1.0F, 1.0F);
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, getEntityWorld().getDifficulty().ordinal() * 50, 0));
setRamming(false);
}
return true;
}
内容来源于网络,如有侵权,请联系作者删除!