Java源码示例:net.minecraft.entity.projectile.ProjectileHelper

示例1
@Override
public void onUpdate() {
    if (this.world.isRemote || this.world.isBlockLoaded(new BlockPos(this))) {
        super.onUpdate();

        ++this.ticksInAir;
        RayTraceResult raytraceresult = ProjectileHelper.forwardsRaycast(this, true, this.ticksInAir >= 25, this.shootingEntity);

        if (raytraceresult != null && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult)) {
            this.onImpact(raytraceresult);
        }

        this.posX += this.motionX;
        this.posY += this.motionY;
        this.posZ += this.motionZ;
        ProjectileHelper.rotateTowardsMovement(this, 0.2F);
        float f = this.getMotionFactor();

        if (this.isInWater()) {
            for (int i = 0; i < 4; ++i) {
                this.world.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * 0.25D, this.posY - this.motionY * 0.25D, this.posZ - this.motionZ * 0.25D, this.motionX, this.motionY, this.motionZ);
            }

            f = 0.8F;
        }

        this.motionX += this.accelerationX;
        this.motionY += this.accelerationY;
        this.motionZ += this.accelerationZ;
        this.motionX *= f;
        this.motionY *= f;
        this.motionZ *= f;
        this.setPosition(this.posX, this.posY, this.posZ);
    } else {
        this.setDead();
    }
}
 
示例2
@Override
public void onUpdate() {

    this.prevPosX = this.posX;
    this.prevPosY = this.posY;
    this.prevPosZ = this.posZ;
    if (this.hurtEntities && this.onGround) {
        this.world.spawnParticle(EnumParticleTypes.CLOUD, this.posX, this.posY, this.posZ, 0.0F, 0.0F, 0.0F);
        this.playSound(SoundEvents.BLOCK_STONE_BREAK, 1.2F, 1.0F);
        if (!this.world.isRemote) {
            this.setDead();
            return;
        }
    }
    if (this.fallTime++ == 300) {
        this.world.spawnParticle(EnumParticleTypes.CLOUD, this.posX, this.posY, this.posZ, 0.0F, 0.0F, 0.0F);
        this.playSound(SoundEvents.BLOCK_STONE_BREAK, 1.2F, 1.0F);
        if (!this.world.isRemote) {
            this.setDead();
            return;
        }
    }


    RayTraceResult raytraceresult = ProjectileHelper.forwardsRaycast(this, true, false, this.owner);

    if (raytraceresult != null && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult)) {
        this.onImpact(raytraceresult);
        this.playSound(SoundEvents.BLOCK_STONE_BREAK, 1.2F, 1.0F);
        this.world.spawnParticle(EnumParticleTypes.CLOUD, this.posX, this.posY, this.posZ, 0.0F, 0.0F, 0.0F);
        if (!this.world.isRemote) {
            this.setDead();
        }
    }


    if (!this.hasNoGravity()) {
        if (this.onGround) {
            this.motionY = 0.0F;
        } else if (this.isInWater() || this.isInLava()) {
            this.motionY = (0.3 - this.motionY) * 0.3;
        } else {
            this.motionY -= 0.03999999910593033D;
        }
    }

    this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ);

    this.motionX *= 0.9800000190734863D;
    this.motionY *= 0.9800000190734863D;
    this.motionZ *= 0.9800000190734863D;
}